forked from polkadot-fellows/runtimes
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic XCM emulator tests (polkadot-fellows#114)
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 polkadot-fellows#103 --------- Co-authored-by: Bastian Köcher <[email protected]>
- Loading branch information
Showing
26 changed files
with
4,822 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
integration-tests/emulated/assets/asset-hub-kusama/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
92
integration-tests/emulated/assets/asset-hub-kusama/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.