@@ -16,15 +16,10 @@ use crate::rust_oracle::{
16
16
pubkey_equal,
17
17
pubkey_is_zero,
18
18
} ;
19
+ use crate :: tests:: test_utils:: AccountSetup ;
19
20
use 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 ;
23
21
use solana_program:: program_error:: ProgramError ;
24
22
use solana_program:: pubkey:: Pubkey ;
25
- use solana_program:: rent:: Rent ;
26
- use solana_program:: system_program;
27
- use std:: mem:: size_of;
28
23
29
24
#[ test]
30
25
fn test_add_mapping ( ) {
@@ -35,61 +30,23 @@ fn test_add_mapping() {
35
30
let instruction_data = bytes_of :: < cmd_hdr_t > ( & hdr) ;
36
31
37
32
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 ( ) ;
42
33
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 ( ) ;
69
36
37
+ let mut curr_mapping_setup = AccountSetup :: new :: < pc_map_table_t > ( & program_id) ;
38
+ let cur_mapping = curr_mapping_setup. to_account_info ( ) ;
70
39
initialize_checked :: < pc_map_table_t > ( & cur_mapping, PC_VERSION ) . unwrap ( ) ;
71
40
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
+
72
44
{
73
45
let mut cur_mapping_data =
74
46
load_checked :: < pc_map_table_t > ( & cur_mapping, PC_VERSION ) . unwrap ( ) ;
75
47
cur_mapping_data. num_ = PC_MAP_TABLE_SIZE ;
76
48
}
77
49
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
-
93
50
assert ! ( add_mapping(
94
51
& program_id,
95
52
& [
@@ -108,7 +65,7 @@ fn test_add_mapping() {
108
65
109
66
assert ! ( pubkey_equal(
110
67
& cur_mapping_data. next_,
111
- & next_mapping_key . to_bytes( )
68
+ & next_mapping . key . to_bytes( )
112
69
) ) ;
113
70
assert ! ( pubkey_is_zero( & next_mapping_data. next_) ) ;
114
71
pubkey_assign ( & mut cur_mapping_data. next_ , & Pubkey :: default ( ) . to_bytes ( ) ) ;
0 commit comments