1 unstable release
0.1.0 | Jul 9, 2022 |
---|
#94 in #add
20KB
390 lines
near-prop
Property-based testing for NEAR using workspaces-rs.
The APIs are an extension of quickcheck which is used for generating data and shrinking data to find minimal failures.
Usage
With test macro:
#[near_prop::test]
async fn prop_test_basic(ctx: PropContext, amount: u64) -> anyhow::Result<bool> {
let r = ctx.contract
.call(&ctx.worker, "add")
.args_json((amount,))?
.transact()
.await?
.json::<u64>()?;
Ok(r == amount)
}
Without test macro:
async fn prop(ctx: PropContext, amount: u64) -> anyhow::Result<bool> {
let r = ctx.contract
.call(&ctx.worker, "add")
.args_json((amount,))?
.transact()
.await?
.json::<u64>()?;
Ok(r == amount)
}
prop_test(prop as fn(PropContext, _) -> _).await;
This will by default compile the current directory's library and run until 100 tests pass. These tests will be run in parallel.
See more examples here
Future functionality:
- Allow overriding wasm file or cargo manifest directory
- Allow re-using contract with prop tests
- Integration with contract ABI (automatic fuzzing of methods?)
Dependencies
~36–53MB
~1M SLoC