Skip to content
This repository was archived by the owner on Jul 1, 2026. It is now read-only.

Commit 1e7cfce

Browse files
committed
cleanups
1 parent 72aa066 commit 1e7cfce

5 files changed

Lines changed: 27 additions & 40 deletions

File tree

packages/neutron-sdk/src/interchain_queries/helpers.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::errors::error::{NeutronError, NeutronResult};
22
use crate::interchain_queries::types::{
33
AddressBytes, QueryPayload, QueryType, TransactionFilterItem, MAX_ADDR_LEN,
44
};
5-
use cosmwasm_std::{Addr, CosmosMsg, StdError, Uint128, Uint256};
5+
use cosmwasm_std::{Addr, CosmosMsg, StdError};
66
use neutron_std::types::neutron::interchainqueries::{
77
KvKey, MsgRegisterInterchainQuery, MsgRemoveInterchainQueryRequest,
88
MsgUpdateInterchainQueryRequest,
@@ -39,13 +39,6 @@ pub fn length_prefix<AddrBytes: AsRef<[u8]>>(addr: AddrBytes) -> NeutronResult<V
3939
Ok(p)
4040
}
4141

42-
pub fn uint256_to_u128(value: Uint256) -> Result<u128, StdError> {
43-
let converted: Uint128 = value
44-
.try_into()
45-
.map_err(|_| StdError::msg("Uint256 value exceeds u128 limits"))?;
46-
Ok(converted.u128())
47-
}
48-
4942
/// Basic helper to define a register interchain query message:
5043
/// * **contract** is a contract address that registers the interchain query.
5144
/// Must be equal to the contract that sends the message.

packages/neutron-sdk/src/interchain_queries/v045/testing.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,19 @@ pub const VALIDATOR_SIGNING_INFO_HEX_RESPONSE: &str = "0a34636f736d6f7376616c636
5252
fn test_balance_reconstruct() {
5353
struct TestCase {
5454
addr: String,
55-
coins: Vec<(String, Uint128)>,
55+
coins: Vec<(String, Uint256)>,
5656
}
5757
let test_cases: Vec<TestCase> = vec![
5858
TestCase {
5959
addr: "osmo1yz54ncxj9csp7un3xled03q6thrrhy9cztkfzs".to_string(),
60-
coins: vec![("uosmo".to_string(), Uint128::from(100u128))],
60+
coins: vec![("uosmo".to_string(), Uint256::from(100u128))],
6161
},
6262
TestCase {
6363
addr: "osmo1yz54ncxj9csp7un3xled03q6thrrhy9cztkfzs".to_string(),
6464
coins: vec![
65-
("uosmo".to_string(), Uint128::from(100u128)),
66-
("uatom".to_string(), Uint128::from(500u128)),
67-
("uluna".to_string(), Uint128::from(80u128)),
65+
("uosmo".to_string(), Uint256::from(100u128)),
66+
("uatom".to_string(), Uint256::from(500u128)),
67+
("uluna".to_string(), Uint256::from(80u128)),
6868
],
6969
},
7070
TestCase {
@@ -98,7 +98,7 @@ fn test_balance_reconstruct() {
9898
assert_eq!(balances.coins.len(), ts.coins.len());
9999
for (i, coin) in balances.coins.iter().enumerate() {
100100
assert_eq!(coin.denom, ts.coins[i].0);
101-
assert_eq!(coin.amount, Uint256::from(ts.coins[i].1))
101+
assert_eq!(coin.amount, ts.coins[i].1);
102102
}
103103
}
104104
}
@@ -155,7 +155,7 @@ fn test_bank_total_supply_reconstruct() {
155155
assert_eq!(coin.denom, ts.values[i].denom);
156156
assert_eq!(
157157
coin.amount,
158-
Uint256::from(Uint128::from_str(ts.values[i].amount.as_str()).unwrap())
158+
Uint256::from_str(ts.values[i].amount.as_str()).unwrap()
159159
)
160160
}
161161
}
@@ -787,17 +787,17 @@ fn test_proposal_votes_reconstruct() {
787787
#[test]
788788
fn test_fee_pool_reconstruct() {
789789
struct TestCase {
790-
coins: Vec<(String, Uint128)>,
790+
coins: Vec<(String, Uint256)>,
791791
}
792792
let test_cases: Vec<TestCase> = vec![
793793
TestCase {
794-
coins: vec![("uosmo".to_string(), Uint128::from(100u128))],
794+
coins: vec![("uosmo".to_string(), Uint256::from(100u128))],
795795
},
796796
TestCase {
797797
coins: vec![
798-
("uosmo".to_string(), Uint128::from(100u128)),
799-
("uatom".to_string(), Uint128::from(500u128)),
800-
("uluna".to_string(), Uint128::from(80u128)),
798+
("uosmo".to_string(), Uint256::from(100u128)),
799+
("uatom".to_string(), Uint256::from(500u128)),
800+
("uluna".to_string(), Uint256::from(80u128)),
801801
],
802802
},
803803
TestCase { coins: vec![] },
@@ -811,7 +811,7 @@ fn test_fee_pool_reconstruct() {
811811
denom: coin.0.clone(),
812812
amount: coin
813813
.1
814-
.mul(Uint128::one().mul(Uint128::from(10u64).pow(DECIMAL_PLACES))) // adjust to Dec gogo proto format
814+
.mul(Uint256::one().mul(Uint256::from(10u64).pow(DECIMAL_PLACES))) // adjust to Dec gogo proto format
815815
.to_string(),
816816
};
817817

@@ -835,7 +835,7 @@ fn test_fee_pool_reconstruct() {
835835
assert_eq!(fee_pool_coins.coins.len(), ts.coins.len());
836836
for (i, coin) in fee_pool_coins.coins.iter().enumerate() {
837837
assert_eq!(coin.denom, ts.coins[i].0);
838-
assert_eq!(coin.amount, Uint256::from(ts.coins[i].1))
838+
assert_eq!(coin.amount, ts.coins[i].1)
839839
}
840840
}
841841
}

packages/neutron-sdk/src/interchain_queries/v045/types.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use super::helpers::{
33
get_update_time,
44
};
55
use crate::errors::error::{NeutronError, NeutronResult};
6-
use crate::interchain_queries::helpers::uint256_to_u128;
76
use crate::interchain_queries::types::KVReconstruct;
87
use crate::interchain_queries::v045::helpers::deconstruct_account_denom_balance_key;
98
use cosmos_sdk_proto::cosmos::gov::v1beta1::Vote;
@@ -524,7 +523,7 @@ impl KVReconstruct for Delegations {
524523
.atomics()
525524
.div(Uint256::new(DECIMAL_FRACTIONAL));
526525

527-
delegation_std.amount = Coin::new(uint256_to_u128(delegated_tokens)?, &denom);
526+
delegation_std.amount = Coin::new(delegated_tokens, &denom);
528527

529528
delegations.push(delegation_std);
530529
}

packages/neutron-sdk/src/interchain_queries/v047/testing.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,10 @@ fn test_balance_reconstruct() {
9292
assert_eq!(coin.denom, ts.coins[i].0);
9393
// special testcase where value is an empty string
9494
if ts.coins[i].1.is_empty() {
95-
assert_eq!(coin.amount, Uint256::from(Uint128::zero()));
95+
assert_eq!(coin.amount, Uint256::zero());
9696
continue;
9797
}
98-
assert_eq!(
99-
coin.amount,
100-
Uint256::from(Uint128::from_str(&ts.coins[i].1).unwrap())
101-
)
98+
assert_eq!(coin.amount, Uint256::from_str(&ts.coins[i].1).unwrap())
10299
}
103100
}
104101
}
@@ -155,7 +152,7 @@ fn test_bank_total_supply_reconstruct() {
155152
assert_eq!(coin.denom, ts.values[i].denom);
156153
assert_eq!(
157154
coin.amount,
158-
Uint256::from(Uint128::from_str(ts.values[i].amount.as_str()).unwrap())
155+
Uint256::from_str(ts.values[i].amount.as_str()).unwrap()
159156
)
160157
}
161158
}
@@ -687,17 +684,17 @@ fn test_government_proposals_reconstruct() {
687684
#[test]
688685
fn test_fee_pool_reconstruct() {
689686
struct TestCase {
690-
coins: Vec<(String, Uint128)>,
687+
coins: Vec<(String, Uint256)>,
691688
}
692689
let test_cases: Vec<TestCase> = vec![
693690
TestCase {
694-
coins: vec![("uosmo".to_string(), Uint128::from(100u128))],
691+
coins: vec![("uosmo".to_string(), Uint256::from(100u128))],
695692
},
696693
TestCase {
697694
coins: vec![
698-
("uosmo".to_string(), Uint128::from(100u128)),
699-
("uatom".to_string(), Uint128::from(500u128)),
700-
("uluna".to_string(), Uint128::from(80u128)),
695+
("uosmo".to_string(), Uint256::from(100u128)),
696+
("uatom".to_string(), Uint256::from(500u128)),
697+
("uluna".to_string(), Uint256::from(80u128)),
701698
],
702699
},
703700
TestCase { coins: vec![] },
@@ -711,7 +708,7 @@ fn test_fee_pool_reconstruct() {
711708
denom: coin.0.clone(),
712709
amount: coin
713710
.1
714-
.mul(Uint128::one().mul(Uint128::from(10u64).pow(DECIMAL_PLACES))) // adjust to Dec gogo proto format
711+
.mul(Uint256::one().mul(Uint256::from(10u64).pow(DECIMAL_PLACES))) // adjust to Dec gogo proto format
715712
.to_string(),
716713
};
717714

@@ -735,7 +732,7 @@ fn test_fee_pool_reconstruct() {
735732
assert_eq!(fee_pool_coins.coins.len(), ts.coins.len());
736733
for (i, coin) in fee_pool_coins.coins.iter().enumerate() {
737734
assert_eq!(coin.denom, ts.coins[i].0);
738-
assert_eq!(coin.amount, Uint256::from(ts.coins[i].1))
735+
assert_eq!(coin.amount, ts.coins[i].1)
739736
}
740737
}
741738
}

packages/neutron-sdk/src/interchain_queries/v047/types.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ pub use crate::interchain_queries::v045::types::*;
99
use crate::interchain_queries::types::KVReconstruct;
1010
use crate::{errors::error::NeutronResult, NeutronError};
1111

12-
use crate::interchain_queries::helpers::uint256_to_u128;
1312
use crate::interchain_queries::v047::helpers::deconstruct_account_denom_balance_key;
1413
use cosmos_sdk_proto::cosmos::staking::v1beta1::{
1514
Delegation, Params, Validator as CosmosValidator,
@@ -126,8 +125,7 @@ impl KVReconstruct for Delegations {
126125
.atomics()
127126
.div(Uint256::new(DECIMAL_FRACTIONAL));
128127

129-
delegation_std.amount =
130-
Coin::new(uint256_to_u128(delegated_tokens)?, &params.bond_denom);
128+
delegation_std.amount = Coin::new(delegated_tokens, &params.bond_denom);
131129

132130
delegations.push(delegation_std);
133131
}

0 commit comments

Comments
 (0)