Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[xcm-emulator] Decouple the AccountId type from AccountId32 #1458

Merged
merged 3 commits into from
Oct 9, 2023
Merged
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
57 changes: 30 additions & 27 deletions cumulus/xcm/xcm-emulator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub use std::{
// Substrate
pub use frame_support::{
assert_ok,
sp_runtime::{traits::Header as HeaderT, AccountId32, DispatchResult},
sp_runtime::{traits::Header as HeaderT, DispatchResult},
traits::{
EnqueueMessage, Get, Hooks, OriginTrait, ProcessMessage, ProcessMessageError, ServiceQueues,
},
Expand Down Expand Up @@ -61,6 +61,8 @@ pub use xcm::v3::prelude::{
};
pub use xcm_executor::traits::ConvertLocation;

pub type AccountIdOf<T> = <T as frame_system::Config>::AccountId;

thread_local! {
/// Downward messages, each message is: `(to_para_id, [(relay_block_number, msg)])`
#[allow(clippy::type_complexity)]
Expand Down Expand Up @@ -90,8 +92,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 = AccountIdOf<Origin::Runtime>> + Clone,
Destination::RuntimeOrigin: OriginTrait<AccountId = AccountIdOf<Destination::Runtime>> + Clone,
Hops: Clone,
Args: Clone,
{
Expand All @@ -103,8 +105,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 = AccountIdOf<Origin::Runtime>> + Clone,
Destination::RuntimeOrigin: OriginTrait<AccountId = AccountIdOf<Destination::Runtime>> + Clone,
Hops: Clone,
Args: Clone,
{
Expand Down Expand Up @@ -219,32 +221,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: AccountIdOf<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<AccountIdOf<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) -> AccountIdOf<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) -> AccountIdOf<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<AccountIdOf<Self::Runtime>>;
type ParachainInfo: Get<ParaId>;
type ParachainSystem;

Expand All @@ -268,7 +270,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) -> AccountIdOf<Self::Runtime> {
Self::LocationToAccountId::convert_location(&location).unwrap()
}
}
Expand Down Expand Up @@ -365,7 +367,7 @@ macro_rules! decl_test_relay_chains {
type RuntimeEvent = $runtime::RuntimeEvent;
type System = $crate::SystemPallet::<Self::Runtime>;

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

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

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

Expand Down Expand Up @@ -1159,9 +1161,10 @@ macro_rules! __impl_check_assertion {
where
Origin: $crate::Chain + Clone,
Destination: $crate::Chain + Clone,
Origin::RuntimeOrigin: $crate::OriginTrait<AccountId = $crate::AccountId32> + Clone,
Origin::RuntimeOrigin:
$crate::OriginTrait<AccountId = $crate::AccountIdOf<Origin::Runtime>> + Clone,
Destination::RuntimeOrigin:
$crate::OriginTrait<AccountId = $crate::AccountId32> + Clone,
$crate::OriginTrait<AccountId = $crate::AccountIdOf<Destination::Runtime>> + Clone,
Hops: Clone,
Args: Clone,
{
Expand Down Expand Up @@ -1308,8 +1311,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: AccountIdOf<R::Runtime>,
pub balance: Balance,
}

Expand All @@ -1326,9 +1329,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, Origin: Chain, Destination: Chain> {
pub sender: AccountIdOf<Origin::Runtime>,
pub receiver: AccountIdOf<Destination::Runtime>,
pub args: T,
}

Expand All @@ -1345,12 +1348,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 = AccountIdOf<Origin::Runtime>> + Clone,
Destination::RuntimeOrigin: OriginTrait<AccountId = AccountIdOf<Destination::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 @@ -1365,12 +1368,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 = AccountIdOf<Origin::Runtime>> + Clone,
Destination::RuntimeOrigin: OriginTrait<AccountId = AccountIdOf<Destination::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