diff --git a/Cargo.lock b/Cargo.lock index c09b8391b..0758095c5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14357,6 +14357,7 @@ dependencies = [ "frame-system", "pallet-balances", "pallet-xcm", + "parachain-info", "parity-scale-codec", "pendulum-runtime", "polkadot-core-primitives", diff --git a/runtime/integration-tests/pendulum/Cargo.toml b/runtime/integration-tests/pendulum/Cargo.toml index 930184425..af93a70f1 100644 --- a/runtime/integration-tests/pendulum/Cargo.toml +++ b/runtime/integration-tests/pendulum/Cargo.toml @@ -16,6 +16,7 @@ sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } +parachain-info = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" } xcm-simulator = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } @@ -29,4 +30,5 @@ polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = polkadot-runtime = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } + pendulum-runtime = { path = "../../pendulum"} diff --git a/runtime/integration-tests/pendulum/src/lib.rs b/runtime/integration-tests/pendulum/src/lib.rs index 7dcd384b5..f4d04909d 100644 --- a/runtime/integration-tests/pendulum/src/lib.rs +++ b/runtime/integration-tests/pendulum/src/lib.rs @@ -1,9 +1,14 @@ // mod parachain; // mod relay_chain; +use frame_support::traits::GenesisBuild; +use pendulum_runtime::{PendulumCurrencyId, Runtime, System}; +use polkadot_core_primitives::{AccountId, Balance, BlockNumber}; use polkadot_parachain::primitives::Id as ParaId; +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 xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, Weight}; pub const ALICE: sp_runtime::AccountId32 = sp_runtime::AccountId32::new([0u8; 32]); pub const INITIAL_BALANCE: u128 = 1_000_000_000; @@ -13,7 +18,7 @@ decl_test_parachain! { Runtime = pendulum_runtime::Runtime, XcmpMessageHandler = pendulum_runtime::XcmpQueue, DmpMessageHandler = pendulum_runtime::DmpQueue, - new_ext = para_ext(1), + new_ext = para_ext_pendulum(1234), } } @@ -29,7 +34,7 @@ decl_test_network! { pub struct MockNet { relay_chain = Relay, parachains = vec![ - (1, PendulumParachain), + (1234, PendulumParachain), // (2, Statemint), ], } @@ -64,8 +69,8 @@ pub fn relay_ext() -> sp_io::TestExternalities { pallet_balances::GenesisConfig:: { balances: vec![ - // (ALICE, INITIAL_BALANCE), (para_account_id(1), INITIAL_BALANCE) - ], + // (ALICE, INITIAL_BALANCE), (para_account_id(1), INITIAL_BALANCE) + ], } .assimilate_storage(&mut t) .unwrap(); @@ -75,12 +80,100 @@ pub fn relay_ext() -> sp_io::TestExternalities { ext } +pub struct ExtBuilderPendulum { + balances: Vec<(AccountId, PendulumCurrencyId, Balance)>, + parachain_id: u32, +} +impl Default for ExtBuilderPendulum { + fn default() -> Self { + Self { balances: vec![], parachain_id: 1234 } + } +} + +pub fn para_ext_pendulum(parachain_id: u32) -> sp_io::TestExternalities { + ExtBuilderPendulum::default() + .balances(vec![]) + .parachain_id(parachain_id) + .build() +} + +impl ExtBuilderPendulum { + pub fn balances(mut self, balances: Vec<(AccountId, PendulumCurrencyId, Balance)>) -> Self { + self.balances = balances; + self + } + pub fn parachain_id(mut self, parachain_id: u32) -> Self { + self.parachain_id = parachain_id; + self + } + pub fn build(self) -> sp_io::TestExternalities { + let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); + // let native_currency_id = Pendulum_runtime::Native::get(); + pallet_balances::GenesisConfig:: { + balances: vec![(AccountId::from(ALICE), INITIAL_BALANCE)], + } + .assimilate_storage(&mut t) + .unwrap(); + >::assimilate_storage( + ¶chain_info::GenesisConfig { parachain_id: self.parachain_id.into() }, + &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 + } +} + +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() + } +} + // pub type RelayChainPalletXcm = pallet_xcm::Pallet; // pub type ParachainPalletXcm = pallet_xcm::Pallet; #[cfg(test)] mod tests { - #[test] + #[test] fn dmp() {} } diff --git a/runtime/pendulum/src/lib.rs b/runtime/pendulum/src/lib.rs index 6a9cd32a3..a6490a8e0 100644 --- a/runtime/pendulum/src/lib.rs +++ b/runtime/pendulum/src/lib.rs @@ -14,6 +14,7 @@ use crate::zenlink::*; use xcm::v1::MultiLocation; use zenlink_protocol::{AssetBalance, MultiAssetsHandler, PairInfo}; +pub use currency::CurrencyId as PendulumCurrencyId; pub use parachain_staking::InflationInfo; use codec::Encode; diff --git a/runtime/pendulum/src/xcm_config.rs b/runtime/pendulum/src/xcm_config.rs index 8450aa20e..460d81a29 100644 --- a/runtime/pendulum/src/xcm_config.rs +++ b/runtime/pendulum/src/xcm_config.rs @@ -7,7 +7,10 @@ use frame_support::{ log, match_types, parameter_types, traits::{Everything, Nothing}, }; -use orml_traits::{location::{RelativeReserveProvider, Reserve}, parameter_type_with_key}; +use orml_traits::{ + location::{RelativeReserveProvider, Reserve}, + parameter_type_with_key, +}; use pallet_xcm::XcmPassthrough; use polkadot_parachain::primitives::Sibling; use polkadot_runtime_common::impls::ToAuthor; @@ -16,12 +19,12 @@ use sp_runtime::traits::Convert; use xcm::latest::{prelude::*, Weight as XCMWeight}; use xcm_builder::{ AccountId32Aliases, AllowUnpaidExecutionFrom, ConvertedConcreteAssetId, EnsureXcmOrigin, - FixedWeightBounds, FungiblesAdapter, LocationInverter, ParentIsPreset, - RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, - SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, UsingComponents, + FixedWeightBounds, FungiblesAdapter, LocationInverter, ParentIsPreset, RelayChainAsNative, + SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, + SignedToAccountId32, SovereignSignedViaLocation, UsingComponents, }; use xcm_executor::{ - traits::{JustTry, ShouldExecute, FilterAssetLocation}, + traits::{FilterAssetLocation, JustTry, ShouldExecute}, XcmExecutor, }; @@ -124,7 +127,7 @@ where fn filter_asset_location(asset: &MultiAsset, origin: &MultiLocation) -> bool { if let Some(ref reserve) = ReserveProvider::reserve(asset) { if reserve == origin { - return true; + return true } } false