diff --git a/runtime/integration-tests/Cargo.toml b/runtime/integration-tests/Cargo.toml index 8bf29961b..473c98fe1 100644 --- a/runtime/integration-tests/Cargo.toml +++ b/runtime/integration-tests/Cargo.toml @@ -8,6 +8,7 @@ version = "0.1.0" [dev-dependencies] codec = { package = "parity-scale-codec", version = "3.0.0" } scale-info = { version = "2.1.2", features = ["derive"] } +serde = { version = "1.0.144", features = ["derive"] } frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } @@ -18,6 +19,7 @@ sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot- sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } sp-tracing = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } +sp-debug-derive = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40" } xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.40" } xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.40" } diff --git a/runtime/integration-tests/src/lib.rs b/runtime/integration-tests/src/lib.rs index 074a05fc3..e9f3ca5bd 100644 --- a/runtime/integration-tests/src/lib.rs +++ b/runtime/integration-tests/src/lib.rs @@ -10,6 +10,7 @@ mod amplitude_tests; #[cfg(test)] mod test_macros; +#[cfg(test)] mod sibling; pub const PENDULUM_ID: u32 = 2094; diff --git a/runtime/integration-tests/src/mock.rs b/runtime/integration-tests/src/mock.rs index fe68daacd..2860597ce 100644 --- a/runtime/integration-tests/src/mock.rs +++ b/runtime/integration-tests/src/mock.rs @@ -199,7 +199,7 @@ impl ExtBuilderParachain { ParachainType::PolkadotAssetHub => POLKADOT_ASSETHUB_ID, ParachainType::KusamaAssetHub => KUSAMA_ASSETHUB_ID, ParachainType::Pendulum => PENDULUM_ID, - ParachainType::Pendulum2 => PENDULUM_ID + 1, + ParachainType::Sibling => PENDULUM_ID + 1, ParachainType::Amplitude => AMPLITUDE_ID, } } diff --git a/runtime/integration-tests/src/pendulum_tests.rs b/runtime/integration-tests/src/pendulum_tests.rs index 35e5b5086..d6d54442c 100644 --- a/runtime/integration-tests/src/pendulum_tests.rs +++ b/runtime/integration-tests/src/pendulum_tests.rs @@ -36,12 +36,12 @@ decl_test_parachain! { } decl_test_parachain! { - pub struct Pendulum2Parachain { + pub struct SiblingParachain { Runtime = pendulum_runtime::Runtime, RuntimeOrigin = pendulum_runtime::RuntimeOrigin, XcmpMessageHandler = pendulum_runtime::XcmpQueue, DmpMessageHandler = pendulum_runtime::DmpQueue, - new_ext = para_ext(ParachainType::Pendulum2), + new_ext = para_ext(ParachainType::Sibling), } } @@ -61,7 +61,7 @@ decl_test_network! { parachains = vec![ (1000, AssetHubParachain), (2094, PendulumParachain), - (2095, Pendulum2Parachain), + (2095, SiblingParachain), ], } } @@ -132,15 +132,15 @@ fn assethub_transfer_asset_to_pendulum_and_back() { #[test] fn transfer_pendulum_native_token_to_pendulum() { // ID for Pendulum's second instance - pub const PENDULUM2_ID: u32 = PENDULUM_ID + 1; + pub const SIBLING_ID: u32 = PENDULUM_ID + 1; transfer_native_token_from_parachain1_to_parachain2!( PolkadotMockNet, pendulum_runtime, PendulumParachain, pendulum_runtime, - Pendulum2Parachain, + SiblingParachain, PENDULUM_ID, - PENDULUM2_ID + SIBLING_ID ); } diff --git a/runtime/integration-tests/src/sibling.rs b/runtime/integration-tests/src/sibling.rs index 16d57d299..f7ed86be0 100644 --- a/runtime/integration-tests/src/sibling.rs +++ b/runtime/integration-tests/src/sibling.rs @@ -1,23 +1,33 @@ // Based on https://github.com/open-web3-stack/open-runtime-module-library/blob/83a76c2bf66c0b1236c31077e6fb24bb760a3535/xtokens/src/mock/para.rs +// This is temporary until successful compiling +#![allow(warnings)] +#![cfg(test)] + use frame_support::{ construct_runtime, match_types, parameter_types, traits::{ConstU128, ConstU32, ConstU64, Everything, Get, Nothing}, weights::constants::WEIGHT_REF_TIME_PER_SECOND, }; +use crate:: + mock::{para_ext, polkadot_relay_ext, ParachainType}; use frame_system::EnsureRoot; +use pendulum_runtime::{ParachainInfo, Tokens}; use sp_core::H256; use sp_runtime::traits::{Convert, IdentityLookup}; - +use codec::{Encode, Decode, MaxEncodedLen}; use scale_info::TypeInfo; use serde::{Deserialize, Serialize}; use sp_runtime::{AccountId32, BoundedVec, BuildStorage}; -use xcm_builder::{CreateMatcher, MatchXcm}; +use xcm::CreateMatcher; +use xcm::MatchXcm; use xcm_executor::{ traits::{ShouldExecute, WeightTrader}, Assets, }; - +use xcm_emulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, TestExt}; +use frame_support::traits::ProcessMessageError; +use sp_debug_derive::RuntimeDebug; use cumulus_primitives_core::{ChannelStatus, GetChannelInfo, ParaId}; use pallet_xcm::XcmPassthrough; use xcm::v3::{prelude::*, Weight}; @@ -27,12 +37,33 @@ use xcm_builder::{ SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, }; use xcm_executor::{Config, XcmExecutor}; - use orml_traits::{location::AbsoluteReserveProvider, parameter_type_with_key}; use orml_xcm_support::{IsNativeConcrete, MultiCurrencyAdapter, MultiNativeAsset}; - +use sp_io::TestExternalities; pub type AccountId = AccountId32; +type Block = frame_system::mocking::MockBlock; +//type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; + +construct_runtime!( + pub enum Runtime + { + System: frame_system, + Balances: pallet_balances, + + //ParachainInfo: parachain_info, + // XcmpQueue: cumulus_pallet_xcmp_queue, + // DmpQueue: cumulus_pallet_dmp_queue, + // CumulusXcm: cumulus_pallet_xcm, + + // Tokens: orml_tokens, + // XTokens: orml_xtokens, + + // PolkadotXcm: pallet_xcm, + // OrmlXcm: orml_xcm, + } +); + #[derive( Encode, Decode, @@ -43,7 +74,7 @@ pub type AccountId = AccountId32; RuntimeDebug, PartialOrd, Ord, - parity_scale_codec::MaxEncodedLen, + MaxEncodedLen, TypeInfo, )] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] @@ -194,6 +225,47 @@ impl Convert> for CurrencyIdConvert { pub type Balance = u128; pub type Amount = i128; +// decl_test_parachain! { +// pub struct SiblingParachain { +// Runtime = Runtime, +// RuntimeOrigin = RuntimeOrigin, +// XcmpMessageHandler = XcmpQueue, +// DmpMessageHandler = DmpQueue, +// new_ext = para_ext(ParachainType::Sibling), +// } +// } + +// I think we're not going to use this but our relay mock instead +// I'll just leave it here in case we need something from it +// decl_test_relay_chain! { +// pub struct Relay { +// Runtime = Runtime, +// RuntimeCall = relay::RuntimeCall, +// RuntimeEvent = relay::RuntimeEvent, +// //XcmConfig = relay::XcmConfig, +// //MessageQueue = relay::MessageQueue, +// System = relay::System, +// new_ext = relay_ext(), +// } +// } + +// decl_test_relay_chain! { +// pub struct PolkadotRelay { +// Runtime = polkadot_runtime::Runtime, +// XcmConfig = polkadot_runtime::xcm_config::XcmConfig, +// new_ext = polkadot_relay_ext(), +// } +// } + +// decl_test_network! { +// pub struct TestNet { +// relay_chain = PolkadotRelay, +// parachains = vec![ +// (1, SiblingParachain), +// ], +// } +// } + impl frame_system::Config for Runtime { type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; @@ -201,6 +273,7 @@ impl frame_system::Config for Runtime { type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; + type Block = Block; type RuntimeEvent = RuntimeEvent; type BlockHashCount = ConstU64<250>; type BlockWeights = (); @@ -236,161 +309,161 @@ parameter_type_with_key! { }; } -impl orml_tokens::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type Balance = Balance; - type Amount = Amount; - type CurrencyId = CurrencyId; - type WeightInfo = (); - type ExistentialDeposits = ExistentialDeposits; - type CurrencyHooks = (); - type MaxLocks = ConstU32<50>; - type MaxReserves = ConstU32<50>; - type ReserveIdentifier = [u8; 8]; - type DustRemovalWhitelist = Everything; -} - -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 parachain_info::Config for Runtime {} - -parameter_types! { - pub const RelayLocation: MultiLocation = MultiLocation::parent(); - pub const RelayNetwork: NetworkId = NetworkId::Kusama; - pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); - pub UniversalLocation: InteriorMultiLocation = - X2(GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())); -} - -pub type LocationToAccountId = ( - ParentIsPreset, - SiblingParachainConvertsVia, - AccountId32Aliases, -); - -pub type XcmOriginToCallOrigin = ( - SovereignSignedViaLocation, - RelayChainAsNative, - SiblingParachainAsNative, - SignedAccountId32AsNative, - XcmPassthrough, -); - -pub type LocalAssetTransactor = MultiCurrencyAdapter< - Tokens, - (), - IsNativeConcrete, - AccountId, - LocationToAccountId, - CurrencyId, - CurrencyIdConvert, - (), ->; - -pub type XcmRouter = ParachainXcmRouter; -pub type Barrier = (TakeWeightCredit, AllowTopLevelPaidExecution); - -parameter_types! { - pub const UnitWeightCost: Weight = Weight::from_parts(10, 10); - pub const BaseXcmWeight: Weight = Weight::from_parts(100_000_000, 100_000_000); - pub const MaxInstructions: u32 = 100; - pub const MaxAssetsIntoHolding: u32 = 64; -} - -pub struct XcmConfig; -impl Config for XcmConfig { - type RuntimeCall = RuntimeCall; - type XcmSender = XcmRouter; - type AssetTransactor = LocalAssetTransactor; - type OriginConverter = XcmOriginToCallOrigin; - type IsReserve = MultiNativeAsset; - type IsTeleporter = NativeAsset; - type UniversalLocation = UniversalLocation; - type Barrier = Barrier; - type Weigher = FixedWeightBounds; - type Trader = (); - type ResponseHandler = (); - type AssetTrap = PolkadotXcm; - type AssetClaims = PolkadotXcm; - type SubscriptionService = PolkadotXcm; - type AssetLocker = PolkadotXcm; - type AssetExchanger = (); - type PalletInstancesInfo = (); - type MaxAssetsIntoHolding = MaxAssetsIntoHolding; - type FeeManager = (); - type MessageExporter = (); - type UniversalAliases = Nothing; - type CallDispatcher = RuntimeCall; - type SafeCallFilter = Everything; -} - -pub struct ChannelInfo; -impl GetChannelInfo for ChannelInfo { - fn get_channel_status(_id: ParaId) -> ChannelStatus { - ChannelStatus::Ready(10, 10) - } - fn get_channel_max(_id: ParaId) -> Option { - Some(usize::max_value()) - } -} - -impl cumulus_pallet_xcmp_queue::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type XcmExecutor = XcmExecutor; - type ChannelInfo = ChannelInfo; - type VersionWrapper = (); - type ExecuteOverweightOrigin = EnsureRoot; - type ControllerOrigin = EnsureRoot; - type ControllerOriginConverter = XcmOriginToCallOrigin; - type WeightInfo = (); - type PriceForSiblingDelivery = (); -} - -impl cumulus_pallet_dmp_queue::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type XcmExecutor = XcmExecutor; - type ExecuteOverweightOrigin = EnsureRoot; -} - -impl cumulus_pallet_xcm::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type XcmExecutor = XcmExecutor; -} - -pub type LocalOriginToLocation = SignedToAccountId32; +// impl orml_tokens::Config for Runtime { +// type RuntimeEvent = RuntimeEvent; +// type Balance = Balance; +// type Amount = Amount; +// type CurrencyId = CurrencyId; +// type WeightInfo = (); +// type ExistentialDeposits = ExistentialDeposits; +// type CurrencyHooks = (); +// type MaxLocks = ConstU32<50>; +// type MaxReserves = ConstU32<50>; +// type ReserveIdentifier = [u8; 8]; +// type DustRemovalWhitelist = Everything; +// } + +// 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 parachain_info::Config for Runtime {} + +// parameter_types! { +// pub const RelayLocation: MultiLocation = MultiLocation::parent(); +// pub const RelayNetwork: NetworkId = NetworkId::Kusama; +// pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); +// pub UniversalLocation: InteriorMultiLocation = +// X2(GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())); +// } + +// pub type LocationToAccountId = ( +// ParentIsPreset, +// SiblingParachainConvertsVia, +// AccountId32Aliases, +// ); + +// pub type XcmOriginToCallOrigin = ( +// SovereignSignedViaLocation, +// RelayChainAsNative, +// SiblingParachainAsNative, +// SignedAccountId32AsNative, +// XcmPassthrough, +// ); + +// pub type LocalAssetTransactor = MultiCurrencyAdapter< +// Tokens, +// (), +// IsNativeConcrete, +// AccountId, +// LocationToAccountId, +// CurrencyId, +// CurrencyIdConvert, +// (), +// >; + +// pub type XcmRouter = ParachainXcmRouter; +// pub type Barrier = (TakeWeightCredit, AllowTopLevelPaidExecution); + +// parameter_types! { +// pub const UnitWeightCost: Weight = Weight::from_parts(10, 10); +// pub const BaseXcmWeight: Weight = Weight::from_parts(100_000_000, 100_000_000); +// pub const MaxInstructions: u32 = 100; +// pub const MaxAssetsIntoHolding: u32 = 64; +// } + +// pub struct XcmConfig; +// impl Config for XcmConfig { +// type RuntimeCall = RuntimeCall; +// type XcmSender = XcmRouter; +// type AssetTransactor = LocalAssetTransactor; +// type OriginConverter = XcmOriginToCallOrigin; +// type IsReserve = MultiNativeAsset; +// type IsTeleporter = NativeAsset; +// type UniversalLocation = UniversalLocation; +// type Barrier = Barrier; +// type Weigher = FixedWeightBounds; +// type Trader = (); +// type ResponseHandler = (); +// type AssetTrap = PolkadotXcm; +// type AssetClaims = PolkadotXcm; +// type SubscriptionService = PolkadotXcm; +// type AssetLocker = PolkadotXcm; +// type AssetExchanger = (); +// type PalletInstancesInfo = (); +// type MaxAssetsIntoHolding = MaxAssetsIntoHolding; +// type FeeManager = (); +// type MessageExporter = (); +// type UniversalAliases = Nothing; +// type CallDispatcher = RuntimeCall; +// type SafeCallFilter = Everything; +// } + +// pub struct ChannelInfo; +// impl GetChannelInfo for ChannelInfo { +// fn get_channel_status(_id: ParaId) -> ChannelStatus { +// ChannelStatus::Ready(10, 10) +// } +// fn get_channel_max(_id: ParaId) -> Option { +// Some(usize::max_value()) +// } +// } + +// impl cumulus_pallet_xcmp_queue::Config for Runtime { +// type RuntimeEvent = RuntimeEvent; +// type XcmExecutor = XcmExecutor; +// type ChannelInfo = ChannelInfo; +// type VersionWrapper = (); +// type ExecuteOverweightOrigin = EnsureRoot; +// type ControllerOrigin = EnsureRoot; +// type ControllerOriginConverter = XcmOriginToCallOrigin; +// type WeightInfo = (); +// type PriceForSiblingDelivery = (); +// } + +// impl cumulus_pallet_dmp_queue::Config for Runtime { +// type RuntimeEvent = RuntimeEvent; +// type XcmExecutor = XcmExecutor; +// type ExecuteOverweightOrigin = EnsureRoot; +// } + +// impl cumulus_pallet_xcm::Config for Runtime { +// type RuntimeEvent = RuntimeEvent; +// type XcmExecutor = XcmExecutor; +// } + +//pub type LocalOriginToLocation = SignedToAccountId32; #[cfg(feature = "runtime-benchmarks")] parameter_types! { pub ReachableDest: Option = Some(Parent.into()); } -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 UniversalLocation = UniversalLocation; - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; - type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; - type Currency = Balances; - type CurrencyMatcher = (); - type TrustedLockers = (); - type SovereignAccountOf = (); - type MaxLockers = ConstU32<8>; - type WeightInfo = pallet_xcm::TestWeightInfo; - #[cfg(feature = "runtime-benchmarks")] - type ReachableDest = ReachableDest; -} +// 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 UniversalLocation = UniversalLocation; +// type RuntimeOrigin = RuntimeOrigin; +// type RuntimeCall = RuntimeCall; +// const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; +// type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; +// type Currency = Balances; +// type CurrencyMatcher = (); +// type TrustedLockers = (); +// type SovereignAccountOf = (); +// type MaxLockers = ConstU32<8>; +// type WeightInfo = pallet_xcm::TestWeightInfo; +// #[cfg(feature = "runtime-benchmarks")] +// type ReachableDest = ReachableDest; +// } pub struct AccountIdToMultiLocation; impl Convert for AccountIdToMultiLocation { @@ -426,44 +499,29 @@ parameter_type_with_key! { }; } -impl orml_xtokens::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type Balance = Balance; - type CurrencyId = CurrencyId; - type CurrencyIdConvert = CurrencyIdConvert; - type AccountIdToMultiLocation = AccountIdToMultiLocation; - type SelfLocation = SelfLocation; - type MultiLocationsFilter = ParentOrParachains; - type MinXcmFee = ParachainMinFee; - type XcmExecutor = XcmExecutor; - type Weigher = FixedWeightBounds; - type BaseXcmWeight = BaseXcmWeight; - type UniversalLocation = UniversalLocation; - type MaxAssetsForTransfer = MaxAssetsForTransfer; - type ReserveProvider = AbsoluteReserveProvider; -} +// impl orml_xtokens::Config for Runtime { +// type RuntimeEvent = RuntimeEvent; +// type Balance = Balance; +// type CurrencyId = CurrencyId; +// type CurrencyIdConvert = CurrencyIdConvert; +// type AccountIdToMultiLocation = AccountIdToMultiLocation; +// type SelfLocation = SelfLocation; +// type MultiLocationsFilter = ParentOrParachains; +// type MinXcmFee = ParachainMinFee; +// type XcmExecutor = XcmExecutor; +// type Weigher = FixedWeightBounds; +// type BaseXcmWeight = BaseXcmWeight; +// type UniversalLocation = UniversalLocation; +// type MaxAssetsForTransfer = MaxAssetsForTransfer; +// type ReserveProvider = AbsoluteReserveProvider; +// } -impl orml_xcm::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type SovereignOrigin = EnsureRoot; -} +// impl orml_xcm::Config for Runtime { +// type RuntimeEvent = RuntimeEvent; +// type SovereignOrigin = EnsureRoot; +// } -type Block = frame_system::mocking::MockBlock; -construct_runtime!( - pub enum Runtime { - System: frame_system, - Balances: pallet_balances, - ParachainInfo: parachain_info, - XcmpQueue: cumulus_pallet_xcmp_queue, - DmpQueue: cumulus_pallet_dmp_queue, - CumulusXcm: cumulus_pallet_xcm, - Tokens: orml_tokens, - XTokens: orml_xtokens, - PolkadotXcm: pallet_xcm, - OrmlXcm: orml_xcm, - } -);