diff --git a/examples/src/4_origins/mod.rs b/examples/src/4_origins/mod.rs index 97a775f..31e0e48 100644 --- a/examples/src/4_origins/mod.rs +++ b/examples/src/4_origins/mod.rs @@ -5,7 +5,6 @@ mod tests { use xcm::latest::prelude::*; use xcm_simulator::TestExt; - const AMOUNT: u128 = 10; const QUERY_ID: u64 = 1234; /// Scenario: @@ -13,9 +12,13 @@ mod tests { fn descend_origin() { MockNet::reset(); ParaA::execute_with(|| { + let message_fee = parachain::estimate_message_fee(6); let message = Xcm(vec![ - WithdrawAsset((Here, AMOUNT).into()), - BuyExecution { fees: (Here, AMOUNT).into(), weight_limit: WeightLimit::Unlimited }, + WithdrawAsset((Here, message_fee).into()), + BuyExecution { + fees: (Here, message_fee).into(), + weight_limit: WeightLimit::Unlimited, + }, // Set the instructions that are executed when ExpectOrigin does not pass. // In this case, reporting back an error to the Parachain. SetErrorHandler(Xcm(vec![ReportError(QueryResponseInfo { @@ -30,6 +33,10 @@ mod tests { assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent, message.clone(),)); }); + Relay::execute_with(|| { + assert!(relay_successful_execution()); + }); + // Check that message queue is empty. // The ExpectOrigin instruction passed so we should not receive an error response. ParaA::execute_with(|| assert_eq!(parachain::MsgQueue::received_dmp(), vec![])); diff --git a/examples/src/simple_test_net/mod.rs b/examples/src/simple_test_net/mod.rs index 917f21a..87539a1 100644 --- a/examples/src/simple_test_net/mod.rs +++ b/examples/src/simple_test_net/mod.rs @@ -138,17 +138,21 @@ pub fn para_ext(para_id: u32) -> sp_io::TestExternalities { }; pallet_balances::GenesisConfig:: { - balances: vec![(ALICE, INITIAL_BALANCE), (relay_sovereign_account_id(), INITIAL_BALANCE), (BOB, INITIAL_BALANCE)] - .into_iter() - .chain(other_para_ids.iter().map( - // Initial balance of native token for ALICE on all sibling sovereign accounts - |¶_id| (sibling_account_sovereign_account_id(para_id, ALICE), INITIAL_BALANCE), - )) - .chain(other_para_ids.iter().map( - // Initial balance of native token all sibling sovereign accounts - |¶_id| (sibling_sovereign_account_id(para_id), INITIAL_BALANCE), - )) - .collect(), + balances: vec![ + (ALICE, INITIAL_BALANCE), + (relay_sovereign_account_id(), INITIAL_BALANCE), + (BOB, INITIAL_BALANCE), + ] + .into_iter() + .chain(other_para_ids.iter().map( + // Initial balance of native token for ALICE on all sibling sovereign accounts + |¶_id| (sibling_account_sovereign_account_id(para_id, ALICE), INITIAL_BALANCE), + )) + .chain(other_para_ids.iter().map( + // Initial balance of native token all sibling sovereign accounts + |¶_id| (sibling_sovereign_account_id(para_id), INITIAL_BALANCE), + )) + .collect(), } .assimilate_storage(&mut t) .unwrap(); @@ -180,7 +184,6 @@ pub fn para_ext(para_id: u32) -> sp_io::TestExternalities { .assimilate_storage(&mut t) .unwrap(); - let mut ext = sp_io::TestExternalities::new(t); ext.execute_with(|| { sp_tracing::try_init_simple(); @@ -226,6 +229,16 @@ pub fn print_relay_events() { System::events().iter().for_each(|r| println!(">>> {:?}", r.event)); } +pub fn relay_successful_execution() -> bool { + use relay_chain::System; + System::events().iter().any(|e| match &e.event { + relay_chain::RuntimeEvent::ParasUmp( + polkadot_runtime_parachains::ump::Event::ExecutedUpward(_, outcome), + ) => outcome.clone().ensure_complete().is_ok(), + _ => false, + }) +} + pub type RelaychainPalletXcm = pallet_xcm::Pallet; pub type ParachainPalletXcm = pallet_xcm::Pallet; pub type RelaychainBalances = pallet_balances::Pallet;