gtest: Make mock `WasmProgram` more useful by allowing it to actively interact with programs
Problem to Solve
Currently mock programs are just receivers, which can only reply on handle messages. They can't execute handle_reply or handle_signal, because of not being able to send messages actively or create system reservations.
Possible Solution
The solution must give more functionality to mock programs. However, imo, we should not re-create all the possibilities of the classical programs as it's just a mock and is supposed to be limited in capabilities.
I see the solution the following way:
struct GTestExecutionContext<'a> {
gas_available: u64,
payload: Vec<u8>,
messages_sent: Vec<Dispatch>
}
impl GTestExecutionContext {
fn payload(&self) -> &[u8] { todo!() }
fn send_message(&mut self, destination: ActorId, payload: Vec<u8>) -> Result<()> {
todo!();
Ok(())
}
fn system_reservation(&mut self, amount: u64) -> Result<()> {
todo!("check available gas");
Ok(())
}
}
trait WasmProgram {
fn handle(&mut self, ctx: GTestExecutionContext) -> Result<Option<Vec<u8>>, &'static str>;
}
Due to nature of the WasmProgram implementors, they do not require strict gas metering and charging. So it's enough to give to the context "initial info" about remaining gas and use it for the methods of the suggested context (like `system_reservation and etc.)
Notes
No response