-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
1,746 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
pub mod parachain; | ||
pub mod relay_chain; | ||
|
||
use sp_runtime::BuildStorage; | ||
use sp_tracing; | ||
use xcm::prelude::*; | ||
use xcm_executor::traits::ConvertLocation; | ||
use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, TestExt}; | ||
|
||
pub const PARA_ALICE: [u8; 20] = [1u8; 20]; | ||
pub const ALICE: sp_runtime::AccountId32 = sp_runtime::AccountId32::new([1u8; 32]); | ||
pub const INITIAL_BALANCE: u128 = 1_000_000_000; | ||
|
||
decl_test_parachain! { | ||
pub struct ParaA { | ||
Runtime = parachain::Runtime, | ||
XcmpMessageHandler = parachain::MsgQueue, | ||
DmpMessageHandler = parachain::MsgQueue, | ||
new_ext = para_ext(1), | ||
} | ||
} | ||
|
||
decl_test_parachain! { | ||
pub struct ParaB { | ||
Runtime = parachain::Runtime, | ||
XcmpMessageHandler = parachain::MsgQueue, | ||
DmpMessageHandler = parachain::MsgQueue, | ||
new_ext = para_ext(2), | ||
} | ||
} | ||
|
||
decl_test_relay_chain! { | ||
pub struct Relay { | ||
Runtime = relay_chain::Runtime, | ||
RuntimeCall = relay_chain::RuntimeCall, | ||
RuntimeEvent = relay_chain::RuntimeEvent, | ||
XcmConfig = relay_chain::XcmConfig, | ||
MessageQueue = relay_chain::MessageQueue, | ||
System = relay_chain::System, | ||
new_ext = relay_ext(), | ||
} | ||
} | ||
|
||
decl_test_network! { | ||
pub struct MockNet { | ||
relay_chain = Relay, | ||
parachains = vec![ | ||
(1, ParaA), | ||
(2, ParaB), | ||
], | ||
} | ||
} | ||
|
||
pub fn parent_account_id() -> parachain::AccountId { | ||
let location = (Parent,); | ||
parachain::location_converter::LocationConverter::convert_location(&location.into()).unwrap() | ||
} | ||
|
||
pub fn child_account_id(para: u32) -> relay_chain::AccountId { | ||
let location = (Parachain(para),); | ||
relay_chain::location_converter::LocationConverter::convert_location(&location.into()).unwrap() | ||
} | ||
|
||
pub fn child_account_account_id(para: u32, who: sp_runtime::AccountId32) -> relay_chain::AccountId { | ||
let location = (Parachain(para), AccountId32 { network: None, id: who.into() }); | ||
relay_chain::location_converter::LocationConverter::convert_location(&location.into()).unwrap() | ||
} | ||
|
||
pub fn sibling_account_account_id(para: u32, who: sp_runtime::AccountId32) -> parachain::AccountId { | ||
let location = (Parent, Parachain(para), AccountId32 { network: None, id: who.into() }); | ||
parachain::location_converter::LocationConverter::convert_location(&location.into()).unwrap() | ||
} | ||
|
||
pub fn parent_account_account_id(who: sp_runtime::AccountId32) -> parachain::AccountId { | ||
let location = (Parent, AccountId32 { network: None, id: who.into() }); | ||
parachain::location_converter::LocationConverter::convert_location(&location.into()).unwrap() | ||
} | ||
|
||
pub fn para_ext(para_id: u32) -> sp_io::TestExternalities { | ||
use parachain::{MsgQueue, Runtime, System}; | ||
|
||
let mut t = frame_system::GenesisConfig::<Runtime>::default().build_storage().unwrap(); | ||
|
||
pallet_balances::GenesisConfig::<Runtime> { | ||
balances: vec![ | ||
(PARA_ALICE.into(), INITIAL_BALANCE), | ||
(parent_account_id(), INITIAL_BALANCE), | ||
], | ||
} | ||
.assimilate_storage(&mut t) | ||
.unwrap(); | ||
|
||
let mut ext = sp_io::TestExternalities::new(t); | ||
ext.execute_with(|| { | ||
sp_tracing::try_init_simple(); | ||
System::set_block_number(1); | ||
MsgQueue::set_para_id(para_id.into()); | ||
}); | ||
ext | ||
} | ||
|
||
pub fn relay_ext() -> sp_io::TestExternalities { | ||
use relay_chain::{Runtime, System}; | ||
|
||
let mut t = frame_system::GenesisConfig::<Runtime>::default().build_storage().unwrap(); | ||
|
||
pallet_balances::GenesisConfig::<Runtime> { | ||
balances: vec![ | ||
(ALICE, INITIAL_BALANCE), | ||
(child_account_id(1), INITIAL_BALANCE), | ||
(child_account_id(2), INITIAL_BALANCE), | ||
], | ||
} | ||
.assimilate_storage(&mut t) | ||
.unwrap(); | ||
|
||
let mut ext = sp_io::TestExternalities::new(t); | ||
ext.execute_with(|| { | ||
System::set_block_number(1); | ||
}); | ||
ext | ||
} | ||
|
||
pub type RelayChainPalletXcm = pallet_xcm::Pallet<relay_chain::Runtime>; | ||
pub type ParachainPalletXcm = pallet_xcm::Pallet<parachain::Runtime>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
mod xcm_config; | ||
use core::marker::PhantomData; | ||
|
||
use evm_runtime_template::configs::xcm_config::SignedToAccountId20; | ||
use frame_support::{ | ||
construct_runtime, derive_impl, parameter_types, | ||
traits::{ConstU128, ContainsPair, Everything, Nothing}, | ||
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, | ||
}; | ||
use frame_system::EnsureRoot; | ||
use sp_core::ConstU32; | ||
use sp_runtime::traits::{Get, IdentityLookup}; | ||
use xcm::latest::prelude::*; | ||
use xcm_builder::EnsureXcmOrigin; | ||
pub use xcm_config::*; | ||
use xcm_executor::XcmExecutor; | ||
use xcm_simulator::mock_message_queue; | ||
|
||
pub type AccountId = fp_account::AccountId20; | ||
pub type Balance = u128; | ||
|
||
parameter_types! { | ||
pub const BlockHashCount: u64 = 250; | ||
} | ||
|
||
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)] | ||
impl frame_system::Config for Runtime { | ||
type AccountData = pallet_balances::AccountData<Balance>; | ||
type AccountId = AccountId; | ||
type Block = Block; | ||
type Lookup = IdentityLookup<Self::AccountId>; | ||
} | ||
|
||
#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)] | ||
impl pallet_balances::Config for Runtime { | ||
type AccountStore = System; | ||
type Balance = Balance; | ||
type ExistentialDeposit = ConstU128<1>; | ||
} | ||
|
||
parameter_types! { | ||
pub const ReservedXcmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); | ||
pub const ReservedDmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); | ||
} | ||
|
||
impl mock_message_queue::Config for Runtime { | ||
type RuntimeEvent = RuntimeEvent; | ||
type XcmExecutor = XcmExecutor<XcmConfig>; | ||
} | ||
|
||
pub type LocalOriginToLocation = | ||
SignedToAccountId20<RuntimeOrigin, AccountId, constants::RelayNetwork>; | ||
|
||
pub struct TrustedLockerCase<T>(PhantomData<T>); | ||
impl<T: Get<(Location, AssetFilter)>> ContainsPair<Location, Asset> for TrustedLockerCase<T> { | ||
fn contains(origin: &Location, asset: &Asset) -> bool { | ||
let (o, a) = T::get(); | ||
a.matches(asset) && &o == origin | ||
} | ||
} | ||
|
||
parameter_types! { | ||
pub RelayTokenForRelay: (Location, AssetFilter) = (Parent.into(), Wild(AllOf { id: AssetId(Parent.into()), fun: WildFungible })); | ||
} | ||
|
||
pub type TrustedLockers = TrustedLockerCase<RelayTokenForRelay>; | ||
|
||
impl pallet_xcm::Config for Runtime { | ||
type AdminOrigin = EnsureRoot<AccountId>; | ||
type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; | ||
type Currency = Balances; | ||
type CurrencyMatcher = (); | ||
type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>; | ||
type MaxLockers = ConstU32<8>; | ||
type MaxRemoteLockConsumers = ConstU32<0>; | ||
type RemoteLockConsumerIdentifier = (); | ||
type RuntimeCall = RuntimeCall; | ||
type RuntimeEvent = RuntimeEvent; | ||
type RuntimeOrigin = RuntimeOrigin; | ||
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>; | ||
type SovereignAccountOf = location_converter::LocationConverter; | ||
type TrustedLockers = TrustedLockers; | ||
type UniversalLocation = constants::UniversalLocation; | ||
type Weigher = weigher::Weigher; | ||
type WeightInfo = pallet_xcm::TestWeightInfo; | ||
type XcmExecuteFilter = Everything; | ||
type XcmExecutor = XcmExecutor<XcmConfig>; | ||
type XcmReserveTransferFilter = Everything; | ||
type XcmRouter = XcmRouter; | ||
type XcmTeleportFilter = Nothing; | ||
|
||
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; | ||
} | ||
|
||
type Block = frame_system::mocking::MockBlock<Runtime>; | ||
|
||
construct_runtime!( | ||
pub struct Runtime { | ||
System: frame_system, | ||
Balances: pallet_balances, | ||
MsgQueue: mock_message_queue, | ||
PolkadotXcm: pallet_xcm, | ||
} | ||
); |
8 changes: 8 additions & 0 deletions
8
evm-template/runtime/tests/xcm_mock/parachain/xcm_config/asset_transactor.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use xcm_builder::{FungibleAdapter, IsConcrete}; | ||
|
||
use crate::parachain::{ | ||
constants::KsmLocation, location_converter::LocationConverter, AccountId, Balances, | ||
}; | ||
|
||
pub type AssetTransactor = | ||
FungibleAdapter<Balances, IsConcrete<KsmLocation>, LocationConverter, AccountId, ()>; |
4 changes: 4 additions & 0 deletions
4
evm-template/runtime/tests/xcm_mock/parachain/xcm_config/barrier.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
use frame_support::traits::Everything; | ||
use xcm_builder::AllowUnpaidExecutionFrom; | ||
|
||
pub type Barrier = AllowUnpaidExecutionFrom<Everything>; |
16 changes: 16 additions & 0 deletions
16
evm-template/runtime/tests/xcm_mock/parachain/xcm_config/constants.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use frame_support::parameter_types; | ||
use xcm::latest::prelude::*; | ||
use xcm_simulator::mock_message_queue::ParachainId; | ||
|
||
use crate::xcm_mock::parachain::Runtime; | ||
|
||
parameter_types! { | ||
pub KsmPerSecondPerByte: (AssetId, u128, u128) = (AssetId(Parent.into()), 1, 1); | ||
pub const MaxAssetsIntoHolding: u32 = 64; | ||
} | ||
|
||
parameter_types! { | ||
pub const KsmLocation: Location = Location::parent(); | ||
pub const RelayNetwork: NetworkId = NetworkId::Kusama; | ||
pub UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get()), Parachain(ParachainId::<Runtime>::get().into())].into(); | ||
} |
10 changes: 10 additions & 0 deletions
10
evm-template/runtime/tests/xcm_mock/parachain/xcm_config/location_converter.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use xcm_builder::{AccountKey20Aliases, DescribeAllTerminal, DescribeFamily, HashedDescription}; | ||
|
||
use crate::xcm_mock::parachain::{constants::RelayNetwork, AccountId}; | ||
|
||
type LocationToAccountId = ( | ||
HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>, | ||
AccountKey20Aliases<RelayNetwork, AccountId>, | ||
); | ||
|
||
pub type LocationConverter = LocationToAccountId; |
Oops, something went wrong.