Struct clone_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.0source§impl Default for MockAddressGenerator
impl Default for MockAddressGenerator
source§fn default() -> MockAddressGenerator
fn default() -> MockAddressGenerator
Auto Trait Implementations§
impl Freeze for MockAddressGenerator
impl RefUnwindSafe for MockAddressGenerator
impl Send for MockAddressGenerator
impl Sync for MockAddressGenerator
impl Unpin for MockAddressGenerator
impl UnwindSafe for MockAddressGenerator
Blanket Implementations§
source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata ) -> <T as Pointee>::Metadata
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request