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_address generates non-predictable addresses for contracts, using the same algorithm as wasmd, see: BuildContractAddressClassic for details.
  • predictable_contract_address generates predictable addresses for contracts using instantiate2_address function defined in cosmwasm-std.

Trait Implementations§

source§

impl AddressGenerator for MockAddressGenerator

source§

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_humanize function, so the resulting value depends on used Api implementation. 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>

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_humanize function, so the resulting value depends on used Api implementation. 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

👎Deprecated since 0.18.0: use contract_address or predictable_contract_address instead; will be removed in version 1.0.0
source§

impl Default for MockAddressGenerator

source§

fn default() -> MockAddressGenerator

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> ArchivePointee for T

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
source§

impl<U> As for U

source§

fn as_<T>(self) -> T
where T: CastFrom<U>,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

source§

fn deserialize( &self, deserializer: &mut D ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
source§

impl<T> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T> LayoutRaw for T

source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Gets the layout of the type.
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Pointee for T

§

type Metadata = ()

The type for metadata in pointers and references to Self.
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> Upcastable for T
where T: Any + Send + Sync + 'static,

source§

fn upcast_any_ref(&self) -> &(dyn Any + 'static)

upcast ref
source§

fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)

upcast mut ref
source§

fn upcast_any_box(self: Box<T>) -> Box<dyn Any>

upcast boxed dyn
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more