Skip to content

Commit 21ec242

Browse files
committed
Add return data checks
1 parent 7e2b908 commit 21ec242

File tree

1 file changed

+18
-40
lines changed

1 file changed

+18
-40
lines changed

program/tests/processor.rs

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,9 @@ use {
2929
},
3030
state::{Account, AccountState, Mint, Multisig},
3131
},
32-
std::{
33-
collections::HashMap,
34-
sync::{Arc, RwLock},
35-
},
32+
std::collections::HashMap,
3633
};
3734

38-
lazy_static::lazy_static! {
39-
static ref EXPECTED_DATA: Arc<RwLock<Vec<u8>>> = Arc::new(RwLock::new(Vec::new()));
40-
}
41-
4235
fn do_process_instruction(
4336
instruction: Instruction,
4437
mut accounts: Vec<&mut SolanaAccount>,
@@ -123,10 +116,6 @@ fn do_process_instruction_dups(
123116
.map_err(|e| ProgramError::try_from(e).unwrap())
124117
}
125118

126-
fn set_expected_data(expected_data: Vec<u8>) {
127-
*EXPECTED_DATA.write().unwrap() = expected_data;
128-
}
129-
130119
fn rent_sysvar() -> SolanaAccount {
131120
create_account_for_test(&Rent::default())
132121
}
@@ -6066,11 +6055,13 @@ fn test_get_account_data_size() {
60666055
)
60676056
.unwrap();
60686057

6069-
set_expected_data(Account::LEN.to_le_bytes().to_vec());
60706058
do_process_instruction(
60716059
get_account_data_size(&program_id, &mint_key).unwrap(),
60726060
vec![&mut mint_account],
6073-
&[Check::success()],
6061+
&[
6062+
Check::success(),
6063+
Check::return_data(&Account::LEN.to_le_bytes()),
6064+
],
60746065
)
60756066
.unwrap();
60766067
}
@@ -6159,35 +6150,31 @@ fn test_amount_to_ui_amount() {
61596150
)
61606151
.unwrap();
61616152

6162-
set_expected_data("0.23".as_bytes().to_vec());
61636153
do_process_instruction(
61646154
amount_to_ui_amount(&program_id, &mint_key, 23).unwrap(),
61656155
vec![&mut mint_account],
6166-
&[Check::success()],
6156+
&[Check::success(), Check::return_data(&"0.23".as_bytes())],
61676157
)
61686158
.unwrap();
61696159

6170-
set_expected_data("1.1".as_bytes().to_vec());
61716160
do_process_instruction(
61726161
amount_to_ui_amount(&program_id, &mint_key, 110).unwrap(),
61736162
vec![&mut mint_account],
6174-
&[Check::success()],
6163+
&[Check::success(), Check::return_data(&"1.1".as_bytes())],
61756164
)
61766165
.unwrap();
61776166

6178-
set_expected_data("42".as_bytes().to_vec());
61796167
do_process_instruction(
61806168
amount_to_ui_amount(&program_id, &mint_key, 4200).unwrap(),
61816169
vec![&mut mint_account],
6182-
&[Check::success()],
6170+
&[Check::success(), Check::return_data(&"42".as_bytes())],
61836171
)
61846172
.unwrap();
61856173

6186-
set_expected_data("0".as_bytes().to_vec());
61876174
do_process_instruction(
61886175
amount_to_ui_amount(&program_id, &mint_key, 0).unwrap(),
61896176
vec![&mut mint_account],
6190-
&[Check::success()],
6177+
&[Check::success(), Check::return_data(&"0".as_bytes())],
61916178
)
61926179
.unwrap();
61936180
}
@@ -6220,75 +6207,66 @@ fn test_ui_amount_to_amount() {
62206207
)
62216208
.unwrap();
62226209

6223-
set_expected_data(23u64.to_le_bytes().to_vec());
62246210
do_process_instruction(
62256211
ui_amount_to_amount(&program_id, &mint_key, "0.23").unwrap(),
62266212
vec![&mut mint_account],
6227-
&[Check::success()],
6213+
&[Check::success(), Check::return_data(&23u64.to_le_bytes())],
62286214
)
62296215
.unwrap();
62306216

6231-
set_expected_data(20u64.to_le_bytes().to_vec());
62326217
do_process_instruction(
62336218
ui_amount_to_amount(&program_id, &mint_key, "0.20").unwrap(),
62346219
vec![&mut mint_account],
6235-
&[Check::success()],
6220+
&[Check::success(), Check::return_data(&20u64.to_le_bytes())],
62366221
)
62376222
.unwrap();
62386223

6239-
set_expected_data(20u64.to_le_bytes().to_vec());
62406224
do_process_instruction(
62416225
ui_amount_to_amount(&program_id, &mint_key, "0.2000").unwrap(),
62426226
vec![&mut mint_account],
6243-
&[Check::success()],
6227+
&[Check::success(), Check::return_data(&20u64.to_le_bytes())],
62446228
)
62456229
.unwrap();
62466230

6247-
set_expected_data(20u64.to_le_bytes().to_vec());
62486231
do_process_instruction(
62496232
ui_amount_to_amount(&program_id, &mint_key, ".20").unwrap(),
62506233
vec![&mut mint_account],
6251-
&[Check::success()],
6234+
&[Check::success(), Check::return_data(&20u64.to_le_bytes())],
62526235
)
62536236
.unwrap();
62546237

6255-
set_expected_data(110u64.to_le_bytes().to_vec());
62566238
do_process_instruction(
62576239
ui_amount_to_amount(&program_id, &mint_key, "1.1").unwrap(),
62586240
vec![&mut mint_account],
6259-
&[Check::success()],
6241+
&[Check::success(), Check::return_data(&110u64.to_le_bytes())],
62606242
)
62616243
.unwrap();
62626244

6263-
set_expected_data(110u64.to_le_bytes().to_vec());
62646245
do_process_instruction(
62656246
ui_amount_to_amount(&program_id, &mint_key, "1.10").unwrap(),
62666247
vec![&mut mint_account],
6267-
&[Check::success()],
6248+
&[Check::success(), Check::return_data(&110u64.to_le_bytes())],
62686249
)
62696250
.unwrap();
62706251

6271-
set_expected_data(4200u64.to_le_bytes().to_vec());
62726252
do_process_instruction(
62736253
ui_amount_to_amount(&program_id, &mint_key, "42").unwrap(),
62746254
vec![&mut mint_account],
6275-
&[Check::success()],
6255+
&[Check::success(), Check::return_data(&4200u64.to_le_bytes())],
62766256
)
62776257
.unwrap();
62786258

6279-
set_expected_data(4200u64.to_le_bytes().to_vec());
62806259
do_process_instruction(
62816260
ui_amount_to_amount(&program_id, &mint_key, "42.").unwrap(),
62826261
vec![&mut mint_account],
6283-
&[Check::success()],
6262+
&[Check::success(), Check::return_data(&4200u64.to_le_bytes())],
62846263
)
62856264
.unwrap();
62866265

6287-
set_expected_data(0u64.to_le_bytes().to_vec());
62886266
do_process_instruction(
62896267
ui_amount_to_amount(&program_id, &mint_key, "0").unwrap(),
62906268
vec![&mut mint_account],
6291-
&[Check::success()],
6269+
&[Check::success(), Check::return_data(&0u64.to_le_bytes())],
62926270
)
62936271
.unwrap();
62946272

0 commit comments

Comments
 (0)