Skip to content

Commit

Permalink
Backport patch for xcm fungible benchmarks required by new FungibleAd…
Browse files Browse the repository at this point in the history
…apter for 1.6 (#3422)

More info here: #3417

Expected patch for  `pallet-xcm-benchmarks` as `7.0.4`
  • Loading branch information
bkontur authored Feb 21, 2024
1 parent 73368f0 commit 1c3b815
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions polkadot/xcm/pallet-xcm-benchmarks/src/fungible/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ benchmarks_instance_pallet! {
let dest_account = T::AccountIdConverter::convert_location(&dest_location).unwrap();

<AssetTransactorOf<T>>::deposit_asset(&asset, &sender_location, None).unwrap();
// We deposit the asset twice so we have enough for ED after transferring
<AssetTransactorOf<T>>::deposit_asset(&asset, &sender_location, None).unwrap();
let sender_account_balance_before = T::TransactAsset::balance(&sender_account);
assert!(T::TransactAsset::balance(&dest_account).is_zero());

let mut executor = new_executor::<T>(sender_location);
Expand All @@ -79,7 +82,7 @@ benchmarks_instance_pallet! {
}: {
executor.bench_process(xcm)?;
} verify {
assert!(T::TransactAsset::balance(&sender_account).is_zero());
assert!(T::TransactAsset::balance(&sender_account) < sender_account_balance_before);
assert!(!T::TransactAsset::balance(&dest_account).is_zero());
}

Expand All @@ -93,12 +96,13 @@ benchmarks_instance_pallet! {
&dest_location,
FeeReason::TransferReserveAsset
);
let sender_account_balance_before = T::TransactAsset::balance(&sender_account);

let asset = T::get_multi_asset();
<AssetTransactorOf<T>>::deposit_asset(&asset, &sender_location, None).unwrap();
assert!(T::TransactAsset::balance(&sender_account) > sender_account_balance_before);
let assets: MultiAssets = vec![ asset ].into();
// We deposit the asset twice so we have enough for ED after transferring
<AssetTransactorOf<T>>::deposit_asset(&asset, &sender_location, None).unwrap();
let sender_account_balance_before = T::TransactAsset::balance(&sender_account);
let assets: MultiAssets = vec![asset].into();
assert!(T::TransactAsset::balance(&dest_account).is_zero());

let mut executor = new_executor::<T>(sender_location);
Expand Down
6 changes: 2 additions & 4 deletions polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ impl xcm_executor::traits::MatchesFungible<u64> for MatchAnyFungible {
}

// Use balances as the asset transactor.
#[allow(deprecated)]
pub type AssetTransactor = xcm_builder::CurrencyAdapter<
pub type AssetTransactor = xcm_builder::FungibleAdapter<
Balances,
MatchAnyFungible,
AccountIdConverter,
Expand Down Expand Up @@ -193,8 +192,7 @@ impl xcm_balances_benchmark::Config for Test {
type TrustedReserve = TrustedReserve;

fn get_multi_asset() -> MultiAsset {
let amount =
<Balances as frame_support::traits::fungible::Inspect<u64>>::minimum_balance() as u128;
let amount = 1_000_000_000_000;
MultiAsset { id: Concrete(Here.into()), fun: Fungible(amount) }
}
}
Expand Down

0 comments on commit 1c3b815

Please sign in to comment.