feat: Improve consensus test ergonomics with snapshot testing#3
Closed
Jiloc wants to merge 87 commits intojferrant:feat/aac-testing-boiler-platefrom
Closed
feat: Improve consensus test ergonomics with snapshot testing#3Jiloc wants to merge 87 commits intojferrant:feat/aac-testing-boiler-platefrom
Jiloc wants to merge 87 commits intojferrant:feat/aac-testing-boiler-platefrom
Conversation
…ate_ephemeral_marf Feat/block simulate ephemeral marf
… node to try to generate bitcoin blocks
…-events chore: remove `stacks-events` binary
…b-cli-to-stacks-inspect chore: move `stackslib::cli` module to `stacks-inspect`
- renamed stacks-inspect functions - replay_block -> validate_block - replay_block_nakamoto -> validate_block_nakamoto
…_replay Renaming block-replay script to block-validation
…only-for-miner bugfix: enforce bitcoin rpc only for miner
…fallible-to-compile-phase-6467 refactor: aac convert infallible error to compile time
insta for easier tests setup
jferrant
reviewed
Sep 30, 2025
| let msg = format!("Invalid Stacks block 518dfea674b5c4874e025a31e01a522c8269005c0685d12658f0359757de6692: {e:?}"); | ||
| let test_vector = ConsensusTestVector { | ||
| initial_balances, | ||
| initial_balances: vec![], |
Owner
There was a problem hiding this comment.
Oh interesting. I am surprised this didn't break the test. Thought it would complain about insufficient stx.
Author
There was a problem hiding this comment.
Yeah I found out that the boot_nakamoto function used internally already gives funds to the private key passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR is about simplifying the process of writing and updating our consensus tests.
the current drill: write a test, run it, see it fail, extract the data and then manually recreate the ExpectedResult struct from the terminal back into your code. It's easy to mess up.
This change introduces snapshot testing using a crate called
insta.Long story short: with this, we don't have to write the
ExpectedResultby hand!So, how does it work
Instead of stuffing the
ExpectedResultinto our test files,instasaves it automatically into a separate.snapfile (or inline, I have an example). These new files live in asnapshots/directory and we check them into Git. They become the "source of truth" for what the output should be.Pros:
instagenerate the correct output for you.git diffon the.snapfile will show exactly what changed in the output. Reviewing consensus-breaking changes should be easier.How do I use this?
Writing a new test:
ConsensusTestVectorlike before, but just... don't add anexpected_result.let result = ConsensusTest::new(...).run();insta::assert_ron_snapshot!(result);cargo insta reviewto create the snapshot for you:.snapfile along with your code.Updating a test after you broke something (on purpose!):
cargo test. It'll fail, andinstawill print a beautiful diff showing you exactly what's different.cargo insta reviewagain.instawill automatically update the snapshot file for you.Applicable issues
Additional info (benefits, drawbacks, caveats)
Checklist
docs/rpc/openapi.yamlandrpc-endpoints.mdfor v2 endpoints,event-dispatcher.mdfor new events)clarity-benchmarkingrepobitcoin-tests.yml