mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 14:01:02 +00:00
8f2a3a5077
* point to my branch * girazoki-add-TakeFirstAssetTrader-to-utility * Commit lock * point at custom branch * add new trader to statemine runtimes * compiles * Back to master * Update last tomls * Imports up * remove non-needing imports * FMT * log messages properly * Use TakeRevenue instead of HandleCredit * Introduce xcm fee handler * check total supply in tests * FMT * fix test * Start decoupling balance calculation into different traits * Make traits a bit more generic * PR suggestions * add import * import well * Place xcmfeesassethandler into parachains common * fix tests * config parameters * Min amount to fee receiver * Make minimum amount for block author to be at least the ED * Doc in AssetFeeAsExistentialDepositMultiplier * saturating sub * make sure we dont enter twice * FMT * fmt again * adapt tests * Add doc and struct for weight refund * Doc * More doc * PR suggestions * store all info related to asset payment as multiasset * return AssetNotFound instead of TooExpensive * Use asset transactor to deposit fee * uninstall from statemint * R for RUntime and CON for BalanceConverter * Rework logic to avoid unnecesary match and error * Rework ED check, also in case of refund * rework typo * In case refund makes drop below ED, just refund the difference * fix test westmint * clone id * move test imports to preamble * move test imports to preamble * test-utils with builderS * lock file updated * remove unused imports Co-authored-by: Stephen Shelton <steve@brewcraft.org> Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> Co-authored-by: joepetrowski <joe@parity.io>
72 lines
2.3 KiB
Rust
72 lines
2.3 KiB
Rust
use asset_test_utils::{ExtBuilder, RuntimeHelper};
|
|
use frame_support::{
|
|
assert_noop, assert_ok, traits::PalletInfo, weights::WeightToFee as WeightToFeeT,
|
|
};
|
|
use parachains_common::{AccountId, StatemintAuraId as AuraId};
|
|
pub use statemint_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_does_not_work_in_statemine() {
|
|
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::ed25519::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,
|
|
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 400e9 weight
|
|
// Because of the ED being higher in statemine
|
|
// and not to complicate things, we use a little
|
|
// bit more of weight
|
|
let bought = 400_000_000_000u64;
|
|
|
|
// lets calculate amount needed
|
|
let 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, amount_needed).into();
|
|
|
|
// Buy weight should return an error, since asset trader not installed
|
|
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);
|
|
});
|
|
}
|