TransactionResult

Struct TransactionResult 

Source
pub struct TransactionResult { /* private fields */ }
Expand description

Wrapper around LiteSVM’s TransactionMetadata with helper methods for testing

This struct provides convenient methods for analyzing transaction results, including log inspection, compute unit tracking, and success assertions.

§Example

let result = svm.send_instruction(ix, &[&signer])?;
result.assert_success();
assert!(result.has_log("Transfer complete"));
println!("Used {} compute units", result.compute_units());

Implementations§

Source§

impl TransactionResult

Source

pub fn new( result: TransactionMetadata, instruction_name: Option<String>, ) -> Self

Create a new TransactionResult wrapper for successful transaction

§Arguments
  • result - The transaction metadata from LiteSVM
  • instruction_name - Optional name of the instruction for debugging
Source

pub fn new_failed( error: String, result: TransactionMetadata, instruction_name: Option<String>, ) -> Self

Create a new TransactionResult wrapper for failed transaction

§Arguments
  • error - The error message
  • result - The transaction metadata from LiteSVM
  • instruction_name - Optional name of the instruction for debugging
Source

pub fn assert_success(&self) -> &Self

Assert that the transaction succeeded, panic with logs if it failed

§Returns

Returns self for chaining

§Example
result.assert_success();
Source

pub fn is_success(&self) -> bool

Check if the transaction succeeded

§Returns

true if the transaction succeeded, false otherwise

Source

pub fn error(&self) -> Option<&String>

Get the error message if the transaction failed

§Returns

The error message if the transaction failed, None otherwise

Source

pub fn logs(&self) -> &[String]

Get the transaction logs

§Returns

A slice of log messages

Source

pub fn has_log(&self, message: &str) -> bool

Check if the logs contain a specific message

§Arguments
  • message - The message to search for
§Returns

true if the message is found in the logs, false otherwise

Source

pub fn find_log(&self, pattern: &str) -> Option<&String>

Find a log entry containing the specified text

§Arguments
  • pattern - The pattern to search for
§Returns

The first matching log entry, or None

Source

pub fn compute_units(&self) -> u64

Get the compute units consumed

§Returns

The number of compute units consumed

Source

pub fn print_logs(&self)

Print the transaction logs

Source

pub fn inner(&self) -> &TransactionMetadata

Get the inner TransactionMetadata for direct access

Source

pub fn assert_failure(&self) -> &Self

Assert that the transaction failed

§Panics

Panics if the transaction succeeded

§Returns

Returns self for chaining

§Example
result.assert_failure();
Source

pub fn assert_error(&self, expected_error: &str) -> &Self

Assert that the transaction failed with a specific error message

§Arguments
  • expected_error - The expected error message (substring match)
§Panics

Panics if the transaction succeeded or failed with a different error

§Returns

Returns self for chaining

§Example
result.assert_error("insufficient funds");
Source

pub fn assert_error_code(&self, error_code: u32) -> &Self

Assert that the transaction failed with a specific error code

This is useful for asserting Anchor custom errors.

§Arguments
  • error_code - The expected error code number
§Panics

Panics if the transaction succeeded or failed with a different error code

§Returns

Returns self for chaining

§Example
// Assert that transaction failed with custom error code 6000
result.assert_error_code(6000);
Source

pub fn assert_anchor_error(&self, error_name: &str) -> &Self

Assert that the transaction failed with a specific Anchor error

This checks for Anchor’s error code format in the logs.

§Arguments
  • error_name - The name of the Anchor error
§Panics

Panics if the transaction succeeded or the error wasn’t found in logs

§Returns

Returns self for chaining

§Example
// Assert that transaction failed with Anchor error
result.assert_anchor_error("InsufficientFunds");
Source

pub fn assert_log_error(&self, error_message: &str) -> &Self

Assert that the logs contain a specific error message

Unlike assert_error, this only checks the logs, not the error field.

§Arguments
  • error_message - The expected error message in logs
§Panics

Panics if the error message is not found in logs

§Returns

Returns self for chaining

§Example
result.assert_log_error("Transfer amount exceeds balance");

Trait Implementations§

Source§

impl Debug for TransactionResult

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V