Skip to content

Commit

Permalink
Merge pull request #380 from CosmWasm/348-multitest-events-match-wasmd
Browse files Browse the repository at this point in the history
Multitest events match wasmd
  • Loading branch information
ethanfrey authored Aug 9, 2021
2 parents e08a68e + 5ed25f3 commit 7798e97
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 106 deletions.
10 changes: 7 additions & 3 deletions contracts/cw20-escrow/src/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,16 @@ fn escrow_happy_path_cw20_tokens() {
let res = router
.execute_contract(owner.clone(), cash_addr.clone(), &send_msg, &[])
.unwrap();
assert_eq!(2, res.events.len());
assert_eq!(4, res.events.len());
println!("{:?}", res.events);
let cw20_attr = res.custom_attrs(0);

assert_eq!(res.events[0].ty.as_str(), "execute");
let cw20_attr = res.custom_attrs(1);
println!("{:?}", cw20_attr);
assert_eq!(4, cw20_attr.len());
let escrow_attr = res.custom_attrs(1);

assert_eq!(res.events[2].ty.as_str(), "execute");
let escrow_attr = res.custom_attrs(3);
println!("{:?}", escrow_attr);
assert_eq!(2, escrow_attr.len());

Expand Down
42 changes: 21 additions & 21 deletions contracts/cw3-flex-multisig/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ mod tests {
.execute_contract(Addr::unchecked(VOTER3), flex_addr.clone(), &proposal, &[])
.unwrap();
assert_eq!(
res.custom_attrs(0),
res.custom_attrs(1),
[
("action", "propose"),
("sender", VOTER3),
Expand All @@ -745,7 +745,7 @@ mod tests {
.execute_contract(Addr::unchecked(VOTER4), flex_addr, &proposal, &[])
.unwrap();
assert_eq!(
res.custom_attrs(0),
res.custom_attrs(1),
[
("action", "propose"),
("sender", VOTER4),
Expand Down Expand Up @@ -812,15 +812,15 @@ mod tests {
let res = app
.execute_contract(Addr::unchecked(VOTER1), flex_addr.clone(), &proposal, &[])
.unwrap();
let proposal_id1: u64 = res.custom_attrs(0)[2].value.parse().unwrap();
let proposal_id1: u64 = res.custom_attrs(1)[2].value.parse().unwrap();

// another proposal immediately passes
app.update_block(next_block);
let proposal = pay_somebody_proposal();
let res = app
.execute_contract(Addr::unchecked(VOTER3), flex_addr.clone(), &proposal, &[])
.unwrap();
let proposal_id2: u64 = res.custom_attrs(0)[2].value.parse().unwrap();
let proposal_id2: u64 = res.custom_attrs(1)[2].value.parse().unwrap();

// expire them both
app.update_block(expire(voting_period));
Expand All @@ -830,7 +830,7 @@ mod tests {
let res = app
.execute_contract(Addr::unchecked(VOTER2), flex_addr.clone(), &proposal, &[])
.unwrap();
let proposal_id3: u64 = res.custom_attrs(0)[2].value.parse().unwrap();
let proposal_id3: u64 = res.custom_attrs(1)[2].value.parse().unwrap();
let proposed_at = app.block_info();

// next block, let's query them all... make sure status is properly updated (1 should be rejected in query)
Expand Down Expand Up @@ -910,7 +910,7 @@ mod tests {
.unwrap();

// Get the proposal id from the logs
let proposal_id: u64 = res.custom_attrs(0)[2].value.parse().unwrap();
let proposal_id: u64 = res.custom_attrs(1)[2].value.parse().unwrap();

// Owner cannot vote (again)
let yes_vote = ExecuteMsg::Vote {
Expand All @@ -933,7 +933,7 @@ mod tests {
.execute_contract(Addr::unchecked(VOTER1), flex_addr.clone(), &yes_vote, &[])
.unwrap();
assert_eq!(
res.custom_attrs(0),
res.custom_attrs(1),
[
("action", "vote"),
("sender", VOTER1),
Expand Down Expand Up @@ -986,7 +986,7 @@ mod tests {
.execute_contract(Addr::unchecked(VOTER4), flex_addr.clone(), &yes_vote, &[])
.unwrap();
assert_eq!(
res.custom_attrs(0),
res.custom_attrs(1),
[
("action", "vote"),
("sender", VOTER4),
Expand Down Expand Up @@ -1066,7 +1066,7 @@ mod tests {
.unwrap();

// Get the proposal id from the logs
let proposal_id: u64 = res.custom_attrs(0)[2].value.parse().unwrap();
let proposal_id: u64 = res.custom_attrs(1)[2].value.parse().unwrap();

// Only Passed can be executed
let execution = ExecuteMsg::Execute { proposal_id };
Expand All @@ -1084,7 +1084,7 @@ mod tests {
.execute_contract(Addr::unchecked(VOTER3), flex_addr.clone(), &vote, &[])
.unwrap();
assert_eq!(
res.custom_attrs(0),
res.custom_attrs(1),
[
("action", "vote"),
("sender", VOTER3),
Expand All @@ -1110,7 +1110,7 @@ mod tests {
)
.unwrap();
assert_eq!(
res.custom_attrs(0),
res.custom_attrs(1),
[
("action", "execute"),
("sender", SOMEBODY),
Expand Down Expand Up @@ -1152,7 +1152,7 @@ mod tests {
.unwrap();

// Get the proposal id from the logs
let proposal_id: u64 = res.custom_attrs(0)[2].value.parse().unwrap();
let proposal_id: u64 = res.custom_attrs(1)[2].value.parse().unwrap();

// Non-expired proposals cannot be closed
let closing = ExecuteMsg::Close { proposal_id };
Expand All @@ -1167,7 +1167,7 @@ mod tests {
.execute_contract(Addr::unchecked(SOMEBODY), flex_addr.clone(), &closing, &[])
.unwrap();
assert_eq!(
res.custom_attrs(0),
res.custom_attrs(1),
[
("action", "close"),
("sender", SOMEBODY),
Expand Down Expand Up @@ -1204,7 +1204,7 @@ mod tests {
.execute_contract(Addr::unchecked(VOTER1), flex_addr.clone(), &proposal, &[])
.unwrap();
// Get the proposal id from the logs
let proposal_id: u64 = res.custom_attrs(0)[2].value.parse().unwrap();
let proposal_id: u64 = res.custom_attrs(1)[2].value.parse().unwrap();
let prop_status = |app: &App, proposal_id: u64| -> Status {
let query_prop = QueryMsg::Proposal { proposal_id };
let prop: ProposalResponse = app
Expand Down Expand Up @@ -1265,7 +1265,7 @@ mod tests {
.execute_contract(Addr::unchecked(VOTER1), flex_addr.clone(), &proposal2, &[])
.unwrap();
// Get the proposal id from the logs
let proposal_id2: u64 = res.custom_attrs(0)[2].value.parse().unwrap();
let proposal_id2: u64 = res.custom_attrs(1)[2].value.parse().unwrap();

// VOTER2 can pass this alone with the updated vote (newer height ignores snapshot)
let yes_vote = ExecuteMsg::Vote {
Expand Down Expand Up @@ -1346,7 +1346,7 @@ mod tests {
)
.unwrap();
// Get the proposal id from the logs
let update_proposal_id: u64 = res.custom_attrs(0)[2].value.parse().unwrap();
let update_proposal_id: u64 = res.custom_attrs(1)[2].value.parse().unwrap();

// next block...
app.update_block(|b| b.height += 1);
Expand All @@ -1362,7 +1362,7 @@ mod tests {
)
.unwrap();
// Get the proposal id from the logs
let cash_proposal_id: u64 = res.custom_attrs(0)[2].value.parse().unwrap();
let cash_proposal_id: u64 = res.custom_attrs(1)[2].value.parse().unwrap();
assert_ne!(cash_proposal_id, update_proposal_id);

// query proposal state
Expand Down Expand Up @@ -1455,7 +1455,7 @@ mod tests {
.execute_contract(Addr::unchecked(VOTER3), flex_addr.clone(), &proposal, &[])
.unwrap();
// Get the proposal id from the logs
let proposal_id: u64 = res.custom_attrs(0)[2].value.parse().unwrap();
let proposal_id: u64 = res.custom_attrs(1)[2].value.parse().unwrap();
let prop_status = |app: &App| -> Status {
let query_prop = QueryMsg::Proposal { proposal_id };
let prop: ProposalResponse = app
Expand Down Expand Up @@ -1499,7 +1499,7 @@ mod tests {
.execute_contract(Addr::unchecked(newbie), flex_addr.clone(), &proposal, &[])
.unwrap();
// Get the proposal id from the logs
let proposal_id2: u64 = res.custom_attrs(0)[2].value.parse().unwrap();
let proposal_id2: u64 = res.custom_attrs(1)[2].value.parse().unwrap();

// check proposal2 status
let query_prop = QueryMsg::Proposal {
Expand Down Expand Up @@ -1537,7 +1537,7 @@ mod tests {
.execute_contract(Addr::unchecked(VOTER3), flex_addr.clone(), &proposal, &[])
.unwrap();
// Get the proposal id from the logs
let proposal_id: u64 = res.custom_attrs(0)[2].value.parse().unwrap();
let proposal_id: u64 = res.custom_attrs(1)[2].value.parse().unwrap();
let prop_status = |app: &App| -> Status {
let query_prop = QueryMsg::Proposal { proposal_id };
let prop: ProposalResponse = app
Expand Down Expand Up @@ -1606,7 +1606,7 @@ mod tests {
.execute_contract(Addr::unchecked(VOTER5), flex_addr.clone(), &proposal, &[])
.unwrap();
// Get the proposal id from the logs
let proposal_id: u64 = res.custom_attrs(0)[2].value.parse().unwrap();
let proposal_id: u64 = res.custom_attrs(1)[2].value.parse().unwrap();
let prop_status = |app: &App| -> Status {
let query_prop = QueryMsg::Proposal { proposal_id };
let prop: ProposalResponse = app
Expand Down
11 changes: 11 additions & 0 deletions packages/multi-test/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
# Multi Test: Test helpers for multi-contract interactions

Warning: **Alpha Software** Designed for internal use only.

This is used for testing cosmwasm-plus contracts, we have no API
stability currently. We are working on refactoring it and will
expose a more refined version for use in other contracts. (Ideally
in cosmwasm-plus 0.9 or 0.10).

**Use at your own risk**

Let us run unit tests with contracts calling contracts, and calling
in and out of bank.

This only works with contracts and bank currently. We are working
on refactoring to make it more extensible for more handlers,
including custom messages/queries as well as IBC.


Loading

0 comments on commit 7798e97

Please sign in to comment.