* MultiAsset TWO

* Draft next MultiAsset API.

* XCM core builds

* XCM Executor builds

* XCM Builder builds

* API changes making their way throughout

* Some TODOs

* Further build fixes

* Basic compile builds

* First test fixed

* All executor tests fixed

* Typo

* Optimize subsume_assets and add test

* Optimize checked_sub

* XCM Builder first test fixed

* Fix builder tests

* Fix doc test

* fix some doc tests

* spelling

* named fields for AllOf

* Update xcm/src/v0/multiasset.rs

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

* Update xcm/src/v0/multiasset.rs

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

* Update xcm/src/v0/multiasset.rs

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

* Update xcm/src/v0/multiasset.rs

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

* Reformat

* Move to XCM version 1

* Spelling

* warnings

* Replace some more v0->v1s

* warnings

* format

* Add max_assets param

* building

* test fixes

* tests

* another test

* final test

* tests

* Rename Null -> Here

* Introduce

* More ergonomics

* More ergonomics

* test fix

* test fixes

* docs

* BuyExecution includes

* Fix XCM extrinsics

* fmt

* Make Vec<MultiAsset>/MultiAssets conversions safe

* More MultiAssets conversion safety

* spelling

* fix doc test

* Apply suggestions from code review

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

* Apply suggestions from code review

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

* fmt

* Add v0, remove VersionedMultiAsset

* Remove VersionedMultiLocation

* Update xcm/src/v1/order.rs

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

* Update xcm/src/v1/mod.rs

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

* XCM v0 backwards compatibility

* Full compatibility

* fmt

* Update xcm/pallet-xcm/src/lib.rs

* Update xcm/src/v0/order.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* Tweaks to versioning system

* Fixes

* fmt

* Update xcm/xcm-executor/src/assets.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* Update xcm/xcm-executor/src/assets.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* Grumbles

* Update xcm/src/v1/multiasset.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* fmt

* Update xcm/src/v1/multiasset.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* Update xcm/src/v1/multiasset.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* Fixes

* Formatting

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
Co-authored-by: Amar Singh <asinghchrony@protonmail.com>
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Gavin Wood
2021-08-06 18:25:01 +02:00
committed by GitHub
parent d86bb658a0
commit ce80bc2d4c
49 changed files with 3475 additions and 1242 deletions
+78 -61
View File
@@ -15,16 +15,14 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
use super::{mock::*, *};
use xcm::v0::{ExecuteXcm, NetworkId::Any, Order, Outcome, Response};
use xcm::latest::prelude::*;
use xcm_executor::{traits::*, Config, XcmExecutor};
use MultiAsset::*;
use Option::None;
#[test]
fn basic_setup_works() {
add_reserve(X1(Parent), AllConcreteFungible { id: X1(Parent) });
add_reserve(X1(Parent), Wild((X1(Parent), WildFungible).into()));
assert!(<TestConfig as Config>::IsReserve::filter_asset_location(
&ConcreteFungible { id: X1(Parent), amount: 100 },
&(X1(Parent), 100).into(),
&X1(Parent),
));
@@ -34,22 +32,23 @@ fn basic_setup_works() {
assert_eq!(to_account(X2(Parent, Parachain(50))), Ok(2050));
assert_eq!(to_account(X1(AccountIndex64 { index: 1, network: Any })), Ok(1));
assert_eq!(to_account(X1(AccountIndex64 { index: 42, network: Any })), Ok(42));
assert_eq!(to_account(Null), Ok(3000));
assert_eq!(to_account(Here), Ok(3000));
}
#[test]
fn weigher_should_work() {
let mut message = opaque::Xcm::ReserveAssetDeposit {
assets: vec![ConcreteFungible { id: X1(Parent), amount: 100 }],
let mut message = opaque::Xcm::ReserveAssetDeposited {
assets: (X1(Parent), 100).into(),
effects: vec![
Order::BuyExecution {
fees: All,
fees: (X1(Parent), 1).into(),
weight: 0,
debt: 30,
halt_on_error: true,
xcm: vec![],
orders: vec![],
instructions: vec![],
},
Order::DepositAsset { assets: vec![All], dest: Null },
Order::DepositAsset { assets: All.into(), max_assets: 1, beneficiary: Here },
],
}
.into();
@@ -58,10 +57,8 @@ fn weigher_should_work() {
#[test]
fn take_weight_credit_barrier_should_work() {
let mut message = opaque::Xcm::TransferAsset {
assets: vec![ConcreteFungible { id: X1(Parent), amount: 100 }],
dest: Null,
};
let mut message =
opaque::Xcm::TransferAsset { assets: (X1(Parent), 100).into(), beneficiary: Here };
let mut weight_credit = 10;
let r =
@@ -77,10 +74,8 @@ fn take_weight_credit_barrier_should_work() {
#[test]
fn allow_unpaid_should_work() {
let mut message = opaque::Xcm::TransferAsset {
assets: vec![ConcreteFungible { id: X1(Parent), amount: 100 }],
dest: Null,
};
let mut message =
opaque::Xcm::TransferAsset { assets: (X1(Parent), 100).into(), beneficiary: Here };
AllowUnpaidFrom::set(vec![X1(Parent)]);
@@ -107,10 +102,8 @@ fn allow_unpaid_should_work() {
fn allow_paid_should_work() {
AllowPaidFrom::set(vec![X1(Parent)]);
let mut message = opaque::Xcm::TransferAsset {
assets: vec![ConcreteFungible { id: X1(Parent), amount: 100 }],
dest: Null,
};
let mut message =
opaque::Xcm::TransferAsset { assets: (X1(Parent), 100).into(), beneficiary: Here };
let r = AllowTopLevelPaidExecutionFrom::<IsInVec<AllowPaidFrom>>::should_execute(
&X1(Parachain(1)),
@@ -121,17 +114,19 @@ fn allow_paid_should_work() {
);
assert_eq!(r, Err(()));
let mut underpaying_message = opaque::Xcm::ReserveAssetDeposit {
assets: vec![ConcreteFungible { id: X1(Parent), amount: 100 }],
let fees = (X1(Parent), 1).into();
let mut underpaying_message = opaque::Xcm::ReserveAssetDeposited {
assets: (X1(Parent), 100).into(),
effects: vec![
Order::BuyExecution {
fees: All,
fees,
weight: 0,
debt: 20,
halt_on_error: true,
xcm: vec![],
orders: vec![],
instructions: vec![],
},
Order::DepositAsset { assets: vec![All], dest: Null },
Order::DepositAsset { assets: All.into(), max_assets: 1, beneficiary: Here },
],
};
@@ -144,17 +139,19 @@ fn allow_paid_should_work() {
);
assert_eq!(r, Err(()));
let mut paying_message = opaque::Xcm::ReserveAssetDeposit {
assets: vec![ConcreteFungible { id: X1(Parent), amount: 100 }],
let fees = (X1(Parent), 1).into();
let mut paying_message = opaque::Xcm::ReserveAssetDeposited {
assets: (X1(Parent), 100).into(),
effects: vec![
Order::BuyExecution {
fees: All,
fees,
weight: 0,
debt: 30,
halt_on_error: true,
xcm: vec![],
orders: vec![],
instructions: vec![],
},
Order::DepositAsset { assets: vec![All], dest: Null },
Order::DepositAsset { assets: All.into(), max_assets: 1, beneficiary: Here },
],
};
@@ -180,27 +177,33 @@ fn allow_paid_should_work() {
#[test]
fn paying_reserve_deposit_should_work() {
AllowPaidFrom::set(vec![X1(Parent)]);
add_reserve(X1(Parent), AllConcreteFungible { id: X1(Parent) });
WeightPrice::set((X1(Parent), 1_000_000_000_000));
add_reserve(X1(Parent), (Parent, WildFungible).into());
WeightPrice::set((Parent.into(), 1_000_000_000_000));
let origin = X1(Parent);
let message = Xcm::<TestCall>::ReserveAssetDeposit {
assets: vec![ConcreteFungible { id: X1(Parent), amount: 100 }],
let fees = (X1(Parent), 30).into();
let message = Xcm::<TestCall>::ReserveAssetDeposited {
assets: (X1(Parent), 100).into(),
effects: vec![
Order::<TestCall>::BuyExecution {
fees: All,
fees,
weight: 0,
debt: 30,
halt_on_error: true,
xcm: vec![],
orders: vec![],
instructions: vec![],
},
Order::<TestCall>::DepositAsset {
assets: All.into(),
max_assets: 1,
beneficiary: Here,
},
Order::<TestCall>::DepositAsset { assets: vec![All], dest: Null },
],
};
let weight_limit = 50;
let r = XcmExecutor::<TestConfig>::execute_xcm(origin, message, weight_limit);
assert_eq!(r, Outcome::Complete(30));
assert_eq!(assets(3000), vec![ConcreteFungible { id: X1(Parent), amount: 70 }]);
assert_eq!(assets(3000), vec![(X1(Parent), 70).into()]);
}
#[test]
@@ -208,19 +211,19 @@ fn transfer_should_work() {
// we'll let them have message execution for free.
AllowUnpaidFrom::set(vec![X1(Parachain(1))]);
// Child parachain #1 owns 1000 tokens held by us in reserve.
add_asset(1001, ConcreteFungible { id: Null, amount: 1000 });
add_asset(1001, (Here, 1000).into());
// They want to transfer 100 of them to their sibling parachain #2
let r = XcmExecutor::<TestConfig>::execute_xcm(
X1(Parachain(1)),
Xcm::TransferAsset {
assets: vec![ConcreteFungible { id: Null, amount: 100 }],
dest: X1(AccountIndex64 { index: 3, network: Any }),
assets: (Here, 100).into(),
beneficiary: X1(AccountIndex64 { index: 3, network: Any }),
},
50,
);
assert_eq!(r, Outcome::Complete(10));
assert_eq!(assets(3), vec![ConcreteFungible { id: Null, amount: 100 }]);
assert_eq!(assets(1001), vec![ConcreteFungible { id: Null, amount: 900 }]);
assert_eq!(assets(3), vec![(Here, 100).into()]);
assert_eq!(assets(1001), vec![(Here, 900).into()]);
assert_eq!(sent_xcm(), vec![]);
}
@@ -228,7 +231,7 @@ fn transfer_should_work() {
fn reserve_transfer_should_work() {
AllowUnpaidFrom::set(vec![X1(Parachain(1))]);
// Child parachain #1 owns 1000 tokens held by us in reserve.
add_asset(1001, ConcreteFungible { id: Null, amount: 1000 });
add_asset(1001, (Here, 1000).into());
// The remote account owned by gav.
let three = X1(AccountIndex64 { index: 3, network: Any });
@@ -237,22 +240,30 @@ fn reserve_transfer_should_work() {
let r = XcmExecutor::<TestConfig>::execute_xcm(
X1(Parachain(1)),
Xcm::TransferReserveAsset {
assets: vec![ConcreteFungible { id: Null, amount: 100 }],
assets: (Here, 100).into(),
dest: X1(Parachain(2)),
effects: vec![Order::DepositAsset { assets: vec![All], dest: three.clone() }],
effects: vec![Order::DepositAsset {
assets: All.into(),
max_assets: 1,
beneficiary: three.clone(),
}],
},
50,
);
assert_eq!(r, Outcome::Complete(10));
assert_eq!(assets(1002), vec![ConcreteFungible { id: Null, amount: 100 }]);
assert_eq!(assets(1002), vec![(Here, 100).into()]);
assert_eq!(
sent_xcm(),
vec![(
X1(Parachain(2)),
Xcm::ReserveAssetDeposit {
assets: vec![ConcreteFungible { id: X1(Parent), amount: 100 }],
effects: vec![Order::DepositAsset { assets: vec![All], dest: three }],
Xcm::ReserveAssetDeposited {
assets: (X1(Parent), 100).into(),
effects: vec![Order::DepositAsset {
assets: All.into(),
max_assets: 1,
beneficiary: three
}],
}
)]
);
@@ -307,32 +318,38 @@ fn transacting_should_refund_weight() {
fn paid_transacting_should_refund_payment_for_unused_weight() {
let one = X1(AccountIndex64 { index: 1, network: Any });
AllowPaidFrom::set(vec![one.clone()]);
add_asset(1, ConcreteFungible { id: X1(Parent), amount: 100 });
WeightPrice::set((X1(Parent), 1_000_000_000_000));
add_asset(1, (Parent, 100).into());
WeightPrice::set((Parent.into(), 1_000_000_000_000));
let origin = one.clone();
let fees = (X1(Parent), 100).into();
let message = Xcm::<TestCall>::WithdrawAsset {
assets: vec![ConcreteFungible { id: X1(Parent), amount: 100 }], // enough for 100 units of weight.
assets: (X1(Parent), 100).into(), // enough for 100 units of weight.
effects: vec![
Order::<TestCall>::BuyExecution {
fees: All,
fees,
weight: 70,
debt: 30,
halt_on_error: true,
xcm: vec![Xcm::<TestCall>::Transact {
orders: vec![],
instructions: vec![Xcm::<TestCall>::Transact {
origin_type: OriginKind::Native,
require_weight_at_most: 60,
// call estimated at 70 but only takes 10.
call: TestCall::Any(60, Some(10)).encode().into(),
}],
},
Order::<TestCall>::DepositAsset { assets: vec![All], dest: one.clone() },
Order::<TestCall>::DepositAsset {
assets: All.into(),
max_assets: 1,
beneficiary: one.clone(),
},
],
};
let weight_limit = 100;
let r = XcmExecutor::<TestConfig>::execute_xcm(origin, message, weight_limit);
assert_eq!(r, Outcome::Complete(50));
assert_eq!(assets(1), vec![ConcreteFungible { id: X1(Parent), amount: 50 }]);
assert_eq!(assets(1), vec![(X1(Parent), 50).into()]);
}
#[test]
@@ -342,7 +359,7 @@ fn prepaid_result_of_query_should_get_free_execution() {
// We put this in manually here, but normally this would be done at the point of crafting the message.
expect_response(query_id, origin.clone());
let the_response = Response::Assets(vec![ConcreteFungible { id: X1(Parent), amount: 100 }]);
let the_response = Response::Assets((X1(Parent), 100).into());
let message = Xcm::<TestCall>::QueryResponse { query_id, response: the_response.clone() };
let weight_limit = 10;