Skip to content

Commit a75ef03

Browse files
authored
Add statemint as trustable chain for pendulum + integration tests (#192)
* update pendulum runtime to support XCM reserve transfer for USDT * add pendulum integration tests for XCM (#190) add pendulum integration tests * add polkadot runtime to integration tests * add xcm test configuration * fix type XcmConfig instead of XCMConfig * add relay chain + parachain base integration tests * add Pendulum parachain to decl_test_network in xcm integration tests * Configure pendulum runtime for xcm simulator (#193) configure pendulum runtime for xcm simulator * Add xcm tests for pendulum (#195) * finished configuration of polkadot + pendulum TestNet * add transfer_ksm_from_relay_chain_to_pendulum * add unit tests to integration * use xcm emulator instead of xcm simulator from polkadot repo. (#194) * transfer_polkadot_from_relay_chain_to_pendulum works * added test for transfer polkadot_from_pendulum_to_relay_chain * Statemint integration tests to cover USDT bidirectional reserve transfer Pendulum <-> Statemint (#196) * add statemint-runtime to integration tests * add Statemint to RelayNet as system chain 1000 * add statemine_transfer_asset_to_pendulum unit tests * check BOB balance in statemine_transfer_asset_to_pendulum test * add statemine_transfer_asset_to_statemint * rename statemine to statemint. because this is tests for polkadot net * add statemint_transfer_incorrect_asset_to_pendulum_fails * move pendulum and statemint configuration from lib.rs to setup.rs * move test from lib.rs to test.rs * move polkadot net configuration to polkadot_test_net * split tests, setup and polkadot_test_net to different files * remove unused import in all files * rename to pendulum-runtime-integration-tests * Revert "rename to pendulum-runtime-integration-tests" This reverts commit 2f18be6. * rename to runtime-integration-tests * Final refactor xcm integration tests (#198) * rename dot function ot one * refactor setup rs file * add #[cfg(test)] attribute for all modules * add comments about fees and rename TEN to TEN_UNITS * update comment and constants name to show what is it * wrap Parachain into X1 to have the same approach everywhere * update transfer_dot_from_pendulum_to_relay_chain assert statement * add. comment statemint_transfer_incorrect_asset_to_pendulum_should_fails * add comment statemint_transfer_asset_to_statemint * move use pendulum_runtime::{RuntimeEvent, System}; to top of the file * move comment up function statemint_transfer_incorrect_asset_to_pendulum * renamed to renamed to fn units(amount) * wrap AccountId32 to X1 when call reserve_transfer_assets * make Foucoco xcm config identical to pendulum runtime (#199) make foucoco xcm config identical to pendulum runtime * remove duplicate of "runtime/development"
1 parent 1dbf537 commit a75ef03

File tree

10 files changed

+1241
-228
lines changed

10 files changed

+1241
-228
lines changed

Cargo.lock

Lines changed: 523 additions & 214 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ members = [
1111
"runtime/foucoco",
1212
"runtime/pendulum",
1313
"runtime/development",
14+
"runtime/integration-tests/pendulum",
1415
]

runtime/foucoco/src/xcm_config.rs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,23 @@ use frame_support::{
77
log, match_types, parameter_types,
88
traits::{Everything, Nothing},
99
};
10-
use orml_traits::{location::AbsoluteReserveProvider, parameter_type_with_key};
10+
use orml_traits::{
11+
location::{RelativeReserveProvider, Reserve},
12+
parameter_type_with_key,
13+
};
1114
use pallet_xcm::XcmPassthrough;
1215
use polkadot_parachain::primitives::Sibling;
1316
use polkadot_runtime_common::impls::ToAuthor;
1417
use sp_runtime::traits::Convert;
1518
use xcm::latest::{prelude::*, Weight as XCMWeight};
1619
use xcm_builder::{
1720
AccountId32Aliases, AllowUnpaidExecutionFrom, ConvertedConcreteAssetId, EnsureXcmOrigin,
18-
FixedWeightBounds, FungiblesAdapter, LocationInverter, NativeAsset, ParentIsPreset,
19-
RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
20-
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, UsingComponents,
21+
FixedWeightBounds, FungiblesAdapter, LocationInverter, ParentIsPreset, RelayChainAsNative,
22+
SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
23+
SignedToAccountId32, SovereignSignedViaLocation, UsingComponents,
2124
};
2225
use xcm_executor::{
23-
traits::{JustTry, ShouldExecute},
26+
traits::{FilterAssetLocation, JustTry, ShouldExecute},
2427
XcmExecutor,
2528
};
2629

@@ -94,6 +97,23 @@ impl xcm_executor::traits::Convert<MultiLocation, CurrencyId> for CurrencyIdConv
9497
}
9598
}
9699

100+
/// A `FilterAssetLocation` implementation. Filters multi native assets whose
101+
/// reserve is same with `origin`.
102+
pub struct MultiNativeAsset<ReserveProvider>(PhantomData<ReserveProvider>);
103+
impl<ReserveProvider> FilterAssetLocation for MultiNativeAsset<ReserveProvider>
104+
where
105+
ReserveProvider: Reserve,
106+
{
107+
fn filter_asset_location(asset: &MultiAsset, origin: &MultiLocation) -> bool {
108+
if let Some(ref reserve) = ReserveProvider::reserve(asset) {
109+
if reserve == origin {
110+
return true
111+
}
112+
}
113+
false
114+
}
115+
}
116+
97117
/// Means for transacting the fungibles assets of ths parachain.
98118
pub type FungiblesTransactor = FungiblesAdapter<
99119
// Use this fungibles implementation
@@ -220,7 +240,7 @@ impl xcm_executor::Config for XcmConfig {
220240
// How to withdraw and deposit an asset.
221241
type AssetTransactor = FungiblesTransactor;
222242
type OriginConverter = XcmOriginToTransactDispatchOrigin;
223-
type IsReserve = NativeAsset;
243+
type IsReserve = MultiNativeAsset<RelativeReserveProvider>;
224244
type IsTeleporter = (); // Teleporting is disabled.
225245
type LocationInverter = LocationInverter<Ancestry>;
226246
type Barrier = Barrier;
@@ -286,7 +306,7 @@ impl orml_xtokens::Config for Runtime {
286306
type MaxAssetsForTransfer = MaxAssetsForTransfer;
287307
type MinXcmFee = ParachainMinFee; //TODO to support hrmp transfer beetween parachain adjust this parameter
288308
type MultiLocationsFilter = Everything;
289-
type ReserveProvider = AbsoluteReserveProvider;
309+
type ReserveProvider = RelativeReserveProvider;
290310
}
291311

292312
pub struct AccountIdToMultiLocation;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[package]
2+
name = "runtime-integration-tests"
3+
description = "Pendulum runtime integration tests"
4+
authors = ["Pendulum"]
5+
edition = "2021"
6+
version = "0.1.0"
7+
8+
[dependencies]
9+
codec = { package = "parity-scale-codec", version = "3.0.0" }
10+
scale-info = { version = "2.1.2", features = ["derive"] }
11+
12+
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
13+
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
14+
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
15+
sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
16+
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
17+
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
18+
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
19+
parachain-info = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
20+
21+
xcm-simulator = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" }
22+
xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" }
23+
xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" }
24+
xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" }
25+
pallet-xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" }
26+
polkadot-core-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" }
27+
polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" }
28+
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" }
29+
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" }
30+
polkadot-runtime = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" }
31+
polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" }
32+
33+
xcm-emulator = { git = "https://github.com/shaunxw/xcm-simulator", rev = "6847a58888e483f0ed2e0b72f90e00767ea0ecac" }
34+
35+
orml-tokens = {git = "https://github.com/open-web3-stack/open-runtime-module-library.git", default-features = false, branch = "polkadot-v0.9.37" }
36+
cumulus-pallet-dmp-queue = {git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.37"}
37+
orml-xtokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, branch = "polkadot-v0.9.37" }
38+
pendulum-runtime = { path = "../../pendulum"}
39+
40+
statemint-runtime = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
41+
42+
cumulus-pallet-xcmp-queue = {git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.37"}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#[cfg(test)]
2+
mod polkadot_test_net;
3+
4+
#[cfg(test)]
5+
mod setup;
6+
7+
#[cfg(test)]
8+
mod tests;
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
use crate::setup::{units, ExtBuilderPendulum, ExtStatemintBuilder, ALICE, BOB};
2+
use frame_support::traits::GenesisBuild;
3+
use polkadot_core_primitives::{AccountId, BlockNumber};
4+
use polkadot_parachain::primitives::Id as ParaId;
5+
use polkadot_primitives::v2::{MAX_CODE_SIZE, MAX_POV_SIZE};
6+
use polkadot_runtime_parachains::configuration::HostConfiguration;
7+
use sp_runtime::traits::AccountIdConversion;
8+
use xcm_emulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, Weight};
9+
10+
decl_test_relay_chain! {
11+
pub struct Relay {
12+
Runtime = polkadot_runtime::Runtime,
13+
XcmConfig = polkadot_runtime::xcm_config::XcmConfig,
14+
new_ext = relay_ext(),
15+
}
16+
}
17+
18+
decl_test_parachain! {
19+
pub struct PendulumParachain {
20+
Runtime = pendulum_runtime::Runtime,
21+
RuntimeOrigin = pendulum_runtime::RuntimeOrigin,
22+
XcmpMessageHandler = pendulum_runtime::XcmpQueue,
23+
DmpMessageHandler = pendulum_runtime::DmpQueue,
24+
new_ext = para_ext_pendulum(2094),
25+
}
26+
}
27+
28+
decl_test_parachain! {
29+
pub struct Statemint {
30+
Runtime = statemint_runtime::Runtime,
31+
RuntimeOrigin = statemint_runtime::RuntimeOrigin,
32+
XcmpMessageHandler = statemint_runtime::XcmpQueue,
33+
DmpMessageHandler = statemint_runtime::DmpQueue,
34+
new_ext = para_ext_statemint(1000),
35+
}
36+
}
37+
38+
decl_test_network! {
39+
pub struct MockNet {
40+
relay_chain = Relay,
41+
parachains = vec![
42+
(1000, Statemint),
43+
(2094, PendulumParachain),
44+
],
45+
}
46+
}
47+
48+
pub fn para_account_id(id: u32) -> polkadot_core_primitives::AccountId {
49+
ParaId::from(id).into_account_truncating()
50+
}
51+
52+
pub fn relay_ext() -> sp_io::TestExternalities {
53+
use polkadot_runtime::{Runtime, System};
54+
let mut t = frame_system::GenesisConfig::default().build_storage::<Runtime>().unwrap();
55+
pallet_balances::GenesisConfig::<Runtime> {
56+
balances: vec![
57+
(AccountId::from(ALICE), units(100000)),
58+
(AccountId::from(BOB), units(100)),
59+
(para_account_id(2094), 10 * units(100000)),
60+
],
61+
}
62+
.assimilate_storage(&mut t)
63+
.unwrap();
64+
polkadot_runtime_parachains::configuration::GenesisConfig::<Runtime> {
65+
config: default_parachains_host_configuration(),
66+
}
67+
.assimilate_storage(&mut t)
68+
.unwrap();
69+
<pallet_xcm::GenesisConfig as GenesisBuild<Runtime>>::assimilate_storage(
70+
&pallet_xcm::GenesisConfig { safe_xcm_version: Some(2) },
71+
&mut t,
72+
)
73+
.unwrap();
74+
let mut ext = sp_io::TestExternalities::new(t);
75+
ext.execute_with(|| System::set_block_number(1));
76+
ext
77+
}
78+
79+
fn default_parachains_host_configuration() -> HostConfiguration<BlockNumber> {
80+
HostConfiguration {
81+
minimum_validation_upgrade_delay: 5,
82+
validation_upgrade_cooldown: 5u32,
83+
validation_upgrade_delay: 5,
84+
code_retention_period: 1200,
85+
max_code_size: MAX_CODE_SIZE,
86+
max_pov_size: MAX_POV_SIZE,
87+
max_head_data_size: 32 * 1024,
88+
group_rotation_frequency: 20,
89+
chain_availability_period: 4,
90+
thread_availability_period: 4,
91+
max_upward_queue_count: 8,
92+
max_upward_queue_size: 1024 * 1024,
93+
max_downward_message_size: 1024,
94+
ump_service_total_weight: Weight::from_ref_time(4 * 1_000_000_000),
95+
max_upward_message_size: 50 * 1024,
96+
max_upward_message_num_per_candidate: 5,
97+
hrmp_sender_deposit: 0,
98+
hrmp_recipient_deposit: 0,
99+
hrmp_channel_max_capacity: 8,
100+
hrmp_channel_max_total_size: 8 * 1024,
101+
hrmp_max_parachain_inbound_channels: 4,
102+
hrmp_max_parathread_inbound_channels: 4,
103+
hrmp_channel_max_message_size: 1024 * 1024,
104+
hrmp_max_parachain_outbound_channels: 4,
105+
hrmp_max_parathread_outbound_channels: 4,
106+
hrmp_max_message_num_per_candidate: 5,
107+
dispute_period: 6,
108+
no_show_slots: 2,
109+
n_delay_tranches: 25,
110+
needed_approvals: 2,
111+
relay_vrf_modulo_samples: 2,
112+
zeroth_delay_tranche_width: 0,
113+
..Default::default()
114+
}
115+
}
116+
117+
pub fn para_ext_pendulum(parachain_id: u32) -> sp_io::TestExternalities {
118+
ExtBuilderPendulum::default()
119+
.balances(vec![])
120+
.parachain_id(parachain_id)
121+
.build()
122+
}
123+
124+
pub fn para_ext_statemint(parachain_id: u32) -> sp_io::TestExternalities {
125+
ExtStatemintBuilder::default()
126+
.balances(vec![])
127+
.parachain_id(parachain_id)
128+
.build()
129+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
use frame_support::traits::GenesisBuild;
2+
use pendulum_runtime::{PendulumCurrencyId, Runtime, System};
3+
use polkadot_core_primitives::{AccountId, Balance};
4+
5+
pub fn units(amount: Balance) -> Balance {
6+
amount * 10u128.saturating_pow(9)
7+
}
8+
9+
pub const ALICE: [u8; 32] = [4u8; 32];
10+
pub const BOB: [u8; 32] = [5u8; 32];
11+
pub const INITIAL_BALANCE: u128 = 1_000_000_000;
12+
13+
pub struct ExtBuilderPendulum {
14+
balances: Vec<(AccountId, PendulumCurrencyId, Balance)>,
15+
parachain_id: u32,
16+
}
17+
18+
impl Default for ExtBuilderPendulum {
19+
fn default() -> Self {
20+
Self { balances: vec![], parachain_id: 2094 }
21+
}
22+
}
23+
24+
impl ExtBuilderPendulum {
25+
pub fn balances(mut self, balances: Vec<(AccountId, PendulumCurrencyId, Balance)>) -> Self {
26+
self.balances = balances;
27+
self
28+
}
29+
30+
pub fn parachain_id(mut self, parachain_id: u32) -> Self {
31+
self.parachain_id = parachain_id;
32+
self
33+
}
34+
35+
pub fn build(self) -> sp_io::TestExternalities {
36+
let mut t = frame_system::GenesisConfig::default().build_storage::<Runtime>().unwrap();
37+
pallet_balances::GenesisConfig::<Runtime> {
38+
balances: vec![
39+
(AccountId::from(ALICE), INITIAL_BALANCE),
40+
(AccountId::from(BOB), INITIAL_BALANCE),
41+
],
42+
}
43+
.assimilate_storage(&mut t)
44+
.unwrap();
45+
46+
orml_tokens::GenesisConfig::<Runtime> {
47+
balances: vec![(AccountId::from(BOB), PendulumCurrencyId::XCM(0), units(100))],
48+
}
49+
.assimilate_storage(&mut t)
50+
.unwrap();
51+
<parachain_info::GenesisConfig as GenesisBuild<Runtime>>::assimilate_storage(
52+
&parachain_info::GenesisConfig { parachain_id: self.parachain_id.into() },
53+
&mut t,
54+
)
55+
.unwrap();
56+
<pallet_xcm::GenesisConfig as GenesisBuild<Runtime>>::assimilate_storage(
57+
&pallet_xcm::GenesisConfig { safe_xcm_version: Some(2) },
58+
&mut t,
59+
)
60+
.unwrap();
61+
let mut ext = sp_io::TestExternalities::new(t);
62+
ext.execute_with(|| System::set_block_number(1));
63+
ext
64+
}
65+
}
66+
67+
pub struct ExtStatemintBuilder {
68+
balances: Vec<(AccountId, u128, Balance)>,
69+
parachain_id: u32,
70+
}
71+
72+
impl Default for ExtStatemintBuilder {
73+
fn default() -> Self {
74+
Self { balances: vec![], parachain_id: 1000 }
75+
}
76+
}
77+
78+
impl ExtStatemintBuilder {
79+
pub fn balances(mut self, balances: Vec<(AccountId, u128, Balance)>) -> Self {
80+
self.balances = balances;
81+
self
82+
}
83+
84+
#[allow(dead_code)]
85+
pub fn parachain_id(mut self, parachain_id: u32) -> Self {
86+
self.parachain_id = parachain_id;
87+
self
88+
}
89+
90+
pub fn build(self) -> sp_io::TestExternalities {
91+
use statemint_runtime::Runtime as StatemintRuntime;
92+
93+
let mut t = frame_system::GenesisConfig::default()
94+
.build_storage::<StatemintRuntime>()
95+
.unwrap();
96+
97+
pallet_balances::GenesisConfig::<StatemintRuntime> { balances: vec![] }
98+
.assimilate_storage(&mut t)
99+
.unwrap();
100+
101+
<parachain_info::GenesisConfig as GenesisBuild<StatemintRuntime>>::assimilate_storage(
102+
&parachain_info::GenesisConfig { parachain_id: self.parachain_id.into() },
103+
&mut t,
104+
)
105+
.unwrap();
106+
107+
<pallet_xcm::GenesisConfig as GenesisBuild<Runtime>>::assimilate_storage(
108+
&pallet_xcm::GenesisConfig { safe_xcm_version: Some(2) },
109+
&mut t,
110+
)
111+
.unwrap();
112+
113+
let mut ext = sp_io::TestExternalities::new(t);
114+
ext.execute_with(|| System::set_block_number(1));
115+
ext
116+
}
117+
}

0 commit comments

Comments
 (0)