@@ -13,14 +13,17 @@ use sp_runtime::ApplyExtrinsicResult;
1313use pallet_transaction_storage:: DEFAULT_MAX_TRANSACTION_SIZE ;
1414
1515fn advance_block ( ) {
16- Executive :: finalize_block ( ) ;
17- let next_number = System :: block_number ( ) + 1 ;
16+ let current_number = System :: block_number ( ) ;
17+ if current_number > 0 {
18+ Executive :: finalize_block ( ) ;
19+ }
20+ let next_number = current_number + 1 ;
1821 let header = Header :: new ( next_number, Default :: default ( ) , Default :: default ( ) , Default :: default ( ) , Default :: default ( ) ) ;
1922 Executive :: initialize_block ( & header) ;
2023
2124 let slot = runtime:: Babe :: current_slot ( ) ;
2225 let now = slot. saturated_into :: < u64 > ( ) * runtime:: SLOT_DURATION ;
23- runtime:: Timestamp :: set ( RuntimeOrigin :: none ( ) , now) . unwrap ( ) ;
26+ assert_ok ! ( runtime:: Timestamp :: set( RuntimeOrigin :: none( ) , now) ) ;
2427}
2528
2629fn construct_extrinsic (
@@ -79,16 +82,11 @@ fn transaction_storage_runtime_sizes() {
7982 runtime:: RuntimeGenesisConfig :: default ( ) . build_storage ( ) . unwrap ( ) ,
8083 )
8184 . execute_with ( || {
82- // Start at block 1
83- runtime:: System :: set_block_number ( 1 ) ;
84- runtime:: TransactionStorage :: on_initialize ( 1 ) ;
85- // set timestamp for block 1
86- let slot = runtime:: Babe :: current_slot ( ) ;
87- let now = slot. saturated_into :: < u64 > ( ) * runtime:: SLOT_DURATION ;
88- runtime:: Timestamp :: set ( RuntimeOrigin :: none ( ) , now) . unwrap ( ) ;
85+ advance_block ( ) ;
8986
90-
91- let who: runtime:: AccountId = sp_keyring:: Sr25519Keyring :: Alice . to_account_id ( ) ;
87+ // prepare data
88+ let account = Sr25519Keyring :: Alice ;
89+ let who: runtime:: AccountId = account. to_account_id ( ) ;
9290 let sizes: [ usize ; 5 ] = [
9391 2000 , // 2 KB
9492 1 * 1024 * 1024 , // 1 MB
@@ -98,6 +96,7 @@ fn transaction_storage_runtime_sizes() {
9896 ] ;
9997 let total_bytes: u64 = sizes. iter ( ) . map ( |s| * s as u64 ) . sum ( ) ;
10098
99+ // authorize
101100 assert_ok ! ( runtime:: TransactionStorage :: authorize_account(
102101 runtime:: RuntimeOrigin :: root( ) ,
103102 who. clone( ) ,
@@ -109,10 +108,10 @@ fn transaction_storage_runtime_sizes() {
109108 AuthorizationExtent { transactions: sizes. len( ) as u32 , bytes: total_bytes } ,
110109 ) ;
111110
112- let alice_pair = Sr25519Keyring :: Alice . pair ( ) ;
111+ // store data
113112 for size in sizes {
114113 let call = RuntimeCall :: TransactionStorage ( TxCall :: < runtime:: Runtime > :: store { data : vec ! [ 0u8 ; size] } ) ;
115- let res = construct_and_apply_extrinsic ( alice_pair . clone ( ) , call) ;
114+ let res = construct_and_apply_extrinsic ( account . pair ( ) , call) ;
116115 assert ! ( res. is_ok( ) , "Failed at size={} bytes: {:?}" , size, res) ;
117116
118117 advance_block ( ) ;
@@ -127,12 +126,12 @@ fn transaction_storage_runtime_sizes() {
127126 let oversize: usize = DEFAULT_MAX_TRANSACTION_SIZE as usize + 1 ; //11 * 1024 * 1024;
128127 assert_ok ! ( runtime:: TransactionStorage :: authorize_account(
129128 runtime:: RuntimeOrigin :: root( ) ,
130- who. clone ( ) ,
129+ who,
131130 1 ,
132131 oversize as u64 ,
133132 ) ) ;
134133 let too_big_call = RuntimeCall :: TransactionStorage ( TxCall :: < runtime:: Runtime > :: store { data : vec ! [ 0u8 ; oversize] } ) ;
135- let res = construct_and_apply_extrinsic ( alice_pair , too_big_call) ;
134+ let res = construct_and_apply_extrinsic ( account . pair ( ) , too_big_call) ;
136135 assert_eq ! (
137136 res,
138137 Err ( BAD_DATA_SIZE . into( ) )
0 commit comments