From 8a30142c6f370302333e88714b814c31c7b2e9af Mon Sep 17 00:00:00 2001 From: CI system <> Date: Thu, 15 Jul 2021 11:36:21 +0100 Subject: [PATCH] more verbose asserts --- node/test/polkadot-simnet/common/src/lib.rs | 76 +++++++++++++-------- node/test/polkadot-simnet/test/src/main.rs | 15 +++- 2 files changed, 58 insertions(+), 33 deletions(-) diff --git a/node/test/polkadot-simnet/common/src/lib.rs b/node/test/polkadot-simnet/common/src/lib.rs index 2ac986ae7fd7..5527de0ba39d 100644 --- a/node/test/polkadot-simnet/common/src/lib.rs +++ b/node/test/polkadot-simnet/common/src/lib.rs @@ -99,10 +99,10 @@ pub async fn dispatch_with_root(call: impl Into< { type DemocracyCall = democracy::Call; - type CouncilCollectiveEvent = collective::Event::; + type CouncilCollectiveEvent = collective::Event; type CouncilCollectiveCall = collective::Call; type TechnicalCollectiveCall = collective::Call; - type TechnicalCollectiveEvent = collective::Event::; + type TechnicalCollectiveEvent = collective::Event; // here lies a black mirror esque copy of on chain whales. let whales = vec![ @@ -126,14 +126,15 @@ pub async fn dispatch_with_root(call: impl Into< Some(proposal_hash), + Event::Democracy(democracy::Event::PreimageNoted(ref proposal_hash, _, _)) + => Some(proposal_hash.clone()), _ => None }) .next() - .ok_or_else(|| "failed to note pre-image")? + .ok_or_else(|| format!("democracy::Event::PreimageNoted not found in events: {:#?}", events))? }; // submit external_propose call through council collective @@ -151,16 +152,17 @@ pub async fn dispatch_with_root(call: impl Into< Some((index, hash)), + Event::Council(CouncilCollectiveEvent::Proposed(_, index, ref hash, _)) => + Some((index, hash.clone())), _ => None } }) .next() - .ok_or_else(|| "failed to execute council::Call::propose(democracy::Call::external_propose_majority)")?; + .ok_or_else(|| format!("CouncilCollectiveEvent::Proposed not found in events: {:#?}", events))?; // vote for member in &council_collective[1..] { @@ -179,16 +181,20 @@ pub async fn dispatch_with_root(call: impl Into< true, + Event::Council(CouncilCollectiveEvent::Closed(_hash, _, _)) if hash == _hash => true, + Event::Council(CouncilCollectiveEvent::Approved(_hash, )) if hash == _hash => true, + Event::Council(CouncilCollectiveEvent::Executed(_hash, Ok(()))) if hash == _hash => true, _ => false, } }) .collect::>(); // make sure all 3 events are in state - assert_eq!(events.len(), 3); + assert_eq!( + events.len(), 3, + "CouncilCollectiveEvent::{{Closed, Approved, Executed}} not found in events: {:#?}", + node.events(), + ); } // next technical collective must fast track the proposal. @@ -205,16 +211,17 @@ pub async fn dispatch_with_root(call: impl Into< Some((index, hash)), + Event::TechnicalCommittee(TechnicalCollectiveEvent::Proposed(_, index, ref hash, _)) + => Some((index, hash.clone())), _ => None } }) .next() - .ok_or_else(|| "failed to execute council::Call::propose(democracy::Call::fast_track))")?; + .ok_or_else(|| format!("TechnicalCollectiveEvent::Proposed not found in events: {:#?}", events))?; // vote for member in &technical_collective[1..] { @@ -233,29 +240,34 @@ pub async fn dispatch_with_root(call: impl Into< true, + Event::TechnicalCommittee(TechnicalCollectiveEvent::Closed(_hash, _, _)) if hash == _hash => true, + Event::TechnicalCommittee(TechnicalCollectiveEvent::Approved(_hash)) if hash == _hash => true, + Event::TechnicalCommittee(TechnicalCollectiveEvent::Executed(_hash, Ok(()))) if hash == _hash => true, _ => false, } }) .collect::>(); // make sure all 3 events are in state - assert_eq!(events.len(), 3); + assert_eq!( + events.len(), 3, + "TechnicalCollectiveEvent::{{Closed, Approved, Executed}} not found in events: {:#?}", + node.events(), + ); } // now runtime upgrade proposal is a fast-tracked referendum we can vote for. - let referendum_index = node.events() + let ref_index = node.events() .into_iter() .filter_map(|event| match event.event { - Event::Democracy(democracy::Event::::Started(index, _)) => Some(index), + Event::Democracy(democracy::Event::Started(index, _)) => Some(index), _ => None, }) .next() - .ok_or_else(|| "failed to execute council::Call::close")?; + .ok_or_else(|| format!("democracy::Event::Started not found in events: {:#?}", node.events()))?; + let call = DemocracyCall::vote( - referendum_index, + ref_index, AccountVote::Standard { vote: Vote { aye: true, conviction: Conviction::Locked1x }, // 10 DOTS @@ -274,16 +286,20 @@ pub async fn dispatch_with_root(call: impl Into< true, + Event::Democracy(democracy::Event::Passed(_index)) if _index == ref_index => true, + Event::Democracy(democracy::Event::PreimageUsed(_hash, _, _)) if _hash == proposal_hash => true, + Event::Democracy(democracy::Event::Executed(_index, true)) if _index == ref_index => true, _ => false, } }) .collect::>(); // make sure all events were emitted - assert_eq!(events.len(), 3); + assert_eq!( + events.len(), 3, + "democracy::Event::{{Passed, PreimageUsed, Executed}} not found in events: {:#?}", + node.events(), + ); Ok(()) } diff --git a/node/test/polkadot-simnet/test/src/main.rs b/node/test/polkadot-simnet/test/src/main.rs index 3b57c40a6079..fccffc6b0e6b 100644 --- a/node/test/polkadot-simnet/test/src/main.rs +++ b/node/test/polkadot-simnet/test/src/main.rs @@ -48,13 +48,18 @@ fn main() -> Result<(), Box> { .collect::>(); // make sure event was emitted - assert_eq!(events.len(), 1); + assert_eq!(events.len(), 1, "system::Event::CodeUpdate not found in events: {:#?}", node.events()); let new_runtime_version = node.client() .executor() .runtime_version(&BlockId::Hash(node.client().info().best_hash))? .spec_version; // just confirming - assert!(new_runtime_version > old_runtime_version); + assert!( + new_runtime_version > old_runtime_version, + "Invariant, spec_version of new runtime: {} not greater than spec_version of old runtime: {}", + new_runtime_version, + old_runtime_version, + ); let (from, dest, balance) = ( AccountId32::from_str("15j4dg5GzsL1bw2U2AWgeyAk6QTxq43V7ZPbXdAmbVLjvDCK")?, @@ -76,7 +81,11 @@ fn main() -> Result<(), Box> { }) .collect::>(); // make sure transfer went through - assert_eq!(events.len(), 1); + assert_eq!( + events.len(), 1, + "balances::Call::transfer failed to execute, balances::Event::Transfer not found in events: {:#?}", + node.events() + ); // we're done, drop node. drop(node);