You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As a first proposal, I wanted to show an example of what could be done to solve this.
We could base ourselves on the bindings feature to create a test_bindings one. Here is what we would do:
Wrap programs in a module called program (or wathever)
Annotate this module with an attribute macro, such as #[wasmlanche_program]
This macro will expand to a constant that locates the binary based on the location of the program as well as cargo settings
#[cfg(not(feature = "bindings"))]use wasmlanche_sdk::Context;use wasmlanche_sdk::{public, state_keys, types::Address,Gas,Program};mod program {usesuper::*;#[state_keys]pubenumStateKeys{/// The count of this program. Key prefix 0x0 + addressCounter(Address),}typeCount = u64;/// Increments the count at the address by the amount.#[cfg(feature = "test_bindings")]pubfninc(simulator:Client<W: std::io::Write,R:Iterator<Item = Result<StepResponse,StepError>>>,context:Context<StateKeys>,to:Address,amount:Count,) -> Result<bool,StepError>{use simulator::{Client,Step,StepError,StepResponse};
simulator
.run_step(
owner_key,&Step{endpoint:Endpoint::Execute,method:"inc".into(),max_units:1000000,params:vec![counter_id.into(), to, amount],},)?
.result.response::<bool>()// TODO figure out error handling.unwrap()}}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
We need to improve programs testing.
As raised by this issue #1036, there are multiple drawbacks with the current testing pattern:
As a first proposal, I wanted to show an example of what could be done to solve this.
We could base ourselves on the
bindings
feature to create atest_bindings
one. Here is what we would do:program
(or wathever)#[wasmlanche_program]
#[public]
attribute expands to a function that passes a reference to the simulator as the first arg, then followContext
and all the rest. The inner of the function is just what we currently do withStep
manually (see 3788373#diff-c0fe3c9010bcd916d3acf32027541e1943e9ebe8650d5901e536157ed0a590a3R138-R145).So it could expand to this:
Beta Was this translation helpful? Give feedback.
All reactions