mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-20 22:11:01 +00:00
This PR reverts #2280 which introduced `TransactionExtension` to replace `SignedExtension`. As a result of the discussion [here](https://github.com/paritytech/polkadot-sdk/pull/3623#issuecomment-1986789700), the changes will be reverted for now with plans to reintroduce the concept in the future. --------- Signed-off-by: georgepisaltu <george.pisaltu@parity.io>
This commit is contained in:
@@ -28,10 +28,7 @@ use frame_support::{
|
||||
use frame_system as system;
|
||||
use mock::{ExtrinsicBaseWeight, *};
|
||||
use pallet_balances::Call as BalancesCall;
|
||||
use sp_runtime::{
|
||||
traits::{DispatchTransaction, StaticLookup},
|
||||
BuildStorage,
|
||||
};
|
||||
use sp_runtime::{traits::StaticLookup, BuildStorage};
|
||||
|
||||
const CALL: &<Runtime as frame_system::Config>::RuntimeCall =
|
||||
&RuntimeCall::Balances(BalancesCall::transfer_allow_death { dest: 2, value: 69 });
|
||||
@@ -163,35 +160,33 @@ fn transaction_payment_in_native_possible() {
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
let len = 10;
|
||||
let (pre, _) = ChargeAssetTxPayment::<Runtime>::from(0, None)
|
||||
.validate_and_prepare(Some(1).into(), CALL, &info_from_weight(WEIGHT_5), len)
|
||||
let pre = ChargeAssetTxPayment::<Runtime>::from(0, None)
|
||||
.pre_dispatch(&1, CALL, &info_from_weight(WEIGHT_5), len)
|
||||
.unwrap();
|
||||
let initial_balance = 10 * balance_factor;
|
||||
assert_eq!(Balances::free_balance(1), initial_balance - 5 - 5 - 10);
|
||||
|
||||
assert_ok!(ChargeAssetTxPayment::<Runtime>::post_dispatch(
|
||||
pre,
|
||||
Some(pre),
|
||||
&info_from_weight(WEIGHT_5),
|
||||
&default_post_info(),
|
||||
len,
|
||||
&Ok(()),
|
||||
&()
|
||||
&Ok(())
|
||||
));
|
||||
assert_eq!(Balances::free_balance(1), initial_balance - 5 - 5 - 10);
|
||||
|
||||
let (pre, _) = ChargeAssetTxPayment::<Runtime>::from(5 /* tipped */, None)
|
||||
.validate_and_prepare(Some(2).into(), CALL, &info_from_weight(WEIGHT_100), len)
|
||||
let pre = ChargeAssetTxPayment::<Runtime>::from(5 /* tipped */, None)
|
||||
.pre_dispatch(&2, CALL, &info_from_weight(WEIGHT_100), len)
|
||||
.unwrap();
|
||||
let initial_balance_for_2 = 20 * balance_factor;
|
||||
|
||||
assert_eq!(Balances::free_balance(2), initial_balance_for_2 - 5 - 10 - 100 - 5);
|
||||
assert_ok!(ChargeAssetTxPayment::<Runtime>::post_dispatch(
|
||||
pre,
|
||||
Some(pre),
|
||||
&info_from_weight(WEIGHT_100),
|
||||
&post_info_from_weight(WEIGHT_50),
|
||||
len,
|
||||
&Ok(()),
|
||||
&()
|
||||
&Ok(())
|
||||
));
|
||||
assert_eq!(Balances::free_balance(2), initial_balance_for_2 - 5 - 10 - 50 - 5);
|
||||
});
|
||||
@@ -242,8 +237,8 @@ fn transaction_payment_in_asset_possible() {
|
||||
let fee_in_asset = input_quote.unwrap();
|
||||
assert_eq!(Assets::balance(asset_id, caller), balance);
|
||||
|
||||
let (pre, _) = ChargeAssetTxPayment::<Runtime>::from(0, Some(asset_id))
|
||||
.validate_and_prepare(Some(caller).into(), CALL, &info_from_weight(WEIGHT_5), len)
|
||||
let pre = ChargeAssetTxPayment::<Runtime>::from(0, Some(asset_id))
|
||||
.pre_dispatch(&caller, CALL, &info_from_weight(WEIGHT_5), len)
|
||||
.unwrap();
|
||||
// assert that native balance is not used
|
||||
assert_eq!(Balances::free_balance(caller), 10 * balance_factor);
|
||||
@@ -252,12 +247,11 @@ fn transaction_payment_in_asset_possible() {
|
||||
assert_eq!(Assets::balance(asset_id, caller), balance - fee_in_asset);
|
||||
|
||||
assert_ok!(ChargeAssetTxPayment::<Runtime>::post_dispatch(
|
||||
pre,
|
||||
Some(pre),
|
||||
&info_from_weight(WEIGHT_5), // estimated tx weight
|
||||
&default_post_info(), // weight actually used == estimated
|
||||
len,
|
||||
&Ok(()),
|
||||
&()
|
||||
&Ok(())
|
||||
));
|
||||
|
||||
assert_eq!(Assets::balance(asset_id, caller), balance - fee_in_asset);
|
||||
@@ -295,8 +289,12 @@ fn transaction_payment_in_asset_fails_if_no_pool_for_that_asset() {
|
||||
assert_eq!(Assets::balance(asset_id, caller), balance);
|
||||
|
||||
let len = 10;
|
||||
let pre = ChargeAssetTxPayment::<Runtime>::from(0, Some(asset_id))
|
||||
.validate_and_prepare(Some(caller).into(), CALL, &info_from_weight(WEIGHT_5), len);
|
||||
let pre = ChargeAssetTxPayment::<Runtime>::from(0, Some(asset_id)).pre_dispatch(
|
||||
&caller,
|
||||
CALL,
|
||||
&info_from_weight(WEIGHT_5),
|
||||
len,
|
||||
);
|
||||
|
||||
// As there is no pool in the dex set up for this asset, conversion should fail.
|
||||
assert!(pre.is_err());
|
||||
@@ -346,8 +344,8 @@ fn transaction_payment_without_fee() {
|
||||
assert_eq!(input_quote, Some(201));
|
||||
|
||||
let fee_in_asset = input_quote.unwrap();
|
||||
let (pre, _) = ChargeAssetTxPayment::<Runtime>::from(0, Some(asset_id))
|
||||
.validate_and_prepare(Some(caller).into(), CALL, &info_from_weight(WEIGHT_5), len)
|
||||
let pre = ChargeAssetTxPayment::<Runtime>::from(0, Some(asset_id))
|
||||
.pre_dispatch(&caller, CALL, &info_from_weight(WEIGHT_5), len)
|
||||
.unwrap();
|
||||
|
||||
// assert that native balance is not used
|
||||
@@ -365,12 +363,11 @@ fn transaction_payment_without_fee() {
|
||||
assert_eq!(refund, 199);
|
||||
|
||||
assert_ok!(ChargeAssetTxPayment::<Runtime>::post_dispatch(
|
||||
pre,
|
||||
Some(pre),
|
||||
&info_from_weight(WEIGHT_5),
|
||||
&post_info_from_pays(Pays::No),
|
||||
len,
|
||||
&Ok(()),
|
||||
&()
|
||||
&Ok(())
|
||||
));
|
||||
|
||||
// caller should get refunded
|
||||
@@ -422,8 +419,8 @@ fn asset_transaction_payment_with_tip_and_refund() {
|
||||
assert_eq!(input_quote, Some(1206));
|
||||
|
||||
let fee_in_asset = input_quote.unwrap();
|
||||
let (pre, _) = ChargeAssetTxPayment::<Runtime>::from(tip, Some(asset_id))
|
||||
.validate_and_prepare(Some(caller).into(), CALL, &info_from_weight(WEIGHT_100), len)
|
||||
let pre = ChargeAssetTxPayment::<Runtime>::from(tip, Some(asset_id))
|
||||
.pre_dispatch(&caller, CALL, &info_from_weight(WEIGHT_100), len)
|
||||
.unwrap();
|
||||
assert_eq!(Assets::balance(asset_id, caller), balance - fee_in_asset);
|
||||
|
||||
@@ -438,12 +435,11 @@ fn asset_transaction_payment_with_tip_and_refund() {
|
||||
.unwrap();
|
||||
|
||||
assert_ok!(ChargeAssetTxPayment::<Runtime>::post_dispatch(
|
||||
pre,
|
||||
Some(pre),
|
||||
&info_from_weight(WEIGHT_100),
|
||||
&post_info_from_weight(WEIGHT_50),
|
||||
len,
|
||||
&Ok(()),
|
||||
&()
|
||||
&Ok(())
|
||||
));
|
||||
|
||||
assert_eq!(TipUnbalancedAmount::get(), tip);
|
||||
@@ -504,8 +500,8 @@ fn payment_from_account_with_only_assets() {
|
||||
.unwrap();
|
||||
assert_eq!(fee_in_asset, 301);
|
||||
|
||||
let (pre, _) = ChargeAssetTxPayment::<Runtime>::from(0, Some(asset_id))
|
||||
.validate_and_prepare(Some(caller).into(), CALL, &info_from_weight(WEIGHT_5), len)
|
||||
let pre = ChargeAssetTxPayment::<Runtime>::from(0, Some(asset_id))
|
||||
.pre_dispatch(&caller, CALL, &info_from_weight(WEIGHT_5), len)
|
||||
.unwrap();
|
||||
assert_eq!(Balances::free_balance(caller), ed);
|
||||
// check that fee was charged in the given asset
|
||||
@@ -520,12 +516,11 @@ fn payment_from_account_with_only_assets() {
|
||||
.unwrap();
|
||||
|
||||
assert_ok!(ChargeAssetTxPayment::<Runtime>::post_dispatch(
|
||||
pre,
|
||||
Some(pre),
|
||||
&info_from_weight(WEIGHT_5),
|
||||
&default_post_info(),
|
||||
len,
|
||||
&Ok(()),
|
||||
&()
|
||||
&Ok(())
|
||||
));
|
||||
assert_eq!(Assets::balance(asset_id, caller), balance - fee_in_asset + refund);
|
||||
assert_eq!(Balances::free_balance(caller), 0);
|
||||
@@ -570,19 +565,18 @@ fn converted_fee_is_never_zero_if_input_fee_is_not() {
|
||||
|
||||
// there will be no conversion when the fee is zero
|
||||
{
|
||||
let (pre, _) = ChargeAssetTxPayment::<Runtime>::from(0, Some(asset_id))
|
||||
.validate_and_prepare(Some(caller).into(), CALL, &info_from_pays(Pays::No), len)
|
||||
let pre = ChargeAssetTxPayment::<Runtime>::from(0, Some(asset_id))
|
||||
.pre_dispatch(&caller, CALL, &info_from_pays(Pays::No), len)
|
||||
.unwrap();
|
||||
// `Pays::No` implies there are no fees
|
||||
assert_eq!(Assets::balance(asset_id, caller), balance);
|
||||
|
||||
assert_ok!(ChargeAssetTxPayment::<Runtime>::post_dispatch(
|
||||
pre,
|
||||
Some(pre),
|
||||
&info_from_pays(Pays::No),
|
||||
&post_info_from_pays(Pays::No),
|
||||
len,
|
||||
&Ok(()),
|
||||
&()
|
||||
&Ok(())
|
||||
));
|
||||
assert_eq!(Assets::balance(asset_id, caller), balance);
|
||||
}
|
||||
@@ -597,23 +591,17 @@ fn converted_fee_is_never_zero_if_input_fee_is_not() {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let (pre, _) = ChargeAssetTxPayment::<Runtime>::from(0, Some(asset_id))
|
||||
.validate_and_prepare(
|
||||
Some(caller).into(),
|
||||
CALL,
|
||||
&info_from_weight(Weight::from_parts(weight, 0)),
|
||||
len,
|
||||
)
|
||||
let pre = ChargeAssetTxPayment::<Runtime>::from(0, Some(asset_id))
|
||||
.pre_dispatch(&caller, CALL, &info_from_weight(Weight::from_parts(weight, 0)), len)
|
||||
.unwrap();
|
||||
assert_eq!(Assets::balance(asset_id, caller), balance - fee_in_asset);
|
||||
|
||||
assert_ok!(ChargeAssetTxPayment::<Runtime>::post_dispatch(
|
||||
pre,
|
||||
Some(pre),
|
||||
&info_from_weight(Weight::from_parts(weight, 0)),
|
||||
&default_post_info(),
|
||||
len,
|
||||
&Ok(()),
|
||||
&()
|
||||
&Ok(())
|
||||
));
|
||||
assert_eq!(Assets::balance(asset_id, caller), balance - fee_in_asset);
|
||||
});
|
||||
@@ -653,8 +641,8 @@ fn post_dispatch_fee_is_zero_if_pre_dispatch_fee_is_zero() {
|
||||
// calculated fee is greater than 0
|
||||
assert!(fee > 0);
|
||||
|
||||
let (pre, _) = ChargeAssetTxPayment::<Runtime>::from(0, Some(asset_id))
|
||||
.validate_and_prepare(Some(caller).into(), CALL, &info_from_pays(Pays::No), len)
|
||||
let pre = ChargeAssetTxPayment::<Runtime>::from(0, Some(asset_id))
|
||||
.pre_dispatch(&caller, CALL, &info_from_pays(Pays::No), len)
|
||||
.unwrap();
|
||||
// `Pays::No` implies no pre-dispatch fees
|
||||
|
||||
@@ -670,12 +658,62 @@ fn post_dispatch_fee_is_zero_if_pre_dispatch_fee_is_zero() {
|
||||
// `Pays::Yes` on post-dispatch does not mean we pay (we never charge more than the
|
||||
// initial fee)
|
||||
assert_ok!(ChargeAssetTxPayment::<Runtime>::post_dispatch(
|
||||
pre,
|
||||
Some(pre),
|
||||
&info_from_pays(Pays::No),
|
||||
&post_info_from_pays(Pays::Yes),
|
||||
len,
|
||||
&Ok(()),
|
||||
&()
|
||||
&Ok(())
|
||||
));
|
||||
assert_eq!(Assets::balance(asset_id, caller), balance);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn post_dispatch_fee_is_zero_if_unsigned_pre_dispatch_fee_is_zero() {
|
||||
let base_weight = 1;
|
||||
ExtBuilder::default()
|
||||
.balance_factor(100)
|
||||
.base_weight(Weight::from_parts(base_weight, 0))
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
// create the asset
|
||||
let asset_id = 1;
|
||||
let min_balance = 100;
|
||||
assert_ok!(Assets::force_create(
|
||||
RuntimeOrigin::root(),
|
||||
asset_id.into(),
|
||||
42, /* owner */
|
||||
true, /* is_sufficient */
|
||||
min_balance
|
||||
));
|
||||
|
||||
// mint into the caller account
|
||||
let caller = 333;
|
||||
let beneficiary = <Runtime as system::Config>::Lookup::unlookup(caller);
|
||||
let balance = 1000;
|
||||
|
||||
assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance));
|
||||
assert_eq!(Assets::balance(asset_id, caller), balance);
|
||||
|
||||
let weight = 1;
|
||||
let len = 1;
|
||||
ChargeAssetTxPayment::<Runtime>::pre_dispatch_unsigned(
|
||||
CALL,
|
||||
&info_from_weight(Weight::from_parts(weight, 0)),
|
||||
len,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(Assets::balance(asset_id, caller), balance);
|
||||
|
||||
// `Pays::Yes` on post-dispatch does not mean we pay (we never charge more than the
|
||||
// initial fee)
|
||||
assert_ok!(ChargeAssetTxPayment::<Runtime>::post_dispatch(
|
||||
None,
|
||||
&info_from_weight(Weight::from_parts(weight, 0)),
|
||||
&post_info_from_pays(Pays::Yes),
|
||||
len,
|
||||
&Ok(())
|
||||
));
|
||||
assert_eq!(Assets::balance(asset_id, caller), balance);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user