Struct cw_multi_test::addons::MockAddressGenerator
source · pub struct MockAddressGenerator;Expand description
Address generator that mimics the original wasmd behavior.
MockAddressGenerator implements AddressGenerator trait in terms of
contract_address and
predictable_contract_address functions:
contract_addressgenerates non-predictable addresses for contracts, using the same algorithm aswasmd, see:BuildContractAddressClassicfor details.predictable_contract_addressgenerates predictable addresses for contracts usinginstantiate2_addressfunction defined incosmwasm-std.
Trait Implementations§
source§impl AddressGenerator for MockAddressGenerator
impl AddressGenerator for MockAddressGenerator
source§fn contract_address(
&self,
api: &dyn Api,
_storage: &mut dyn Storage,
code_id: u64,
instance_id: u64
) -> AnyResult<Addr>
fn contract_address( &self, api: &dyn Api, _storage: &mut dyn Storage, code_id: u64, instance_id: u64 ) -> AnyResult<Addr>
Generates a non-predictable contract address, like wasmd does it in real-life chain.
Note that addresses generated by wasmd may change and users should not
rely on this value in any extend.
Returns the contract address after its instantiation.
Address generated by this function is returned as a result
of processing WasmMsg::Instantiate message.
NOTES
👉 The canonical address generated by this function is humanized using the
Api::addr_humanizefunction, so the resulting value depends on usedApiimplementation. The following example uses Bech32 format for humanizing canonical addresses.
👉 Do NOT use this function directly to generate a contract address, pass this address generator to
WasmKeeper:WasmKeeper::new().with_address_generator(MockAddressGenerator::default());
§Example
// use `Api` that implements Bech32 format
let api = MockApiBech32::new("juno");
// prepare mock storage
let mut storage = MockStorage::default();
// initialize the address generator
let address_generator = MockAddressGenerator::default();
// generate the address
let addr = address_generator.contract_address(&api, &mut storage, 1, 1).unwrap();
assert_eq!(addr.to_string(),
"juno14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9skjuwg8");source§fn predictable_contract_address(
&self,
api: &dyn Api,
_storage: &mut dyn Storage,
_code_id: u64,
_instance_id: u64,
checksum: &[u8],
creator: &CanonicalAddr,
salt: &[u8]
) -> AnyResult<Addr>
fn predictable_contract_address( &self, api: &dyn Api, _storage: &mut dyn Storage, _code_id: u64, _instance_id: u64, checksum: &[u8], creator: &CanonicalAddr, salt: &[u8] ) -> AnyResult<Addr>
Generates a predictable contract address, like wasmd does it in real-life chain.
Returns a contract address after its instantiation.
Address generated by this function is returned as a result
of processing WasmMsg::Instantiate2 message.
NOTES
👉 The canonical address generated by this function is humanized using the
Api::addr_humanizefunction, so the resulting value depends on usedApiimplementation. The following example uses Bech32 format for humanizing canonical addresses.
👉 Do NOT use this function directly to generate a contract address, pass this address generator to WasmKeeper:
WasmKeeper::new().with_address_generator(MockAddressGenerator::default());
§Example
// use `Api` that implements Bech32 format
let api = MockApiBech32::new("juno");
// prepare mock storage
let mut storage = MockStorage::default();
// initialize the address generator
let address_generator = MockAddressGenerator::default();
// checksum of the contract code base
let checksum = [0, 1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10,
11,12,13,14,15,16,17,18,19,20,21,
22,23,24,25,26,27,28,29,30,31];
// creator address
let creator = api.addr_canonicalize(api.addr_make("creator").as_str()).unwrap();
// salt
let salt = [10,11,12];
// generate the address
let addr = address_generator
.predictable_contract_address(&api, &mut storage, 1, 1, &checksum, &creator, &salt)
.unwrap();
assert_eq!(addr.to_string(),
"juno1sv3gjp85m3xxluxreruards8ruxk5ykys8qfljwrdj5tv8kqxuhsmlfyud");source§fn next_address(&self, storage: &mut dyn Storage) -> Addr
fn next_address(&self, storage: &mut dyn Storage) -> Addr
contract_address or predictable_contract_address instead; will be removed in version 1.0.0