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:
Branislav Kontur
2023-08-01 14:14:34 +02:00
committed by GitHub
parent a15f573e7d
commit a4ae46b743
5 changed files with 313 additions and 296 deletions
+7 -5
View File
@@ -146,8 +146,9 @@ impl<
&mut self,
weight: Weight,
payment: xcm_executor::Assets,
context: &XcmContext,
) -> 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
if self.0.is_some() {
@@ -196,8 +197,8 @@ impl<
Ok(unused)
}
fn refund_weight(&mut self, weight: Weight) -> Option<MultiAsset> {
log::trace!(target: "xcm::weight", "TakeFirstAssetTrader::refund_weight weight: {:?}", weight);
fn refund_weight(&mut self, weight: Weight, context: &XcmContext) -> Option<MultiAsset> {
log::trace!(target: "xcm::weight", "TakeFirstAssetTrader::refund_weight weight: {:?}, context: {:?}", weight, context);
if let Some(AssetTraderRefunder {
mut weight_outstanding,
outstanding_concrete_asset: MultiAsset { id, fun },
@@ -526,6 +527,7 @@ mod tests {
FeeChargerAssetsHandleRefund,
>;
let mut trader = <Trader as WeightTrader>::new();
let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None };
// prepare test data
let asset: MultiAsset = (Here, AMOUNT).into();
@@ -533,9 +535,9 @@ mod tests {
let weight_to_buy = Weight::from_parts(1_000, 1_000);
// 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)
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));
}
}