A parser proved against its grammar
MystenLabs/sui-rust-sdk
#218 ↗ Rust
Example tests check the cases the author imagined. Property tests generate the grammar and check a law — here, that printing a type and parsing it back returns the same type.
The gap
The TypeTag / StructTag / Identifier parser carried a // TODO add proptests comment from its original implementation. Its example tests covered the shapes someone had thought to write down, which is exactly the set of inputs least likely to contain the bug.
Why it mattered
Type tags are how Sui names every type crossing a boundary. They nest arbitrarily — vectors of vectors, structs with recursive generics — so the input space is infinite and enumeration by hand is not a strategy. The existing Arbitrary derives deliberately skip those deep paths to keep BCS fuzzing fast, which left the richest part of the grammar untested by anything.
The approach
Custom generation strategies that produce the full grammar, then assert a round-trip law: Display → FromStr returns the value you started with, for arbitrary type tags, for both letter- and underscore-prefixed identifiers, and for vector<vector<…>> nested to depth eight. A law like that is stronger than any list of examples, because the framework searches for a counterexample and then shrinks it to the smallest one that still fails.
How it was proven
cargo test --all-features -p sui-sdk-types -- type_tag::parse::tests. Seven tests pass in about two tenths of a second — cheap enough that nobody is tempted to skip them, which is the property that decides whether a test suite survives.