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: i32Implementations§
Source§impl MockRuntime
impl MockRuntime
pub fn new() -> Self
pub fn with_storage(self, storage: MockStorage) -> Self
pub fn with_trigger(self, trigger: i32) -> Self
pub fn with_time(self, time: i64) -> Self
pub fn with_network(self, network: i64) -> Self
pub fn with_witness(self, address: &[u8]) -> Self
pub fn with_script_container(self, container: NeoArray<NeoValue>) -> Self
pub fn with_calling_script_hash(self, hash: &[u8]) -> Self
pub fn with_executing_script_hash(self, hash: &[u8]) -> Self
pub fn with_entry_script_hash(self, hash: &[u8]) -> Self
pub fn with_gas_left(self, gas: i64) -> Self
pub fn storage_ref(&self) -> &MockStorage
pub fn storage_mut(&mut self) -> &mut MockStorage
pub fn trigger_value(&self) -> i32
pub fn time_value(&self) -> i64
pub fn network_value(&self) -> i64
pub fn address_version_value(&self) -> i32
pub fn witnesses(&self) -> &[NeoByteString]
pub fn witnesses_mut(&mut self) -> &mut Vec<NeoByteString>
pub fn notifications(&self) -> &[(NeoString, NeoArray<NeoValue>)]
pub fn logs(&self) -> &[String]
pub fn clear_notifications(&mut self)
pub fn clear_logs(&mut self)
pub fn add_log(&mut self, message: &str)
pub fn add_notification(&mut self, event: NeoString, state: NeoArray<NeoValue>)
pub fn check_witness(&self, hash: &[u8]) -> bool
pub fn calling_script_hash(&self) -> Option<&NeoByteString>
pub fn executing_script_hash(&self) -> Option<&NeoByteString>
pub fn entry_script_hash(&self) -> Option<&NeoByteString>
pub fn gas_left(&self) -> i64
pub fn consume_gas(&mut self, amount: i64)
pub fn invocation_counter(&self) -> i32
pub fn increment_invocation_counter(&mut self)
pub fn get_storage_context(&mut self) -> MockStorageContext
pub fn get_read_only_storage_context(&mut self) -> MockStorageContext
Sourcepub fn storage_put(&mut self, key: &[u8], value: &[u8])
pub fn storage_put(&mut self, key: &[u8], value: &[u8])
Simulate storage put operation
Sourcepub fn storage_put_with_context(
&mut self,
context: &MockStorageContext,
key: &[u8],
value: &[u8],
) -> NeoResult<()>
pub fn storage_put_with_context( &mut self, context: &MockStorageContext, key: &[u8], value: &[u8], ) -> NeoResult<()>
Simulate storage put operation with storage context validation.
Sourcepub fn storage_delete(&mut self, key: &[u8])
pub fn storage_delete(&mut self, key: &[u8])
Simulate storage delete operation
Sourcepub fn storage_delete_with_context(
&mut self,
context: &MockStorageContext,
key: &[u8],
) -> NeoResult<()>
pub fn storage_delete_with_context( &mut self, context: &MockStorageContext, key: &[u8], ) -> NeoResult<()>
Simulate storage delete operation with storage context validation.
Sourcepub fn storage_find(&self, prefix: &[u8]) -> Vec<(Vec<u8>, Vec<u8>)>
pub fn storage_find(&self, prefix: &[u8]) -> Vec<(Vec<u8>, Vec<u8>)>
Simulate storage find operation
Sourcepub fn clear_storage_contexts(&mut self)
pub fn clear_storage_contexts(&mut self)
Reset known storage contexts to the runtime default context.
Trait Implementations§
Source§impl Clone for MockRuntime
impl Clone for MockRuntime
Source§fn clone(&self) -> MockRuntime
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MockRuntime
impl Debug for MockRuntime
Auto Trait Implementations§
impl Freeze for MockRuntime
impl RefUnwindSafe for MockRuntime
impl Send for MockRuntime
impl Sync for MockRuntime
impl Unpin for MockRuntime
impl UnsafeUnpin for MockRuntime
impl UnwindSafe for MockRuntime
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more