From 9a09790ed445bf60990906a793e261eb427a0227 Mon Sep 17 00:00:00 2001 From: girazoki Date: Fri, 18 Aug 2023 16:34:33 +0200 Subject: [PATCH 1/4] AccountId based on runtime --- .../emulated/common/src/lib.rs | 2 +- xcm/xcm-emulator/src/lib.rs | 52 ++++++++++--------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/parachains/integration-tests/emulated/common/src/lib.rs b/parachains/integration-tests/emulated/common/src/lib.rs index 55cfdb10901..0177878e12e 100644 --- a/parachains/integration-tests/emulated/common/src/lib.rs +++ b/parachains/integration-tests/emulated/common/src/lib.rs @@ -22,7 +22,7 @@ use xcm_emulator::{ assert_expected_events, bx, decl_test_bridges, decl_test_networks, decl_test_parachains, decl_test_relay_chains, decl_test_sender_receiver_accounts_parameter_types, helpers::weight_within_threshold, BridgeMessageHandler, Chain, DefaultMessageProcessor, ParaId, - Parachain, RelayChain, TestExt, + Parachain, RelayChain, TestExt, RuntimeAccountId }; pub use xcm::{ diff --git a/xcm/xcm-emulator/src/lib.rs b/xcm/xcm-emulator/src/lib.rs index a82b51948bc..5651dfccf56 100644 --- a/xcm/xcm-emulator/src/lib.rs +++ b/xcm/xcm-emulator/src/lib.rs @@ -76,6 +76,8 @@ pub use xcm::{ }; pub use xcm_executor::traits::ConvertLocation; +pub type RuntimeAccountId = ::AccountId; + thread_local! { /// Downward messages, each message is: `(to_para_id, [(relay_block_number, msg)])` #[allow(clippy::type_complexity)] @@ -103,8 +105,8 @@ pub trait CheckAssertion where Origin: Chain + Clone, Destination: Chain + Clone, - Origin::RuntimeOrigin: OriginTrait + Clone, - Destination::RuntimeOrigin: OriginTrait + Clone, + Origin::RuntimeOrigin: OriginTrait> + Clone, + Destination::RuntimeOrigin: OriginTrait> + Clone, Hops: Clone, Args: Clone, { @@ -116,8 +118,8 @@ impl CheckAssertion + Clone, - Destination::RuntimeOrigin: OriginTrait + Clone, + Origin::RuntimeOrigin: OriginTrait> + Clone, + Destination::RuntimeOrigin: OriginTrait> + Clone, Hops: Clone, Args: Clone, { @@ -227,28 +229,28 @@ pub trait Chain: TestExt + NetworkComponent { type RuntimeEvent; type System; - fn account_id_of(seed: &str) -> AccountId { + fn account_id_of(seed: &str) -> AccountId { helpers::get_account_id_from_seed::(seed) } - fn account_data_of(account: AccountId) -> AccountData; + fn account_data_of(account: RuntimeAccountId) -> AccountData; fn events() -> Vec<::RuntimeEvent>; } pub trait RelayChain: Chain { type MessageProcessor: ProcessMessage; - type SovereignAccountOf: ConvertLocation; + type SovereignAccountOf: ConvertLocation>; fn child_location_of(id: ParaId) -> MultiLocation { (Ancestor(0), ParachainJunction(id.into())).into() } - fn sovereign_account_id_of(location: MultiLocation) -> AccountId { + fn sovereign_account_id_of(location: MultiLocation) -> RuntimeAccountId { Self::SovereignAccountOf::convert_location(&location).unwrap() } - fn sovereign_account_id_of_child_para(id: ParaId) -> AccountId { + fn sovereign_account_id_of_child_para(id: ParaId) -> RuntimeAccountId { Self::sovereign_account_id_of(Self::child_location_of(id)) } } @@ -256,7 +258,7 @@ pub trait RelayChain: Chain { pub trait Parachain: Chain { type XcmpMessageHandler: XcmpMessageHandler; type DmpMessageHandler: DmpMessageHandler; - type LocationToAccountId: ConvertLocation; + type LocationToAccountId: ConvertLocation>; type ParachainInfo: Get; type ParachainSystem; @@ -272,7 +274,7 @@ pub trait Parachain: Chain { (Parent, X1(ParachainJunction(para_id.into()))).into() } - fn sovereign_account_id_of(location: MultiLocation) -> AccountId { + fn sovereign_account_id_of(location: MultiLocation) -> RuntimeAccountId { Self::LocationToAccountId::convert_location(&location).unwrap() } @@ -1125,9 +1127,9 @@ macro_rules! __impl_check_assertion { where Origin: Chain + Clone, Destination: Chain + Clone, - Origin::RuntimeOrigin: $crate::OriginTrait + Clone, + Origin::RuntimeOrigin: $crate::OriginTrait> + Clone, Destination::RuntimeOrigin: - $crate::OriginTrait + Clone, + $crate::OriginTrait> + Clone, Hops: Clone, Args: Clone, { @@ -1272,8 +1274,8 @@ where /// Struct that keeps account's id and balance #[derive(Clone)] -pub struct TestAccount { - pub account_id: AccountId, +pub struct TestAccount { + pub account_id: RuntimeAccountId, pub balance: Balance, } @@ -1290,9 +1292,9 @@ pub struct TestArgs { } /// Auxiliar struct to help creating a new `Test` instance -pub struct TestContext { - pub sender: AccountId, - pub receiver: AccountId, +pub struct TestContext { + pub sender: RuntimeAccountId, + pub receiver: RuntimeAccountId, pub args: T, } @@ -1309,12 +1311,12 @@ pub struct Test where Origin: Chain + Clone, Destination: Chain + Clone, - Origin::RuntimeOrigin: OriginTrait + Clone, - Destination::RuntimeOrigin: OriginTrait + Clone, + Origin::RuntimeOrigin: OriginTrait> + Clone, + Destination::RuntimeOrigin: OriginTrait> + Clone, Hops: Clone, { - pub sender: TestAccount, - pub receiver: TestAccount, + pub sender: TestAccount, + pub receiver: TestAccount, pub signed_origin: Origin::RuntimeOrigin, pub root_origin: Origin::RuntimeOrigin, pub hops_assertion: HashMap, @@ -1329,12 +1331,12 @@ where Args: Clone, Origin: Chain + Clone + CheckAssertion, Destination: Chain + Clone + CheckAssertion, - Origin::RuntimeOrigin: OriginTrait + Clone, - Destination::RuntimeOrigin: OriginTrait + Clone, + Origin::RuntimeOrigin: OriginTrait> + Clone, + Destination::RuntimeOrigin: OriginTrait> + Clone, Hops: Clone + CheckAssertion, { /// Creates a new `Test` instance - pub fn new(test_args: TestContext) -> Self { + pub fn new(test_args: TestContext) -> Self { Test { sender: TestAccount { account_id: test_args.sender.clone(), From 7122b38c720c32fcd90484a3ed8723f21d32c3bf Mon Sep 17 00:00:00 2001 From: girazoki Date: Fri, 18 Aug 2023 18:21:36 +0200 Subject: [PATCH 2/4] wip --- xcm/xcm-emulator/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xcm/xcm-emulator/src/lib.rs b/xcm/xcm-emulator/src/lib.rs index 5651dfccf56..1e412b2a270 100644 --- a/xcm/xcm-emulator/src/lib.rs +++ b/xcm/xcm-emulator/src/lib.rs @@ -372,7 +372,7 @@ macro_rules! decl_test_relay_chains { type RuntimeEvent = $runtime::RuntimeEvent; type System = $crate::SystemPallet::; - fn account_data_of(account: AccountId) -> $crate::AccountData { + fn account_data_of(account: RuntimeAccountId>) -> $crate::AccountData { Self::ext_wrapper(|| $crate::SystemPallet::::account(account).data.into()) } @@ -596,7 +596,7 @@ macro_rules! decl_test_parachains { type RuntimeEvent = $runtime::RuntimeEvent; type System = $crate::SystemPallet::; - fn account_data_of(account: AccountId) -> $crate::AccountData { + fn account_data_of(account: RuntimeAccountId) -> $crate::AccountData { Self::ext_wrapper(|| $crate::SystemPallet::::account(account).data.into()) } From 0f75d040f9d18e8eecde2b39803cf088021daa36 Mon Sep 17 00:00:00 2001 From: girazoki Date: Fri, 18 Aug 2023 18:41:13 +0200 Subject: [PATCH 3/4] fix --- xcm/xcm-emulator/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xcm/xcm-emulator/src/lib.rs b/xcm/xcm-emulator/src/lib.rs index 1e412b2a270..89009bf2270 100644 --- a/xcm/xcm-emulator/src/lib.rs +++ b/xcm/xcm-emulator/src/lib.rs @@ -233,7 +233,7 @@ pub trait Chain: TestExt + NetworkComponent { helpers::get_account_id_from_seed::(seed) } - fn account_data_of(account: RuntimeAccountId) -> AccountData; + fn account_data_of(account: RuntimeAccountId) -> AccountData; fn events() -> Vec<::RuntimeEvent>; } @@ -372,7 +372,7 @@ macro_rules! decl_test_relay_chains { type RuntimeEvent = $runtime::RuntimeEvent; type System = $crate::SystemPallet::; - fn account_data_of(account: RuntimeAccountId>) -> $crate::AccountData { + fn account_data_of(account: RuntimeAccountId) -> $crate::AccountData { Self::ext_wrapper(|| $crate::SystemPallet::::account(account).data.into()) } From cc4fe2f15752191ca60d77e95a2c20dde8f6a926 Mon Sep 17 00:00:00 2001 From: girazoki Date: Mon, 21 Aug 2023 09:36:43 +0200 Subject: [PATCH 4/4] fmt --- parachains/integration-tests/emulated/common/src/lib.rs | 2 +- xcm/xcm-emulator/src/lib.rs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/parachains/integration-tests/emulated/common/src/lib.rs b/parachains/integration-tests/emulated/common/src/lib.rs index 0177878e12e..5eb58faf263 100644 --- a/parachains/integration-tests/emulated/common/src/lib.rs +++ b/parachains/integration-tests/emulated/common/src/lib.rs @@ -22,7 +22,7 @@ use xcm_emulator::{ assert_expected_events, bx, decl_test_bridges, decl_test_networks, decl_test_parachains, decl_test_relay_chains, decl_test_sender_receiver_accounts_parameter_types, helpers::weight_within_threshold, BridgeMessageHandler, Chain, DefaultMessageProcessor, ParaId, - Parachain, RelayChain, TestExt, RuntimeAccountId + Parachain, RelayChain, RuntimeAccountId, TestExt, }; pub use xcm::{ diff --git a/xcm/xcm-emulator/src/lib.rs b/xcm/xcm-emulator/src/lib.rs index 89009bf2270..65ba89ea9b4 100644 --- a/xcm/xcm-emulator/src/lib.rs +++ b/xcm/xcm-emulator/src/lib.rs @@ -229,7 +229,7 @@ pub trait Chain: TestExt + NetworkComponent { type RuntimeEvent; type System; - fn account_id_of(seed: &str) -> AccountId { + fn account_id_of(seed: &str) -> AccountId { helpers::get_account_id_from_seed::(seed) } @@ -1127,7 +1127,8 @@ macro_rules! __impl_check_assertion { where Origin: Chain + Clone, Destination: Chain + Clone, - Origin::RuntimeOrigin: $crate::OriginTrait> + Clone, + Origin::RuntimeOrigin: + $crate::OriginTrait> + Clone, Destination::RuntimeOrigin: $crate::OriginTrait> + Clone, Hops: Clone,