add integration tests to xcm-builder (#3537)

* add integration tests to xcm-builder

* add an integration test for reserve_transfer_assets

* add query holding and teleport tests

* formatting

* add to barrier doc comments and fix doc tests warnings

* use more realistic barrier for integration tests

* improve imports

* adjust base xcm weight and existential deposit to be in line with Kusama

* remove AnyNetwork

Co-authored-by: Amar Singh <asinghchrony@protonmail.com>

* add more comments and remove unnecessary code

* move mock into separate file

* reduce imports

* update cargo.lock

* remove reserve transfer test from xcm builder integration tests

* reword barrier doc comment

* elaborate on QueryHolding test scenario

* add an integration test for reserve based transfers from parachain to parachain

* add teleport tests

* fix failing teleport filter tests

* Update xcm/xcm-builder/src/integration_tests.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Update xcm/xcm-builder/src/integration_tests.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Update xcm/xcm-builder/src/integration_tests.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Move integration tests to tests/ directory

* Fix merge

* Replace All wildcard with a concrete seed amount

* Rename SEED_AMOUNT to REGISTER_AMOUNT

* Fix compilation error

* Check for teleport destination first before checking out assets

* Fix unit test

* Do not run tests in integration mock

* Add a permissive assets filter for teleportation

* Remove check for teleport location in InitiateTeleport XCM

* Remove defunct test

* Apply suggestions from code review

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Reword comment

Co-authored-by: Amar Singh <asinghchrony@protonmail.com>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
This commit is contained in:
Alexander Popiak
2021-08-17 23:39:47 +02:00
committed by GitHub
parent e014e53f4a
commit 7b054850fb
9 changed files with 551 additions and 9 deletions
+7
View File
@@ -23,6 +23,10 @@ use xcm::latest::{Junction, Junctions, MultiLocation, Order, Xcm};
use xcm_executor::traits::{OnResponse, ShouldExecute};
/// Execution barrier that just takes `shallow_weight` from `weight_credit`.
///
/// Useful to allow XCM execution by local chain users via extrinsics.
/// E.g. `pallet_xcm::reserve_asset_transfer` to transfer a reserve asset
/// out of the local chain to another one.
pub struct TakeWeightCredit;
impl ShouldExecute for TakeWeightCredit {
fn should_execute<Call>(
@@ -39,6 +43,9 @@ impl ShouldExecute for TakeWeightCredit {
/// Allows execution from `origin` if it is contained in `T` (i.e. `T::Contains(origin)`) taking payments into
/// account.
///
/// Only allows for `TeleportAsset`, `WithdrawAsset` and `ReserveAssetDeposit` XCMs because they are the only ones
/// that place assets in the Holding Register to pay for execution.
pub struct AllowTopLevelPaidExecutionFrom<T>(PhantomData<T>);
impl<T: Contains<MultiLocation>> ShouldExecute for AllowTopLevelPaidExecutionFrom<T> {
fn should_execute<Call>(
@@ -61,8 +61,8 @@ impl From<Error> for XcmError {
///
/// /// Our relay chain's location.
/// parameter_types! {
/// RelayChain: MultiLocation = Parent.into();
/// CheckingAccount: AccountId = Default::default();
/// pub RelayChain: MultiLocation = Parent.into();
/// pub CheckingAccount: AccountId = Default::default();
/// }
///
/// /// Some items that implement `Convert<MultiLocation, AccountId>`. Can be more, but for now we just assume we accept
+2 -2
View File
@@ -119,8 +119,8 @@ thread_local! {
pub fn assets(who: u64) -> Vec<MultiAsset> {
ASSETS.with(|a| a.borrow().get(&who).map_or(vec![], |a| a.clone().into()))
}
pub fn add_asset(who: u64, what: MultiAsset) {
ASSETS.with(|a| a.borrow_mut().entry(who).or_insert(Assets::new()).subsume(what));
pub fn add_asset<AssetArg: Into<MultiAsset>>(who: u64, what: AssetArg) {
ASSETS.with(|a| a.borrow_mut().entry(who).or_insert(Assets::new()).subsume(what.into()));
}
pub struct TestAssetTransactor;
+3 -3
View File
@@ -223,7 +223,7 @@ fn transfer_should_work() {
// we'll let them have message execution for free.
AllowUnpaidFrom::set(vec![X1(Parachain(1)).into()]);
// Child parachain #1 owns 1000 tokens held by us in reserve.
add_asset(1001, (Here, 1000).into());
add_asset(1001, (Here, 1000));
// They want to transfer 100 of them to their sibling parachain #2
let r = XcmExecutor::<TestConfig>::execute_xcm(
Parachain(1).into(),
@@ -243,7 +243,7 @@ fn transfer_should_work() {
fn reserve_transfer_should_work() {
AllowUnpaidFrom::set(vec![X1(Parachain(1)).into()]);
// Child parachain #1 owns 1000 tokens held by us in reserve.
add_asset(1001, (Here, 1000).into());
add_asset(1001, (Here, 1000));
// The remote account owned by gav.
let three: MultiLocation = X1(AccountIndex64 { index: 3, network: Any }).into();
@@ -330,7 +330,7 @@ fn transacting_should_refund_weight() {
fn paid_transacting_should_refund_payment_for_unused_weight() {
let one: MultiLocation = X1(AccountIndex64 { index: 1, network: Any }).into();
AllowPaidFrom::set(vec![one.clone()]);
add_asset(1, (Parent, 100).into());
add_asset(1, (Parent, 100));
WeightPrice::set((Parent.into(), 1_000_000_000_000));
let origin = one.clone();