diff --git a/contracts/double_counter/src/lib.rs b/contracts/double_counter/src/lib.rs index 2625f74d..b5c97a02 100644 --- a/contracts/double_counter/src/lib.rs +++ b/contracts/double_counter/src/lib.rs @@ -10,6 +10,7 @@ #![no_std] use piecrust_uplink as uplink; +use uplink::{ContractError, ContractId}; /// Struct that describes the state of the DoubleCounter contract pub struct DoubleCounter { @@ -40,6 +41,20 @@ impl DoubleCounter { let value = self.right_value + 1; self.right_value = value; } + + /// Increment the counter by 1 and call the given contract, with the given + /// arguments. + /// + /// This is intended to test the behavior of the contract on calling a + /// contract that doesn't exist. + pub fn increment_left_and_call( + &mut self, + contract: ContractId, + ) -> Result<(), ContractError> { + let value = self.left_value + 1; + self.left_value = value; + uplink::call(contract, "hello", &()) + } } /// Expose `Counter::read_value()` to the host @@ -59,3 +74,11 @@ unsafe fn increment_left(arg_len: u32) -> u32 { unsafe fn increment_right(arg_len: u32) -> u32 { uplink::wrap_call(arg_len, |_: ()| STATE.increment_right()) } + +/// Expose `Counter::increment_and_call()` to the host +#[no_mangle] +unsafe fn increment_left_and_call(arg_len: u32) -> u32 { + uplink::wrap_call_unchecked(arg_len, |arg| { + STATE.increment_left_and_call(arg) + }) +}