Open maxmousse opened 2 months ago
try this
#[test]
fn instantiation() {
let mut app = App::default();
let code = ContractWrapper::new(execute, instantiate, query);
let code_id = app.store_code(Box::new(code));
let addr = app
.instantiate_contract(
code_id,
Addr::unchecked("owner"),
&InstantiateMsg { admins: vec![] },
&[],
"Contract",
None,
)
.unwrap();
let resp: AdminsListResp = app
.wrap()
.query_wasm_smart(addr, &QueryMsg::AdminsList {})
.unwrap();
assert_eq!(resp, AdminsListResp { admins: vec![] });
let admin1 = app.api().addr_make("admin1").to_string();
let admin2 = app.api().addr_make("admin2").to_string();
let addr = app
.instantiate_contract(
code_id,
Addr::unchecked("owner"),
&(InstantiateMsg {
admins: vec![admin1.clone(), admin2.clone()],
}),
&[],
"Contract 2",
None,
)
.unwrap();
let resp: AdminsListResp = app
.wrap()
.query_wasm_smart(addr, &QueryMsg::AdminsList {})
.unwrap();
assert_eq!(
resp,
AdminsListResp {
admins: vec![Addr::unchecked(admin1), Addr::unchecked(admin2)],
}
);
}
Hey @asher-gh, thank your for your response!
I am a little bit confused to be honest:
app.api().addr_make("admin1").to_string()
to create the addresses right ?If you have an explanation, I'd be very interested to understand what goes wrong with my code sample.
Anyway I'll keep using the app.api().addr_make("admin1")
as it seems to fix the problem. Thanks a lot for your help!
Yeah, I stumbled upon the same thing. It seems like it has something to do with bech32 address encoding in cw_multi_test.
I found the usage of addr_make
in the cw-plus examples and they have this in their tests.
All right I'll have a look at those examples. I also opened an issue in the cw_multi_test repository, if anyone is interested: https://github.com/CosmWasm/cw-multi-test/issues/169
Tell me when there is a consensus about how it should be done, I can submit a PR to update the book examples =)
Hi everyone,
First, thanks a lot for writing/maintaining this book. This is an awesome learning resource!
While following the book, I found an error when running unit tests. The following block of code
leads to the next error:
From what I understand, it seems to come from cw_multi_test. They currently have an issue opened that seems to relate to the problem: https://github.com/CosmWasm/cw-multi-test/issues/165
Here is a repository containing the bug: https://github.com/maxmousse/cosmwasm-test/tree/cosmwasm-tuto. Just run
cargo test
and the error should show.I'd be happy to submit a pull request when there is a consensus about how to fix this =)