#near #prop #testing #failure #generate #bool #workspaces-rs

nightly near-prop

Property based testing library for NEAR using workspaces-rs

1 unstable release

0.1.0 Jul 9, 2022

#5 in #prop

23 downloads per month

MIT/Apache

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

~39–57MB
~1M SLoC