From cb5346aaeb200670d7fd85bfa850c6313e2d9109 Mon Sep 17 00:00:00 2001 From: cr4pt0 Date: Wed, 29 Mar 2023 22:08:55 +0100 Subject: [PATCH] add relay chain + parachain base integration tests --- runtime/integration-tests/pendulum/src/lib.rs | 392 +++++++++++++----- .../pendulum/src/parachain.rs | 316 ++++++++++++++ .../pendulum/src/relay_chain.rs | 174 ++++++++ 3 files changed, 775 insertions(+), 107 deletions(-) create mode 100644 runtime/integration-tests/pendulum/src/parachain.rs create mode 100644 runtime/integration-tests/pendulum/src/relay_chain.rs diff --git a/runtime/integration-tests/pendulum/src/lib.rs b/runtime/integration-tests/pendulum/src/lib.rs index b1c77f8dc..5bfa146a0 100644 --- a/runtime/integration-tests/pendulum/src/lib.rs +++ b/runtime/integration-tests/pendulum/src/lib.rs @@ -1,35 +1,30 @@ -use frame_support::{ - construct_runtime, parameter_types, - traits::{Everything, Nothing}, -}; -use sp_core::H256; -use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32}; +// mod parachain; +// mod relay_chain; use polkadot_parachain::primitives::Id as ParaId; -use polkadot_runtime_parachains::{configuration, origin, shared, ump}; -use xcm::latest::prelude::*; -use xcm_builder::{ - AccountId32Aliases, AllowUnpaidExecutionFrom, ChildParachainAsNative, - ChildParachainConvertsVia, ChildSystemParachainAsSuperuser, - CurrencyAdapter as XcmCurrencyAdapter, FixedRateOfFungible, FixedWeightBounds, IsConcrete, - LocationInverter, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, -}; -use xcm_executor::{Config, XcmExecutor}; - -pub type AccountId = AccountId32; -pub type Balance = u128; - -use polkadot_core_primitives::BlockNumber; -use polkadot_primitives::v2::{MAX_CODE_SIZE, MAX_POV_SIZE}; -use polkadot_runtime_parachains::configuration::HostConfiguration; use sp_runtime::traits::AccountIdConversion; use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain}; -use frame_support::traits::GenesisBuild; -use frame_support::weights::Weight; -use polkadot_parachain::primitives::{ - DmpMessageHandler, Sibling, XcmpMessageFormat, XcmpMessageHandler, -}; +pub const ALICE: sp_runtime::AccountId32 = sp_runtime::AccountId32::new([0u8; 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 { @@ -40,95 +35,278 @@ decl_test_relay_chain! { } decl_test_network! { - pub struct TestNet{ - relay_chain = Relay, - parachains = vec![ ] - } + pub struct MockNet { + relay_chain = Relay, + parachains = vec![ + // (1, ParaA), + // (2, ParaB), + ], + } } +// pub fn para_account_id(id: u32) -> relay_chain::AccountId { +// ParaId::from(id).into_account_truncating() +// } + +// pub fn para_ext(para_id: u32) -> sp_io::TestExternalities { +// use parachain::{MsgQueue, Runtime, System}; + +// let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); + +// pallet_balances::GenesisConfig:: { balances: vec![(ALICE, INITIAL_BALANCE)] } +// .assimilate_storage(&mut t) +// .unwrap(); + +// let mut ext = sp_io::TestExternalities::new(t); +// ext.execute_with(|| { +// System::set_block_number(1); +// MsgQueue::set_para_id(para_id.into()); +// }); +// ext +// } pub fn relay_ext() -> sp_io::TestExternalities { - use polkadot_runtime::{Runtime, System}; - let mut t = frame_system::GenesisConfig::default() - .build_storage::() - .unwrap(); - pallet_balances::GenesisConfig:: { - balances: vec![ - // (AccountId::from(ALICE), cfg(2002)), - // ( - // ParaId::from(parachains::polkadot::centrifuge::ID).into_account_truncating(), - // cfg(7), - // ), - // ( - // ParaId::from(PARA_ID_SIBLING).into_account_truncating(), - // cfg(7), - // ), - ], - } - .assimilate_storage(&mut t) - .unwrap(); - polkadot_runtime_parachains::configuration::GenesisConfig:: { - config: default_parachains_host_configuration(), - } - .assimilate_storage(&mut t) - .unwrap(); - >::assimilate_storage( - &pallet_xcm::GenesisConfig { - safe_xcm_version: Some(2), - }, - &mut t, - ) - .unwrap(); - let mut ext = sp_io::TestExternalities::new(t); - ext.execute_with(|| System::set_block_number(1)); - ext -} + // use relay_chain::{Runtime, System}; + use polkadot_runtime::{Runtime, System}; -fn default_parachains_host_configuration() -> HostConfiguration { - HostConfiguration { - minimum_validation_upgrade_delay: 5, - validation_upgrade_cooldown: 5u32, - validation_upgrade_delay: 5, - code_retention_period: 1200, - max_code_size: MAX_CODE_SIZE, - max_pov_size: MAX_POV_SIZE, - max_head_data_size: 32 * 1024, - group_rotation_frequency: 20, - chain_availability_period: 4, - thread_availability_period: 4, - max_upward_queue_count: 8, - max_upward_queue_size: 1024 * 1024, - max_downward_message_size: 1024, - ump_service_total_weight: Weight::from_ref_time(4 * 1_000_000_000), - max_upward_message_size: 50 * 1024, - max_upward_message_num_per_candidate: 5, - hrmp_sender_deposit: 0, - hrmp_recipient_deposit: 0, - hrmp_channel_max_capacity: 8, - hrmp_channel_max_total_size: 8 * 1024, - hrmp_max_parachain_inbound_channels: 4, - hrmp_max_parathread_inbound_channels: 4, - hrmp_channel_max_message_size: 1024 * 1024, - hrmp_max_parachain_outbound_channels: 4, - hrmp_max_parathread_outbound_channels: 4, - hrmp_max_message_num_per_candidate: 5, - dispute_period: 6, - no_show_slots: 2, - n_delay_tranches: 25, - needed_approvals: 2, - relay_vrf_modulo_samples: 2, - zeroth_delay_tranche_width: 0, - ..Default::default() - } + let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); + + pallet_balances::GenesisConfig:: { + balances: vec![ + // (ALICE, INITIAL_BALANCE), (para_account_id(1), 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; +// pub type ParachainPalletXcm = pallet_xcm::Pallet; #[cfg(test)] mod tests { - use super::*; - #[test] - fn dmp() { + fn dmp() {} +} + +// #[cfg(test)] +// mod tests { +// use super::*; + +// use codec::Encode; +// use frame_support::assert_ok; +// use xcm::latest::prelude::*; +// use xcm_simulator::TestExt; + +// // Helper function for forming buy execution message +// fn buy_execution(fees: impl Into) -> Instruction { +// BuyExecution { fees: fees.into(), weight_limit: Unlimited } +// } + +// #[test] +// fn dmp() { +// MockNet::reset(); + +// let remark = parachain::RuntimeCall::System( +// frame_system::Call::::remark_with_event { remark: vec![1, 2, 3] }, +// ); +// Relay::execute_with(|| { +// assert_ok!(RelayChainPalletXcm::send_xcm( +// Here, +// Parachain(1), +// Xcm(vec![Transact { +// origin_type: OriginKind::SovereignAccount, +// require_weight_at_most: INITIAL_BALANCE as u64, +// call: remark.encode().into(), +// }]), +// )); +// }); + +// ParaA::execute_with(|| { +// use parachain::{RuntimeEvent, System}; +// assert!(System::events().iter().any(|r| matches!( +// r.event, +// RuntimeEvent::System(frame_system::Event::Remarked { .. }) +// ))); +// }); +// } + +// #[test] +// fn ump() { +// MockNet::reset(); + +// let remark = relay_chain::RuntimeCall::System( +// frame_system::Call::::remark_with_event { remark: vec![1, 2, 3] }, +// ); +// ParaA::execute_with(|| { +// assert_ok!(ParachainPalletXcm::send_xcm( +// Here, +// Parent, +// Xcm(vec![Transact { +// origin_type: OriginKind::SovereignAccount, +// require_weight_at_most: INITIAL_BALANCE as u64, +// call: remark.encode().into(), +// }]), +// )); +// }); + +// Relay::execute_with(|| { +// use relay_chain::{RuntimeEvent, System}; +// assert!(System::events().iter().any(|r| matches!( +// r.event, +// RuntimeEvent::System(frame_system::Event::Remarked { .. }) +// ))); +// }); +// } + +// #[test] +// fn xcmp() { +// MockNet::reset(); + +// let remark = parachain::RuntimeCall::System( +// frame_system::Call::::remark_with_event { remark: vec![1, 2, 3] }, +// ); +// ParaA::execute_with(|| { +// assert_ok!(ParachainPalletXcm::send_xcm( +// Here, +// (Parent, Parachain(2)), +// Xcm(vec![Transact { +// origin_type: OriginKind::SovereignAccount, +// require_weight_at_most: INITIAL_BALANCE as u64, +// call: remark.encode().into(), +// }]), +// )); +// }); + +// ParaB::execute_with(|| { +// use parachain::{RuntimeEvent, System}; +// assert!(System::events().iter().any(|r| matches!( +// r.event, +// RuntimeEvent::System(frame_system::Event::Remarked { .. }) +// ))); +// }); +// } + +// #[test] +// fn reserve_transfer() { +// MockNet::reset(); + +// let withdraw_amount = 123; + +// Relay::execute_with(|| { +// assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( +// relay_chain::RuntimeOrigin::signed(ALICE), +// Box::new(X1(Parachain(1)).into().into()), +// Box::new(X1(AccountId32 { network: Any, id: ALICE.into() }).into().into()), +// Box::new((Here, withdraw_amount).into()), +// 0, +// )); +// assert_eq!( +// parachain::Balances::free_balance(¶_account_id(1)), +// INITIAL_BALANCE + withdraw_amount +// ); +// }); + +// ParaA::execute_with(|| { +// // free execution, full amount received +// assert_eq!( +// pallet_balances::Pallet::::free_balance(&ALICE), +// INITIAL_BALANCE + withdraw_amount +// ); +// }); +// } + +// /// Scenario: +// /// A parachain transfers funds on the relay chain to another parachain account. +// /// +// /// Asserts that the parachain accounts are updated as expected. +// #[test] +// fn withdraw_and_deposit() { +// MockNet::reset(); + +// let send_amount = 10; + +// ParaA::execute_with(|| { +// let message = Xcm(vec![ +// WithdrawAsset((Here, send_amount).into()), +// buy_execution((Here, send_amount)), +// DepositAsset { +// assets: All.into(), +// max_assets: 1, +// beneficiary: Parachain(2).into(), +// }, +// ]); +// // Send withdraw and deposit +// assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent, message.clone())); +// }); + +// Relay::execute_with(|| { +// assert_eq!( +// relay_chain::Balances::free_balance(para_account_id(1)), +// INITIAL_BALANCE - send_amount +// ); +// assert_eq!(relay_chain::Balances::free_balance(para_account_id(2)), send_amount); +// }); +// } + +// /// Scenario: +// /// A parachain wants to be notified that a transfer worked correctly. +// /// It sends a `QueryHolding` after the deposit to get notified on success. +// /// +// /// Asserts that the balances are updated correctly and the expected XCM is sent. +// #[test] +// fn query_holding() { +// MockNet::reset(); + +// let send_amount = 10; +// let query_id_set = 1234; + +// // Send a message which fully succeeds on the relay chain +// ParaA::execute_with(|| { +// let message = Xcm(vec![ +// WithdrawAsset((Here, send_amount).into()), +// buy_execution((Here, send_amount)), +// DepositAsset { +// assets: All.into(), +// max_assets: 1, +// beneficiary: Parachain(2).into(), +// }, +// QueryHolding { +// query_id: query_id_set, +// dest: Parachain(1).into(), +// assets: All.into(), +// max_response_weight: 1_000_000_000, +// }, +// ]); +// // Send withdraw and deposit with query holding +// assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent, message.clone(),)); +// }); + +// // Check that transfer was executed +// Relay::execute_with(|| { +// // Withdraw executed +// assert_eq!( +// relay_chain::Balances::free_balance(para_account_id(1)), +// INITIAL_BALANCE - send_amount +// ); +// // Deposit executed +// assert_eq!(relay_chain::Balances::free_balance(para_account_id(2)), send_amount); +// }); - } -} \ No newline at end of file +// // Check that QueryResponse message was received +// ParaA::execute_with(|| { +// assert_eq!( +// parachain::MsgQueue::received_dmp(), +// vec![Xcm(vec![QueryResponse { +// query_id: query_id_set, +// response: Response::Assets(MultiAssets::new()), +// max_weight: 1_000_000_000, +// }])], +// ); +// }); +// } +// } diff --git a/runtime/integration-tests/pendulum/src/parachain.rs b/runtime/integration-tests/pendulum/src/parachain.rs new file mode 100644 index 000000000..ac791102f --- /dev/null +++ b/runtime/integration-tests/pendulum/src/parachain.rs @@ -0,0 +1,316 @@ +// use codec::{Decode, Encode}; +// use frame_support::{ +// construct_runtime, parameter_types, +// traits::{Everything, Nothing}, +// weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, +// }; +// use sp_core::H256; +// use sp_runtime::{ +// testing::Header, +// traits::{Hash, IdentityLookup}, +// AccountId32, +// }; +// use sp_std::prelude::*; + +// use pallet_xcm::XcmPassthrough; +// use polkadot_core_primitives::BlockNumber as RelayBlockNumber; +// use polkadot_parachain::primitives::{ +// DmpMessageHandler, Id as ParaId, Sibling, XcmpMessageFormat, XcmpMessageHandler, +// }; +// use xcm::{latest::prelude::*, VersionedXcm}; +// use xcm_builder::{ +// AccountId32Aliases, AllowUnpaidExecutionFrom, CurrencyAdapter as XcmCurrencyAdapter, +// EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, IsConcrete, LocationInverter, +// NativeAsset, ParentIsPreset, SiblingParachainConvertsVia, SignedAccountId32AsNative, +// SignedToAccountId32, SovereignSignedViaLocation, +// }; +// use xcm_executor::{Config, XcmExecutor}; + +// pub type AccountId = AccountId32; +// pub type Balance = u128; + +// parameter_types! { +// pub const BlockHashCount: u64 = 250; +// } + +// impl frame_system::Config for Runtime { +// type RuntimeOrigin = RuntimeOrigin; +// type RuntimeCall = RuntimeCall; +// type Index = u64; +// type BlockNumber = u64; +// type Hash = H256; +// type Hashing = ::sp_runtime::traits::BlakeTwo256; +// type AccountId = AccountId; +// type Lookup = IdentityLookup; +// type Header = Header; +// type RuntimeEvent = RuntimeEvent; +// type BlockHashCount = BlockHashCount; +// type BlockWeights = (); +// type BlockLength = (); +// type Version = (); +// type PalletInfo = PalletInfo; +// type AccountData = pallet_balances::AccountData; +// type OnNewAccount = (); +// type OnKilledAccount = (); +// type DbWeight = (); +// type BaseCallFilter = Everything; +// type SystemWeightInfo = (); +// type SS58Prefix = (); +// type OnSetCode = (); +// type MaxConsumers = frame_support::traits::ConstU32<16>; +// } + +// parameter_types! { +// pub ExistentialDeposit: Balance = 1; +// pub const MaxLocks: u32 = 50; +// pub const MaxReserves: u32 = 50; +// } + +// impl pallet_balances::Config for Runtime { +// type MaxLocks = MaxLocks; +// type Balance = Balance; +// type RuntimeEvent = RuntimeEvent; +// type DustRemoval = (); +// type ExistentialDeposit = ExistentialDeposit; +// type AccountStore = System; +// type WeightInfo = (); +// type MaxReserves = MaxReserves; +// type ReserveIdentifier = [u8; 8]; +// } + +// parameter_types! { +// pub const ReservedXcmpWeight: Weight = Weight::from_ref_time(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4)); +// pub const ReservedDmpWeight: Weight = Weight::from_ref_time(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4)); +// } + +// parameter_types! { +// pub const KsmLocation: MultiLocation = MultiLocation::parent(); +// pub const RelayNetwork: NetworkId = NetworkId::Kusama; +// pub Ancestry: MultiLocation = Parachain(MsgQueue::parachain_id().into()).into(); +// } + +// pub type LocationToAccountId = ( +// ParentIsPreset, +// SiblingParachainConvertsVia, +// AccountId32Aliases, +// ); + +// pub type XcmOriginToCallOrigin = ( +// SovereignSignedViaLocation, +// SignedAccountId32AsNative, +// XcmPassthrough, +// ); + +// parameter_types! { +// pub const UnitWeightCost: u64 = 1; +// pub KsmPerSecond: (AssetId, u128) = (Concrete(Parent.into()), 1); +// pub const MaxInstructions: u32 = 100; +// } + +// pub type LocalAssetTransactor = +// XcmCurrencyAdapter, LocationToAccountId, AccountId, ()>; + +// pub type XcmRouter = super::ParachainXcmRouter; +// pub type Barrier = AllowUnpaidExecutionFrom; + +// pub struct XcmConfig; +// impl Config for XcmConfig { +// type RuntimeCall = RuntimeCall; +// type XcmSender = XcmRouter; +// type AssetTransactor = LocalAssetTransactor; +// type OriginConverter = XcmOriginToCallOrigin; +// type IsReserve = NativeAsset; +// type IsTeleporter = (); +// type LocationInverter = LocationInverter; +// type Barrier = Barrier; +// type Weigher = FixedWeightBounds; +// type Trader = FixedRateOfFungible; +// type ResponseHandler = (); +// type AssetTrap = (); +// type AssetClaims = (); +// type SubscriptionService = (); +// } + +// #[frame_support::pallet] +// pub mod mock_msg_queue { +// use super::*; +// use frame_support::pallet_prelude::*; + +// #[pallet::config] +// pub trait Config: frame_system::Config { +// type RuntimeEvent: From> + IsType<::RuntimeEvent>; +// type XcmExecutor: ExecuteXcm; +// } + +// #[pallet::call] +// impl Pallet {} + +// #[pallet::pallet] +// #[pallet::generate_store(pub(super) trait Store)] +// #[pallet::without_storage_info] +// pub struct Pallet(_); + +// #[pallet::storage] +// #[pallet::getter(fn parachain_id)] +// pub(super) type ParachainId = StorageValue<_, ParaId, ValueQuery>; + +// #[pallet::storage] +// #[pallet::getter(fn received_dmp)] +// /// A queue of received DMP messages +// pub(super) type ReceivedDmp = StorageValue<_, Vec>, ValueQuery>; + +// impl Get for Pallet { +// fn get() -> ParaId { +// Self::parachain_id() +// } +// } + +// pub type MessageId = [u8; 32]; + +// #[pallet::event] +// #[pallet::generate_deposit(pub(super) fn deposit_event)] +// pub enum Event { +// // XCMP +// /// Some XCM was executed OK. +// Success(Option), +// /// Some XCM failed. +// Fail(Option, XcmError), +// /// Bad XCM version used. +// BadVersion(Option), +// /// Bad XCM format used. +// BadFormat(Option), + +// // DMP +// /// Downward message is invalid XCM. +// InvalidFormat(MessageId), +// /// Downward message is unsupported version of XCM. +// UnsupportedVersion(MessageId), +// /// Downward message executed with the given outcome. +// ExecutedDownward(MessageId, Outcome), +// } + +// impl Pallet { +// pub fn set_para_id(para_id: ParaId) { +// ParachainId::::put(para_id); +// } + +// fn handle_xcmp_message( +// sender: ParaId, +// _sent_at: RelayBlockNumber, +// xcm: VersionedXcm, +// max_weight: Weight, +// ) -> Result { +// let hash = Encode::using_encoded(&xcm, T::Hashing::hash); +// let (result, event) = match Xcm::::try_from(xcm) { +// Ok(xcm) => { +// let location = (1, Parachain(sender.into())); +// match T::XcmExecutor::execute_xcm(location, xcm, max_weight.ref_time()) { +// Outcome::Error(e) => (Err(e.clone()), Event::Fail(Some(hash), e)), +// Outcome::Complete(w) => +// (Ok(Weight::from_ref_time(w)), Event::Success(Some(hash))), +// // As far as the caller is concerned, this was dispatched without error, so +// // we just report the weight used. +// Outcome::Incomplete(w, e) => +// (Ok(Weight::from_ref_time(w)), Event::Fail(Some(hash), e)), +// } +// }, +// Err(()) => (Err(XcmError::UnhandledXcmVersion), Event::BadVersion(Some(hash))), +// }; +// Self::deposit_event(event); +// result +// } +// } + +// impl XcmpMessageHandler for Pallet { +// fn handle_xcmp_messages<'a, I: Iterator>( +// iter: I, +// max_weight: Weight, +// ) -> Weight { +// for (sender, sent_at, data) in iter { +// let mut data_ref = data; +// let _ = XcmpMessageFormat::decode(&mut data_ref) +// .expect("Simulator encodes with versioned xcm format; qed"); + +// let mut remaining_fragments = &data_ref[..]; +// while !remaining_fragments.is_empty() { +// if let Ok(xcm) = +// VersionedXcm::::decode(&mut remaining_fragments) +// { +// let _ = Self::handle_xcmp_message(sender, sent_at, xcm, max_weight); +// } else { +// debug_assert!(false, "Invalid incoming XCMP message data"); +// } +// } +// } +// max_weight +// } +// } + +// impl DmpMessageHandler for Pallet { +// fn handle_dmp_messages( +// iter: impl Iterator)>, +// limit: Weight, +// ) -> Weight { +// for (_i, (_sent_at, data)) in iter.enumerate() { +// let id = sp_io::hashing::blake2_256(&data[..]); +// let maybe_msg = VersionedXcm::::decode(&mut &data[..]) +// .map(Xcm::::try_from); +// match maybe_msg { +// Err(_) => { +// Self::deposit_event(Event::InvalidFormat(id)); +// }, +// Ok(Err(())) => { +// Self::deposit_event(Event::UnsupportedVersion(id)); +// }, +// Ok(Ok(x)) => { +// let outcome = +// T::XcmExecutor::execute_xcm(Parent, x.clone(), limit.ref_time()); +// >::append(x); +// Self::deposit_event(Event::ExecutedDownward(id, outcome)); +// }, +// } +// } +// limit +// } +// } +// } + +// impl mock_msg_queue::Config for Runtime { +// type RuntimeEvent = RuntimeEvent; +// type XcmExecutor = XcmExecutor; +// } + +// pub type LocalOriginToLocation = SignedToAccountId32; + +// impl pallet_xcm::Config for Runtime { +// type RuntimeEvent = RuntimeEvent; +// type SendXcmOrigin = EnsureXcmOrigin; +// type XcmRouter = XcmRouter; +// type ExecuteXcmOrigin = EnsureXcmOrigin; +// type XcmExecuteFilter = Everything; +// type XcmExecutor = XcmExecutor; +// type XcmTeleportFilter = Nothing; +// type XcmReserveTransferFilter = Everything; +// type Weigher = FixedWeightBounds; +// type LocationInverter = LocationInverter; +// type RuntimeOrigin = RuntimeOrigin; +// type RuntimeCall = RuntimeCall; +// const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; +// type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; +// } + +// type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +// type Block = frame_system::mocking::MockBlock; + +// construct_runtime!( +// pub enum Runtime where +// Block = Block, +// NodeBlock = Block, +// UncheckedExtrinsic = UncheckedExtrinsic, +// { +// System: frame_system::{Pallet, Call, Storage, Config, Event}, +// Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, +// MsgQueue: mock_msg_queue::{Pallet, Storage, Event}, +// PolkadotXcm: pallet_xcm::{Pallet, Call, Event, Origin}, +// } +// ); diff --git a/runtime/integration-tests/pendulum/src/relay_chain.rs b/runtime/integration-tests/pendulum/src/relay_chain.rs new file mode 100644 index 000000000..11dd8b74a --- /dev/null +++ b/runtime/integration-tests/pendulum/src/relay_chain.rs @@ -0,0 +1,174 @@ +// use frame_support::{ +// construct_runtime, parameter_types, +// traits::{Everything, Nothing}, +// }; +// use sp_core::H256; +// use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32}; + +// use polkadot_parachain::primitives::Id as ParaId; +// use polkadot_runtime_parachains::{configuration, origin, shared, ump}; +// use xcm::latest::prelude::*; +// use xcm_builder::{ +// AccountId32Aliases, AllowUnpaidExecutionFrom, ChildParachainAsNative, +// ChildParachainConvertsVia, ChildSystemParachainAsSuperuser, +// CurrencyAdapter as XcmCurrencyAdapter, FixedRateOfFungible, FixedWeightBounds, IsConcrete, +// LocationInverter, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, +// }; +// use xcm_executor::{Config, XcmExecutor}; + +// pub type AccountId = AccountId32; +// pub type Balance = u128; + +// parameter_types! { +// pub const BlockHashCount: u64 = 250; +// } + +// impl frame_system::Config for Runtime { +// type RuntimeOrigin = RuntimeOrigin; +// type RuntimeCall = RuntimeCall; +// type Index = u64; +// type BlockNumber = u64; +// type Hash = H256; +// type Hashing = ::sp_runtime::traits::BlakeTwo256; +// type AccountId = AccountId; +// type Lookup = IdentityLookup; +// type Header = Header; +// type RuntimeEvent = RuntimeEvent; +// type BlockHashCount = BlockHashCount; +// type BlockWeights = (); +// type BlockLength = (); +// type Version = (); +// type PalletInfo = PalletInfo; +// type AccountData = pallet_balances::AccountData; +// type OnNewAccount = (); +// type OnKilledAccount = (); +// type DbWeight = (); +// type BaseCallFilter = Everything; +// type SystemWeightInfo = (); +// type SS58Prefix = (); +// type OnSetCode = (); +// type MaxConsumers = frame_support::traits::ConstU32<16>; +// } + +// parameter_types! { +// pub ExistentialDeposit: Balance = 1; +// pub const MaxLocks: u32 = 50; +// pub const MaxReserves: u32 = 50; +// } + +// impl pallet_balances::Config for Runtime { +// type MaxLocks = MaxLocks; +// type Balance = Balance; +// type RuntimeEvent = RuntimeEvent; +// type DustRemoval = (); +// type ExistentialDeposit = ExistentialDeposit; +// type AccountStore = System; +// type WeightInfo = (); +// type MaxReserves = MaxReserves; +// type ReserveIdentifier = [u8; 8]; +// } + +// impl shared::Config for Runtime {} + +// impl configuration::Config for Runtime { +// type WeightInfo = configuration::TestWeightInfo; +// } + +// parameter_types! { +// pub const KsmLocation: MultiLocation = Here.into(); +// pub const KusamaNetwork: NetworkId = NetworkId::Kusama; +// pub const AnyNetwork: NetworkId = NetworkId::Any; +// pub Ancestry: MultiLocation = Here.into(); +// pub UnitWeightCost: u64 = 1_000; +// } + +// pub type SovereignAccountOf = +// (ChildParachainConvertsVia, AccountId32Aliases); + +// pub type LocalAssetTransactor = +// XcmCurrencyAdapter, SovereignAccountOf, AccountId, ()>; + +// type LocalOriginConverter = ( +// SovereignSignedViaLocation, +// ChildParachainAsNative, +// SignedAccountId32AsNative, +// ChildSystemParachainAsSuperuser, +// ); + +// parameter_types! { +// pub const BaseXcmWeight: u64 = 1_000; +// pub KsmPerSecond: (AssetId, u128) = (Concrete(KsmLocation::get()), 1); +// pub const MaxInstructions: u32 = 100; +// } + +// pub type XcmRouter = super::RelayChainXcmRouter; +// pub type Barrier = AllowUnpaidExecutionFrom; + +// pub struct XcmConfig; +// impl Config for XcmConfig { +// type RuntimeCall = RuntimeCall; +// type XcmSender = XcmRouter; +// type AssetTransactor = LocalAssetTransactor; +// type OriginConverter = LocalOriginConverter; +// type IsReserve = (); +// type IsTeleporter = (); +// type LocationInverter = LocationInverter; +// type Barrier = Barrier; +// type Weigher = FixedWeightBounds; +// type Trader = FixedRateOfFungible; +// type ResponseHandler = (); +// type AssetTrap = (); +// type AssetClaims = (); +// type SubscriptionService = (); +// } + +// pub type LocalOriginToLocation = SignedToAccountId32; + +// impl pallet_xcm::Config for Runtime { +// type RuntimeEvent = RuntimeEvent; +// type SendXcmOrigin = xcm_builder::EnsureXcmOrigin; +// type XcmRouter = XcmRouter; +// // Anyone can execute XCM messages locally... +// type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin; +// type XcmExecuteFilter = Nothing; +// type XcmExecutor = XcmExecutor; +// type XcmTeleportFilter = Everything; +// type XcmReserveTransferFilter = Everything; +// type Weigher = FixedWeightBounds; +// type LocationInverter = LocationInverter; +// type RuntimeOrigin = RuntimeOrigin; +// type RuntimeCall = RuntimeCall; +// const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; +// type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; +// } + +// parameter_types! { +// pub const FirstMessageFactorPercent: u64 = 100; +// } + +// impl ump::Config for Runtime { +// type RuntimeEvent = RuntimeEvent; +// type UmpSink = ump::XcmSink, Runtime>; +// type FirstMessageFactorPercent = FirstMessageFactorPercent; +// type ExecuteOverweightOrigin = frame_system::EnsureRoot; +// type WeightInfo = ump::TestWeightInfo; +// } + +// impl origin::Config for Runtime {} + +// type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +// type Block = frame_system::mocking::MockBlock; + +// construct_runtime!( +// pub enum Runtime where +// Block = Block, +// NodeBlock = Block, +// UncheckedExtrinsic = UncheckedExtrinsic, +// { +// System: frame_system::{Pallet, Call, Storage, Config, Event}, +// Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, +// ParasOrigin: origin::{Pallet, Origin}, +// ParasUmp: ump::{Pallet, Call, Storage, Event}, +// XcmPallet: pallet_xcm::{Pallet, Call, Storage, Event, Origin}, +// } +// );