Skip to content

Commit

Permalink
Create xcm emulator tests for People-Rococo (#2373)
Browse files Browse the repository at this point in the history
- Adds `reap_identity` and 12 XCM emulator test cases. 
- Moves `relay_test_args` and `relay_test_args` into a `/common`,
- Adds teleport tests. 
- Adds necessary code for emulated chain environments.

---------

Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
Co-authored-by: command-bot <>
Co-authored-by: Dónal Murray <donal.murray@parity.io>
Co-authored-by: joepetrowski <joe@parity.io>
Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
  • Loading branch information
5 people authored Dec 5, 2023
1 parent 39e7e45 commit d186f73
Show file tree
Hide file tree
Showing 27 changed files with 1,243 additions and 109 deletions.
44 changes: 44 additions & 0 deletions Cargo.lock

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

9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,26 @@ members = [
"cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend",
"cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-rococo",
"cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend",
"cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo",
"cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal",
"cumulus/parachains/integration-tests/emulated/chains/relays/rococo",
"cumulus/parachains/integration-tests/emulated/chains/relays/rococo",
"cumulus/parachains/integration-tests/emulated/chains/relays/westend",
"cumulus/parachains/integration-tests/emulated/chains/relays/westend",
"cumulus/parachains/integration-tests/emulated/common",
"cumulus/parachains/integration-tests/emulated/common",
"cumulus/parachains/integration-tests/emulated/networks/rococo-system",
"cumulus/parachains/integration-tests/emulated/networks/rococo-westend-system",
"cumulus/parachains/integration-tests/emulated/networks/westend-system",
"cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo",
"cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo",
"cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend",
"cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-westend",
"cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo",
"cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo",
"cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend",
"cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend",
"cumulus/parachains/integration-tests/emulated/tests/people/people-rococo",
"cumulus/parachains/pallets/collective-content",
"cumulus/parachains/pallets/parachain-info",
"cumulus/parachains/pallets/ping",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "people-rococo-emulated-chain"
version = "0.1.0"
authors.workspace = true
edition.workspace = true
license = "Apache-2.0"
description = "People Rococo emulated chain"
publish = false

[dependencies]
serde_json = "1.0.104"

# Substrate
sp-core = { path = "../../../../../../../../substrate/primitives/core", default-features = false }
sp-runtime = { path = "../../../../../../../../substrate/primitives/runtime", default-features = false }
frame-support = { path = "../../../../../../../../substrate/frame/support", default-features = false }

# Polakadot
parachains-common = { path = "../../../../../../../parachains/common" }

# Cumulus
cumulus-primitives-core = { path = "../../../../../../../primitives/core", default-features = false }
emulated-integration-tests-common = { path = "../../../../common", default-features = false }
people-rococo-runtime = { path = "../../../../../../runtimes/people/people-rococo" }
rococo-emulated-chain = { path = "../../../relays/rococo" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// 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.

// Substrate
use sp_core::storage::Storage;

// Cumulus
use cumulus_primitives_core::ParaId;
use emulated_integration_tests_common::{build_genesis_storage, collators, SAFE_XCM_VERSION};
use parachains_common::Balance;

pub const PARA_ID: u32 = 1004;
pub const ED: Balance = parachains_common::rococo::currency::EXISTENTIAL_DEPOSIT;

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

build_genesis_storage(
&genesis_config,
people_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// 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.

pub mod genesis;

// Substrate
use frame_support::traits::OnInitialize;

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

// PeopleRococo Parachain declaration
decl_test_parachains! {
pub struct PeopleRococo {
genesis = genesis::genesis(),
on_init = {
people_rococo_runtime::AuraExt::on_initialize(1);
},
runtime = people_rococo_runtime,
core = {
XcmpMessageHandler: people_rococo_runtime::XcmpQueue,
LocationToAccountId: people_rococo_runtime::xcm_config::LocationToAccountId,
ParachainInfo: people_rococo_runtime::ParachainInfo,
},
pallets = {
PolkadotXcm: people_rococo_runtime::PolkadotXcm,
Balances: people_rococo_runtime::Balances,
Identity: people_rococo_runtime::Identity,
IdentityMigrator: people_rococo_runtime::IdentityMigrator,
}
},
}

// PeopleRococo implementation
impl_accounts_helpers_for_parachain!(PeopleRococo);
impl_assert_events_helpers_for_parachain!(PeopleRococo);
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ decl_test_relay_chains! {
Sudo: rococo_runtime::Sudo,
Balances: rococo_runtime::Balances,
Hrmp: rococo_runtime::Hrmp,
Identity: rococo_runtime::Identity,
IdentityMigrator: rococo_runtime::IdentityMigrator,
}
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ macro_rules! impl_assert_events_helpers_for_relay_chain {
);
}

/// Asserts a XCM message is sent
/// Asserts an XCM program is sent.
pub fn assert_xcm_pallet_sent() {
$crate::impls::assert_expected_events!(
Self,
Expand All @@ -250,7 +250,8 @@ macro_rules! impl_assert_events_helpers_for_relay_chain {
);
}

/// Asserts a XCM from System Parachain is succesfully received and proccessed
/// Asserts an XCM program from a System Parachain is successfully received and
/// processed within expectations.
pub fn assert_ump_queue_processed(
expected_success: bool,
expected_id: Option<$crate::impls::ParaId>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use sp_runtime::{
// Polakdot
use parachains_common::BlockNumber;
use polkadot_runtime_parachains::configuration::HostConfiguration;
use xcm;

// Cumulus
use parachains_common::{AccountId, AssetHubPolkadotAuraId, AuraId};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ emulated-integration-tests-common = { path = "../../common", default-features =
rococo-emulated-chain = { path = "../../chains/relays/rococo" }
asset-hub-rococo-emulated-chain = { path = "../../chains/parachains/assets/asset-hub-rococo" }
bridge-hub-rococo-emulated-chain = { path = "../../chains/parachains/bridges/bridge-hub-rococo" }
people-rococo-emulated-chain = { path = "../../chains/parachains/people/people-rococo" }
penpal-emulated-chain = { path = "../../chains/parachains/testing/penpal" }
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
pub use asset_hub_rococo_emulated_chain;
pub use bridge_hub_rococo_emulated_chain;
pub use penpal_emulated_chain;
pub use people_rococo_emulated_chain;
pub use rococo_emulated_chain;

use asset_hub_rococo_emulated_chain::AssetHubRococo;
use bridge_hub_rococo_emulated_chain::BridgeHubRococo;
use penpal_emulated_chain::{PenpalA, PenpalB};
use people_rococo_emulated_chain::PeopleRococo;
use rococo_emulated_chain::Rococo;

// Cumulus
Expand All @@ -37,6 +39,7 @@ decl_test_networks! {
BridgeHubRococo,
PenpalA,
PenpalB,
PeopleRococo,
],
bridge = ()
},
Expand All @@ -47,5 +50,6 @@ decl_test_sender_receiver_accounts_parameter_types! {
AssetHubRococoPara { sender: ALICE, receiver: BOB },
BridgeHubRococoPara { sender: ALICE, receiver: BOB },
PenpalAPara { sender: ALICE, receiver: BOB },
PenpalBPara { sender: ALICE, receiver: BOB }
PenpalBPara { sender: ALICE, receiver: BOB },
PeopleRococoPara { sender: ALICE, receiver: BOB }
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,42 +66,5 @@ pub type SystemParaToRelayTest = Test<AssetHubRococo, Rococo>;
pub type SystemParaToParaTest = Test<AssetHubRococo, PenpalA>;
pub type ParaToSystemParaTest = Test<PenpalA, AssetHubRococo>;

/// Returns a `TestArgs` instance to be used for the Relay Chain across integration tests
pub fn relay_test_args(
dest: MultiLocation,
beneficiary_id: AccountId32,
amount: Balance,
) -> TestArgs {
TestArgs {
dest,
beneficiary: AccountId32Junction { network: None, id: beneficiary_id.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 by parachains across integration tests
pub fn para_test_args(
dest: MultiLocation,
beneficiary_id: AccountId32,
amount: Balance,
assets: MultiAssets,
asset_id: Option<u32>,
fee_asset_item: u32,
) -> TestArgs {
TestArgs {
dest,
beneficiary: AccountId32Junction { network: None, id: beneficiary_id.into() }.into(),
amount,
assets,
asset_id,
fee_asset_item,
weight_limit: WeightLimit::Unlimited,
}
}

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ fn reserve_transfer_native_asset_from_relay_to_para() {
let test_args = TestContext {
sender: RococoSender::get(),
receiver: PenpalAReceiver::get(),
args: relay_test_args(destination, beneficiary_id, amount_to_send),
args: TestArgs::new_relay(destination, beneficiary_id, amount_to_send),
};

let mut test = RelayToParaTest::new(test_args);
Expand Down Expand Up @@ -319,7 +319,7 @@ fn reserve_transfer_native_asset_from_system_para_to_para() {
let test_args = TestContext {
sender: AssetHubRococoSender::get(),
receiver: PenpalAReceiver::get(),
args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0),
args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0),
};

let mut test = SystemParaToParaTest::new(test_args);
Expand Down Expand Up @@ -363,7 +363,7 @@ fn reserve_transfer_native_asset_from_para_to_system_para() {
let test_args = TestContext {
sender: PenpalASender::get(),
receiver: AssetHubRococoReceiver::get(),
args: para_test_args(destination, beneficiary_id, amount_to_send, assets, None, 0),
args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0),
};

let mut test = ParaToSystemParaTest::new(test_args);
Expand Down Expand Up @@ -443,7 +443,7 @@ fn reserve_transfer_assets_from_system_para_to_para() {
let para_test_args = TestContext {
sender: AssetHubRococoSender::get(),
receiver: PenpalAReceiver::get(),
args: para_test_args(
args: TestArgs::new_para(
destination,
beneficiary_id,
asset_amount_to_send,
Expand Down
Loading

0 comments on commit d186f73

Please sign in to comment.