11#![ allow( unsafe_op_in_unsafe_fn) ]
2+ #![ allow( clippy:: missing_safety_doc) ]
3+ #![ allow( clippy:: arithmetic_side_effects) ]
24
35use {
46 core:: { alloc:: Layout , ptr:: null_mut, slice} ,
@@ -25,7 +27,7 @@ fn set_buffer_length(base_address: u64, new_length: u64) -> u64 {
2527 unsafe {
2628 let syscall: extern "C" fn ( u64 , u64 , u64 , u64 , u64 ) -> u64 =
2729 core:: mem:: transmute ( 0x713026f5u64 ) ;
28- syscall ( base_address as u64 , new_length, 0 , 0 , 0 )
30+ syscall ( base_address, new_length, 0 , 0 , 0 )
2931 }
3032}
3133
@@ -149,7 +151,7 @@ unsafe fn test_valid_accesses(
149151 assert_eq ! ( current_ix. index_of_caller_instruction, u16 :: MAX ) ;
150152
151153 if tx_frame. current_executing_instruction == 0 {
152- let ix_accounts = current_ix. instruction_accounts . deref ( ) ;
154+ let ix_accounts = current_ix. instruction_accounts . as_slice ( ) ;
153155 assert_eq ! ( ix_accounts. len( ) , 2 ) ;
154156 assert ! (
155157 ix_accounts. get_unchecked( 0 ) . is_writable( ) && ix_accounts. get_unchecked( 0 ) . is_signer( )
@@ -163,16 +165,16 @@ unsafe fn test_valid_accesses(
163165 . get_unchecked ( ix_accounts. get_unchecked ( 0 ) . index_in_transaction as usize ) ;
164166 assert_eq ! ( acc_1. lamports, 223450 ) ;
165167 assert_eq ! ( acc_1. owner. to_bytes( ) , [ 0u8 ; 32 ] ) ;
166- assert_eq ! ( acc_1. payload. deref ( ) , & [ 1 , 2 , 3 ] ) ;
168+ assert_eq ! ( acc_1. payload. as_slice ( ) , & [ 1 , 2 , 3 ] ) ;
167169
168170 let acc_2 = tx_accounts_metadata
169171 . get_unchecked ( ix_accounts. get_unchecked ( 1 ) . index_in_transaction as usize ) ;
170172 assert_eq ! ( acc_2. lamports, 90123 ) ;
171- assert_eq ! ( acc_2. key. to_bytes( ) , acc_2. payload. deref ( ) ) ;
173+ assert_eq ! ( acc_2. key. to_bytes( ) , acc_2. payload. as_slice ( ) ) ;
172174
173- assert_eq ! ( current_ix. instruction_data. deref ( ) , b"\x02 " ) ;
175+ assert_eq ! ( current_ix. instruction_data. as_slice ( ) , b"\x02 " ) ;
174176 } else if tx_frame. current_executing_instruction == 1 {
175- let ix_accounts = current_ix. instruction_accounts . deref ( ) ;
177+ let ix_accounts = current_ix. instruction_accounts . as_slice ( ) ;
176178 assert_eq ! ( ix_accounts. len( ) , 2 ) ;
177179 assert ! (
178180 !ix_accounts. get_unchecked( 0 ) . is_writable( ) && ix_accounts. get_unchecked( 0 ) . is_signer( )
@@ -185,14 +187,14 @@ unsafe fn test_valid_accesses(
185187 . get_unchecked ( ix_accounts. get_unchecked ( 0 ) . index_in_transaction as usize ) ;
186188 assert_eq ! ( acc_1. lamports, 35 ) ;
187189 assert_eq ! ( acc_1. owner. to_bytes( ) , [ 0u8 ; 32 ] ) ;
188- assert_eq ! ( acc_1. payload. deref ( ) , & [ 3 , 4 , 5 ] ) ;
190+ assert_eq ! ( acc_1. payload. as_slice ( ) , & [ 3 , 4 , 5 ] ) ;
189191
190192 let acc_2 = tx_accounts_metadata
191193 . get_unchecked ( ix_accounts. get_unchecked ( 1 ) . index_in_transaction as usize ) ;
192194 assert_eq ! ( acc_2. lamports, 9123 ) ;
193195 assert_eq ! ( acc_2. owner, acc_1. key) ;
194196
195- assert_eq ! ( current_ix. instruction_data. deref ( ) , b"\x03 " ) ;
197+ assert_eq ! ( current_ix. instruction_data. as_slice ( ) , b"\x03 " ) ;
196198 } else {
197199 panic ! ( "Not expecting more than two instructions." )
198200 }
@@ -211,13 +213,13 @@ unsafe fn write_to_account(
211213 current_ix : & InstructionFrame ,
212214 tx_accounts_metadata : & mut [ AccountSharedFields ] ,
213215) {
214- let ix_accounts = current_ix. instruction_accounts . deref ( ) ;
216+ let ix_accounts = current_ix. instruction_accounts . as_slice ( ) ;
215217 let ix_account = ix_accounts. get_unchecked ( 0 ) ;
216218
217219 let account_data = tx_accounts_metadata
218220 . get_unchecked_mut ( ix_account. index_in_transaction as usize )
219221 . payload
220- . deref_mut ( ) ;
222+ . as_slice_mut ( ) ;
221223 * account_data. get_unchecked_mut ( 0 ) = 7 ;
222224 * account_data. get_unchecked_mut ( 1 ) = 8 ;
223225 * account_data. get_unchecked_mut ( 2 ) = 9 ;
@@ -244,15 +246,15 @@ unsafe fn test_set_buffer_length_account(
244246 let meta = & account_metadata[ account_idx as usize ] ;
245247 assert_eq ! ( meta. payload. len( ) , 3 ) ;
246248 let mut expected_data = [ 0 ; 6 ] ;
247- expected_data[ ..3 ] . copy_from_slice ( meta. payload . deref ( ) ) ;
249+ expected_data[ ..3 ] . copy_from_slice ( meta. payload . as_slice ( ) ) ;
248250 set_buffer_length ( meta. payload . ptr ( ) , 6 ) ;
249251 assert_eq ! ( meta. payload. len( ) , 6 ) ;
250252 let account_data = core:: slice:: from_raw_parts ( meta. payload . ptr ( ) as * const u8 , 6 ) ;
251253 assert_eq ! ( account_data, expected_data) ;
252254}
253255
254256unsafe fn test_assign_owner ( ix_ctx : & InstructionFrame , accounts : & mut [ AccountSharedFields ] ) {
255- let ix_accounts = ix_ctx. instruction_accounts . deref ( ) ;
257+ let ix_accounts = ix_ctx. instruction_accounts . as_slice ( ) ;
256258 let first_account_idx_in_tx = ix_accounts. get_unchecked ( 0 ) . index_in_transaction as usize ;
257259 let second_account_idx_in_tx = ix_accounts. get_unchecked ( 1 ) . index_in_transaction as usize ;
258260 let debug_str = format ! (
@@ -262,14 +264,14 @@ unsafe fn test_assign_owner(ix_ctx: &InstructionFrame, accounts: &mut [AccountSh
262264 sol_log ( debug_str. as_bytes ( ) ) ;
263265
264266 let first_account = accounts. get_unchecked ( first_account_idx_in_tx) ;
265- let new_ower = Pubkey :: new_from_array ( first_account. payload . deref ( ) [ 0 ..32 ] . try_into ( ) . unwrap ( ) ) ;
266- let write_to_account_afterwards = first_account. payload . deref ( ) [ 32 ] ;
267+ let new_ower =
268+ Pubkey :: new_from_array ( first_account. payload . as_slice ( ) [ 0 ..32 ] . try_into ( ) . unwrap ( ) ) ;
269+ let write_to_account_afterwards = first_account. payload . as_slice ( ) [ 32 ] ;
267270
268271 // Asserting old owner
269272 let program_id = accounts
270273 . get_unchecked ( ix_ctx. program_account_index_in_tx as usize )
271- . key
272- . clone ( ) ;
274+ . key ;
273275 let second_account = accounts. get_unchecked_mut ( second_account_idx_in_tx) ;
274276 assert_eq ! ( program_id, second_account. owner) ;
275277
@@ -282,15 +284,15 @@ unsafe fn test_assign_owner(ix_ctx: &InstructionFrame, accounts: &mut [AccountSh
282284 // I cannot write to the account after changing its owner
283285 // This write should fail
284286 if write_to_account_afterwards == 1 {
285- * second_account. payload . deref_mut ( ) . get_unchecked_mut ( 0 ) = 9 ;
287+ * second_account. payload . as_slice_mut ( ) . get_unchecked_mut ( 0 ) = 9 ;
286288 }
287289}
288290
289291unsafe fn test_sol_transfer_lamports (
290292 account_metadata : & mut [ AccountSharedFields ] ,
291293 ix_frame : & InstructionFrame ,
292294) {
293- let instruction_accounts = ix_frame. instruction_accounts . deref ( ) ;
295+ let instruction_accounts = ix_frame. instruction_accounts . as_slice ( ) ;
294296 let to_account_idx_tx = instruction_accounts. get_unchecked ( 0 ) . index_in_transaction as usize ;
295297 let from_account_idx_tx = instruction_accounts. get_unchecked ( 1 ) . index_in_transaction as usize ;
296298
@@ -334,7 +336,7 @@ pub unsafe extern "C" fn entrypoint() -> u64 {
334336 let current_ix = instruction_trace
335337 . get ( tx_frame. current_executing_instruction as usize )
336338 . unwrap ( ) ;
337- match current_ix. instruction_data . deref ( ) {
339+ match current_ix. instruction_data . as_slice ( ) {
338340 [ 0x00 , ..] => {
339341 let mes = format ! ( "tx accs: {}" , tx_frame. number_of_transaction_accounts) ;
340342 sol_log ( mes. as_bytes ( ) ) ;
0 commit comments