Update polkadot with one more commit: from 54bcee1d5615f53781d5172fcce6700dbf35dad2 -> 3dd8331414c92f5d01d6a470eae43049099d7aa9 (#2266)

* Update polkadot with one commit: from 54bcee1d5615f53781d5172fcce6700dbf35dad2 -> 3dd8331414c92f5d01d6a470eae43049099d7aa9

* Fix test

* Fix test better

* typo
This commit is contained in:
Branislav Kontur
2023-03-03 10:02:49 +01:00
committed by GitHub
parent 3249186fe6
commit 1de575dc25
5 changed files with 213 additions and 69 deletions
+141
View File
@@ -315,6 +315,13 @@ pub trait ChargeWeightInFungibles<AccountId, Assets: fungibles::Inspect<AccountI
mod tests {
use super::*;
use cumulus_primitives_core::UpwardMessage;
use frame_support::{
assert_ok,
dispatch::DispatchResult,
traits::tokens::{DepositConsequence, WithdrawConsequence},
};
use sp_runtime::DispatchError;
use xcm_executor::{traits::Error, Assets};
/// Validates [`validate`] for required Some(destination) and Some(message)
struct OkFixedXcmHashWithAssertingRequiredInputsSender;
@@ -410,4 +417,138 @@ mod tests {
)>(dest.into(), message)
);
}
#[test]
fn take_first_asset_trader_buy_weight_called_twice_throws_error() {
const AMOUNT: u128 = 100;
// prepare prerequisites to instantiate `TakeFirstAssetTrader`
type TestAccountId = u32;
type TestAssetId = u32;
type TestBalance = u128;
struct TestAssets;
impl MatchesFungibles<TestAssetId, TestBalance> for TestAssets {
fn matches_fungibles(a: &MultiAsset) -> Result<(TestAssetId, TestBalance), Error> {
match a {
MultiAsset { fun: Fungible(amount), id: Concrete(_id) } => Ok((1, *amount)),
_ => Err(Error::AssetNotHandled),
}
}
}
impl fungibles::Inspect<TestAccountId> for TestAssets {
type AssetId = TestAssetId;
type Balance = TestBalance;
fn total_issuance(_: Self::AssetId) -> Self::Balance {
todo!()
}
fn minimum_balance(_: Self::AssetId) -> Self::Balance {
0
}
fn balance(_: Self::AssetId, _: &TestAccountId) -> Self::Balance {
todo!()
}
fn reducible_balance(_: Self::AssetId, _: &TestAccountId, _: bool) -> Self::Balance {
todo!()
}
fn can_deposit(
_: Self::AssetId,
_: &TestAccountId,
_: Self::Balance,
_: bool,
) -> DepositConsequence {
todo!()
}
fn can_withdraw(
_: Self::AssetId,
_: &TestAccountId,
_: Self::Balance,
) -> WithdrawConsequence<Self::Balance> {
todo!()
}
fn asset_exists(_: Self::AssetId) -> bool {
todo!()
}
}
impl fungibles::Mutate<TestAccountId> for TestAssets {
fn mint_into(_: Self::AssetId, _: &TestAccountId, _: Self::Balance) -> DispatchResult {
todo!()
}
fn burn_from(
_: Self::AssetId,
_: &TestAccountId,
_: Self::Balance,
) -> Result<Self::Balance, DispatchError> {
todo!()
}
}
impl fungibles::Transfer<TestAccountId> for TestAssets {
fn transfer(
_: Self::AssetId,
_: &TestAccountId,
_: &TestAccountId,
_: Self::Balance,
_: bool,
) -> Result<Self::Balance, DispatchError> {
todo!()
}
}
impl fungibles::Unbalanced<TestAccountId> for TestAssets {
fn set_balance(
_: Self::AssetId,
_: &TestAccountId,
_: Self::Balance,
) -> DispatchResult {
todo!()
}
fn set_total_issuance(_: Self::AssetId, _: Self::Balance) {
todo!()
}
}
struct FeeChargerAssetsHandleRefund;
impl ChargeWeightInFungibles<TestAccountId, TestAssets> for FeeChargerAssetsHandleRefund {
fn charge_weight_in_fungibles(
_: <TestAssets as Inspect<TestAccountId>>::AssetId,
_: Weight,
) -> Result<<TestAssets as Inspect<TestAccountId>>::Balance, XcmError> {
Ok(AMOUNT)
}
}
impl TakeRevenue for FeeChargerAssetsHandleRefund {
fn take_revenue(_: MultiAsset) {}
}
// create new instance
type Trader = TakeFirstAssetTrader<
TestAccountId,
FeeChargerAssetsHandleRefund,
TestAssets,
TestAssets,
FeeChargerAssetsHandleRefund,
>;
let mut trader = <Trader as WeightTrader>::new();
// prepare test data
let asset: MultiAsset = (Here, AMOUNT).into();
let payment = Assets::from(asset.clone());
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()));
// lets do second call (error)
assert_eq!(
trader.buy_weight(weight_to_buy, payment.clone()),
Err(XcmError::NotWithdrawable)
);
}
}