Skip to content

Commit

Permalink
test: interlay xcm tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sander2 committed Jun 20, 2022
1 parent 6fe09cb commit 1bdd11a
Show file tree
Hide file tree
Showing 8 changed files with 1,288 additions and 176 deletions.
355 changes: 185 additions & 170 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions parachain/runtime/runtime-tests/Cargo.toml
Expand Up @@ -53,6 +53,7 @@ pallet-society = { git = "https://github.com/paritytech/substrate", branch = "po
pallet-authorship = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24", default-features = false }
pallet-aura = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24", default-features = false }
sp-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24", default-features = false }
pallet-session = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24", default-features = false }

# Cumulus dependencies
cumulus-pallet-aura-ext = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.24", default-features = false }
Expand All @@ -72,6 +73,7 @@ polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch =
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.24", default-features = false }
polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.24", default-features = false }
kusama-runtime = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.24", default-features = false }
polkadot-runtime = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.24", default-features = false }
xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.24", default-features = false }
xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.24", default-features = false }
xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.24", default-features = false }
Expand All @@ -98,6 +100,7 @@ annuity = { path = "../../../crates/annuity", default-features = false }
supply = { path = "../../../crates/supply", default-features = false }

kintsugi-runtime-parachain = { path = "../kintsugi", default-features = false }
interlay-runtime-parachain = { path = "../interlay", default-features = false }
testnet-kintsugi-runtime-parachain = { path = "../testnet-kintsugi", default-features = false }
testnet-interlay-runtime-parachain = { path = "../testnet-interlay", default-features = false }

Expand Down Expand Up @@ -172,6 +175,7 @@ std = [

"pallet-authorship/std",
"pallet-aura/std",
"pallet-session/std",
"sp-consensus-aura/std",

"cumulus-pallet-aura-ext/std",
Expand All @@ -189,12 +193,14 @@ std = [
"polkadot-primitives/std",
"polkadot-runtime-parachains/std",
"kusama-runtime/std",
"polkadot-runtime/std",
"xcm/std",
"xcm-builder/std",
"xcm-executor/std",
"pallet-xcm/std",

"kintsugi-runtime-parachain/std",
"interlay-runtime-parachain/std",
"testnet-kintsugi-runtime-parachain/std",
"testnet-interlay-runtime-parachain/std",

Expand Down
1 change: 0 additions & 1 deletion parachain/runtime/runtime-tests/src/lib.rs
@@ -1,4 +1,3 @@
#![cfg(test)]

mod relaychain;
mod setup;
@@ -1,9 +1,14 @@
use crate::{relaychain::kusama_test_net::*, setup::*};
use crate::relaychain::kusama_test_net::*;
use codec::Encode;
use frame_support::{assert_ok, weights::WeightToFee};
use orml_traits::MultiCurrency;
use primitives::CurrencyId::Token;
use primitives::{
CurrencyId::{ForeignAsset, Token},
CustomMetadata,
};
use xcm::latest::prelude::*;
use xcm_builder::ParentIsPreset;
use xcm_emulator::TestExt;
use xcm_emulator::{TestExt, XcmExecutor};
use xcm_executor::traits::Convert;

mod hrmp {
Expand Down
91 changes: 89 additions & 2 deletions parachain/runtime/runtime-tests/src/relaychain/kusama_test_net.rs
@@ -1,10 +1,17 @@
use crate::setup::*;
use frame_support::traits::GenesisBuild;
pub use kintsugi_runtime_parachain::{xcm_config::*, *};
use polkadot_primitives::v2::{BlockNumber, MAX_CODE_SIZE, MAX_POV_SIZE};
use polkadot_runtime_parachains::configuration::HostConfiguration;
use primitives::CurrencyId::Token;
pub use primitives::{
CurrencyId::Token,
TokenSymbol::{KINT, KSM},
};
use sp_runtime::traits::AccountIdConversion;
use xcm_emulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain};

pub const KINTSUGI_PARA_ID: u32 = 2092;
pub const SIBLING_PARA_ID: u32 = 2001;

decl_test_relay_chain! {
pub struct KusamaNet {
Runtime = kusama_runtime::Runtime,
Expand Down Expand Up @@ -144,3 +151,83 @@ pub fn para_ext(parachain_id: u32) -> sp_io::TestExternalities {
.parachain_id(parachain_id)
.build()
}

#[allow(dead_code)]
pub const DEFAULT: [u8; 32] = [0u8; 32];
#[allow(dead_code)]
pub const ALICE: [u8; 32] = [4u8; 32];
#[allow(dead_code)]
pub const BOB: [u8; 32] = [5u8; 32];

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

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

impl ExtBuilder {
pub fn balances(mut self, balances: Vec<(AccountId, CurrencyId, 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 {
let mut t = frame_system::GenesisConfig::default()
.build_storage::<Runtime>()
.unwrap();

let native_currency_id = GetNativeCurrencyId::get();

orml_tokens::GenesisConfig::<Runtime> {
balances: self
.balances
.into_iter()
.filter(|(_, currency_id, _)| *currency_id != native_currency_id)
.collect::<Vec<_>>(),
}
.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(crate) fn kintsugi_sovereign_account_on_kusama() -> AccountId {
polkadot_parachain::primitives::Id::from(KINTSUGI_PARA_ID).into_account_truncating()
}

pub(crate) fn sibling_sovereign_account_on_kusama() -> AccountId {
polkadot_parachain::primitives::Id::from(SIBLING_PARA_ID).into_account_truncating()
}
2 changes: 2 additions & 0 deletions parachain/runtime/runtime-tests/src/relaychain/mod.rs
@@ -1,2 +1,4 @@
mod kusama_cross_chain_transfer;
pub mod kusama_test_net;
mod polkadot_cross_chain_transfer;
pub mod polkadot_test_net;

0 comments on commit 1bdd11a

Please sign in to comment.