mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 08:11:03 +00:00
Companion for Polkadot#7563 (#2956)
* `XcmContext` to `buy_weight / refund_weight`
* Fix tests
* Fix more tests
* update lockfile for {"substrate", "polkadot"}
---------
Co-authored-by: parity-processbot <>
This commit is contained in:
Generated
+264
-264
File diff suppressed because it is too large
Load Diff
@@ -108,9 +108,10 @@ fn test_asset_xcm_trader() {
|
|||||||
(asset_multilocation, asset_amount_needed + asset_amount_extra).into();
|
(asset_multilocation, asset_amount_needed + asset_amount_extra).into();
|
||||||
|
|
||||||
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
||||||
|
let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None };
|
||||||
|
|
||||||
// Lets buy_weight and make sure buy_weight does not return an error
|
// Lets buy_weight and make sure buy_weight does not return an error
|
||||||
let unused_assets = trader.buy_weight(bought, asset.into()).expect("Expected Ok");
|
let unused_assets = trader.buy_weight(bought, asset.into(), &ctx).expect("Expected Ok");
|
||||||
// Check whether a correct amount of unused assets is returned
|
// Check whether a correct amount of unused assets is returned
|
||||||
assert_ok!(
|
assert_ok!(
|
||||||
unused_assets.ensure_contains(&(asset_multilocation, asset_amount_extra).into())
|
unused_assets.ensure_contains(&(asset_multilocation, asset_amount_extra).into())
|
||||||
@@ -163,6 +164,7 @@ fn test_asset_xcm_trader_with_refund() {
|
|||||||
));
|
));
|
||||||
|
|
||||||
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
||||||
|
let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None };
|
||||||
|
|
||||||
// Set Alice as block author, who will receive fees
|
// Set Alice as block author, who will receive fees
|
||||||
RuntimeHelper::<Runtime>::run_to_block(2, Some(AccountId::from(ALICE)));
|
RuntimeHelper::<Runtime>::run_to_block(2, Some(AccountId::from(ALICE)));
|
||||||
@@ -178,11 +180,11 @@ fn test_asset_xcm_trader_with_refund() {
|
|||||||
let asset: MultiAsset = (asset_multilocation, amount_bought).into();
|
let asset: MultiAsset = (asset_multilocation, amount_bought).into();
|
||||||
|
|
||||||
// Make sure buy_weight does not return an error
|
// Make sure buy_weight does not return an error
|
||||||
assert_ok!(trader.buy_weight(bought, asset.clone().into()));
|
assert_ok!(trader.buy_weight(bought, asset.clone().into(), &ctx));
|
||||||
|
|
||||||
// Make sure again buy_weight does return an error
|
// Make sure again buy_weight does return an error
|
||||||
// This assert relies on the fact, that we use `TakeFirstAssetTrader` in `WeightTrader` tuple chain, which cannot be called twice
|
// This assert relies on the fact, that we use `TakeFirstAssetTrader` in `WeightTrader` tuple chain, which cannot be called twice
|
||||||
assert_noop!(trader.buy_weight(bought, asset.into()), XcmError::TooExpensive);
|
assert_noop!(trader.buy_weight(bought, asset.into(), &ctx), XcmError::TooExpensive);
|
||||||
|
|
||||||
// We actually use half of the weight
|
// We actually use half of the weight
|
||||||
let weight_used = bought / 2;
|
let weight_used = bought / 2;
|
||||||
@@ -191,7 +193,7 @@ fn test_asset_xcm_trader_with_refund() {
|
|||||||
let amount_refunded = WeightToFee::weight_to_fee(&(bought - weight_used));
|
let amount_refunded = WeightToFee::weight_to_fee(&(bought - weight_used));
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
trader.refund_weight(bought - weight_used),
|
trader.refund_weight(bought - weight_used, &ctx),
|
||||||
Some((asset_multilocation, amount_refunded).into())
|
Some((asset_multilocation, amount_refunded).into())
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -233,6 +235,7 @@ fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() {
|
|||||||
));
|
));
|
||||||
|
|
||||||
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
||||||
|
let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None };
|
||||||
|
|
||||||
// Set Alice as block author, who will receive fees
|
// Set Alice as block author, who will receive fees
|
||||||
RuntimeHelper::<Runtime>::run_to_block(2, Some(AccountId::from(ALICE)));
|
RuntimeHelper::<Runtime>::run_to_block(2, Some(AccountId::from(ALICE)));
|
||||||
@@ -252,7 +255,7 @@ fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() {
|
|||||||
let asset: MultiAsset = (asset_multilocation, amount_bought).into();
|
let asset: MultiAsset = (asset_multilocation, amount_bought).into();
|
||||||
|
|
||||||
// Buy weight should return an error
|
// Buy weight should return an error
|
||||||
assert_noop!(trader.buy_weight(bought, asset.into()), XcmError::TooExpensive);
|
assert_noop!(trader.buy_weight(bought, asset.into(), &ctx), XcmError::TooExpensive);
|
||||||
|
|
||||||
// not credited since the ED is higher than this value
|
// not credited since the ED is higher than this value
|
||||||
assert_eq!(Assets::balance(1, AccountId::from(ALICE)), 0);
|
assert_eq!(Assets::balance(1, AccountId::from(ALICE)), 0);
|
||||||
@@ -284,6 +287,7 @@ fn test_that_buying_ed_refund_does_not_refund() {
|
|||||||
));
|
));
|
||||||
|
|
||||||
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
||||||
|
let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None };
|
||||||
|
|
||||||
// Set Alice as block author, who will receive fees
|
// Set Alice as block author, who will receive fees
|
||||||
RuntimeHelper::<Runtime>::run_to_block(2, Some(AccountId::from(ALICE)));
|
RuntimeHelper::<Runtime>::run_to_block(2, Some(AccountId::from(ALICE)));
|
||||||
@@ -303,17 +307,17 @@ fn test_that_buying_ed_refund_does_not_refund() {
|
|||||||
// We know we will have to buy at least ED, so lets make sure first it will
|
// We know we will have to buy at least ED, so lets make sure first it will
|
||||||
// fail with a payment of less than ED
|
// fail with a payment of less than ED
|
||||||
let asset: MultiAsset = (asset_multilocation, amount_bought).into();
|
let asset: MultiAsset = (asset_multilocation, amount_bought).into();
|
||||||
assert_noop!(trader.buy_weight(bought, asset.into()), XcmError::TooExpensive);
|
assert_noop!(trader.buy_weight(bought, asset.into(), &ctx), XcmError::TooExpensive);
|
||||||
|
|
||||||
// Now lets buy ED at least
|
// Now lets buy ED at least
|
||||||
let asset: MultiAsset = (asset_multilocation, ExistentialDeposit::get()).into();
|
let asset: MultiAsset = (asset_multilocation, ExistentialDeposit::get()).into();
|
||||||
|
|
||||||
// Buy weight should work
|
// Buy weight should work
|
||||||
assert_ok!(trader.buy_weight(bought, asset.into()));
|
assert_ok!(trader.buy_weight(bought, asset.into(), &ctx));
|
||||||
|
|
||||||
// Should return None. We have a specific check making sure we dont go below ED for
|
// Should return None. We have a specific check making sure we dont go below ED for
|
||||||
// drop payment
|
// drop payment
|
||||||
assert_eq!(trader.refund_weight(bought), None);
|
assert_eq!(trader.refund_weight(bought, &ctx), None);
|
||||||
|
|
||||||
// Drop trader
|
// Drop trader
|
||||||
drop(trader);
|
drop(trader);
|
||||||
@@ -356,6 +360,7 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() {
|
|||||||
));
|
));
|
||||||
|
|
||||||
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
||||||
|
let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None };
|
||||||
|
|
||||||
// Set Alice as block author, who will receive fees
|
// Set Alice as block author, who will receive fees
|
||||||
RuntimeHelper::<Runtime>::run_to_block(2, Some(AccountId::from(ALICE)));
|
RuntimeHelper::<Runtime>::run_to_block(2, Some(AccountId::from(ALICE)));
|
||||||
@@ -371,7 +376,7 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() {
|
|||||||
let asset: MultiAsset = (asset_multilocation, asset_amount_needed).into();
|
let asset: MultiAsset = (asset_multilocation, asset_amount_needed).into();
|
||||||
|
|
||||||
// Make sure again buy_weight does return an error
|
// Make sure again buy_weight does return an error
|
||||||
assert_noop!(trader.buy_weight(bought, asset.into()), XcmError::TooExpensive);
|
assert_noop!(trader.buy_weight(bought, asset.into(), &ctx), XcmError::TooExpensive);
|
||||||
|
|
||||||
// Drop trader
|
// Drop trader
|
||||||
drop(trader);
|
drop(trader);
|
||||||
|
|||||||
@@ -112,9 +112,10 @@ fn test_asset_xcm_trader() {
|
|||||||
(asset_multilocation, asset_amount_needed + asset_amount_extra).into();
|
(asset_multilocation, asset_amount_needed + asset_amount_extra).into();
|
||||||
|
|
||||||
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
||||||
|
let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None };
|
||||||
|
|
||||||
// Lets buy_weight and make sure buy_weight does not return an error
|
// Lets buy_weight and make sure buy_weight does not return an error
|
||||||
let unused_assets = trader.buy_weight(bought, asset.into()).expect("Expected Ok");
|
let unused_assets = trader.buy_weight(bought, asset.into(), &ctx).expect("Expected Ok");
|
||||||
// Check whether a correct amount of unused assets is returned
|
// Check whether a correct amount of unused assets is returned
|
||||||
assert_ok!(
|
assert_ok!(
|
||||||
unused_assets.ensure_contains(&(asset_multilocation, asset_amount_extra).into())
|
unused_assets.ensure_contains(&(asset_multilocation, asset_amount_extra).into())
|
||||||
@@ -167,6 +168,7 @@ fn test_asset_xcm_trader_with_refund() {
|
|||||||
));
|
));
|
||||||
|
|
||||||
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
||||||
|
let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None };
|
||||||
|
|
||||||
// Set Alice as block author, who will receive fees
|
// Set Alice as block author, who will receive fees
|
||||||
RuntimeHelper::<Runtime>::run_to_block(2, Some(AccountId::from(ALICE)));
|
RuntimeHelper::<Runtime>::run_to_block(2, Some(AccountId::from(ALICE)));
|
||||||
@@ -185,11 +187,11 @@ fn test_asset_xcm_trader_with_refund() {
|
|||||||
let asset: MultiAsset = (asset_multilocation, amount_bought).into();
|
let asset: MultiAsset = (asset_multilocation, amount_bought).into();
|
||||||
|
|
||||||
// Make sure buy_weight does not return an error
|
// Make sure buy_weight does not return an error
|
||||||
assert_ok!(trader.buy_weight(bought, asset.clone().into()));
|
assert_ok!(trader.buy_weight(bought, asset.clone().into(), &ctx));
|
||||||
|
|
||||||
// Make sure again buy_weight does return an error
|
// Make sure again buy_weight does return an error
|
||||||
// This assert relies on the fact, that we use `TakeFirstAssetTrader` in `WeightTrader` tuple chain, which cannot be called twice
|
// This assert relies on the fact, that we use `TakeFirstAssetTrader` in `WeightTrader` tuple chain, which cannot be called twice
|
||||||
assert_noop!(trader.buy_weight(bought, asset.into()), XcmError::TooExpensive);
|
assert_noop!(trader.buy_weight(bought, asset.into(), &ctx), XcmError::TooExpensive);
|
||||||
|
|
||||||
// We actually use half of the weight
|
// We actually use half of the weight
|
||||||
let weight_used = bought / 2;
|
let weight_used = bought / 2;
|
||||||
@@ -198,7 +200,7 @@ fn test_asset_xcm_trader_with_refund() {
|
|||||||
let amount_refunded = WeightToFee::weight_to_fee(&(bought - weight_used));
|
let amount_refunded = WeightToFee::weight_to_fee(&(bought - weight_used));
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
trader.refund_weight(bought - weight_used),
|
trader.refund_weight(bought - weight_used, &ctx),
|
||||||
Some((asset_multilocation, amount_refunded).into())
|
Some((asset_multilocation, amount_refunded).into())
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -240,6 +242,7 @@ fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() {
|
|||||||
));
|
));
|
||||||
|
|
||||||
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
||||||
|
let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None };
|
||||||
|
|
||||||
// Set Alice as block author, who will receive fees
|
// Set Alice as block author, who will receive fees
|
||||||
RuntimeHelper::<Runtime>::run_to_block(2, Some(AccountId::from(ALICE)));
|
RuntimeHelper::<Runtime>::run_to_block(2, Some(AccountId::from(ALICE)));
|
||||||
@@ -262,7 +265,7 @@ fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() {
|
|||||||
let asset: MultiAsset = (asset_multilocation, amount_bought).into();
|
let asset: MultiAsset = (asset_multilocation, amount_bought).into();
|
||||||
|
|
||||||
// Buy weight should return an error
|
// Buy weight should return an error
|
||||||
assert_noop!(trader.buy_weight(bought, asset.into()), XcmError::TooExpensive);
|
assert_noop!(trader.buy_weight(bought, asset.into(), &ctx), XcmError::TooExpensive);
|
||||||
|
|
||||||
// not credited since the ED is higher than this value
|
// not credited since the ED is higher than this value
|
||||||
assert_eq!(Assets::balance(1, AccountId::from(ALICE)), 0);
|
assert_eq!(Assets::balance(1, AccountId::from(ALICE)), 0);
|
||||||
@@ -294,6 +297,7 @@ fn test_that_buying_ed_refund_does_not_refund() {
|
|||||||
));
|
));
|
||||||
|
|
||||||
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
||||||
|
let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None };
|
||||||
|
|
||||||
// Set Alice as block author, who will receive fees
|
// Set Alice as block author, who will receive fees
|
||||||
RuntimeHelper::<Runtime>::run_to_block(2, Some(AccountId::from(ALICE)));
|
RuntimeHelper::<Runtime>::run_to_block(2, Some(AccountId::from(ALICE)));
|
||||||
@@ -313,17 +317,17 @@ fn test_that_buying_ed_refund_does_not_refund() {
|
|||||||
// We know we will have to buy at least ED, so lets make sure first it will
|
// We know we will have to buy at least ED, so lets make sure first it will
|
||||||
// fail with a payment of less than ED
|
// fail with a payment of less than ED
|
||||||
let asset: MultiAsset = (asset_multilocation, amount_bought).into();
|
let asset: MultiAsset = (asset_multilocation, amount_bought).into();
|
||||||
assert_noop!(trader.buy_weight(bought, asset.into()), XcmError::TooExpensive);
|
assert_noop!(trader.buy_weight(bought, asset.into(), &ctx), XcmError::TooExpensive);
|
||||||
|
|
||||||
// Now lets buy ED at least
|
// Now lets buy ED at least
|
||||||
let asset: MultiAsset = (asset_multilocation, ExistentialDeposit::get()).into();
|
let asset: MultiAsset = (asset_multilocation, ExistentialDeposit::get()).into();
|
||||||
|
|
||||||
// Buy weight should work
|
// Buy weight should work
|
||||||
assert_ok!(trader.buy_weight(bought, asset.into()));
|
assert_ok!(trader.buy_weight(bought, asset.into(), &ctx));
|
||||||
|
|
||||||
// Should return None. We have a specific check making sure we dont go below ED for
|
// Should return None. We have a specific check making sure we dont go below ED for
|
||||||
// drop payment
|
// drop payment
|
||||||
assert_eq!(trader.refund_weight(bought), None);
|
assert_eq!(trader.refund_weight(bought, &ctx), None);
|
||||||
|
|
||||||
// Drop trader
|
// Drop trader
|
||||||
drop(trader);
|
drop(trader);
|
||||||
@@ -366,6 +370,7 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() {
|
|||||||
));
|
));
|
||||||
|
|
||||||
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
||||||
|
let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None };
|
||||||
|
|
||||||
// Set Alice as block author, who will receive fees
|
// Set Alice as block author, who will receive fees
|
||||||
RuntimeHelper::<Runtime>::run_to_block(2, Some(AccountId::from(ALICE)));
|
RuntimeHelper::<Runtime>::run_to_block(2, Some(AccountId::from(ALICE)));
|
||||||
@@ -384,7 +389,7 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() {
|
|||||||
let asset: MultiAsset = (asset_multilocation, asset_amount_needed).into();
|
let asset: MultiAsset = (asset_multilocation, asset_amount_needed).into();
|
||||||
|
|
||||||
// Make sure again buy_weight does return an error
|
// Make sure again buy_weight does return an error
|
||||||
assert_noop!(trader.buy_weight(bought, asset.into()), XcmError::TooExpensive);
|
assert_noop!(trader.buy_weight(bought, asset.into(), &ctx), XcmError::TooExpensive);
|
||||||
|
|
||||||
// Drop trader
|
// Drop trader
|
||||||
drop(trader);
|
drop(trader);
|
||||||
|
|||||||
@@ -119,9 +119,10 @@ fn test_asset_xcm_trader() {
|
|||||||
(asset_multilocation, asset_amount_needed + asset_amount_extra).into();
|
(asset_multilocation, asset_amount_needed + asset_amount_extra).into();
|
||||||
|
|
||||||
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
||||||
|
let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None };
|
||||||
|
|
||||||
// Lets buy_weight and make sure buy_weight does not return an error
|
// Lets buy_weight and make sure buy_weight does not return an error
|
||||||
let unused_assets = trader.buy_weight(bought, asset.into()).expect("Expected Ok");
|
let unused_assets = trader.buy_weight(bought, asset.into(), &ctx).expect("Expected Ok");
|
||||||
// Check whether a correct amount of unused assets is returned
|
// Check whether a correct amount of unused assets is returned
|
||||||
assert_ok!(
|
assert_ok!(
|
||||||
unused_assets.ensure_contains(&(asset_multilocation, asset_amount_extra).into())
|
unused_assets.ensure_contains(&(asset_multilocation, asset_amount_extra).into())
|
||||||
@@ -174,6 +175,7 @@ fn test_asset_xcm_trader_with_refund() {
|
|||||||
));
|
));
|
||||||
|
|
||||||
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
||||||
|
let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None };
|
||||||
|
|
||||||
// Set Alice as block author, who will receive fees
|
// Set Alice as block author, who will receive fees
|
||||||
RuntimeHelper::<Runtime>::run_to_block(2, Some(AccountId::from(ALICE)));
|
RuntimeHelper::<Runtime>::run_to_block(2, Some(AccountId::from(ALICE)));
|
||||||
@@ -188,11 +190,11 @@ fn test_asset_xcm_trader_with_refund() {
|
|||||||
let asset: MultiAsset = (asset_multilocation, amount_bought).into();
|
let asset: MultiAsset = (asset_multilocation, amount_bought).into();
|
||||||
|
|
||||||
// Make sure buy_weight does not return an error
|
// Make sure buy_weight does not return an error
|
||||||
assert_ok!(trader.buy_weight(bought, asset.clone().into()));
|
assert_ok!(trader.buy_weight(bought, asset.clone().into(), &ctx));
|
||||||
|
|
||||||
// Make sure again buy_weight does return an error
|
// Make sure again buy_weight does return an error
|
||||||
// This assert relies on the fact, that we use `TakeFirstAssetTrader` in `WeightTrader` tuple chain, which cannot be called twice
|
// This assert relies on the fact, that we use `TakeFirstAssetTrader` in `WeightTrader` tuple chain, which cannot be called twice
|
||||||
assert_noop!(trader.buy_weight(bought, asset.into()), XcmError::TooExpensive);
|
assert_noop!(trader.buy_weight(bought, asset.into(), &ctx), XcmError::TooExpensive);
|
||||||
|
|
||||||
// We actually use half of the weight
|
// We actually use half of the weight
|
||||||
let weight_used = bought / 2;
|
let weight_used = bought / 2;
|
||||||
@@ -201,7 +203,7 @@ fn test_asset_xcm_trader_with_refund() {
|
|||||||
let amount_refunded = WeightToFee::weight_to_fee(&(bought - weight_used));
|
let amount_refunded = WeightToFee::weight_to_fee(&(bought - weight_used));
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
trader.refund_weight(bought - weight_used),
|
trader.refund_weight(bought - weight_used, &ctx),
|
||||||
Some((asset_multilocation, amount_refunded).into())
|
Some((asset_multilocation, amount_refunded).into())
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -243,6 +245,7 @@ fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() {
|
|||||||
));
|
));
|
||||||
|
|
||||||
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
||||||
|
let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None };
|
||||||
|
|
||||||
// Set Alice as block author, who will receive fees
|
// Set Alice as block author, who will receive fees
|
||||||
RuntimeHelper::<Runtime>::run_to_block(2, Some(AccountId::from(ALICE)));
|
RuntimeHelper::<Runtime>::run_to_block(2, Some(AccountId::from(ALICE)));
|
||||||
@@ -262,7 +265,7 @@ fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() {
|
|||||||
let asset: MultiAsset = (asset_multilocation, amount_bought).into();
|
let asset: MultiAsset = (asset_multilocation, amount_bought).into();
|
||||||
|
|
||||||
// Buy weight should return an error
|
// Buy weight should return an error
|
||||||
assert_noop!(trader.buy_weight(bought, asset.into()), XcmError::TooExpensive);
|
assert_noop!(trader.buy_weight(bought, asset.into(), &ctx), XcmError::TooExpensive);
|
||||||
|
|
||||||
// not credited since the ED is higher than this value
|
// not credited since the ED is higher than this value
|
||||||
assert_eq!(Assets::balance(1, AccountId::from(ALICE)), 0);
|
assert_eq!(Assets::balance(1, AccountId::from(ALICE)), 0);
|
||||||
@@ -294,6 +297,7 @@ fn test_that_buying_ed_refund_does_not_refund() {
|
|||||||
));
|
));
|
||||||
|
|
||||||
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
||||||
|
let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None };
|
||||||
|
|
||||||
// Set Alice as block author, who will receive fees
|
// Set Alice as block author, who will receive fees
|
||||||
RuntimeHelper::<Runtime>::run_to_block(2, Some(AccountId::from(ALICE)));
|
RuntimeHelper::<Runtime>::run_to_block(2, Some(AccountId::from(ALICE)));
|
||||||
@@ -312,17 +316,17 @@ fn test_that_buying_ed_refund_does_not_refund() {
|
|||||||
// We know we will have to buy at least ED, so lets make sure first it will
|
// We know we will have to buy at least ED, so lets make sure first it will
|
||||||
// fail with a payment of less than ED
|
// fail with a payment of less than ED
|
||||||
let asset: MultiAsset = (asset_multilocation, amount_bought).into();
|
let asset: MultiAsset = (asset_multilocation, amount_bought).into();
|
||||||
assert_noop!(trader.buy_weight(bought, asset.into()), XcmError::TooExpensive);
|
assert_noop!(trader.buy_weight(bought, asset.into(), &ctx), XcmError::TooExpensive);
|
||||||
|
|
||||||
// Now lets buy ED at least
|
// Now lets buy ED at least
|
||||||
let asset: MultiAsset = (asset_multilocation, ExistentialDeposit::get()).into();
|
let asset: MultiAsset = (asset_multilocation, ExistentialDeposit::get()).into();
|
||||||
|
|
||||||
// Buy weight should work
|
// Buy weight should work
|
||||||
assert_ok!(trader.buy_weight(bought, asset.into()));
|
assert_ok!(trader.buy_weight(bought, asset.into(), &ctx));
|
||||||
|
|
||||||
// Should return None. We have a specific check making sure we dont go below ED for
|
// Should return None. We have a specific check making sure we dont go below ED for
|
||||||
// drop payment
|
// drop payment
|
||||||
assert_eq!(trader.refund_weight(bought), None);
|
assert_eq!(trader.refund_weight(bought, &ctx), None);
|
||||||
|
|
||||||
// Drop trader
|
// Drop trader
|
||||||
drop(trader);
|
drop(trader);
|
||||||
@@ -365,6 +369,7 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() {
|
|||||||
));
|
));
|
||||||
|
|
||||||
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
||||||
|
let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None };
|
||||||
|
|
||||||
// Set Alice as block author, who will receive fees
|
// Set Alice as block author, who will receive fees
|
||||||
RuntimeHelper::<Runtime>::run_to_block(2, Some(AccountId::from(ALICE)));
|
RuntimeHelper::<Runtime>::run_to_block(2, Some(AccountId::from(ALICE)));
|
||||||
@@ -380,7 +385,7 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() {
|
|||||||
let asset: MultiAsset = (asset_multilocation, asset_amount_needed).into();
|
let asset: MultiAsset = (asset_multilocation, asset_amount_needed).into();
|
||||||
|
|
||||||
// Make sure again buy_weight does return an error
|
// Make sure again buy_weight does return an error
|
||||||
assert_noop!(trader.buy_weight(bought, asset.into()), XcmError::TooExpensive);
|
assert_noop!(trader.buy_weight(bought, asset.into(), &ctx), XcmError::TooExpensive);
|
||||||
|
|
||||||
// Drop trader
|
// Drop trader
|
||||||
drop(trader);
|
drop(trader);
|
||||||
|
|||||||
@@ -146,8 +146,9 @@ impl<
|
|||||||
&mut self,
|
&mut self,
|
||||||
weight: Weight,
|
weight: Weight,
|
||||||
payment: xcm_executor::Assets,
|
payment: xcm_executor::Assets,
|
||||||
|
context: &XcmContext,
|
||||||
) -> Result<xcm_executor::Assets, XcmError> {
|
) -> Result<xcm_executor::Assets, XcmError> {
|
||||||
log::trace!(target: "xcm::weight", "TakeFirstAssetTrader::buy_weight weight: {:?}, payment: {:?}", weight, payment);
|
log::trace!(target: "xcm::weight", "TakeFirstAssetTrader::buy_weight weight: {:?}, payment: {:?}, context: {:?}", weight, payment, context);
|
||||||
|
|
||||||
// Make sure we dont enter twice
|
// Make sure we dont enter twice
|
||||||
if self.0.is_some() {
|
if self.0.is_some() {
|
||||||
@@ -196,8 +197,8 @@ impl<
|
|||||||
Ok(unused)
|
Ok(unused)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn refund_weight(&mut self, weight: Weight) -> Option<MultiAsset> {
|
fn refund_weight(&mut self, weight: Weight, context: &XcmContext) -> Option<MultiAsset> {
|
||||||
log::trace!(target: "xcm::weight", "TakeFirstAssetTrader::refund_weight weight: {:?}", weight);
|
log::trace!(target: "xcm::weight", "TakeFirstAssetTrader::refund_weight weight: {:?}, context: {:?}", weight, context);
|
||||||
if let Some(AssetTraderRefunder {
|
if let Some(AssetTraderRefunder {
|
||||||
mut weight_outstanding,
|
mut weight_outstanding,
|
||||||
outstanding_concrete_asset: MultiAsset { id, fun },
|
outstanding_concrete_asset: MultiAsset { id, fun },
|
||||||
@@ -526,6 +527,7 @@ mod tests {
|
|||||||
FeeChargerAssetsHandleRefund,
|
FeeChargerAssetsHandleRefund,
|
||||||
>;
|
>;
|
||||||
let mut trader = <Trader as WeightTrader>::new();
|
let mut trader = <Trader as WeightTrader>::new();
|
||||||
|
let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None };
|
||||||
|
|
||||||
// prepare test data
|
// prepare test data
|
||||||
let asset: MultiAsset = (Here, AMOUNT).into();
|
let asset: MultiAsset = (Here, AMOUNT).into();
|
||||||
@@ -533,9 +535,9 @@ mod tests {
|
|||||||
let weight_to_buy = Weight::from_parts(1_000, 1_000);
|
let weight_to_buy = Weight::from_parts(1_000, 1_000);
|
||||||
|
|
||||||
// lets do first call (success)
|
// lets do first call (success)
|
||||||
assert_ok!(trader.buy_weight(weight_to_buy, payment.clone()));
|
assert_ok!(trader.buy_weight(weight_to_buy, payment.clone(), &ctx));
|
||||||
|
|
||||||
// lets do second call (error)
|
// lets do second call (error)
|
||||||
assert_eq!(trader.buy_weight(weight_to_buy, payment), Err(XcmError::NotWithdrawable));
|
assert_eq!(trader.buy_weight(weight_to_buy, payment, &ctx), Err(XcmError::NotWithdrawable));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user