Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix typo
  • Loading branch information
nazar-pc committed May 24, 2022
commit be59c7eb617fc240edaefa8a0a1e632136529ef4
4 changes: 2 additions & 2 deletions bin/node/executor/tests/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@ fn transaction_fee_is_correct() {
let mut balance_alice = (100 - 69) * DOLLARS;

let base_weight = ExtrinsicBaseWeight::get();
let base_fee = IdentityFee::<Balance>::wight_to_fee(&base_weight);
let base_fee = IdentityFee::<Balance>::weight_to_fee(&base_weight);

let length_fee = TransactionByteFee::get() * (xt.clone().encode().len() as Balance);
balance_alice -= length_fee;

let weight = default_transfer_call().get_dispatch_info().weight;
let weight_fee = IdentityFee::<Balance>::wight_to_fee(&weight);
let weight_fee = IdentityFee::<Balance>::weight_to_fee(&weight);

// we know that weight to fee multiplier is effect-less in block 1.
// current weight of transfer = 200_000_000
Expand Down
2 changes: 1 addition & 1 deletion bin/node/runtime/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ mod multiplier_tests {
fm = next;
iterations += 1;
let fee =
<Runtime as pallet_transaction_payment::Config>::WeightToFee::wight_to_fee(
<Runtime as pallet_transaction_payment::Config>::WeightToFee::weight_to_fee(
&tx_weight,
);
let adjusted_fee = fm.saturating_mul_acc_int(fee);
Expand Down
4 changes: 2 additions & 2 deletions frame/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ mod tests {
.get(DispatchClass::Normal)
.base_extrinsic;
let fee: Balance =
<Runtime as pallet_transaction_payment::Config>::WeightToFee::wight_to_fee(&weight);
<Runtime as pallet_transaction_payment::Config>::WeightToFee::weight_to_fee(&weight);
let mut t = sp_io::TestExternalities::new(t);
t.execute_with(|| {
Executive::initialize_block(&Header::new(
Expand Down Expand Up @@ -1151,7 +1151,7 @@ mod tests {
.get(DispatchClass::Normal)
.base_extrinsic;
let fee: Balance =
<Runtime as pallet_transaction_payment::Config>::WeightToFee::wight_to_fee(
<Runtime as pallet_transaction_payment::Config>::WeightToFee::weight_to_fee(
&weight,
);
Executive::initialize_block(&Header::new(
Expand Down
32 changes: 16 additions & 16 deletions frame/support/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ pub trait WeightToFee {
type Balance: BaseArithmetic + From<u32> + Copy + Unsigned;

/// Calculates the fee from the passed `weight`.
fn wight_to_fee(weight: &Weight) -> Self::Balance;
fn weight_to_fee(weight: &Weight) -> Self::Balance;
}

/// A trait that describes the weight to fee calculation as polynomial.
Expand Down Expand Up @@ -685,7 +685,7 @@ where
///
/// This should not be overriden in most circumstances. Calculation is done in the
/// `Balance` type and never overflows. All evaluation is saturating.
fn wight_to_fee(weight: &Weight) -> Self::Balance {
fn weight_to_fee(weight: &Weight) -> Self::Balance {
Self::polynomial()
.iter()
.fold(Self::Balance::saturated_from(0u32), |mut acc, args| {
Expand Down Expand Up @@ -718,7 +718,7 @@ where
{
type Balance = T;

fn wight_to_fee(weight: &Weight) -> Self::Balance {
fn weight_to_fee(weight: &Weight) -> Self::Balance {
Self::Balance::saturated_from(*weight)
}
}
Expand All @@ -741,7 +741,7 @@ where
{
type Balance = T;

fn wight_to_fee(weight: &Weight) -> Self::Balance {
fn weight_to_fee(weight: &Weight) -> Self::Balance {
Self::Balance::saturated_from(*weight).saturating_mul(M::get())
}
}
Expand Down Expand Up @@ -999,40 +999,40 @@ mod tests {
#[test]
fn polynomial_works() {
// 100^3/2=500000 100^2*(2+1/3)=23333 700 -10000
assert_eq!(Poly::wight_to_fee(&100), 514033);
assert_eq!(Poly::weight_to_fee(&100), 514033);
// 10123^3/2=518677865433 10123^2*(2+1/3)=239108634 70861 -10000
assert_eq!(Poly::wight_to_fee(&10_123), 518917034928);
assert_eq!(Poly::weight_to_fee(&10_123), 518917034928);
}

#[test]
fn polynomial_does_not_underflow() {
assert_eq!(Poly::wight_to_fee(&0), 0);
assert_eq!(Poly::wight_to_fee(&10), 0);
assert_eq!(Poly::weight_to_fee(&0), 0);
assert_eq!(Poly::weight_to_fee(&10), 0);
}

#[test]
fn polynomial_does_not_overflow() {
assert_eq!(Poly::wight_to_fee(&Weight::max_value()), Balance::max_value() - 10_000);
assert_eq!(Poly::weight_to_fee(&Weight::max_value()), Balance::max_value() - 10_000);
}

#[test]
fn identity_fee_works() {
assert_eq!(IdentityFee::<Balance>::wight_to_fee(&0), 0);
assert_eq!(IdentityFee::<Balance>::wight_to_fee(&50), 50);
assert_eq!(IdentityFee::<Balance>::weight_to_fee(&0), 0);
assert_eq!(IdentityFee::<Balance>::weight_to_fee(&50), 50);
assert_eq!(
IdentityFee::<Balance>::wight_to_fee(&Weight::max_value()),
IdentityFee::<Balance>::weight_to_fee(&Weight::max_value()),
Balance::max_value()
);
}

#[test]
fn constant_fee_works() {
use crate::traits::ConstU128;
assert_eq!(ConstantMultiplier::<u128, ConstU128<100u128>>::wight_to_fee(&0), 0);
assert_eq!(ConstantMultiplier::<u128, ConstU128<10u128>>::wight_to_fee(&50), 500);
assert_eq!(ConstantMultiplier::<u128, ConstU128<1024u128>>::wight_to_fee(&16), 16384);
assert_eq!(ConstantMultiplier::<u128, ConstU128<100u128>>::weight_to_fee(&0), 0);
assert_eq!(ConstantMultiplier::<u128, ConstU128<10u128>>::weight_to_fee(&50), 500);
assert_eq!(ConstantMultiplier::<u128, ConstU128<1024u128>>::weight_to_fee(&16), 16384);
assert_eq!(
ConstantMultiplier::<u128, ConstU128<{ u128::MAX }>>::wight_to_fee(&2),
ConstantMultiplier::<u128, ConstU128<{ u128::MAX }>>::weight_to_fee(&2),
u128::MAX
);
}
Expand Down
4 changes: 2 additions & 2 deletions frame/transaction-payment/asset-tx-payment/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ impl pallet_balances::Config for Runtime {
impl WeightToFeeT for WeightToFee {
type Balance = u64;

fn wight_to_fee(weight: &Weight) -> Self::Balance {
fn weight_to_fee(weight: &Weight) -> Self::Balance {
Self::Balance::saturated_from(*weight).saturating_mul(WEIGHT_TO_FEE.with(|v| *v.borrow()))
}
}

impl WeightToFeeT for TransactionByteFee {
type Balance = u64;

fn wight_to_fee(weight: &Weight) -> Self::Balance {
fn weight_to_fee(weight: &Weight) -> Self::Balance {
Self::Balance::saturated_from(*weight)
.saturating_mul(TRANSACTION_BYTE_FEE.with(|v| *v.borrow()))
}
Expand Down
8 changes: 4 additions & 4 deletions frame/transaction-payment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,14 +517,14 @@ where
}

fn length_to_fee(length: u32) -> BalanceOf<T> {
T::LengthToFee::wight_to_fee(&(length as Weight))
T::LengthToFee::weight_to_fee(&(length as Weight))
}

fn weight_to_fee(weight: Weight) -> BalanceOf<T> {
// cap the weight to the maximum defined in runtime, otherwise it will be the
// `Bounded` maximum of its data type, which is not desired.
let capped_weight = weight.min(T::BlockWeights::get().max_block);
T::WeightToFee::wight_to_fee(&capped_weight)
T::WeightToFee::weight_to_fee(&capped_weight)
}
}

Expand Down Expand Up @@ -864,7 +864,7 @@ mod tests {
impl WeightToFeeT for WeightToFee {
type Balance = u64;

fn wight_to_fee(weight: &Weight) -> Self::Balance {
fn weight_to_fee(weight: &Weight) -> Self::Balance {
Self::Balance::saturated_from(*weight)
.saturating_mul(WEIGHT_TO_FEE.with(|v| *v.borrow()))
}
Expand All @@ -873,7 +873,7 @@ mod tests {
impl WeightToFeeT for TransactionByteFee {
type Balance = u64;

fn wight_to_fee(weight: &Weight) -> Self::Balance {
fn weight_to_fee(weight: &Weight) -> Self::Balance {
Self::Balance::saturated_from(*weight)
.saturating_mul(TRANSACTION_BYTE_FEE.with(|v| *v.borrow()))
}
Expand Down