test(dapi): make transactionsFilter bloom-filter test deterministic#4023
Conversation
The testTransactionAgainstFilter unit tests built a fresh BloomFilter and inserted a randomly generated key, then asserted that unrelated data (an outpoint, a different address, the tx hash) did NOT match. Because a bloom filter has a non-zero false-positive rate, those negative assertions occasionally matched by chance and the test flaked -- e.g. "should not add outpoint to the filter if BLOOM_UPDATE_NONE flag is set" intermittently failed with `expected true to be false` (seen on CI run 28774171971). Replace the random `new PrivateKey()` inputs with a fixed pool of deterministic test-vector keys so every assertion is reproducible. Verified by running the spec 400x with zero failures (the previous version flaked ~1% of runs). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR modifies a unit test file to replace randomly generated ChangesDeterministic Test Key Vectors
Estimated code review effort: 1 (Trivial) | ~5 minutes Estimated code review effort: 1 (Trivial) | ~5 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
✅ Review complete (commit 9988b1c) |
There was a problem hiding this comment.
Code Review
Source: reviewers opus (claude-general) and gpt-5.5 (codex-general); verifier opus (claude); specialists: none.
Both agents independently reviewed this test-only PR that replaces random private keys with deterministic secp256k1 test vectors in the DAPI transactionsFilter unit tests. Neither found any in-scope defects, and the change is well-scoped to eliminating bloom-filter false-positive flakiness. Approving.
Issue being fixed or feature implemented
The
testTransactionAgainstFilterunit test "should not add outpoint to the filter if BLOOM_UPDATE_NONE flag is set in the filter" is flaky. It intermittently fails with:This flaked on CI run 28774171971 (job 85315592482) for an unrelated PR (#3841) that touches no dapi code.
Root cause: the affected tests build a fresh
BloomFilter.create(1, 0.0001), insert a randomly generated address/pubkey (new PrivateKey().toAddress()), and then assert that unrelated data does not match. ButtestTransactionAgainstFilteralso runs the transaction hash (checkHash) and the input outpointtxid:vout(checkInputs) throughfilter.contains()— neither of which was inserted. A bloom filter has a non-zero false-positive rate, so with random inputs those negative checks occasionally match by chance and the expectedfalseflips totrue.The same latent flakiness affects every test in the file that generates random keys and asserts
.to.be.false()(the "no such output", "input doesn't contain desired data",BLOOM_UPDATE_P2PUBKEY_ONLYpub-key-hash, and multisigBLOOM_UPDATE_NONEcases).What was done?
Replaced the random
new PrivateKey()inputs with a fixed pool of deterministic test-vector private keys (0x01…0x0a), mirroring the idiom already used by the neighboring "should pass the same test vector as dashcore implementation does" test. Every address, transaction hash, and outpoint is now fixed, so each assertion is fully reproducible. A comment documents why the keys must stay fixed.No production code changed — this is a test-only fix.
How Has This Been Tested?
Because the repo's
node_modulesweren't installed locally, I ran the actual post-edit spec file through the same tool versions the package pins (mocha 11, chai 4, dirty-chai 2,@dashevo/dashcore-lib0.22.0) in an isolated sandbox against an exact copy of the lib under test:All 12 tests in the file pass. Reviewers can confirm in an installed tree with:
Breaking Changes
None.
Checklist:
For repository code-owners and collaborators only
🤖 Generated with Claude Code
Summary by CodeRabbit