mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 15:27:57 +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:
@@ -21,14 +21,11 @@ use crate as pallet_transaction_payment;
|
||||
use codec::Encode;
|
||||
|
||||
use sp_runtime::{
|
||||
generic::UncheckedExtrinsic,
|
||||
traits::{DispatchTransaction, One},
|
||||
transaction_validity::InvalidTransaction,
|
||||
BuildStorage,
|
||||
testing::TestXt, traits::One, transaction_validity::InvalidTransaction, BuildStorage,
|
||||
};
|
||||
|
||||
use frame_support::{
|
||||
assert_ok,
|
||||
assert_noop, assert_ok,
|
||||
dispatch::{DispatchClass, DispatchInfo, GetDispatchInfo, PostDispatchInfo},
|
||||
traits::Currency,
|
||||
weights::Weight,
|
||||
@@ -131,37 +128,44 @@ fn default_post_info() -> PostDispatchInfo {
|
||||
PostDispatchInfo { actual_weight: None, pays_fee: Default::default() }
|
||||
}
|
||||
|
||||
type Ext = ChargeTransactionPayment<Runtime>;
|
||||
|
||||
#[test]
|
||||
fn transaction_extension_transaction_payment_work() {
|
||||
fn signed_extension_transaction_payment_work() {
|
||||
ExtBuilder::default()
|
||||
.balance_factor(10)
|
||||
.base_weight(Weight::from_parts(5, 0))
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
let info = info_from_weight(Weight::from_parts(5, 0));
|
||||
Ext::from(0)
|
||||
.test_run(Some(1).into(), CALL, &info, 10, |_| {
|
||||
assert_eq!(Balances::free_balance(1), 100 - 5 - 5 - 10);
|
||||
Ok(default_post_info())
|
||||
})
|
||||
.unwrap()
|
||||
let len = 10;
|
||||
let pre = ChargeTransactionPayment::<Runtime>::from(0)
|
||||
.pre_dispatch(&1, CALL, &info_from_weight(Weight::from_parts(5, 0)), len)
|
||||
.unwrap();
|
||||
assert_eq!(Balances::free_balance(1), 100 - 5 - 5 - 10);
|
||||
|
||||
assert_ok!(ChargeTransactionPayment::<Runtime>::post_dispatch(
|
||||
Some(pre),
|
||||
&info_from_weight(Weight::from_parts(5, 0)),
|
||||
&default_post_info(),
|
||||
len,
|
||||
&Ok(())
|
||||
));
|
||||
assert_eq!(Balances::free_balance(1), 100 - 5 - 5 - 10);
|
||||
assert_eq!(FeeUnbalancedAmount::get(), 5 + 5 + 10);
|
||||
assert_eq!(TipUnbalancedAmount::get(), 0);
|
||||
|
||||
FeeUnbalancedAmount::mutate(|a| *a = 0);
|
||||
|
||||
let info = info_from_weight(Weight::from_parts(100, 0));
|
||||
Ext::from(5 /* tipped */)
|
||||
.test_run(Some(2).into(), CALL, &info, 10, |_| {
|
||||
assert_eq!(Balances::free_balance(2), 200 - 5 - 10 - 100 - 5);
|
||||
Ok(post_info_from_weight(Weight::from_parts(50, 0)))
|
||||
})
|
||||
.unwrap()
|
||||
let pre = ChargeTransactionPayment::<Runtime>::from(5 /* tipped */)
|
||||
.pre_dispatch(&2, CALL, &info_from_weight(Weight::from_parts(100, 0)), len)
|
||||
.unwrap();
|
||||
assert_eq!(Balances::free_balance(2), 200 - 5 - 10 - 100 - 5);
|
||||
|
||||
assert_ok!(ChargeTransactionPayment::<Runtime>::post_dispatch(
|
||||
Some(pre),
|
||||
&info_from_weight(Weight::from_parts(100, 0)),
|
||||
&post_info_from_weight(Weight::from_parts(50, 0)),
|
||||
len,
|
||||
&Ok(())
|
||||
));
|
||||
assert_eq!(Balances::free_balance(2), 200 - 5 - 10 - 50 - 5);
|
||||
assert_eq!(FeeUnbalancedAmount::get(), 5 + 10 + 50);
|
||||
assert_eq!(TipUnbalancedAmount::get(), 5);
|
||||
@@ -169,37 +173,43 @@ fn transaction_extension_transaction_payment_work() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transaction_extension_transaction_payment_multiplied_refund_works() {
|
||||
fn signed_extension_transaction_payment_multiplied_refund_works() {
|
||||
ExtBuilder::default()
|
||||
.balance_factor(10)
|
||||
.base_weight(Weight::from_parts(5, 0))
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
let len = 10;
|
||||
<NextFeeMultiplier<Runtime>>::put(Multiplier::saturating_from_rational(3, 2));
|
||||
|
||||
let len = 10;
|
||||
let origin = Some(2).into();
|
||||
let info = info_from_weight(Weight::from_parts(100, 0));
|
||||
Ext::from(5 /* tipped */)
|
||||
.test_run(origin, CALL, &info, len, |_| {
|
||||
// 5 base fee, 10 byte fee, 3/2 * 100 weight fee, 5 tip
|
||||
assert_eq!(Balances::free_balance(2), 200 - 5 - 10 - 150 - 5);
|
||||
Ok(post_info_from_weight(Weight::from_parts(50, 0)))
|
||||
})
|
||||
.unwrap()
|
||||
let pre = ChargeTransactionPayment::<Runtime>::from(5 /* tipped */)
|
||||
.pre_dispatch(&2, CALL, &info_from_weight(Weight::from_parts(100, 0)), len)
|
||||
.unwrap();
|
||||
// 5 base fee, 10 byte fee, 3/2 * 100 weight fee, 5 tip
|
||||
assert_eq!(Balances::free_balance(2), 200 - 5 - 10 - 150 - 5);
|
||||
|
||||
assert_ok!(ChargeTransactionPayment::<Runtime>::post_dispatch(
|
||||
Some(pre),
|
||||
&info_from_weight(Weight::from_parts(100, 0)),
|
||||
&post_info_from_weight(Weight::from_parts(50, 0)),
|
||||
len,
|
||||
&Ok(())
|
||||
));
|
||||
// 75 (3/2 of the returned 50 units of weight) is refunded
|
||||
assert_eq!(Balances::free_balance(2), 200 - 5 - 10 - 75 - 5);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transaction_extension_transaction_payment_is_bounded() {
|
||||
fn signed_extension_transaction_payment_is_bounded() {
|
||||
ExtBuilder::default().balance_factor(1000).byte_fee(0).build().execute_with(|| {
|
||||
// maximum weight possible
|
||||
let info = info_from_weight(Weight::MAX);
|
||||
assert_ok!(Ext::from(0).validate_and_prepare(Some(1).into(), CALL, &info, 10));
|
||||
assert_ok!(ChargeTransactionPayment::<Runtime>::from(0).pre_dispatch(
|
||||
&1,
|
||||
CALL,
|
||||
&info_from_weight(Weight::MAX),
|
||||
10
|
||||
));
|
||||
// fee will be proportional to what is the actual maximum weight in the runtime.
|
||||
assert_eq!(
|
||||
Balances::free_balance(&1),
|
||||
@@ -210,7 +220,7 @@ fn transaction_extension_transaction_payment_is_bounded() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transaction_extension_allows_free_transactions() {
|
||||
fn signed_extension_allows_free_transactions() {
|
||||
ExtBuilder::default()
|
||||
.base_weight(Weight::from_parts(100, 0))
|
||||
.balance_factor(0)
|
||||
@@ -222,28 +232,38 @@ fn transaction_extension_allows_free_transactions() {
|
||||
let len = 100;
|
||||
|
||||
// This is a completely free (and thus wholly insecure/DoS-ridden) transaction.
|
||||
let op_tx = DispatchInfo {
|
||||
let operational_transaction = DispatchInfo {
|
||||
weight: Weight::from_parts(0, 0),
|
||||
class: DispatchClass::Operational,
|
||||
pays_fee: Pays::No,
|
||||
};
|
||||
assert_ok!(Ext::from(0).validate_only(Some(1).into(), CALL, &op_tx, len));
|
||||
assert_ok!(ChargeTransactionPayment::<Runtime>::from(0).validate(
|
||||
&1,
|
||||
CALL,
|
||||
&operational_transaction,
|
||||
len
|
||||
));
|
||||
|
||||
// like a InsecureFreeNormal
|
||||
let free_tx = DispatchInfo {
|
||||
let free_transaction = DispatchInfo {
|
||||
weight: Weight::from_parts(0, 0),
|
||||
class: DispatchClass::Normal,
|
||||
pays_fee: Pays::Yes,
|
||||
};
|
||||
assert_eq!(
|
||||
Ext::from(0).validate_only(Some(1).into(), CALL, &free_tx, len).unwrap_err(),
|
||||
assert_noop!(
|
||||
ChargeTransactionPayment::<Runtime>::from(0).validate(
|
||||
&1,
|
||||
CALL,
|
||||
&free_transaction,
|
||||
len
|
||||
),
|
||||
TransactionValidityError::Invalid(InvalidTransaction::Payment),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transaction_ext_length_fee_is_also_updated_per_congestion() {
|
||||
fn signed_ext_length_fee_is_also_updated_per_congestion() {
|
||||
ExtBuilder::default()
|
||||
.base_weight(Weight::from_parts(5, 0))
|
||||
.balance_factor(10)
|
||||
@@ -252,15 +272,16 @@ fn transaction_ext_length_fee_is_also_updated_per_congestion() {
|
||||
// all fees should be x1.5
|
||||
<NextFeeMultiplier<Runtime>>::put(Multiplier::saturating_from_rational(3, 2));
|
||||
let len = 10;
|
||||
let info = &info_from_weight(Weight::from_parts(3, 0));
|
||||
assert_ok!(Ext::from(10).validate_and_prepare(Some(1).into(), CALL, info, len));
|
||||
|
||||
assert_ok!(ChargeTransactionPayment::<Runtime>::from(10) // tipped
|
||||
.pre_dispatch(&1, CALL, &info_from_weight(Weight::from_parts(3, 0)), len));
|
||||
assert_eq!(
|
||||
Balances::free_balance(1),
|
||||
100 // original
|
||||
- 10 // tip
|
||||
- 5 // base
|
||||
- 10 // len
|
||||
- (3 * 3 / 2) // adjusted weight
|
||||
- 10 // tip
|
||||
- 5 // base
|
||||
- 10 // len
|
||||
- (3 * 3 / 2) // adjusted weight
|
||||
);
|
||||
})
|
||||
}
|
||||
@@ -270,62 +291,62 @@ fn query_info_and_fee_details_works() {
|
||||
let call = RuntimeCall::Balances(BalancesCall::transfer_allow_death { dest: 2, value: 69 });
|
||||
let origin = 111111;
|
||||
let extra = ();
|
||||
let xt = UncheckedExtrinsic::new_signed(call.clone(), origin, (), extra);
|
||||
let xt = TestXt::new(call.clone(), Some((origin, extra)));
|
||||
let info = xt.get_dispatch_info();
|
||||
let ext = xt.encode();
|
||||
let len = ext.len() as u32;
|
||||
|
||||
let unsigned_xt = UncheckedExtrinsic::<u64, _, (), ()>::new_bare(call);
|
||||
let unsigned_xt = TestXt::<_, ()>::new(call, None);
|
||||
let unsigned_xt_info = unsigned_xt.get_dispatch_info();
|
||||
|
||||
ExtBuilder::default()
|
||||
.base_weight(Weight::from_parts(5, 0))
|
||||
.weight_fee(2)
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
// all fees should be x1.5
|
||||
<NextFeeMultiplier<Runtime>>::put(Multiplier::saturating_from_rational(3, 2));
|
||||
.base_weight(Weight::from_parts(5, 0))
|
||||
.weight_fee(2)
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
// all fees should be x1.5
|
||||
<NextFeeMultiplier<Runtime>>::put(Multiplier::saturating_from_rational(3, 2));
|
||||
|
||||
assert_eq!(
|
||||
TransactionPayment::query_info(xt.clone(), len),
|
||||
RuntimeDispatchInfo {
|
||||
weight: info.weight,
|
||||
class: info.class,
|
||||
partial_fee: 5 * 2 /* base * weight_fee */
|
||||
+ len as u64 /* len * 1 */
|
||||
+ info.weight.min(BlockWeights::get().max_block).ref_time() as u64 * 2 * 3 / 2 /* weight */
|
||||
},
|
||||
);
|
||||
assert_eq!(
|
||||
TransactionPayment::query_info(xt.clone(), len),
|
||||
RuntimeDispatchInfo {
|
||||
weight: info.weight,
|
||||
class: info.class,
|
||||
partial_fee: 5 * 2 /* base * weight_fee */
|
||||
+ len as u64 /* len * 1 */
|
||||
+ info.weight.min(BlockWeights::get().max_block).ref_time() as u64 * 2 * 3 / 2 /* weight */
|
||||
},
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
TransactionPayment::query_info(unsigned_xt.clone(), len),
|
||||
RuntimeDispatchInfo {
|
||||
weight: unsigned_xt_info.weight,
|
||||
class: unsigned_xt_info.class,
|
||||
partial_fee: 0,
|
||||
},
|
||||
);
|
||||
assert_eq!(
|
||||
TransactionPayment::query_info(unsigned_xt.clone(), len),
|
||||
RuntimeDispatchInfo {
|
||||
weight: unsigned_xt_info.weight,
|
||||
class: unsigned_xt_info.class,
|
||||
partial_fee: 0,
|
||||
},
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
TransactionPayment::query_fee_details(xt, len),
|
||||
FeeDetails {
|
||||
inclusion_fee: Some(InclusionFee {
|
||||
base_fee: 5 * 2,
|
||||
len_fee: len as u64,
|
||||
adjusted_weight_fee: info
|
||||
.weight
|
||||
.min(BlockWeights::get().max_block)
|
||||
.ref_time() as u64 * 2 * 3 / 2
|
||||
}),
|
||||
tip: 0,
|
||||
},
|
||||
);
|
||||
assert_eq!(
|
||||
TransactionPayment::query_fee_details(xt, len),
|
||||
FeeDetails {
|
||||
inclusion_fee: Some(InclusionFee {
|
||||
base_fee: 5 * 2,
|
||||
len_fee: len as u64,
|
||||
adjusted_weight_fee: info
|
||||
.weight
|
||||
.min(BlockWeights::get().max_block)
|
||||
.ref_time() as u64 * 2 * 3 / 2
|
||||
}),
|
||||
tip: 0,
|
||||
},
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
TransactionPayment::query_fee_details(unsigned_xt, len),
|
||||
FeeDetails { inclusion_fee: None, tip: 0 },
|
||||
);
|
||||
});
|
||||
assert_eq!(
|
||||
TransactionPayment::query_fee_details(unsigned_xt, len),
|
||||
FeeDetails { inclusion_fee: None, tip: 0 },
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -336,39 +357,39 @@ fn query_call_info_and_fee_details_works() {
|
||||
let len = encoded_call.len() as u32;
|
||||
|
||||
ExtBuilder::default()
|
||||
.base_weight(Weight::from_parts(5, 0))
|
||||
.weight_fee(2)
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
// all fees should be x1.5
|
||||
<NextFeeMultiplier<Runtime>>::put(Multiplier::saturating_from_rational(3, 2));
|
||||
.base_weight(Weight::from_parts(5, 0))
|
||||
.weight_fee(2)
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
// all fees should be x1.5
|
||||
<NextFeeMultiplier<Runtime>>::put(Multiplier::saturating_from_rational(3, 2));
|
||||
|
||||
assert_eq!(
|
||||
TransactionPayment::query_call_info(call.clone(), len),
|
||||
RuntimeDispatchInfo {
|
||||
weight: info.weight,
|
||||
class: info.class,
|
||||
partial_fee: 5 * 2 /* base * weight_fee */
|
||||
+ len as u64 /* len * 1 */
|
||||
+ info.weight.min(BlockWeights::get().max_block).ref_time() as u64 * 2 * 3 / 2 /* weight */
|
||||
},
|
||||
);
|
||||
assert_eq!(
|
||||
TransactionPayment::query_call_info(call.clone(), len),
|
||||
RuntimeDispatchInfo {
|
||||
weight: info.weight,
|
||||
class: info.class,
|
||||
partial_fee: 5 * 2 /* base * weight_fee */
|
||||
+ len as u64 /* len * 1 */
|
||||
+ info.weight.min(BlockWeights::get().max_block).ref_time() as u64 * 2 * 3 / 2 /* weight */
|
||||
},
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
TransactionPayment::query_call_fee_details(call, len),
|
||||
FeeDetails {
|
||||
inclusion_fee: Some(InclusionFee {
|
||||
base_fee: 5 * 2, /* base * weight_fee */
|
||||
len_fee: len as u64, /* len * 1 */
|
||||
adjusted_weight_fee: info
|
||||
.weight
|
||||
.min(BlockWeights::get().max_block)
|
||||
.ref_time() as u64 * 2 * 3 / 2 /* weight * weight_fee * multipler */
|
||||
}),
|
||||
tip: 0,
|
||||
},
|
||||
);
|
||||
});
|
||||
assert_eq!(
|
||||
TransactionPayment::query_call_fee_details(call, len),
|
||||
FeeDetails {
|
||||
inclusion_fee: Some(InclusionFee {
|
||||
base_fee: 5 * 2, /* base * weight_fee */
|
||||
len_fee: len as u64, /* len * 1 */
|
||||
adjusted_weight_fee: info
|
||||
.weight
|
||||
.min(BlockWeights::get().max_block)
|
||||
.ref_time() as u64 * 2 * 3 / 2 /* weight * weight_fee * multipler */
|
||||
}),
|
||||
tip: 0,
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -505,23 +526,27 @@ fn refund_does_not_recreate_account() {
|
||||
.execute_with(|| {
|
||||
// So events are emitted
|
||||
System::set_block_number(10);
|
||||
let info = info_from_weight(Weight::from_parts(100, 0));
|
||||
Ext::from(5 /* tipped */)
|
||||
.test_run(Some(2).into(), CALL, &info, 10, |origin| {
|
||||
assert_eq!(Balances::free_balance(2), 200 - 5 - 10 - 100 - 5);
|
||||
|
||||
// kill the account between pre and post dispatch
|
||||
assert_ok!(Balances::transfer_allow_death(
|
||||
origin,
|
||||
3,
|
||||
Balances::free_balance(2)
|
||||
));
|
||||
assert_eq!(Balances::free_balance(2), 0);
|
||||
|
||||
Ok(post_info_from_weight(Weight::from_parts(50, 0)))
|
||||
})
|
||||
.unwrap()
|
||||
let len = 10;
|
||||
let pre = ChargeTransactionPayment::<Runtime>::from(5 /* tipped */)
|
||||
.pre_dispatch(&2, CALL, &info_from_weight(Weight::from_parts(100, 0)), len)
|
||||
.unwrap();
|
||||
assert_eq!(Balances::free_balance(2), 200 - 5 - 10 - 100 - 5);
|
||||
|
||||
// kill the account between pre and post dispatch
|
||||
assert_ok!(Balances::transfer_allow_death(
|
||||
Some(2).into(),
|
||||
3,
|
||||
Balances::free_balance(2)
|
||||
));
|
||||
assert_eq!(Balances::free_balance(2), 0);
|
||||
|
||||
assert_ok!(ChargeTransactionPayment::<Runtime>::post_dispatch(
|
||||
Some(pre),
|
||||
&info_from_weight(Weight::from_parts(100, 0)),
|
||||
&post_info_from_weight(Weight::from_parts(50, 0)),
|
||||
len,
|
||||
&Ok(())
|
||||
));
|
||||
assert_eq!(Balances::free_balance(2), 0);
|
||||
// Transfer Event
|
||||
System::assert_has_event(RuntimeEvent::Balances(pallet_balances::Event::Transfer {
|
||||
@@ -543,15 +568,20 @@ fn actual_weight_higher_than_max_refunds_nothing() {
|
||||
.base_weight(Weight::from_parts(5, 0))
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
let info = info_from_weight(Weight::from_parts(100, 0));
|
||||
Ext::from(5 /* tipped */)
|
||||
.test_run(Some(2).into(), CALL, &info, 10, |_| {
|
||||
assert_eq!(Balances::free_balance(2), 200 - 5 - 10 - 100 - 5);
|
||||
Ok(post_info_from_weight(Weight::from_parts(101, 0)))
|
||||
})
|
||||
.unwrap()
|
||||
let len = 10;
|
||||
let pre = ChargeTransactionPayment::<Runtime>::from(5 /* tipped */)
|
||||
.pre_dispatch(&2, CALL, &info_from_weight(Weight::from_parts(100, 0)), len)
|
||||
.unwrap();
|
||||
assert_eq!(Balances::free_balance(2), 200 - 5 - 10 - 100 - 5);
|
||||
|
||||
assert_ok!(ChargeTransactionPayment::<Runtime>::post_dispatch(
|
||||
Some(pre),
|
||||
&info_from_weight(Weight::from_parts(100, 0)),
|
||||
&post_info_from_weight(Weight::from_parts(101, 0)),
|
||||
len,
|
||||
&Ok(())
|
||||
));
|
||||
assert_eq!(Balances::free_balance(2), 200 - 5 - 10 - 100 - 5);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -564,20 +594,25 @@ fn zero_transfer_on_free_transaction() {
|
||||
.execute_with(|| {
|
||||
// So events are emitted
|
||||
System::set_block_number(10);
|
||||
let info = DispatchInfo {
|
||||
let len = 10;
|
||||
let dispatch_info = DispatchInfo {
|
||||
weight: Weight::from_parts(100, 0),
|
||||
pays_fee: Pays::No,
|
||||
class: DispatchClass::Normal,
|
||||
};
|
||||
let user = 69;
|
||||
Ext::from(0)
|
||||
.test_run(Some(user).into(), CALL, &info, 10, |_| {
|
||||
assert_eq!(Balances::total_balance(&user), 0);
|
||||
Ok(default_post_info())
|
||||
})
|
||||
.unwrap()
|
||||
let pre = ChargeTransactionPayment::<Runtime>::from(0)
|
||||
.pre_dispatch(&user, CALL, &dispatch_info, len)
|
||||
.unwrap();
|
||||
assert_eq!(Balances::total_balance(&user), 0);
|
||||
assert_ok!(ChargeTransactionPayment::<Runtime>::post_dispatch(
|
||||
Some(pre),
|
||||
&dispatch_info,
|
||||
&default_post_info(),
|
||||
len,
|
||||
&Ok(())
|
||||
));
|
||||
assert_eq!(Balances::total_balance(&user), 0);
|
||||
// TransactionFeePaid Event
|
||||
System::assert_has_event(RuntimeEvent::TransactionPayment(
|
||||
pallet_transaction_payment::Event::TransactionFeePaid {
|
||||
@@ -604,11 +639,19 @@ fn refund_consistent_with_actual_weight() {
|
||||
|
||||
<NextFeeMultiplier<Runtime>>::put(Multiplier::saturating_from_rational(5, 4));
|
||||
|
||||
Ext::from(tip)
|
||||
.test_run(Some(2).into(), CALL, &info, len, |_| Ok(post_info))
|
||||
.unwrap()
|
||||
let pre = ChargeTransactionPayment::<Runtime>::from(tip)
|
||||
.pre_dispatch(&2, CALL, &info, len)
|
||||
.unwrap();
|
||||
|
||||
ChargeTransactionPayment::<Runtime>::post_dispatch(
|
||||
Some(pre),
|
||||
&info,
|
||||
&post_info,
|
||||
len,
|
||||
&Ok(()),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let refund_based_fee = prev_balance - Balances::free_balance(2);
|
||||
let actual_fee =
|
||||
Pallet::<Runtime>::compute_actual_fee(len as u32, &info, &post_info, tip);
|
||||
@@ -630,13 +673,18 @@ fn should_alter_operational_priority() {
|
||||
class: DispatchClass::Normal,
|
||||
pays_fee: Pays::Yes,
|
||||
};
|
||||
let priority = ChargeTransactionPayment::<Runtime>(tip)
|
||||
.validate(&2, CALL, &normal, len)
|
||||
.unwrap()
|
||||
.priority;
|
||||
|
||||
let ext = Ext::from(tip);
|
||||
let priority = ext.validate_only(Some(2).into(), CALL, &normal, len).unwrap().0.priority;
|
||||
assert_eq!(priority, 60);
|
||||
|
||||
let ext = Ext::from(2 * tip);
|
||||
let priority = ext.validate_only(Some(2).into(), CALL, &normal, len).unwrap().0.priority;
|
||||
let priority = ChargeTransactionPayment::<Runtime>(2 * tip)
|
||||
.validate(&2, CALL, &normal, len)
|
||||
.unwrap()
|
||||
.priority;
|
||||
|
||||
assert_eq!(priority, 110);
|
||||
});
|
||||
|
||||
@@ -646,13 +694,16 @@ fn should_alter_operational_priority() {
|
||||
class: DispatchClass::Operational,
|
||||
pays_fee: Pays::Yes,
|
||||
};
|
||||
|
||||
let ext = Ext::from(tip);
|
||||
let priority = ext.validate_only(Some(2).into(), CALL, &op, len).unwrap().0.priority;
|
||||
let priority = ChargeTransactionPayment::<Runtime>(tip)
|
||||
.validate(&2, CALL, &op, len)
|
||||
.unwrap()
|
||||
.priority;
|
||||
assert_eq!(priority, 5810);
|
||||
|
||||
let ext = Ext::from(2 * tip);
|
||||
let priority = ext.validate_only(Some(2).into(), CALL, &op, len).unwrap().0.priority;
|
||||
let priority = ChargeTransactionPayment::<Runtime>(2 * tip)
|
||||
.validate(&2, CALL, &op, len)
|
||||
.unwrap()
|
||||
.priority;
|
||||
assert_eq!(priority, 6110);
|
||||
});
|
||||
}
|
||||
@@ -668,8 +719,11 @@ fn no_tip_has_some_priority() {
|
||||
class: DispatchClass::Normal,
|
||||
pays_fee: Pays::Yes,
|
||||
};
|
||||
let ext = Ext::from(tip);
|
||||
let priority = ext.validate_only(Some(2).into(), CALL, &normal, len).unwrap().0.priority;
|
||||
let priority = ChargeTransactionPayment::<Runtime>(tip)
|
||||
.validate(&2, CALL, &normal, len)
|
||||
.unwrap()
|
||||
.priority;
|
||||
|
||||
assert_eq!(priority, 10);
|
||||
});
|
||||
|
||||
@@ -679,8 +733,10 @@ fn no_tip_has_some_priority() {
|
||||
class: DispatchClass::Operational,
|
||||
pays_fee: Pays::Yes,
|
||||
};
|
||||
let ext = Ext::from(tip);
|
||||
let priority = ext.validate_only(Some(2).into(), CALL, &op, len).unwrap().0.priority;
|
||||
let priority = ChargeTransactionPayment::<Runtime>(tip)
|
||||
.validate(&2, CALL, &op, len)
|
||||
.unwrap()
|
||||
.priority;
|
||||
assert_eq!(priority, 5510);
|
||||
});
|
||||
}
|
||||
@@ -688,8 +744,8 @@ fn no_tip_has_some_priority() {
|
||||
#[test]
|
||||
fn higher_tip_have_higher_priority() {
|
||||
let get_priorities = |tip: u64| {
|
||||
let mut pri1 = 0;
|
||||
let mut pri2 = 0;
|
||||
let mut priority1 = 0;
|
||||
let mut priority2 = 0;
|
||||
let len = 10;
|
||||
ExtBuilder::default().balance_factor(100).build().execute_with(|| {
|
||||
let normal = DispatchInfo {
|
||||
@@ -697,8 +753,10 @@ fn higher_tip_have_higher_priority() {
|
||||
class: DispatchClass::Normal,
|
||||
pays_fee: Pays::Yes,
|
||||
};
|
||||
let ext = Ext::from(tip);
|
||||
pri1 = ext.validate_only(Some(2).into(), CALL, &normal, len).unwrap().0.priority;
|
||||
priority1 = ChargeTransactionPayment::<Runtime>(tip)
|
||||
.validate(&2, CALL, &normal, len)
|
||||
.unwrap()
|
||||
.priority;
|
||||
});
|
||||
|
||||
ExtBuilder::default().balance_factor(100).build().execute_with(|| {
|
||||
@@ -707,11 +765,13 @@ fn higher_tip_have_higher_priority() {
|
||||
class: DispatchClass::Operational,
|
||||
pays_fee: Pays::Yes,
|
||||
};
|
||||
let ext = Ext::from(tip);
|
||||
pri2 = ext.validate_only(Some(2).into(), CALL, &op, len).unwrap().0.priority;
|
||||
priority2 = ChargeTransactionPayment::<Runtime>(tip)
|
||||
.validate(&2, CALL, &op, len)
|
||||
.unwrap()
|
||||
.priority;
|
||||
});
|
||||
|
||||
(pri1, pri2)
|
||||
(priority1, priority2)
|
||||
};
|
||||
|
||||
let mut prev_priorities = get_priorities(0);
|
||||
@@ -739,11 +799,19 @@ fn post_info_can_change_pays_fee() {
|
||||
|
||||
<NextFeeMultiplier<Runtime>>::put(Multiplier::saturating_from_rational(5, 4));
|
||||
|
||||
let post_info = ChargeTransactionPayment::<Runtime>::from(tip)
|
||||
.test_run(Some(2).into(), CALL, &info, len, |_| Ok(post_info))
|
||||
.unwrap()
|
||||
let pre = ChargeTransactionPayment::<Runtime>::from(tip)
|
||||
.pre_dispatch(&2, CALL, &info, len)
|
||||
.unwrap();
|
||||
|
||||
ChargeTransactionPayment::<Runtime>::post_dispatch(
|
||||
Some(pre),
|
||||
&info,
|
||||
&post_info,
|
||||
len,
|
||||
&Ok(()),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let refund_based_fee = prev_balance - Balances::free_balance(2);
|
||||
let actual_fee =
|
||||
Pallet::<Runtime>::compute_actual_fee(len as u32, &info, &post_info, tip);
|
||||
|
||||
Reference in New Issue
Block a user