Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport teleport tests from polkadot-fellows repo #5087

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
bc6dc7e
backport claim assets test in westend
Jul 2, 2024
7156e01
add this test for other runtime tests
Jul 3, 2024
bbd4d6b
refactory claim assets tests after merge master
Jul 3, 2024
67d9277
".git/.scripts/commands/fmt/fmt.sh"
Jul 4, 2024
2719bdf
backport other macro/tests
Jul 5, 2024
3a00332
add claim assets tests for people
Jul 10, 2024
da8df3f
import coretime rococo parachain and network in integration tests
Jul 11, 2024
ae44cd3
run claim assets test in coretime chain
Jul 11, 2024
9d5ff40
add claim test to coretime westend
Jul 15, 2024
cfd3605
rebase master to solve conflict
programskillforverification Jul 16, 2024
2d6ee95
Merge branch 'backport-tests-for-claim-assets' into backport-tests-fo…
programskillforverification Jul 16, 2024
3445be5
initially rewrite teleport tests in assethub
programskillforverification Jul 16, 2024
342f63f
Merge branch 'master' into backport-tests-for-teleport
programskillforverification Jul 16, 2024
3afa7de
Merge branch 'master' into backport-tests-for-claim-assets
programskillforverification Jul 16, 2024
2634c22
Merge branch 'master' into backport-tests-for-claim-assets
programskillforverification Jul 16, 2024
cd5867e
add prdoc
programskillforverification Jul 16, 2024
d735da0
Merge branch 'master' into backport-tests-for-claim-assets
acatangiu Jul 18, 2024
09291f7
Merge branch 'master' into backport-tests-for-teleport
programskillforverification Jul 18, 2024
375c91c
Merge branch 'master' into backport-tests-for-claim-assets
programskillforverification Jul 19, 2024
0937e1d
fix ci not pass tests
programskillforverification Jul 19, 2024
211c930
Merge branch 'master' into backport-tests-for-claim-assets
acatangiu Jul 19, 2024
c44a470
Update prdoc/pr_4930.prdoc
programskillforverification Jul 19, 2024
e73f5ed
Merge branch 'master' into backport-tests-for-claim-assets
acatangiu Jul 19, 2024
15c835c
Merge branch 'backport-tests-for-claim-assets' into backport-tests-fo…
programskillforverification Jul 19, 2024
e696b8a
add dry-run teleport macro
programskillforverification Jul 20, 2024
ae3f435
Merge branch 'master' into backport-tests-for-teleport
programskillforverification Jul 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

66 changes: 49 additions & 17 deletions cumulus/parachains/integration-tests/emulated/common/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ macro_rules! test_parachain_is_trusted_teleporter {
let sender = [<$sender_para Sender>]::get();
let mut para_sender_balance_before =
<$sender_para as $crate::macros::Chain>::account_data_of(sender.clone()).free;
let origin = <$sender_para as $crate::macros::Chain>::RuntimeOrigin::signed(sender.clone());
let fee_asset_item = 0;
let weight_limit = $crate::macros::WeightLimit::Unlimited;

Expand All @@ -61,18 +60,56 @@ macro_rules! test_parachain_is_trusted_teleporter {
let beneficiary: Location =
$crate::macros::AccountId32 { network: None, id: receiver.clone().into() }.into();

// Dry-run first.
let call = <$sender_para as Chain>::RuntimeCall::PolkadotXcm(pallet_xcm::Call::limited_teleport_assets {
dest: bx!(para_destination.clone().into()),
beneficiary: bx!(beneficiary.clone().into()),
assets: bx!($assets.clone().into()),
fee_asset_item: fee_asset_item,
weight_limit: weight_limit.clone(),
});
// These will be filled in the closure.
let mut delivery_fees_amount = 0;
let mut remote_message = VersionedXcm::V4(Xcm(Vec::new()));
<$sender_para>::execute_with(|| {
type Runtime = <$sender_para as Chain>::Runtime;
type OriginCaller = <$sender_para as Chain>::OriginCaller;

let origin = OriginCaller::system(RawOrigin::Signed(sender.clone()));
let result = Runtime::dry_run_call(origin, call.clone()).unwrap();
// We filter the result to get only the messages we are interested in.
let (destination_to_query, messages_to_query) = &result
.forwarded_xcms
.iter()
.find(|(destination, _)| {
*destination == VersionedLocation::V4(Location::new(1, [Parachain(<$receiver_para>::para_id().into())]))
})
.unwrap();
assert_eq!(messages_to_query.len(), 1);
remote_message = messages_to_query[0].clone();
let delivery_fees =
Runtime::query_delivery_fees(destination_to_query.clone(), remote_message.clone())
.unwrap();
let latest_delivery_fees: Assets = delivery_fees.clone().try_into().unwrap();
delivery_fees_amount = if let Some(first_asset) = latest_delivery_fees.inner().first() {
let Fungible(inner_delivery_fees_amount) = first_asset.fun else {
unreachable!("asset is fungible");
};
inner_delivery_fees_amount
} else {
0
}
});

// Reset to send actual message.
<$sender_para>::reset_ext();
<$receiver_para>::reset_ext();

// Send XCM message from Origin Parachain
// We are only testing the limited teleport version, which should be ok since success will
// depend only on a proper `XcmConfig` at destination.
<$sender_para>::execute_with(|| {
assert_ok!(<$sender_para as [<$sender_para Pallet>]>::PolkadotXcm::limited_teleport_assets(
origin.clone(),
bx!(para_destination.clone().into()),
bx!(beneficiary.clone().into()),
bx!($assets.clone().into()),
fee_asset_item,
weight_limit.clone(),
));

let origin = <$sender_para as Chain>::RuntimeOrigin::signed(sender.clone());
assert_ok!(call.dispatch(origin));

type RuntimeEvent = <$sender_para as $crate::macros::Chain>::RuntimeEvent;

Expand Down Expand Up @@ -114,13 +151,8 @@ macro_rules! test_parachain_is_trusted_teleporter {
<$sender_para as $crate::macros::Chain>::account_data_of(sender.clone()).free;
let para_receiver_balance_after =
<$receiver_para as $crate::macros::Chain>::account_data_of(receiver.clone()).free;
let delivery_fees = <$sender_para>::execute_with(|| {
$crate::macros::asset_test_utils::xcm_helpers::teleport_assets_delivery_fees::<
<$sender_xcm_config as xcm_executor::Config>::XcmSender,
>($assets.clone(), fee_asset_item, weight_limit.clone(), beneficiary, para_destination)
});

assert_eq!(para_sender_balance_before - $amount - delivery_fees, para_sender_balance_after);
assert_eq!(para_sender_balance_before - $amount - delivery_fees_amount, para_sender_balance_after);
assert!(para_receiver_balance_after > para_receiver_balance_before);

// Update sender balance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pallet-xcm = { workspace = true }
xcm-executor = { workspace = true }
polkadot-runtime-common = { workspace = true, default-features = true }
rococo-runtime-constants = { workspace = true, default-features = true }
xcm-runtime-apis = { workspace = true }

# Cumulus
asset-test-utils = { workspace = true, default-features = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ mod imports {
pub const ASSET_ID: u32 = 3;
pub const ASSET_MIN_BALANCE: u128 = 1000;

pub type RelayToSystemParaTest = Test<Rococo, AssetHubRococo>;
pub type RelayToParaTest = Test<Rococo, PenpalA>;
pub type ParaToRelayTest = Test<PenpalA, Rococo>;
pub type SystemParaToRelayTest = Test<AssetHubRococo, Rococo>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,53 +14,16 @@
// limitations under the License.

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(631_531_000, 7_186)));

assert_expected_events!(
Rococo,
vec![
// Amount to teleport is withdrawn from Sender
RuntimeEvent::Balances(pallet_balances::Event::Burned { who, amount }) => {
who: *who == t.sender.account_id,
amount: *amount == t.args.amount,
},
// Amount to teleport is deposited in Relay's `CheckAccount`
RuntimeEvent::Balances(pallet_balances::Event::Minted { who, amount }) => {
who: *who == <Rococo as RococoPallet>::XcmPallet::check_account(),
amount: *amount == t.args.amount,
},
]
);
}

fn relay_dest_assertions(t: SystemParaToRelayTest) {
type RuntimeEvent = <Rococo as Chain>::RuntimeEvent;

Rococo::assert_ump_queue_processed(
true,
Some(AssetHubRococo::para_id()),
Some(Weight::from_parts(307_225_000, 7_186)),
);

assert_expected_events!(
Rococo,
vec![
// Amount is withdrawn from Relay Chain's `CheckAccount`
RuntimeEvent::Balances(pallet_balances::Event::Burned { who, amount }) => {
who: *who == <Rococo as RococoPallet>::XcmPallet::check_account(),
amount: *amount == t.args.amount,
},
// Amount minus fees are deposited in Receiver's account
RuntimeEvent::Balances(pallet_balances::Event::Minted { who, .. }) => {
who: *who == t.receiver.account_id,
},
]
);
}
use emulated_integration_tests_common::{
test_parachain_is_trusted_teleporter_for_relay, test_relay_is_trusted_teleporter,
};
use frame_support::{
dispatch::RawOrigin, sp_runtime::traits::Dispatchable, traits::fungible::Mutate,
};
use xcm_runtime_apis::{
dry_run::runtime_decl_for_dry_run_api::DryRunApiV1,
fees::runtime_decl_for_xcm_payment_api::XcmPaymentApiV1,
};

fn relay_dest_assertions_fail(_t: SystemParaToRelayTest) {
Rococo::assert_ump_queue_processed(
Expand Down Expand Up @@ -92,22 +55,6 @@ fn para_origin_assertions(t: SystemParaToRelayTest) {
);
}

fn para_dest_assertions(t: RelayToSystemParaTest) {
type RuntimeEvent = <AssetHubRococo as Chain>::RuntimeEvent;

AssetHubRococo::assert_dmp_queue_complete(Some(Weight::from_parts(157_718_000, 3593)));

assert_expected_events!(
AssetHubRococo,
vec![
// Amount minus fees are deposited in Receiver's account
RuntimeEvent::Balances(pallet_balances::Event::Minted { who, .. }) => {
who: *who == t.receiver.account_id,
},
]
);
}

fn penpal_to_ah_foreign_assets_sender_assertions(t: ParaToSystemParaTest) {
type RuntimeEvent = <PenpalA as Chain>::RuntimeEvent;
let system_para_native_asset_location = RelayLocation::get();
Expand Down Expand Up @@ -232,17 +179,6 @@ fn ah_to_penpal_foreign_assets_receiver_assertions(t: SystemParaToParaTest) {
);
}

fn relay_limited_teleport_assets(t: RelayToSystemParaTest) -> DispatchResult {
<Rococo as RococoPallet>::XcmPallet::limited_teleport_assets(
t.signed_origin,
bx!(t.args.dest.into()),
bx!(t.args.beneficiary.into()),
bx!(t.args.assets.into()),
t.args.fee_asset_item,
t.args.weight_limit,
)
}

fn system_para_limited_teleport_assets(t: SystemParaToRelayTest) -> DispatchResult {
<AssetHubRococo as AssetHubRococoPallet>::PolkadotXcm::limited_teleport_assets(
t.signed_origin,
Expand Down Expand Up @@ -276,86 +212,26 @@ fn system_para_to_para_transfer_assets(t: SystemParaToParaTest) -> DispatchResul
)
}

/// Limited Teleport of native asset from Relay Chain to the System Parachain should work
#[test]
fn limited_teleport_native_assets_from_relay_to_system_para_works() {
// Init values for Relay Chain
let amount_to_send: Balance = ROCOCO_ED * 1000;
let dest = Rococo::child_location_of(AssetHubRococo::para_id());
let beneficiary_id = AssetHubRococoReceiver::get();
let test_args = TestContext {
sender: RococoSender::get(),
receiver: AssetHubRococoReceiver::get(),
args: TestArgs::new_relay(dest, beneficiary_id, amount_to_send),
};

let mut test = RelayToSystemParaTest::new(test_args);

let sender_balance_before = test.sender.balance;
let receiver_balance_before = test.receiver.balance;

test.set_assertion::<Rococo>(relay_origin_assertions);
test.set_assertion::<AssetHubRococo>(para_dest_assertions);
test.set_dispatchable::<Rococo>(relay_limited_teleport_assets);
test.assert();

let delivery_fees = Rococo::execute_with(|| {
xcm_helpers::teleport_assets_delivery_fees::<
<RococoXcmConfig as xcm_executor::Config>::XcmSender,
>(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest)
});

let sender_balance_after = test.sender.balance;
let receiver_balance_after = test.receiver.balance;

// Sender's balance is reduced
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);
}

/// Limited Teleport of native asset from System Parachain to Relay Chain
/// should work when there is enough balance in Relay Chain's `CheckAccount`
#[test]
fn limited_teleport_native_assets_back_from_system_para_to_relay_works() {
// Dependency - Relay Chain's `CheckAccount` should have enough balance
limited_teleport_native_assets_from_relay_to_system_para_works();

// Init values for Relay Chain
let amount_to_send: Balance = ASSET_HUB_ROCOCO_ED * 1000;
let destination = AssetHubRococo::parent_location();
let beneficiary_id = RococoReceiver::get();
let assets = (Parent, amount_to_send).into();

let test_args = TestContext {
sender: AssetHubRococoSender::get(),
receiver: RococoReceiver::get(),
args: TestArgs::new_para(destination, beneficiary_id, amount_to_send, assets, None, 0),
};

let mut test = SystemParaToRelayTest::new(test_args);

let sender_balance_before = test.sender.balance;
let receiver_balance_before = test.receiver.balance;

test.set_assertion::<AssetHubRococo>(para_origin_assertions);
test.set_assertion::<Rococo>(relay_dest_assertions);
test.set_dispatchable::<AssetHubRococo>(system_para_limited_teleport_assets);
test.assert();

let sender_balance_after = test.sender.balance;
let receiver_balance_after = test.receiver.balance;

let delivery_fees = AssetHubRococo::execute_with(|| {
xcm_helpers::teleport_assets_delivery_fees::<
<AssetHubRococoXcmConfig as xcm_executor::Config>::XcmSender,
>(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest)
});
fn teleport_from_and_to_relay() {
let amount = ROCOCO_ED * 1000;
let native_asset: Assets = (Here, amount).into();

test_relay_is_trusted_teleporter!(
Rococo, // Origin
RococoXcmConfig, // XCM Configuration
vec![AssetHubRococo], // Destinations
(native_asset, amount)
);

// Sender's balance is reduced
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);
test_parachain_is_trusted_teleporter_for_relay!(
AssetHubRococo, // Origin
AssetHubRococoXcmConfig, // XCM Configuration
Rococo, // Destination
amount
);
}

/// Limited Teleport of native asset from System Parachain to Relay Chain
Expand Down Expand Up @@ -390,7 +266,9 @@ fn limited_teleport_native_assets_from_system_para_to_relay_fails() {
let delivery_fees = AssetHubRococo::execute_with(|| {
xcm_helpers::teleport_assets_delivery_fees::<
<AssetHubRococoXcmConfig as xcm_executor::Config>::XcmSender,
>(test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest)
>(
test.args.assets.clone(), 0, test.args.weight_limit, test.args.beneficiary, test.args.dest
)
});

// Sender's balance is reduced
Expand Down
Loading