mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 22:11:02 +00:00
8428f678fe
# Note for reviewer
Most changes are just syntax changes necessary for the new version.
Most important files should be the ones under the `xcm` folder.
# Description
Added XCMv4.
## Removed `Multi` prefix
The following types have been renamed:
- MultiLocation -> Location
- MultiAsset -> Asset
- MultiAssets -> Assets
- InteriorMultiLocation -> InteriorLocation
- MultiAssetFilter -> AssetFilter
- VersionedMultiAsset -> VersionedAsset
- WildMultiAsset -> WildAsset
- VersionedMultiLocation -> VersionedLocation
In order to fix a name conflict, the `Assets` in `xcm-executor` were
renamed to `HoldingAssets`, as they represent assets in holding.
## Removed `Abstract` asset id
It was not being used anywhere and this simplifies the code.
Now assets are just constructed as follows:
```rust
let asset: Asset = (AssetId(Location::new(1, Here)), 100u128).into();
```
No need for specifying `Concrete` anymore.
## Outcome is now a named fields struct
Instead of
```rust
pub enum Outcome {
Complete(Weight),
Incomplete(Weight, Error),
Error(Error),
}
```
we now have
```rust
pub enum Outcome {
Complete { used: Weight },
Incomplete { used: Weight, error: Error },
Error { error: Error },
}
```
## Added Reanchorable trait
Now both locations and assets implement this trait, making it easier to
reanchor both.
## New syntax for building locations and junctions
Now junctions are built using the following methods:
```rust
let location = Location {
parents: 1,
interior: [Parachain(1000), PalletInstance(50), GeneralIndex(1984)].into()
};
```
or
```rust
let location = Location::new(1, [Parachain(1000), PalletInstance(50), GeneralIndex(1984)]);
```
And they are matched like so:
```rust
match location.unpack() {
(1, [Parachain(id)]) => ...
(0, Here) => ...,
(1, [_]) => ...,
}
```
This syntax is mandatory in v4, and has been also implemented for v2 and
v3 for easier migration.
This was needed to make all sizes smaller.
# TODO
- [x] Scaffold v4
- [x] Port github.com/paritytech/polkadot/pull/7236
- [x] Remove `Multi` prefix
- [x] Remove `Abstract` asset id
---------
Co-authored-by: command-bot <>
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
810 lines
25 KiB
Rust
810 lines
25 KiB
Rust
// This file is part of Cumulus.
|
|
|
|
// Copyright (C) Parity Technologies (UK) Ltd.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
//! Tests for the Westmint (Westend Assets Hub) chain.
|
|
|
|
use asset_hub_westend_runtime::{
|
|
xcm_config,
|
|
xcm_config::{
|
|
bridging, ForeignCreatorsSovereignAccountOf, LocationToAccountId, WestendLocation,
|
|
WestendLocationV3,
|
|
},
|
|
AllPalletsWithoutSystem, MetadataDepositBase, MetadataDepositPerByte, PolkadotXcm, RuntimeCall,
|
|
RuntimeEvent, RuntimeOrigin, ToRococoXcmRouterInstance, XcmpQueue,
|
|
};
|
|
pub use asset_hub_westend_runtime::{
|
|
xcm_config::{
|
|
CheckingAccount, TrustBackedAssetsPalletLocation, TrustBackedAssetsPalletLocationV3,
|
|
XcmConfig,
|
|
},
|
|
AssetConversion, AssetDeposit, Assets, Balances, CollatorSelection, ExistentialDeposit,
|
|
ForeignAssets, ForeignAssetsInstance, ParachainSystem, Runtime, SessionKeys, System,
|
|
TrustBackedAssetsInstance,
|
|
};
|
|
use asset_test_utils::{
|
|
test_cases_over_bridge::TestBridgingConfig, CollatorSessionKey, CollatorSessionKeys, ExtBuilder,
|
|
};
|
|
use codec::{Decode, Encode};
|
|
use frame_support::{
|
|
assert_ok,
|
|
traits::{
|
|
fungible::{Inspect, Mutate},
|
|
fungibles::{
|
|
Create, Inspect as FungiblesInspect, InspectEnumerable, Mutate as FungiblesMutate,
|
|
},
|
|
},
|
|
weights::{Weight, WeightToFee as WeightToFeeT},
|
|
};
|
|
use parachains_common::{
|
|
westend::{currency::UNITS, fee::WeightToFee},
|
|
AccountId, AssetIdForTrustBackedAssets, AuraId, Balance,
|
|
};
|
|
use sp_runtime::traits::MaybeEquivalence;
|
|
use std::convert::Into;
|
|
use xcm::latest::prelude::{Assets as XcmAssets, *};
|
|
use xcm_builder::V4V3LocationConverter;
|
|
use xcm_executor::traits::{JustTry, WeightTrader};
|
|
|
|
const ALICE: [u8; 32] = [1u8; 32];
|
|
const SOME_ASSET_ADMIN: [u8; 32] = [5u8; 32];
|
|
|
|
type AssetIdForTrustBackedAssetsConvert =
|
|
assets_common::AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocationV3>;
|
|
|
|
type AssetIdForTrustBackedAssetsConvertLatest =
|
|
assets_common::AssetIdForTrustBackedAssetsConvertLatest<TrustBackedAssetsPalletLocation>;
|
|
|
|
type RuntimeHelper = asset_test_utils::RuntimeHelper<Runtime, AllPalletsWithoutSystem>;
|
|
|
|
fn collator_session_key(account: [u8; 32]) -> CollatorSessionKey<Runtime> {
|
|
CollatorSessionKey::new(
|
|
AccountId::from(account),
|
|
AccountId::from(account),
|
|
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(account)) },
|
|
)
|
|
}
|
|
|
|
fn collator_session_keys() -> CollatorSessionKeys<Runtime> {
|
|
CollatorSessionKeys::default().add(collator_session_key(ALICE))
|
|
}
|
|
|
|
#[test]
|
|
fn test_buy_and_refund_weight_in_native() {
|
|
ExtBuilder::<Runtime>::default()
|
|
.with_collators(vec![AccountId::from(ALICE)])
|
|
.with_session_keys(vec![(
|
|
AccountId::from(ALICE),
|
|
AccountId::from(ALICE),
|
|
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) },
|
|
)])
|
|
.build()
|
|
.execute_with(|| {
|
|
let bob: AccountId = SOME_ASSET_ADMIN.into();
|
|
let staking_pot = CollatorSelection::account_id();
|
|
let native_location = WestendLocation::get();
|
|
let initial_balance = 200 * UNITS;
|
|
|
|
assert_ok!(Balances::mint_into(&bob, initial_balance));
|
|
assert_ok!(Balances::mint_into(&staking_pot, initial_balance));
|
|
|
|
// keep initial total issuance to assert later.
|
|
let total_issuance = Balances::total_issuance();
|
|
|
|
// prepare input to buy weight.
|
|
let weight = Weight::from_parts(4_000_000_000, 0);
|
|
let fee = WeightToFee::weight_to_fee(&weight);
|
|
let extra_amount = 100;
|
|
let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None };
|
|
let payment: Asset = (native_location.clone(), fee + extra_amount).into();
|
|
|
|
// init trader and buy weight.
|
|
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
|
let unused_asset =
|
|
trader.buy_weight(weight, payment.into(), &ctx).expect("Expected Ok");
|
|
|
|
// assert.
|
|
let unused_amount =
|
|
unused_asset.fungible.get(&native_location.clone().into()).map_or(0, |a| *a);
|
|
assert_eq!(unused_amount, extra_amount);
|
|
assert_eq!(Balances::total_issuance(), total_issuance);
|
|
|
|
// prepare input to refund weight.
|
|
let refund_weight = Weight::from_parts(1_000_000_000, 0);
|
|
let refund = WeightToFee::weight_to_fee(&refund_weight);
|
|
|
|
// refund.
|
|
let actual_refund = trader.refund_weight(refund_weight, &ctx).unwrap();
|
|
assert_eq!(actual_refund, (native_location, refund).into());
|
|
|
|
// assert.
|
|
assert_eq!(Balances::balance(&staking_pot), initial_balance);
|
|
// only after `trader` is dropped we expect the fee to be resolved into the treasury
|
|
// account.
|
|
drop(trader);
|
|
assert_eq!(Balances::balance(&staking_pot), initial_balance + fee - refund);
|
|
assert_eq!(Balances::total_issuance(), total_issuance + fee - refund);
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() {
|
|
ExtBuilder::<Runtime>::default()
|
|
.with_collators(vec![AccountId::from(ALICE)])
|
|
.with_session_keys(vec![(
|
|
AccountId::from(ALICE),
|
|
AccountId::from(ALICE),
|
|
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) },
|
|
)])
|
|
.build()
|
|
.execute_with(|| {
|
|
let bob: AccountId = SOME_ASSET_ADMIN.into();
|
|
let staking_pot = CollatorSelection::account_id();
|
|
let asset_1: u32 = 1;
|
|
let native_location = WestendLocationV3::get();
|
|
let asset_1_location =
|
|
AssetIdForTrustBackedAssetsConvert::convert_back(&asset_1).unwrap();
|
|
// bob's initial balance for native and `asset1` assets.
|
|
let initial_balance = 200 * UNITS;
|
|
// liquidity for both arms of (native, asset1) pool.
|
|
let pool_liquidity = 100 * UNITS;
|
|
|
|
// init asset, balances and pool.
|
|
assert_ok!(<Assets as Create<_>>::create(asset_1, bob.clone(), true, 10));
|
|
|
|
assert_ok!(Assets::mint_into(asset_1, &bob, initial_balance));
|
|
assert_ok!(Balances::mint_into(&bob, initial_balance));
|
|
assert_ok!(Balances::mint_into(&staking_pot, initial_balance));
|
|
|
|
assert_ok!(AssetConversion::create_pool(
|
|
RuntimeHelper::origin_of(bob.clone()),
|
|
Box::new(native_location),
|
|
Box::new(asset_1_location)
|
|
));
|
|
|
|
assert_ok!(AssetConversion::add_liquidity(
|
|
RuntimeHelper::origin_of(bob.clone()),
|
|
Box::new(native_location),
|
|
Box::new(asset_1_location),
|
|
pool_liquidity,
|
|
pool_liquidity,
|
|
1,
|
|
1,
|
|
bob,
|
|
));
|
|
|
|
// keep initial total issuance to assert later.
|
|
let asset_total_issuance = Assets::total_issuance(asset_1);
|
|
let native_total_issuance = Balances::total_issuance();
|
|
|
|
let asset_1_location_latest: Location = asset_1_location.try_into().unwrap();
|
|
|
|
// prepare input to buy weight.
|
|
let weight = Weight::from_parts(4_000_000_000, 0);
|
|
let fee = WeightToFee::weight_to_fee(&weight);
|
|
let asset_fee =
|
|
AssetConversion::get_amount_in(&fee, &pool_liquidity, &pool_liquidity).unwrap();
|
|
let extra_amount = 100;
|
|
let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None };
|
|
let payment: Asset = (asset_1_location_latest.clone(), asset_fee + extra_amount).into();
|
|
|
|
// init trader and buy weight.
|
|
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
|
let unused_asset =
|
|
trader.buy_weight(weight, payment.into(), &ctx).expect("Expected Ok");
|
|
|
|
// assert.
|
|
let unused_amount = unused_asset
|
|
.fungible
|
|
.get(&asset_1_location_latest.clone().into())
|
|
.map_or(0, |a| *a);
|
|
assert_eq!(unused_amount, extra_amount);
|
|
assert_eq!(Assets::total_issuance(asset_1), asset_total_issuance + asset_fee);
|
|
|
|
// prepare input to refund weight.
|
|
let refund_weight = Weight::from_parts(1_000_000_000, 0);
|
|
let refund = WeightToFee::weight_to_fee(&refund_weight);
|
|
let (reserve1, reserve2) =
|
|
AssetConversion::get_reserves(native_location, asset_1_location).unwrap();
|
|
let asset_refund =
|
|
AssetConversion::get_amount_out(&refund, &reserve1, &reserve2).unwrap();
|
|
|
|
// refund.
|
|
let actual_refund = trader.refund_weight(refund_weight, &ctx).unwrap();
|
|
assert_eq!(actual_refund, (asset_1_location_latest, asset_refund).into());
|
|
|
|
// assert.
|
|
assert_eq!(Balances::balance(&staking_pot), initial_balance);
|
|
// only after `trader` is dropped we expect the fee to be resolved into the treasury
|
|
// account.
|
|
drop(trader);
|
|
assert_eq!(Balances::balance(&staking_pot), initial_balance + fee - refund);
|
|
assert_eq!(
|
|
Assets::total_issuance(asset_1),
|
|
asset_total_issuance + asset_fee - asset_refund
|
|
);
|
|
assert_eq!(Balances::total_issuance(), native_total_issuance);
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() {
|
|
ExtBuilder::<Runtime>::default()
|
|
.with_collators(vec![AccountId::from(ALICE)])
|
|
.with_session_keys(vec![(
|
|
AccountId::from(ALICE),
|
|
AccountId::from(ALICE),
|
|
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) },
|
|
)])
|
|
.build()
|
|
.execute_with(|| {
|
|
let bob: AccountId = SOME_ASSET_ADMIN.into();
|
|
let staking_pot = CollatorSelection::account_id();
|
|
let native_location = WestendLocationV3::get();
|
|
let foreign_location = xcm::v3::Location {
|
|
parents: 1,
|
|
interior: (
|
|
xcm::v3::Junction::Parachain(1234),
|
|
xcm::v3::Junction::GeneralIndex(12345),
|
|
)
|
|
.into(),
|
|
};
|
|
// bob's initial balance for native and `asset1` assets.
|
|
let initial_balance = 200 * UNITS;
|
|
// liquidity for both arms of (native, asset1) pool.
|
|
let pool_liquidity = 100 * UNITS;
|
|
|
|
// init asset, balances and pool.
|
|
assert_ok!(<ForeignAssets as Create<_>>::create(
|
|
foreign_location,
|
|
bob.clone(),
|
|
true,
|
|
10
|
|
));
|
|
|
|
assert_ok!(ForeignAssets::mint_into(foreign_location, &bob, initial_balance));
|
|
assert_ok!(Balances::mint_into(&bob, initial_balance));
|
|
assert_ok!(Balances::mint_into(&staking_pot, initial_balance));
|
|
|
|
assert_ok!(AssetConversion::create_pool(
|
|
RuntimeHelper::origin_of(bob.clone()),
|
|
Box::new(native_location),
|
|
Box::new(foreign_location)
|
|
));
|
|
|
|
assert_ok!(AssetConversion::add_liquidity(
|
|
RuntimeHelper::origin_of(bob.clone()),
|
|
Box::new(native_location),
|
|
Box::new(foreign_location),
|
|
pool_liquidity,
|
|
pool_liquidity,
|
|
1,
|
|
1,
|
|
bob,
|
|
));
|
|
|
|
// keep initial total issuance to assert later.
|
|
let asset_total_issuance = ForeignAssets::total_issuance(foreign_location);
|
|
let native_total_issuance = Balances::total_issuance();
|
|
|
|
let foreign_location_latest: Location = foreign_location.try_into().unwrap();
|
|
|
|
// prepare input to buy weight.
|
|
let weight = Weight::from_parts(4_000_000_000, 0);
|
|
let fee = WeightToFee::weight_to_fee(&weight);
|
|
let asset_fee =
|
|
AssetConversion::get_amount_in(&fee, &pool_liquidity, &pool_liquidity).unwrap();
|
|
let extra_amount = 100;
|
|
let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None };
|
|
let payment: Asset = (foreign_location_latest.clone(), asset_fee + extra_amount).into();
|
|
|
|
// init trader and buy weight.
|
|
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
|
let unused_asset =
|
|
trader.buy_weight(weight, payment.into(), &ctx).expect("Expected Ok");
|
|
|
|
// assert.
|
|
let unused_amount = unused_asset
|
|
.fungible
|
|
.get(&foreign_location_latest.clone().into())
|
|
.map_or(0, |a| *a);
|
|
assert_eq!(unused_amount, extra_amount);
|
|
assert_eq!(
|
|
ForeignAssets::total_issuance(foreign_location),
|
|
asset_total_issuance + asset_fee
|
|
);
|
|
|
|
// prepare input to refund weight.
|
|
let refund_weight = Weight::from_parts(1_000_000_000, 0);
|
|
let refund = WeightToFee::weight_to_fee(&refund_weight);
|
|
let (reserve1, reserve2) =
|
|
AssetConversion::get_reserves(native_location, foreign_location).unwrap();
|
|
let asset_refund =
|
|
AssetConversion::get_amount_out(&refund, &reserve1, &reserve2).unwrap();
|
|
|
|
// refund.
|
|
let actual_refund = trader.refund_weight(refund_weight, &ctx).unwrap();
|
|
assert_eq!(actual_refund, (foreign_location_latest, asset_refund).into());
|
|
|
|
// assert.
|
|
assert_eq!(Balances::balance(&staking_pot), initial_balance);
|
|
// only after `trader` is dropped we expect the fee to be resolved into the treasury
|
|
// account.
|
|
drop(trader);
|
|
assert_eq!(Balances::balance(&staking_pot), initial_balance + fee - refund);
|
|
assert_eq!(
|
|
ForeignAssets::total_issuance(foreign_location),
|
|
asset_total_issuance + asset_fee - asset_refund
|
|
);
|
|
assert_eq!(Balances::total_issuance(), native_total_issuance);
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn test_assets_balances_api_works() {
|
|
use assets_common::runtime_api::runtime_decl_for_fungibles_api::FungiblesApi;
|
|
|
|
ExtBuilder::<Runtime>::default()
|
|
.with_collators(vec![AccountId::from(ALICE)])
|
|
.with_session_keys(vec![(
|
|
AccountId::from(ALICE),
|
|
AccountId::from(ALICE),
|
|
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) },
|
|
)])
|
|
.build()
|
|
.execute_with(|| {
|
|
let local_asset_id = 1;
|
|
let foreign_asset_id_location = xcm::v3::Location {
|
|
parents: 1,
|
|
interior: [
|
|
xcm::v3::Junction::Parachain(1234),
|
|
xcm::v3::Junction::GeneralIndex(12345),
|
|
]
|
|
.into(),
|
|
};
|
|
|
|
// check before
|
|
assert_eq!(Assets::balance(local_asset_id, AccountId::from(ALICE)), 0);
|
|
assert_eq!(
|
|
ForeignAssets::balance(foreign_asset_id_location, AccountId::from(ALICE)),
|
|
0
|
|
);
|
|
assert_eq!(Balances::free_balance(AccountId::from(ALICE)), 0);
|
|
assert!(Runtime::query_account_balances(AccountId::from(ALICE))
|
|
.unwrap()
|
|
.try_as::<XcmAssets>()
|
|
.unwrap()
|
|
.is_none());
|
|
|
|
// Drip some balance
|
|
use frame_support::traits::fungible::Mutate;
|
|
let some_currency = ExistentialDeposit::get();
|
|
Balances::mint_into(&AccountId::from(ALICE), some_currency).unwrap();
|
|
|
|
// We need root origin to create a sufficient asset
|
|
let minimum_asset_balance = 3333333_u128;
|
|
assert_ok!(Assets::force_create(
|
|
RuntimeHelper::root_origin(),
|
|
local_asset_id.into(),
|
|
AccountId::from(ALICE).into(),
|
|
true,
|
|
minimum_asset_balance
|
|
));
|
|
|
|
// We first mint enough asset for the account to exist for assets
|
|
assert_ok!(Assets::mint(
|
|
RuntimeHelper::origin_of(AccountId::from(ALICE)),
|
|
local_asset_id.into(),
|
|
AccountId::from(ALICE).into(),
|
|
minimum_asset_balance
|
|
));
|
|
|
|
// create foreign asset
|
|
let foreign_asset_minimum_asset_balance = 3333333_u128;
|
|
assert_ok!(ForeignAssets::force_create(
|
|
RuntimeHelper::root_origin(),
|
|
foreign_asset_id_location,
|
|
AccountId::from(SOME_ASSET_ADMIN).into(),
|
|
false,
|
|
foreign_asset_minimum_asset_balance
|
|
));
|
|
|
|
// We first mint enough asset for the account to exist for assets
|
|
assert_ok!(ForeignAssets::mint(
|
|
RuntimeHelper::origin_of(AccountId::from(SOME_ASSET_ADMIN)),
|
|
foreign_asset_id_location,
|
|
AccountId::from(ALICE).into(),
|
|
6 * foreign_asset_minimum_asset_balance
|
|
));
|
|
|
|
// check after
|
|
assert_eq!(
|
|
Assets::balance(local_asset_id, AccountId::from(ALICE)),
|
|
minimum_asset_balance
|
|
);
|
|
assert_eq!(
|
|
ForeignAssets::balance(foreign_asset_id_location, AccountId::from(ALICE)),
|
|
6 * minimum_asset_balance
|
|
);
|
|
assert_eq!(Balances::free_balance(AccountId::from(ALICE)), some_currency);
|
|
|
|
let result: XcmAssets = Runtime::query_account_balances(AccountId::from(ALICE))
|
|
.unwrap()
|
|
.try_into()
|
|
.unwrap();
|
|
assert_eq!(result.len(), 3);
|
|
|
|
// check currency
|
|
assert!(result.inner().iter().any(|asset| asset.eq(
|
|
&assets_common::fungible_conversion::convert_balance::<WestendLocation, Balance>(
|
|
some_currency
|
|
)
|
|
.unwrap()
|
|
)));
|
|
// check trusted asset
|
|
assert!(result.inner().iter().any(|asset| asset.eq(&(
|
|
AssetIdForTrustBackedAssetsConvertLatest::convert_back(&local_asset_id).unwrap(),
|
|
minimum_asset_balance
|
|
)
|
|
.into())));
|
|
// check foreign asset
|
|
assert!(result.inner().iter().any(|asset| asset.eq(&(
|
|
V4V3LocationConverter::convert_back(&foreign_asset_id_location).unwrap(),
|
|
6 * foreign_asset_minimum_asset_balance
|
|
)
|
|
.into())));
|
|
});
|
|
}
|
|
|
|
asset_test_utils::include_teleports_for_native_asset_works!(
|
|
Runtime,
|
|
AllPalletsWithoutSystem,
|
|
XcmConfig,
|
|
CheckingAccount,
|
|
WeightToFee,
|
|
ParachainSystem,
|
|
collator_session_keys(),
|
|
ExistentialDeposit::get(),
|
|
Box::new(|runtime_event_encoded: Vec<u8>| {
|
|
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
|
|
Ok(RuntimeEvent::PolkadotXcm(event)) => Some(event),
|
|
_ => None,
|
|
}
|
|
}),
|
|
1000
|
|
);
|
|
|
|
asset_test_utils::include_teleports_for_foreign_assets_works!(
|
|
Runtime,
|
|
AllPalletsWithoutSystem,
|
|
XcmConfig,
|
|
CheckingAccount,
|
|
WeightToFee,
|
|
ParachainSystem,
|
|
ForeignCreatorsSovereignAccountOf,
|
|
ForeignAssetsInstance,
|
|
collator_session_keys(),
|
|
ExistentialDeposit::get(),
|
|
Box::new(|runtime_event_encoded: Vec<u8>| {
|
|
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
|
|
Ok(RuntimeEvent::PolkadotXcm(event)) => Some(event),
|
|
_ => None,
|
|
}
|
|
}),
|
|
Box::new(|runtime_event_encoded: Vec<u8>| {
|
|
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
|
|
Ok(RuntimeEvent::XcmpQueue(event)) => Some(event),
|
|
_ => None,
|
|
}
|
|
})
|
|
);
|
|
|
|
asset_test_utils::include_asset_transactor_transfer_with_local_consensus_currency_works!(
|
|
Runtime,
|
|
XcmConfig,
|
|
collator_session_keys(),
|
|
ExistentialDeposit::get(),
|
|
Box::new(|| {
|
|
assert!(Assets::asset_ids().collect::<Vec<_>>().is_empty());
|
|
assert!(ForeignAssets::asset_ids().collect::<Vec<_>>().is_empty());
|
|
}),
|
|
Box::new(|| {
|
|
assert!(Assets::asset_ids().collect::<Vec<_>>().is_empty());
|
|
assert!(ForeignAssets::asset_ids().collect::<Vec<_>>().is_empty());
|
|
})
|
|
);
|
|
|
|
asset_test_utils::include_asset_transactor_transfer_with_pallet_assets_instance_works!(
|
|
asset_transactor_transfer_with_trust_backed_assets_works,
|
|
Runtime,
|
|
XcmConfig,
|
|
TrustBackedAssetsInstance,
|
|
AssetIdForTrustBackedAssets,
|
|
AssetIdForTrustBackedAssetsConvertLatest,
|
|
collator_session_keys(),
|
|
ExistentialDeposit::get(),
|
|
12345,
|
|
Box::new(|| {
|
|
assert!(ForeignAssets::asset_ids().collect::<Vec<_>>().is_empty());
|
|
}),
|
|
Box::new(|| {
|
|
assert!(ForeignAssets::asset_ids().collect::<Vec<_>>().is_empty());
|
|
})
|
|
);
|
|
|
|
asset_test_utils::include_asset_transactor_transfer_with_pallet_assets_instance_works!(
|
|
asset_transactor_transfer_with_foreign_assets_works,
|
|
Runtime,
|
|
XcmConfig,
|
|
ForeignAssetsInstance,
|
|
xcm::v3::Location,
|
|
JustTry,
|
|
collator_session_keys(),
|
|
ExistentialDeposit::get(),
|
|
xcm::v3::Location {
|
|
parents: 1,
|
|
interior: [xcm::v3::Junction::Parachain(1313), xcm::v3::Junction::GeneralIndex(12345)]
|
|
.into()
|
|
},
|
|
Box::new(|| {
|
|
assert!(Assets::asset_ids().collect::<Vec<_>>().is_empty());
|
|
}),
|
|
Box::new(|| {
|
|
assert!(Assets::asset_ids().collect::<Vec<_>>().is_empty());
|
|
})
|
|
);
|
|
|
|
asset_test_utils::include_create_and_manage_foreign_assets_for_local_consensus_parachain_assets_works!(
|
|
Runtime,
|
|
XcmConfig,
|
|
WeightToFee,
|
|
ForeignCreatorsSovereignAccountOf,
|
|
ForeignAssetsInstance,
|
|
xcm::v3::Location,
|
|
V4V3LocationConverter,
|
|
collator_session_keys(),
|
|
ExistentialDeposit::get(),
|
|
AssetDeposit::get(),
|
|
MetadataDepositBase::get(),
|
|
MetadataDepositPerByte::get(),
|
|
Box::new(|pallet_asset_call| RuntimeCall::ForeignAssets(pallet_asset_call).encode()),
|
|
Box::new(|runtime_event_encoded: Vec<u8>| {
|
|
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
|
|
Ok(RuntimeEvent::ForeignAssets(pallet_asset_event)) => Some(pallet_asset_event),
|
|
_ => None,
|
|
}
|
|
}),
|
|
Box::new(|| {
|
|
assert!(Assets::asset_ids().collect::<Vec<_>>().is_empty());
|
|
assert!(ForeignAssets::asset_ids().collect::<Vec<_>>().is_empty());
|
|
}),
|
|
Box::new(|| {
|
|
assert!(Assets::asset_ids().collect::<Vec<_>>().is_empty());
|
|
assert_eq!(ForeignAssets::asset_ids().collect::<Vec<_>>().len(), 1);
|
|
})
|
|
);
|
|
|
|
fn bridging_to_asset_hub_rococo() -> TestBridgingConfig {
|
|
let _ = PolkadotXcm::force_xcm_version(
|
|
RuntimeOrigin::root(),
|
|
Box::new(bridging::to_rococo::AssetHubRococo::get()),
|
|
XCM_VERSION,
|
|
)
|
|
.expect("version saved!");
|
|
TestBridgingConfig {
|
|
bridged_network: bridging::to_rococo::RococoNetwork::get(),
|
|
local_bridge_hub_para_id: bridging::SiblingBridgeHubParaId::get(),
|
|
local_bridge_hub_location: bridging::SiblingBridgeHub::get(),
|
|
bridged_target_location: bridging::to_rococo::AssetHubRococo::get(),
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn limited_reserve_transfer_assets_for_native_asset_to_asset_hub_rococo_works() {
|
|
asset_test_utils::test_cases_over_bridge::limited_reserve_transfer_assets_for_native_asset_works::<
|
|
Runtime,
|
|
AllPalletsWithoutSystem,
|
|
XcmConfig,
|
|
ParachainSystem,
|
|
XcmpQueue,
|
|
LocationToAccountId,
|
|
>(
|
|
collator_session_keys(),
|
|
ExistentialDeposit::get(),
|
|
AccountId::from(ALICE),
|
|
Box::new(|runtime_event_encoded: Vec<u8>| {
|
|
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
|
|
Ok(RuntimeEvent::PolkadotXcm(event)) => Some(event),
|
|
_ => None,
|
|
}
|
|
}),
|
|
Box::new(|runtime_event_encoded: Vec<u8>| {
|
|
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
|
|
Ok(RuntimeEvent::XcmpQueue(event)) => Some(event),
|
|
_ => None,
|
|
}
|
|
}),
|
|
bridging_to_asset_hub_rococo,
|
|
WeightLimit::Unlimited,
|
|
Some(xcm_config::bridging::XcmBridgeHubRouterFeeAssetId::get()),
|
|
Some(xcm_config::TreasuryAccount::get()),
|
|
)
|
|
}
|
|
#[test]
|
|
fn receive_reserve_asset_deposited_roc_from_asset_hub_rococo_works() {
|
|
const BLOCK_AUTHOR_ACCOUNT: [u8; 32] = [13; 32];
|
|
asset_test_utils::test_cases_over_bridge::receive_reserve_asset_deposited_from_different_consensus_works::<
|
|
Runtime,
|
|
AllPalletsWithoutSystem,
|
|
XcmConfig,
|
|
LocationToAccountId,
|
|
ForeignAssetsInstance,
|
|
>(
|
|
collator_session_keys().add(collator_session_key(BLOCK_AUTHOR_ACCOUNT)),
|
|
ExistentialDeposit::get(),
|
|
AccountId::from([73; 32]),
|
|
AccountId::from(BLOCK_AUTHOR_ACCOUNT),
|
|
// receiving ROCs
|
|
(xcm::v3::Location::new(2, [xcm::v3::Junction::GlobalConsensus(xcm::v3::NetworkId::Rococo)]), 1000000000000, 1_000_000_000),
|
|
bridging_to_asset_hub_rococo,
|
|
(
|
|
[PalletInstance(bp_bridge_hub_westend::WITH_BRIDGE_WESTEND_TO_ROCOCO_MESSAGES_PALLET_INDEX)].into(),
|
|
GlobalConsensus(Rococo),
|
|
[Parachain(1000)].into()
|
|
)
|
|
)
|
|
}
|
|
#[test]
|
|
fn report_bridge_status_from_xcm_bridge_router_for_rococo_works() {
|
|
asset_test_utils::test_cases_over_bridge::report_bridge_status_from_xcm_bridge_router_works::<
|
|
Runtime,
|
|
AllPalletsWithoutSystem,
|
|
XcmConfig,
|
|
LocationToAccountId,
|
|
ToRococoXcmRouterInstance,
|
|
>(
|
|
collator_session_keys(),
|
|
bridging_to_asset_hub_rococo,
|
|
|| {
|
|
sp_std::vec![
|
|
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
|
|
Transact {
|
|
origin_kind: OriginKind::Xcm,
|
|
require_weight_at_most:
|
|
bp_asset_hub_westend::XcmBridgeHubRouterTransactCallMaxWeight::get(),
|
|
call: bp_asset_hub_westend::Call::ToRococoXcmRouter(
|
|
bp_asset_hub_westend::XcmBridgeHubRouterCall::report_bridge_status {
|
|
bridge_id: Default::default(),
|
|
is_congested: true,
|
|
}
|
|
)
|
|
.encode()
|
|
.into(),
|
|
}
|
|
]
|
|
.into()
|
|
},
|
|
|| {
|
|
sp_std::vec![
|
|
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
|
|
Transact {
|
|
origin_kind: OriginKind::Xcm,
|
|
require_weight_at_most:
|
|
bp_asset_hub_westend::XcmBridgeHubRouterTransactCallMaxWeight::get(),
|
|
call: bp_asset_hub_westend::Call::ToRococoXcmRouter(
|
|
bp_asset_hub_westend::XcmBridgeHubRouterCall::report_bridge_status {
|
|
bridge_id: Default::default(),
|
|
is_congested: false,
|
|
}
|
|
)
|
|
.encode()
|
|
.into(),
|
|
}
|
|
]
|
|
.into()
|
|
},
|
|
)
|
|
}
|
|
|
|
#[test]
|
|
fn test_report_bridge_status_call_compatibility() {
|
|
// if this test fails, make sure `bp_asset_hub_rococo` has valid encoding
|
|
assert_eq!(
|
|
RuntimeCall::ToRococoXcmRouter(pallet_xcm_bridge_hub_router::Call::report_bridge_status {
|
|
bridge_id: Default::default(),
|
|
is_congested: true,
|
|
})
|
|
.encode(),
|
|
bp_asset_hub_westend::Call::ToRococoXcmRouter(
|
|
bp_asset_hub_westend::XcmBridgeHubRouterCall::report_bridge_status {
|
|
bridge_id: Default::default(),
|
|
is_congested: true,
|
|
}
|
|
)
|
|
.encode()
|
|
)
|
|
}
|
|
|
|
#[test]
|
|
fn check_sane_weight_report_bridge_status() {
|
|
use pallet_xcm_bridge_hub_router::WeightInfo;
|
|
let actual = <Runtime as pallet_xcm_bridge_hub_router::Config<
|
|
ToRococoXcmRouterInstance,
|
|
>>::WeightInfo::report_bridge_status();
|
|
let max_weight = bp_asset_hub_westend::XcmBridgeHubRouterTransactCallMaxWeight::get();
|
|
assert!(
|
|
actual.all_lte(max_weight),
|
|
"max_weight: {:?} should be adjusted to actual {:?}",
|
|
max_weight,
|
|
actual
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn change_xcm_bridge_hub_router_byte_fee_by_governance_works() {
|
|
asset_test_utils::test_cases::change_storage_constant_by_governance_works::<
|
|
Runtime,
|
|
bridging::XcmBridgeHubRouterByteFee,
|
|
Balance,
|
|
>(
|
|
collator_session_keys(),
|
|
1000,
|
|
Box::new(|call| RuntimeCall::System(call).encode()),
|
|
|| {
|
|
(
|
|
bridging::XcmBridgeHubRouterByteFee::key().to_vec(),
|
|
bridging::XcmBridgeHubRouterByteFee::get(),
|
|
)
|
|
},
|
|
|old_value| {
|
|
if let Some(new_value) = old_value.checked_add(1) {
|
|
new_value
|
|
} else {
|
|
old_value.checked_sub(1).unwrap()
|
|
}
|
|
},
|
|
)
|
|
}
|
|
|
|
#[test]
|
|
fn reserve_transfer_native_asset_to_non_teleport_para_works() {
|
|
asset_test_utils::test_cases::reserve_transfer_native_asset_to_non_teleport_para_works::<
|
|
Runtime,
|
|
AllPalletsWithoutSystem,
|
|
XcmConfig,
|
|
ParachainSystem,
|
|
XcmpQueue,
|
|
LocationToAccountId,
|
|
>(
|
|
collator_session_keys(),
|
|
ExistentialDeposit::get(),
|
|
AccountId::from(ALICE),
|
|
Box::new(|runtime_event_encoded: Vec<u8>| {
|
|
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
|
|
Ok(RuntimeEvent::PolkadotXcm(event)) => Some(event),
|
|
_ => None,
|
|
}
|
|
}),
|
|
Box::new(|runtime_event_encoded: Vec<u8>| {
|
|
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
|
|
Ok(RuntimeEvent::XcmpQueue(event)) => Some(event),
|
|
_ => None,
|
|
}
|
|
}),
|
|
WeightLimit::Unlimited,
|
|
);
|
|
}
|