Skip to main content

MockRuntime

Struct MockRuntime 

Source
pub struct MockRuntime {
Show 13 fields pub storage: MockStorage, pub trigger: i32, pub time: i64, pub network: i64, pub address_version: i32, pub notifications: Vec<(NeoString, NeoArray<NeoValue>)>, pub logs: Vec<String>, pub script_container: Option<NeoArray<NeoValue>>, pub calling_script_hash: Option<NeoByteString>, pub executing_script_hash: Option<NeoByteString>, pub entry_script_hash: Option<NeoByteString>, pub gas_left: i64, pub invocation_counter: i32, /* private fields */
}
Expand description

Mock runtime for testing contract execution

This provides a complete simulation of the Neo N3 runtime environment for testing smart contracts.

Fields§

§storage: MockStorage§trigger: i32§time: i64§network: i64§address_version: i32§notifications: Vec<(NeoString, NeoArray<NeoValue>)>§logs: Vec<String>§script_container: Option<NeoArray<NeoValue>>§calling_script_hash: Option<NeoByteString>§executing_script_hash: Option<NeoByteString>§entry_script_hash: Option<NeoByteString>§gas_left: i64§invocation_counter: i32

Implementations§

Source§

impl MockRuntime

Source

pub fn new() -> Self

Source

pub fn with_storage(self, storage: MockStorage) -> Self

Source

pub fn with_trigger(self, trigger: i32) -> Self

Source

pub fn with_time(self, time: i64) -> Self

Source

pub fn with_network(self, network: i64) -> Self

Source

pub fn with_witness(self, address: &[u8]) -> Self

Source

pub fn with_script_container(self, container: NeoArray<NeoValue>) -> Self

Source

pub fn with_calling_script_hash(self, hash: &[u8]) -> Self

Source

pub fn with_executing_script_hash(self, hash: &[u8]) -> Self

Source

pub fn with_entry_script_hash(self, hash: &[u8]) -> Self

Source

pub fn with_gas_left(self, gas: i64) -> Self

Source

pub fn storage_ref(&self) -> &MockStorage

Source

pub fn storage_mut(&mut self) -> &mut MockStorage

Source

pub fn trigger_value(&self) -> i32

Source

pub fn time_value(&self) -> i64

Source

pub fn network_value(&self) -> i64

Source

pub fn address_version_value(&self) -> i32

Source

pub fn witnesses(&self) -> &[NeoByteString]

Source

pub fn witnesses_mut(&mut self) -> &mut Vec<NeoByteString>

Source

pub fn notifications(&self) -> &[(NeoString, NeoArray<NeoValue>)]

Source

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

Source

pub fn clear_notifications(&mut self)

Source

pub fn clear_logs(&mut self)

Source

pub fn add_log(&mut self, message: &str)

Source

pub fn add_notification(&mut self, event: NeoString, state: NeoArray<NeoValue>)

Source

pub fn check_witness(&self, hash: &[u8]) -> bool

Source

pub fn calling_script_hash(&self) -> Option<&NeoByteString>

Source

pub fn executing_script_hash(&self) -> Option<&NeoByteString>

Source

pub fn entry_script_hash(&self) -> Option<&NeoByteString>

Source

pub fn gas_left(&self) -> i64

Source

pub fn consume_gas(&mut self, amount: i64)

Source

pub fn invocation_counter(&self) -> i32

Source

pub fn increment_invocation_counter(&mut self)

Source

pub fn get_storage_context(&mut self) -> MockStorageContext

Source

pub fn get_read_only_storage_context(&mut self) -> MockStorageContext

Source

pub fn storage_get(&self, key: &[u8]) -> Option<Vec<u8>>

Simulate storage get operation

Source

pub fn storage_put(&mut self, key: &[u8], value: &[u8])

Simulate storage put operation

Source

pub fn storage_put_with_context( &mut self, context: &MockStorageContext, key: &[u8], value: &[u8], ) -> NeoResult<()>

Simulate storage put operation with storage context validation.

Source

pub fn storage_delete(&mut self, key: &[u8])

Simulate storage delete operation

Source

pub fn storage_delete_with_context( &mut self, context: &MockStorageContext, key: &[u8], ) -> NeoResult<()>

Simulate storage delete operation with storage context validation.

Source

pub fn storage_find(&self, prefix: &[u8]) -> Vec<(Vec<u8>, Vec<u8>)>

Simulate storage find operation

Source

pub fn reset(&mut self)

Reset the runtime state

Source

pub fn clear_storage_contexts(&mut self)

Reset known storage contexts to the runtime default context.

Trait Implementations§

Source§

impl Clone for MockRuntime

Source§

fn clone(&self) -> MockRuntime

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MockRuntime

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for MockRuntime

Source§

fn default() -> Self

Returns the “default value” for a type. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.