Trait gtest::WasmProgram

source ·
pub trait WasmProgram: Debug {
    // Required methods
    fn init(
        &mut self,
        payload: Vec<u8>
    ) -> Result<Option<Vec<u8>>, &'static str>;
    fn handle(
        &mut self,
        payload: Vec<u8>
    ) -> Result<Option<Vec<u8>>, &'static str>;
    fn handle_reply(&mut self, payload: Vec<u8>) -> Result<(), &'static str>;
    fn handle_signal(&mut self, payload: Vec<u8>) -> Result<(), &'static str>;
    fn state(&mut self) -> Result<Vec<u8>, &'static str>;

    // Provided method
    fn debug(&mut self, data: &str) { ... }
}
Expand description

Trait for mocking gear programs.

See Program and Program::mock for the usages.

Required Methods§

source

fn init(&mut self, payload: Vec<u8>) -> Result<Option<Vec<u8>>, &'static str>

Init wasm program with given payload.

Returns Ok(Some(payload)) if program has reply logic with given payload.

If error occurs, the program will be terminated which means that handle and handle_reply will not be called.

source

fn handle(&mut self, payload: Vec<u8>) -> Result<Option<Vec<u8>>, &'static str>

Message handler with given payload.

Returns Ok(Some(payload)) if program has reply logic.

source

fn handle_reply(&mut self, payload: Vec<u8>) -> Result<(), &'static str>

Reply message handler with given payload.

source

fn handle_signal(&mut self, payload: Vec<u8>) -> Result<(), &'static str>

Signal handler with given payload.

source

fn state(&mut self) -> Result<Vec<u8>, &'static str>

State of wasm program.

See Program::read_state for the usage.

Provided Methods§

source

fn debug(&mut self, data: &str)

Emit debug message in program with given data.

Logging target gwasm is used in this method.

Implementors§