From 848dbf0ab4cf8ca1b337c966e052078813336386 Mon Sep 17 00:00:00 2001 From: bgallois <benjamin@gallois.cc> Date: Mon, 23 Sep 2024 19:43:51 +0200 Subject: [PATCH] refactore fee tests --- runtime/gdev/tests/fee_tests.rs | 49 +++++++++++++-------------------- 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/runtime/gdev/tests/fee_tests.rs b/runtime/gdev/tests/fee_tests.rs index 796cf1221..14c7f15e3 100644 --- a/runtime/gdev/tests/fee_tests.rs +++ b/runtime/gdev/tests/fee_tests.rs @@ -38,8 +38,14 @@ fn test_fees_empty() { value: 500, }); - let xt = - common::get_unchecked_extrinsic(call, 4u64, 8u64, AccountKeyring::Alice, 0u64, 0); + let xt = common::get_unchecked_extrinsic( + call, + 4u64, + 8u64, + AccountKeyring::Alice, + 0u64, + 0u32, + ); assert_ok!(Executive::apply_extrinsic(xt)); // The block is almost empty, so the extrinsic should incur no fee assert_eq!( @@ -61,35 +67,25 @@ fn test_fees_weight() { ]) .build() .execute_with(|| { - let mut transactions = 0u64; let weights = BlockWeights::get(); let normal_max_weight = weights .get(DispatchClass::Normal) .max_total .unwrap_or(weights.max_block); - // Stopping just below the limit - while System::block_weight() - .get(DispatchClass::Normal) - .all_lt(Target::get() * normal_max_weight * Perbill::from_percent(99)) - { - let call = RuntimeCall::System(SystemCall::remark { - remark: vec![255u8; 1], - }); - let xt = get_unchecked_extrinsic( - call, - 4u64, - 8u64, - AccountKeyring::Alice, - 0u64, - transactions as u32, - ); - assert_ok!(Executive::apply_extrinsic(xt)); - transactions += 1; - } + + // Ensure that the next extrinsic is below the limit. + System::set_block_consumed_resources(Weight::zero(), 0_usize); + + let call = RuntimeCall::System(SystemCall::remark { + remark: vec![255u8; 1], + }); + let xt = get_unchecked_extrinsic(call, 4u64, 8u64, AccountKeyring::Alice, 0u64, 0); + assert_ok!(Executive::apply_extrinsic(xt)); assert_eq!( Balances::free_balance(AccountKeyring::Alice.to_account_id()), 10_000 ); + // Ensure that the next extrinsic exceeds the limit. 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. @@ -97,14 +93,7 @@ fn test_fees_weight() { remark: vec![255u8; 1], }); - let xt = get_unchecked_extrinsic( - call, - 4u64, - 8u64, - AccountKeyring::Alice, - 0u64, - transactions as u32, - ); + let xt = get_unchecked_extrinsic(call, 4u64, 8u64, AccountKeyring::Alice, 0u64, 1u32); assert_ok!(Executive::apply_extrinsic(xt)); assert_ne!( Balances::free_balance(AccountKeyring::Alice.to_account_id()), -- GitLab