@@ -16,15 +16,10 @@ use crate::rust_oracle::{
1616 pubkey_equal,
1717 pubkey_is_zero,
1818} ;
19+ use crate :: tests:: test_utils:: AccountSetup ;
1920use bytemuck:: bytes_of;
20- use solana_program:: account_info:: AccountInfo ;
21- use solana_program:: clock:: Epoch ;
22- use solana_program:: native_token:: LAMPORTS_PER_SOL ;
2321use solana_program:: program_error:: ProgramError ;
2422use solana_program:: pubkey:: Pubkey ;
25- use solana_program:: rent:: Rent ;
26- use solana_program:: system_program;
27- use std:: mem:: size_of;
2823
2924#[ test]
3025fn test_add_mapping ( ) {
@@ -35,61 +30,23 @@ fn test_add_mapping() {
3530 let instruction_data = bytes_of :: < cmd_hdr_t > ( & hdr) ;
3631
3732 let program_id = Pubkey :: new_unique ( ) ;
38- let funding_key = Pubkey :: new_unique ( ) ;
39- let cur_mapping_key = Pubkey :: new_unique ( ) ;
40- let next_mapping_key = Pubkey :: new_unique ( ) ;
41- let system_program = system_program:: id ( ) ;
4233
43- let mut funding_balance = LAMPORTS_PER_SOL . clone ( ) ;
44- let funding_account = AccountInfo :: new (
45- & funding_key,
46- true ,
47- true ,
48- & mut funding_balance,
49- & mut [ ] ,
50- & system_program,
51- false ,
52- Epoch :: default ( ) ,
53- ) ;
54-
55- let mut cur_mapping_balance =
56- Rent :: minimum_balance ( & Rent :: default ( ) , size_of :: < pc_map_table_t > ( ) ) ;
57- let mut cur_mapping_raw_data = [ 0u8 ; size_of :: < pc_map_table_t > ( ) ] ;
58-
59- let cur_mapping = AccountInfo :: new (
60- & cur_mapping_key,
61- true ,
62- true ,
63- & mut cur_mapping_balance,
64- & mut cur_mapping_raw_data,
65- & program_id,
66- false ,
67- Epoch :: default ( ) ,
68- ) ;
34+ let mut funding_setup = AccountSetup :: new_funding ( ) ;
35+ let funding_account = funding_setup. to_account_info ( ) ;
6936
37+ let mut curr_mapping_setup = AccountSetup :: new :: < pc_map_table_t > ( & program_id) ;
38+ let cur_mapping = curr_mapping_setup. to_account_info ( ) ;
7039 initialize_checked :: < pc_map_table_t > ( & cur_mapping, PC_VERSION ) . unwrap ( ) ;
7140
41+ let mut next_mapping_setup = AccountSetup :: new :: < pc_map_table_t > ( & program_id) ;
42+ let next_mapping = next_mapping_setup. to_account_info ( ) ;
43+
7244 {
7345 let mut cur_mapping_data =
7446 load_checked :: < pc_map_table_t > ( & cur_mapping, PC_VERSION ) . unwrap ( ) ;
7547 cur_mapping_data. num_ = PC_MAP_TABLE_SIZE ;
7648 }
7749
78- let mut next_mapping_balance =
79- Rent :: minimum_balance ( & Rent :: default ( ) , size_of :: < pc_map_table_t > ( ) ) ;
80- let mut next_mapping_raw_data = [ 0u8 ; size_of :: < pc_map_table_t > ( ) ] ;
81-
82- let next_mapping = AccountInfo :: new (
83- & next_mapping_key,
84- true ,
85- true ,
86- & mut next_mapping_balance,
87- & mut next_mapping_raw_data,
88- & program_id,
89- false ,
90- Epoch :: default ( ) ,
91- ) ;
92-
9350 assert ! ( add_mapping(
9451 & program_id,
9552 & [
@@ -108,7 +65,7 @@ fn test_add_mapping() {
10865
10966 assert ! ( pubkey_equal(
11067 & cur_mapping_data. next_,
111- & next_mapping_key . to_bytes( )
68+ & next_mapping . key . to_bytes( )
11269 ) ) ;
11370 assert ! ( pubkey_is_zero( & next_mapping_data. next_) ) ;
11471 pubkey_assign ( & mut cur_mapping_data. next_ , & Pubkey :: default ( ) . to_bytes ( ) ) ;
0 commit comments