Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
5018eb5
add integration tests to xcm-builder
apopiak Jul 31, 2021
29b7b04
add an integration test for reserve_transfer_assets
apopiak Jul 31, 2021
ee9b9c7
add query holding and teleport tests
apopiak Jul 31, 2021
7a09753
formatting
apopiak Jul 31, 2021
d1539f6
add to barrier doc comments and fix doc tests warnings
apopiak Jul 31, 2021
d9ebc77
use more realistic barrier for integration tests
apopiak Jul 31, 2021
ec426b9
improve imports
apopiak Jul 31, 2021
32b67ca
adjust base xcm weight and existential deposit to be in line with Kusama
apopiak Jul 31, 2021
7881628
remove AnyNetwork
apopiak Aug 1, 2021
5e8507f
add more comments and remove unnecessary code
apopiak Aug 1, 2021
cea48f9
Merge branch 'apopiak/xcm-integration-tests' of github.com:paritytech…
apopiak Aug 1, 2021
24b79ec
move mock into separate file
apopiak Aug 1, 2021
4aba2d6
reduce imports
apopiak Aug 1, 2021
114ef4e
update cargo.lock
apopiak Aug 1, 2021
97fb7a8
remove reserve transfer test from xcm builder integration tests
apopiak Aug 3, 2021
21a7e74
reword barrier doc comment
apopiak Aug 3, 2021
aababe1
elaborate on QueryHolding test scenario
apopiak Aug 3, 2021
2b63830
add an integration test for reserve based transfers from parachain to…
apopiak Aug 3, 2021
eed0fbc
add teleport tests
apopiak Aug 3, 2021
dc2a1bf
fix failing teleport filter tests
apopiak Aug 3, 2021
5dd3744
Update xcm/xcm-builder/src/integration_tests.rs
apopiak Aug 10, 2021
3b63468
Update xcm/xcm-builder/src/integration_tests.rs
apopiak Aug 10, 2021
26e7f53
Update xcm/xcm-builder/src/integration_tests.rs
apopiak Aug 10, 2021
4bd50a7
Move integration tests to tests/ directory
KiChjang Aug 14, 2021
75d0971
Merge remote-tracking branch 'origin/master' into apopiak/xcm-integra…
KiChjang Aug 14, 2021
f8a4847
Fix merge
KiChjang Aug 14, 2021
e3605c5
Replace All wildcard with a concrete seed amount
KiChjang Aug 14, 2021
4266a94
Rename SEED_AMOUNT to REGISTER_AMOUNT
KiChjang Aug 14, 2021
412ce69
Fix compilation error
KiChjang Aug 14, 2021
72975eb
Check for teleport destination first before checking out assets
KiChjang Aug 14, 2021
0d17e0a
Fix unit test
KiChjang Aug 14, 2021
304fd94
Do not run tests in integration mock
KiChjang Aug 14, 2021
ab81960
Add a permissive assets filter for teleportation
KiChjang Aug 14, 2021
2fba6af
Remove check for teleport location in InitiateTeleport XCM
KiChjang Aug 16, 2021
fd51b75
Remove defunct test
KiChjang Aug 17, 2021
1f15e4b
Apply suggestions from code review
apopiak Aug 17, 2021
dcd947b
Reword comment
apopiak Aug 17, 2021
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
Prev Previous commit
Next Next commit
adjust base xcm weight and existential deposit to be in line with Kusama
  • Loading branch information
apopiak committed Jul 31, 2021
commit 32b67ca4127c8800f722a972846b136c9d833e8b
79 changes: 48 additions & 31 deletions xcm/xcm-builder/src/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ use xcm_builder::{
ChildParachainConvertsVia, ChildSystemParachainAsSuperuser,
CurrencyAdapter as XcmCurrencyAdapter, FixedRateOfConcreteFungible, FixedWeightBounds,
IsConcrete, LocationInverter, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit
SovereignSignedViaLocation, TakeWeightCredit, IsChildSystemParachain, AllowUnpaidExecutionFrom
};
use crate::mock;

pub type AccountId = AccountId32;
pub type Balance = u128;

// copied from kusama constants
pub const UNITS: Balance = 1_000_000_000_000;
pub const CENTS: Balance = UNITS / 30_000;

parameter_types! {
pub const BlockHashCount: u64 = 250;
}
Expand Down Expand Up @@ -57,7 +61,7 @@ impl frame_system::Config for Runtime {
}

parameter_types! {
pub ExistentialDeposit: Balance = 1;
pub ExistentialDeposit: Balance = 1 * CENTS;
pub const MaxLocks: u32 = 50;
pub const MaxReserves: u32 = 50;
}
Expand All @@ -78,19 +82,20 @@ impl shared::Config for Runtime {}

impl configuration::Config for Runtime {}

// aims to closely emulate the Kusama XcmConfig
parameter_types! {
pub const KsmLocation: MultiLocation = MultiLocation::Null;
pub const KusamaNetwork: NetworkId = NetworkId::Kusama;
pub const AnyNetwork: NetworkId = NetworkId::Any;
pub Ancestry: MultiLocation = MultiLocation::Null;
pub UnitWeightCost: Weight = 1_000;
pub CheckAccount: AccountId = XcmPallet::check_account();
}

pub type SovereignAccountOf =
(ChildParachainConvertsVia<ParaId, AccountId>, AccountId32Aliases<KusamaNetwork, AccountId>);

pub type LocalAssetTransactor =
XcmCurrencyAdapter<Balances, IsConcrete<KsmLocation>, SovereignAccountOf, AccountId, ()>;
XcmCurrencyAdapter<Balances, IsConcrete<KsmLocation>, SovereignAccountOf, AccountId, CheckAccount>;

type LocalOriginConverter = (
SovereignSignedViaLocation<SovereignAccountOf, Origin>,
Expand All @@ -100,11 +105,16 @@ type LocalOriginConverter = (
);

parameter_types! {
pub const BaseXcmWeight: Weight = 1_000;
pub const BaseXcmWeight: Weight = 1_000_000_000;
pub KsmPerSecond: (MultiLocation, u128) = (KsmLocation::get(), 1);
}

pub type Barrier = (TakeWeightCredit, AllowTopLevelPaidExecutionFrom<All<MultiLocation>>);
pub type Barrier = (
TakeWeightCredit,
AllowTopLevelPaidExecutionFrom<All<MultiLocation>>,
// Unused/Untested
AllowUnpaidExecutionFrom<IsChildSystemParachain<ParaId>>,
);

pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
Expand Down Expand Up @@ -169,13 +179,11 @@ pub const ALICE: AccountId = AccountId::new([0u8; 32]);
pub const PARA_ID: u32 = 2000;
pub const INITIAL_BALANCE: u128 = 100_000_000_000;

pub fn kusama_like_ext() -> sp_io::TestExternalities {
pub fn kusama_like_with_balances(balances: Vec<(AccountId, Balance)>) -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default().build_storage::<Runtime>().unwrap();

let parachain_acc: AccountId = ParaId::from(PARA_ID).into_account();

pallet_balances::GenesisConfig::<Runtime> {
balances: vec![(ALICE, INITIAL_BALANCE), (parachain_acc, INITIAL_BALANCE)],
balances,
}
.assimilate_storage(&mut t)
.unwrap();
Expand Down Expand Up @@ -244,24 +252,27 @@ fn buy_execution<C>(debt: Weight) -> Order<C> {
#[test]
fn withdraw_and_deposit_works() {
use xcm::opaque::v0::prelude::*;
kusama_like_ext().execute_with(|| {
let para_acc: AccountId = ParaId::from(PARA_ID).into_account();
let balances = vec![(ALICE, INITIAL_BALANCE), (para_acc.clone(), INITIAL_BALANCE)];
kusama_like_with_balances(balances).execute_with(|| {
let other_para_id = 3000;
let amount = 5_000_000;
let amount = 10 * ExistentialDeposit::get();
let weight = 3 * BaseXcmWeight::get();
let r = XcmExecutor::<XcmConfig>::execute_xcm(
Parachain(PARA_ID).into(),
Xcm::WithdrawAsset {
assets: vec![ConcreteFungible { id: Null, amount }],
effects: vec![
buy_execution(3_000),
buy_execution(weight),
Order::DepositAsset {
assets: vec![All],
dest: Parachain(other_para_id).into(),
},
],
},
2_000_000,
weight,
);
assert_eq!(r, Outcome::Complete(3_000));
assert_eq!(r, Outcome::Complete(weight));
let other_para_acc: AccountId = ParaId::from(other_para_id).into_account();
assert_eq!(Balances::free_balance(other_para_acc), amount);
});
Expand All @@ -270,9 +281,12 @@ fn withdraw_and_deposit_works() {
#[test]
fn reserve_transfer_assets_works() {
use xcm::opaque::v0::prelude::*;
kusama_like_ext().execute_with(|| {
let amount = 5_000_000;
let dest_weight = 2_000_000;
let para_acc: AccountId = ParaId::from(PARA_ID).into_account();
let balances = vec![(ALICE, INITIAL_BALANCE), (para_acc.clone(), INITIAL_BALANCE)];
kusama_like_with_balances(balances).execute_with(|| {
let amount = 10 * ExistentialDeposit::get();
// We just assume that the destination uses the same base weight for XCM
let dest_weight = 2 * BaseXcmWeight::get();
assert_ok!(XcmPallet::reserve_transfer_assets(
Origin::signed(ALICE),
Parachain(PARA_ID).into(),
Expand All @@ -282,7 +296,6 @@ fn reserve_transfer_assets_works() {
));

assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE - amount);
let para_acc: AccountId = ParaId::from(PARA_ID).into_account();
assert_eq!(Balances::free_balance(para_acc), INITIAL_BALANCE + amount);
assert_eq!(
mock::sent_xcm(),
Expand Down Expand Up @@ -310,16 +323,19 @@ fn reserve_transfer_assets_works() {
#[test]
fn query_holding_works() {
use xcm::opaque::v0::prelude::*;
kusama_like_ext().execute_with(|| {
let para_acc: AccountId = ParaId::from(PARA_ID).into_account();
let balances = vec![(ALICE, INITIAL_BALANCE), (para_acc.clone(), INITIAL_BALANCE)];
kusama_like_with_balances(balances).execute_with(|| {
let other_para_id = 3000;
let amount = 5_000_000;
let amount = 10 * ExistentialDeposit::get();
let query_id = 1234;
let weight = 4 * BaseXcmWeight::get();
let r = XcmExecutor::<XcmConfig>::execute_xcm(
Parachain(PARA_ID).into(),
Xcm::WithdrawAsset {
assets: vec![ConcreteFungible { id: Null, amount }],
effects: vec![
buy_execution(4_000),
buy_execution(weight),
Order::QueryHolding {
query_id,
dest: Parachain(PARA_ID).into(),
Expand All @@ -331,12 +347,11 @@ fn query_holding_works() {
},
],
},
2_000_000,
weight,
);
assert_eq!(r, Outcome::Complete(4_000));
assert_eq!(r, Outcome::Complete(weight));
let other_para_acc: AccountId = ParaId::from(other_para_id).into_account();
assert_eq!(Balances::free_balance(other_para_acc), amount);
let para_acc: AccountId = ParaId::from(PARA_ID).into_account();
assert_eq!(Balances::free_balance(para_acc), INITIAL_BALANCE - amount);
assert_eq!(
mock::sent_xcm(),
Expand All @@ -357,30 +372,32 @@ fn query_holding_works() {
#[test]
fn teleport_to_statemine_works() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fn teleport_to_statemine_works() {
fn teleport_to_statemine_works_trusted() {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Teleport already implies trusting, so I think this naming change isn't necessary.

use xcm::opaque::v0::prelude::*;
kusama_like_ext().execute_with(|| {
let para_acc: AccountId = ParaId::from(PARA_ID).into_account();
let balances = vec![(ALICE, INITIAL_BALANCE), (para_acc.clone(), INITIAL_BALANCE)];
kusama_like_with_balances(balances).execute_with(|| {
let statemine_id = 1000;
let amount = 5_000_000;
let amount = 10 * ExistentialDeposit::get();
let teleport_effects = vec![
buy_execution(0),
Order::DepositAsset { assets: vec![All], dest: Parachain(PARA_ID).into() },
];
let weight = 3 * BaseXcmWeight::get();
let r = XcmExecutor::<XcmConfig>::execute_xcm(
Parachain(PARA_ID).into(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this not be called ORIGIN_PARA_ID?

Xcm::WithdrawAsset {
assets: vec![ConcreteFungible { id: Null, amount }],
effects: vec![
buy_execution(3_000),
buy_execution(weight),
Order::InitiateTeleport {
assets: vec![All],
dest: Parachain(statemine_id).into(),
effects: teleport_effects.clone(),
},
],
},
2_000_000,
weight,
);
assert_eq!(r, Outcome::Complete(3_000));
let para_acc: AccountId = ParaId::from(PARA_ID).into_account();
assert_eq!(r, Outcome::Complete(weight));
assert_eq!(Balances::free_balance(para_acc), INITIAL_BALANCE - amount);
assert_eq!(
mock::sent_xcm(),
Expand Down