Function demand_instruction_error

Source
pub fn demand_instruction_error(
    expected_error: InstructionError,
    result: TransactionResult,
)
Expand description

Asserts that a transaction fails with a specific instruction error, regardless of index.

This is the “anywhere” version of instruction error testing - it matches the specified instruction error without caring which instruction in the transaction produced it. Perfect for single-instruction transactions or when you just need to verify the error type.

For precise instruction-index control, use demand_instruction_error_at_index.

§Arguments

§Panics

Panics if:

  • The transaction succeeds (no error)
  • The error is not an instruction error
  • The instruction error doesn’t match the expected error

§Example

demand_instruction_error(
    InstructionError::Custom(1),
    result
);