Skip to content

chore(xcm): add emulated tests #2410

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
970 changes: 574 additions & 396 deletions Cargo.lock

Large diffs are not rendered by default.

13,777 changes: 13,777 additions & 0 deletions emulated-test/Cargo.lock

Large diffs are not rendered by default.

67 changes: 67 additions & 0 deletions emulated-test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
[workspace]
members = [
"chains/frequency-westend",
"networks/westend",
"test/frequency-westend"
]
resolver = "2"

[workspace.lints.rust]
nonstandard-style = "deny"

[workspace.lints.clippy]
correctness = { level = "deny", priority = -1 }
style = { level = "deny", priority = -1 }
complexity = { level = "deny", priority = -1 }
perf = { level = "deny", priority = -1 }
suspicious = { level = "deny", priority = -1 }

wildcard_dependencies = "deny"
from_over_into = "allow"
type_complexity = "allow"
identity_op = "allow"
derivable_impls = "allow"
assign_op_pattern = "allow"
too_many_arguments = "allow"
new_without_default = "allow"
get_first = "allow"
len_zero = "allow"
large_enum_variant = "allow"
empty_line_after_outer_attr = "allow"
enum_variant_names = "allow"

[workspace.dependencies]
log = { version = "0.4.17", default-features = false }
env_logger = "0.11.7"
xcm-emulator = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2503" }
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2503", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2503", default-features = false }
parachains-common = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2503", default-features = false }
polkadot-primitives = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2503" }

emulated-integration-tests-common = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2503" }
frequency-runtime = { path = "../runtime/frequency", features = [
"frequency-westend",
"frequency-bridging",
"frequency-local",
"frequency-lint-check",
] }
cumulus-primitives-core = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2503", default-features = false }
sp-keyring = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2503", default-features = false }
frame-support = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2503", default-features = false }
staging-xcm = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2503", default-features = false }

asset-hub-westend-emulated-chain = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2503" }
frequency-emulated-chain = { path = "./chains/frequency-westend" }
westend-emulated-chain = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2503" }

asset-test-utils = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2503" }
pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2503", default-features = false }
pallet-message-queue = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2503", default-features = false }
pallet-xcm = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2503", default-features = false }
westend-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2503" }
westend-system-emulated-network = { path = "../../networks/westend" }
xcm-executor = { package = "staging-xcm-executor", git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2503", default-features = false }
pallet-assets = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2503", default-features = false }
sp-io = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2503", default-features = false }

35 changes: 35 additions & 0 deletions emulated-test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
UNAME := $(shell uname)
NIGHTLY = +nightly-2025-04-03

.PHONY: all
all: build

.PHONY: clean
clean:
cargo clean

.PHONY: format
format:
cargo $(NIGHTLY) fmt

.PHONY: lint lint-audit lint-fix lint-clippy
lint:
cargo $(NIGHTLY) fmt --check
SKIP_WASM_BUILD=1 cargo clippy -- -Dwarnings
RUSTC_BOOTSTRAP=1 RUSTDOCFLAGS="--enable-index-page --check -Zunstable-options" cargo doc --no-deps

lint-clippy:
SKIP_WASM_BUILD=1 cargo clippy -- -Dwarnings

lint-audit:
cargo deny check -c deny.toml

lint-fix:
cargo $(NIGHTLY) fmt
SKIP_WASM_BUILD=1 cargo clippy --fix

.PHONY: format-lint
format-lint: format lint

check:
SKIP_WASM_BUILD= cargo check
27 changes: 27 additions & 0 deletions emulated-test/chains/frequency-westend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
authors = ["Frequency"]
edition = '2021'
homepage = "https://frequency.xyz"
license = "Apache-2.0"
name = 'frequency-emulated-chain'
publish = false
version = "0.0.0"

[dependencies]
xcm-emulator = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
parachains-common = { workspace = true }
polkadot-primitives = { workspace = true }

emulated-integration-tests-common = { workspace = true }
frequency-runtime = { workspace = true, features = [
"frequency-westend",
"frequency-bridging",
"frequency-local",
"frequency-lint-check",
] }
cumulus-primitives-core = { workspace = true }
sp-keyring = { workspace = true }
frame-support = { workspace = true }
staging-xcm = { workspace = true }
54 changes: 54 additions & 0 deletions emulated-test/chains/frequency-westend/src/genesis.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use frame_support::parameter_types;
use sp_core::storage::Storage;
use sp_keyring::Sr25519Keyring as Keyring;

// Cumulus
use emulated_integration_tests_common::{accounts, build_genesis_storage, collators};
use parachains_common::{AccountId, Balance};

pub const PARA_ID: u32 = 2000;
pub const ED: Balance = frequency_runtime::EXISTENTIAL_DEPOSIT;

parameter_types! {
pub FrequencySudoAccount: AccountId = Keyring::Alice.to_account_id();
pub FrequencyAssetOwner: AccountId = FrequencySudoAccount::get();
}

pub fn genesis(para_id: u32) -> Storage {
let genesis_config = frequency_runtime::RuntimeGenesisConfig {
system: frequency_runtime::SystemConfig::default(),
balances: frequency_runtime::BalancesConfig {
balances: accounts::init_balances().iter().cloned().map(|k| (k, ED * 4096)).collect(),
..Default::default()
},
parachain_info: frequency_runtime::ParachainInfoConfig {
parachain_id: para_id.into(),
..Default::default()
},
collator_selection: frequency_runtime::CollatorSelectionConfig {
invulnerables: collators::invulnerables().iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: ED * 16,
..Default::default()
},
session: frequency_runtime::SessionConfig {
keys: collators::invulnerables()
.into_iter()
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc, // validator id
frequency_runtime::SessionKeys { aura }, // session keys
)
})
.collect(),
..Default::default()
},
sudo: frequency_runtime::SudoConfig { key: Some(FrequencySudoAccount::get()) },
..Default::default()
};

build_genesis_storage(
&genesis_config,
frequency_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
)
}
36 changes: 36 additions & 0 deletions emulated-test/chains/frequency-westend/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
pub use frequency_runtime::{self, xcm::RelayNetwork as FrequencyRelayNetworkId};

mod genesis;
pub use genesis::{genesis, FrequencyAssetOwner, FrequencySudoAccount, ED, PARA_ID};

use frame_support::traits::OnInitialize;

use emulated_integration_tests_common::{
impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain,
impl_xcm_helpers_for_parachain, impls::Parachain, xcm_emulator::decl_test_parachains,
};

decl_test_parachains! {
pub struct FrequencyWestend {
genesis = genesis(PARA_ID),
on_init = {
frequency_runtime::AuraExt::on_initialize(1);
},
runtime = frequency_runtime,
core = {
XcmpMessageHandler: frequency_runtime::XcmpQueue,
LocationToAccountId: frequency_runtime::xcm::LocationToAccountId,
ParachainInfo: frequency_runtime::ParachainInfo,
MessageOrigin: cumulus_primitives_core::AggregateMessageOrigin,
},
pallets = {
PolkadotXcm: frequency_runtime::PolkadotXcm,
ForeignAssets: frequency_runtime::ForeignAssets,
Balances: frequency_runtime::Balances,
}
},
}

impl_accounts_helpers_for_parachain!(FrequencyWestend);
impl_xcm_helpers_for_parachain!(FrequencyWestend);
impl_assert_events_helpers_for_parachain!(FrequencyWestend);
14 changes: 14 additions & 0 deletions emulated-test/networks/westend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
authors = ["Frequency"]
edition = '2021'
homepage = "https://frequency.xyz"
license = "Apache-2.0"
name = 'westend-system-emulated-network'
publish = false
version = "0.0.0"

[dependencies]
asset-hub-westend-emulated-chain = { workspace = true }
emulated-integration-tests-common = { workspace = true }
westend-emulated-chain = { workspace = true }
frequency-emulated-chain = { path = "../../chains/frequency-westend" }
30 changes: 30 additions & 0 deletions emulated-test/networks/westend/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
pub use asset_hub_westend_emulated_chain;
pub use frequency_emulated_chain;
pub use westend_emulated_chain;

pub use asset_hub_westend_emulated_chain::AssetHubWestend;
use frequency_emulated_chain::FrequencyWestend;
use westend_emulated_chain::Westend;

// Cumulus
use emulated_integration_tests_common::{
accounts::{ALICE, BOB},
xcm_emulator::{decl_test_networks, decl_test_sender_receiver_accounts_parameter_types},
};

decl_test_networks! {
pub struct WestendMockNet {
relay_chain = Westend,
parachains = vec![
AssetHubWestend,
FrequencyWestend,
],
bridge = ()
},
}

decl_test_sender_receiver_accounts_parameter_types! {
WestendRelay { sender: ALICE, receiver: BOB },
AssetHubWestendPara { sender: ALICE, receiver: BOB },
FrequencyWestendPara { sender: ALICE, receiver: BOB }
}
24 changes: 24 additions & 0 deletions emulated-test/test/frequency-westend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
authors = ["Frequency"]
edition = '2021'
homepage = "https://frequency.xyz"
license = "Apache-2.0"
name = "frequency-westend-integration-tests"
publish = false
version = "0.0.0"

[dependencies]
asset-test-utils = { workspace = true }
emulated-integration-tests-common = { workspace = true }
frame-support = { workspace = true }
pallet-balances = { workspace = true }
pallet-message-queue = { workspace = true }
pallet-xcm = { workspace = true }
parachains-common = { workspace = true }
sp-runtime = { workspace = true }
westend-runtime = { workspace = true }
westend-system-emulated-network = { path = "../../networks/westend" }
xcm-executor = { workspace = true }
staging-xcm = { workspace = true }
pallet-assets = { workspace = true }
sp-io = { workspace = true }
71 changes: 71 additions & 0 deletions emulated-test/test/frequency-westend/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#[cfg(test)]
mod imports {
pub use frame_support::{
assert_ok,
sp_runtime::DispatchResult,
traits::{
fungible::Inspect,
fungibles::{Inspect as FungiblesInspect, Mutate as FungiblesMutate},
},
BoundedVec,
};

pub use staging_xcm::{
latest::AssetTransferFilter,
prelude::{AccountId32 as AccountId32Junction, *},
};

pub use emulated_integration_tests_common::{
xcm_emulator::{
assert_expected_events, bx, AccountIdOf, Chain, Parachain as Para, RelayChain as Relay,
Test, TestArgs, TestContext, TestExt,
},
xcm_helpers::{fee_asset, non_fee_asset},
};
pub use parachains_common::Balance;
pub use westend_system_emulated_network::{
self,
asset_hub_westend_emulated_chain::{
asset_hub_westend_runtime::{
xcm_config::WestendLocation, ExistentialDeposit as AssetHubExistentialDeposit,
},
AssetHubWestendParaPallet as AssetHubWestendPallet,
},
frequency_emulated_chain::{
frequency_runtime::ExistentialDeposit as FrequencyExistentialDeposit,
FrequencyAssetOwner, FrequencyWestendParaPallet as FrequencyWestendPallet,
},
westend_emulated_chain::{genesis::ED as WESTEND_ED, WestendRelayPallet as WestendPallet},
AssetHubWestendPara as AssetHubWestend,
AssetHubWestendParaReceiver as AssetHubWestendReceiver,
AssetHubWestendParaSender as AssetHubWestendSender,
FrequencyWestendPara as FrequencyWestend,
FrequencyWestendParaReceiver as FrequencyWestendReceiver,
FrequencyWestendParaSender as FrequencyWestendSender, WestendRelay as Westend,
WestendRelayReceiver as WestendReceiver, WestendRelaySender as WestendSender,
};

pub type AssetHubToFrequencyTest = Test<AssetHubWestend, FrequencyWestend>;
pub type FrequencyToAssetHubTest = Test<FrequencyWestend, AssetHubWestend>;
pub type RelayToFrequencyTest = Test<Westend, FrequencyWestend>;
pub type FrequencyToRelayTest = Test<FrequencyWestend, Westend>;

pub fn frequency_balance_of(
who: &AccountIdOf<<FrequencyWestend as Chain>::Runtime>,
) -> Balance {
FrequencyWestend::execute_with(|| {
type Balances = <FrequencyWestend as FrequencyWestendPallet>::Balances;
<Balances as Inspect<_>>::balance(who)
})
}

pub fn assethub_balance_of(who: &AccountIdOf<<AssetHubWestend as Chain>::Runtime>) -> Balance {
AssetHubWestend::execute_with(|| {
type Balances = <AssetHubWestend as AssetHubWestendPallet>::Balances;
<Balances as Inspect<_>>::balance(who)
})
}
}

#[cfg(test)]
mod tests;
24 changes: 24 additions & 0 deletions emulated-test/test/frequency-westend/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// mod teleport;

mod reserve_transfer_dot_from_asset_hub;
mod reserve_transfer_dot_from_relay;
mod reserve_transfer_dot_to_assethub;
mod reserve_transfer_dot_to_relay;

mod teleport_xfrqcy_to_assethub_with_dot_fee;

mod teleport_xfrqcy_with_dot_fee_from_assethub;

mod utils;

#[macro_export]
macro_rules! foreign_balance_on {
( $chain:ident, $id:expr, $who:expr ) => {
emulated_integration_tests_common::impls::paste::paste! {
<$chain>::execute_with(|| {
type ForeignAssets = <$chain as [<$chain Pallet>]>::ForeignAssets;
<ForeignAssets as FungiblesInspect<_>>::balance($id, $who)
})
}
};
}
Loading
Loading