Skip to content

Commit 0f963cf

Browse files
committed
Now that the account index and the inner instruction index of the erroring program is added to TransactionError::InstructionError, patch up all of the tests
1 parent 5d401f4 commit 0f963cf

File tree

26 files changed

+549
-232
lines changed

26 files changed

+549
-232
lines changed

Cargo.lock

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compute-budget-instruction/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ crate-type = ["lib"]
2929
name = "solana_compute_budget_instruction"
3030

3131
[dev-dependencies]
32+
assert_matches = { workspace = true }
3233
bincode = { workspace = true }
3334
criterion = { workspace = true }
3435
rand = { workspace = true }

compute-budget-instruction/src/compute_budget_instruction_details.rs

+2
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,8 @@ mod test {
413413
let expected_heap_size_err = Err(TransactionError::InstructionError(
414414
3,
415415
InstructionError::InvalidInstructionData,
416+
None,
417+
None,
416418
));
417419
// invalid: requested_heap_size can't be zero
418420
let instruction_details = ComputeBudgetInstructionDetails {

compute-budget-instruction/src/instructions_processor.rs

+8
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ mod tests {
164164
Err(TransactionError::InstructionError(
165165
0,
166166
InstructionError::InvalidInstructionData,
167+
None,
168+
None,
167169
))
168170
);
169171
test!(
@@ -174,6 +176,8 @@ mod tests {
174176
Err(TransactionError::InstructionError(
175177
0,
176178
InstructionError::InvalidInstructionData,
179+
None,
180+
None,
177181
))
178182
);
179183
test!(
@@ -184,6 +188,8 @@ mod tests {
184188
Err(TransactionError::InstructionError(
185189
0,
186190
InstructionError::InvalidInstructionData,
191+
None,
192+
None,
187193
))
188194
);
189195
test!(
@@ -222,6 +228,8 @@ mod tests {
222228
Err(TransactionError::InstructionError(
223229
3,
224230
InstructionError::InvalidInstructionData,
231+
None,
232+
None,
225233
))
226234
);
227235
test!(

core/src/banking_stage/consumer.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -1573,17 +1573,20 @@ mod tests {
15731573
(transaction.signatures[0], meta.status)
15741574
})
15751575
.collect();
1576-
let expected_tx_results = vec![
1577-
(success_signature, Ok(())),
1576+
assert_eq!(actual_tx_results.len(), 2);
1577+
assert_eq!(actual_tx_results[0], (success_signature, Ok(())));
1578+
assert_matches!(
1579+
actual_tx_results[1],
15781580
(
1579-
ix_error_signature,
1581+
actual_ix_signature,
15801582
Err(TransactionError::InstructionError(
15811583
0,
15821584
InstructionError::Custom(1),
1585+
None,
1586+
Some(ii),
15831587
)),
1584-
),
1585-
];
1586-
assert_eq!(actual_tx_results, expected_tx_results);
1588+
) if ii > 0 && actual_ix_signature == ix_error_signature
1589+
);
15871590

15881591
poh_recorder
15891592
.read()

core/src/replay_stage.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -5347,17 +5347,22 @@ pub(crate) mod tests {
53475347
(transaction.signatures[0], meta.status)
53485348
})
53495349
.collect();
5350-
let expected_tx_results = vec![
5351-
(test_signatures_iter.next().unwrap(), Ok(())),
5350+
assert_eq!(actual_tx_results.len(), 2);
5351+
let first_expected_result = test_signatures_iter.next().unwrap();
5352+
assert_eq!(actual_tx_results[0], (first_expected_result, Ok(())));
5353+
let second_expected_result = test_signatures_iter.next().unwrap();
5354+
assert_matches!(
5355+
actual_tx_results[1],
53525356
(
5353-
test_signatures_iter.next().unwrap(),
5357+
actual_result,
53545358
Err(TransactionError::InstructionError(
53555359
0,
53565360
InstructionError::Custom(1),
5361+
None,
5362+
Some(ii),
53575363
)),
5358-
),
5359-
];
5360-
assert_eq!(actual_tx_results, expected_tx_results);
5364+
) if ii > 0 && actual_result == second_expected_result
5365+
);
53615366
assert!(test_signatures_iter.next().is_none());
53625367
}
53635368
Blockstore::destroy(&ledger_path).unwrap();

core/tests/scheduler_cost_adjustment.rs

+23-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![cfg(test)]
22
use {
3+
assert_matches::assert_matches,
34
solana_compute_budget::compute_budget_limits::MAX_BUILTIN_ALLOCATION_COMPUTE_UNIT_LIMIT,
45
solana_cost_model::cost_model::CostModel,
56
solana_runtime::{bank::Bank, bank_forks::BankForks},
@@ -230,19 +231,20 @@ fn test_builtin_ix_cost_adjustment_with_cu_limit_too_low() {
230231
// Cost model & Compute budget: reserve/allocate requested CU Limit `1`
231232
// VM Execution: consume `1` CU, then fail
232233
// Result: 0 adjustment
233-
let expected = TestResult {
234-
cost_adjustment: 0,
235-
execution_status: Err(TransactionError::InstructionError(
236-
0,
237-
InstructionError::ComputationalBudgetExceeded,
238-
)),
239-
};
240-
assert_eq!(
241-
expected,
234+
assert_matches!(
242235
test_setup.execute_test_transaction(&[
243236
test_setup.transfer_ix(),
244237
test_setup.set_cu_limit_ix(cu_limit),
245-
])
238+
]),
239+
TestResult {
240+
cost_adjustment: 0,
241+
execution_status: Err(TransactionError::InstructionError(
242+
0,
243+
InstructionError::ComputationalBudgetExceeded,
244+
None,
245+
Some(ii),
246+
)),
247+
} if ii > 0
246248
);
247249
}
248250

@@ -282,16 +284,17 @@ fn test_builtin_ix_cost_adjustment_with_memo_no_cu_limit() {
282284
// (3_000 + 200_000) = 203_000 CUs (note: less than memo_ix needs)
283285
// VM Execution: consume all allocated CUs, then fail
284286
// Result: no adjustment
285-
let expected = TestResult {
286-
cost_adjustment: 0,
287-
execution_status: Err(TransactionError::InstructionError(
288-
1,
289-
InstructionError::ProgramFailedToComplete,
290-
)),
291-
};
292-
assert_eq!(
293-
expected,
294-
test_setup.execute_test_transaction(&[test_setup.transfer_ix(), memo_ix.clone()],)
287+
assert_matches!(
288+
test_setup.execute_test_transaction(&[test_setup.transfer_ix(), memo_ix.clone()],),
289+
TestResult {
290+
cost_adjustment: 0,
291+
execution_status: Err(TransactionError::InstructionError(
292+
1,
293+
InstructionError::ProgramFailedToComplete,
294+
None,
295+
Some(ii),
296+
)),
297+
} if ii > 0
295298
);
296299
}
297300

ledger/src/blockstore_processor.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -3995,12 +3995,14 @@ pub mod tests {
39953995
bank.transfer(1_000, &mint_keypair, &pubkey).unwrap();
39963996
assert_eq!(bank.transaction_count(), 1);
39973997
assert_eq!(bank.get_balance(&pubkey), 1_000);
3998-
assert_eq!(
3998+
assert_matches!(
39993999
bank.transfer(10_001, &mint_keypair, &pubkey),
40004000
Err(TransactionError::InstructionError(
40014001
0,
4002-
SystemError::ResultWithNegativeLamports.into(),
4003-
))
4002+
actual_err,
4003+
None,
4004+
Some(ii),
4005+
)) if ii > 0 && actual_err == SystemError::ResultWithNegativeLamports.into()
40044006
);
40054007
assert_eq!(
40064008
bank.transfer(10_001, &mint_keypair, &pubkey),

program-test/tests/panic.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use {
2+
assert_matches::assert_matches,
23
solana_program_test::{processor, ProgramTest},
34
solana_sdk::{
45
account_info::AccountInfo,
@@ -30,13 +31,18 @@ async fn panic_test() {
3031
&[&context.payer],
3132
context.last_blockhash,
3233
);
33-
assert_eq!(
34+
assert_matches!(
3435
context
3536
.banks_client
3637
.process_transaction(transaction)
3738
.await
3839
.unwrap_err()
3940
.unwrap(),
40-
TransactionError::InstructionError(0, InstructionError::ProgramFailedToComplete)
41+
TransactionError::InstructionError(
42+
0,
43+
InstructionError::ProgramFailedToComplete,
44+
None,
45+
Some(ii),
46+
) if ii > 0
4147
);
4248
}

program-test/tests/warp.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
mod setup;
44

55
use {
6+
assert_matches::assert_matches,
67
bincode::deserialize,
78
log::debug,
89
setup::{setup_stake, setup_vote},
@@ -78,14 +79,19 @@ async fn clock_sysvar_updated_from_warp() {
7879
&[&context.payer],
7980
context.last_blockhash,
8081
);
81-
assert_eq!(
82+
assert_matches!(
8283
context
8384
.banks_client
8485
.process_transaction(transaction)
8586
.await
8687
.unwrap_err()
8788
.unwrap(),
88-
TransactionError::InstructionError(0, InstructionError::Custom(WRONG_SLOT_ERROR))
89+
TransactionError::InstructionError(
90+
0,
91+
InstructionError::Custom(WRONG_SLOT_ERROR),
92+
None,
93+
Some(ii),
94+
) if ii > 0
8995
);
9096

9197
// Warp to success!

programs/bpf-loader-tests/tests/common.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![allow(dead_code)]
22

33
use {
4+
assert_matches::assert_matches,
45
solana_program_test::*,
56
solana_sdk::{
67
account::AccountSharedData,
@@ -41,14 +42,19 @@ pub async fn assert_ix_error(
4142
recent_blockhash,
4243
);
4344

44-
assert_eq!(
45+
assert_matches!(
4546
client
4647
.process_transaction(transaction)
4748
.await
4849
.unwrap_err()
4950
.unwrap(),
50-
TransactionError::InstructionError(0, expected_err),
51-
"{assertion_failed_msg}",
51+
TransactionError::InstructionError(
52+
0,
53+
actual_err,
54+
Some(_) | None,
55+
Some(ii),
56+
) if ii > 0 && actual_err == expected_err,
57+
"{assertion_failed_msg}"
5258
);
5359
}
5460

programs/bpf-loader-tests/tests/extend_program_ix.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,12 @@ async fn test_failed_extend_twice_in_same_slot() {
155155
.await
156156
.unwrap_err()
157157
.unwrap(),
158-
TransactionError::InstructionError(0, InstructionError::InvalidArgument)
158+
TransactionError::InstructionError(
159+
0,
160+
InstructionError::InvalidArgument,
161+
None,
162+
Some(ii),
163+
) if ii > 0
159164
);
160165
}
161166

programs/ed25519-tests/tests/process_transaction.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,13 @@ async fn test_failure() {
7070
assert_matches!(
7171
client.process_transaction(transaction).await,
7272
Err(BanksClientError::TransactionError(
73-
TransactionError::InstructionError(0, InstructionError::Custom(3))
74-
))
73+
TransactionError::InstructionError(
74+
0,
75+
InstructionError::Custom(3),
76+
None,
77+
Some(ii),
78+
),
79+
)) if ii > 0
7580
);
7681
// this assert is for documenting the matched error code above
7782
assert_eq!(3, PrecompileError::InvalidDataOffsets as u32);

programs/stake-tests/tests/test_move_stake_and_lamports.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ async fn process_instruction<T: Signers + ?Sized>(
269269
Err(e) => {
270270
// banks client error -> transaction error -> instruction error -> program error
271271
match e.unwrap() {
272-
TransactionError::InstructionError(_, e) => Err(e.try_into().unwrap()),
272+
TransactionError::InstructionError(_, e, _, _) => Err(e.try_into().unwrap()),
273273
TransactionError::InsufficientFundsForRent { .. } => {
274274
Err(ProgramError::InsufficientFunds)
275275
}

programs/zk-elgamal-proof-tests/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ license = { workspace = true }
88
edition = { workspace = true }
99

1010
[dev-dependencies]
11+
assert_matches = { workspace = true }
1112
bytemuck = { workspace = true }
1213
solana-account = { workspace = true }
1314
solana-compute-budget = { workspace = true }

0 commit comments

Comments
 (0)