snarkVM
snarkVM copied to clipboard
Snapshot testing for constraint counts
Motivation
This PR:
- Introduces
UpdatableCount, a struct that stores the desired number of constants, public variables, private variables, and constraints. - Demonstrates how to use
UpdatableCountinpow_wrapped.rsandpow_checked.rs.
Usage
- Initialize an
UpdatableCountusingcount_is!orcount_less_than!. - Use
UpdatableCount::assert_matchesto check that the number of constants, variables, and constraints match. - Set an environment variable
UPDATE_COUNT=<query>while runningcargo testto update invocations ofcount_is!andcount_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.