Skip to main content

TestEnvironment

Struct TestEnvironment 

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

Test environment for Neo N3 contract testing

Implementations§

Source§

impl TestEnvironment

Source

pub fn new() -> Self

Source

pub fn with_runtime(self, runtime: MockRuntime) -> Self

Source

pub fn runtime(&self) -> &MockRuntime

Source

pub fn runtime_mut(&mut self) -> &mut MockRuntime

Source

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

Source

pub fn get_storage_context(&mut self) -> MockStorageContext

Source

pub fn get_read_only_storage_context(&mut self) -> MockStorageContext

Source

pub fn put_storage_with_context( &mut self, context: &MockStorageContext, key: &[u8], value: &[u8], ) -> Result<(), NeoError>

Source

pub fn delete_storage_with_context( &mut self, context: &MockStorageContext, key: &[u8], ) -> Result<(), NeoError>

Source

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

Source

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

Source

pub fn set_trigger(&mut self, trigger: i32)

Source

pub fn set_time(&mut self, time: i64)

Source

pub fn set_network(&mut self, network: i64)

Source

pub fn add_witness(&mut self, address: &[u8])

Source

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

Source

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

Source

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

Source

pub fn clear_logs(&mut self)

Source

pub fn assert_runtime(&self) -> RuntimeAssertions<'_>

Source

pub fn assert_storage(&self) -> StorageAssertions<'_>

Source

pub fn call_method<F, R>(&self, name: &str, args: &[NeoValue], f: F) -> R
where F: FnOnce() -> R,

Run a contract method against this mock environment under a readable label, returning its result.

This is the unit / logic testing layer: f invokes your contract method natively (host execution) so it reads/writes this environment’s mock storage and runtime. name/args document the call and appear in failure diagnostics; they do not dispatch (native Rust calls are type-checked directly).

To execute the translated NeoVM bytecode on a real VM instead — the equivalent of Solana’s solana-program-test — use the neo-vm-test crate’s Contract::compile(..).invoke(..).

Source

pub fn deploy(&mut self, script: &[u8], manifest: &[u8]) -> TestResult

Source

pub fn update(&mut self, script: &[u8]) -> TestResult

Source

pub fn update_with_manifest( &mut self, script: &[u8], manifest: &[u8], ) -> TestResult

Source

pub fn destroy(&mut self) -> TestResult

Source

pub fn is_deployed(&self) -> bool

Source

pub fn deployed_script(&self) -> Option<&[u8]>

Source

pub fn deployed_manifest(&self) -> Option<&[u8]>

Source

pub fn reset(&mut self)

Trait Implementations§

Source§

impl Default for TestEnvironment

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> 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, 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.