mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 17:01:09 +00:00
Allow PostDispatchInfo to disable fees (#6749)
* initial mock * add test * remove unneeded clone * Update frame/support/src/weights.rs Co-authored-by: Alexander Theißen <alex.theissen@me.com> * fix compile * Update frame/support/src/weights.rs Co-authored-by: Alexander Popiak <alexander.popiak@parity.io> * Update frame/sudo/src/lib.rs Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Alexander Theißen <alex.theissen@me.com> Co-authored-by: Alexander Popiak <alexander.popiak@parity.io> Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -371,7 +371,7 @@ impl<T: Trait> Module<T> where
|
||||
) -> BalanceOf<T> where
|
||||
T::Call: Dispatchable<Info=DispatchInfo,PostInfo=PostDispatchInfo>,
|
||||
{
|
||||
Self::compute_fee_raw(len, post_info.calc_actual_weight(info), tip, info.pays_fee)
|
||||
Self::compute_fee_raw(len, post_info.calc_actual_weight(info), tip, post_info.pays_fee(info))
|
||||
}
|
||||
|
||||
fn compute_fee_raw(
|
||||
@@ -762,11 +762,24 @@ mod tests {
|
||||
}
|
||||
|
||||
fn post_info_from_weight(w: Weight) -> PostDispatchInfo {
|
||||
PostDispatchInfo { actual_weight: Some(w), }
|
||||
PostDispatchInfo {
|
||||
actual_weight: Some(w),
|
||||
pays_fee: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
fn post_info_from_pays(p: Pays) -> PostDispatchInfo {
|
||||
PostDispatchInfo {
|
||||
actual_weight: None,
|
||||
pays_fee: p,
|
||||
}
|
||||
}
|
||||
|
||||
fn default_post_info() -> PostDispatchInfo {
|
||||
PostDispatchInfo { actual_weight: None, }
|
||||
PostDispatchInfo {
|
||||
actual_weight: None,
|
||||
pays_fee: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1211,4 +1224,38 @@ mod tests {
|
||||
assert_eq!(refund_based_fee, actual_fee);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn post_info_can_change_pays_fee() {
|
||||
ExtBuilder::default()
|
||||
.balance_factor(10)
|
||||
.base_weight(7)
|
||||
.build()
|
||||
.execute_with(||
|
||||
{
|
||||
let info = info_from_weight(100);
|
||||
let post_info = post_info_from_pays(Pays::No);
|
||||
let prev_balance = Balances::free_balance(2);
|
||||
let len = 10;
|
||||
let tip = 5;
|
||||
|
||||
NextFeeMultiplier::put(Multiplier::saturating_from_rational(5, 4));
|
||||
|
||||
let pre = ChargeTransactionPayment::<Runtime>::from(tip)
|
||||
.pre_dispatch(&2, CALL, &info, len)
|
||||
.unwrap();
|
||||
|
||||
ChargeTransactionPayment::<Runtime>
|
||||
::post_dispatch(pre, &info, &post_info, len, &Ok(()))
|
||||
.unwrap();
|
||||
|
||||
let refund_based_fee = prev_balance - Balances::free_balance(2);
|
||||
let actual_fee = Module::<Runtime>
|
||||
::compute_actual_fee(len as u32, &info, &post_info, tip);
|
||||
|
||||
// Only 5 tip is paid
|
||||
assert_eq!(actual_fee, 5);
|
||||
assert_eq!(refund_based_fee, actual_fee);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user