-
Notifications
You must be signed in to change notification settings - Fork 706
feat: Improve consensus test ergonomics with snapshot testing #6555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Improve consensus test ergonomics with snapshot testing #6555
Conversation
33d7113
Codecov Report❌ Patch coverage is
❌ Your project status has failed because the head coverage (65.83%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## develop #6555 +/- ##
============================================
- Coverage 79.88% 65.83% -14.05%
============================================
Files 568 568
Lines 347203 347125 -78
============================================
- Hits 277377 228547 -48830
- Misses 69826 118578 +48752
... and 345 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
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
ExpectedResult
by hand!So, how does it work
Instead of stuffing the
ExpectedResult
into our test files,insta
saves it automatically into a separate.snap
file (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:
insta
generate the correct output for you.git diff
on the.snap
file will show exactly what changed in the output. Reviewing consensus-breaking changes should be easier.How do I use this?
Writing a new test:
ConsensusTestVector
like before, but just... don't add anexpected_result
.let result = ConsensusTest::new(...).run();
insta::assert_ron_snapshot!(result);
cargo insta review
to create the snapshot for you:.snap
file along with your code.Updating a test after you broke something (on purpose!):
cargo test
. It'll fail, andinsta
will print a beautiful diff showing you exactly what's different.cargo insta review
again.insta
will automatically update the snapshot file for you.Applicable issues
Additional info (benefits, drawbacks, caveats)
Checklist
docs/rpc/openapi.yaml
andrpc-endpoints.md
for v2 endpoints,event-dispatcher.md
for new events)clarity-benchmarking
repobitcoin-tests.yml