Struct cw_multi_test::addons::MockApiBech32
source · pub struct MockApiBech32 { /* private fields */ }Expand description
Implementation of the Api trait that uses Bech32 format
for humanizing canonical addresses.
Implementations§
source§impl MockApiBech32
impl MockApiBech32
sourcepub fn new(prefix: &'static str) -> Self
pub fn new(prefix: &'static str) -> Self
Returns Api implementation that uses specified prefix
to generate addresses in Bech32 format.
§Example
use cw_multi_test::addons::MockApiBech32;
let api = MockApiBech32::new("juno");
let addr = api.addr_make("creator");
assert_eq!(addr.as_str(),
"juno1h34lmpywh4upnjdg90cjf4j70aee6z8qqfspugamjp42e4q28kqsksmtyp");source§impl MockApiBech32
impl MockApiBech32
sourcepub fn addr_make(&self, input: &str) -> Addr
pub fn addr_make(&self, input: &str) -> Addr
Returns an address in Bech32 format, built from provided input string.
§Example
use cw_multi_test::addons::MockApiBech32;
let api = MockApiBech32::new("juno");
let addr = api.addr_make("creator");
assert_eq!(addr.as_str(),
"juno1h34lmpywh4upnjdg90cjf4j70aee6z8qqfspugamjp42e4q28kqsksmtyp");§Panics
This function panics when generating a valid address in Bech32 format is not possible, especially when prefix is too long or empty.
Trait Implementations§
source§impl Api for MockApiBech32
impl Api for MockApiBech32
source§fn addr_validate(&self, input: &str) -> StdResult<Addr>
fn addr_validate(&self, input: &str) -> StdResult<Addr>
Takes a human readable address in Bech32 format and checks if it is valid.
If the validation succeeds, an Addr containing the same string as the input is returned.
§Example
use cosmwasm_std::Api;
use cw_multi_test::addons::MockApiBech32;
let api = MockApiBech32::new("juno");
let addr = api.addr_make("creator");
assert_eq!(api.addr_validate(addr.as_str()).unwrap().as_str(),
addr.as_str());source§fn addr_canonicalize(&self, input: &str) -> StdResult<CanonicalAddr>
fn addr_canonicalize(&self, input: &str) -> StdResult<CanonicalAddr>
Takes a human readable address in Bech32 format and returns a canonical binary representation of it.
§Example
use cosmwasm_std::Api;
use cw_multi_test::addons::MockApiBech32;
let api = MockApiBech32::new("juno");
let addr = api.addr_make("creator");
assert_eq!(api.addr_canonicalize(addr.as_str()).unwrap().to_string(),
"BC6BFD848EBD7819C9A82BF124D65E7F739D08E002601E23BB906AACD40A3D81");source§fn addr_humanize(&self, canonical: &CanonicalAddr) -> StdResult<Addr>
fn addr_humanize(&self, canonical: &CanonicalAddr) -> StdResult<Addr>
Takes a canonical address and returns a human readable address in Bech32 format.
This is the inverse operation of addr_canonicalize.
§Example
use cosmwasm_std::Api;
use cw_multi_test::addons::MockApiBech32;
let api = MockApiBech32::new("juno");
let addr = api.addr_make("creator");
let canonical_addr = api.addr_canonicalize(addr.as_str()).unwrap();
assert_eq!(api.addr_humanize(&canonical_addr).unwrap().as_str(),
addr.as_str());