mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 09:51:02 +00:00
XCMv4 (#1230)
# 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>
This commit is contained in:
committed by
GitHub
parent
ec7bfae00a
commit
8428f678fe
@@ -32,36 +32,36 @@ pub struct Pallet<T: Config>(crate::Pallet<T>);
|
||||
|
||||
/// Trait that must be implemented by runtime to be able to benchmark pallet properly.
|
||||
pub trait Config: crate::Config {
|
||||
/// A `MultiLocation` that can be reached via `XcmRouter`. Used only in benchmarks.
|
||||
/// A `Location` that can be reached via `XcmRouter`. Used only in benchmarks.
|
||||
///
|
||||
/// If `None`, the benchmarks that depend on a reachable destination will be skipped.
|
||||
fn reachable_dest() -> Option<MultiLocation> {
|
||||
fn reachable_dest() -> Option<Location> {
|
||||
None
|
||||
}
|
||||
|
||||
/// A `(MultiAsset, MultiLocation)` pair representing asset and the destination it can be
|
||||
/// A `(Asset, Location)` pair representing asset and the destination it can be
|
||||
/// teleported to. Used only in benchmarks.
|
||||
///
|
||||
/// Implementation should also make sure `dest` is reachable/connected.
|
||||
///
|
||||
/// If `None`, the benchmarks that depend on this will default to `Weight::MAX`.
|
||||
fn teleportable_asset_and_dest() -> Option<(MultiAsset, MultiLocation)> {
|
||||
fn teleportable_asset_and_dest() -> Option<(Asset, Location)> {
|
||||
None
|
||||
}
|
||||
|
||||
/// A `(MultiAsset, MultiLocation)` pair representing asset and the destination it can be
|
||||
/// A `(Asset, Location)` pair representing asset and the destination it can be
|
||||
/// reserve-transferred to. Used only in benchmarks.
|
||||
///
|
||||
/// Implementation should also make sure `dest` is reachable/connected.
|
||||
///
|
||||
/// If `None`, the benchmarks that depend on this will default to `Weight::MAX`.
|
||||
fn reserve_transferable_asset_and_dest() -> Option<(MultiAsset, MultiLocation)> {
|
||||
fn reserve_transferable_asset_and_dest() -> Option<(Asset, Location)> {
|
||||
None
|
||||
}
|
||||
|
||||
/// Sets up a complex transfer (usually consisting of a teleport and reserve-based transfer), so
|
||||
/// that runtime can properly benchmark `transfer_assets()` extrinsic. Should return a tuple
|
||||
/// `(MultiAsset, u32, MultiLocation, dyn FnOnce())` representing the assets to transfer, the
|
||||
/// `(Asset, u32, Location, dyn FnOnce())` representing the assets to transfer, the
|
||||
/// `u32` index of the asset to be used for fees, the destination chain for the transfer, and a
|
||||
/// `verify()` closure to verify the intended transfer side-effects.
|
||||
///
|
||||
@@ -71,8 +71,7 @@ pub trait Config: crate::Config {
|
||||
/// Used only in benchmarks.
|
||||
///
|
||||
/// If `None`, the benchmarks that depend on this will default to `Weight::MAX`.
|
||||
fn set_up_complex_asset_transfer(
|
||||
) -> Option<(MultiAssets, u32, MultiLocation, Box<dyn FnOnce()>)> {
|
||||
fn set_up_complex_asset_transfer() -> Option<(Assets, u32, Location, Box<dyn FnOnce()>)> {
|
||||
None
|
||||
}
|
||||
}
|
||||
@@ -90,7 +89,7 @@ benchmarks! {
|
||||
return Err(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))
|
||||
}
|
||||
let msg = Xcm(vec![ClearOrigin]);
|
||||
let versioned_dest: VersionedMultiLocation = T::reachable_dest().ok_or(
|
||||
let versioned_dest: VersionedLocation = T::reachable_dest().ok_or(
|
||||
BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)),
|
||||
)?
|
||||
.into();
|
||||
@@ -106,7 +105,7 @@ benchmarks! {
|
||||
Fungible(amount) => *amount,
|
||||
_ => return Err(BenchmarkError::Stop("Benchmark asset not fungible")),
|
||||
}.into();
|
||||
let assets: MultiAssets = asset.into();
|
||||
let assets: Assets = asset.into();
|
||||
|
||||
let existential_deposit = T::ExistentialDeposit::get();
|
||||
let caller = whitelisted_caller();
|
||||
@@ -126,10 +125,10 @@ benchmarks! {
|
||||
}
|
||||
|
||||
let recipient = [0u8; 32];
|
||||
let versioned_dest: VersionedMultiLocation = destination.into();
|
||||
let versioned_beneficiary: VersionedMultiLocation =
|
||||
let versioned_dest: VersionedLocation = destination.into();
|
||||
let versioned_beneficiary: VersionedLocation =
|
||||
AccountId32 { network: None, id: recipient.into() }.into();
|
||||
let versioned_assets: VersionedMultiAssets = assets.into();
|
||||
let versioned_assets: VersionedAssets = assets.into();
|
||||
}: _<RuntimeOrigin<T>>(send_origin.into(), Box::new(versioned_dest), Box::new(versioned_beneficiary), Box::new(versioned_assets), 0)
|
||||
verify {
|
||||
// verify balance after transfer, decreased by transferred amount (+ maybe XCM delivery fees)
|
||||
@@ -145,7 +144,7 @@ benchmarks! {
|
||||
Fungible(amount) => *amount,
|
||||
_ => return Err(BenchmarkError::Stop("Benchmark asset not fungible")),
|
||||
}.into();
|
||||
let assets: MultiAssets = asset.into();
|
||||
let assets: Assets = asset.into();
|
||||
|
||||
let existential_deposit = T::ExistentialDeposit::get();
|
||||
let caller = whitelisted_caller();
|
||||
@@ -165,10 +164,10 @@ benchmarks! {
|
||||
}
|
||||
|
||||
let recipient = [0u8; 32];
|
||||
let versioned_dest: VersionedMultiLocation = destination.into();
|
||||
let versioned_beneficiary: VersionedMultiLocation =
|
||||
let versioned_dest: VersionedLocation = destination.into();
|
||||
let versioned_beneficiary: VersionedLocation =
|
||||
AccountId32 { network: None, id: recipient.into() }.into();
|
||||
let versioned_assets: VersionedMultiAssets = assets.into();
|
||||
let versioned_assets: VersionedAssets = assets.into();
|
||||
}: _<RuntimeOrigin<T>>(send_origin.into(), Box::new(versioned_dest), Box::new(versioned_beneficiary), Box::new(versioned_assets), 0)
|
||||
verify {
|
||||
// verify balance after transfer, decreased by transferred amount (+ maybe XCM delivery fees)
|
||||
@@ -182,10 +181,10 @@ benchmarks! {
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let send_origin = RawOrigin::Signed(caller.clone());
|
||||
let recipient = [0u8; 32];
|
||||
let versioned_dest: VersionedMultiLocation = destination.into();
|
||||
let versioned_beneficiary: VersionedMultiLocation =
|
||||
let versioned_dest: VersionedLocation = destination.into();
|
||||
let versioned_beneficiary: VersionedLocation =
|
||||
AccountId32 { network: None, id: recipient.into() }.into();
|
||||
let versioned_assets: VersionedMultiAssets = assets.into();
|
||||
let versioned_assets: VersionedAssets = assets.into();
|
||||
}: _<RuntimeOrigin<T>>(send_origin.into(), Box::new(versioned_dest), Box::new(versioned_beneficiary), Box::new(versioned_assets), 0, WeightLimit::Unlimited)
|
||||
verify {
|
||||
// run provided verification function
|
||||
@@ -214,7 +213,7 @@ benchmarks! {
|
||||
force_default_xcm_version {}: _(RawOrigin::Root, Some(2))
|
||||
|
||||
force_subscribe_version_notify {
|
||||
let versioned_loc: VersionedMultiLocation = T::reachable_dest().ok_or(
|
||||
let versioned_loc: VersionedLocation = T::reachable_dest().ok_or(
|
||||
BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)),
|
||||
)?
|
||||
.into();
|
||||
@@ -224,7 +223,7 @@ benchmarks! {
|
||||
let loc = T::reachable_dest().ok_or(
|
||||
BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)),
|
||||
)?;
|
||||
let versioned_loc: VersionedMultiLocation = loc.into();
|
||||
let versioned_loc: VersionedLocation = loc.clone().into();
|
||||
let _ = crate::Pallet::<T>::request_version_notify(loc);
|
||||
}: _(RawOrigin::Root, Box::new(versioned_loc))
|
||||
|
||||
@@ -232,7 +231,7 @@ benchmarks! {
|
||||
|
||||
migrate_supported_version {
|
||||
let old_version = XCM_VERSION - 1;
|
||||
let loc = VersionedMultiLocation::from(MultiLocation::from(Parent));
|
||||
let loc = VersionedLocation::from(Location::from(Parent));
|
||||
SupportedVersion::<T>::insert(old_version, loc, old_version);
|
||||
}: {
|
||||
crate::Pallet::<T>::check_xcm_version_change(VersionMigrationStage::MigrateSupportedVersion, Weight::zero());
|
||||
@@ -240,7 +239,7 @@ benchmarks! {
|
||||
|
||||
migrate_version_notifiers {
|
||||
let old_version = XCM_VERSION - 1;
|
||||
let loc = VersionedMultiLocation::from(MultiLocation::from(Parent));
|
||||
let loc = VersionedLocation::from(Location::from(Parent));
|
||||
VersionNotifiers::<T>::insert(old_version, loc, 0);
|
||||
}: {
|
||||
crate::Pallet::<T>::check_xcm_version_change(VersionMigrationStage::MigrateVersionNotifiers, Weight::zero());
|
||||
@@ -250,7 +249,7 @@ benchmarks! {
|
||||
let loc = T::reachable_dest().ok_or(
|
||||
BenchmarkError::Override(BenchmarkResult::from_weight(T::DbWeight::get().reads(1))),
|
||||
)?;
|
||||
let loc = VersionedMultiLocation::from(loc);
|
||||
let loc = VersionedLocation::from(loc);
|
||||
let current_version = T::AdvertisedXcmVersion::get();
|
||||
VersionNotifyTargets::<T>::insert(current_version, loc, (0, Weight::zero(), current_version));
|
||||
}: {
|
||||
@@ -261,7 +260,7 @@ benchmarks! {
|
||||
let loc = T::reachable_dest().ok_or(
|
||||
BenchmarkError::Override(BenchmarkResult::from_weight(T::DbWeight::get().reads_writes(1, 3))),
|
||||
)?;
|
||||
let loc = VersionedMultiLocation::from(loc);
|
||||
let loc = VersionedLocation::from(loc);
|
||||
let current_version = T::AdvertisedXcmVersion::get();
|
||||
let old_version = current_version - 1;
|
||||
VersionNotifyTargets::<T>::insert(current_version, loc, (0, Weight::zero(), old_version));
|
||||
@@ -276,7 +275,7 @@ benchmarks! {
|
||||
part: v2::BodyPart::Voice,
|
||||
}
|
||||
.into();
|
||||
let bad_loc = VersionedMultiLocation::from(bad_loc);
|
||||
let bad_loc = VersionedLocation::from(bad_loc);
|
||||
let current_version = T::AdvertisedXcmVersion::get();
|
||||
VersionNotifyTargets::<T>::insert(current_version, bad_loc, (0, Weight::zero(), current_version));
|
||||
}: {
|
||||
@@ -286,7 +285,7 @@ benchmarks! {
|
||||
migrate_version_notify_targets {
|
||||
let current_version = T::AdvertisedXcmVersion::get();
|
||||
let old_version = current_version - 1;
|
||||
let loc = VersionedMultiLocation::from(MultiLocation::from(Parent));
|
||||
let loc = VersionedLocation::from(Location::from(Parent));
|
||||
VersionNotifyTargets::<T>::insert(old_version, loc, (0, Weight::zero(), current_version));
|
||||
}: {
|
||||
crate::Pallet::<T>::check_xcm_version_change(VersionMigrationStage::MigrateAndNotifyOldTargets, Weight::zero());
|
||||
@@ -296,7 +295,7 @@ benchmarks! {
|
||||
let loc = T::reachable_dest().ok_or(
|
||||
BenchmarkError::Override(BenchmarkResult::from_weight(T::DbWeight::get().reads_writes(1, 3))),
|
||||
)?;
|
||||
let loc = VersionedMultiLocation::from(loc);
|
||||
let loc = VersionedLocation::from(loc);
|
||||
let old_version = T::AdvertisedXcmVersion::get() - 1;
|
||||
VersionNotifyTargets::<T>::insert(old_version, loc, (0, Weight::zero(), old_version));
|
||||
}: {
|
||||
@@ -304,17 +303,17 @@ benchmarks! {
|
||||
}
|
||||
|
||||
new_query {
|
||||
let responder = MultiLocation::from(Parent);
|
||||
let responder = Location::from(Parent);
|
||||
let timeout = 1u32.into();
|
||||
let match_querier = MultiLocation::from(Here);
|
||||
let match_querier = Location::from(Here);
|
||||
}: {
|
||||
crate::Pallet::<T>::new_query(responder, timeout, match_querier);
|
||||
}
|
||||
|
||||
take_response {
|
||||
let responder = MultiLocation::from(Parent);
|
||||
let responder = Location::from(Parent);
|
||||
let timeout = 1u32.into();
|
||||
let match_querier = MultiLocation::from(Here);
|
||||
let match_querier = Location::from(Here);
|
||||
let query_id = crate::Pallet::<T>::new_query(responder, timeout, match_querier);
|
||||
let infos = (0 .. xcm::v3::MaxPalletsInfo::get()).map(|_| PalletInfo::new(
|
||||
u32::MAX,
|
||||
@@ -340,17 +339,17 @@ benchmarks! {
|
||||
pub mod helpers {
|
||||
use super::*;
|
||||
pub fn native_teleport_as_asset_transfer<T>(
|
||||
native_asset_location: MultiLocation,
|
||||
destination: MultiLocation,
|
||||
) -> Option<(MultiAssets, u32, MultiLocation, Box<dyn FnOnce()>)>
|
||||
native_asset_location: Location,
|
||||
destination: Location,
|
||||
) -> Option<(Assets, u32, Location, Box<dyn FnOnce()>)>
|
||||
where
|
||||
T: Config + pallet_balances::Config,
|
||||
u128: From<<T as pallet_balances::Config>::Balance>,
|
||||
{
|
||||
// Relay/native token can be teleported to/from AH.
|
||||
let amount = T::ExistentialDeposit::get() * 100u32.into();
|
||||
let assets: MultiAssets =
|
||||
MultiAsset { fun: Fungible(amount.into()), id: Concrete(native_asset_location) }.into();
|
||||
let assets: Assets =
|
||||
Asset { fun: Fungible(amount.into()), id: AssetId(native_asset_location) }.into();
|
||||
let fee_index = 0u32;
|
||||
|
||||
// Give some multiple of transferred amount
|
||||
|
||||
+339
-331
File diff suppressed because it is too large
Load Diff
+112
-108
@@ -16,7 +16,7 @@
|
||||
|
||||
use codec::Encode;
|
||||
use frame_support::{
|
||||
construct_runtime, derive_impl, match_types, parameter_types,
|
||||
construct_runtime, derive_impl, parameter_types,
|
||||
traits::{
|
||||
AsEnsureOriginWithArg, ConstU128, ConstU32, Contains, Equals, Everything, EverythingBut,
|
||||
Nothing,
|
||||
@@ -76,7 +76,7 @@ pub mod pallet_test_notifier {
|
||||
pub enum Event<T: Config> {
|
||||
QueryPrepared(QueryId),
|
||||
NotifyQueryPrepared(QueryId),
|
||||
ResponseReceived(MultiLocation, QueryId, Response),
|
||||
ResponseReceived(Location, QueryId, Response),
|
||||
}
|
||||
|
||||
#[pallet::error]
|
||||
@@ -89,7 +89,7 @@ pub mod pallet_test_notifier {
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pallet::call_index(0)]
|
||||
#[pallet::weight(Weight::from_parts(1_000_000, 1_000_000))]
|
||||
pub fn prepare_new_query(origin: OriginFor<T>, querier: MultiLocation) -> DispatchResult {
|
||||
pub fn prepare_new_query(origin: OriginFor<T>, querier: Location) -> DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
let id = who
|
||||
.using_encoded(|mut d| <[u8; 32]>::decode(&mut d))
|
||||
@@ -105,10 +105,7 @@ pub mod pallet_test_notifier {
|
||||
|
||||
#[pallet::call_index(1)]
|
||||
#[pallet::weight(Weight::from_parts(1_000_000, 1_000_000))]
|
||||
pub fn prepare_new_notify_query(
|
||||
origin: OriginFor<T>,
|
||||
querier: MultiLocation,
|
||||
) -> DispatchResult {
|
||||
pub fn prepare_new_notify_query(origin: OriginFor<T>, querier: Location) -> DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
let id = who
|
||||
.using_encoded(|mut d| <[u8; 32]>::decode(&mut d))
|
||||
@@ -144,7 +141,7 @@ construct_runtime!(
|
||||
{
|
||||
System: frame_system::{Pallet, Call, Storage, Config<T>, Event<T>},
|
||||
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
|
||||
Assets: pallet_assets::{Pallet, Call, Storage, Config<T>, Event<T>},
|
||||
AssetsPallet: pallet_assets::{Pallet, Call, Storage, Config<T>, Event<T>},
|
||||
ParasOrigin: origin::{Pallet, Origin},
|
||||
XcmPallet: pallet_xcm::{Pallet, Call, Storage, Event<T>, Origin, Config<T>},
|
||||
TestNotifier: pallet_test_notifier::{Pallet, Call, Event<T>},
|
||||
@@ -152,13 +149,13 @@ construct_runtime!(
|
||||
);
|
||||
|
||||
thread_local! {
|
||||
pub static SENT_XCM: RefCell<Vec<(MultiLocation, Xcm<()>)>> = RefCell::new(Vec::new());
|
||||
pub static SENT_XCM: RefCell<Vec<(Location, Xcm<()>)>> = RefCell::new(Vec::new());
|
||||
pub static FAIL_SEND_XCM: RefCell<bool> = RefCell::new(false);
|
||||
}
|
||||
pub(crate) fn sent_xcm() -> Vec<(MultiLocation, Xcm<()>)> {
|
||||
pub(crate) fn sent_xcm() -> Vec<(Location, Xcm<()>)> {
|
||||
SENT_XCM.with(|q| (*q.borrow()).clone())
|
||||
}
|
||||
pub(crate) fn take_sent_xcm() -> Vec<(MultiLocation, Xcm<()>)> {
|
||||
pub(crate) fn take_sent_xcm() -> Vec<(Location, Xcm<()>)> {
|
||||
SENT_XCM.with(|q| {
|
||||
let mut r = Vec::new();
|
||||
std::mem::swap(&mut r, &mut *q.borrow_mut());
|
||||
@@ -171,18 +168,18 @@ pub(crate) fn set_send_xcm_artificial_failure(should_fail: bool) {
|
||||
/// Sender that never returns error.
|
||||
pub struct TestSendXcm;
|
||||
impl SendXcm for TestSendXcm {
|
||||
type Ticket = (MultiLocation, Xcm<()>);
|
||||
type Ticket = (Location, Xcm<()>);
|
||||
fn validate(
|
||||
dest: &mut Option<MultiLocation>,
|
||||
dest: &mut Option<Location>,
|
||||
msg: &mut Option<Xcm<()>>,
|
||||
) -> SendResult<(MultiLocation, Xcm<()>)> {
|
||||
) -> SendResult<(Location, Xcm<()>)> {
|
||||
if FAIL_SEND_XCM.with(|q| *q.borrow()) {
|
||||
return Err(SendError::Transport("Intentional send failure used in tests"))
|
||||
}
|
||||
let pair = (dest.take().unwrap(), msg.take().unwrap());
|
||||
Ok((pair, MultiAssets::new()))
|
||||
Ok((pair, Assets::new()))
|
||||
}
|
||||
fn deliver(pair: (MultiLocation, Xcm<()>)) -> Result<XcmHash, SendError> {
|
||||
fn deliver(pair: (Location, Xcm<()>)) -> Result<XcmHash, SendError> {
|
||||
let hash = fake_message_hash(&pair.1);
|
||||
SENT_XCM.with(|q| q.borrow_mut().push(pair));
|
||||
Ok(hash)
|
||||
@@ -191,11 +188,11 @@ impl SendXcm for TestSendXcm {
|
||||
/// Sender that returns error if `X8` junction and stops routing
|
||||
pub struct TestSendXcmErrX8;
|
||||
impl SendXcm for TestSendXcmErrX8 {
|
||||
type Ticket = (MultiLocation, Xcm<()>);
|
||||
type Ticket = (Location, Xcm<()>);
|
||||
fn validate(
|
||||
dest: &mut Option<MultiLocation>,
|
||||
dest: &mut Option<Location>,
|
||||
_: &mut Option<Xcm<()>>,
|
||||
) -> SendResult<(MultiLocation, Xcm<()>)> {
|
||||
) -> SendResult<(Location, Xcm<()>)> {
|
||||
if dest.as_ref().unwrap().len() == 8 {
|
||||
dest.take();
|
||||
Err(SendError::Transport("Destination location full"))
|
||||
@@ -203,7 +200,7 @@ impl SendXcm for TestSendXcmErrX8 {
|
||||
Err(SendError::NotApplicable)
|
||||
}
|
||||
}
|
||||
fn deliver(pair: (MultiLocation, Xcm<()>)) -> Result<XcmHash, SendError> {
|
||||
fn deliver(pair: (Location, Xcm<()>)) -> Result<XcmHash, SendError> {
|
||||
let hash = fake_message_hash(&pair.1);
|
||||
SENT_XCM.with(|q| q.borrow_mut().push(pair));
|
||||
Ok(hash)
|
||||
@@ -212,18 +209,18 @@ impl SendXcm for TestSendXcmErrX8 {
|
||||
|
||||
parameter_types! {
|
||||
pub Para3000: u32 = 3000;
|
||||
pub Para3000Location: MultiLocation = Parachain(Para3000::get()).into();
|
||||
pub Para3000Location: Location = Parachain(Para3000::get()).into();
|
||||
pub Para3000PaymentAmount: u128 = 1;
|
||||
pub Para3000PaymentMultiAssets: MultiAssets = MultiAssets::from(MultiAsset::from((Here, Para3000PaymentAmount::get())));
|
||||
pub Para3000PaymentAssets: Assets = Assets::from(Asset::from((Here, Para3000PaymentAmount::get())));
|
||||
}
|
||||
/// Sender only sends to `Parachain(3000)` destination requiring payment.
|
||||
pub struct TestPaidForPara3000SendXcm;
|
||||
impl SendXcm for TestPaidForPara3000SendXcm {
|
||||
type Ticket = (MultiLocation, Xcm<()>);
|
||||
type Ticket = (Location, Xcm<()>);
|
||||
fn validate(
|
||||
dest: &mut Option<MultiLocation>,
|
||||
dest: &mut Option<Location>,
|
||||
msg: &mut Option<Xcm<()>>,
|
||||
) -> SendResult<(MultiLocation, Xcm<()>)> {
|
||||
) -> SendResult<(Location, Xcm<()>)> {
|
||||
if let Some(dest) = dest.as_ref() {
|
||||
if !dest.eq(&Para3000Location::get()) {
|
||||
return Err(SendError::NotApplicable)
|
||||
@@ -233,9 +230,9 @@ impl SendXcm for TestPaidForPara3000SendXcm {
|
||||
}
|
||||
|
||||
let pair = (dest.take().unwrap(), msg.take().unwrap());
|
||||
Ok((pair, Para3000PaymentMultiAssets::get()))
|
||||
Ok((pair, Para3000PaymentAssets::get()))
|
||||
}
|
||||
fn deliver(pair: (MultiLocation, Xcm<()>)) -> Result<XcmHash, SendError> {
|
||||
fn deliver(pair: (Location, Xcm<()>)) -> Result<XcmHash, SendError> {
|
||||
let hash = fake_message_hash(&pair.1);
|
||||
SENT_XCM.with(|q| q.borrow_mut().push(pair));
|
||||
Ok(hash)
|
||||
@@ -300,17 +297,17 @@ impl pallet_balances::Config for Test {
|
||||
/// Simple conversion of `u32` into an `AssetId` for use in benchmarking.
|
||||
pub struct XcmBenchmarkHelper;
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
impl pallet_assets::BenchmarkHelper<MultiLocation> for XcmBenchmarkHelper {
|
||||
fn create_asset_id_parameter(id: u32) -> MultiLocation {
|
||||
MultiLocation { parents: 1, interior: X1(Parachain(id)) }
|
||||
impl pallet_assets::BenchmarkHelper<Location> for XcmBenchmarkHelper {
|
||||
fn create_asset_id_parameter(id: u32) -> Location {
|
||||
Location::new(1, [Parachain(id)])
|
||||
}
|
||||
}
|
||||
|
||||
impl pallet_assets::Config for Test {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type Balance = Balance;
|
||||
type AssetId = MultiLocation;
|
||||
type AssetIdParameter = MultiLocation;
|
||||
type AssetId = Location;
|
||||
type AssetIdParameter = Location;
|
||||
type Currency = Balances;
|
||||
type CreateOrigin = AsEnsureOriginWithArg<frame_system::EnsureSigned<AccountId>>;
|
||||
type ForceOrigin = EnsureRoot<AccountId>;
|
||||
@@ -354,61 +351,61 @@ pub const OTHER_PARA_ID: u32 = 2009;
|
||||
pub const FILTERED_PARA_ID: u32 = 2010;
|
||||
|
||||
parameter_types! {
|
||||
pub const RelayLocation: MultiLocation = Here.into_location();
|
||||
pub const NativeAsset: MultiAsset = MultiAsset {
|
||||
pub const RelayLocation: Location = Here.into_location();
|
||||
pub const NativeAsset: Asset = Asset {
|
||||
fun: Fungible(10),
|
||||
id: Concrete(Here.into_location()),
|
||||
id: AssetId(Here.into_location()),
|
||||
};
|
||||
pub const SystemParachainLocation: MultiLocation = MultiLocation {
|
||||
parents: 0,
|
||||
interior: X1(Parachain(SOME_SYSTEM_PARA))
|
||||
};
|
||||
pub const ForeignReserveLocation: MultiLocation = MultiLocation {
|
||||
parents: 0,
|
||||
interior: X1(Parachain(FOREIGN_ASSET_RESERVE_PARA_ID))
|
||||
};
|
||||
pub const ForeignAsset: MultiAsset = MultiAsset {
|
||||
pub SystemParachainLocation: Location = Location::new(
|
||||
0,
|
||||
[Parachain(SOME_SYSTEM_PARA)]
|
||||
);
|
||||
pub ForeignReserveLocation: Location = Location::new(
|
||||
0,
|
||||
[Parachain(FOREIGN_ASSET_RESERVE_PARA_ID)]
|
||||
);
|
||||
pub ForeignAsset: Asset = Asset {
|
||||
fun: Fungible(10),
|
||||
id: Concrete(MultiLocation {
|
||||
parents: 0,
|
||||
interior: X2(Parachain(FOREIGN_ASSET_RESERVE_PARA_ID), FOREIGN_ASSET_INNER_JUNCTION),
|
||||
}),
|
||||
id: AssetId(Location::new(
|
||||
0,
|
||||
[Parachain(FOREIGN_ASSET_RESERVE_PARA_ID), FOREIGN_ASSET_INNER_JUNCTION],
|
||||
)),
|
||||
};
|
||||
pub const UsdcReserveLocation: MultiLocation = MultiLocation {
|
||||
parents: 0,
|
||||
interior: X1(Parachain(USDC_RESERVE_PARA_ID))
|
||||
};
|
||||
pub const Usdc: MultiAsset = MultiAsset {
|
||||
pub UsdcReserveLocation: Location = Location::new(
|
||||
0,
|
||||
[Parachain(USDC_RESERVE_PARA_ID)]
|
||||
);
|
||||
pub Usdc: Asset = Asset {
|
||||
fun: Fungible(10),
|
||||
id: Concrete(MultiLocation {
|
||||
parents: 0,
|
||||
interior: X2(Parachain(USDC_RESERVE_PARA_ID), USDC_INNER_JUNCTION),
|
||||
}),
|
||||
id: AssetId(Location::new(
|
||||
0,
|
||||
[Parachain(USDC_RESERVE_PARA_ID), USDC_INNER_JUNCTION],
|
||||
)),
|
||||
};
|
||||
pub const UsdtTeleportLocation: MultiLocation = MultiLocation {
|
||||
parents: 0,
|
||||
interior: X1(Parachain(USDT_PARA_ID))
|
||||
};
|
||||
pub const Usdt: MultiAsset = MultiAsset {
|
||||
pub UsdtTeleportLocation: Location = Location::new(
|
||||
0,
|
||||
[Parachain(USDT_PARA_ID)]
|
||||
);
|
||||
pub Usdt: Asset = Asset {
|
||||
fun: Fungible(10),
|
||||
id: Concrete(MultiLocation {
|
||||
parents: 0,
|
||||
interior: X1(Parachain(USDT_PARA_ID)),
|
||||
}),
|
||||
id: AssetId(Location::new(
|
||||
0,
|
||||
[Parachain(USDT_PARA_ID)],
|
||||
)),
|
||||
};
|
||||
pub const FilteredTeleportLocation: MultiLocation = MultiLocation {
|
||||
parents: 0,
|
||||
interior: X1(Parachain(FILTERED_PARA_ID))
|
||||
};
|
||||
pub const FilteredTeleportAsset: MultiAsset = MultiAsset {
|
||||
pub FilteredTeleportLocation: Location = Location::new(
|
||||
0,
|
||||
[Parachain(FILTERED_PARA_ID)]
|
||||
);
|
||||
pub FilteredTeleportAsset: Asset = Asset {
|
||||
fun: Fungible(10),
|
||||
id: Concrete(MultiLocation {
|
||||
parents: 0,
|
||||
interior: X1(Parachain(FILTERED_PARA_ID)),
|
||||
}),
|
||||
id: AssetId(Location::new(
|
||||
0,
|
||||
[Parachain(FILTERED_PARA_ID)],
|
||||
)),
|
||||
};
|
||||
pub const AnyNetwork: Option<NetworkId> = None;
|
||||
pub UniversalLocation: InteriorMultiLocation = Here;
|
||||
pub UniversalLocation: InteriorLocation = Here;
|
||||
pub UnitWeightCost: u64 = 1_000;
|
||||
pub CheckingAccount: AccountId = XcmPallet::check_account();
|
||||
}
|
||||
@@ -420,7 +417,7 @@ pub type SovereignAccountOf = (
|
||||
);
|
||||
|
||||
pub type ForeignAssetsConvertedConcreteId = MatchedConvertedConcreteId<
|
||||
MultiLocation,
|
||||
Location,
|
||||
Balance,
|
||||
// Excludes relay/parent chain currency
|
||||
EverythingBut<(Equals<RelayLocation>,)>,
|
||||
@@ -432,7 +429,7 @@ pub type ForeignAssetsConvertedConcreteId = MatchedConvertedConcreteId<
|
||||
pub type AssetTransactors = (
|
||||
XcmCurrencyAdapter<Balances, IsConcrete<RelayLocation>, SovereignAccountOf, AccountId, ()>,
|
||||
FungiblesAdapter<
|
||||
Assets,
|
||||
AssetsPallet,
|
||||
ForeignAssetsConvertedConcreteId,
|
||||
SovereignAccountOf,
|
||||
AccountId,
|
||||
@@ -450,24 +447,29 @@ type LocalOriginConverter = (
|
||||
|
||||
parameter_types! {
|
||||
pub const BaseXcmWeight: Weight = Weight::from_parts(1_000, 1_000);
|
||||
pub CurrencyPerSecondPerByte: (AssetId, u128, u128) = (Concrete(RelayLocation::get()), 1, 1);
|
||||
pub TrustedLocal: (MultiAssetFilter, MultiLocation) = (All.into(), Here.into());
|
||||
pub TrustedSystemPara: (MultiAssetFilter, MultiLocation) = (NativeAsset::get().into(), SystemParachainLocation::get());
|
||||
pub TrustedUsdt: (MultiAssetFilter, MultiLocation) = (Usdt::get().into(), UsdtTeleportLocation::get());
|
||||
pub TrustedFilteredTeleport: (MultiAssetFilter, MultiLocation) = (FilteredTeleportAsset::get().into(), FilteredTeleportLocation::get());
|
||||
pub TeleportUsdtToForeign: (MultiAssetFilter, MultiLocation) = (Usdt::get().into(), ForeignReserveLocation::get());
|
||||
pub TrustedForeign: (MultiAssetFilter, MultiLocation) = (ForeignAsset::get().into(), ForeignReserveLocation::get());
|
||||
pub TrustedUsdc: (MultiAssetFilter, MultiLocation) = (Usdc::get().into(), UsdcReserveLocation::get());
|
||||
pub CurrencyPerSecondPerByte: (AssetId, u128, u128) = (AssetId(RelayLocation::get()), 1, 1);
|
||||
pub TrustedLocal: (AssetFilter, Location) = (All.into(), Here.into());
|
||||
pub TrustedSystemPara: (AssetFilter, Location) = (NativeAsset::get().into(), SystemParachainLocation::get());
|
||||
pub TrustedUsdt: (AssetFilter, Location) = (Usdt::get().into(), UsdtTeleportLocation::get());
|
||||
pub TrustedFilteredTeleport: (AssetFilter, Location) = (FilteredTeleportAsset::get().into(), FilteredTeleportLocation::get());
|
||||
pub TeleportUsdtToForeign: (AssetFilter, Location) = (Usdt::get().into(), ForeignReserveLocation::get());
|
||||
pub TrustedForeign: (AssetFilter, Location) = (ForeignAsset::get().into(), ForeignReserveLocation::get());
|
||||
pub TrustedUsdc: (AssetFilter, Location) = (Usdc::get().into(), UsdcReserveLocation::get());
|
||||
pub const MaxInstructions: u32 = 100;
|
||||
pub const MaxAssetsIntoHolding: u32 = 64;
|
||||
pub XcmFeesTargetAccount: AccountId = AccountId::new([167u8; 32]);
|
||||
}
|
||||
|
||||
pub const XCM_FEES_NOT_WAIVED_USER_ACCOUNT: [u8; 32] = [37u8; 32];
|
||||
match_types! {
|
||||
pub type XcmFeesNotWaivedLocations: impl Contains<MultiLocation> = {
|
||||
MultiLocation { parents: 0, interior: X1(Junction::AccountId32 {network: None, id: XCM_FEES_NOT_WAIVED_USER_ACCOUNT})}
|
||||
};
|
||||
|
||||
pub struct XcmFeesNotWaivedLocations;
|
||||
impl Contains<Location> for XcmFeesNotWaivedLocations {
|
||||
fn contains(location: &Location) -> bool {
|
||||
matches!(
|
||||
location.unpack(),
|
||||
(0, [Junction::AccountId32 { network: None, id: XCM_FEES_NOT_WAIVED_USER_ACCOUNT }])
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub type Barrier = (
|
||||
@@ -519,12 +521,12 @@ impl xcm_executor::Config for XcmConfig {
|
||||
pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, AnyNetwork>;
|
||||
|
||||
parameter_types! {
|
||||
pub static AdvertisedXcmVersion: pallet_xcm::XcmVersion = 3;
|
||||
pub static AdvertisedXcmVersion: pallet_xcm::XcmVersion = 4;
|
||||
}
|
||||
|
||||
pub struct XcmTeleportFiltered;
|
||||
impl Contains<(MultiLocation, Vec<MultiAsset>)> for XcmTeleportFiltered {
|
||||
fn contains(t: &(MultiLocation, Vec<MultiAsset>)) -> bool {
|
||||
impl Contains<(Location, Vec<Asset>)> for XcmTeleportFiltered {
|
||||
fn contains(t: &(Location, Vec<Asset>)) -> bool {
|
||||
let filtered = FilteredTeleportAsset::get();
|
||||
t.1.iter().any(|asset| asset == &filtered)
|
||||
}
|
||||
@@ -566,24 +568,23 @@ impl pallet_test_notifier::Config for Test {
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
impl super::benchmarking::Config for Test {
|
||||
fn reachable_dest() -> Option<MultiLocation> {
|
||||
fn reachable_dest() -> Option<Location> {
|
||||
Some(Parachain(1000).into())
|
||||
}
|
||||
|
||||
fn teleportable_asset_and_dest() -> Option<(MultiAsset, MultiLocation)> {
|
||||
fn teleportable_asset_and_dest() -> Option<(Asset, Location)> {
|
||||
Some((NativeAsset::get(), SystemParachainLocation::get()))
|
||||
}
|
||||
|
||||
fn reserve_transferable_asset_and_dest() -> Option<(MultiAsset, MultiLocation)> {
|
||||
fn reserve_transferable_asset_and_dest() -> Option<(Asset, Location)> {
|
||||
Some((
|
||||
MultiAsset { fun: Fungible(10), id: Concrete(Here.into_location()) },
|
||||
Asset { fun: Fungible(10), id: AssetId(Here.into_location()) },
|
||||
Parachain(OTHER_PARA_ID).into(),
|
||||
))
|
||||
}
|
||||
|
||||
fn set_up_complex_asset_transfer(
|
||||
) -> Option<(MultiAssets, u32, MultiLocation, Box<dyn FnOnce()>)> {
|
||||
use crate::tests::assets_transfer::{into_multiassets_checked, set_up_foreign_asset};
|
||||
fn set_up_complex_asset_transfer() -> Option<(Assets, u32, Location, Box<dyn FnOnce()>)> {
|
||||
use crate::tests::assets_transfer::{into_assets_checked, set_up_foreign_asset};
|
||||
// Transfer native asset (local reserve) to `USDT_PARA_ID`. Using teleport-trusted USDT for
|
||||
// fees.
|
||||
|
||||
@@ -600,7 +601,7 @@ impl super::benchmarking::Config for Test {
|
||||
);
|
||||
// create sufficient foreign asset USDT
|
||||
let usdt_initial_local_amount = fee_amount * 10;
|
||||
let (usdt_chain, _, usdt_id_multilocation) = set_up_foreign_asset(
|
||||
let (usdt_chain, _, usdt_id_location) = set_up_foreign_asset(
|
||||
USDT_PARA_ID,
|
||||
None,
|
||||
caller.clone(),
|
||||
@@ -610,22 +611,25 @@ impl super::benchmarking::Config for Test {
|
||||
|
||||
// native assets transfer destination is USDT chain (teleport trust only for USDT)
|
||||
let dest = usdt_chain;
|
||||
let (assets, fee_index, _, _) = into_multiassets_checked(
|
||||
let (assets, fee_index, _, _) = into_assets_checked(
|
||||
// USDT for fees (is sufficient on local chain too) - teleported
|
||||
(usdt_id_multilocation, fee_amount).into(),
|
||||
(usdt_id_location.clone(), fee_amount).into(),
|
||||
// native asset to transfer (not used for fees) - local reserve
|
||||
(MultiLocation::here(), asset_amount).into(),
|
||||
(Location::here(), asset_amount).into(),
|
||||
);
|
||||
// verify initial balances
|
||||
assert_eq!(Balances::free_balance(&caller), balance);
|
||||
assert_eq!(Assets::balance(usdt_id_multilocation, &caller), usdt_initial_local_amount);
|
||||
assert_eq!(
|
||||
AssetsPallet::balance(usdt_id_location.clone(), &caller),
|
||||
usdt_initial_local_amount
|
||||
);
|
||||
|
||||
// verify transferred successfully
|
||||
let verify = Box::new(move || {
|
||||
// verify balances after transfer, decreased by transferred amounts
|
||||
assert_eq!(Balances::free_balance(&caller), balance - asset_amount);
|
||||
assert_eq!(
|
||||
Assets::balance(usdt_id_multilocation, &caller),
|
||||
AssetsPallet::balance(usdt_id_location, &caller),
|
||||
usdt_initial_local_amount - fee_amount
|
||||
);
|
||||
});
|
||||
@@ -641,13 +645,13 @@ pub(crate) fn last_events(n: usize) -> Vec<RuntimeEvent> {
|
||||
System::events().into_iter().map(|e| e.event).rev().take(n).rev().collect()
|
||||
}
|
||||
|
||||
pub(crate) fn buy_execution<C>(fees: impl Into<MultiAsset>) -> Instruction<C> {
|
||||
pub(crate) fn buy_execution<C>(fees: impl Into<Asset>) -> Instruction<C> {
|
||||
use xcm::latest::prelude::*;
|
||||
BuyExecution { fees: fees.into(), weight_limit: Unlimited }
|
||||
}
|
||||
|
||||
pub(crate) fn buy_limited_execution<C>(
|
||||
fees: impl Into<MultiAsset>,
|
||||
fees: impl Into<Asset>,
|
||||
weight_limit: WeightLimit,
|
||||
) -> Instruction<C> {
|
||||
use xcm::latest::prelude::*;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -19,9 +19,8 @@
|
||||
pub(crate) mod assets_transfer;
|
||||
|
||||
use crate::{
|
||||
mock::*, AssetTraps, CurrentMigration, Error, LatestVersionedMultiLocation, Queries,
|
||||
QueryStatus, VersionDiscoveryQueue, VersionMigrationStage, VersionNotifiers,
|
||||
VersionNotifyTargets,
|
||||
mock::*, AssetTraps, CurrentMigration, Error, LatestVersionedLocation, Queries, QueryStatus,
|
||||
VersionDiscoveryQueue, VersionMigrationStage, VersionNotifiers, VersionNotifyTargets,
|
||||
};
|
||||
use frame_support::{
|
||||
assert_noop, assert_ok,
|
||||
@@ -49,9 +48,11 @@ fn report_outcome_notify_works() {
|
||||
(ALICE, INITIAL_BALANCE),
|
||||
(ParaId::from(OTHER_PARA_ID).into_account_truncating(), INITIAL_BALANCE),
|
||||
];
|
||||
let sender: MultiLocation = AccountId32 { network: None, id: ALICE.into() }.into();
|
||||
let mut message =
|
||||
Xcm(vec![TransferAsset { assets: (Here, SEND_AMOUNT).into(), beneficiary: sender }]);
|
||||
let sender: Location = AccountId32 { network: None, id: ALICE.into() }.into();
|
||||
let mut message = Xcm(vec![TransferAsset {
|
||||
assets: (Here, SEND_AMOUNT).into(),
|
||||
beneficiary: sender.clone(),
|
||||
}]);
|
||||
let call = pallet_test_notifier::Call::notification_received {
|
||||
query_id: 0,
|
||||
response: Default::default(),
|
||||
@@ -76,12 +77,12 @@ fn report_outcome_notify_works() {
|
||||
TransferAsset { assets: (Here, SEND_AMOUNT).into(), beneficiary: sender },
|
||||
])
|
||||
);
|
||||
let querier: MultiLocation = Here.into();
|
||||
let querier: Location = Here.into();
|
||||
let status = QueryStatus::Pending {
|
||||
responder: MultiLocation::from(Parachain(OTHER_PARA_ID)).into(),
|
||||
responder: Location::from(Parachain(OTHER_PARA_ID)).into(),
|
||||
maybe_notify: Some((5, 2)),
|
||||
timeout: 100,
|
||||
maybe_match_querier: Some(querier.into()),
|
||||
maybe_match_querier: Some(querier.clone().into()),
|
||||
};
|
||||
assert_eq!(crate::Queries::<Test>::iter().collect::<Vec<_>>(), vec![(0, status)]);
|
||||
|
||||
@@ -91,14 +92,15 @@ fn report_outcome_notify_works() {
|
||||
max_weight: Weight::from_parts(1_000_000, 1_000_000),
|
||||
querier: Some(querier),
|
||||
}]);
|
||||
let hash = fake_message_hash(&message);
|
||||
let r = XcmExecutor::<XcmConfig>::execute_xcm(
|
||||
let mut hash = fake_message_hash(&message);
|
||||
let r = XcmExecutor::<XcmConfig>::prepare_and_execute(
|
||||
Parachain(OTHER_PARA_ID),
|
||||
message,
|
||||
hash,
|
||||
&mut hash,
|
||||
Weight::from_parts(1_000_000_000, 1_000_000_000),
|
||||
Weight::zero(),
|
||||
);
|
||||
assert_eq!(r, Outcome::Complete(Weight::from_parts(1_000, 1_000)));
|
||||
assert_eq!(r, Outcome::Complete { used: Weight::from_parts(1_000, 1_000) });
|
||||
assert_eq!(
|
||||
last_events(2),
|
||||
vec![
|
||||
@@ -124,9 +126,11 @@ fn report_outcome_works() {
|
||||
(ALICE, INITIAL_BALANCE),
|
||||
(ParaId::from(OTHER_PARA_ID).into_account_truncating(), INITIAL_BALANCE),
|
||||
];
|
||||
let sender: MultiLocation = AccountId32 { network: None, id: ALICE.into() }.into();
|
||||
let mut message =
|
||||
Xcm(vec![TransferAsset { assets: (Here, SEND_AMOUNT).into(), beneficiary: sender }]);
|
||||
let sender: Location = AccountId32 { network: None, id: ALICE.into() }.into();
|
||||
let mut message = Xcm(vec![TransferAsset {
|
||||
assets: (Here, SEND_AMOUNT).into(),
|
||||
beneficiary: sender.clone(),
|
||||
}]);
|
||||
new_test_ext_with_balances(balances).execute_with(|| {
|
||||
XcmPallet::report_outcome(&mut message, Parachain(OTHER_PARA_ID).into_location(), 100)
|
||||
.unwrap();
|
||||
@@ -141,12 +145,12 @@ fn report_outcome_works() {
|
||||
TransferAsset { assets: (Here, SEND_AMOUNT).into(), beneficiary: sender },
|
||||
])
|
||||
);
|
||||
let querier: MultiLocation = Here.into();
|
||||
let querier: Location = Here.into();
|
||||
let status = QueryStatus::Pending {
|
||||
responder: MultiLocation::from(Parachain(OTHER_PARA_ID)).into(),
|
||||
responder: Location::from(Parachain(OTHER_PARA_ID)).into(),
|
||||
maybe_notify: None,
|
||||
timeout: 100,
|
||||
maybe_match_querier: Some(querier.into()),
|
||||
maybe_match_querier: Some(querier.clone().into()),
|
||||
};
|
||||
assert_eq!(crate::Queries::<Test>::iter().collect::<Vec<_>>(), vec![(0, status)]);
|
||||
|
||||
@@ -156,14 +160,15 @@ fn report_outcome_works() {
|
||||
max_weight: Weight::zero(),
|
||||
querier: Some(querier),
|
||||
}]);
|
||||
let hash = fake_message_hash(&message);
|
||||
let r = XcmExecutor::<XcmConfig>::execute_xcm(
|
||||
let mut hash = fake_message_hash(&message);
|
||||
let r = XcmExecutor::<XcmConfig>::prepare_and_execute(
|
||||
Parachain(OTHER_PARA_ID),
|
||||
message,
|
||||
hash,
|
||||
&mut hash,
|
||||
Weight::from_parts(1_000_000_000, 1_000_000_000),
|
||||
Weight::zero(),
|
||||
);
|
||||
assert_eq!(r, Outcome::Complete(Weight::from_parts(1_000, 1_000)));
|
||||
assert_eq!(r, Outcome::Complete { used: Weight::from_parts(1_000, 1_000) });
|
||||
assert_eq!(
|
||||
last_event(),
|
||||
RuntimeEvent::XcmPallet(crate::Event::ResponseReady {
|
||||
@@ -185,16 +190,15 @@ fn custom_querier_works() {
|
||||
(ParaId::from(OTHER_PARA_ID).into_account_truncating(), INITIAL_BALANCE),
|
||||
];
|
||||
new_test_ext_with_balances(balances).execute_with(|| {
|
||||
let querier: MultiLocation =
|
||||
(Parent, AccountId32 { network: None, id: ALICE.into() }).into();
|
||||
let querier: Location = (Parent, AccountId32 { network: None, id: ALICE.into() }).into();
|
||||
|
||||
let r = TestNotifier::prepare_new_query(RuntimeOrigin::signed(ALICE), querier);
|
||||
let r = TestNotifier::prepare_new_query(RuntimeOrigin::signed(ALICE), querier.clone());
|
||||
assert_eq!(r, Ok(()));
|
||||
let status = QueryStatus::Pending {
|
||||
responder: MultiLocation::from(AccountId32 { network: None, id: ALICE.into() }).into(),
|
||||
responder: Location::from(AccountId32 { network: None, id: ALICE.into() }).into(),
|
||||
maybe_notify: None,
|
||||
timeout: 100,
|
||||
maybe_match_querier: Some(querier.into()),
|
||||
maybe_match_querier: Some(querier.clone().into()),
|
||||
};
|
||||
assert_eq!(crate::Queries::<Test>::iter().collect::<Vec<_>>(), vec![(0, status)]);
|
||||
|
||||
@@ -205,21 +209,21 @@ fn custom_querier_works() {
|
||||
max_weight: Weight::zero(),
|
||||
querier: None,
|
||||
}]);
|
||||
let hash = fake_message_hash(&message);
|
||||
let r = XcmExecutor::<XcmConfig>::execute_xcm_in_credit(
|
||||
let mut hash = fake_message_hash(&message);
|
||||
let r = XcmExecutor::<XcmConfig>::prepare_and_execute(
|
||||
AccountId32 { network: None, id: ALICE.into() },
|
||||
message,
|
||||
hash,
|
||||
&mut hash,
|
||||
Weight::from_parts(1_000_000_000, 1_000_000_000),
|
||||
Weight::from_parts(1_000, 1_000),
|
||||
);
|
||||
assert_eq!(r, Outcome::Complete(Weight::from_parts(1_000, 1_000)));
|
||||
assert_eq!(r, Outcome::Complete { used: Weight::from_parts(1_000, 1_000) });
|
||||
assert_eq!(
|
||||
last_event(),
|
||||
RuntimeEvent::XcmPallet(crate::Event::InvalidQuerier {
|
||||
origin: AccountId32 { network: None, id: ALICE.into() }.into(),
|
||||
query_id: 0,
|
||||
expected_querier: querier,
|
||||
expected_querier: querier.clone(),
|
||||
maybe_actual_querier: None,
|
||||
}),
|
||||
);
|
||||
@@ -229,24 +233,24 @@ fn custom_querier_works() {
|
||||
query_id: 0,
|
||||
response: Response::ExecutionResult(None),
|
||||
max_weight: Weight::zero(),
|
||||
querier: Some(MultiLocation::here()),
|
||||
querier: Some(Location::here()),
|
||||
}]);
|
||||
let hash = fake_message_hash(&message);
|
||||
let r = XcmExecutor::<XcmConfig>::execute_xcm_in_credit(
|
||||
let mut hash = fake_message_hash(&message);
|
||||
let r = XcmExecutor::<XcmConfig>::prepare_and_execute(
|
||||
AccountId32 { network: None, id: ALICE.into() },
|
||||
message,
|
||||
hash,
|
||||
&mut hash,
|
||||
Weight::from_parts(1_000_000_000, 1_000_000_000),
|
||||
Weight::from_parts(1_000, 1_000),
|
||||
);
|
||||
assert_eq!(r, Outcome::Complete(Weight::from_parts(1_000, 1_000)));
|
||||
assert_eq!(r, Outcome::Complete { used: Weight::from_parts(1_000, 1_000) });
|
||||
assert_eq!(
|
||||
last_event(),
|
||||
RuntimeEvent::XcmPallet(crate::Event::InvalidQuerier {
|
||||
origin: AccountId32 { network: None, id: ALICE.into() }.into(),
|
||||
query_id: 0,
|
||||
expected_querier: querier,
|
||||
maybe_actual_querier: Some(MultiLocation::here()),
|
||||
expected_querier: querier.clone(),
|
||||
maybe_actual_querier: Some(Location::here()),
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -257,14 +261,15 @@ fn custom_querier_works() {
|
||||
max_weight: Weight::zero(),
|
||||
querier: Some(querier),
|
||||
}]);
|
||||
let hash = fake_message_hash(&message);
|
||||
let r = XcmExecutor::<XcmConfig>::execute_xcm(
|
||||
let mut hash = fake_message_hash(&message);
|
||||
let r = XcmExecutor::<XcmConfig>::prepare_and_execute(
|
||||
AccountId32 { network: None, id: ALICE.into() },
|
||||
message,
|
||||
hash,
|
||||
&mut hash,
|
||||
Weight::from_parts(1_000_000_000, 1_000_000_000),
|
||||
Weight::zero(),
|
||||
);
|
||||
assert_eq!(r, Outcome::Complete(Weight::from_parts(1_000, 1_000)));
|
||||
assert_eq!(r, Outcome::Complete { used: Weight::from_parts(1_000, 1_000) });
|
||||
assert_eq!(
|
||||
last_event(),
|
||||
RuntimeEvent::XcmPallet(crate::Event::ResponseReady {
|
||||
@@ -289,12 +294,12 @@ fn send_works() {
|
||||
(ParaId::from(OTHER_PARA_ID).into_account_truncating(), INITIAL_BALANCE),
|
||||
];
|
||||
new_test_ext_with_balances(balances).execute_with(|| {
|
||||
let sender: MultiLocation = AccountId32 { network: None, id: ALICE.into() }.into();
|
||||
let sender: Location = AccountId32 { network: None, id: ALICE.into() }.into();
|
||||
let message = Xcm(vec![
|
||||
ReserveAssetDeposited((Parent, SEND_AMOUNT).into()),
|
||||
ClearOrigin,
|
||||
buy_execution((Parent, SEND_AMOUNT)),
|
||||
DepositAsset { assets: AllCounted(1).into(), beneficiary: sender },
|
||||
DepositAsset { assets: AllCounted(1).into(), beneficiary: sender.clone() },
|
||||
]);
|
||||
|
||||
let versioned_dest = Box::new(RelayLocation::get().into());
|
||||
@@ -304,7 +309,7 @@ fn send_works() {
|
||||
versioned_dest,
|
||||
versioned_message
|
||||
));
|
||||
let sent_message = Xcm(Some(DescendOrigin(sender.try_into().unwrap()))
|
||||
let sent_message = Xcm(Some(DescendOrigin(sender.clone().try_into().unwrap()))
|
||||
.into_iter()
|
||||
.chain(message.0.clone().into_iter())
|
||||
.collect());
|
||||
@@ -333,8 +338,7 @@ fn send_fails_when_xcm_router_blocks() {
|
||||
(ParaId::from(OTHER_PARA_ID).into_account_truncating(), INITIAL_BALANCE),
|
||||
];
|
||||
new_test_ext_with_balances(balances).execute_with(|| {
|
||||
let sender: MultiLocation =
|
||||
Junction::AccountId32 { network: None, id: ALICE.into() }.into();
|
||||
let sender: Location = Junction::AccountId32 { network: None, id: ALICE.into() }.into();
|
||||
let message = Xcm(vec![
|
||||
ReserveAssetDeposited((Parent, SEND_AMOUNT).into()),
|
||||
buy_execution((Parent, SEND_AMOUNT)),
|
||||
@@ -343,7 +347,7 @@ fn send_fails_when_xcm_router_blocks() {
|
||||
assert_noop!(
|
||||
XcmPallet::send(
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
Box::new(MultiLocation::ancestor(8).into()),
|
||||
Box::new(Location::ancestor(8).into()),
|
||||
Box::new(VersionedXcm::from(message.clone())),
|
||||
),
|
||||
crate::Error::<Test>::SendFailure
|
||||
@@ -363,7 +367,7 @@ fn execute_withdraw_to_deposit_works() {
|
||||
];
|
||||
new_test_ext_with_balances(balances).execute_with(|| {
|
||||
let weight = BaseXcmWeight::get() * 3;
|
||||
let dest: MultiLocation = Junction::AccountId32 { network: None, id: BOB.into() }.into();
|
||||
let dest: Location = Junction::AccountId32 { network: None, id: BOB.into() }.into();
|
||||
assert_eq!(Balances::total_balance(&ALICE), INITIAL_BALANCE);
|
||||
assert_ok!(XcmPallet::execute(
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
@@ -378,7 +382,9 @@ fn execute_withdraw_to_deposit_works() {
|
||||
assert_eq!(Balances::total_balance(&BOB), SEND_AMOUNT);
|
||||
assert_eq!(
|
||||
last_event(),
|
||||
RuntimeEvent::XcmPallet(crate::Event::Attempted { outcome: Outcome::Complete(weight) })
|
||||
RuntimeEvent::XcmPallet(crate::Event::Attempted {
|
||||
outcome: Outcome::Complete { used: weight }
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -389,7 +395,7 @@ fn trapped_assets_can_be_claimed() {
|
||||
let balances = vec![(ALICE, INITIAL_BALANCE), (BOB, INITIAL_BALANCE)];
|
||||
new_test_ext_with_balances(balances).execute_with(|| {
|
||||
let weight = BaseXcmWeight::get() * 6;
|
||||
let dest: MultiLocation = Junction::AccountId32 { network: None, id: BOB.into() }.into();
|
||||
let dest: Location = Junction::AccountId32 { network: None, id: BOB.into() }.into();
|
||||
|
||||
assert_ok!(XcmPallet::execute(
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
@@ -401,15 +407,14 @@ fn trapped_assets_can_be_claimed() {
|
||||
// This will make an error.
|
||||
Trap(0),
|
||||
// This would succeed, but we never get to it.
|
||||
DepositAsset { assets: AllCounted(1).into(), beneficiary: dest },
|
||||
DepositAsset { assets: AllCounted(1).into(), beneficiary: dest.clone() },
|
||||
]))),
|
||||
weight
|
||||
));
|
||||
let source: MultiLocation =
|
||||
Junction::AccountId32 { network: None, id: ALICE.into() }.into();
|
||||
let source: Location = Junction::AccountId32 { network: None, id: ALICE.into() }.into();
|
||||
let trapped = AssetTraps::<Test>::iter().collect::<Vec<_>>();
|
||||
let vma = VersionedMultiAssets::from(MultiAssets::from((Here, SEND_AMOUNT)));
|
||||
let hash = BlakeTwo256::hash_of(&(source, vma.clone()));
|
||||
let vma = VersionedAssets::from(Assets::from((Here, SEND_AMOUNT)));
|
||||
let hash = BlakeTwo256::hash_of(&(source.clone(), vma.clone()));
|
||||
assert_eq!(
|
||||
last_events(2),
|
||||
vec![
|
||||
@@ -419,7 +424,7 @@ fn trapped_assets_can_be_claimed() {
|
||||
assets: vma
|
||||
}),
|
||||
RuntimeEvent::XcmPallet(crate::Event::Attempted {
|
||||
outcome: Outcome::Complete(BaseXcmWeight::get() * 5)
|
||||
outcome: Outcome::Complete { used: BaseXcmWeight::get() * 5 }
|
||||
}),
|
||||
]
|
||||
);
|
||||
@@ -435,7 +440,7 @@ fn trapped_assets_can_be_claimed() {
|
||||
Box::new(VersionedXcm::from(Xcm(vec![
|
||||
ClaimAsset { assets: (Here, SEND_AMOUNT).into(), ticket: Here.into() },
|
||||
buy_execution((Here, SEND_AMOUNT)),
|
||||
DepositAsset { assets: AllCounted(1).into(), beneficiary: dest },
|
||||
DepositAsset { assets: AllCounted(1).into(), beneficiary: dest.clone() },
|
||||
]))),
|
||||
weight
|
||||
));
|
||||
@@ -454,7 +459,8 @@ fn trapped_assets_can_be_claimed() {
|
||||
]))),
|
||||
weight
|
||||
));
|
||||
let outcome = Outcome::Incomplete(BaseXcmWeight::get(), XcmError::UnknownClaim);
|
||||
let outcome =
|
||||
Outcome::Incomplete { used: BaseXcmWeight::get(), error: XcmError::UnknownClaim };
|
||||
assert_eq!(last_event(), RuntimeEvent::XcmPallet(crate::Event::Attempted { outcome }));
|
||||
});
|
||||
}
|
||||
@@ -468,10 +474,10 @@ fn incomplete_execute_reverts_side_effects() {
|
||||
let balances = vec![(ALICE, INITIAL_BALANCE), (BOB, INITIAL_BALANCE)];
|
||||
new_test_ext_with_balances(balances).execute_with(|| {
|
||||
let weight = BaseXcmWeight::get() * 4;
|
||||
let dest: MultiLocation = Junction::AccountId32 { network: None, id: BOB.into() }.into();
|
||||
let dest: Location = Junction::AccountId32 { network: None, id: BOB.into() }.into();
|
||||
assert_eq!(Balances::total_balance(&ALICE), INITIAL_BALANCE);
|
||||
let amount_to_send = INITIAL_BALANCE - ExistentialDeposit::get();
|
||||
let assets: MultiAssets = (Here, amount_to_send).into();
|
||||
let assets: Assets = (Here, amount_to_send).into();
|
||||
let result = XcmPallet::execute(
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
Box::new(VersionedXcm::from(Xcm(vec![
|
||||
@@ -506,35 +512,38 @@ fn incomplete_execute_reverts_side_effects() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fake_latest_versioned_multilocation_works() {
|
||||
fn fake_latest_versioned_location_works() {
|
||||
use codec::Encode;
|
||||
let remote: MultiLocation = Parachain(1000).into();
|
||||
let versioned_remote = LatestVersionedMultiLocation(&remote);
|
||||
let remote: Location = Parachain(1000).into();
|
||||
let versioned_remote = LatestVersionedLocation(&remote);
|
||||
assert_eq!(versioned_remote.encode(), remote.into_versioned().encode());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn basic_subscription_works() {
|
||||
new_test_ext_with_balances(vec![]).execute_with(|| {
|
||||
let remote: MultiLocation = Parachain(1000).into();
|
||||
let remote: Location = Parachain(1000).into();
|
||||
assert_ok!(XcmPallet::force_subscribe_version_notify(
|
||||
RuntimeOrigin::root(),
|
||||
Box::new(remote.into()),
|
||||
Box::new(remote.clone().into()),
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
Queries::<Test>::iter().collect::<Vec<_>>(),
|
||||
vec![(0, QueryStatus::VersionNotifier { origin: remote.into(), is_active: false })]
|
||||
vec![(
|
||||
0,
|
||||
QueryStatus::VersionNotifier { origin: remote.clone().into(), is_active: false }
|
||||
)]
|
||||
);
|
||||
assert_eq!(
|
||||
VersionNotifiers::<Test>::iter().collect::<Vec<_>>(),
|
||||
vec![(XCM_VERSION, remote.into(), 0)]
|
||||
vec![(XCM_VERSION, remote.clone().into(), 0)]
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
take_sent_xcm(),
|
||||
vec![(
|
||||
remote,
|
||||
remote.clone(),
|
||||
Xcm(vec![SubscribeVersion { query_id: 0, max_response_weight: Weight::zero() }]),
|
||||
),]
|
||||
);
|
||||
@@ -561,16 +570,16 @@ fn basic_subscription_works() {
|
||||
#[test]
|
||||
fn subscriptions_increment_id() {
|
||||
new_test_ext_with_balances(vec![]).execute_with(|| {
|
||||
let remote: MultiLocation = Parachain(1000).into();
|
||||
let remote: Location = Parachain(1000).into();
|
||||
assert_ok!(XcmPallet::force_subscribe_version_notify(
|
||||
RuntimeOrigin::root(),
|
||||
Box::new(remote.into()),
|
||||
Box::new(remote.clone().into()),
|
||||
));
|
||||
|
||||
let remote2: MultiLocation = Parachain(1001).into();
|
||||
let remote2: Location = Parachain(1001).into();
|
||||
assert_ok!(XcmPallet::force_subscribe_version_notify(
|
||||
RuntimeOrigin::root(),
|
||||
Box::new(remote2.into()),
|
||||
Box::new(remote2.clone().into()),
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
@@ -598,10 +607,10 @@ fn subscriptions_increment_id() {
|
||||
#[test]
|
||||
fn double_subscription_fails() {
|
||||
new_test_ext_with_balances(vec![]).execute_with(|| {
|
||||
let remote: MultiLocation = Parachain(1000).into();
|
||||
let remote: Location = Parachain(1000).into();
|
||||
assert_ok!(XcmPallet::force_subscribe_version_notify(
|
||||
RuntimeOrigin::root(),
|
||||
Box::new(remote.into()),
|
||||
Box::new(remote.clone().into()),
|
||||
));
|
||||
assert_noop!(
|
||||
XcmPallet::force_subscribe_version_notify(
|
||||
@@ -616,19 +625,19 @@ fn double_subscription_fails() {
|
||||
#[test]
|
||||
fn unsubscribe_works() {
|
||||
new_test_ext_with_balances(vec![]).execute_with(|| {
|
||||
let remote: MultiLocation = Parachain(1000).into();
|
||||
let remote: Location = Parachain(1000).into();
|
||||
assert_ok!(XcmPallet::force_subscribe_version_notify(
|
||||
RuntimeOrigin::root(),
|
||||
Box::new(remote.into()),
|
||||
Box::new(remote.clone().into()),
|
||||
));
|
||||
assert_ok!(XcmPallet::force_unsubscribe_version_notify(
|
||||
RuntimeOrigin::root(),
|
||||
Box::new(remote.into())
|
||||
Box::new(remote.clone().into())
|
||||
));
|
||||
assert_noop!(
|
||||
XcmPallet::force_unsubscribe_version_notify(
|
||||
RuntimeOrigin::root(),
|
||||
Box::new(remote.into())
|
||||
Box::new(remote.clone().into())
|
||||
),
|
||||
Error::<Test>::NoSubscription,
|
||||
);
|
||||
@@ -637,13 +646,13 @@ fn unsubscribe_works() {
|
||||
take_sent_xcm(),
|
||||
vec![
|
||||
(
|
||||
remote,
|
||||
remote.clone(),
|
||||
Xcm(vec![SubscribeVersion {
|
||||
query_id: 0,
|
||||
max_response_weight: Weight::zero()
|
||||
}]),
|
||||
),
|
||||
(remote, Xcm(vec![UnsubscribeVersion]),),
|
||||
(remote.clone(), Xcm(vec![UnsubscribeVersion]),),
|
||||
]
|
||||
);
|
||||
});
|
||||
@@ -655,13 +664,19 @@ fn subscription_side_works() {
|
||||
new_test_ext_with_balances(vec![]).execute_with(|| {
|
||||
AdvertisedXcmVersion::set(1);
|
||||
|
||||
let remote: MultiLocation = Parachain(1000).into();
|
||||
let remote: Location = Parachain(1000).into();
|
||||
let weight = BaseXcmWeight::get();
|
||||
let message =
|
||||
Xcm(vec![SubscribeVersion { query_id: 0, max_response_weight: Weight::zero() }]);
|
||||
let hash = fake_message_hash(&message);
|
||||
let r = XcmExecutor::<XcmConfig>::execute_xcm(remote, message, hash, weight);
|
||||
assert_eq!(r, Outcome::Complete(weight));
|
||||
let mut hash = fake_message_hash(&message);
|
||||
let r = XcmExecutor::<XcmConfig>::prepare_and_execute(
|
||||
remote.clone(),
|
||||
message,
|
||||
&mut hash,
|
||||
weight,
|
||||
Weight::zero(),
|
||||
);
|
||||
assert_eq!(r, Outcome::Complete { used: weight });
|
||||
|
||||
let instr = QueryResponse {
|
||||
query_id: 0,
|
||||
@@ -669,7 +684,7 @@ fn subscription_side_works() {
|
||||
response: Response::Version(1),
|
||||
querier: None,
|
||||
};
|
||||
assert_eq!(take_sent_xcm(), vec![(remote, Xcm(vec![instr]))]);
|
||||
assert_eq!(take_sent_xcm(), vec![(remote.clone(), Xcm(vec![instr]))]);
|
||||
|
||||
// A runtime upgrade which doesn't alter the version sends no notifications.
|
||||
CurrentMigration::<Test>::put(VersionMigrationStage::default());
|
||||
@@ -698,7 +713,7 @@ fn subscription_side_upgrades_work_with_notify() {
|
||||
AdvertisedXcmVersion::set(1);
|
||||
|
||||
// An entry from a previous runtime with v2 XCM.
|
||||
let v2_location = VersionedMultiLocation::V2(xcm::v2::Junction::Parachain(1001).into());
|
||||
let v2_location = VersionedLocation::V2(xcm::v2::Junction::Parachain(1001).into());
|
||||
VersionNotifyTargets::<Test>::insert(1, v2_location, (70, Weight::zero(), 2));
|
||||
let v3_location = Parachain(1003).into_versioned();
|
||||
VersionNotifyTargets::<Test>::insert(3, v3_location, (72, Weight::zero(), 2));
|
||||
@@ -751,7 +766,7 @@ fn subscription_side_upgrades_work_with_notify() {
|
||||
fn subscription_side_upgrades_work_without_notify() {
|
||||
new_test_ext_with_balances(vec![]).execute_with(|| {
|
||||
// An entry from a previous runtime with v2 XCM.
|
||||
let v2_location = VersionedMultiLocation::V2(xcm::v2::Junction::Parachain(1001).into());
|
||||
let v2_location = VersionedLocation::V2(xcm::v2::Junction::Parachain(1001).into());
|
||||
VersionNotifyTargets::<Test>::insert(1, v2_location, (70, Weight::zero(), 2));
|
||||
let v3_location = Parachain(1003).into_versioned();
|
||||
VersionNotifyTargets::<Test>::insert(3, v3_location, (72, Weight::zero(), 2));
|
||||
@@ -765,8 +780,8 @@ fn subscription_side_upgrades_work_without_notify() {
|
||||
assert_eq!(
|
||||
contents,
|
||||
vec![
|
||||
(XCM_VERSION, Parachain(1001).into_versioned(), (70, Weight::zero(), 3)),
|
||||
(XCM_VERSION, Parachain(1003).into_versioned(), (72, Weight::zero(), 3)),
|
||||
(XCM_VERSION, Parachain(1001).into_versioned(), (70, Weight::zero(), 4)),
|
||||
(XCM_VERSION, Parachain(1003).into_versioned(), (72, Weight::zero(), 4)),
|
||||
]
|
||||
);
|
||||
});
|
||||
@@ -775,10 +790,10 @@ fn subscription_side_upgrades_work_without_notify() {
|
||||
#[test]
|
||||
fn subscriber_side_subscription_works() {
|
||||
new_test_ext_with_balances_and_xcm_version(vec![], Some(XCM_VERSION)).execute_with(|| {
|
||||
let remote: MultiLocation = Parachain(1000).into();
|
||||
let remote: Location = Parachain(1000).into();
|
||||
assert_ok!(XcmPallet::force_subscribe_version_notify(
|
||||
RuntimeOrigin::root(),
|
||||
Box::new(remote.into()),
|
||||
Box::new(remote.clone().into()),
|
||||
));
|
||||
assert_eq!(XcmPallet::get_version_for(&remote), None);
|
||||
take_sent_xcm();
|
||||
@@ -795,9 +810,15 @@ fn subscriber_side_subscription_works() {
|
||||
querier: None,
|
||||
},
|
||||
]);
|
||||
let hash = fake_message_hash(&message);
|
||||
let r = XcmExecutor::<XcmConfig>::execute_xcm(remote, message, hash, weight);
|
||||
assert_eq!(r, Outcome::Complete(weight));
|
||||
let mut hash = fake_message_hash(&message);
|
||||
let r = XcmExecutor::<XcmConfig>::prepare_and_execute(
|
||||
remote.clone(),
|
||||
message,
|
||||
&mut hash,
|
||||
weight,
|
||||
Weight::zero(),
|
||||
);
|
||||
assert_eq!(r, Outcome::Complete { used: weight });
|
||||
assert_eq!(take_sent_xcm(), vec![]);
|
||||
assert_eq!(XcmPallet::get_version_for(&remote), Some(1));
|
||||
|
||||
@@ -814,9 +835,15 @@ fn subscriber_side_subscription_works() {
|
||||
querier: None,
|
||||
},
|
||||
]);
|
||||
let hash = fake_message_hash(&message);
|
||||
let r = XcmExecutor::<XcmConfig>::execute_xcm(remote, message, hash, weight);
|
||||
assert_eq!(r, Outcome::Complete(weight));
|
||||
let mut hash = fake_message_hash(&message);
|
||||
let r = XcmExecutor::<XcmConfig>::prepare_and_execute(
|
||||
remote.clone(),
|
||||
message,
|
||||
&mut hash,
|
||||
weight,
|
||||
Weight::zero(),
|
||||
);
|
||||
assert_eq!(r, Outcome::Complete { used: weight });
|
||||
assert_eq!(take_sent_xcm(), vec![]);
|
||||
assert_eq!(XcmPallet::get_version_for(&remote), Some(2));
|
||||
|
||||
@@ -832,73 +859,79 @@ fn subscriber_side_subscription_works() {
|
||||
#[test]
|
||||
fn auto_subscription_works() {
|
||||
new_test_ext_with_balances_and_xcm_version(vec![], None).execute_with(|| {
|
||||
let remote_v2: MultiLocation = Parachain(1000).into();
|
||||
let remote_v3: MultiLocation = Parachain(1001).into();
|
||||
let remote_v2: Location = Parachain(1000).into();
|
||||
let remote_v4: Location = Parachain(1001).into();
|
||||
|
||||
assert_ok!(XcmPallet::force_default_xcm_version(RuntimeOrigin::root(), Some(2)));
|
||||
|
||||
// Wrapping a version for a destination we don't know elicits a subscription.
|
||||
let msg_v2 = xcm::v2::Xcm::<()>(vec![xcm::v2::Instruction::Trap(0)]);
|
||||
let msg_v3 = xcm::v3::Xcm::<()>(vec![xcm::v3::Instruction::ClearTopic]);
|
||||
let msg_v4 = xcm::v4::Xcm::<()>(vec![xcm::v4::Instruction::ClearTopic]);
|
||||
assert_eq!(
|
||||
XcmPallet::wrap_version(&remote_v2, msg_v2.clone()),
|
||||
Ok(VersionedXcm::from(msg_v2.clone())),
|
||||
);
|
||||
assert_eq!(XcmPallet::wrap_version(&remote_v2, msg_v3.clone()), Err(()));
|
||||
assert_eq!(XcmPallet::wrap_version(&remote_v2, msg_v4.clone()), Err(()));
|
||||
|
||||
let expected = vec![(remote_v2.into(), 2)];
|
||||
let expected = vec![(remote_v2.clone().into(), 2)];
|
||||
assert_eq!(VersionDiscoveryQueue::<Test>::get().into_inner(), expected);
|
||||
|
||||
assert_eq!(
|
||||
XcmPallet::wrap_version(&remote_v3, msg_v2.clone()),
|
||||
XcmPallet::wrap_version(&remote_v4, msg_v2.clone()),
|
||||
Ok(VersionedXcm::from(msg_v2.clone())),
|
||||
);
|
||||
assert_eq!(XcmPallet::wrap_version(&remote_v3, msg_v3.clone()), Err(()));
|
||||
assert_eq!(XcmPallet::wrap_version(&remote_v4, msg_v4.clone()), Err(()));
|
||||
|
||||
let expected = vec![(remote_v2.into(), 2), (remote_v3.into(), 2)];
|
||||
let expected = vec![(remote_v2.clone().into(), 2), (remote_v4.clone().into(), 2)];
|
||||
assert_eq!(VersionDiscoveryQueue::<Test>::get().into_inner(), expected);
|
||||
|
||||
XcmPallet::on_initialize(1);
|
||||
assert_eq!(
|
||||
take_sent_xcm(),
|
||||
vec![(
|
||||
remote_v3,
|
||||
remote_v4.clone(),
|
||||
Xcm(vec![SubscribeVersion { query_id: 0, max_response_weight: Weight::zero() }]),
|
||||
)]
|
||||
);
|
||||
|
||||
// Assume remote_v3 is working ok and XCM version 3.
|
||||
// Assume remote_v4 is working ok and XCM version 4.
|
||||
|
||||
let weight = BaseXcmWeight::get();
|
||||
let message = Xcm(vec![
|
||||
// Remote supports XCM v3
|
||||
// Remote supports XCM v4
|
||||
QueryResponse {
|
||||
query_id: 0,
|
||||
max_weight: Weight::zero(),
|
||||
response: Response::Version(3),
|
||||
response: Response::Version(4),
|
||||
querier: None,
|
||||
},
|
||||
]);
|
||||
let hash = fake_message_hash(&message);
|
||||
let r = XcmExecutor::<XcmConfig>::execute_xcm(remote_v3, message, hash, weight);
|
||||
assert_eq!(r, Outcome::Complete(weight));
|
||||
|
||||
// V2 messages can be sent to remote_v3 under XCM v3.
|
||||
assert_eq!(
|
||||
XcmPallet::wrap_version(&remote_v3, msg_v2.clone()),
|
||||
Ok(VersionedXcm::from(msg_v2.clone()).into_version(3).unwrap()),
|
||||
let mut hash = fake_message_hash(&message);
|
||||
let r = XcmExecutor::<XcmConfig>::prepare_and_execute(
|
||||
remote_v4.clone(),
|
||||
message,
|
||||
&mut hash,
|
||||
weight,
|
||||
Weight::zero(),
|
||||
);
|
||||
// This message can now be sent to remote_v3 as it's v3.
|
||||
assert_eq!(r, Outcome::Complete { used: weight });
|
||||
|
||||
// V2 messages can be sent to remote_v4 under XCM v4.
|
||||
assert_eq!(
|
||||
XcmPallet::wrap_version(&remote_v3, msg_v3.clone()),
|
||||
Ok(VersionedXcm::from(msg_v3.clone()))
|
||||
XcmPallet::wrap_version(&remote_v4, msg_v2.clone()),
|
||||
Ok(VersionedXcm::from(msg_v2.clone()).into_version(4).unwrap()),
|
||||
);
|
||||
// This message can now be sent to remote_v4 as it's v4.
|
||||
assert_eq!(
|
||||
XcmPallet::wrap_version(&remote_v4, msg_v4.clone()),
|
||||
Ok(VersionedXcm::from(msg_v4.clone()))
|
||||
);
|
||||
|
||||
XcmPallet::on_initialize(2);
|
||||
assert_eq!(
|
||||
take_sent_xcm(),
|
||||
vec![(
|
||||
remote_v2,
|
||||
remote_v2.clone(),
|
||||
Xcm(vec![SubscribeVersion { query_id: 1, max_response_weight: Weight::zero() }]),
|
||||
)]
|
||||
);
|
||||
@@ -915,16 +948,22 @@ fn auto_subscription_works() {
|
||||
querier: None,
|
||||
},
|
||||
]);
|
||||
let hash = fake_message_hash(&message);
|
||||
let r = XcmExecutor::<XcmConfig>::execute_xcm(remote_v2, message, hash, weight);
|
||||
assert_eq!(r, Outcome::Complete(weight));
|
||||
let mut hash = fake_message_hash(&message);
|
||||
let r = XcmExecutor::<XcmConfig>::prepare_and_execute(
|
||||
remote_v2.clone(),
|
||||
message,
|
||||
&mut hash,
|
||||
weight,
|
||||
Weight::zero(),
|
||||
);
|
||||
assert_eq!(r, Outcome::Complete { used: weight });
|
||||
|
||||
// v3 messages cannot be sent to remote_v2...
|
||||
// v4 messages cannot be sent to remote_v2...
|
||||
assert_eq!(
|
||||
XcmPallet::wrap_version(&remote_v2, msg_v2.clone()),
|
||||
Ok(VersionedXcm::V2(msg_v2))
|
||||
);
|
||||
assert_eq!(XcmPallet::wrap_version(&remote_v2, msg_v3.clone()), Err(()));
|
||||
assert_eq!(XcmPallet::wrap_version(&remote_v2, msg_v4.clone()), Err(()));
|
||||
})
|
||||
}
|
||||
|
||||
@@ -934,9 +973,9 @@ fn subscription_side_upgrades_work_with_multistage_notify() {
|
||||
AdvertisedXcmVersion::set(1);
|
||||
|
||||
// An entry from a previous runtime with v0 XCM.
|
||||
let v2_location = VersionedMultiLocation::V2(xcm::v2::Junction::Parachain(1001).into());
|
||||
let v2_location = VersionedLocation::V2(xcm::v2::Junction::Parachain(1001).into());
|
||||
VersionNotifyTargets::<Test>::insert(1, v2_location, (70, Weight::zero(), 1));
|
||||
let v2_location = VersionedMultiLocation::V2(xcm::v2::Junction::Parachain(1002).into());
|
||||
let v2_location = VersionedLocation::V2(xcm::v2::Junction::Parachain(1002).into());
|
||||
VersionNotifyTargets::<Test>::insert(2, v2_location, (71, Weight::zero(), 1));
|
||||
let v3_location = Parachain(1003).into_versioned();
|
||||
VersionNotifyTargets::<Test>::insert(3, v3_location, (72, Weight::zero(), 1));
|
||||
@@ -1003,9 +1042,9 @@ fn subscription_side_upgrades_work_with_multistage_notify() {
|
||||
#[test]
|
||||
fn get_and_wrap_version_works() {
|
||||
new_test_ext_with_balances_and_xcm_version(vec![], None).execute_with(|| {
|
||||
let remote_a: MultiLocation = Parachain(1000).into();
|
||||
let remote_b: MultiLocation = Parachain(1001).into();
|
||||
let remote_c: MultiLocation = Parachain(1002).into();
|
||||
let remote_a: Location = Parachain(1000).into();
|
||||
let remote_b: Location = Parachain(1001).into();
|
||||
let remote_c: Location = Parachain(1002).into();
|
||||
|
||||
// no `safe_xcm_version` version at `GenesisConfig`
|
||||
assert_eq!(XcmPallet::get_version_for(&remote_a), None);
|
||||
@@ -1023,7 +1062,7 @@ fn get_and_wrap_version_works() {
|
||||
// set XCM version only for `remote_a`
|
||||
assert_ok!(XcmPallet::force_xcm_version(
|
||||
RuntimeOrigin::root(),
|
||||
Box::new(remote_a),
|
||||
Box::new(remote_a.clone()),
|
||||
XCM_VERSION
|
||||
));
|
||||
assert_eq!(XcmPallet::get_version_for(&remote_a), Some(XCM_VERSION));
|
||||
@@ -1041,7 +1080,10 @@ fn get_and_wrap_version_works() {
|
||||
// does not work because remote_b has unknown version and default is set to 1, and
|
||||
// `XCM_VERSION` cannot be wrapped to the `1`
|
||||
assert_eq!(XcmPallet::wrap_version(&remote_b, xcm.clone()), Err(()));
|
||||
assert_eq!(VersionDiscoveryQueue::<Test>::get().into_inner(), vec![(remote_b.into(), 1)]);
|
||||
assert_eq!(
|
||||
VersionDiscoveryQueue::<Test>::get().into_inner(),
|
||||
vec![(remote_b.clone().into(), 1)]
|
||||
);
|
||||
|
||||
// set default to the `XCM_VERSION`
|
||||
assert_ok!(XcmPallet::force_default_xcm_version(RuntimeOrigin::root(), Some(XCM_VERSION)));
|
||||
@@ -1053,10 +1095,17 @@ fn get_and_wrap_version_works() {
|
||||
XcmPallet::wrap_version(&remote_b, xcm.clone()),
|
||||
Ok(VersionedXcm::from(xcm.clone()))
|
||||
);
|
||||
assert_eq!(VersionDiscoveryQueue::<Test>::get().into_inner(), vec![(remote_b.into(), 2)]);
|
||||
assert_eq!(
|
||||
VersionDiscoveryQueue::<Test>::get().into_inner(),
|
||||
vec![(remote_b.clone().into(), 2)]
|
||||
);
|
||||
|
||||
// change remote_c to `1`
|
||||
assert_ok!(XcmPallet::force_xcm_version(RuntimeOrigin::root(), Box::new(remote_c), 1));
|
||||
assert_ok!(XcmPallet::force_xcm_version(
|
||||
RuntimeOrigin::root(),
|
||||
Box::new(remote_c.clone()),
|
||||
1
|
||||
));
|
||||
|
||||
// does not work because remote_c has `1` and default is `XCM_VERSION` which cannot be
|
||||
// wrapped to the `1`
|
||||
|
||||
Reference in New Issue
Block a user