#near #testing #prop #macro #near-prop

macro near-prop-macros

Macros for near-prop testing library

1 unstable release

0.1.0 Jul 9, 2022

#6 in #prop


Used in near-prop

MIT/Apache

4KB

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

~1.5MB
~33K SLoC