Skip to content

Commit

Permalink
Use BTreeMap for DistributionQuerier field
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Nov 8, 2023
1 parent e5ef873 commit 44e0220
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion packages/std/src/testing/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ impl StakingQuerier {
#[cfg(feature = "cosmwasm_1_3")]
#[derive(Clone, Default)]
pub struct DistributionQuerier {
withdraw_addresses: HashMap<String, String>,
withdraw_addresses: BTreeMap<String, String>,
/// Mock of accumulated rewards, indexed first by delegator and then validator address.
rewards: BTreeMap<String, BTreeMap<String, Vec<DecCoin>>>,
/// Mock of validators that a delegator has bonded to.
Expand Down Expand Up @@ -2363,4 +2363,26 @@ mod tests {
fn making_an_address_with_empty_prefix_should_panic() {
MockApi::default().with_prefix("").addr_make("creator");
}

#[test]
fn distribution_querier_new_works() {
let addresses = [
("addr0000".to_string(), "addr0001".to_string()),
("addr0002".to_string(), "addr0001".to_string()),
];
let btree_map = BTreeMap::from(addresses.clone());

// should still work with HashMap
let hashmap = HashMap::from(addresses.clone());
let querier = DistributionQuerier::new(hashmap);
assert_eq!(querier.withdraw_addresses, btree_map);

// should work with BTreeMap
let querier = DistributionQuerier::new(btree_map.clone());
assert_eq!(querier.withdraw_addresses, btree_map);

// should work with array
let querier = DistributionQuerier::new(addresses);
assert_eq!(querier.withdraw_addresses, btree_map);
}
}

0 comments on commit 44e0220

Please sign in to comment.