Skip to content

Commit

Permalink
asset-hub-westend-integration-tests: add more asset transfers tests (#…
Browse files Browse the repository at this point in the history
…2488)

Just adds more tests.
  • Loading branch information
acatangiu authored Nov 27, 2023
1 parent 2610450 commit 4298bc6
Show file tree
Hide file tree
Showing 16 changed files with 402 additions and 127 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ decl_test_parachains! {

// AssetHubRococo implementation
impl_accounts_helpers_for_parachain!(AssetHubRococo);
impl_assert_events_helpers_for_parachain!(AssetHubRococo, false);
impl_assert_events_helpers_for_parachain!(AssetHubRococo);
impl_assets_helpers_for_parachain!(AssetHubRococo, Rococo);
impl_foreign_assets_helpers_for_parachain!(AssetHubRococo, Rococo);
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ decl_test_parachains! {

// AssetHubWestend implementation
impl_accounts_helpers_for_parachain!(AssetHubWestend);
impl_assert_events_helpers_for_parachain!(AssetHubWestend, false);
impl_assert_events_helpers_for_parachain!(AssetHubWestend);
impl_assets_helpers_for_parachain!(AssetHubWestend, Westend);
impl_foreign_assets_helpers_for_parachain!(AssetHubWestend, Westend);
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ decl_test_parachains! {

// BridgeHubRococo implementation
impl_accounts_helpers_for_parachain!(BridgeHubRococo);
impl_assert_events_helpers_for_parachain!(BridgeHubRococo, false);
impl_assert_events_helpers_for_parachain!(BridgeHubRococo);
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ decl_test_parachains! {

// BridgeHubWestend implementation
impl_accounts_helpers_for_parachain!(BridgeHubWestend);
impl_assert_events_helpers_for_parachain!(BridgeHubWestend, false);
impl_assert_events_helpers_for_parachain!(BridgeHubWestend);
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ cumulus-primitives-core = { path = "../../../../../../../primitives/core", defau
emulated-integration-tests-common = { path = "../../../../common", default-features = false }
penpal-runtime = { path = "../../../../../../runtimes/testing/penpal" }
rococo-emulated-chain = { path = "../../../relays/rococo" }
westend-emulated-chain = { path = "../../../relays/westend" }
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use emulated_integration_tests_common::{
impl_assets_helpers_for_parachain, impls::Parachain, xcm_emulator::decl_test_parachains,
};
use rococo_emulated_chain::Rococo;
use westend_emulated_chain::Westend;

// Penpal Parachain declaration
decl_test_parachains! {
Expand Down Expand Up @@ -67,5 +68,6 @@ decl_test_parachains! {
// Penpal implementation
impl_accounts_helpers_for_parachain!(PenpalA);
impl_assets_helpers_for_parachain!(PenpalA, Rococo);
impl_assert_events_helpers_for_parachain!(PenpalA, true);
impl_assert_events_helpers_for_parachain!(PenpalB, true);
impl_assets_helpers_for_parachain!(PenpalB, Westend);
impl_assert_events_helpers_for_parachain!(PenpalA);
impl_assert_events_helpers_for_parachain!(PenpalB);
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ macro_rules! impl_accounts_helpers_for_parachain {

#[macro_export]
macro_rules! impl_assert_events_helpers_for_parachain {
( $chain:ident, $ignore_weight:expr ) => {
( $chain:ident ) => {
$crate::impls::paste::paste! {
type [<$chain RuntimeEvent>]<N> = <$chain<N> as $crate::impls::Chain>::RuntimeEvent;

Expand All @@ -431,7 +431,7 @@ macro_rules! impl_assert_events_helpers_for_parachain {
[<$chain RuntimeEvent>]::<N>::PolkadotXcm(
$crate::impls::pallet_xcm::Event::Attempted { outcome: $crate::impls::Outcome::Complete(weight) }
) => {
weight: $ignore_weight || $crate::impls::weight_within_threshold(
weight: $crate::impls::weight_within_threshold(
($crate::impls::REF_TIME_THRESHOLD, $crate::impls::PROOF_SIZE_THRESHOLD),
expected_weight.unwrap_or(*weight),
*weight
Expand All @@ -453,7 +453,7 @@ macro_rules! impl_assert_events_helpers_for_parachain {
[<$chain RuntimeEvent>]::<N>::PolkadotXcm(
$crate::impls::pallet_xcm::Event::Attempted { outcome: $crate::impls::Outcome::Incomplete(weight, error) }
) => {
weight: $ignore_weight || $crate::impls::weight_within_threshold(
weight: $crate::impls::weight_within_threshold(
($crate::impls::REF_TIME_THRESHOLD, $crate::impls::PROOF_SIZE_THRESHOLD),
expected_weight.unwrap_or(*weight),
*weight
Expand Down Expand Up @@ -509,7 +509,7 @@ macro_rules! impl_assert_events_helpers_for_parachain {
[<$chain RuntimeEvent>]::<N>::MessageQueue($crate::impls::pallet_message_queue::Event::Processed {
success: true, weight_used: weight, ..
}) => {
weight: $ignore_weight || $crate::impls::weight_within_threshold(
weight: $crate::impls::weight_within_threshold(
($crate::impls::REF_TIME_THRESHOLD, $crate::impls::PROOF_SIZE_THRESHOLD),
expected_weight.unwrap_or(*weight),
*weight
Expand All @@ -529,7 +529,7 @@ macro_rules! impl_assert_events_helpers_for_parachain {
[<$chain RuntimeEvent>]::<N>::MessageQueue($crate::impls::pallet_message_queue::Event::Processed {
success: false, weight_used: weight, ..
}) => {
weight: $ignore_weight || $crate::impls::weight_within_threshold(
weight: $crate::impls::weight_within_threshold(
($crate::impls::REF_TIME_THRESHOLD, $crate::impls::PROOF_SIZE_THRESHOLD),
expected_weight.unwrap_or(*weight),
*weight
Expand Down Expand Up @@ -560,7 +560,7 @@ macro_rules! impl_assert_events_helpers_for_parachain {
vec![
[<$chain RuntimeEvent>]::<N>::MessageQueue($crate::impls::pallet_message_queue::Event::Processed { success: true, weight_used: weight, .. }
) => {
weight: $ignore_weight || $crate::impls::weight_within_threshold(
weight: $crate::impls::weight_within_threshold(
($crate::impls::REF_TIME_THRESHOLD, $crate::impls::PROOF_SIZE_THRESHOLD),
expected_weight.unwrap_or(*weight),
*weight
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,6 @@ fn relay_to_para_sender_assertions(t: RelayToParaTest) {
);
}

fn relay_to_para_receiver_assertions<Test>(_: Test) {
type RuntimeEvent = <PenpalA as Chain>::RuntimeEvent;
assert_expected_events!(
PenpalA,
vec![
RuntimeEvent::Balances(pallet_balances::Event::Deposit { .. }) => {},
RuntimeEvent::MessageQueue(
pallet_message_queue::Event::Processed { success: true, .. }
) => {},
]
);
}

fn system_para_to_para_sender_assertions(t: SystemParaToParaTest) {
type RuntimeEvent = <AssetHubRococo as Chain>::RuntimeEvent;

Expand All @@ -78,7 +65,7 @@ fn system_para_to_para_sender_assertions(t: SystemParaToParaTest) {
);
}

fn system_para_to_para_receiver_assertions<Test>(_: Test) {
fn para_receiver_assertions<Test>(_: Test) {
type RuntimeEvent = <PenpalA as Chain>::RuntimeEvent;
assert_expected_events!(
PenpalA,
Expand Down Expand Up @@ -297,7 +284,7 @@ fn reserve_transfer_native_asset_from_relay_to_para() {
let receiver_balance_before = test.receiver.balance;

test.set_assertion::<Rococo>(relay_to_para_sender_assertions);
test.set_assertion::<PenpalA>(relay_to_para_receiver_assertions);
test.set_assertion::<PenpalA>(para_receiver_assertions);
test.set_dispatchable::<Rococo>(relay_to_para_limited_reserve_transfer_assets);
test.assert();

Expand All @@ -314,6 +301,10 @@ fn reserve_transfer_native_asset_from_relay_to_para() {
assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after);
// Receiver's balance is increased
assert!(receiver_balance_after > receiver_balance_before);
// Receiver's balance increased by `amount_to_send - delivery_fees - bought_execution`;
// `delivery_fees` might be paid from transfer or JIT, also `bought_execution` is unknown but
// should be non-zero
assert!(receiver_balance_after < receiver_balance_before + amount_to_send);
}

/// Reserve Transfers of native asset from System Parachain to Parachain should work
Expand All @@ -337,7 +328,7 @@ fn reserve_transfer_native_asset_from_system_para_to_para() {
let receiver_balance_before = test.receiver.balance;

test.set_assertion::<AssetHubRococo>(system_para_to_para_sender_assertions);
test.set_assertion::<PenpalA>(system_para_to_para_receiver_assertions);
test.set_assertion::<PenpalA>(para_receiver_assertions);
test.set_dispatchable::<AssetHubRococo>(system_para_to_para_limited_reserve_transfer_assets);
test.assert();

Expand All @@ -354,6 +345,10 @@ fn reserve_transfer_native_asset_from_system_para_to_para() {
assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after);
// Receiver's balance is increased
assert!(receiver_balance_after > receiver_balance_before);
// Receiver's balance increased by `amount_to_send - delivery_fees - bought_execution`;
// `delivery_fees` might be paid from transfer or JIT, also `bought_execution` is unknown but
// should be non-zero
assert!(receiver_balance_after < receiver_balance_before + amount_to_send);
}

/// Reserve Transfers of native asset from Parachain to System Parachain should work
Expand Down Expand Up @@ -400,6 +395,10 @@ fn reserve_transfer_native_asset_from_para_to_system_para() {
assert_eq!(sender_balance_before - amount_to_send - delivery_fees, sender_balance_after);
// Receiver's balance is increased
assert!(receiver_balance_after > receiver_balance_before);
// Receiver's balance increased by `amount_to_send - delivery_fees - bought_execution`;
// `delivery_fees` might be paid from transfer or JIT, also `bought_execution` is unknown but
// should be non-zero
assert!(receiver_balance_after < receiver_balance_before + amount_to_send);
}

/// Reserve Transfers of a local asset and native asset from System Parachain to Parachain should
Expand All @@ -420,7 +419,7 @@ fn reserve_transfer_assets_from_system_para_to_para() {
ASSET_MIN_BALANCE,
false,
PenpalASender::get(),
Some(Weight::from_parts(1_019_445_000, 200_000)),
None,
0,
);

Expand Down Expand Up @@ -485,6 +484,10 @@ fn reserve_transfer_assets_from_system_para_to_para() {
assert!(sender_balance_after < sender_balance_before);
// Receiver's balance is increased
assert!(receiver_balance_after > receiver_balance_before);
// Receiver's balance increased by `amount_to_send - delivery_fees - bought_execution`;
// `delivery_fees` might be paid from transfer or JIT, also `bought_execution` is unknown but
// should be non-zero
assert!(receiver_balance_after < receiver_balance_before + fee_amount_to_send);

let sender_assets_after = AssetHubRococo::execute_with(|| {
type Assets = <AssetHubRococo as AssetHubRococoPallet>::Assets;
Expand All @@ -495,8 +498,8 @@ fn reserve_transfer_assets_from_system_para_to_para() {
<Assets as Inspect<_>>::balance(ASSET_ID, &PenpalAReceiver::get())
});

// Sender's balance is reduced
// Sender's balance is reduced by exact amount
assert_eq!(sender_assets_before - asset_amount_to_send, sender_assets_after);
// Receiver's balance is increased
assert!(receiver_assets_after > receiver_assets_before);
// Receiver's balance is increased by exact amount
assert_eq!(receiver_assets_after, receiver_assets_before + asset_amount_to_send);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ fn swap_locally_on_chain_using_local_assets() {
100_000_000_000_000,
));

assert_ok!(<AssetHubRococo as AssetHubRococoPallet>::Balances::force_set_balance(
<AssetHubRococo as Chain>::RuntimeOrigin::root(),
AssetHubRococoSender::get().into(),
100_000_000_000_000,
));

assert_ok!(<AssetHubRococo as AssetHubRococoPallet>::AssetConversion::create_pool(
<AssetHubRococo as Chain>::RuntimeOrigin::signed(AssetHubRococoSender::get()),
asset_native.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ asset-test-utils = { path = "../../../../../runtimes/assets/test-utils" }
cumulus-pallet-dmp-queue = { default-features = false, path = "../../../../../../pallets/dmp-queue" }
cumulus-pallet-parachain-system = { default-features = false, path = "../../../../../../pallets/parachain-system" }
emulated-integration-tests-common = { path = "../../../common", default-features = false}
penpal-runtime = { path = "../../../../../runtimes/testing/penpal" }
westend-system-emulated-network ={ path = "../../../networks/westend-system" }
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ pub use westend_system_emulated_network::{
asset_hub_westend_emulated_chain::{
genesis::ED as ASSET_HUB_WESTEND_ED, AssetHubWestendParaPallet as AssetHubWestendPallet,
},
penpal_emulated_chain::PenpalAParaPallet as PenpalAPallet,
penpal_emulated_chain::PenpalBParaPallet as PenpalBPallet,
westend_emulated_chain::{genesis::ED as WESTEND_ED, WestendRelayPallet as WestendPallet},
AssetHubWestendPara as AssetHubWestend, AssetHubWestendParaReceiver as AssetHubWestendReceiver,
AssetHubWestendParaSender as AssetHubWestendSender, PenpalAPara as PenpalA,
PenpalAParaReceiver as PenpalAReceiver, PenpalAParaSender as PenpalASender,
AssetHubWestendParaSender as AssetHubWestendSender, BridgeHubWestendPara as BridgeHubWestend,
BridgeHubWestendParaReceiver as BridgeHubWestendReceiver, PenpalBPara as PenpalB,
PenpalBParaReceiver as PenpalBReceiver, PenpalBParaSender as PenpalBSender,
WestendRelay as Westend, WestendRelayReceiver as WestendReceiver,
WestendRelaySender as WestendSender,
};
Expand All @@ -62,18 +63,20 @@ pub const ASSET_MIN_BALANCE: u128 = 1000;
pub const ASSETS_PALLET_ID: u8 = 50;

pub type RelayToSystemParaTest = Test<Westend, AssetHubWestend>;
pub type RelayToParaTest = Test<Westend, PenpalB>;
pub type SystemParaToRelayTest = Test<AssetHubWestend, Westend>;
pub type SystemParaToParaTest = Test<AssetHubWestend, PenpalA>;
pub type SystemParaToParaTest = Test<AssetHubWestend, PenpalB>;
pub type ParaToSystemParaTest = Test<PenpalB, AssetHubWestend>;

/// Returns a `TestArgs` instance to be used for the Relay Chain across integration tests
pub fn relay_test_args(amount: Balance) -> TestArgs {
pub fn relay_test_args(
dest: MultiLocation,
beneficiary_id: AccountId32,
amount: Balance,
) -> TestArgs {
TestArgs {
dest: Westend::child_location_of(AssetHubWestend::para_id()),
beneficiary: AccountId32Junction {
network: None,
id: AssetHubWestendReceiver::get().into(),
}
.into(),
dest,
beneficiary: AccountId32Junction { network: None, id: beneficiary_id.into() }.into(),
amount,
assets: (Here, amount).into(),
asset_id: None,
Expand All @@ -82,21 +85,22 @@ pub fn relay_test_args(amount: Balance) -> TestArgs {
}
}

/// Returns a `TestArgs` instance to be used for the System Parachain across integration tests
pub fn system_para_test_args(
/// 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: 0,
fee_asset_item,
weight_limit: WeightLimit::Unlimited,
}
}
Expand Down
Loading

0 comments on commit 4298bc6

Please sign in to comment.