Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Add-xcm-emulator-and-tests (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
metricaez authored Oct 31, 2023
1 parent a08df55 commit e51c1fe
Show file tree
Hide file tree
Showing 13 changed files with 2,962 additions and 77 deletions.
1,397 changes: 1,329 additions & 68 deletions Cargo.lock

Large diffs are not rendered by default.

28 changes: 21 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ members = [
"runtime/stout",
"runtime/trappist",
"primitives/xcm",
"integration-tests/emulated",
]
exclude = [
"xcm-simulator"
]
exclude = ["xcm-simulator"]
resolver = "2"

[profile.release]
Expand All @@ -34,13 +33,17 @@ license = "Apache License v2"
# common
async-trait = "0.1"
clap = { version = "4.3" }
parity-scale-codec = { version = "3.6", default-features = false, features = ["derive"] }
parity-scale-codec = { version = "3.6", default-features = false, features = [
"derive",
] }
futures = { version = "0.3" }
hex-literal = { version = "0.4" }
log = { version = "0.4" }
serde = { version = "1.0.186" }
serde_json = "1.0.104"
scale-info = { version = "2.9", default-features = false, features = ["derive"] }
scale-info = { version = "2.9", default-features = false, features = [
"derive",
] }
smallvec = "1.11"

# Local dependencies
Expand Down Expand Up @@ -159,7 +162,9 @@ cumulus-relay-chain-interface = { git = "https://github.com/paritytech/polkadot-
assets-common = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
cumulus-pallet-aura-ext = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false, features = [
"parameterized-consensus-hook",
] }
cumulus-pallet-xcm = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
cumulus-ping = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
Expand All @@ -171,8 +176,17 @@ parachains-common = { git = "https://github.com/paritytech/polkadot-sdk", branch
parachain-info = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
cumulus-pallet-session-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false, version = "3.0.0" }

# Cumulus Xcm Emulator
xcm-emulator = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
integration-tests-common = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
asset-hub-kusama-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
asset-hub-polkadot-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
rococo-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }

# Polkadot
polkadot-cli = { git = "https://github.com/paritytech/polkadot-sdk", features = ["rococo-native"], branch = "release-polkadot-v1.1.0" }
polkadot-cli = { git = "https://github.com/paritytech/polkadot-sdk", features = [
"rococo-native",
], branch = "release-polkadot-v1.1.0" }
polkadot-primitives = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
polkadot-service = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.1.0" }
Expand Down
59 changes: 59 additions & 0 deletions integration-tests/emulated/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[package]
name = "integration-tests"
version = "0.1.0"
edition = "2021"

[dependencies]
parity-scale-codec = { workspace = true }
thousands = "0.2.0"

# Tracing
tracing = { version = "0.1.37" }
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }

# Substrate
frame-system = { workspace = true }
frame-support = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
pallet-assets = { workspace = true }

# Cumulus
integration-tests-common = { workspace = true }
xcm-emulator = { workspace = true }

# Polkadot
polkadot-parachain-primitives = { workspace = true }
xcm = { workspace = true }
xcm-executor = { workspace = true }
pallet-xcm = { workspace = true }
xcm-primitives = { workspace = true }

# Runtimes
polkadot-runtime-common = { workspace = true }
parachains-common = { workspace = true }
rococo-runtime = { workspace = true }
asset-hub-kusama-runtime = { workspace = true }
asset-hub-polkadot-runtime = { workspace = true }
trappist-runtime = { path = "../../runtime/trappist" }
stout-runtime = { path = "../../runtime/stout" }

# Local
pallet-asset-registry = { workspace = true }

[features]
runtime-benchmarks = [
"polkadot-runtime-common/runtime-benchmarks",
"rococo-runtime/runtime-benchmarks",
"asset-hub-kusama-runtime/runtime-benchmarks",
"asset-hub-polkadot-runtime/runtime-benchmarks",
"trappist-runtime/runtime-benchmarks",
"stout-runtime/runtime-benchmarks",
"polkadot-parachain-primitives/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"integration-tests-common/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
]
216 changes: 216 additions & 0 deletions integration-tests/emulated/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
use parachains_common::Balance;
use sp_core::{sr25519, storage::Storage};
use sp_runtime::BuildStorage;
use xcm_emulator::{
decl_test_networks, decl_test_parachains, decl_test_relay_chains,
helpers::get_account_id_from_seed, DefaultMessageProcessor, Hooks, ParaId,
};

#[cfg(test)]
mod tests;

decl_test_relay_chains! {
// Rococo
#[api_version(5)]
pub struct Rococo {
genesis = integration_tests_common::constants::rococo::genesis(),
on_init = (),
runtime = rococo_runtime,
core = {
MessageProcessor: DefaultMessageProcessor<Rococo>,
SovereignAccountOf: rococo_runtime::xcm_config::LocationConverter,
},
pallets = {
XcmPallet: rococo_runtime::XcmPallet,
Sudo: rococo_runtime::Sudo,
Balances: rococo_runtime::Balances,
}
}
}

// Declare Parachains
decl_test_parachains! {
// Parachain A
pub struct Trappist {
genesis = para_a_genesis(),
on_init = {trappist_runtime::AuraExt::on_initialize(1);}
,
runtime = trappist_runtime,
core = {
XcmpMessageHandler: trappist_runtime::XcmpQueue,
DmpMessageHandler: trappist_runtime::DmpQueue,
LocationToAccountId: trappist_runtime::xcm_config::LocationToAccountId,
ParachainInfo: trappist_runtime::ParachainInfo,
},
pallets= {
XcmPallet: trappist_runtime::PolkadotXcm,
Assets: trappist_runtime::Assets,
Sudo: trappist_runtime::Sudo,
AssetRegistry: trappist_runtime::AssetRegistry,
Balances: trappist_runtime::Balances,
}
},
// Parachain B
pub struct Stout {
genesis = para_b_genesis(),
on_init = {stout_runtime::AuraExt::on_initialize(1);},
runtime = stout_runtime,
core = {
XcmpMessageHandler: stout_runtime::XcmpQueue,
DmpMessageHandler: stout_runtime::DmpQueue,
LocationToAccountId: stout_runtime::xcm_config::LocationToAccountId,
ParachainInfo: stout_runtime::ParachainInfo,
},
pallets= {
XcmPallet: stout_runtime::PolkadotXcm,
Assets: stout_runtime::Assets,
Sudo: stout_runtime::Sudo,
AssetRegistry: stout_runtime::AssetRegistry,
Balances: stout_runtime::Balances,
}
},

// AssetHub
pub struct AssetHubRococo {
genesis = integration_tests_common::constants::asset_hub_kusama::genesis(),
on_init = {
asset_hub_polkadot_runtime::AuraExt::on_initialize(1);
},
runtime = asset_hub_kusama_runtime,
core = {
XcmpMessageHandler: asset_hub_kusama_runtime::XcmpQueue,
DmpMessageHandler: asset_hub_kusama_runtime::DmpQueue,
LocationToAccountId: asset_hub_kusama_runtime::xcm_config::LocationToAccountId,
ParachainInfo: asset_hub_kusama_runtime::ParachainInfo,
},
pallets = {
PolkadotXcm: asset_hub_kusama_runtime::PolkadotXcm,
Assets: asset_hub_kusama_runtime::Assets,
Balances: asset_hub_kusama_runtime::Balances,
}
},
}

//Define network(s)
decl_test_networks! {
// Rococo
pub struct RococoMockNet {
relay_chain = Rococo,
parachains = vec![Trappist, Stout, AssetHubRococo,],
bridge = ()
}
}

fn para_a_genesis() -> Storage {
const PARA_ID: ParaId = ParaId::new(1836);
const ED: Balance = trappist_runtime::constants::currency::EXISTENTIAL_DEPOSIT;

let genesis_config = trappist_runtime::RuntimeGenesisConfig {
system: trappist_runtime::SystemConfig {
code: trappist_runtime::WASM_BINARY
.expect("WASM binary was not build, please build it!")
.to_vec(),
..Default::default()
},
balances: trappist_runtime::BalancesConfig {
balances: integration_tests_common::constants::accounts::init_balances()
.iter()
.cloned()
.map(|k| (k, ED * 1_000_000_000))
.collect(),
},
parachain_info: trappist_runtime::ParachainInfoConfig {
parachain_id: PARA_ID,
..Default::default()
},
collator_selection: trappist_runtime::CollatorSelectionConfig {
invulnerables:
integration_tests_common::constants::collators::invulnerables_asset_hub_polkadot()
.iter()
.cloned()
.map(|(acc, _)| acc)
.collect(),
candidacy_bond: ED * 16,
..Default::default()
},
session: trappist_runtime::SessionConfig {
keys: integration_tests_common::constants::collators::invulnerables()
.into_iter()
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc, // validator id
trappist_runtime::SessionKeys { aura }, // session keys
)
})
.collect(),
},
sudo: trappist_runtime::SudoConfig {
key: Some(get_account_id_from_seed::<sr25519::Public>("Alice")),
},
polkadot_xcm: trappist_runtime::PolkadotXcmConfig {
safe_xcm_version: Some(xcm::prelude::XCM_VERSION),
..Default::default()
},
..Default::default()
};

genesis_config.build_storage().unwrap()
}

fn para_b_genesis() -> Storage {
const PARA_ID: ParaId = ParaId::new(3000);
const ED: Balance = stout_runtime::constants::currency::EXISTENTIAL_DEPOSIT;

let genesis_config = stout_runtime::RuntimeGenesisConfig {
system: stout_runtime::SystemConfig {
code: stout_runtime::WASM_BINARY
.expect("WASM binary was not build, please build it!")
.to_vec(),
..Default::default()
},
balances: stout_runtime::BalancesConfig {
balances: integration_tests_common::constants::accounts::init_balances()
.iter()
.cloned()
.map(|k| (k, ED * 1_000_000_000))
.collect(),
},
parachain_info: stout_runtime::ParachainInfoConfig {
parachain_id: PARA_ID,
..Default::default()
},
collator_selection: stout_runtime::CollatorSelectionConfig {
invulnerables:
integration_tests_common::constants::collators::invulnerables_asset_hub_polkadot()
.iter()
.cloned()
.map(|(acc, _)| acc)
.collect(),
candidacy_bond: ED * 16,
..Default::default()
},
session: stout_runtime::SessionConfig {
keys: integration_tests_common::constants::collators::invulnerables()
.into_iter()
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc, // validator id
stout_runtime::SessionKeys { aura }, // session keys
)
})
.collect(),
},
sudo: stout_runtime::SudoConfig {
key: Some(get_account_id_from_seed::<sr25519::Public>("Alice")),
},
polkadot_xcm: stout_runtime::PolkadotXcmConfig {
safe_xcm_version: Some(xcm::prelude::XCM_VERSION),
..Default::default()
},
..Default::default()
};

genesis_config.build_storage().unwrap()
}
30 changes: 30 additions & 0 deletions integration-tests/emulated/src/tests/misc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use crate::tests::*;

#[test]
fn event_collection_works() {
//init_tracing();

const AMOUNT: u128 = 1_000_000_000 * 10;
const MAX_WEIGHT: u128 = 1_000_000_000;
let alice_account: sp_runtime::AccountId32 = get_account_id_from_seed::<sr25519::Public>(ALICE);

Trappist::execute_with(|| {
assert_ok!(<Trappist as TrappistPallet>::XcmPallet::execute(
<Trappist as Chain>::RuntimeOrigin::signed(alice_account.clone()),
Box::new(VersionedXcm::from(Xcm(vec![WithdrawAsset((Here, AMOUNT).into())]))),
(MAX_WEIGHT as u64).into()
));
output_events::<<Trappist as Chain>::Runtime>();
assert_eq!(3, <Trappist as Chain>::System::events().len());
});

Stout::execute_with(|| {
assert_ok!(<Stout as StoutPallet>::XcmPallet::execute(
<Stout as Chain>::RuntimeOrigin::signed(alice_account),
Box::new(VersionedXcm::from(Xcm(vec![WithdrawAsset((Here, AMOUNT).into())]))),
(MAX_WEIGHT as u64).into()
));
output_events::<<Stout as Chain>::Runtime>();
assert_eq!(1, <Stout as Chain>::System::events().len());
});
}
Loading

0 comments on commit e51c1fe

Please sign in to comment.