snarkVM icon indicating copy to clipboard operation
snarkVM copied to clipboard

Snapshot testing for constraint counts

Open d0cd opened this issue 3 years ago • 0 comments

Motivation

This PR:

  • Introduces UpdatableCount, a struct that stores the desired number of constants, public variables, private variables, and constraints.
  • Demonstrates how to use UpdatableCount in pow_wrapped.rs and pow_checked.rs.

Usage

  1. Initialize an UpdatableCount using count_is! or count_less_than!.
  2. Use UpdatableCount::assert_matches to check that the number of constants, variables, and constraints match.
  3. Set an environment variable UPDATE_COUNT=<query> while running cargo test to update invocations of count_is! and count_less_than! with correct numbers (on failing cases) in the source files whose name contains the substring <query>.

Example. To update counts in pow_checked.rs, run:

UPDATE_COUNT=pow_checked cargo test -- --include-ignored

If you would like to see update statistics, enable the nocapture flag.

UPDATE_COUNT=pow_checked cargo test -- --include-ignored --nocapture

Notes

The updated counts are only accurate for the cases that are tests. When using this feature, you may have to run your tests (with UPDATE_COUNT set) multiple times to reach a fixed point.

d0cd avatar May 26 '22 07:05 d0cd