CosmWasm / cw-multi-test

CosmWasm multi-contract testing framework
Apache License 2.0
45 stars 39 forks source link

Where has `MockAddressGenerator` gone? #208

Closed DariuszDepta closed 2 weeks ago

DariuszDepta commented 2 weeks ago

Power users are asking where cw_multi_test::addons::MockAddressGenerator has gone from version 0.x.x to 1.x.x of MultiTest?

image

As a maintainer of the MultiTest library, I would like to sincerely apologize for any shortcomings in my communication on this topic, especially not informing about this change directly in the CHANGELOG.

Since version 1.0.0 of MultiTest the cw_multi_test::addons::MockAddressGenerator has been removed permanently and new convenient options for creating addresses were shipped with this version. All of them work the same way since version 1.0.0 of MultiTest and are described in this article in section Summary of address generation options in tests.

For your convenience, all these options are presented below as short test cases. Thanks for using MultiTest!

cosmwasm_std::testing::MockApi

#[test]
fn creating_address_with_default_prefix_should_work() {
    use cosmwasm_std::testing::MockApi;

    let addr = MockApi::default().addr_make("owner");
    assert_eq!(
        "cosmwasm1fsgzj6t7udv8zhf6zj32mkqhcjcpv52yph5qsdcl0qt94jgdckqs2g053y",
        addr.as_str()
    );
}
#[test]
fn creating_address_with_custom_prefix_should_work() {
    use cosmwasm_std::testing::MockApi;

    let addr = MockApi::default().with_prefix("juno").addr_make("owner");
    assert_eq!(
        "juno1fsgzj6t7udv8zhf6zj32mkqhcjcpv52yph5qsdcl0qt94jgdckqsmg2ndy",
        addr.as_str()
    );
}

cw_multi_test::MockApiBech32

#[test]
fn creating_address_with_prefix_should_work() {
    use cw_multi_test::MockApiBech32;

    let addr = MockApiBech32::new("cosmwasm").addr_make("owner");
    assert_eq!(
        "cosmwasm1fsgzj6t7udv8zhf6zj32mkqhcjcpv52yph5qsdcl0qt94jgdckqs2g053y",
        addr.as_str()
    );
}

cw_multi_test::MockApiBech32m

#[test]
fn creating_address_with_prefix_should_work() {
    use cw_multi_test::MockApiBech32m;

    let addr = MockApiBech32m::new("cosmwasm").addr_make("owner");
    assert_eq!(
        "cosmwasm1fsgzj6t7udv8zhf6zj32mkqhcjcpv52yph5qsdcl0qt94jgdckqsl5lc5x",
        addr.as_str()
    );
}

cw_multi_test::IntoAddr

#[test]
fn creating_address_with_default_prefix_should_work() {
    use cw_multi_test::IntoAddr;

    let addr = "owner".into_addr();
    assert_eq!(
        "cosmwasm1fsgzj6t7udv8zhf6zj32mkqhcjcpv52yph5qsdcl0qt94jgdckqs2g053y",
        addr.as_str()
    );
}
#[test]
fn creating_address_with_custom_prefix_should_work() {
    use cw_multi_test::IntoAddr;

    let addr = "owner".into_addr_with_prefix("juno");
    assert_eq!(
        "juno1fsgzj6t7udv8zhf6zj32mkqhcjcpv52yph5qsdcl0qt94jgdckqsmg2ndy",
        addr.as_str()
    );
}

cw_multi_test::IntoBech32

#[test]
fn creating_address_with_default_prefix_should_work() {
    use cw_multi_test::IntoBech32;

    let addr = "owner".into_bech32();
    assert_eq!(
        "cosmwasm1fsgzj6t7udv8zhf6zj32mkqhcjcpv52yph5qsdcl0qt94jgdckqs2g053y",
        addr.as_str()
    );
}
#[test]
fn creating_address_with_custom_prefix_should_work() {
    use cw_multi_test::IntoBech32;

    let addr = "owner".into_bech32_with_prefix("juno");
    assert_eq!(
        "juno1fsgzj6t7udv8zhf6zj32mkqhcjcpv52yph5qsdcl0qt94jgdckqsmg2ndy",
        addr.as_str()
    );
}

cw_multi_test::IntoBech32m

#[test]
fn creating_address_with_default_prefix_should_work() {
    use cw_multi_test::IntoBech32m;

    let addr = "owner".into_bech32m();
    assert_eq!(
        "cosmwasm1fsgzj6t7udv8zhf6zj32mkqhcjcpv52yph5qsdcl0qt94jgdckqsl5lc5x",
        addr.as_str()
    );
}
#[test]
fn creating_address_with_custom_prefix_should_work() {
    use cw_multi_test::IntoBech32m;

    let addr = "owner".into_bech32m_with_prefix("juno");
    assert_eq!(
        "juno1fsgzj6t7udv8zhf6zj32mkqhcjcpv52yph5qsdcl0qt94jgdckqsw56lgx",
        addr.as_str()
    );
}

cw_multi_test::App

#[test]
fn creating_address_with_default_prefix_should_work() {
    use cw_multi_test::App;

    let app = App::default();

    let addr = app.api().addr_make("owner");
    assert_eq!(
        "cosmwasm1fsgzj6t7udv8zhf6zj32mkqhcjcpv52yph5qsdcl0qt94jgdckqs2g053y",
        addr.as_str()
    );
}
#[test]
fn creating_bech32_address_with_custom_prefix_should_work() {
    use cw_multi_test::{no_init, AppBuilder, MockApiBech32};

    let app = AppBuilder::default()
        .with_api(MockApiBech32::new("juno"))
        .build(no_init);

    let addr = app.api().addr_make("owner");
    assert_eq!(
        "juno1fsgzj6t7udv8zhf6zj32mkqhcjcpv52yph5qsdcl0qt94jgdckqsmg2ndy",
        addr.as_str()
    );
}
#[test]
fn creating_bech32m_address_with_custom_prefix_should_work() {
    use cw_multi_test::{no_init, AppBuilder, MockApiBech32m};

    let app = AppBuilder::default()
        .with_api(MockApiBech32m::new("juno"))
        .build(no_init);

    let addr = app.api().addr_make("owner");
    assert_eq!(
        "juno1fsgzj6t7udv8zhf6zj32mkqhcjcpv52yph5qsdcl0qt94jgdckqsw56lgx",
        addr.as_str()
    );
}
DariuszDepta commented 2 weeks ago

I hope this helps.