Skip to content

Commit

Permalink
Add basic XCM emulator tests (#114)
Browse files Browse the repository at this point in the history
This PR adds XCM emulator tests for Relay chains and Asset Hub System
parachains.

It adds them under new `integration-tests/emulated/` dir which lives at
the root of the repo and doesn't pollute the prod networks
code/crates/etc in any way. As you can see from the `diff`, no other
files outside `integration-tests` are touched by this PR (except
workspace `Cargo.toml` and `Cargo.lock`).

Tests added by this PR are rather old/limited, but I will update them
when we bump polkadot-sdk crates deps to `v1.4` or `v1.5` release. This
will bring in more refined tests for existing scenarios and many new
tests for new scenarios such as complex asset-transfers and bridging -
sending XCMs over bridge, and asset transfers between AHs on different
relays using bridge.

Also after bumping repo to sdk `v1.4` or `v1.5` release, we can also
drop 90% of `integration-tests/emulated/common` and get it from
`crates.io`.

Fixes #103

---------

Co-authored-by: Bastian Köcher <[email protected]>
  • Loading branch information
acatangiu and bkchr authored Jan 4, 2024
1 parent ab96e82 commit 4422084
Show file tree
Hide file tree
Showing 26 changed files with 4,822 additions and 1 deletion.
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ jobs:
run: cargo test --workspace --release --locked -q --features=runtime-metrics,try-runtime
env:
RUSTFLAGS: "-C debug-assertions -D warnings"
SKIP_WASM_BUILD: 1

- name: Test all features
run: cargo test --workspace --release --locked -q --features=runtime-benchmarks,runtime-metrics,try-runtime
Expand Down
186 changes: 186 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ members = [
"system-parachains/bridge-hubs/bridge-hub-polkadot",
"system-parachains/collectives/collectives-polkadot",
"system-parachains/gluttons/glutton-kusama",
"integration-tests/emulated/assets/asset-hub-kusama",
"integration-tests/emulated/assets/asset-hub-polkadot",
]

[profile.release]
Expand Down
40 changes: 40 additions & 0 deletions integration-tests/emulated/assets/asset-hub-kusama/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[package]
name = "asset-hub-kusama-integration-tests"
version = "1.0.0"
authors.workspace = true
edition.workspace = true
license = "Apache-2.0"
description = "Asset Hub Kusama runtime integration tests with xcm-emulator"
publish = false

[dependencies]
codec = { package = "parity-scale-codec", version = "3.4.0" }
assert_matches = "1.5.0"

# Substrate
sp-runtime = { version = "28.0.0" }
frame-support = { version = "25.0.0" }
frame-system = { version = "25.0.0" }
pallet-assets = { version = "26.0.0" }
pallet-balances = { version = "25.0.0" }
pallet-asset-conversion = { version = "7.0.0" }

# Polkadot
polkadot-core-primitives = { version = "4.0.0" }
polkadot-parachain-primitives = { version = "3.0.0" }
polkadot-runtime-parachains = { version = "4.0.0" }
xcm = { package = "staging-xcm", version = "4.0.0" }
pallet-xcm = { version = "4.0.0" }

# Cumulus
parachains-common = { version = "4.0.0" }
xcm-emulator = { version = "0.2.0" }
asset-hub-kusama-runtime = { path = "../../../../system-parachains/asset-hubs/asset-hub-kusama" }

# Local
integration-tests-common = { path = "../../common" }

[features]
runtime-benchmarks = [
"integration-tests-common/runtime-benchmarks"
]
92 changes: 92 additions & 0 deletions integration-tests/emulated/assets/asset-hub-kusama/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#![cfg(not(feature = "runtime-benchmarks"))]

pub use codec::Encode;
pub use frame_support::{
assert_err, assert_ok,
pallet_prelude::Weight,
sp_runtime::{AccountId32, DispatchError, DispatchResult},
traits::fungibles::Inspect,
};
pub use integration_tests_common::{
constants::{
asset_hub_kusama::ED as ASSET_HUB_KUSAMA_ED, kusama::ED as KUSAMA_ED, PROOF_SIZE_THRESHOLD,
REF_TIME_THRESHOLD, XCM_V3,
},
xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution},
AssetHubKusama, AssetHubKusamaPallet, AssetHubKusamaReceiver, AssetHubKusamaSender, Kusama,
KusamaPallet, KusamaReceiver, KusamaSender, PenpalKusamaA, PenpalKusamaAPallet,
PenpalKusamaAReceiver, PenpalKusamaASender, PenpalKusamaB, PenpalKusamaBPallet,
};
pub use parachains_common::{AccountId, Balance};
pub use xcm::{
prelude::{AccountId32 as AccountId32Junction, *},
v3::{Error, NetworkId::Kusama as KusamaId},
};
pub use xcm_emulator::{
assert_expected_events, bx, helpers::weight_within_threshold, Chain, Parachain as Para,
RelayChain as Relay, Test, TestArgs, TestContext, TestExt,
};

pub const ASSET_ID: u32 = 1;
pub const ASSET_MIN_BALANCE: u128 = 1000;
// `Assets` pallet index
pub const ASSETS_PALLET_ID: u8 = 50;

pub type RelayToSystemParaTest = Test<Kusama, AssetHubKusama>;
pub type SystemParaToRelayTest = Test<AssetHubKusama, Kusama>;
pub type SystemParaToParaTest = Test<AssetHubKusama, PenpalKusamaA>;

/// Returns a `TestArgs` instance to be used for the Relay Chain across integration tests
pub fn relay_test_args(amount: Balance) -> TestArgs {
TestArgs {
dest: Kusama::child_location_of(AssetHubKusama::para_id()),
beneficiary: AccountId32Junction {
network: None,
id: AssetHubKusamaReceiver::get().into(),
}
.into(),
amount,
assets: (Here, amount).into(),
asset_id: None,
fee_asset_item: 0,
weight_limit: WeightLimit::Unlimited,
}
}

/// Returns a `TestArgs` instance to be used for the System Parachain across integration tests
pub fn system_para_test_args(
dest: MultiLocation,
beneficiary_id: AccountId32,
amount: Balance,
assets: MultiAssets,
asset_id: Option<u32>,
) -> TestArgs {
TestArgs {
dest,
beneficiary: AccountId32Junction { network: None, id: beneficiary_id.into() }.into(),
amount,
assets,
asset_id,
fee_asset_item: 0,
weight_limit: WeightLimit::Unlimited,
}
}

#[cfg(test)]
#[cfg(not(feature = "runtime-benchmarks"))]
mod tests;
Loading

0 comments on commit 4422084

Please sign in to comment.