Skip to content

Commit

Permalink
xcm-executor: allow deposit of multiple assets if at least one of the…
Browse files Browse the repository at this point in the history
…m satisfies ED (paritytech#4460)

Closes paritytech#4242

XCM programs that deposit assets to some new (empty) account will now
succeed if at least one of the deposited assets satisfies ED. Before
this change, the requirement was that the _first_ asset had to satisfy
ED, but assets order can be changed during reanchoring so it is not
reliable.

With this PR, ordering doesn't matter, any one(s) of them can satisfy ED
for the whole deposit to work.

Kusama address: FkB6QEo8VnV3oifugNj5NeVG3Mvq1zFbrUu4P5YwRoe5mQN

---------

Co-authored-by: Adrian Catangiu <[email protected]>
Co-authored-by: Francisco Aguirre <[email protected]>
Co-authored-by: command-bot <>
  • Loading branch information
3 people committed Aug 12, 2024
1 parent 0b52a2c commit ebcbca3
Show file tree
Hide file tree
Showing 26 changed files with 869 additions and 831 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ pub mod accounts {
pub const EVE_STASH: &str = "Eve//stash";
pub const FERDIE_STASH: &str = "Ferdie//stash";
pub const FERDIE_BEEFY: &str = "Ferdie//stash";
pub const DUMMY_EMPTY: &str = "JohnDoe";

pub fn init_balances() -> Vec<AccountId> {
vec![
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ mod imports {
// Cumulus
pub use asset_test_utils::xcm_helpers;
pub use emulated_integration_tests_common::{
test_parachain_is_trusted_teleporter,
accounts::DUMMY_EMPTY,
get_account_id_from_seed, test_parachain_is_trusted_teleporter,
xcm_emulator::{
assert_expected_events, bx, Chain, Parachain as Para, RelayChain as Relay, Test,
TestArgs, TestContext, TestExt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,9 @@ fn reserve_transfer_assets_from_system_para_to_para() {

/// Reserve Transfers of a random asset and native asset from Parachain to System Para should
/// work
/// Receiver is empty account to show deposit works as long as transfer includes enough DOT for ED.
/// Once we have https://github.com/paritytech/polkadot-sdk/issues/5298,
/// we should do equivalent test with USDT instead of DOT.
#[test]
fn reserve_transfer_assets_from_para_to_system_para() {
// Init values for Parachain
Expand All @@ -965,24 +968,23 @@ fn reserve_transfer_assets_from_para_to_system_para() {
// Fund Parachain's sender account with some foreign assets
PenpalA::mint_foreign_asset(
penpal_asset_owner_signer.clone(),
asset_location_on_penpal,
asset_location_on_penpal.clone(),
sender.clone(),
asset_amount_to_send * 2,
);
// Fund Parachain's sender account with some system assets
PenpalA::mint_foreign_asset(
penpal_asset_owner_signer,
system_asset_location_on_penpal,
system_asset_location_on_penpal.clone(),
sender.clone(),
fee_amount_to_send * 2,
);

// Beneficiary is a new (empty) account
let receiver = get_account_id_from_seed::<sp_runtime::testing::sr25519::Public>(DUMMY_EMPTY);
// Init values for System Parachain
let receiver = AssetHubRococoReceiver::get();
let penpal_location_as_seen_by_ahr = AssetHubRococo::sibling_location_of(PenpalA::para_id());
let sov_penpal_on_ahr = AssetHubRococo::sovereign_account_id_of(penpal_location_as_seen_by_ahr);
let system_para_native_asset_location = RelayLocation::get();
let system_para_foreign_asset_location = PenpalLocalReservableFromAssetHub::get();
let ah_asset_owner = AssetHubRococoAssetOwner::get();
let ah_asset_owner_signer = <AssetHubRococo as Chain>::RuntimeOrigin::signed(ah_asset_owner);

Expand Down Expand Up @@ -1017,11 +1019,11 @@ fn reserve_transfer_assets_from_para_to_system_para() {
// Query initial balances
let sender_system_assets_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(system_para_native_asset_location.clone(), &sender)
<ForeignAssets as Inspect<_>>::balance(system_asset_location_on_penpal.clone(), &sender)
});
let sender_foreign_assets_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(system_para_foreign_asset_location.clone(), &sender)
<ForeignAssets as Inspect<_>>::balance(asset_location_on_penpal.clone(), &sender)
});
let receiver_balance_before = test.receiver.balance;
let receiver_assets_before = AssetHubRococo::execute_with(|| {
Expand All @@ -1038,11 +1040,11 @@ fn reserve_transfer_assets_from_para_to_system_para() {
// Query final balances
let sender_system_assets_after = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(system_para_native_asset_location.clone(), &sender)
<ForeignAssets as Inspect<_>>::balance(system_asset_location_on_penpal, &sender)
});
let sender_foreign_assets_after = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(system_para_foreign_asset_location, &sender)
<ForeignAssets as Inspect<_>>::balance(asset_location_on_penpal, &sender)
});
let receiver_balance_after = test.receiver.balance;
let receiver_assets_after = AssetHubRococo::execute_with(|| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ mod imports {
// Cumulus
pub use asset_test_utils::xcm_helpers;
pub use emulated_integration_tests_common::{
test_parachain_is_trusted_teleporter,
accounts::DUMMY_EMPTY,
get_account_id_from_seed, test_parachain_is_trusted_teleporter,
xcm_emulator::{
assert_expected_events, bx, Chain, Parachain as Para, RelayChain as Relay, Test,
TestArgs, TestContext, TestExt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,9 @@ fn reserve_transfer_assets_from_system_para_to_para() {

/// Reserve Transfers of a random asset and native asset from Parachain to System Para should
/// work
/// Receiver is empty account to show deposit works as long as transfer includes enough DOT for ED.
/// Once we have https://github.com/paritytech/polkadot-sdk/issues/5298,
/// we should do equivalent test with USDT instead of DOT.
#[test]
fn reserve_transfer_assets_from_para_to_system_para() {
// Init values for Parachain
Expand All @@ -966,25 +969,24 @@ fn reserve_transfer_assets_from_para_to_system_para() {
// Fund Parachain's sender account with some foreign assets
PenpalA::mint_foreign_asset(
penpal_asset_owner_signer.clone(),
asset_location_on_penpal,
asset_location_on_penpal.clone(),
sender.clone(),
asset_amount_to_send * 2,
);
// Fund Parachain's sender account with some system assets
PenpalA::mint_foreign_asset(
penpal_asset_owner_signer,
system_asset_location_on_penpal,
system_asset_location_on_penpal.clone(),
sender.clone(),
fee_amount_to_send * 2,
);

// Beneficiary is a new (empty) account
let receiver = get_account_id_from_seed::<sp_runtime::testing::sr25519::Public>(DUMMY_EMPTY);
// Init values for System Parachain
let receiver = AssetHubWestendReceiver::get();
let penpal_location_as_seen_by_ahr = AssetHubWestend::sibling_location_of(PenpalA::para_id());
let sov_penpal_on_ahr =
AssetHubWestend::sovereign_account_id_of(penpal_location_as_seen_by_ahr);
let system_para_native_asset_location = RelayLocation::get();
let system_para_foreign_asset_location = PenpalLocalReservableFromAssetHub::get();
let ah_asset_owner = AssetHubWestendAssetOwner::get();
let ah_asset_owner_signer = <AssetHubWestend as Chain>::RuntimeOrigin::signed(ah_asset_owner);

Expand Down Expand Up @@ -1019,11 +1021,11 @@ fn reserve_transfer_assets_from_para_to_system_para() {
// Query initial balances
let sender_system_assets_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(system_para_native_asset_location.clone(), &sender)
<ForeignAssets as Inspect<_>>::balance(system_asset_location_on_penpal.clone(), &sender)
});
let sender_foreign_assets_before = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(system_para_foreign_asset_location.clone(), &sender)
<ForeignAssets as Inspect<_>>::balance(asset_location_on_penpal.clone(), &sender)
});
let receiver_balance_before = test.receiver.balance;
let receiver_assets_before = AssetHubWestend::execute_with(|| {
Expand All @@ -1040,11 +1042,11 @@ fn reserve_transfer_assets_from_para_to_system_para() {
// Query final balances
let sender_system_assets_after = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(system_para_native_asset_location, &sender)
<ForeignAssets as Inspect<_>>::balance(system_asset_location_on_penpal, &sender)
});
let sender_foreign_assets_after = PenpalA::execute_with(|| {
type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(system_para_foreign_asset_location, &sender)
<ForeignAssets as Inspect<_>>::balance(asset_location_on_penpal, &sender)
});
let receiver_balance_after = test.receiver.balance;
let receiver_assets_after = AssetHubWestend::execute_with(|| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,8 @@ fn send_token_from_ethereum_to_non_existent_account_on_asset_hub_with_insufficie
#[test]
fn send_token_from_ethereum_to_non_existent_account_on_asset_hub_with_sufficient_fee_but_do_not_satisfy_ed(
) {
// On AH the xcm fee is 33_873_024 and the ED is 3_300_000
send_token_from_ethereum_to_asset_hub_with_fee([1; 32], 36_000_000);
// On AH the xcm fee is 26_789_690 and the ED is 3_300_000
send_token_from_ethereum_to_asset_hub_with_fee([1; 32], 30_000_000);

AssetHubRococo::execute_with(|| {
type RuntimeEvent = <AssetHubRococo as Chain>::RuntimeEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ mod imports {
// Substrate
pub use frame_support::{
assert_ok,
pallet_prelude::Weight,
sp_runtime::{AccountId32, DispatchResult},
traits::fungibles::Inspect,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::imports::*;

fn relay_origin_assertions(t: RelayToSystemParaTest) {
type RuntimeEvent = <Rococo as Chain>::RuntimeEvent;
Rococo::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(627_959_000, 7_200)));
Rococo::assert_xcm_pallet_attempted_complete(None);

assert_expected_events!(
Rococo,
Expand All @@ -39,11 +39,7 @@ fn relay_origin_assertions(t: RelayToSystemParaTest) {
fn relay_dest_assertions(t: SystemParaToRelayTest) {
type RuntimeEvent = <Rococo as Chain>::RuntimeEvent;

Rococo::assert_ump_queue_processed(
true,
Some(PeopleRococo::para_id()),
Some(Weight::from_parts(304_266_000, 7_186)),
);
Rococo::assert_ump_queue_processed(true, Some(PeopleRococo::para_id()), None);

assert_expected_events!(
Rococo,
Expand All @@ -62,20 +58,13 @@ fn relay_dest_assertions(t: SystemParaToRelayTest) {
}

fn relay_dest_assertions_fail(_t: SystemParaToRelayTest) {
Rococo::assert_ump_queue_processed(
false,
Some(PeopleRococo::para_id()),
Some(Weight::from_parts(157_718_000, 3_593)),
);
Rococo::assert_ump_queue_processed(false, Some(PeopleRococo::para_id()), None);
}

fn para_origin_assertions(t: SystemParaToRelayTest) {
type RuntimeEvent = <PeopleRococo as Chain>::RuntimeEvent;

PeopleRococo::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(
600_000_000,
7_000,
)));
PeopleRococo::assert_xcm_pallet_attempted_complete(None);

PeopleRococo::assert_parachain_system_ump_sent();

Expand All @@ -94,7 +83,7 @@ fn para_origin_assertions(t: SystemParaToRelayTest) {
fn para_dest_assertions(t: RelayToSystemParaTest) {
type RuntimeEvent = <PeopleRococo as Chain>::RuntimeEvent;

PeopleRococo::assert_dmp_queue_complete(Some(Weight::from_parts(162_456_000, 0)));
PeopleRococo::assert_dmp_queue_complete(None);

assert_expected_events!(
PeopleRococo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ mod imports {
// Substrate
pub use frame_support::{
assert_ok,
pallet_prelude::Weight,
sp_runtime::{AccountId32, DispatchResult},
traits::fungibles::Inspect,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::imports::*;

fn relay_origin_assertions(t: RelayToSystemParaTest) {
type RuntimeEvent = <Westend as Chain>::RuntimeEvent;
Westend::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(627_959_000, 7_200)));
Westend::assert_xcm_pallet_attempted_complete(None);

assert_expected_events!(
Westend,
Expand All @@ -39,11 +39,7 @@ fn relay_origin_assertions(t: RelayToSystemParaTest) {
fn relay_dest_assertions(t: SystemParaToRelayTest) {
type RuntimeEvent = <Westend as Chain>::RuntimeEvent;

Westend::assert_ump_queue_processed(
true,
Some(PeopleWestend::para_id()),
Some(Weight::from_parts(304_266_000, 7_186)),
);
Westend::assert_ump_queue_processed(true, Some(PeopleWestend::para_id()), None);

assert_expected_events!(
Westend,
Expand All @@ -62,20 +58,13 @@ fn relay_dest_assertions(t: SystemParaToRelayTest) {
}

fn relay_dest_assertions_fail(_t: SystemParaToRelayTest) {
Westend::assert_ump_queue_processed(
false,
Some(PeopleWestend::para_id()),
Some(Weight::from_parts(157_718_000, 3_593)),
);
Westend::assert_ump_queue_processed(false, Some(PeopleWestend::para_id()), None);
}

fn para_origin_assertions(t: SystemParaToRelayTest) {
type RuntimeEvent = <PeopleWestend as Chain>::RuntimeEvent;

PeopleWestend::assert_xcm_pallet_attempted_complete(Some(Weight::from_parts(
351_425_000,
3_593,
)));
PeopleWestend::assert_xcm_pallet_attempted_complete(None);

PeopleWestend::assert_parachain_system_ump_sent();

Expand All @@ -94,7 +83,7 @@ fn para_origin_assertions(t: SystemParaToRelayTest) {
fn para_dest_assertions(t: RelayToSystemParaTest) {
type RuntimeEvent = <PeopleWestend as Chain>::RuntimeEvent;

PeopleWestend::assert_dmp_queue_complete(Some(Weight::from_parts(162_456_000, 0)));
PeopleWestend::assert_dmp_queue_complete(None);

assert_expected_events!(
PeopleWestend,
Expand Down
Loading

0 comments on commit ebcbca3

Please sign in to comment.