mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 21:01:02 +00:00
3a459e8fcf
* Fixes * Undiener * Undiener * Undiener * Lockfile * Changes for send returning hash * Include message ID as params to execute_xcm * Fixes * Fixes * Fixes * Fixes * Fixes * Fixes * Companion fixes * Formatting * Fixes * Formatting * Bump * Bump * Fixes * Formatting * Make the price of UMP/XCMP message sending configurable * cargo fmt * Remove InvertLocation * Formatting * Use ConstantPrice from polkadot-runtime-common * Fix naming * cargo fmt * Fixes * Fixes * Fixes * Add CallDispatcher * Fixes * Fixes * Fixes * Fixes * Fixes * Fixes * Fixes * Fixes * Fixes * Fixes * Fixes * Fixes * Fixes * Fixes * Fixes * Fixes * Fixes * Fixes * Fixes * Remove unused import * Remove unused import * XCMv3 fixes (#1710) * Fixes XCMv3 related Fixes XCMv3 (removed query_holding) Fixes XCMv3 - should use _depositable_count? Fixes XCMv3 - removed TrustedReserve Fixes - missing weights for statemine/statemint/westmint [DO-NOT-CHERRY-PICK] tmp return query_holding to aviod conficts to master Fixes - missing functions for pallet_xcm_benchmarks::generic::Config Fixes for XCMv3 benchmarking Fix xcm - removed query_holding * ".git/.scripts/bench-bot.sh" xcm statemine assets pallet_xcm_benchmarks::generic * ".git/.scripts/bench-bot.sh" xcm statemint assets pallet_xcm_benchmarks::generic * ".git/.scripts/bench-bot.sh" xcm westmint assets pallet_xcm_benchmarks::generic * Fix imports * Avoid consuming XCM message for NotApplicable scenario (#1787) * Avoid consuming message for NotApplicable scenario * Avoid consuming message for NotApplicable scenario tests * Add 10 message processing limit to DMP queue * Add 10 message limit to XCMP queue * Always increment the message_processed count whenever a message is processed * Fix formatting * Set an upper limit to the overweight message DMP queue * Add upper limit to XCMP overweight message queue * Fix for missing weight for `fn unpaid_execution()` * Fix - usage of `messages_processed` * Fixes * Fixes * Fixes * cargo fmt * Fixes * Fixes * Fixes * Fixes * Remove unused import * Fixes for gav-xcm-v3 (#1835) * Fix for FungiblesAdapter - trait changes: Contains -> AssetChecking * Fix for missing weight for `fn unpaid_execution()` * Used NonLocalMint for all NonZeroIssuance * Fix * Fixes * Fixes * Fixes * Fixes * Fixes * Fix tests * Fixes * Add SafeCallFilter * Add missing config items * Add TODO * Use () as the PriceForParentDelivery * Fixes * Fixes * Fixes * Fixes * Update transact_origin to transact_origin_and_runtime_call * Add ReachableDest config item to XCM pallet * Update SafeCallFilter to allow remark_with_event in runtime benchmarks * cargo fmt * Update substrate * Fix worst_case_holding * Fix DMQ queue unit tests * Remove unused label * cargo fmt * Actually process incoming XCMs * Fixes * Fixes * Fixes * Fixes - return back Weightless * Added measured benchmarks for `pallet_xcm` (#1968) * Fix Fix Fix * Fix * Fixes for transact benchmark * Fixes add pallet_xcm to benchmarks * Revert remark_with_event * ".git/.scripts/bench-bot.sh" xcm statemine assets pallet_xcm_benchmarks::generic * Fixes * TMP * Fix for reserve_asset_deposited * ".git/.scripts/bench-bot.sh" pallet statemine assets pallet_xcm * Fix * ".git/.scripts/bench-bot.sh" pallet statemint assets pallet_xcm * Fix * ".git/.scripts/bench-bot.sh" pallet westmint assets pallet_xcm * Fix westmint * ".git/.scripts/bench-bot.sh" xcm statemine assets pallet_xcm_benchmarks::generic * Fix * ".git/.scripts/bench-bot.sh" xcm westmint assets pallet_xcm_benchmarks::generic * ".git/.scripts/bench-bot.sh" xcm statemint assets pallet_xcm_benchmarks::generic * ".git/.scripts/bench-bot.sh" pallet collectives-polkadot collectives pallet_xcm * Fix for collectives * ".git/.scripts/bench-bot.sh" pallet bridge-hub-kusama bridge-hubs pallet_xcm * ".git/.scripts/bench-bot.sh" pallet bridge-hub-rococo bridge-hubs pallet_xcm * Fixes for bridge-hubs * Fixes - return back Weightless * Fix - removed MigrateToTrackInactive for contracts-rococo Co-authored-by: command-bot <> * cargo fmt * Fix benchmarks * Bko gav xcm v3 (#1993) * Fix * ".git/.scripts/bench-bot.sh" xcm statemint assets pallet_xcm_benchmarks::fungible * ".git/.scripts/bench-bot.sh" xcm statemine assets pallet_xcm_benchmarks::fungible * ".git/.scripts/bench-bot.sh" xcm westmint assets pallet_xcm_benchmarks::fungible * ".git/.scripts/bench-bot.sh" xcm statemine assets pallet_xcm_benchmarks::generic * ".git/.scripts/bench-bot.sh" xcm statemint assets pallet_xcm_benchmarks::generic * ".git/.scripts/bench-bot.sh" xcm westmint assets pallet_xcm_benchmarks::generic * ".git/.scripts/bench-bot.sh" pallet statemine assets pallet_xcm * ".git/.scripts/bench-bot.sh" pallet westmint assets pallet_xcm * ".git/.scripts/bench-bot.sh" pallet statemint assets pallet_xcm * ".git/.scripts/bench-bot.sh" pallet collectives-polkadot collectives pallet_xcm * ".git/.scripts/bench-bot.sh" pallet bridge-hub-kusama bridge-hubs pallet_xcm * ".git/.scripts/bench-bot.sh" pallet bridge-hub-rococo bridge-hubs pallet_xcm Co-authored-by: command-bot <> * Change AllowUnpaidExecutionFrom to be explicit * xcm-v3 benchmarks, weights, fixes for bridge-hubs (#2035) * Dumy weights to get compile * Change UniversalLocation according to https://github.com/paritytech/polkadot/pull/4097 (Location Inversion Removed) * Fix bridge-hubs weights * ".git/.scripts/bench-bot.sh" pallet statemine assets pallet_xcm * ".git/.scripts/bench-bot.sh" pallet statemint assets pallet_xcm * ".git/.scripts/bench-bot.sh" pallet collectives-polkadot collectives pallet_xcm * ".git/.scripts/bench-bot.sh" pallet westmint assets pallet_xcm * ".git/.scripts/bench-bot.sh" xcm bridge-hub-kusama bridge-hubs pallet_xcm_benchmarks::generic * ".git/.scripts/bench-bot.sh" xcm bridge-hub-kusama bridge-hubs pallet_xcm_benchmarks::fungible * ".git/.scripts/bench-bot.sh" pallet bridge-hub-kusama bridge-hubs pallet_xcm * ".git/.scripts/bench-bot.sh" pallet bridge-hub-rococo bridge-hubs pallet_xcm * ".git/.scripts/bench-bot.sh" xcm bridge-hub-rococo bridge-hubs pallet_xcm_benchmarks::fungible * ".git/.scripts/bench-bot.sh" xcm bridge-hub-rococo bridge-hubs pallet_xcm_benchmarks::generic * Change NetworkId to Option<NetworkId> Co-authored-by: command-bot <> Co-authored-by: Keith Yeung <kungfukeith11@gmail.com> * Add event for showing the hash of an UMP sent message (#1228) * Add UpwardMessageSent event in parachain-system * additional fixes * Message Id * Fix errors from merge * fmt * more fmt * Remove todo * more formatting * Fixes * Fixes * Fixes * Fixes * Allow explicit unpaid executions from the relay chains for system parachains (#2060) * Allow explicit unpaid executions from the relay chains for system parachains * Put origin-filtering barriers into WithComputedOrigin * Use ConstU32<8> * Small nits * formatting * cargo fmt * Allow receiving XCMs from any relay chain plurality * Fixes * update lockfile for {"polkadot", "substrate"} * Update polkadot * Add runtime-benchmarks feature Co-authored-by: Keith Yeung <kungfukeith11@gmail.com> Co-authored-by: Branislav Kontur <bkontur@gmail.com> Co-authored-by: girazoki <gorka.irazoki@gmail.com> Co-authored-by: parity-processbot <>
391 lines
12 KiB
Rust
391 lines
12 KiB
Rust
use asset_test_utils::{ExtBuilder, RuntimeHelper};
|
|
use cumulus_primitives_utility::ChargeWeightInFungibles;
|
|
use frame_support::{
|
|
assert_noop, assert_ok,
|
|
traits::PalletInfo,
|
|
weights::{Weight, WeightToFee as WeightToFeeT},
|
|
};
|
|
use parachains_common::{AccountId, AuraId};
|
|
use statemine_runtime::xcm_config::AssetFeeAsExistentialDepositMultiplierFeeCharger;
|
|
pub use statemine_runtime::{
|
|
constants::fee::WeightToFee, xcm_config::XcmConfig, Assets, Balances, ExistentialDeposit,
|
|
Runtime, SessionKeys, System,
|
|
};
|
|
use xcm::latest::prelude::*;
|
|
use xcm_executor::traits::WeightTrader;
|
|
|
|
pub const ALICE: [u8; 32] = [1u8; 32];
|
|
|
|
#[test]
|
|
fn test_asset_xcm_trader() {
|
|
ExtBuilder::<Runtime>::default()
|
|
.with_collators(vec![AccountId::from(ALICE)])
|
|
.with_session_keys(vec![(
|
|
AccountId::from(ALICE),
|
|
AccountId::from(ALICE),
|
|
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) },
|
|
)])
|
|
.build()
|
|
.execute_with(|| {
|
|
// We need root origin to create a sufficient asset
|
|
let minimum_asset_balance = 3333333_u128;
|
|
let local_asset_id = 1;
|
|
assert_ok!(Assets::force_create(
|
|
RuntimeHelper::<Runtime>::root_origin(),
|
|
local_asset_id.into(),
|
|
AccountId::from(ALICE).into(),
|
|
true,
|
|
minimum_asset_balance
|
|
));
|
|
|
|
// We first mint enough asset for the account to exist for assets
|
|
assert_ok!(Assets::mint(
|
|
RuntimeHelper::<Runtime>::origin_of(AccountId::from(ALICE)),
|
|
local_asset_id.into(),
|
|
AccountId::from(ALICE).into(),
|
|
minimum_asset_balance
|
|
));
|
|
|
|
// get asset id as multilocation
|
|
let asset_multilocation = MultiLocation::new(
|
|
0,
|
|
X2(
|
|
PalletInstance(
|
|
<Runtime as frame_system::Config>::PalletInfo::index::<Assets>().unwrap()
|
|
as u8,
|
|
),
|
|
GeneralIndex(local_asset_id.into()),
|
|
),
|
|
);
|
|
|
|
// Set Alice as block author, who will receive fees
|
|
RuntimeHelper::<Runtime>::run_to_block(2, Some(AccountId::from(ALICE)));
|
|
|
|
// We are going to buy 4e9 weight
|
|
let bought = Weight::from_ref_time(4_000_000_000u64);
|
|
|
|
// Lets calculate amount needed
|
|
let asset_amount_needed =
|
|
AssetFeeAsExistentialDepositMultiplierFeeCharger::charge_weight_in_fungibles(
|
|
local_asset_id,
|
|
bought,
|
|
)
|
|
.expect("failed to compute");
|
|
|
|
// Lets pay with: asset_amount_needed + asset_amount_extra
|
|
let asset_amount_extra = 100_u128;
|
|
let asset: MultiAsset =
|
|
(asset_multilocation.clone(), asset_amount_needed + asset_amount_extra).into();
|
|
|
|
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
|
|
|
// Lets buy_weight and make sure buy_weight does not return an error
|
|
match trader.buy_weight(bought, asset.into()) {
|
|
Ok(unused_assets) => {
|
|
// Check whether a correct amount of unused assets is returned
|
|
assert_ok!(unused_assets
|
|
.ensure_contains(&(asset_multilocation, asset_amount_extra).into()));
|
|
},
|
|
Err(e) => assert!(false, "Expected Ok(_). Got {:#?}", e),
|
|
}
|
|
|
|
// Drop trader
|
|
drop(trader);
|
|
|
|
// Make sure author(Alice) has received the amount
|
|
assert_eq!(
|
|
Assets::balance(1, AccountId::from(ALICE)),
|
|
minimum_asset_balance + asset_amount_needed
|
|
);
|
|
|
|
// We also need to ensure the total supply increased
|
|
assert_eq!(Assets::total_supply(1), minimum_asset_balance + asset_amount_needed);
|
|
});
|
|
}
|
|
|
|
#[test]
|
|
fn test_asset_xcm_trader_with_refund() {
|
|
ExtBuilder::<Runtime>::default()
|
|
.with_collators(vec![AccountId::from(ALICE)])
|
|
.with_session_keys(vec![(
|
|
AccountId::from(ALICE),
|
|
AccountId::from(ALICE),
|
|
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) },
|
|
)])
|
|
.build()
|
|
.execute_with(|| {
|
|
// We need root origin to create a sufficient asset
|
|
// We set existential deposit to be identical to the one for Balances first
|
|
assert_ok!(Assets::force_create(
|
|
RuntimeHelper::<Runtime>::root_origin(),
|
|
1.into(),
|
|
AccountId::from(ALICE).into(),
|
|
true,
|
|
ExistentialDeposit::get()
|
|
));
|
|
|
|
// We first mint enough asset for the account to exist for assets
|
|
assert_ok!(Assets::mint(
|
|
RuntimeHelper::<Runtime>::origin_of(AccountId::from(ALICE)),
|
|
1.into(),
|
|
AccountId::from(ALICE).into(),
|
|
ExistentialDeposit::get()
|
|
));
|
|
|
|
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
|
|
|
// Set Alice as block author, who will receive fees
|
|
RuntimeHelper::<Runtime>::run_to_block(2, Some(AccountId::from(ALICE)));
|
|
|
|
// We are going to buy 4e9 weight
|
|
let bought = Weight::from_ref_time(4_000_000_000u64);
|
|
|
|
let asset_multilocation = MultiLocation::new(
|
|
0,
|
|
X2(
|
|
PalletInstance(
|
|
<Runtime as frame_system::Config>::PalletInfo::index::<Assets>().unwrap()
|
|
as u8,
|
|
),
|
|
GeneralIndex(1),
|
|
),
|
|
);
|
|
|
|
// lets calculate amount needed
|
|
let amount_bought = WeightToFee::weight_to_fee(&bought);
|
|
|
|
let asset: MultiAsset = (asset_multilocation.clone(), amount_bought).into();
|
|
|
|
// Make sure buy_weight does not return an error
|
|
assert_ok!(trader.buy_weight(bought, asset.clone().into()));
|
|
|
|
// Make sure again buy_weight does return an error
|
|
assert_noop!(trader.buy_weight(bought, asset.into()), XcmError::NotWithdrawable);
|
|
|
|
// We actually use half of the weight
|
|
let weight_used = bought / 2;
|
|
|
|
// Make sure refurnd works.
|
|
let amount_refunded = WeightToFee::weight_to_fee(&(bought - weight_used));
|
|
|
|
assert_eq!(
|
|
trader.refund_weight(bought - weight_used),
|
|
Some((asset_multilocation, amount_refunded).into())
|
|
);
|
|
|
|
// Drop trader
|
|
drop(trader);
|
|
|
|
// We only should have paid for half of the bought weight
|
|
let fees_paid = WeightToFee::weight_to_fee(&weight_used);
|
|
|
|
assert_eq!(
|
|
Assets::balance(1, AccountId::from(ALICE)),
|
|
ExistentialDeposit::get() + fees_paid
|
|
);
|
|
|
|
// We also need to ensure the total supply increased
|
|
assert_eq!(Assets::total_supply(1), ExistentialDeposit::get() + fees_paid);
|
|
});
|
|
}
|
|
|
|
#[test]
|
|
fn test_asset_xcm_trader_refund_not_possible_since_amount_less_than_ed() {
|
|
ExtBuilder::<Runtime>::default()
|
|
.with_collators(vec![AccountId::from(ALICE)])
|
|
.with_session_keys(vec![(
|
|
AccountId::from(ALICE),
|
|
AccountId::from(ALICE),
|
|
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) },
|
|
)])
|
|
.build()
|
|
.execute_with(|| {
|
|
// We need root origin to create a sufficient asset
|
|
// We set existential deposit to be identical to the one for Balances first
|
|
assert_ok!(Assets::force_create(
|
|
RuntimeHelper::<Runtime>::root_origin(),
|
|
1.into(),
|
|
AccountId::from(ALICE).into(),
|
|
true,
|
|
ExistentialDeposit::get()
|
|
));
|
|
|
|
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
|
|
|
// Set Alice as block author, who will receive fees
|
|
RuntimeHelper::<Runtime>::run_to_block(2, Some(AccountId::from(ALICE)));
|
|
|
|
// We are going to buy small amount
|
|
let bought = Weight::from_ref_time(500_000_000u64);
|
|
|
|
let asset_multilocation = MultiLocation::new(
|
|
0,
|
|
X2(
|
|
PalletInstance(
|
|
<Runtime as frame_system::Config>::PalletInfo::index::<Assets>().unwrap()
|
|
as u8,
|
|
),
|
|
GeneralIndex(1),
|
|
),
|
|
);
|
|
|
|
let amount_bought = WeightToFee::weight_to_fee(&bought);
|
|
|
|
assert!(
|
|
amount_bought < ExistentialDeposit::get(),
|
|
"we are testing what happens when the amount does not exceed ED"
|
|
);
|
|
|
|
let asset: MultiAsset = (asset_multilocation.clone(), amount_bought).into();
|
|
|
|
// Buy weight should return an error
|
|
assert_noop!(trader.buy_weight(bought, asset.into()), XcmError::TooExpensive);
|
|
|
|
// not credited since the ED is higher than this value
|
|
assert_eq!(Assets::balance(1, AccountId::from(ALICE)), 0);
|
|
|
|
// We also need to ensure the total supply did not increase
|
|
assert_eq!(Assets::total_supply(1), 0);
|
|
});
|
|
}
|
|
|
|
#[test]
|
|
fn test_that_buying_ed_refund_does_not_refund() {
|
|
ExtBuilder::<Runtime>::default()
|
|
.with_collators(vec![AccountId::from(ALICE)])
|
|
.with_session_keys(vec![(
|
|
AccountId::from(ALICE),
|
|
AccountId::from(ALICE),
|
|
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) },
|
|
)])
|
|
.build()
|
|
.execute_with(|| {
|
|
// We need root origin to create a sufficient asset
|
|
// We set existential deposit to be identical to the one for Balances first
|
|
assert_ok!(Assets::force_create(
|
|
RuntimeHelper::<Runtime>::root_origin(),
|
|
1.into(),
|
|
AccountId::from(ALICE).into(),
|
|
true,
|
|
ExistentialDeposit::get()
|
|
));
|
|
|
|
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
|
|
|
// Set Alice as block author, who will receive fees
|
|
RuntimeHelper::<Runtime>::run_to_block(2, Some(AccountId::from(ALICE)));
|
|
|
|
// We are gonna buy ED
|
|
let bought = Weight::from_ref_time(ExistentialDeposit::get().try_into().unwrap());
|
|
|
|
let asset_multilocation = MultiLocation::new(
|
|
0,
|
|
X2(
|
|
PalletInstance(
|
|
<Runtime as frame_system::Config>::PalletInfo::index::<Assets>().unwrap()
|
|
as u8,
|
|
),
|
|
GeneralIndex(1),
|
|
),
|
|
);
|
|
|
|
let amount_bought = WeightToFee::weight_to_fee(&bought);
|
|
|
|
assert!(
|
|
amount_bought < ExistentialDeposit::get(),
|
|
"we are testing what happens when the amount does not exceed ED"
|
|
);
|
|
|
|
// 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
|
|
let asset: MultiAsset = (asset_multilocation.clone(), amount_bought).into();
|
|
assert_noop!(trader.buy_weight(bought, asset.into()), XcmError::TooExpensive);
|
|
|
|
// Now lets buy ED at least
|
|
let asset: MultiAsset = (asset_multilocation.clone(), ExistentialDeposit::get()).into();
|
|
|
|
// Buy weight should work
|
|
assert_ok!(trader.buy_weight(bought, asset.into()));
|
|
|
|
// Should return None. We have a specific check making sure we dont go below ED for
|
|
// drop payment
|
|
assert_eq!(trader.refund_weight(bought), None);
|
|
|
|
// Drop trader
|
|
drop(trader);
|
|
|
|
// Make sure author(Alice) has received the amount
|
|
assert_eq!(Assets::balance(1, AccountId::from(ALICE)), ExistentialDeposit::get());
|
|
|
|
// We also need to ensure the total supply increased
|
|
assert_eq!(Assets::total_supply(1), ExistentialDeposit::get());
|
|
});
|
|
}
|
|
|
|
#[test]
|
|
fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() {
|
|
ExtBuilder::<Runtime>::default()
|
|
.with_collators(vec![AccountId::from(ALICE)])
|
|
.with_session_keys(vec![(
|
|
AccountId::from(ALICE),
|
|
AccountId::from(ALICE),
|
|
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) },
|
|
)])
|
|
.build()
|
|
.execute_with(|| {
|
|
// Create a non-sufficient asset with specific existential deposit
|
|
let minimum_asset_balance = 1_000_000_u128;
|
|
assert_ok!(Assets::force_create(
|
|
RuntimeHelper::<Runtime>::root_origin(),
|
|
1.into(),
|
|
AccountId::from(ALICE).into(),
|
|
false,
|
|
minimum_asset_balance
|
|
));
|
|
|
|
// We first mint enough asset for the account to exist for assets
|
|
assert_ok!(Assets::mint(
|
|
RuntimeHelper::<Runtime>::origin_of(AccountId::from(ALICE)),
|
|
1.into(),
|
|
AccountId::from(ALICE).into(),
|
|
minimum_asset_balance
|
|
));
|
|
|
|
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
|
|
|
// Set Alice as block author, who will receive fees
|
|
RuntimeHelper::<Runtime>::run_to_block(2, Some(AccountId::from(ALICE)));
|
|
|
|
// We are going to buy 4e9 weight
|
|
let bought = Weight::from_ref_time(4_000_000_000u64);
|
|
|
|
// lets calculate amount needed
|
|
let asset_amount_needed = WeightToFee::weight_to_fee(&bought);
|
|
|
|
let asset_multilocation = MultiLocation::new(
|
|
0,
|
|
X2(
|
|
PalletInstance(
|
|
<Runtime as frame_system::Config>::PalletInfo::index::<Assets>().unwrap()
|
|
as u8,
|
|
),
|
|
GeneralIndex(1),
|
|
),
|
|
);
|
|
|
|
let asset: MultiAsset = (asset_multilocation, asset_amount_needed).into();
|
|
|
|
// Make sure again buy_weight does return an error
|
|
assert_noop!(trader.buy_weight(bought, asset.into()), XcmError::TooExpensive);
|
|
|
|
// Drop trader
|
|
drop(trader);
|
|
|
|
// Make sure author(Alice) has NOT received the amount
|
|
assert_eq!(Assets::balance(1, AccountId::from(ALICE)), minimum_asset_balance);
|
|
|
|
// We also need to ensure the total supply NOT increased
|
|
assert_eq!(Assets::total_supply(1), minimum_asset_balance);
|
|
});
|
|
}
|