Skip to content
Snippets Groups Projects
Commit 848dbf0a authored by bgallois's avatar bgallois Committed by Hugo Trentesaux
Browse files

refactore fee tests

parent ac3ca587
No related branches found
No related tags found
No related merge requests found
...@@ -38,8 +38,14 @@ fn test_fees_empty() { ...@@ -38,8 +38,14 @@ fn test_fees_empty() {
value: 500, value: 500,
}); });
let xt = let xt = common::get_unchecked_extrinsic(
common::get_unchecked_extrinsic(call, 4u64, 8u64, AccountKeyring::Alice, 0u64, 0); call,
4u64,
8u64,
AccountKeyring::Alice,
0u64,
0u32,
);
assert_ok!(Executive::apply_extrinsic(xt)); assert_ok!(Executive::apply_extrinsic(xt));
// The block is almost empty, so the extrinsic should incur no fee // The block is almost empty, so the extrinsic should incur no fee
assert_eq!( assert_eq!(
...@@ -61,35 +67,25 @@ fn test_fees_weight() { ...@@ -61,35 +67,25 @@ fn test_fees_weight() {
]) ])
.build() .build()
.execute_with(|| { .execute_with(|| {
let mut transactions = 0u64;
let weights = BlockWeights::get(); let weights = BlockWeights::get();
let normal_max_weight = weights let normal_max_weight = weights
.get(DispatchClass::Normal) .get(DispatchClass::Normal)
.max_total .max_total
.unwrap_or(weights.max_block); .unwrap_or(weights.max_block);
// Stopping just below the limit
while System::block_weight() // Ensure that the next extrinsic is below the limit.
.get(DispatchClass::Normal) System::set_block_consumed_resources(Weight::zero(), 0_usize);
.all_lt(Target::get() * normal_max_weight * Perbill::from_percent(99))
{
let call = RuntimeCall::System(SystemCall::remark { let call = RuntimeCall::System(SystemCall::remark {
remark: vec![255u8; 1], remark: vec![255u8; 1],
}); });
let xt = get_unchecked_extrinsic( let xt = get_unchecked_extrinsic(call, 4u64, 8u64, AccountKeyring::Alice, 0u64, 0);
call,
4u64,
8u64,
AccountKeyring::Alice,
0u64,
transactions as u32,
);
assert_ok!(Executive::apply_extrinsic(xt)); assert_ok!(Executive::apply_extrinsic(xt));
transactions += 1;
}
assert_eq!( assert_eq!(
Balances::free_balance(AccountKeyring::Alice.to_account_id()), Balances::free_balance(AccountKeyring::Alice.to_account_id()),
10_000 10_000
); );
// Ensure that the next extrinsic exceeds the limit. // Ensure that the next extrinsic exceeds the limit.
System::set_block_consumed_resources(Target::get() * normal_max_weight, 0_usize); System::set_block_consumed_resources(Target::get() * normal_max_weight, 0_usize);
// The block will reach the fee limit, so the next extrinsic should start incurring fees. // The block will reach the fee limit, so the next extrinsic should start incurring fees.
...@@ -97,14 +93,7 @@ fn test_fees_weight() { ...@@ -97,14 +93,7 @@ fn test_fees_weight() {
remark: vec![255u8; 1], remark: vec![255u8; 1],
}); });
let xt = get_unchecked_extrinsic( let xt = get_unchecked_extrinsic(call, 4u64, 8u64, AccountKeyring::Alice, 0u64, 1u32);
call,
4u64,
8u64,
AccountKeyring::Alice,
0u64,
transactions as u32,
);
assert_ok!(Executive::apply_extrinsic(xt)); assert_ok!(Executive::apply_extrinsic(xt));
assert_ne!( assert_ne!(
Balances::free_balance(AccountKeyring::Alice.to_account_id()), Balances::free_balance(AccountKeyring::Alice.to_account_id()),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment