mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 12:11:02 +00:00
[xcm-emulator] Decouple the AccountId type from AccountId32 (#1458)
Closes: #1381 Originally from: https://github.com/paritytech/cumulus/pull/3037 --------- Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
This commit is contained in:
@@ -26,7 +26,7 @@ pub use std::{
|
|||||||
// Substrate
|
// Substrate
|
||||||
pub use frame_support::{
|
pub use frame_support::{
|
||||||
assert_ok,
|
assert_ok,
|
||||||
sp_runtime::{traits::Header as HeaderT, AccountId32, DispatchResult},
|
sp_runtime::{traits::Header as HeaderT, DispatchResult},
|
||||||
traits::{
|
traits::{
|
||||||
EnqueueMessage, Get, Hooks, OriginTrait, ProcessMessage, ProcessMessageError, ServiceQueues,
|
EnqueueMessage, Get, Hooks, OriginTrait, ProcessMessage, ProcessMessageError, ServiceQueues,
|
||||||
},
|
},
|
||||||
@@ -61,6 +61,8 @@ pub use xcm::v3::prelude::{
|
|||||||
};
|
};
|
||||||
pub use xcm_executor::traits::ConvertLocation;
|
pub use xcm_executor::traits::ConvertLocation;
|
||||||
|
|
||||||
|
pub type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
|
||||||
|
|
||||||
thread_local! {
|
thread_local! {
|
||||||
/// Downward messages, each message is: `(to_para_id, [(relay_block_number, msg)])`
|
/// Downward messages, each message is: `(to_para_id, [(relay_block_number, msg)])`
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
@@ -90,8 +92,8 @@ pub trait CheckAssertion<Origin, Destination, Hops, Args>
|
|||||||
where
|
where
|
||||||
Origin: Chain + Clone,
|
Origin: Chain + Clone,
|
||||||
Destination: Chain + Clone,
|
Destination: Chain + Clone,
|
||||||
Origin::RuntimeOrigin: OriginTrait<AccountId = AccountId32> + Clone,
|
Origin::RuntimeOrigin: OriginTrait<AccountId = AccountIdOf<Origin::Runtime>> + Clone,
|
||||||
Destination::RuntimeOrigin: OriginTrait<AccountId = AccountId32> + Clone,
|
Destination::RuntimeOrigin: OriginTrait<AccountId = AccountIdOf<Destination::Runtime>> + Clone,
|
||||||
Hops: Clone,
|
Hops: Clone,
|
||||||
Args: Clone,
|
Args: Clone,
|
||||||
{
|
{
|
||||||
@@ -103,8 +105,8 @@ impl<Origin, Destination, Hops, Args> CheckAssertion<Origin, Destination, Hops,
|
|||||||
where
|
where
|
||||||
Origin: Chain + Clone,
|
Origin: Chain + Clone,
|
||||||
Destination: Chain + Clone,
|
Destination: Chain + Clone,
|
||||||
Origin::RuntimeOrigin: OriginTrait<AccountId = AccountId32> + Clone,
|
Origin::RuntimeOrigin: OriginTrait<AccountId = AccountIdOf<Origin::Runtime>> + Clone,
|
||||||
Destination::RuntimeOrigin: OriginTrait<AccountId = AccountId32> + Clone,
|
Destination::RuntimeOrigin: OriginTrait<AccountId = AccountIdOf<Destination::Runtime>> + Clone,
|
||||||
Hops: Clone,
|
Hops: Clone,
|
||||||
Args: Clone,
|
Args: Clone,
|
||||||
{
|
{
|
||||||
@@ -219,24 +221,24 @@ pub trait Chain: TestExt + NetworkComponent {
|
|||||||
helpers::get_account_id_from_seed::<sr25519::Public>(seed)
|
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>;
|
fn events() -> Vec<<Self as Chain>::RuntimeEvent>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait RelayChain: Chain {
|
pub trait RelayChain: Chain {
|
||||||
type MessageProcessor: ProcessMessage;
|
type MessageProcessor: ProcessMessage;
|
||||||
type SovereignAccountOf: ConvertLocation<AccountId>;
|
type SovereignAccountOf: ConvertLocation<AccountIdOf<Self::Runtime>>;
|
||||||
|
|
||||||
fn child_location_of(id: ParaId) -> MultiLocation {
|
fn child_location_of(id: ParaId) -> MultiLocation {
|
||||||
(Ancestor(0), ParachainJunction(id.into())).into()
|
(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()
|
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))
|
Self::sovereign_account_id_of(Self::child_location_of(id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -244,7 +246,7 @@ pub trait RelayChain: Chain {
|
|||||||
pub trait Parachain: Chain {
|
pub trait Parachain: Chain {
|
||||||
type XcmpMessageHandler: XcmpMessageHandler;
|
type XcmpMessageHandler: XcmpMessageHandler;
|
||||||
type DmpMessageHandler: DmpMessageHandler;
|
type DmpMessageHandler: DmpMessageHandler;
|
||||||
type LocationToAccountId: ConvertLocation<AccountId>;
|
type LocationToAccountId: ConvertLocation<AccountIdOf<Self::Runtime>>;
|
||||||
type ParachainInfo: Get<ParaId>;
|
type ParachainInfo: Get<ParaId>;
|
||||||
type ParachainSystem;
|
type ParachainSystem;
|
||||||
|
|
||||||
@@ -268,7 +270,7 @@ pub trait Parachain: Chain {
|
|||||||
(Parent, X1(ParachainJunction(para_id.into()))).into()
|
(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()
|
Self::LocationToAccountId::convert_location(&location).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -365,7 +367,7 @@ macro_rules! decl_test_relay_chains {
|
|||||||
type RuntimeEvent = $runtime::RuntimeEvent;
|
type RuntimeEvent = $runtime::RuntimeEvent;
|
||||||
type System = $crate::SystemPallet::<Self::Runtime>;
|
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())
|
<Self as $crate::TestExt>::ext_wrapper(|| $crate::SystemPallet::<Self::Runtime>::account(account).data.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -590,7 +592,7 @@ macro_rules! decl_test_parachains {
|
|||||||
type RuntimeEvent = $runtime::RuntimeEvent;
|
type RuntimeEvent = $runtime::RuntimeEvent;
|
||||||
type System = $crate::SystemPallet::<Self::Runtime>;
|
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())
|
<Self as $crate::TestExt>::ext_wrapper(|| $crate::SystemPallet::<Self::Runtime>::account(account).data.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1159,9 +1161,10 @@ macro_rules! __impl_check_assertion {
|
|||||||
where
|
where
|
||||||
Origin: $crate::Chain + Clone,
|
Origin: $crate::Chain + Clone,
|
||||||
Destination: $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:
|
Destination::RuntimeOrigin:
|
||||||
$crate::OriginTrait<AccountId = $crate::AccountId32> + Clone,
|
$crate::OriginTrait<AccountId = $crate::AccountIdOf<Destination::Runtime>> + Clone,
|
||||||
Hops: Clone,
|
Hops: Clone,
|
||||||
Args: Clone,
|
Args: Clone,
|
||||||
{
|
{
|
||||||
@@ -1308,8 +1311,8 @@ where
|
|||||||
|
|
||||||
/// Struct that keeps account's id and balance
|
/// Struct that keeps account's id and balance
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct TestAccount {
|
pub struct TestAccount<R: Chain> {
|
||||||
pub account_id: AccountId,
|
pub account_id: AccountIdOf<R::Runtime>,
|
||||||
pub balance: Balance,
|
pub balance: Balance,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1326,9 +1329,9 @@ pub struct TestArgs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Auxiliar struct to help creating a new `Test` instance
|
/// Auxiliar struct to help creating a new `Test` instance
|
||||||
pub struct TestContext<T> {
|
pub struct TestContext<T, Origin: Chain, Destination: Chain> {
|
||||||
pub sender: AccountId,
|
pub sender: AccountIdOf<Origin::Runtime>,
|
||||||
pub receiver: AccountId,
|
pub receiver: AccountIdOf<Destination::Runtime>,
|
||||||
pub args: T,
|
pub args: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1345,12 +1348,12 @@ pub struct Test<Origin, Destination, Hops = (), Args = TestArgs>
|
|||||||
where
|
where
|
||||||
Origin: Chain + Clone,
|
Origin: Chain + Clone,
|
||||||
Destination: Chain + Clone,
|
Destination: Chain + Clone,
|
||||||
Origin::RuntimeOrigin: OriginTrait<AccountId = AccountId32> + Clone,
|
Origin::RuntimeOrigin: OriginTrait<AccountId = AccountIdOf<Origin::Runtime>> + Clone,
|
||||||
Destination::RuntimeOrigin: OriginTrait<AccountId = AccountId32> + Clone,
|
Destination::RuntimeOrigin: OriginTrait<AccountId = AccountIdOf<Destination::Runtime>> + Clone,
|
||||||
Hops: Clone,
|
Hops: Clone,
|
||||||
{
|
{
|
||||||
pub sender: TestAccount,
|
pub sender: TestAccount<Origin>,
|
||||||
pub receiver: TestAccount,
|
pub receiver: TestAccount<Destination>,
|
||||||
pub signed_origin: Origin::RuntimeOrigin,
|
pub signed_origin: Origin::RuntimeOrigin,
|
||||||
pub root_origin: Origin::RuntimeOrigin,
|
pub root_origin: Origin::RuntimeOrigin,
|
||||||
pub hops_assertion: HashMap<String, fn(Self)>,
|
pub hops_assertion: HashMap<String, fn(Self)>,
|
||||||
@@ -1365,12 +1368,12 @@ where
|
|||||||
Args: Clone,
|
Args: Clone,
|
||||||
Origin: Chain + Clone + CheckAssertion<Origin, Destination, Hops, Args>,
|
Origin: Chain + Clone + CheckAssertion<Origin, Destination, Hops, Args>,
|
||||||
Destination: Chain + Clone + CheckAssertion<Origin, Destination, Hops, Args>,
|
Destination: Chain + Clone + CheckAssertion<Origin, Destination, Hops, Args>,
|
||||||
Origin::RuntimeOrigin: OriginTrait<AccountId = AccountId32> + Clone,
|
Origin::RuntimeOrigin: OriginTrait<AccountId = AccountIdOf<Origin::Runtime>> + Clone,
|
||||||
Destination::RuntimeOrigin: OriginTrait<AccountId = AccountId32> + Clone,
|
Destination::RuntimeOrigin: OriginTrait<AccountId = AccountIdOf<Destination::Runtime>> + Clone,
|
||||||
Hops: Clone + CheckAssertion<Origin, Destination, Hops, Args>,
|
Hops: Clone + CheckAssertion<Origin, Destination, Hops, Args>,
|
||||||
{
|
{
|
||||||
/// Creates a new `Test` instance
|
/// Creates a new `Test` instance
|
||||||
pub fn new(test_args: TestContext<Args>) -> Self {
|
pub fn new(test_args: TestContext<Args, Origin, Destination>) -> Self {
|
||||||
Test {
|
Test {
|
||||||
sender: TestAccount {
|
sender: TestAccount {
|
||||||
account_id: test_args.sender.clone(),
|
account_id: test_args.sender.clone(),
|
||||||
|
|||||||
Reference in New Issue
Block a user