Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add statemint as trustable chain for pendulum + integration tests #192

Merged
merged 19 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
73a4799
update pendulum runtime to support XCM reserve transfer for USDT
RustNinja Mar 29, 2023
0761f1a
add pendulum integration tests for XCM (#190)
RustNinja Mar 29, 2023
08a81de
add polkadot runtime to integration tests
RustNinja Mar 29, 2023
2717818
add xcm test configuration
RustNinja Mar 29, 2023
1c9aad6
fix type XcmConfig instead of XCMConfig
RustNinja Mar 29, 2023
cb5346a
add relay chain + parachain base integration tests
RustNinja Mar 29, 2023
8396e3f
add Pendulum parachain to decl_test_network in xcm integration tests
RustNinja Mar 29, 2023
e4b60ce
Configure pendulum runtime for xcm simulator (#193)
RustNinja Mar 31, 2023
82e3409
Add xcm tests for pendulum (#195)
RustNinja Mar 31, 2023
54fa5dd
added test for transfer polkadot_from_pendulum_to_relay_chain
RustNinja Apr 3, 2023
75b0c81
Statemint integration tests to cover USDT bidirectional reserve trans…
RustNinja Apr 4, 2023
c41a382
rename to runtime-integration-tests
RustNinja Apr 4, 2023
741ae7d
Final refactor xcm integration tests (#198)
RustNinja Apr 5, 2023
039bdbd
move comment up function statemint_transfer_incorrect_asset_to_pendulum
RustNinja Apr 6, 2023
79a7c99
renamed to renamed to fn units(amount)
RustNinja Apr 6, 2023
0471cad
wrap AccountId32 to X1 when call reserve_transfer_assets
RustNinja Apr 6, 2023
0f42bd0
Merge remote-tracking branch 'origin/main' into add-statemint-as-trus…
RustNinja Apr 6, 2023
63b8975
make Foucoco xcm config identical to pendulum runtime (#199)
RustNinja Apr 6, 2023
35386bc
remove duplicate of "runtime/development"
RustNinja Apr 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
737 changes: 523 additions & 214 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ members = [
"runtime/foucoco",
"runtime/pendulum",
"runtime/development",
"runtime/development",
RustNinja marked this conversation as resolved.
Show resolved Hide resolved
"runtime/integration-tests/pendulum",
]
42 changes: 42 additions & 0 deletions runtime/integration-tests/pendulum/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[package]
name = "runtime-integration-tests"
description = "Pendulum runtime integration tests"
authors = ["Pendulum"]
edition = "2021"
version = "0.1.0"

[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0" }
scale-info = { version = "2.1.2", features = ["derive"] }

frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
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" }
xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" }
xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" }
pallet-xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" }
polkadot-core-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" }
polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" }
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" }
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" }
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" }

xcm-emulator = { git = "https://github.com/shaunxw/xcm-simulator", rev = "6847a58888e483f0ed2e0b72f90e00767ea0ecac" }

orml-tokens = {git = "https://github.com/open-web3-stack/open-runtime-module-library.git", default-features = false, branch = "polkadot-v0.9.37" }
cumulus-pallet-dmp-queue = {git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.37"}
orml-xtokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, branch = "polkadot-v0.9.37" }
pendulum-runtime = { path = "../../pendulum"}

statemint-runtime = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }

cumulus-pallet-xcmp-queue = {git = "https://github.com/paritytech/cumulus", default-features = false, branch = "polkadot-v0.9.37"}
8 changes: 8 additions & 0 deletions runtime/integration-tests/pendulum/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#[cfg(test)]
mod polkadot_test_net;

#[cfg(test)]
mod setup;

#[cfg(test)]
mod tests;
129 changes: 129 additions & 0 deletions runtime/integration-tests/pendulum/src/polkadot_test_net.rs
ebma marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
use crate::setup::{one, ExtBuilderPendulum, ExtStatemintBuilder, ALICE, BOB};
use frame_support::traits::GenesisBuild;
use polkadot_core_primitives::{AccountId, 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_emulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, Weight};

decl_test_relay_chain! {
pub struct Relay {
Runtime = polkadot_runtime::Runtime,
XcmConfig = polkadot_runtime::xcm_config::XcmConfig,
new_ext = relay_ext(),
}
}

decl_test_parachain! {
pub struct PendulumParachain {
Runtime = pendulum_runtime::Runtime,
RuntimeOrigin = pendulum_runtime::RuntimeOrigin,
XcmpMessageHandler = pendulum_runtime::XcmpQueue,
DmpMessageHandler = pendulum_runtime::DmpQueue,
new_ext = para_ext_pendulum(2094),
}
}

decl_test_parachain! {
pub struct Statemint {
Runtime = statemint_runtime::Runtime,
RuntimeOrigin = statemint_runtime::RuntimeOrigin,
XcmpMessageHandler = statemint_runtime::XcmpQueue,
DmpMessageHandler = statemint_runtime::DmpQueue,
new_ext = para_ext_statemint(1000),
}
}

decl_test_network! {
pub struct MockNet {
relay_chain = Relay,
parachains = vec![
(1000, Statemint),
(2094, PendulumParachain),
],
}
}

pub fn para_account_id(id: u32) -> polkadot_core_primitives::AccountId {
ParaId::from(id).into_account_truncating()
}

pub fn relay_ext() -> sp_io::TestExternalities {
use polkadot_runtime::{Runtime, System};
let mut t = frame_system::GenesisConfig::default().build_storage::<Runtime>().unwrap();
pallet_balances::GenesisConfig::<Runtime> {
balances: vec![
(AccountId::from(ALICE), one(100000)),
(AccountId::from(BOB), one(100)),
(para_account_id(2094), 10 * one(100000)),
],
}
.assimilate_storage(&mut t)
.unwrap();
polkadot_runtime_parachains::configuration::GenesisConfig::<Runtime> {
config: default_parachains_host_configuration(),
}
.assimilate_storage(&mut t)
.unwrap();
<pallet_xcm::GenesisConfig as GenesisBuild<Runtime>>::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<BlockNumber> {
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 fn para_ext_pendulum(parachain_id: u32) -> sp_io::TestExternalities {
ExtBuilderPendulum::default()
.balances(vec![])
.parachain_id(parachain_id)
.build()
}

pub fn para_ext_statemint(parachain_id: u32) -> sp_io::TestExternalities {
ExtStatemintBuilder::default()
.balances(vec![])
.parachain_id(parachain_id)
.build()
}
117 changes: 117 additions & 0 deletions runtime/integration-tests/pendulum/src/setup.rs
ebma marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
use frame_support::traits::GenesisBuild;
use pendulum_runtime::{PendulumCurrencyId, Runtime, System};
use polkadot_core_primitives::{AccountId, Balance};

pub fn one(amount: Balance) -> Balance {
amount * 10u128.saturating_pow(9)
ebma marked this conversation as resolved.
Show resolved Hide resolved
}

pub const ALICE: [u8; 32] = [4u8; 32];
pub const BOB: [u8; 32] = [5u8; 32];
pub const INITIAL_BALANCE: u128 = 1_000_000_000;

pub struct ExtBuilderPendulum {
balances: Vec<(AccountId, PendulumCurrencyId, Balance)>,
parachain_id: u32,
}

impl Default for ExtBuilderPendulum {
fn default() -> Self {
Self { balances: vec![], parachain_id: 2094 }
}
}

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::<Runtime>().unwrap();
pallet_balances::GenesisConfig::<Runtime> {
balances: vec![
(AccountId::from(ALICE), INITIAL_BALANCE),
(AccountId::from(BOB), INITIAL_BALANCE),
],
}
.assimilate_storage(&mut t)
.unwrap();

orml_tokens::GenesisConfig::<Runtime> {
balances: vec![(AccountId::from(BOB), PendulumCurrencyId::XCM(0), one(100))],
}
.assimilate_storage(&mut t)
.unwrap();
<parachain_info::GenesisConfig as GenesisBuild<Runtime>>::assimilate_storage(
&parachain_info::GenesisConfig { parachain_id: self.parachain_id.into() },
&mut t,
)
.unwrap();
<pallet_xcm::GenesisConfig as GenesisBuild<Runtime>>::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
}
}

pub struct ExtStatemintBuilder {
balances: Vec<(AccountId, u128, Balance)>,
parachain_id: u32,
}

impl Default for ExtStatemintBuilder {
fn default() -> Self {
Self { balances: vec![], parachain_id: 1000 }
}
}

impl ExtStatemintBuilder {
pub fn balances(mut self, balances: Vec<(AccountId, u128, Balance)>) -> Self {
self.balances = balances;
self
}

#[allow(dead_code)]
pub fn parachain_id(mut self, parachain_id: u32) -> Self {
self.parachain_id = parachain_id;
self
}

pub fn build(self) -> sp_io::TestExternalities {
use statemint_runtime::Runtime as StatemintRuntime;

let mut t = frame_system::GenesisConfig::default()
.build_storage::<StatemintRuntime>()
.unwrap();

pallet_balances::GenesisConfig::<StatemintRuntime> { balances: vec![] }
.assimilate_storage(&mut t)
.unwrap();

<parachain_info::GenesisConfig as GenesisBuild<StatemintRuntime>>::assimilate_storage(
&parachain_info::GenesisConfig { parachain_id: self.parachain_id.into() },
&mut t,
)
.unwrap();

<pallet_xcm::GenesisConfig as GenesisBuild<Runtime>>::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
}
}
Loading