From cc079517658ad95e042dfcdaa17fb654e8f36b18 Mon Sep 17 00:00:00 2001 From: Ignacio Palacios Date: Mon, 3 Jul 2023 12:49:18 +0200 Subject: [PATCH] Backport `xcm-emulator` fixes #2800 and #2711 (#2809) * Xcm Emulator: prepare XCMP on init (#2711) * std for pallet-glutton * fix xcm-emulator init * headers for it tests * Fix for `xcm-emulator` - Wrong Parachain processing message (#2800) * fix * forgot para_id * remove unreachable code * remove glutton dep --------- Co-authored-by: Muharem Ismailov --- .../emulated/assets/statemine/src/lib.rs | 16 ++++ .../assets/statemine/src/tests/mod.rs | 16 ++++ .../statemine/src/tests/reserve_transfer.rs | 16 ++++ .../assets/statemine/src/tests/teleport.rs | 16 ++++ .../assets/statemine/src/tests/transact.rs | 16 ++++ .../emulated/assets/statemint/src/lib.rs | 16 ++++ .../assets/statemint/src/tests/mod.rs | 16 ++++ .../statemint/src/tests/reserve_transfer.rs | 16 ++++ .../assets/statemint/src/tests/teleport.rs | 16 ++++ .../assets/statemint/src/tests/transact.rs | 16 ++++ .../src/tests/fellowship.rs | 77 +++++++++++++++++++ xcm/xcm-emulator/src/lib.rs | 12 ++- 12 files changed, 245 insertions(+), 4 deletions(-) create mode 100644 parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/fellowship.rs diff --git a/parachains/integration-tests/emulated/assets/statemine/src/lib.rs b/parachains/integration-tests/emulated/assets/statemine/src/lib.rs index 7616a871b84..b4b168c91f1 100644 --- a/parachains/integration-tests/emulated/assets/statemine/src/lib.rs +++ b/parachains/integration-tests/emulated/assets/statemine/src/lib.rs @@ -1,3 +1,19 @@ +// Copyright Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + pub use codec::Encode; pub use frame_support::{ assert_ok, instances::Instance1, pallet_prelude::Weight, traits::fungibles::Inspect, diff --git a/parachains/integration-tests/emulated/assets/statemine/src/tests/mod.rs b/parachains/integration-tests/emulated/assets/statemine/src/tests/mod.rs index 996f9fd0aae..44861d2a872 100644 --- a/parachains/integration-tests/emulated/assets/statemine/src/tests/mod.rs +++ b/parachains/integration-tests/emulated/assets/statemine/src/tests/mod.rs @@ -1,3 +1,19 @@ +// Copyright Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + mod reserve_transfer; mod teleport; mod transact; diff --git a/parachains/integration-tests/emulated/assets/statemine/src/tests/reserve_transfer.rs b/parachains/integration-tests/emulated/assets/statemine/src/tests/reserve_transfer.rs index 2139e0324b9..4cf360abac2 100644 --- a/parachains/integration-tests/emulated/assets/statemine/src/tests/reserve_transfer.rs +++ b/parachains/integration-tests/emulated/assets/statemine/src/tests/reserve_transfer.rs @@ -1,3 +1,19 @@ +// Copyright Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + use crate::*; #[test] diff --git a/parachains/integration-tests/emulated/assets/statemine/src/tests/teleport.rs b/parachains/integration-tests/emulated/assets/statemine/src/tests/teleport.rs index 389f1a365ea..1f061b128ec 100644 --- a/parachains/integration-tests/emulated/assets/statemine/src/tests/teleport.rs +++ b/parachains/integration-tests/emulated/assets/statemine/src/tests/teleport.rs @@ -1,3 +1,19 @@ +// Copyright Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + use crate::*; #[test] diff --git a/parachains/integration-tests/emulated/assets/statemine/src/tests/transact.rs b/parachains/integration-tests/emulated/assets/statemine/src/tests/transact.rs index 144c8cc9f21..43d41ca56b2 100644 --- a/parachains/integration-tests/emulated/assets/statemine/src/tests/transact.rs +++ b/parachains/integration-tests/emulated/assets/statemine/src/tests/transact.rs @@ -1,3 +1,19 @@ +// Copyright Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + use crate::*; #[test] diff --git a/parachains/integration-tests/emulated/assets/statemint/src/lib.rs b/parachains/integration-tests/emulated/assets/statemint/src/lib.rs index f7ca680a800..3caddf10faa 100644 --- a/parachains/integration-tests/emulated/assets/statemint/src/lib.rs +++ b/parachains/integration-tests/emulated/assets/statemint/src/lib.rs @@ -1,3 +1,19 @@ +// Copyright Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + pub use codec::Encode; pub use frame_support::{ assert_ok, instances::Instance1, pallet_prelude::Weight, traits::fungibles::Inspect, diff --git a/parachains/integration-tests/emulated/assets/statemint/src/tests/mod.rs b/parachains/integration-tests/emulated/assets/statemint/src/tests/mod.rs index 996f9fd0aae..44861d2a872 100644 --- a/parachains/integration-tests/emulated/assets/statemint/src/tests/mod.rs +++ b/parachains/integration-tests/emulated/assets/statemint/src/tests/mod.rs @@ -1,3 +1,19 @@ +// Copyright Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + mod reserve_transfer; mod teleport; mod transact; diff --git a/parachains/integration-tests/emulated/assets/statemint/src/tests/reserve_transfer.rs b/parachains/integration-tests/emulated/assets/statemint/src/tests/reserve_transfer.rs index 55d201c5608..ff8867f8648 100644 --- a/parachains/integration-tests/emulated/assets/statemint/src/tests/reserve_transfer.rs +++ b/parachains/integration-tests/emulated/assets/statemint/src/tests/reserve_transfer.rs @@ -1,3 +1,19 @@ +// Copyright Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + use crate::*; #[test] diff --git a/parachains/integration-tests/emulated/assets/statemint/src/tests/teleport.rs b/parachains/integration-tests/emulated/assets/statemint/src/tests/teleport.rs index 163db77ddfd..4a4a6b0b0e5 100644 --- a/parachains/integration-tests/emulated/assets/statemint/src/tests/teleport.rs +++ b/parachains/integration-tests/emulated/assets/statemint/src/tests/teleport.rs @@ -1,3 +1,19 @@ +// Copyright Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + use crate::*; #[test] diff --git a/parachains/integration-tests/emulated/assets/statemint/src/tests/transact.rs b/parachains/integration-tests/emulated/assets/statemint/src/tests/transact.rs index 9220d914e47..9b712f3620c 100644 --- a/parachains/integration-tests/emulated/assets/statemint/src/tests/transact.rs +++ b/parachains/integration-tests/emulated/assets/statemint/src/tests/transact.rs @@ -1,3 +1,19 @@ +// Copyright Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + use crate::*; #[test] diff --git a/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/fellowship.rs b/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/fellowship.rs new file mode 100644 index 00000000000..233fd67083d --- /dev/null +++ b/parachains/integration-tests/emulated/collectives/collectives-polkadot/src/tests/fellowship.rs @@ -0,0 +1,77 @@ +// Copyright Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + +//! Integration tests concerning the Fellowship. + +use crate::*; +use collectives_polkadot_runtime::fellowship::FellowshipSalaryPaymaster; +use frame_support::traits::{ + fungibles::{Create, Mutate}, + tokens::Pay, +}; +use sp_core::crypto::Ss58Codec; +use xcm_emulator::TestExt; + +#[test] +fn pay_salary() { + let asset_id: u32 = 1984; + let pay_from: AccountId = + ::from_string("13w7NdvSR1Af8xsQTArDtZmVvjE8XhWNdL4yed3iFHrUNCnS") + .unwrap(); + let pay_to = Polkadot::account_id_of(ALICE); + let pay_amount = 9000; + + AssetHub::execute_with(|| { + type AssetHubAssets = ::Assets; + + assert_ok!(>::create( + asset_id, + pay_to.clone(), + true, + pay_amount / 2 + )); + assert_ok!(>::mint_into(asset_id, &pay_from, pay_amount * 2)); + }); + + Collectives::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_ok!(FellowshipSalaryPaymaster::pay(&pay_to, (), pay_amount)); + assert_expected_events!( + Collectives, + vec![ + RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. }) => {}, + ] + ); + }); + + AssetHub::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + + assert_expected_events!( + AssetHub, + vec![ + RuntimeEvent::Assets(pallet_assets::Event::Transferred { asset_id: id, from, to, amount }) => { + asset_id: id == &asset_id, + from: from == &pay_from, + to: to == &pay_to, + amount: amount == &pay_amount, + }, + RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::Success { .. }) => {}, + ] + ); + }); +} diff --git a/xcm/xcm-emulator/src/lib.rs b/xcm/xcm-emulator/src/lib.rs index a31d7c5b7e5..0ef731a10d7 100644 --- a/xcm/xcm-emulator/src/lib.rs +++ b/xcm/xcm-emulator/src/lib.rs @@ -739,6 +739,8 @@ macro_rules! decl_test_networks { $crate::HORIZONTAL_MESSAGES.with(|b| b.borrow_mut().insert(stringify!($name).to_string(), $crate::VecDeque::new())); $crate::RELAY_BLOCK_NUMBER.with(|b| b.borrow_mut().insert(stringify!($name).to_string(), 1)); $crate::PARA_IDS.with(|b| b.borrow_mut().insert(stringify!($name).to_string(), Self::_para_ids())); + + $( <$parachain>::prepare_for_xcmp(); )* } } @@ -777,7 +779,9 @@ macro_rules! decl_test_networks { while let Some((to_para_id, messages)) = $crate::DOWNWARD_MESSAGES.with(|b| b.borrow_mut().get_mut(stringify!($name)).unwrap().pop_front()) { $( - if $crate::PARA_IDS.with(|b| b.borrow_mut().get_mut(stringify!($name)).unwrap().contains(&to_para_id)) { + let para_id: u32 = <$parachain>::para_id().into(); + + if $crate::PARA_IDS.with(|b| b.borrow_mut().get_mut(stringify!($name)).unwrap().contains(&to_para_id)) && para_id == to_para_id { let mut msg_dedup: Vec<(RelayChainBlockNumber, Vec)> = Vec::new(); for m in &messages { msg_dedup.push((m.0, m.1.clone())); @@ -793,8 +797,6 @@ macro_rules! decl_test_networks { $crate::DMP_DONE.with(|b| b.borrow_mut().get_mut(stringify!($name)).unwrap().push_back((to_para_id, m.0, m.1))); } } - } else { - unreachable!(); } )* } @@ -807,7 +809,9 @@ macro_rules! decl_test_networks { = $crate::HORIZONTAL_MESSAGES.with(|b| b.borrow_mut().get_mut(stringify!($name)).unwrap().pop_front()) { let iter = messages.iter().map(|(p, b, m)| (*p, *b, &m[..])).collect::>().into_iter(); $( - if $crate::PARA_IDS.with(|b| b.borrow_mut().get_mut(stringify!($name)).unwrap().contains(&to_para_id)) { + let para_id: u32 = <$parachain>::para_id().into(); + + if $crate::PARA_IDS.with(|b| b.borrow_mut().get_mut(stringify!($name)).unwrap().contains(&to_para_id)) && para_id == to_para_id { <$parachain>::handle_xcmp_messages(iter.clone(), $crate::Weight::max_value()); } )*