Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Support westend integration tests (#2649)
Browse files Browse the repository at this point in the history
* mostly there with westend

* add network

* initial way to set host api version

* 3 tests all passing

* Remove duplication

* fix runtime-benchmarks

* Fix typo

---------

Co-authored-by: joepetrowski <joe@parity.io>
  • Loading branch information
gilescope and joepetrowski authored Jun 2, 2023
1 parent 80aaed3 commit 93b7fe3
Show file tree
Hide file tree
Showing 12 changed files with 533 additions and 8 deletions.
30 changes: 30 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ members = [
"parachains/integration-tests/emulated/common",
"parachains/integration-tests/emulated/assets/asset-hub-kusama",
"parachains/integration-tests/emulated/assets/asset-hub-polkadot",
"parachains/integration-tests/emulated/assets/asset-hub-westend",
"test/client",
"test/relay-sproof-builder",
"test/relay-validation-worker-provider",
Expand All @@ -71,4 +72,3 @@ opt-level = 3
inherits = "release"
lto = true
codegen-units = 1

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "asset-hub-westend-integration-tests"
version = "1.0.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2021"
description = "Asset Hub Westend runtime integration tests with xcm-emulator"

[dependencies]
codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false }

# Substrate
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }
sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }
sp-weights = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }
pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }
pallet-assets = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "master" }

# Polkadot
polkadot-core-primitives = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "master" }
polkadot-parachain = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "master" }
polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "master" }
polkadot-runtime = { git = "https://github.com/paritytech/polkadot", branch = "master" }
westend-runtime = { git = "https://github.com/paritytech/polkadot", branch = "master" }
xcm = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "master" }
xcm-executor = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "master" }
pallet-xcm = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "master" }

# Cumulus
parachains-common = { path = "../../../../common" }
penpal-runtime = { path = "../../../../runtimes/testing/penpal" }
asset-hub-westend-runtime = { path = "../../../../runtimes/assets/asset-hub-westend" }

# Local
xcm-emulator = { default-features = false, path = "../../../../../xcm/xcm-emulator" }
integration-tests-common = { default-features = false, path = "../../common" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
pub use codec::Encode;
pub use frame_support::{
assert_ok, instances::Instance1, pallet_prelude::Weight, traits::fungibles::Inspect,
};
pub use integration_tests_common::{
constants::{
accounts::{ALICE, BOB},
polkadot::ED as POLKADOT_ED,
PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3,
},
AccountId, AssetHubWestend, AssetHubWestendPallet, AssetHubWestendReceiver,
AssetHubWestendSender, Collectives, CollectivesPallet, CollectivesReceiver, CollectivesSender,
PenpalWestend, Westend, WestendPallet, WestendReceiver, WestendSender,
};
pub use polkadot_core_primitives::InboundDownwardMessage;
pub use xcm::{
prelude::*,
v3::{
Error,
NetworkId::{Kusama as KusamaId, Polkadot as PolkadotId},
},
};
pub use xcm_emulator::{
assert_expected_events, bx, cumulus_pallet_dmp_queue, helpers::weight_within_threshold,
Parachain as Para, RelayChain as Relay, TestExt,
};

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod reserve_transfer;
mod teleport;
mod transact;
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use crate::*;

#[test]
fn reserve_transfer_native_asset_from_relay_to_assets() {
// Init tests variables
let amount = POLKADOT_ED * 1000;
let relay_sender_balance_before = Westend::account_data_of(WestendSender::get()).free;
let para_receiver_balance_before =
AssetHubWestend::account_data_of(AssetHubWestendReceiver::get()).free;

let origin = <Westend as Relay>::RuntimeOrigin::signed(WestendSender::get());
let assets_para_destination: VersionedMultiLocation =
Westend::child_location_of(AssetHubWestend::para_id()).into();
let beneficiary: VersionedMultiLocation =
AccountId32 { network: None, id: AssetHubWestendReceiver::get().into() }.into();
let native_assets: VersionedMultiAssets = (Here, amount).into();
let fee_asset_item = 0;
let weight_limit = WeightLimit::Unlimited;

// Send XCM message from Relay Chain
Westend::execute_with(|| {
assert_ok!(<Westend as WestendPallet>::XcmPallet::limited_reserve_transfer_assets(
origin,
bx!(assets_para_destination),
bx!(beneficiary),
bx!(native_assets),
fee_asset_item,
weight_limit,
));

type RuntimeEvent = <Westend as Relay>::RuntimeEvent;

assert_expected_events!(
Westend,
vec![
RuntimeEvent::XcmPallet(pallet_xcm::Event::Attempted { outcome: Outcome::Complete(weight) }) => {
weight: weight_within_threshold((REF_TIME_THRESHOLD, PROOF_SIZE_THRESHOLD), Weight::from_parts(731_495_000, 0), *weight),
},
]
);
});

// Receive XCM message in Assets Parachain
AssetHubWestend::execute_with(|| {
type RuntimeEvent = <AssetHubWestend as Para>::RuntimeEvent;

assert_expected_events!(
AssetHubWestend,
vec![
RuntimeEvent::DmpQueue(cumulus_pallet_dmp_queue::Event::ExecutedDownward {
outcome: Outcome::Incomplete(_, Error::UntrustedReserveLocation),
..
}) => {},
]
);
});

// Check if balances are updated accordingly in Relay Chain and Assets Parachain
let relay_sender_balance_after = Westend::account_data_of(WestendSender::get()).free;
let para_sender_balance_after =
AssetHubWestend::account_data_of(AssetHubWestendReceiver::get()).free;

assert_eq!(relay_sender_balance_before - amount, relay_sender_balance_after);
assert_eq!(para_sender_balance_after, para_receiver_balance_before);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use crate::*;

#[test]
fn teleport_native_assets_from_relay_to_assets_para() {
// Init tests variables
let amount = POLKADOT_ED * 1000;
let relay_sender_balance_before = Westend::account_data_of(WestendSender::get()).free;
let para_receiver_balance_before =
AssetHubWestend::account_data_of(AssetHubWestendReceiver::get()).free;

let origin = <Westend as Relay>::RuntimeOrigin::signed(WestendSender::get());
let assets_para_destination: VersionedMultiLocation =
Westend::child_location_of(AssetHubWestend::para_id()).into();
let beneficiary: VersionedMultiLocation =
AccountId32 { network: None, id: AssetHubWestendReceiver::get().into() }.into();
let native_assets: VersionedMultiAssets = (Here, amount).into();
let fee_asset_item = 0;
let weight_limit = WeightLimit::Unlimited;

// Send XCM message from Relay Chain
Westend::execute_with(|| {
assert_ok!(<Westend as WestendPallet>::XcmPallet::limited_teleport_assets(
origin,
bx!(assets_para_destination),
bx!(beneficiary),
bx!(native_assets),
fee_asset_item,
weight_limit,
));

type RuntimeEvent = <Westend as Relay>::RuntimeEvent;

assert_expected_events!(
Westend,
vec![
RuntimeEvent::XcmPallet(pallet_xcm::Event::Attempted { outcome: Outcome::Complete { .. } }) => {},
]
);
});

// Receive XCM message in Assets Parachain
AssetHubWestend::execute_with(|| {
type RuntimeEvent = <AssetHubWestend as Para>::RuntimeEvent;

assert_expected_events!(
AssetHubWestend,
vec![
RuntimeEvent::Balances(pallet_balances::Event::Deposit { who, .. }) => {
who: *who == AssetHubWestendReceiver::get().into(),
},
]
);
});

// Check if balances are updated accordingly in Relay Chain and Assets Parachain
let relay_sender_balance_after = Westend::account_data_of(WestendSender::get()).free;
let para_sender_balance_after =
AssetHubWestend::account_data_of(AssetHubWestendReceiver::get()).free;

assert_eq!(relay_sender_balance_before - amount, relay_sender_balance_after);
assert!(para_sender_balance_after > para_receiver_balance_before);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use crate::*;

#[test]
fn transact_sudo_from_relay_to_assets_para() {
// Init tests variables
// Call to be executed in Assets Parachain
const ASSET_ID: u32 = 1;

let call = <AssetHubWestend as Para>::RuntimeCall::Assets(pallet_assets::Call::<
<AssetHubWestend as Para>::Runtime,
Instance1,
>::force_create {
id: ASSET_ID.into(),
is_sufficient: true,
min_balance: 1000,
owner: AssetHubWestendSender::get().into(),
})
.encode()
.into();

// XcmPallet send arguments
let sudo_origin = <Westend as Relay>::RuntimeOrigin::root();
let assets_para_destination: VersionedMultiLocation =
Westend::child_location_of(AssetHubWestend::para_id()).into();

let weight_limit = WeightLimit::Unlimited;
let require_weight_at_most = Weight::from_parts(1000000000, 200000);
let origin_kind = OriginKind::Superuser;
let check_origin = None;

let xcm = VersionedXcm::from(Xcm(vec![
UnpaidExecution { weight_limit, check_origin },
Transact { require_weight_at_most, origin_kind, call },
]));

// Send XCM message from Relay Chain
Westend::execute_with(|| {
assert_ok!(<Westend as WestendPallet>::XcmPallet::send(
sudo_origin,
bx!(assets_para_destination),
bx!(xcm),
));

type RuntimeEvent = <Westend as Relay>::RuntimeEvent;

assert_expected_events!(
Westend,
vec![
RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {},
]
);
});

// Receive XCM message in Assets Parachain
AssetHubWestend::execute_with(|| {
assert!(<AssetHubWestend as AssetHubWestendPallet>::Assets::asset_exists(ASSET_ID));
});
}
5 changes: 5 additions & 0 deletions parachains/integration-tests/emulated/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ polkadot-runtime = { git = "https://github.com/paritytech/polkadot", branch = "m
polkadot-runtime-constants = { git = "https://github.com/paritytech/polkadot", branch = "master" }
kusama-runtime = { git = "https://github.com/paritytech/polkadot", branch = "master" }
kusama-runtime-constants = { git = "https://github.com/paritytech/polkadot", branch = "master" }
westend-runtime = { git = "https://github.com/paritytech/polkadot", branch = "master" }
westend-runtime-constants = { git = "https://github.com/paritytech/polkadot", branch = "master" }
xcm = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "master" }
xcm-executor = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "master" }
pallet-xcm = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "master" }
Expand All @@ -43,6 +45,7 @@ cumulus-primitives-core = { path = "../../../../primitives/core" }
penpal-runtime = { path = "../../../runtimes/testing/penpal" }
asset-hub-polkadot-runtime = { path = "../../../runtimes/assets/asset-hub-polkadot" }
asset-hub-kusama-runtime = { path = "../../../runtimes/assets/asset-hub-kusama" }
asset-hub-westend-runtime = { path = "../../../runtimes/assets/asset-hub-westend" }
collectives-polkadot-runtime = { path = "../../../runtimes/collectives/collectives-polkadot" }
bridge-hub-kusama-runtime = { path = "../../../runtimes/bridge-hubs/bridge-hub-kusama" }
bridge-hub-polkadot-runtime = { path = "../../../runtimes/bridge-hubs/bridge-hub-polkadot" }
Expand All @@ -51,4 +54,6 @@ xcm-emulator = { default-features = false, path = "../../../../xcm/xcm-emulator"
[features]
runtime-benchmarks = [
"kusama-runtime/runtime-benchmarks",
"polkadot-runtime/runtime-benchmarks",
"westend-runtime/runtime-benchmarks",
]
Loading

0 comments on commit 93b7fe3

Please sign in to comment.