Skip to content

tests: improve clarity vm tests#7257

Open
federico-stacks wants to merge 13 commits into
stacks-network:developfrom
federico-stacks:test/improve-vm-tests
Open

tests: improve clarity vm tests#7257
federico-stacks wants to merge 13 commits into
stacks-network:developfrom
federico-stacks:test/improve-vm-tests

Conversation

@federico-stacks

@federico-stacks federico-stacks commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

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's BurnStateDB epoch and the cost contracts actually deployed in the ClarityDatabase could disagree the tests still passed, but exercised the wrong costs-N contract for the epoch under test.

This issue emerged during PR #6959 where caching for ClarityDatabase epoch was introduced, making the now "fixed" tests failing.

Applicable issues

  • fixes #

Additional info (benefits, drawbacks, caveats)

Checklist

  • Test coverage for new or modified code paths
  • For new Clarity features or consensus changes, add property tests (see docs/property-testing.md)
  • Changelog fragment(s) or "no changelog" label added (see changelog.d/README.md)
  • Required documentation changes (e.g., rpc/openapi.yaml for RPC endpoints, event-dispatcher.md for new events)
  • New clarity functions have corresponding PR in clarity-benchmarking repo

@federico-stacks federico-stacks self-assigned this Jun 1, 2026
@coveralls

coveralls commented Jun 1, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 28179718097

Coverage increased (+0.3%) to 86.047%

Details

  • Coverage increased (+0.3%) from the base build.
  • Patch coverage: 4 uncovered changes across 1 file (187 of 191 lines covered, 97.91%).
  • 8890 coverage regressions across 130 files.

Uncovered Changes

File Changed Covered %
stackslib/src/chainstate/stacks/db/mod.rs 124 120 96.77%
Total (2 files) 191 187 97.91%

Coverage Regressions

8890 previously-covered lines in 130 files lost coverage.

Top 10 Files by Coverage Loss Lines Losing Coverage Coverage
stackslib/src/chainstate/burn/db/sortdb.rs 505 90.19%
stackslib/src/chainstate/stacks/db/blocks.rs 502 89.93%
stackslib/src/chainstate/nakamoto/mod.rs 403 84.62%
stackslib/src/config/mod.rs 376 68.96%
stackslib/src/net/mod.rs 309 78.12%
stackslib/src/chainstate/stacks/index/storage.rs 277 82.41%
clarity/src/vm/database/clarity_db.rs 268 82.11%
stackslib/src/chainstate/stacks/miner.rs 253 83.4%
stackslib/src/chainstate/stacks/db/transactions.rs 239 97.16%
stackslib/src/net/inv/epoch2x.rs 221 79.49%

Coverage Stats

Coverage Status
Relevant Lines: 226549
Covered Lines: 194939
Line Coverage: 86.05%
Coverage Strength: 18801135.9 hits per line

💛 - Coveralls

Comment thread stackslib/src/chainstate/stacks/db/mod.rs Outdated
Comment thread stackslib/src/clarity_vm/tests/analysis_costs.rs Outdated

@francesco-stacks francesco-stacks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@federico-stacks

federico-stacks commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

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
I kept the usage hidden behind the instantiate_chainstate* methods to reduce impact on the existent tests.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 TestChainstateBuilder and new chainstate instantiation helpers to optionally deploy all costs-N contracts at genesis (and normalize chainstate_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.

Comment thread stackslib/src/clarity_vm/tests/test_utils.rs
Comment thread stackslib/src/chainstate/stacks/db/mod.rs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants