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

Add-xcm-emulator-and-tests #304

Merged
merged 32 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
30bafe5
add emulator and set xcm test
metricaez Sep 21, 2023
6e562d1
add asset hub runtime dependency
metricaez Sep 21, 2023
c330b62
break change: Add AssetHub to emulator from import
metricaez Sep 22, 2023
2b405c1
remove unused assethub import
metricaez Sep 22, 2023
58941df
fix: add AssetHub to mock network
metricaez Sep 22, 2023
d2375fb
setup as rococo mock net
metricaez Sep 22, 2023
7fd01a5
test build, create and mint asset on Asset Hub
metricaez Sep 22, 2023
723c452
add create asset on Trappist to test
metricaez Sep 22, 2023
70c5660
test build: register asset on trappist
metricaez Sep 25, 2023
6d40f6d
breaking: add transcat call from relay
metricaez Sep 26, 2023
5d1b54d
add sufficient and reserve transfer passes
metricaez Sep 29, 2023
745c1e9
add balance increment check on trappist
metricaez Sep 29, 2023
dc9ae3c
organize structure with mod
metricaez Oct 2, 2023
aa9cd71
code cleanup and start tertiary reserve transfer
metricaez Oct 2, 2023
8afe9f2
reserve asset transfer to tertiary para
metricaez Oct 3, 2023
4f1bb9d
add balance assertions
metricaez Oct 3, 2023
5b3859d
add event collector
metricaez Oct 3, 2023
a909895
add native asset trap test
metricaez Oct 4, 2023
9ae6097
add dust trap test
metricaez Oct 4, 2023
433d47b
change type wording for explicit
metricaez Oct 5, 2023
b849b29
add comments
metricaez Oct 5, 2023
5e8d3c2
finish asset trap tests
metricaez Oct 5, 2023
ac429b5
Merge branch 'main' into add-xcm-emulator-and-tests
metricaez Oct 6, 2023
c7ef901
bump to v1.1
metricaez Oct 9, 2023
21ff504
resolve imports
metricaez Oct 16, 2023
915aa78
add on_init to Trappist and Stout
metricaez Oct 16, 2023
d5a4cf8
bump reserve transfer test
metricaez Oct 16, 2023
8e852ff
enable all previously translated tests
metricaez Oct 16, 2023
04406a9
move imports to avoid warnings
metricaez Oct 17, 2023
21d7e05
Add benchmark feature and cleanup
metricaez Oct 17, 2023
ac894ec
comment non passing asset trap tests
metricaez Oct 17, 2023
9384f0d
cargo fmt
metricaez Oct 17, 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
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