demand_instruction_error_at_index

Function demand_instruction_error_at_index 

Source
pub fn demand_instruction_error_at_index(
    expected_index: u8,
    expected_error: InstructionError,
    result: TransactionResult,
)
Expand description

Asserts that a specific instruction fails with a specific error.

This is the “surgical” version of instruction error testing - it validates both the error type AND which instruction produced it. Use this for multi-instruction transactions where you need to verify that a specific instruction fails with a specific error.

For “anywhere” matching (don’t care about index), use demand_instruction_error.

§Arguments

  • expected_index - The index of the instruction that should fail (0-based)
  • expected_error - The expected instruction error
  • result - The result of executing a transaction via litesvm::LiteSVM::send_transaction

§Panics

Panics if:

  • The transaction succeeds (no error)
  • The error is not an instruction error
  • The error occurs at a different instruction index
  • The instruction error doesn’t match the expected error

§Example

// Expect the second instruction (index 1) to fail with Custom(42)
demand_instruction_error_at_index(
    1,
    InstructionError::Custom(42),
    result
);