Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

update origins test + add execution check function #43

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions examples/src/4_origins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@ mod tests {
use xcm::latest::prelude::*;
use xcm_simulator::TestExt;

const AMOUNT: u128 = 10;
const QUERY_ID: u64 = 1234;

/// Scenario:
#[test]
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,
Copy link
Collaborator

@franciscoaguirre franciscoaguirre Aug 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use Limited instead with estimate_weight

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do it, but then I propose we do it in a separate pr for all examples

},
// 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 {
Expand All @@ -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![]));
Expand Down
37 changes: 25 additions & 12 deletions examples/src/simple_test_net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,21 @@ pub fn para_ext(para_id: u32) -> sp_io::TestExternalities {
};

pallet_balances::GenesisConfig::<Runtime> {
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
|&para_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
|&para_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
|&para_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
|&para_id| (sibling_sovereign_account_id(para_id), INITIAL_BALANCE),
))
.collect(),
}
.assimilate_storage(&mut t)
.unwrap();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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<relay_chain::Runtime>;
pub type ParachainPalletXcm = pallet_xcm::Pallet<parachain::Runtime>;
pub type RelaychainBalances = pallet_balances::Pallet<relay_chain::Runtime>;
Expand Down