tests: improve clarity vm tests#7257
Conversation
…tantiate_chainstate when using empty balances
Coverage Report for CI Build 28179718097Coverage increased (+0.3%) to 86.047%Details
Uncovered Changes
Coverage Regressions8890 previously-covered lines in 130 files lost coverage.
Coverage Stats
💛 - Coveralls |
francesco-stacks
left a comment
There was a problem hiding this comment.
overall looks good, I think that we start to have a bit too many initializers for StacksChainState and maybe it would improve a bit to refactor it with the builder pattern, but I also get that this is a very niche test suite, so i don't have a strong opinion about it
I gave the builder idea a try: b3e9510 |
There was a problem hiding this comment.
Pull request overview
This PR refactors and corrects Clarity VM/unit-test harness setup to ensure the epoch under test aligns with the boot cost contracts actually deployed in the underlying Clarity database/MARF. It centralizes epoch-transition setup for Clarity VM tests and expands chainstate test instantiation helpers to optionally predeploy all costs-N contracts at genesis for tests that exercise multiple epochs.
Changes:
- Add
apply_transitions_for_epoch()test helper and adopt it in VM tests to reach target epochs deterministically. - Introduce
TestChainstateBuilderand new chainstate instantiation helpers to optionally deploy allcosts-Ncontracts at genesis (and normalizechainstate_path()for::in test names). - Update multiple tests to use the revised helpers and tighten assertions around expected cost-contract defaults.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| stackslib/src/core/tests/mod.rs | Switch test chainstate setup to simplified instantiation helper. |
| stackslib/src/clarity_vm/tests/test_utils.rs | New shared helper to run genesis + epoch transitions for VM tests. |
| stackslib/src/clarity_vm/tests/mod.rs | Export the new test_utils module. |
| stackslib/src/clarity_vm/tests/large_contract.rs | Use the shared epoch-transition helper to ensure correct cost contracts for the epoch under test. |
| stackslib/src/clarity_vm/tests/costs.rs | Replace ad-hoc epoch transition sequences with shared helper; tighten expected default cost-version checks. |
| stackslib/src/clarity_vm/tests/analysis_costs.rs | Adjust genesis/transition burn-state usage so cost tracker loads the intended boot cost contract from MARF. |
| stackslib/src/chainstate/stacks/tests/block_construction.rs | Update mempool-walk tests to use the simplified chainstate instantiation helper. |
| stackslib/src/chainstate/stacks/db/transactions.rs | Update transaction-processing tests to use chainstate helpers that predeploy all costs-N contracts when iterating over multiple epochs. |
| stackslib/src/chainstate/stacks/db/mod.rs | Add TestChainstateBuilder, deploy-all-costs helper, new instantiation variants, and sanitize chainstate_path(). |
| changelog.d/improve-clarity-vm-tests.changed | Add changelog entry for the test harness improvements. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
Tidy-up and correctness pass over the Clarity VM unit tests (
costs.rs,analysis_costs.rs,large_contract.rs,transactions.rs) and the shared test instantiation helpers. The main functional fix addresses a latent mismatch where a test'sBurnStateDBepoch and the cost contracts actually deployed in theClarityDatabasecould disagree the tests still passed, but exercised the wrong costs-N contract for the epoch under test.Applicable issues
Additional info (benefits, drawbacks, caveats)
Checklist
docs/property-testing.md)changelog.d/README.md)rpc/openapi.yamlfor RPC endpoints,event-dispatcher.mdfor new events)clarity-benchmarkingrepo