mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-19 03:01:02 +00:00
Weight v1.5: Opaque Struct (#12138)
* initial idea * update frame_support * update a bunch more * add ord * adjust RuntimeDbWeight * frame_system builds * re-export * frame_support tests pass * frame_executive compile * frame_executive builds * frame_system tests passing * pallet-utility tests pass * fix a bunch of pallets * more * phragmen * state-trie-migration * scheduler and referenda * pallet-election-provider-multi-phase * aura * staking * more * babe * balances * bunch more * sudo * transaction-payment * asset-tx-payment * last pallets * fix alliance merge * fix node template runtime * fix pallet-contracts cc @athei * fix node runtime * fix compile on runtime-benchmarks feature * comment * fix frame-support-test * fix more tests * weight regex * frame system works * fix a bunch * more * more * more * more * more * more fixes * update templates * fix contracts benchmarks * Update lib.rs * Update lib.rs * fix ui * make scalar saturating mul const * more const functions * scalar div * refactor using constant functions * move impl * fix overhead template * use compactas * Update lib.rs
This commit is contained in:
@@ -66,7 +66,8 @@ use frame_support::{
|
||||
dispatch::DispatchResult,
|
||||
traits::{EstimateCallFee, Get},
|
||||
weights::{
|
||||
DispatchClass, DispatchInfo, GetDispatchInfo, Pays, PostDispatchInfo, Weight, WeightToFee,
|
||||
DispatchClass, DispatchInfo, GetDispatchInfo, Pays, PostDispatchInfo, RefTimeWeight,
|
||||
Weight, WeightToFee,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -189,7 +190,11 @@ where
|
||||
weights.get(DispatchClass::Normal).max_total.unwrap_or(weights.max_block);
|
||||
let current_block_weight = <frame_system::Pallet<T>>::block_weight();
|
||||
let normal_block_weight =
|
||||
*current_block_weight.get(DispatchClass::Normal).min(&normal_max_weight);
|
||||
current_block_weight.get(DispatchClass::Normal).min(normal_max_weight);
|
||||
|
||||
// TODO: Handle all weight dimensions
|
||||
let normal_max_weight = normal_max_weight.ref_time();
|
||||
let normal_block_weight = normal_block_weight.ref_time();
|
||||
|
||||
let s = S::get();
|
||||
let v = V::get();
|
||||
@@ -347,7 +352,7 @@ pub mod pallet {
|
||||
assert!(
|
||||
<Multiplier as sp_runtime::traits::Bounded>::max_value() >=
|
||||
Multiplier::checked_from_integer::<u128>(
|
||||
T::BlockWeights::get().max_block.try_into().unwrap()
|
||||
T::BlockWeights::get().max_block.ref_time().try_into().unwrap()
|
||||
)
|
||||
.unwrap(),
|
||||
);
|
||||
@@ -359,7 +364,7 @@ pub mod pallet {
|
||||
);
|
||||
// add 1 percent;
|
||||
let addition = target / 100;
|
||||
if addition == 0 {
|
||||
if addition == Weight::zero() {
|
||||
// this is most likely because in a test setup we set everything to ().
|
||||
return
|
||||
}
|
||||
@@ -554,7 +559,7 @@ where
|
||||
}
|
||||
|
||||
fn length_to_fee(length: u32) -> BalanceOf<T> {
|
||||
T::LengthToFee::weight_to_fee(&(length as Weight))
|
||||
T::LengthToFee::weight_to_fee(&Weight::from_ref_time(length as RefTimeWeight))
|
||||
}
|
||||
|
||||
fn weight_to_fee(weight: Weight) -> BalanceOf<T> {
|
||||
@@ -655,7 +660,11 @@ where
|
||||
let max_block_weight = T::BlockWeights::get().max_block;
|
||||
let max_block_length = *T::BlockLength::get().max.get(info.class) as u64;
|
||||
|
||||
let bounded_weight = info.weight.max(1).min(max_block_weight);
|
||||
// TODO: Take into account all dimensions of weight
|
||||
let max_block_weight = max_block_weight.ref_time();
|
||||
let info_weight = info.weight.ref_time();
|
||||
|
||||
let bounded_weight = info_weight.max(1).min(max_block_weight);
|
||||
let bounded_length = (len as u64).max(1).min(max_block_length);
|
||||
|
||||
let max_tx_per_block_weight = max_block_weight / bounded_weight;
|
||||
@@ -836,19 +845,19 @@ mod tests {
|
||||
&Call::Balances(BalancesCall::transfer { dest: 2, value: 69 });
|
||||
|
||||
thread_local! {
|
||||
static EXTRINSIC_BASE_WEIGHT: RefCell<u64> = RefCell::new(0);
|
||||
static EXTRINSIC_BASE_WEIGHT: RefCell<Weight> = RefCell::new(Weight::new());
|
||||
}
|
||||
|
||||
pub struct BlockWeights;
|
||||
impl Get<frame_system::limits::BlockWeights> for BlockWeights {
|
||||
fn get() -> frame_system::limits::BlockWeights {
|
||||
frame_system::limits::BlockWeights::builder()
|
||||
.base_block(0)
|
||||
.base_block(Weight::zero())
|
||||
.for_class(DispatchClass::all(), |weights| {
|
||||
weights.base_extrinsic = EXTRINSIC_BASE_WEIGHT.with(|v| *v.borrow()).into();
|
||||
})
|
||||
.for_class(DispatchClass::non_mandatory(), |weights| {
|
||||
weights.max_total = 1024.into();
|
||||
weights.max_total = Weight::from_ref_time(1024).into();
|
||||
})
|
||||
.build_or_panic()
|
||||
}
|
||||
@@ -903,7 +912,7 @@ mod tests {
|
||||
type Balance = u64;
|
||||
|
||||
fn weight_to_fee(weight: &Weight) -> Self::Balance {
|
||||
Self::Balance::saturated_from(*weight)
|
||||
Self::Balance::saturated_from(weight.ref_time())
|
||||
.saturating_mul(WEIGHT_TO_FEE.with(|v| *v.borrow()))
|
||||
}
|
||||
}
|
||||
@@ -912,7 +921,7 @@ mod tests {
|
||||
type Balance = u64;
|
||||
|
||||
fn weight_to_fee(weight: &Weight) -> Self::Balance {
|
||||
Self::Balance::saturated_from(*weight)
|
||||
Self::Balance::saturated_from(weight.ref_time())
|
||||
.saturating_mul(TRANSACTION_BYTE_FEE.with(|v| *v.borrow()))
|
||||
}
|
||||
}
|
||||
@@ -947,19 +956,19 @@ mod tests {
|
||||
|
||||
pub struct ExtBuilder {
|
||||
balance_factor: u64,
|
||||
base_weight: u64,
|
||||
base_weight: Weight,
|
||||
byte_fee: u64,
|
||||
weight_to_fee: u64,
|
||||
}
|
||||
|
||||
impl Default for ExtBuilder {
|
||||
fn default() -> Self {
|
||||
Self { balance_factor: 1, base_weight: 0, byte_fee: 1, weight_to_fee: 1 }
|
||||
Self { balance_factor: 1, base_weight: Weight::zero(), byte_fee: 1, weight_to_fee: 1 }
|
||||
}
|
||||
}
|
||||
|
||||
impl ExtBuilder {
|
||||
pub fn base_weight(mut self, base_weight: u64) -> Self {
|
||||
pub fn base_weight(mut self, base_weight: Weight) -> Self {
|
||||
self.base_weight = base_weight;
|
||||
self
|
||||
}
|
||||
@@ -1025,18 +1034,18 @@ mod tests {
|
||||
fn signed_extension_transaction_payment_work() {
|
||||
ExtBuilder::default()
|
||||
.balance_factor(10)
|
||||
.base_weight(5)
|
||||
.base_weight(Weight::from_ref_time(5))
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
let len = 10;
|
||||
let pre = ChargeTransactionPayment::<Runtime>::from(0)
|
||||
.pre_dispatch(&1, CALL, &info_from_weight(5), len)
|
||||
.pre_dispatch(&1, CALL, &info_from_weight(Weight::from_ref_time(5)), len)
|
||||
.unwrap();
|
||||
assert_eq!(Balances::free_balance(1), 100 - 5 - 5 - 10);
|
||||
|
||||
assert_ok!(ChargeTransactionPayment::<Runtime>::post_dispatch(
|
||||
Some(pre),
|
||||
&info_from_weight(5),
|
||||
&info_from_weight(Weight::from_ref_time(5)),
|
||||
&default_post_info(),
|
||||
len,
|
||||
&Ok(())
|
||||
@@ -1048,14 +1057,14 @@ mod tests {
|
||||
FEE_UNBALANCED_AMOUNT.with(|a| *a.borrow_mut() = 0);
|
||||
|
||||
let pre = ChargeTransactionPayment::<Runtime>::from(5 /* tipped */)
|
||||
.pre_dispatch(&2, CALL, &info_from_weight(100), len)
|
||||
.pre_dispatch(&2, CALL, &info_from_weight(Weight::from_ref_time(100)), len)
|
||||
.unwrap();
|
||||
assert_eq!(Balances::free_balance(2), 200 - 5 - 10 - 100 - 5);
|
||||
|
||||
assert_ok!(ChargeTransactionPayment::<Runtime>::post_dispatch(
|
||||
Some(pre),
|
||||
&info_from_weight(100),
|
||||
&post_info_from_weight(50),
|
||||
&info_from_weight(Weight::from_ref_time(100)),
|
||||
&post_info_from_weight(Weight::from_ref_time(50)),
|
||||
len,
|
||||
&Ok(())
|
||||
));
|
||||
@@ -1069,22 +1078,22 @@ mod tests {
|
||||
fn signed_extension_transaction_payment_multiplied_refund_works() {
|
||||
ExtBuilder::default()
|
||||
.balance_factor(10)
|
||||
.base_weight(5)
|
||||
.base_weight(Weight::from_ref_time(5))
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
let len = 10;
|
||||
<NextFeeMultiplier<Runtime>>::put(Multiplier::saturating_from_rational(3, 2));
|
||||
|
||||
let pre = ChargeTransactionPayment::<Runtime>::from(5 /* tipped */)
|
||||
.pre_dispatch(&2, CALL, &info_from_weight(100), len)
|
||||
.pre_dispatch(&2, CALL, &info_from_weight(Weight::from_ref_time(100)), 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(100),
|
||||
&post_info_from_weight(50),
|
||||
&info_from_weight(Weight::from_ref_time(100)),
|
||||
&post_info_from_weight(Weight::from_ref_time(50)),
|
||||
len,
|
||||
&Ok(())
|
||||
));
|
||||
@@ -1100,13 +1109,14 @@ mod tests {
|
||||
assert_ok!(ChargeTransactionPayment::<Runtime>::from(0).pre_dispatch(
|
||||
&1,
|
||||
CALL,
|
||||
&info_from_weight(Weight::max_value()),
|
||||
&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),
|
||||
(10000 - <Runtime as frame_system::Config>::BlockWeights::get().max_block) as u64
|
||||
(10000 -
|
||||
<Runtime as frame_system::Config>::BlockWeights::get().max_block.ref_time()) as u64
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -1114,7 +1124,7 @@ mod tests {
|
||||
#[test]
|
||||
fn signed_extension_allows_free_transactions() {
|
||||
ExtBuilder::default()
|
||||
.base_weight(100)
|
||||
.base_weight(Weight::from_ref_time(100))
|
||||
.balance_factor(0)
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
@@ -1125,7 +1135,7 @@ mod tests {
|
||||
|
||||
// This is a completely free (and thus wholly insecure/DoS-ridden) transaction.
|
||||
let operational_transaction = DispatchInfo {
|
||||
weight: 0,
|
||||
weight: Weight::from_ref_time(0),
|
||||
class: DispatchClass::Operational,
|
||||
pays_fee: Pays::No,
|
||||
};
|
||||
@@ -1137,8 +1147,11 @@ mod tests {
|
||||
));
|
||||
|
||||
// like a InsecureFreeNormal
|
||||
let free_transaction =
|
||||
DispatchInfo { weight: 0, class: DispatchClass::Normal, pays_fee: Pays::Yes };
|
||||
let free_transaction = DispatchInfo {
|
||||
weight: Weight::from_ref_time(0),
|
||||
class: DispatchClass::Normal,
|
||||
pays_fee: Pays::Yes,
|
||||
};
|
||||
assert_noop!(
|
||||
ChargeTransactionPayment::<Runtime>::from(0).validate(
|
||||
&1,
|
||||
@@ -1154,7 +1167,7 @@ mod tests {
|
||||
#[test]
|
||||
fn signed_ext_length_fee_is_also_updated_per_congestion() {
|
||||
ExtBuilder::default()
|
||||
.base_weight(5)
|
||||
.base_weight(Weight::from_ref_time(5))
|
||||
.balance_factor(10)
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
@@ -1162,8 +1175,10 @@ mod tests {
|
||||
<NextFeeMultiplier<Runtime>>::put(Multiplier::saturating_from_rational(3, 2));
|
||||
let len = 10;
|
||||
|
||||
assert_ok!(ChargeTransactionPayment::<Runtime>::from(10) // tipped
|
||||
.pre_dispatch(&1, CALL, &info_from_weight(3), len));
|
||||
assert_ok!(
|
||||
ChargeTransactionPayment::<Runtime>::from(10) // tipped
|
||||
.pre_dispatch(&1, CALL, &info_from_weight(Weight::from_ref_time(3)), len)
|
||||
);
|
||||
assert_eq!(
|
||||
Balances::free_balance(1),
|
||||
100 // original
|
||||
@@ -1188,48 +1203,54 @@ mod tests {
|
||||
let unsigned_xt = TestXt::<_, ()>::new(call, None);
|
||||
let unsigned_xt_info = unsigned_xt.get_dispatch_info();
|
||||
|
||||
ExtBuilder::default().base_weight(5).weight_fee(2).build().execute_with(|| {
|
||||
// all fees should be x1.5
|
||||
<NextFeeMultiplier<Runtime>>::put(Multiplier::saturating_from_rational(3, 2));
|
||||
ExtBuilder::default()
|
||||
.base_weight(Weight::from_ref_time(5))
|
||||
.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 */
|
||||
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) as u64 * 2 * 3 / 2 /* weight */
|
||||
},
|
||||
);
|
||||
+ 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) 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]
|
||||
@@ -1239,40 +1260,46 @@ mod tests {
|
||||
let encoded_call = call.encode();
|
||||
let len = encoded_call.len() as u32;
|
||||
|
||||
ExtBuilder::default().base_weight(5).weight_fee(2).build().execute_with(|| {
|
||||
// all fees should be x1.5
|
||||
<NextFeeMultiplier<Runtime>>::put(Multiplier::saturating_from_rational(3, 2));
|
||||
ExtBuilder::default()
|
||||
.base_weight(Weight::from_ref_time(5))
|
||||
.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 */
|
||||
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) as u64 * 2 * 3 / 2 /* weight */
|
||||
},
|
||||
);
|
||||
+ 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) 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]
|
||||
fn compute_fee_works_without_multiplier() {
|
||||
ExtBuilder::default()
|
||||
.base_weight(100)
|
||||
.base_weight(Weight::from_ref_time(100))
|
||||
.byte_fee(10)
|
||||
.balance_factor(0)
|
||||
.build()
|
||||
@@ -1282,14 +1309,14 @@ mod tests {
|
||||
|
||||
// Tip only, no fees works
|
||||
let dispatch_info = DispatchInfo {
|
||||
weight: 0,
|
||||
weight: Weight::from_ref_time(0),
|
||||
class: DispatchClass::Operational,
|
||||
pays_fee: Pays::No,
|
||||
};
|
||||
assert_eq!(Pallet::<Runtime>::compute_fee(0, &dispatch_info, 10), 10);
|
||||
// No tip, only base fee works
|
||||
let dispatch_info = DispatchInfo {
|
||||
weight: 0,
|
||||
weight: Weight::from_ref_time(0),
|
||||
class: DispatchClass::Operational,
|
||||
pays_fee: Pays::Yes,
|
||||
};
|
||||
@@ -1300,7 +1327,7 @@ mod tests {
|
||||
assert_eq!(Pallet::<Runtime>::compute_fee(42, &dispatch_info, 0), 520);
|
||||
// Weight fee + base fee works
|
||||
let dispatch_info = DispatchInfo {
|
||||
weight: 1000,
|
||||
weight: Weight::from_ref_time(1000),
|
||||
class: DispatchClass::Operational,
|
||||
pays_fee: Pays::Yes,
|
||||
};
|
||||
@@ -1311,7 +1338,7 @@ mod tests {
|
||||
#[test]
|
||||
fn compute_fee_works_with_multiplier() {
|
||||
ExtBuilder::default()
|
||||
.base_weight(100)
|
||||
.base_weight(Weight::from_ref_time(100))
|
||||
.byte_fee(10)
|
||||
.balance_factor(0)
|
||||
.build()
|
||||
@@ -1320,7 +1347,7 @@ mod tests {
|
||||
<NextFeeMultiplier<Runtime>>::put(Multiplier::saturating_from_rational(3, 2));
|
||||
// Base fee is unaffected by multiplier
|
||||
let dispatch_info = DispatchInfo {
|
||||
weight: 0,
|
||||
weight: Weight::from_ref_time(0),
|
||||
class: DispatchClass::Operational,
|
||||
pays_fee: Pays::Yes,
|
||||
};
|
||||
@@ -1328,7 +1355,7 @@ mod tests {
|
||||
|
||||
// Everything works together :)
|
||||
let dispatch_info = DispatchInfo {
|
||||
weight: 123,
|
||||
weight: Weight::from_ref_time(123),
|
||||
class: DispatchClass::Operational,
|
||||
pays_fee: Pays::Yes,
|
||||
};
|
||||
@@ -1343,7 +1370,7 @@ mod tests {
|
||||
#[test]
|
||||
fn compute_fee_works_with_negative_multiplier() {
|
||||
ExtBuilder::default()
|
||||
.base_weight(100)
|
||||
.base_weight(Weight::from_ref_time(100))
|
||||
.byte_fee(10)
|
||||
.balance_factor(0)
|
||||
.build()
|
||||
@@ -1353,7 +1380,7 @@ mod tests {
|
||||
|
||||
// Base fee is unaffected by multiplier.
|
||||
let dispatch_info = DispatchInfo {
|
||||
weight: 0,
|
||||
weight: Weight::from_ref_time(0),
|
||||
class: DispatchClass::Operational,
|
||||
pays_fee: Pays::Yes,
|
||||
};
|
||||
@@ -1361,7 +1388,7 @@ mod tests {
|
||||
|
||||
// Everything works together.
|
||||
let dispatch_info = DispatchInfo {
|
||||
weight: 123,
|
||||
weight: Weight::from_ref_time(123),
|
||||
class: DispatchClass::Operational,
|
||||
pays_fee: Pays::Yes,
|
||||
};
|
||||
@@ -1376,14 +1403,14 @@ mod tests {
|
||||
#[test]
|
||||
fn compute_fee_does_not_overflow() {
|
||||
ExtBuilder::default()
|
||||
.base_weight(100)
|
||||
.base_weight(Weight::from_ref_time(100))
|
||||
.byte_fee(10)
|
||||
.balance_factor(0)
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
// Overflow is handled
|
||||
let dispatch_info = DispatchInfo {
|
||||
weight: Weight::max_value(),
|
||||
weight: Weight::MAX,
|
||||
class: DispatchClass::Operational,
|
||||
pays_fee: Pays::Yes,
|
||||
};
|
||||
@@ -1398,14 +1425,14 @@ mod tests {
|
||||
fn refund_does_not_recreate_account() {
|
||||
ExtBuilder::default()
|
||||
.balance_factor(10)
|
||||
.base_weight(5)
|
||||
.base_weight(Weight::from_ref_time(5))
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
// So events are emitted
|
||||
System::set_block_number(10);
|
||||
let len = 10;
|
||||
let pre = ChargeTransactionPayment::<Runtime>::from(5 /* tipped */)
|
||||
.pre_dispatch(&2, CALL, &info_from_weight(100), len)
|
||||
.pre_dispatch(&2, CALL, &info_from_weight(Weight::from_ref_time(100)), len)
|
||||
.unwrap();
|
||||
assert_eq!(Balances::free_balance(2), 200 - 5 - 10 - 100 - 5);
|
||||
|
||||
@@ -1415,8 +1442,8 @@ mod tests {
|
||||
|
||||
assert_ok!(ChargeTransactionPayment::<Runtime>::post_dispatch(
|
||||
Some(pre),
|
||||
&info_from_weight(100),
|
||||
&post_info_from_weight(50),
|
||||
&info_from_weight(Weight::from_ref_time(100)),
|
||||
&post_info_from_weight(Weight::from_ref_time(50)),
|
||||
len,
|
||||
&Ok(())
|
||||
));
|
||||
@@ -1438,19 +1465,19 @@ mod tests {
|
||||
fn actual_weight_higher_than_max_refunds_nothing() {
|
||||
ExtBuilder::default()
|
||||
.balance_factor(10)
|
||||
.base_weight(5)
|
||||
.base_weight(Weight::from_ref_time(5))
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
let len = 10;
|
||||
let pre = ChargeTransactionPayment::<Runtime>::from(5 /* tipped */)
|
||||
.pre_dispatch(&2, CALL, &info_from_weight(100), len)
|
||||
.pre_dispatch(&2, CALL, &info_from_weight(Weight::from_ref_time(100)), len)
|
||||
.unwrap();
|
||||
assert_eq!(Balances::free_balance(2), 200 - 5 - 10 - 100 - 5);
|
||||
|
||||
assert_ok!(ChargeTransactionPayment::<Runtime>::post_dispatch(
|
||||
Some(pre),
|
||||
&info_from_weight(100),
|
||||
&post_info_from_weight(101),
|
||||
&info_from_weight(Weight::from_ref_time(100)),
|
||||
&post_info_from_weight(Weight::from_ref_time(101)),
|
||||
len,
|
||||
&Ok(())
|
||||
));
|
||||
@@ -1462,14 +1489,17 @@ mod tests {
|
||||
fn zero_transfer_on_free_transaction() {
|
||||
ExtBuilder::default()
|
||||
.balance_factor(10)
|
||||
.base_weight(5)
|
||||
.base_weight(Weight::from_ref_time(5))
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
// So events are emitted
|
||||
System::set_block_number(10);
|
||||
let len = 10;
|
||||
let dispatch_info =
|
||||
DispatchInfo { weight: 100, pays_fee: Pays::No, class: DispatchClass::Normal };
|
||||
let dispatch_info = DispatchInfo {
|
||||
weight: Weight::from_ref_time(100),
|
||||
pays_fee: Pays::No,
|
||||
class: DispatchClass::Normal,
|
||||
};
|
||||
let user = 69;
|
||||
let pre = ChargeTransactionPayment::<Runtime>::from(0)
|
||||
.pre_dispatch(&user, CALL, &dispatch_info, len)
|
||||
@@ -1498,11 +1528,11 @@ mod tests {
|
||||
fn refund_consistent_with_actual_weight() {
|
||||
ExtBuilder::default()
|
||||
.balance_factor(10)
|
||||
.base_weight(7)
|
||||
.base_weight(Weight::from_ref_time(7))
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
let info = info_from_weight(100);
|
||||
let post_info = post_info_from_weight(33);
|
||||
let info = info_from_weight(Weight::from_ref_time(100));
|
||||
let post_info = post_info_from_weight(Weight::from_ref_time(33));
|
||||
let prev_balance = Balances::free_balance(2);
|
||||
let len = 10;
|
||||
let tip = 5;
|
||||
@@ -1538,8 +1568,11 @@ mod tests {
|
||||
let len = 10;
|
||||
|
||||
ExtBuilder::default().balance_factor(100).build().execute_with(|| {
|
||||
let normal =
|
||||
DispatchInfo { weight: 100, class: DispatchClass::Normal, pays_fee: Pays::Yes };
|
||||
let normal = DispatchInfo {
|
||||
weight: Weight::from_ref_time(100),
|
||||
class: DispatchClass::Normal,
|
||||
pays_fee: Pays::Yes,
|
||||
};
|
||||
let priority = ChargeTransactionPayment::<Runtime>(tip)
|
||||
.validate(&2, CALL, &normal, len)
|
||||
.unwrap()
|
||||
@@ -1557,7 +1590,7 @@ mod tests {
|
||||
|
||||
ExtBuilder::default().balance_factor(100).build().execute_with(|| {
|
||||
let op = DispatchInfo {
|
||||
weight: 100,
|
||||
weight: Weight::from_ref_time(100),
|
||||
class: DispatchClass::Operational,
|
||||
pays_fee: Pays::Yes,
|
||||
};
|
||||
@@ -1581,8 +1614,11 @@ mod tests {
|
||||
let len = 10;
|
||||
|
||||
ExtBuilder::default().balance_factor(100).build().execute_with(|| {
|
||||
let normal =
|
||||
DispatchInfo { weight: 100, class: DispatchClass::Normal, pays_fee: Pays::Yes };
|
||||
let normal = DispatchInfo {
|
||||
weight: Weight::from_ref_time(100),
|
||||
class: DispatchClass::Normal,
|
||||
pays_fee: Pays::Yes,
|
||||
};
|
||||
let priority = ChargeTransactionPayment::<Runtime>(tip)
|
||||
.validate(&2, CALL, &normal, len)
|
||||
.unwrap()
|
||||
@@ -1593,7 +1629,7 @@ mod tests {
|
||||
|
||||
ExtBuilder::default().balance_factor(100).build().execute_with(|| {
|
||||
let op = DispatchInfo {
|
||||
weight: 100,
|
||||
weight: Weight::from_ref_time(100),
|
||||
class: DispatchClass::Operational,
|
||||
pays_fee: Pays::Yes,
|
||||
};
|
||||
@@ -1612,8 +1648,11 @@ mod tests {
|
||||
let mut priority2 = 0;
|
||||
let len = 10;
|
||||
ExtBuilder::default().balance_factor(100).build().execute_with(|| {
|
||||
let normal =
|
||||
DispatchInfo { weight: 100, class: DispatchClass::Normal, pays_fee: Pays::Yes };
|
||||
let normal = DispatchInfo {
|
||||
weight: Weight::from_ref_time(100),
|
||||
class: DispatchClass::Normal,
|
||||
pays_fee: Pays::Yes,
|
||||
};
|
||||
priority1 = ChargeTransactionPayment::<Runtime>(tip)
|
||||
.validate(&2, CALL, &normal, len)
|
||||
.unwrap()
|
||||
@@ -1622,7 +1661,7 @@ mod tests {
|
||||
|
||||
ExtBuilder::default().balance_factor(100).build().execute_with(|| {
|
||||
let op = DispatchInfo {
|
||||
weight: 100,
|
||||
weight: Weight::from_ref_time(100),
|
||||
class: DispatchClass::Operational,
|
||||
pays_fee: Pays::Yes,
|
||||
};
|
||||
@@ -1649,10 +1688,10 @@ mod tests {
|
||||
fn post_info_can_change_pays_fee() {
|
||||
ExtBuilder::default()
|
||||
.balance_factor(10)
|
||||
.base_weight(7)
|
||||
.base_weight(Weight::from_ref_time(7))
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
let info = info_from_weight(100);
|
||||
let info = info_from_weight(Weight::from_ref_time(100));
|
||||
let post_info = post_info_from_pays(Pays::No);
|
||||
let prev_balance = Balances::free_balance(2);
|
||||
let len = 10;
|
||||
|
||||
@@ -135,12 +135,12 @@ mod tests {
|
||||
#[test]
|
||||
fn should_serialize_and_deserialize_properly_with_string() {
|
||||
let info = RuntimeDispatchInfo {
|
||||
weight: 5,
|
||||
weight: Weight::from_ref_time(5),
|
||||
class: DispatchClass::Normal,
|
||||
partial_fee: 1_000_000_u64,
|
||||
};
|
||||
|
||||
let json_str = r#"{"weight":5,"class":"normal","partialFee":"1000000"}"#;
|
||||
let json_str = r#"{"weight":{"ref_time":5},"class":"normal","partialFee":"1000000"}"#;
|
||||
|
||||
assert_eq!(serde_json::to_string(&info).unwrap(), json_str);
|
||||
assert_eq!(serde_json::from_str::<RuntimeDispatchInfo<u64>>(json_str).unwrap(), info);
|
||||
@@ -152,12 +152,12 @@ mod tests {
|
||||
#[test]
|
||||
fn should_serialize_and_deserialize_properly_large_value() {
|
||||
let info = RuntimeDispatchInfo {
|
||||
weight: 5,
|
||||
weight: Weight::from_ref_time(5),
|
||||
class: DispatchClass::Normal,
|
||||
partial_fee: u128::max_value(),
|
||||
};
|
||||
|
||||
let json_str = r#"{"weight":5,"class":"normal","partialFee":"340282366920938463463374607431768211455"}"#;
|
||||
let json_str = r#"{"weight":{"ref_time":5},"class":"normal","partialFee":"340282366920938463463374607431768211455"}"#;
|
||||
|
||||
assert_eq!(serde_json::to_string(&info).unwrap(), json_str);
|
||||
assert_eq!(serde_json::from_str::<RuntimeDispatchInfo<u128>>(json_str).unwrap(), info);
|
||||
|
||||
Reference in New Issue
Block a user