Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Flexibility in xcm-emulator methods #3037

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion parachains/integration-tests/emulated/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, RuntimeAccountId, TestExt,
};

pub use xcm::{
Expand Down
55 changes: 29 additions & 26 deletions xcm/xcm-emulator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ pub use xcm::{
};
pub use xcm_executor::traits::ConvertLocation;

pub type RuntimeAccountId<T> = <T as frame_system::Config>::AccountId;
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wondering if we could call it AccountIdOf?


thread_local! {
/// Downward messages, each message is: `(to_para_id, [(relay_block_number, msg)])`
#[allow(clippy::type_complexity)]
Expand Down Expand Up @@ -103,8 +105,8 @@ pub trait CheckAssertion<Origin, Destination, Hops, Args>
where
Origin: Chain + Clone,
Destination: Chain + Clone,
Origin::RuntimeOrigin: OriginTrait<AccountId = AccountId32> + Clone,
Destination::RuntimeOrigin: OriginTrait<AccountId = AccountId32> + Clone,
Origin::RuntimeOrigin: OriginTrait<AccountId = RuntimeAccountId<Origin::Runtime>> + Clone,
Destination::RuntimeOrigin: OriginTrait<AccountId = RuntimeAccountId<Origin::Runtime>> + Clone,
Hops: Clone,
Args: Clone,
{
Expand All @@ -116,8 +118,8 @@ impl<Origin, Destination, Hops, Args> CheckAssertion<Origin, Destination, Hops,
where
Origin: Chain + Clone,
Destination: Chain + Clone,
Origin::RuntimeOrigin: OriginTrait<AccountId = AccountId32> + Clone,
Destination::RuntimeOrigin: OriginTrait<AccountId = AccountId32> + Clone,
Origin::RuntimeOrigin: OriginTrait<AccountId = RuntimeAccountId<Origin::Runtime>> + Clone,
Destination::RuntimeOrigin: OriginTrait<AccountId = RuntimeAccountId<Origin::Runtime>> + Clone,
Hops: Clone,
Args: Clone,
{
Expand Down Expand Up @@ -231,32 +233,32 @@ pub trait Chain: TestExt + NetworkComponent {
helpers::get_account_id_from_seed::<sr25519::Public>(seed)
}

fn account_data_of(account: AccountId) -> AccountData<Balance>;
fn account_data_of(account: RuntimeAccountId<Self::Runtime>) -> AccountData<Balance>;

fn events() -> Vec<<Self as Chain>::RuntimeEvent>;
}

pub trait RelayChain: Chain {
type MessageProcessor: ProcessMessage;
type SovereignAccountOf: ConvertLocation<AccountId>;
type SovereignAccountOf: ConvertLocation<RuntimeAccountId<Self::Runtime>>;

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::Runtime> {
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::Runtime> {
Self::sovereign_account_id_of(Self::child_location_of(id))
}
}

pub trait Parachain: Chain {
type XcmpMessageHandler: XcmpMessageHandler;
type DmpMessageHandler: DmpMessageHandler;
type LocationToAccountId: ConvertLocation<AccountId>;
type LocationToAccountId: ConvertLocation<RuntimeAccountId<Self::Runtime>>;
type ParachainInfo: Get<ParaId>;
type ParachainSystem;

Expand All @@ -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::Runtime> {
Self::LocationToAccountId::convert_location(&location).unwrap()
}

Expand Down Expand Up @@ -370,7 +372,7 @@ macro_rules! decl_test_relay_chains {
type RuntimeEvent = $runtime::RuntimeEvent;
type System = $crate::SystemPallet::<Self::Runtime>;

fn account_data_of(account: AccountId) -> $crate::AccountData<Balance> {
fn account_data_of(account: RuntimeAccountId<Self::Runtime>) -> $crate::AccountData<Balance> {
Self::ext_wrapper(|| $crate::SystemPallet::<Self::Runtime>::account(account).data.into())
}

Expand Down Expand Up @@ -594,7 +596,7 @@ macro_rules! decl_test_parachains {
type RuntimeEvent = $runtime::RuntimeEvent;
type System = $crate::SystemPallet::<Self::Runtime>;

fn account_data_of(account: AccountId) -> $crate::AccountData<Balance> {
fn account_data_of(account: RuntimeAccountId<Self::Runtime>) -> $crate::AccountData<Balance> {
Self::ext_wrapper(|| $crate::SystemPallet::<Self::Runtime>::account(account).data.into())
}

Expand Down Expand Up @@ -1125,9 +1127,10 @@ macro_rules! __impl_check_assertion {
where
Origin: Chain + Clone,
Destination: Chain + Clone,
Origin::RuntimeOrigin: $crate::OriginTrait<AccountId = $crate::AccountId32> + Clone,
Origin::RuntimeOrigin:
$crate::OriginTrait<AccountId = RuntimeAccountId<Origin::Runtime>> + Clone,
Destination::RuntimeOrigin:
$crate::OriginTrait<AccountId = $crate::AccountId32> + Clone,
$crate::OriginTrait<AccountId = RuntimeAccountId<Origin::Runtime>> + Clone,
Hops: Clone,
Args: Clone,
{
Expand Down Expand Up @@ -1272,8 +1275,8 @@ where

/// Struct that keeps account's id and balance
#[derive(Clone)]
pub struct TestAccount {
pub account_id: AccountId,
pub struct TestAccount<R: Chain> {
pub account_id: RuntimeAccountId<R::Runtime>,
pub balance: Balance,
}

Expand All @@ -1290,9 +1293,9 @@ pub struct TestArgs {
}

/// Auxiliar struct to help creating a new `Test` instance
pub struct TestContext<T> {
pub sender: AccountId,
pub receiver: AccountId,
pub struct TestContext<T, R: Chain, D: Chain> {
pub sender: RuntimeAccountId<R::Runtime>,
pub receiver: RuntimeAccountId<D::Runtime>,
pub args: T,
}

Expand All @@ -1309,12 +1312,12 @@ pub struct Test<Origin, Destination, Hops = (), Args = TestArgs>
where
Origin: Chain + Clone,
Destination: Chain + Clone,
Origin::RuntimeOrigin: OriginTrait<AccountId = AccountId32> + Clone,
Destination::RuntimeOrigin: OriginTrait<AccountId = AccountId32> + Clone,
Origin::RuntimeOrigin: OriginTrait<AccountId = RuntimeAccountId<Origin::Runtime>> + Clone,
Destination::RuntimeOrigin: OriginTrait<AccountId = RuntimeAccountId<Origin::Runtime>> + Clone,
Hops: Clone,
{
pub sender: TestAccount,
pub receiver: TestAccount,
pub sender: TestAccount<Origin>,
pub receiver: TestAccount<Destination>,
pub signed_origin: Origin::RuntimeOrigin,
pub root_origin: Origin::RuntimeOrigin,
pub hops_assertion: HashMap<String, fn(Self)>,
Expand All @@ -1329,12 +1332,12 @@ where
Args: Clone,
Origin: Chain + Clone + CheckAssertion<Origin, Destination, Hops, Args>,
Destination: Chain + Clone + CheckAssertion<Origin, Destination, Hops, Args>,
Origin::RuntimeOrigin: OriginTrait<AccountId = AccountId32> + Clone,
Destination::RuntimeOrigin: OriginTrait<AccountId = AccountId32> + Clone,
Origin::RuntimeOrigin: OriginTrait<AccountId = RuntimeAccountId<Origin::Runtime>> + Clone,
Destination::RuntimeOrigin: OriginTrait<AccountId = RuntimeAccountId<Origin::Runtime>> + Clone,
Hops: Clone + CheckAssertion<Origin, Destination, Hops, Args>,
{
/// Creates a new `Test` instance
pub fn new(test_args: TestContext<Args>) -> Self {
pub fn new(test_args: TestContext<Args, Origin, Destination>) -> Self {
Test {
sender: TestAccount {
account_id: test_args.sender.clone(),
Expand Down
Loading