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§
sourcefn init(&mut self, payload: Vec<u8>) -> Result<Option<Vec<u8>>, &'static str>
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.
sourcefn handle(&mut self, payload: Vec<u8>) -> Result<Option<Vec<u8>>, &'static str>
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.
sourcefn handle_reply(&mut self, payload: Vec<u8>) -> Result<(), &'static str>
fn handle_reply(&mut self, payload: Vec<u8>) -> Result<(), &'static str>
Reply message handler with given payload
.