{"data":{"slug":"discovered-fb461d3d5c6675645d90668abab9319720df98d92998c6e2","title":"Property Based Testing","summary":"Write, review, and debug property-based tests using tools like Hypothesis, fast-check, proptest, jqwik, rapid, and Echidna or Medusa for Solidity invariants. Focus on testing whole input domains rather than individual examples, such as encode\/decode pairs, parsers, normalizers, validators, and smart-contract state invariants.","url":"https:\/\/skillshunter.net\/skills\/discovered-fb461d3d5c6675645d90668abab9319720df98d92998c6e2","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/discovered-fb461d3d5c6675645d90668abab9319720df98d92998c6e2","markdown_url":"https:\/\/skillshunter.net\/skills\/discovered-fb461d3d5c6675645d90668abab9319720df98d92998c6e2.md","download_url":"https:\/\/skillshunter.net\/skills\/discovered-fb461d3d5c6675645d90668abab9319720df98d92998c6e2\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Before writing a property test, ensure the function supports a property stronger than 'no crash' \u2014 such as type preservation, invariants, or roundtrip properties. If only 'no crash' is possible, consider whether a small rearrangement of the code might expose a stronger property.","instructions":"---\ndescription: 'Writes, reviews, and debugs property-based tests \u2014 Hypothesis, fast-check, proptest, jqwik, rapid, and Echidna or Medusa for Solidity invariants. Use whenever tests should cover a whole input domain instead of a hand-picked list of examples: encode\/decode and serialize\/deserialize pairs, parsers, canonicalizers and normalizers, validators, numeric and Decimal types, comparators and sort order, data structures, and smart-contract state invariants. Also use when adding cases to an existing @given, fast-check, or proptest suite, when judging whether existing property tests assert anything real, and when a generator has shrunk a counterexample and you need to tell a wrong property from a genuine bug. Not for coverage-guided binary fuzzing (libFuzzer, AFL), mutation-testing campaigns, static analysis, benchmarking, or end-to-end UI tests.'\neffort: low\nmetadata:\n    github-path: plugins\/property-based-testing\/skills\/property-based-testing\n    github-pinned: 149d7b21f4067765b82e67029730b42d228ef4b4\n    github-ref: 149d7b21f4067765b82e67029730b42d228ef4b4\n    github-repo: https:\/\/github.com\/trailofbits\/skills\n    github-tree-sha: cf5e77d684180c80a2f3aa228c53d04b1fa1ba77\nname: property-based-testing\n---\n# Property-Based Testing\n\nAn example test asserts one point. A property asserts a rule over the whole input\ndomain and lets the generator hunt for the counterexample. That trade is worth making\nwhen the code has an algebraic shape \u2014 an inverse, an invariant, an oracle \u2014 and not\notherwise. Code with no such shape gets example tests; saying so is a valid outcome.\n\nCheck first whether the shape is missing or merely buried. A calculation wrapped in I\/O,\na string built by concatenation, an in-place mutation \u2014 each has a property and no seam\nto assert it through. See [references\/refactoring.md](references\/refactoring.md) before\nconcluding there is nothing to assert.\n\n## Property catalog\n\n| Property | Formula | Where it applies |\n|---|---|---|\n| Roundtrip | `decode(encode(x)) == x` | Serialization, conversion pairs |\n| Inverse | `f(g(x)) == x` | encrypt\/decrypt, compress\/decompress |\n| Oracle | `new(x) == reference(x)` | Optimization, refactoring, reimplementation |\n| Idempotence | `f(f(x)) == f(x)` | Normalization, formatting, sorting |\n| Invariant | Holds before and after | Any transformation, contract state |\n| Easy to verify | `is_sorted(sort(x))` | Complex algorithms with cheap checkers |\n| Commutativity | `f(a, b) == f(b, a)` | Binary and set operations |\n| Associativity | `f(f(a,b), c) == f(a, f(b,c))` | Combining operations |\n| Identity | `f(x, e) == x` | Operations with a neutral element |\n\nStrength ordering, weakest to strongest:\n`no crash \u2192 type preservation \u2192 invariant \u2192 idempotence \u2192 roundtrip \/ oracle`.\n\nAssert the strongest property the code supports. \"No crash\" alone rarely justifies the\ndependency \u2014 if that is all you can find, either a small rearrangement exposes something\nstronger, or the honest report is that this code is a poor PBT candidate. Rule out the\nfirst before settling for the second.\n\n## The two ways a property test asserts nothing\n\n- **Tautology.** `assert add(a, b) == a + b` restates the implementation; no bug they\n  share can fail it. Pick a property that constrains the function without recomputing\n  it. Note the exception: `f(x) == f(x)` is a genuine determinism property when `f`\n  is not obviously pure \u2014 serializers over dicts or sets, hashing, anything reading\n  the clock.\n- **Vacuity.** `assume()` that filters out nearly every input passes without\n  exercising anything, and self-contradictory `assume()` passes having run zero cases.\n  Push constraints into the strategy so the generator produces valid inputs directly.\n\n## Where to look next\n\nLoad the one that matches the task in front of you:\n\n| Task | File |\n|---|---|\n| Writing new tests, designing strategies | [references\/generating.md](references\/generating.md) |\n| The code has no property to assert yet | [references\/refactoring.md](references\/refactoring.md) |\n| Reviewing existing property tests | [references\/reviewing.md](references\/reviewing.md) |\n| A property test just failed | [references\/interpreting-failures.md](references\/interpreting-failures.md) |\n| Library choice, Echidna and Medusa | [references\/libraries.md](references\/libraries.md) |\n\n## Introducing PBT to a project that lacks it\n\nIf the project already uses a PBT library, just write the tests in it. If it does not,\nadding one is a dependency decision that belongs to the user \u2014 offer it once with the\nspecific property you would write, and take the answer either way.\n","use_cases":["Testing encode\/decode and serialize\/deserialize pairs for roundtrip properties","Validating invariants in smart contracts using Echidna or Medusa","Reviewing existing property tests for tautologies or vacuous assumptions","Designing strategies for property-based tests with edge-case pinning and settings","Triaging property test failures to distinguish between wrong properties, ambiguous specs, and real bugs"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/sajaddp\/sonjoo-seo-audit\/blob\/b53a2eae486acf635a0b1dbd76be236343deb4b2\/.agents\/skills\/property-based-testing\/SKILL.md","source_commit":"b53a2eae486acf635a0b1dbd76be236343deb4b2","license":null,"version":null,"listing_approved_at":"2026-11-30","created_at":"2026-11-29T11:05:01.000000Z","updated_at":"2026-11-30T06:51:59.000000Z","seo_title":"Property-Based Testing for Software Development","seo_description":"Expert in writing and reviewing property-based tests using Hypothesis, fast-check, proptest, and Echidna\/Medusa. Focus on testing whole input domains, including encode\/\u89e3\u7801","seo_keywords":["property-based testing","Hypothesis","fast-check","proptest","jqwik","Echidna","Medusa","roundtrip property testing"]}}