1
1
use alloc:: collections:: BTreeMap ;
2
2
use bech32:: { encode, ToBase32 , Variant } ;
3
+ use core:: iter:: IntoIterator ;
3
4
use core:: marker:: PhantomData ;
4
5
#[ cfg( feature = "cosmwasm_1_3" ) ]
5
6
use core:: ops:: Bound ;
@@ -989,7 +990,7 @@ impl StakingQuerier {
989
990
#[ cfg( feature = "cosmwasm_1_3" ) ]
990
991
#[ derive( Clone , Default ) ]
991
992
pub struct DistributionQuerier {
992
- withdraw_addresses : HashMap < String , String > ,
993
+ withdraw_addresses : BTreeMap < String , String > ,
993
994
/// Mock of accumulated rewards, indexed first by delegator and then validator address.
994
995
rewards : BTreeMap < String , BTreeMap < String , Vec < DecCoin > > > ,
995
996
/// Mock of validators that a delegator has bonded to.
@@ -998,9 +999,12 @@ pub struct DistributionQuerier {
998
999
999
1000
#[ cfg( feature = "cosmwasm_1_3" ) ]
1000
1001
impl DistributionQuerier {
1001
- pub fn new ( withdraw_addresses : HashMap < String , String > ) -> Self {
1002
+ pub fn new < T > ( withdraw_addresses : T ) -> Self
1003
+ where
1004
+ T : IntoIterator < Item = ( String , String ) > ,
1005
+ {
1002
1006
DistributionQuerier {
1003
- withdraw_addresses,
1007
+ withdraw_addresses : withdraw_addresses . into_iter ( ) . collect ( ) ,
1004
1008
..Default :: default ( )
1005
1009
}
1006
1010
}
@@ -2359,4 +2363,27 @@ mod tests {
2359
2363
fn making_an_address_with_empty_prefix_should_panic ( ) {
2360
2364
MockApi :: default ( ) . with_prefix ( "" ) . addr_make ( "creator" ) ;
2361
2365
}
2366
+
2367
+ #[ test]
2368
+ #[ cfg( feature = "cosmwasm_1_3" ) ]
2369
+ fn distribution_querier_new_works ( ) {
2370
+ let addresses = [
2371
+ ( "addr0000" . to_string ( ) , "addr0001" . to_string ( ) ) ,
2372
+ ( "addr0002" . to_string ( ) , "addr0001" . to_string ( ) ) ,
2373
+ ] ;
2374
+ let btree_map = BTreeMap :: from ( addresses. clone ( ) ) ;
2375
+
2376
+ // should still work with HashMap
2377
+ let hashmap = HashMap :: from ( addresses. clone ( ) ) ;
2378
+ let querier = DistributionQuerier :: new ( hashmap) ;
2379
+ assert_eq ! ( querier. withdraw_addresses, btree_map) ;
2380
+
2381
+ // should work with BTreeMap
2382
+ let querier = DistributionQuerier :: new ( btree_map. clone ( ) ) ;
2383
+ assert_eq ! ( querier. withdraw_addresses, btree_map) ;
2384
+
2385
+ // should work with array
2386
+ let querier = DistributionQuerier :: new ( addresses) ;
2387
+ assert_eq ! ( querier. withdraw_addresses, btree_map) ;
2388
+ }
2362
2389
}
0 commit comments