Skip to content

Commit

Permalink
feat(xcm): reserver transfer + xcm emulator (#18)
Browse files Browse the repository at this point in the history
* feat: XCM emulator

* fmt

* Removed unnecessary dependency

* fmt

* refactor: moved rococo_network.rs to lib.rs + cleaning up

* chore: update toml and comment

* chore: update .toml

* style: cargo fmt

* style: remove trailing space

* fix: add deps std feature

* chore: update .toml to use default-features = false

* chore: use std features

* chore: add try-runtime and runtime-benchmark features

* fix(deps): fix features

* refactor(deps): copy constants to tests to avoid unnecessary compilation

* fix(integration-test): move para_id out of reserved range

* test: remove irrelevant tests

* test(xcm): reserve transfer to relay

* feat(xcm): reserve transfers to relay/asset hub

* refactor(integration-tests): simplify crate name

* fix: update pop para id

* fix: reduce visibility, address clippy warning

* refactor: uplift network declaration

---------

Co-authored-by: Peter White <[email protected]>
Co-authored-by: Frank Bell <[email protected]>
  • Loading branch information
3 people authored Mar 9, 2024
1 parent 56288e9 commit b2dec1e
Show file tree
Hide file tree
Showing 15 changed files with 2,002 additions and 164 deletions.
1,197 changes: 1,076 additions & 121 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 14 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repository = "https://github.com/r0gue-io/pop-node/"
members = [
"node",
"runtime",
"integration-tests",
"pop-api",
]
exclude = [
Expand All @@ -31,14 +32,14 @@ clap = { version = "4.4.18", features = ["derive"] }
jsonrpsee = { version = "0.20.3", features = ["server"] }
futures = "0.3.28"
serde_json = "1.0.111"
tracing-subscriber = { version = "0.3", default-features = false }

# Build
substrate-wasm-builder = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1" }
substrate-build-script-utils = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1" }

# Local

pop-runtime = { path = "./runtime" }
pop-runtime = { path = "./runtime", default-features = false }
pop-api-primitives = { path = "./pop-api/primitives", default-features = false }

# Substrate
Expand Down Expand Up @@ -84,9 +85,13 @@ pallet-transaction-payment = { git = "https://github.com/paritytech/polkadot-sdk
pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1" }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
sp-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
sp-authority-discovery = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
sp-block-builder = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
sp-blockchain = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1" }
sp-consensus-aura = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
sp-consensus-babe = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
sp-consensus-beefy = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
sp-consensus-grandpa = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
sp-keystore = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1" }
sp-io = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
Expand All @@ -106,20 +111,25 @@ sp-version = { git = "https://github.com/paritytech/polkadot-sdk", branch = "rel
pallet-xcm = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
polkadot-cli = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1" }
polkadot-parachain-primitives = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
polkadot-primitives = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1" }
xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
polkadot-primitives = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
rococo-runtime-constants = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
rococo-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
xcm-builder = { package = "staging-xcm-builder", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
xcm-executor = { package = "staging-xcm-executor", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }

# Cumulus
asset-hub-rococo-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
asset-test-utils = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
cumulus-pallet-aura-ext = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false, features = ["parameterized-consensus-hook"] }
cumulus-pallet-session-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
cumulus-pallet-xcm = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
cumulus-primitives-core = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
cumulus-primitives-utility = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
emulated-integration-tests-common = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
pallet-collator-selection = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
parachains-common = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
parachain-info = { package = "staging-parachain-info", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.1", default-features = false }
Expand Down
89 changes: 89 additions & 0 deletions integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
[package]
name = "integration-tests"
authors.workspace = true
edition.workspace = true
homepage.workspace = true
license.workspace = true
repository.workspace = true

[dependencies]
codec.workspace = true

# Substrate
frame-support.workspace = true
pallet-assets.workspace = true
pallet-balances.workspace = true
pallet-message-queue.workspace = true
sp-core.workspace = true
sp-authority-discovery.workspace = true
sp-consensus-babe.workspace = true
sp-consensus-beefy.workspace = true
sp-consensus-grandpa.workspace = true
sp-runtime.workspace = true

# Polkadot
polkadot-primitives.workspace = true
rococo-runtime-constants.workspace = true
rococo-runtime.workspace = true
xcm.workspace = true
xcm-executor.workspace = true

# Cumulus
asset-hub-rococo-runtime.workspace = true
asset-test-utils.workspace = true
cumulus-primitives-core.workspace = true
emulated-integration-tests-common.workspace = true

# Local
pop-runtime.workspace = true

[dev-dependencies]
tracing-subscriber = { workspace = true, features = ["env-filter", "fmt", "std", "tracing-log"] }

[features]
default = ["std"]
std = [
"asset-hub-rococo-runtime/std",
"cumulus-primitives-core/std",
"frame-support/std",
"pallet-assets/std",
"pallet-balances/std",
"pallet-message-queue/std",
"polkadot-primitives/std",
"pop-runtime/std",
"rococo-runtime-constants/std",
"rococo-runtime/std",
"sp-authority-discovery/std",
"sp-consensus-babe/std",
"sp-consensus-beefy/std",
"sp-consensus-grandpa/std",
"sp-core/std",
"sp-runtime/std",
"xcm-executor/std",
"xcm/std",
]

runtime-benchmarks = [
"asset-hub-rococo-runtime/runtime-benchmarks",
"cumulus-primitives-core/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-message-queue/runtime-benchmarks",
"polkadot-primitives/runtime-benchmarks",
"pop-runtime/runtime-benchmarks",
"rococo-runtime/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
]

try-runtime = [
"asset-hub-rococo-runtime/try-runtime",
"frame-support/try-runtime",
"pallet-assets/try-runtime",
"pallet-balances/std",
"pallet-message-queue/try-runtime",
"pop-runtime/try-runtime",
"rococo-runtime/try-runtime",
"sp-runtime/try-runtime",
]
52 changes: 52 additions & 0 deletions integration-tests/src/chains/asset_hub_rococo/genesis.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use emulated_integration_tests_common::{
accounts, build_genesis_storage, collators, SAFE_XCM_VERSION,
};
use pop_runtime::Balance;
use sp_core::storage::Storage;

pub(crate) const PARA_ID: u32 = 1000;
pub(crate) const ED: Balance = rococo_runtime_constants::currency::EXISTENTIAL_DEPOSIT / 10;

pub(crate) fn genesis() -> Storage {
let genesis_config = asset_hub_rococo_runtime::RuntimeGenesisConfig {
system: asset_hub_rococo_runtime::SystemConfig::default(),
balances: asset_hub_rococo_runtime::BalancesConfig {
balances: accounts::init_balances()
.iter()
.cloned()
.map(|k| (k, ED * 4096 * 4096))
.collect(),
},
parachain_info: asset_hub_rococo_runtime::ParachainInfoConfig {
parachain_id: PARA_ID.into(),
..Default::default()
},
collator_selection: asset_hub_rococo_runtime::CollatorSelectionConfig {
invulnerables: collators::invulnerables().iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: ED * 16,
..Default::default()
},
session: asset_hub_rococo_runtime::SessionConfig {
keys: collators::invulnerables()
.into_iter()
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc, // validator id
asset_hub_rococo_runtime::SessionKeys { aura }, // session keys
)
})
.collect(),
},
polkadot_xcm: asset_hub_rococo_runtime::PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION),
..Default::default()
},
..Default::default()
};

build_genesis_storage(
&genesis_config,
asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
)
}
39 changes: 39 additions & 0 deletions integration-tests/src/chains/asset_hub_rococo/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
pub(crate) mod genesis;

use crate::chains::rococo::Rococo;
use emulated_integration_tests_common::{
impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain,
impl_assets_helpers_for_parachain, impl_foreign_assets_helpers_for_parachain,
impl_xcm_helpers_for_parachain, impls::Parachain, xcm_emulator::decl_test_parachains,
};
use frame_support::traits::OnInitialize;

// AssetHubRococo Parachain declaration
decl_test_parachains! {
pub struct AssetHubRococo {
genesis = genesis::genesis(),
on_init = {
asset_hub_rococo_runtime::AuraExt::on_initialize(1);
},
runtime = asset_hub_rococo_runtime,
core = {
XcmpMessageHandler: asset_hub_rococo_runtime::XcmpQueue,
LocationToAccountId: asset_hub_rococo_runtime::xcm_config::LocationToAccountId,
ParachainInfo: asset_hub_rococo_runtime::ParachainInfo,
MessageOrigin: cumulus_primitives_core::AggregateMessageOrigin,
},
pallets = {
PolkadotXcm: asset_hub_rococo_runtime::PolkadotXcm,
Assets: asset_hub_rococo_runtime::Assets,
ForeignAssets: asset_hub_rococo_runtime::ForeignAssets,
Balances: asset_hub_rococo_runtime::Balances,
}
},
}

// AssetHubRococo implementation
impl_accounts_helpers_for_parachain!(AssetHubRococo);
impl_assert_events_helpers_for_parachain!(AssetHubRococo);
impl_assets_helpers_for_parachain!(AssetHubRococo, Rococo);
impl_foreign_assets_helpers_for_parachain!(AssetHubRococo, Rococo);
impl_xcm_helpers_for_parachain!(AssetHubRococo);
3 changes: 3 additions & 0 deletions integration-tests/src/chains/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub(crate) mod asset_hub_rococo;
pub(crate) mod pop_network;
pub(crate) mod rococo;
51 changes: 51 additions & 0 deletions integration-tests/src/chains/pop_network/genesis.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use emulated_integration_tests_common::{accounts, build_genesis_storage, collators};
use pop_runtime::Balance;
use sp_core::storage::Storage;

pub(crate) const ED: Balance = pop_runtime::EXISTENTIAL_DEPOSIT;
const PARA_ID: u32 = 9090;
const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION;

pub(crate) fn genesis() -> Storage {
let genesis_config = pop_runtime::RuntimeGenesisConfig {
system: pop_runtime::SystemConfig::default(),
balances: pop_runtime::BalancesConfig {
balances: accounts::init_balances()
.iter()
.cloned()
.map(|k| (k, ED * 4096 * 4096))
.collect(),
},
parachain_info: pop_runtime::ParachainInfoConfig {
parachain_id: PARA_ID.into(),
..Default::default()
},
collator_selection: pop_runtime::CollatorSelectionConfig {
invulnerables: collators::invulnerables().iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: ED * 16,
..Default::default()
},
session: pop_runtime::SessionConfig {
keys: collators::invulnerables()
.into_iter()
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc, // validator id
pop_runtime::SessionKeys { aura }, // session keys
)
})
.collect(),
},
polkadot_xcm: pop_runtime::PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION),
..Default::default()
},
..Default::default()
};

build_genesis_storage(
&genesis_config,
pop_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
)
}
37 changes: 37 additions & 0 deletions integration-tests/src/chains/pop_network/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
pub(crate) mod genesis;

use crate::chains::rococo::Rococo;
use emulated_integration_tests_common::{
impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain,
impl_assets_helpers_for_parachain, impl_xcm_helpers_for_parachain, impls::Parachain,
xcm_emulator::decl_test_parachains,
};
use frame_support::traits::OnInitialize;

// PopNetwork Parachain declaration
decl_test_parachains! {
pub struct PopNetwork {
genesis = genesis::genesis(),
on_init = {
pop_runtime::AuraExt::on_initialize(1);
},
runtime = pop_runtime,
core = {
XcmpMessageHandler: pop_runtime::XcmpQueue,
LocationToAccountId: pop_runtime::xcm_config::LocationToAccountId,
ParachainInfo: pop_runtime::ParachainInfo,
MessageOrigin: cumulus_primitives_core::AggregateMessageOrigin,
},
pallets = {
PolkadotXcm: pop_runtime::PolkadotXcm,
Assets: pop_runtime::Assets,
Balances: pop_runtime::Balances,
}
},
}

// PopNetwork implementation
impl_accounts_helpers_for_parachain!(PopNetwork);
impl_assert_events_helpers_for_parachain!(PopNetwork);
impl_assets_helpers_for_parachain!(PopNetwork, Rococo);
impl_xcm_helpers_for_parachain!(PopNetwork);
Loading

0 comments on commit b2dec1e

Please sign in to comment.