Skip to content

Commit e4f8a6d

Browse files
authored
[tests] dedup test code, add more tests, improve naming and docs (#5338)
This is mostly tests cleanup: - uses helper macro for generating teleport tests, - adds missing treasury tests, - improves naming and docs for transfer tests. - [x] does not need a PRDOC --------- Co-authored-by: command-bot <>
1 parent d944ac2 commit e4f8a6d

File tree

33 files changed

+376
-1838
lines changed

33 files changed

+376
-1838
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ use sp_core::storage::Storage;
1818

1919
// Cumulus
2020
use cumulus_primitives_core::ParaId;
21-
use emulated_integration_tests_common::{build_genesis_storage, collators, SAFE_XCM_VERSION};
21+
use emulated_integration_tests_common::{
22+
accounts, build_genesis_storage, collators, SAFE_XCM_VERSION,
23+
};
2224
use parachains_common::Balance;
2325

2426
pub const PARA_ID: u32 = 1004;
@@ -27,6 +29,9 @@ pub const ED: Balance = testnet_parachains_constants::rococo::currency::EXISTENT
2729
pub fn genesis() -> Storage {
2830
let genesis_config = people_rococo_runtime::RuntimeGenesisConfig {
2931
system: people_rococo_runtime::SystemConfig::default(),
32+
balances: people_rococo_runtime::BalancesConfig {
33+
balances: accounts::init_balances().iter().cloned().map(|k| (k, ED * 4096)).collect(),
34+
},
3035
parachain_info: people_rococo_runtime::ParachainInfoConfig {
3136
parachain_id: ParaId::from(PARA_ID),
3237
..Default::default()

cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-westend/src/genesis.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ use sp_core::storage::Storage;
1818

1919
// Cumulus
2020
use cumulus_primitives_core::ParaId;
21-
use emulated_integration_tests_common::{build_genesis_storage, collators, SAFE_XCM_VERSION};
21+
use emulated_integration_tests_common::{
22+
accounts, build_genesis_storage, collators, SAFE_XCM_VERSION,
23+
};
2224
use parachains_common::Balance;
2325

2426
pub const PARA_ID: u32 = 1004;
@@ -27,6 +29,9 @@ pub const ED: Balance = testnet_parachains_constants::westend::currency::EXISTEN
2729
pub fn genesis() -> Storage {
2830
let genesis_config = people_westend_runtime::RuntimeGenesisConfig {
2931
system: people_westend_runtime::SystemConfig::default(),
32+
balances: people_westend_runtime::BalancesConfig {
33+
balances: accounts::init_balances().iter().cloned().map(|k| (k, ED * 4096)).collect(),
34+
},
3035
parachain_info: people_westend_runtime::ParachainInfoConfig {
3136
parachain_id: ParaId::from(PARA_ID),
3237
..Default::default()

cumulus/parachains/integration-tests/emulated/common/src/macros.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ macro_rules! test_parachain_is_trusted_teleporter_for_relay {
228228
$crate::macros::paste::paste! {
229229
// init Origin variables
230230
let sender = [<$sender_para Sender>]::get();
231-
let mut para_sender_balance_before =
231+
let para_sender_balance_before =
232232
<$sender_para as $crate::macros::Chain>::account_data_of(sender.clone()).free;
233233
let origin = <$sender_para as $crate::macros::Chain>::RuntimeOrigin::signed(sender.clone());
234234
let assets: Assets = (Parent, $amount).into();
@@ -302,9 +302,6 @@ macro_rules! test_parachain_is_trusted_teleporter_for_relay {
302302

303303
assert_eq!(para_sender_balance_before - $amount - delivery_fees, para_sender_balance_after);
304304
assert!(relay_receiver_balance_after > relay_receiver_balance_before);
305-
306-
// Update sender balance
307-
para_sender_balance_before = <$sender_para as $crate::macros::Chain>::account_data_of(sender.clone()).free;
308305
}
309306
};
310307
}

cumulus/parachains/integration-tests/emulated/common/src/xcm_helpers.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,15 @@ use xcm::{prelude::*, DoubleEncoded};
2323
pub fn xcm_transact_paid_execution(
2424
call: DoubleEncoded<()>,
2525
origin_kind: OriginKind,
26-
native_asset: Asset,
26+
fees: Asset,
2727
beneficiary: AccountId,
2828
) -> VersionedXcm<()> {
2929
let weight_limit = WeightLimit::Unlimited;
3030
let require_weight_at_most = Weight::from_parts(1000000000, 200000);
31-
let native_assets: Assets = native_asset.clone().into();
3231

3332
VersionedXcm::from(Xcm(vec![
34-
WithdrawAsset(native_assets),
35-
BuyExecution { fees: native_asset, weight_limit },
33+
WithdrawAsset(fees.clone().into()),
34+
BuyExecution { fees, weight_limit },
3635
Transact { require_weight_at_most, origin_kind, call },
3736
RefundSurplus,
3837
DepositAsset {

cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ mod imports {
3737
pub use emulated_integration_tests_common::{
3838
accounts::DUMMY_EMPTY,
3939
get_account_id_from_seed, test_parachain_is_trusted_teleporter,
40+
test_parachain_is_trusted_teleporter_for_relay, test_relay_is_trusted_teleporter,
4041
xcm_emulator::{
4142
assert_expected_events, bx, Chain, Parachain as Para, RelayChain as Relay, Test,
4243
TestArgs, TestContext, TestExt,
@@ -91,7 +92,6 @@ mod imports {
9192
pub const ASSET_ID: u32 = 3;
9293
pub const ASSET_MIN_BALANCE: u128 = 1000;
9394

94-
pub type RelayToSystemParaTest = Test<Rococo, AssetHubRococo>;
9595
pub type RelayToParaTest = Test<Rococo, PenpalA>;
9696
pub type ParaToRelayTest = Test<PenpalA, Rococo>;
9797
pub type SystemParaToRelayTest = Test<AssetHubRococo, Rococo>;

cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/reserve_transfer.rs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -493,9 +493,9 @@ fn para_to_para_through_relay_limited_reserve_transfer_assets(
493493
)
494494
}
495495

496-
/// Reserve Transfers of native asset from Relay Chain to the System Parachain shouldn't work
496+
/// Reserve Transfers of native asset from Relay Chain to the Asset Hub shouldn't work
497497
#[test]
498-
fn reserve_transfer_native_asset_from_relay_to_system_para_fails() {
498+
fn reserve_transfer_native_asset_from_relay_to_asset_hub_fails() {
499499
// Init values for Relay Chain
500500
let signed_origin = <Rococo as Chain>::RuntimeOrigin::signed(RococoSender::get().into());
501501
let destination = Rococo::child_location_of(AssetHubRococo::para_id());
@@ -526,10 +526,10 @@ fn reserve_transfer_native_asset_from_relay_to_system_para_fails() {
526526
});
527527
}
528528

529-
/// Reserve Transfers of native asset from System Parachain to Relay Chain shouldn't work
529+
/// Reserve Transfers of native asset from Asset Hub to Relay Chain shouldn't work
530530
#[test]
531-
fn reserve_transfer_native_asset_from_system_para_to_relay_fails() {
532-
// Init values for System Parachain
531+
fn reserve_transfer_native_asset_from_asset_hub_to_relay_fails() {
532+
// Init values for Asset Hub
533533
let signed_origin =
534534
<AssetHubRococo as Chain>::RuntimeOrigin::signed(AssetHubRococoSender::get().into());
535535
let destination = AssetHubRococo::parent_location();
@@ -691,10 +691,10 @@ fn reserve_transfer_native_asset_from_para_to_relay() {
691691
// =========================================================================
692692
// ======= Reserve Transfers - Native Asset - AssetHub<>Parachain ==========
693693
// =========================================================================
694-
/// Reserve Transfers of native asset from System Parachain to Parachain should work
694+
/// Reserve Transfers of native asset from Asset Hub to Parachain should work
695695
#[test]
696-
fn reserve_transfer_native_asset_from_system_para_to_para() {
697-
// Init values for System Parachain
696+
fn reserve_transfer_native_asset_from_asset_hub_to_para() {
697+
// Init values for Asset Hub
698698
let destination = AssetHubRococo::sibling_location_of(PenpalA::para_id());
699699
let sender = AssetHubRococoSender::get();
700700
let amount_to_send: Balance = ASSET_HUB_ROCOCO_ED * 10000;
@@ -749,9 +749,9 @@ fn reserve_transfer_native_asset_from_system_para_to_para() {
749749
assert!(receiver_assets_after < receiver_assets_before + amount_to_send);
750750
}
751751

752-
/// Reserve Transfers of native asset from Parachain to System Parachain should work
752+
/// Reserve Transfers of native asset from Parachain to Asset Hub should work
753753
#[test]
754-
fn reserve_transfer_native_asset_from_para_to_system_para() {
754+
fn reserve_transfer_native_asset_from_para_to_asset_hub() {
755755
// Init values for Parachain
756756
let destination = PenpalA::sibling_location_of(AssetHubRococo::para_id());
757757
let sender = PenpalASender::get();
@@ -768,12 +768,12 @@ fn reserve_transfer_native_asset_from_para_to_system_para() {
768768
amount_to_send * 2,
769769
);
770770

771-
// Init values for System Parachain
771+
// Init values for Asset Hub
772772
let receiver = AssetHubRococoReceiver::get();
773773
let penpal_location_as_seen_by_ahr = AssetHubRococo::sibling_location_of(PenpalA::para_id());
774774
let sov_penpal_on_ahr = AssetHubRococo::sovereign_account_id_of(penpal_location_as_seen_by_ahr);
775775

776-
// fund Parachain's SA on System Parachain with the native tokens held in reserve
776+
// fund Parachain's SA on Asset Hub with the native tokens held in reserve
777777
AssetHubRococo::fund_accounts(vec![(sov_penpal_on_ahr.into(), amount_to_send * 2)]);
778778

779779
// Init Test
@@ -824,11 +824,11 @@ fn reserve_transfer_native_asset_from_para_to_system_para() {
824824
// ==================================================================================
825825
// ======= Reserve Transfers - Native + Non-system Asset - AssetHub<>Parachain ======
826826
// ==================================================================================
827-
/// Reserve Transfers of a local asset and native asset from System Parachain to Parachain should
827+
/// Reserve Transfers of a local asset and native asset from Asset Hub to Parachain should
828828
/// work
829829
#[test]
830-
fn reserve_transfer_assets_from_system_para_to_para() {
831-
// Init values for System Parachain
830+
fn reserve_transfer_multiple_assets_from_asset_hub_to_para() {
831+
// Init values for Asset Hub
832832
let destination = AssetHubRococo::sibling_location_of(PenpalA::para_id());
833833
let sov_penpal_on_ahr = AssetHubRococo::sovereign_account_id_of(destination.clone());
834834
let sender = AssetHubRococoSender::get();
@@ -939,13 +939,12 @@ fn reserve_transfer_assets_from_system_para_to_para() {
939939
);
940940
}
941941

942-
/// Reserve Transfers of a random asset and native asset from Parachain to System Para should
943-
/// work
942+
/// Reserve Transfers of a random asset and native asset from Parachain to Asset Hub should work
944943
/// Receiver is empty account to show deposit works as long as transfer includes enough DOT for ED.
945944
/// Once we have https://github.com/paritytech/polkadot-sdk/issues/5298,
946945
/// we should do equivalent test with USDT instead of DOT.
947946
#[test]
948-
fn reserve_transfer_assets_from_para_to_system_para() {
947+
fn reserve_transfer_multiple_assets_from_para_to_asset_hub() {
949948
// Init values for Parachain
950949
let destination = PenpalA::sibling_location_of(AssetHubRococo::para_id());
951950
let sender = PenpalASender::get();
@@ -982,7 +981,7 @@ fn reserve_transfer_assets_from_para_to_system_para() {
982981

983982
// Beneficiary is a new (empty) account
984983
let receiver = get_account_id_from_seed::<sp_runtime::testing::sr25519::Public>(DUMMY_EMPTY);
985-
// Init values for System Parachain
984+
// Init values for Asset Hub
986985
let penpal_location_as_seen_by_ahr = AssetHubRococo::sibling_location_of(PenpalA::para_id());
987986
let sov_penpal_on_ahr = AssetHubRococo::sovereign_account_id_of(penpal_location_as_seen_by_ahr);
988987
let ah_asset_owner = AssetHubRococoAssetOwner::get();

cumulus/parachains/integration-tests/emulated/tests/assets/asset-hub-rococo/src/tests/send.rs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::imports::*;
1818
/// Relay Chain should be able to execute `Transact` instructions in System Parachain
1919
/// when `OriginKind::Superuser`.
2020
#[test]
21-
fn send_transact_as_superuser_from_relay_to_system_para_works() {
21+
fn send_transact_as_superuser_from_relay_to_asset_hub_works() {
2222
AssetHubRococo::force_create_asset_from_relay_as_root(
2323
ASSET_ID,
2424
ASSET_MIN_BALANCE,
@@ -29,10 +29,10 @@ fn send_transact_as_superuser_from_relay_to_system_para_works() {
2929
}
3030

3131
/// We tests two things here:
32-
/// - Parachain should be able to send XCM paying its fee with system asset in the System Parachain
33-
/// - Parachain should be able to create a new Foreign Asset in the System Parachain
32+
/// - Parachain should be able to send XCM paying its fee at Asset Hub using system asset
33+
/// - Parachain should be able to create a new Foreign Asset at Asset Hub
3434
#[test]
35-
fn send_xcm_from_para_to_system_para_paying_fee_with_system_assets_works() {
35+
fn send_xcm_from_para_to_asset_hub_paying_fee_with_system_asset() {
3636
let para_sovereign_account = AssetHubRococo::sovereign_account_id_of(
3737
AssetHubRococo::sibling_location_of(PenpalA::para_id()),
3838
);
@@ -83,12 +83,7 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_system_assets_works() {
8383

8484
AssetHubRococo::execute_with(|| {
8585
type RuntimeEvent = <AssetHubRococo as Chain>::RuntimeEvent;
86-
87-
AssetHubRococo::assert_xcmp_queue_success(Some(Weight::from_parts(
88-
15_594_564_000,
89-
562_893,
90-
)));
91-
86+
AssetHubRococo::assert_xcmp_queue_success(None);
9287
assert_expected_events!(
9388
AssetHubRococo,
9489
vec![
@@ -112,15 +107,15 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_system_assets_works() {
112107
}
113108

114109
/// We tests two things here:
115-
/// - Parachain should be able to send XCM paying its fee with system assets in the System Parachain
116-
/// - Parachain should be able to create a new Asset in the System Parachain
110+
/// - Parachain should be able to send XCM paying its fee at Asset Hub using sufficient asset
111+
/// - Parachain should be able to create a new Asset at Asset Hub
117112
#[test]
118-
fn send_xcm_from_para_to_system_para_paying_fee_with_assets_works() {
113+
fn send_xcm_from_para_to_asset_hub_paying_fee_with_sufficient_asset() {
119114
let para_sovereign_account = AssetHubRococo::sovereign_account_id_of(
120115
AssetHubRococo::sibling_location_of(PenpalA::para_id()),
121116
);
122117

123-
// Force create and mint assets for Parachain's sovereign account
118+
// Force create and mint sufficient assets for Parachain's sovereign account
124119
AssetHubRococo::force_create_and_mint_asset(
125120
ASSET_ID,
126121
ASSET_MIN_BALANCE,
@@ -167,12 +162,7 @@ fn send_xcm_from_para_to_system_para_paying_fee_with_assets_works() {
167162

168163
AssetHubRococo::execute_with(|| {
169164
type RuntimeEvent = <AssetHubRococo as Chain>::RuntimeEvent;
170-
171-
AssetHubRococo::assert_xcmp_queue_success(Some(Weight::from_parts(
172-
15_594_564_000,
173-
562_893,
174-
)));
175-
165+
AssetHubRococo::assert_xcmp_queue_success(None);
176166
assert_expected_events!(
177167
AssetHubRococo,
178168
vec![

0 commit comments

Comments
 (0)