1919use bulletin_westend_runtime:: {
2020 xcm_config:: { GovernanceLocation , LocationToAccountId } ,
2121 AllPalletsWithoutSystem , Block , Runtime , RuntimeCall , RuntimeEvent , RuntimeOrigin , SessionKeys ,
22- System , TxExtension , UncheckedExtrinsic ,
22+ System , SystemConfig , TxExtension , UncheckedExtrinsic ,
2323} ;
2424use frame_support:: {
2525 assert_err, assert_ok, dispatch:: GetDispatchInfo , traits:: fungible:: Mutate as FungibleMutate ,
@@ -28,7 +28,9 @@ use parachains_common::{AccountId, AuraId, Balance, Hash as PcHash, Signature as
2828use parachains_runtimes_test_utils:: { ExtBuilder , GovernanceOrigin , RuntimeHelper } ;
2929use sp_core:: { crypto:: Ss58Codec , Encode , Pair } ;
3030use sp_keyring:: Sr25519Keyring ;
31- use sp_runtime:: { transaction_validity:: InvalidTransaction , ApplyExtrinsicResult , Either } ;
31+ use sp_runtime:: {
32+ transaction_validity, transaction_validity:: InvalidTransaction , ApplyExtrinsicResult , Either ,
33+ } ;
3234use testnet_parachains_constants:: westend:: { fee:: WeightToFee , locations:: PeopleLocation } ;
3335use xcm:: latest:: prelude:: * ;
3436use xcm_runtime_apis:: conversions:: LocationToAccountHelper ;
@@ -211,8 +213,7 @@ fn transaction_storage_max_throughput_per_block() {
211213 use sp_keyring:: Sr25519Keyring ;
212214
213215 const NUM_TRANSACTIONS : u32 = 8 ;
214- const TRANSACTION_SIZE : usize = 1024 * 1024 ; // 1 MiB
215- const TOTAL_BYTES : u64 = ( NUM_TRANSACTIONS as u64 ) * ( TRANSACTION_SIZE as u64 ) ; // 8 MiB
216+ const TRANSACTION_SIZE : u64 = 1024 * 1024 ; // 1 MiB
216217
217218 sp_io:: TestExternalities :: new (
218219 runtime:: RuntimeGenesisConfig :: default ( ) . build_storage ( ) . unwrap ( ) ,
@@ -225,16 +226,19 @@ fn transaction_storage_max_throughput_per_block() {
225226 let initial: Balance = 10_000_000_000_000_000_000u128 ;
226227 <pallet_balances:: Pallet < Runtime > as FungibleMutate < _ > >:: set_balance ( & who, initial) ;
227228
228- // authorize 8 transactions of 1 MiB each
229+ // authorize 8+1 transactions of 1 MiB each
229230 assert_ok ! ( runtime:: TransactionStorage :: authorize_account(
230231 RuntimeOrigin :: root( ) ,
231232 who. clone( ) ,
232- NUM_TRANSACTIONS ,
233- TOTAL_BYTES ,
233+ NUM_TRANSACTIONS + 1 ,
234+ ( NUM_TRANSACTIONS as u64 + 1 ) * TRANSACTION_SIZE ,
234235 ) ) ;
235236 assert_eq ! (
236237 runtime:: TransactionStorage :: account_authorization_extent( who. clone( ) ) ,
237- AuthorizationExtent { transactions: NUM_TRANSACTIONS , bytes: TOTAL_BYTES } ,
238+ AuthorizationExtent {
239+ transactions: NUM_TRANSACTIONS + 1 ,
240+ bytes: ( NUM_TRANSACTIONS as u64 + 1 ) * TRANSACTION_SIZE
241+ } ,
238242 ) ;
239243
240244 // Advance to a fresh block
@@ -245,17 +249,30 @@ fn transaction_storage_max_throughput_per_block() {
245249 let res = construct_and_apply_extrinsic (
246250 account. pair ( ) ,
247251 RuntimeCall :: TransactionStorage ( TxStorageCall :: < Runtime > :: store {
248- data : vec ! [ 0u8 ; TRANSACTION_SIZE ] ,
252+ data : vec ! [ 0u8 ; TRANSACTION_SIZE as _ ] ,
249253 } ) ,
250254 ) ;
251255 assert_ok ! ( res) ;
252256 assert_ok ! ( res. unwrap( ) ) ;
253257 }
254258
255- // Verify all authorizations were consumed
259+ // 9th should fail.
260+ assert_err ! (
261+ construct_and_apply_extrinsic(
262+ account. pair( ) ,
263+ RuntimeCall :: TransactionStorage ( TxStorageCall :: <Runtime >:: store {
264+ data: vec![ 0u8 ; TRANSACTION_SIZE as _] ,
265+ } ) ,
266+ ) ,
267+ transaction_validity:: TransactionValidityError :: Invalid (
268+ InvalidTransaction :: ExhaustsResources
269+ )
270+ ) ;
271+
272+ // Verify just 8 authorizations were consumed
256273 assert_eq ! (
257274 runtime:: TransactionStorage :: account_authorization_extent( who. clone( ) ) ,
258- AuthorizationExtent { transactions: 0 , bytes: 0 } ,
275+ AuthorizationExtent { transactions: 1 , bytes: TRANSACTION_SIZE } ,
259276 ) ;
260277 } ) ;
261278}
0 commit comments