fix(dapi): use deterministic keys in subscribeToNewTransactions test to prevent bloom filter false positives#3160
Conversation
The test used random PrivateKey() instances for address generation. Since bloom filters are probabilistic, random addresses can occasionally produce false positive matches (anotherAddress matching a filter built for address), causing the 'should send instant locks for new transactions' assertion to fail intermittently. Replace random keys with fixed deterministic private keys that are verified to not collide in the bloom filter configuration used by the test (BloomFilter.create(1, 0.0001)).
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughTests updated to replace randomly generated private keys with deterministic PrivateKey instances (explicit hex seeds) in bloom filter address setup to stabilize test addresses and prevent intermittent false positives. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@packages/dapi/test/integration/transactionsFilter/subscribeToNewTransactions.spec.js`:
- Around line 45-46: The hex string assigned to anotherAddress is 63 characters
long and will be truncated by Buffer.from when PrivateKey is constructed; update
the string used to create anotherAddress (the argument passed into new
PrivateKey(...).toAddress()) so it is exactly 64 hex characters (for example by
prepending a '0') so the PrivateKey receives a full 32-byte buffer.
packages/dapi/test/integration/transactionsFilter/subscribeToNewTransactions.spec.js
Outdated
Show resolved
Hide resolved
|
Hey @QuantumExplorer @shumkov — friendly ping for review on this one when you get a chance. 🙏 Quick summary: this fixes a known flaky test in CI is all green ✅ and the change is small (single test file). |
The second deterministic key was 63 hex chars (odd length), which causes Node.js Buffer.from(hex) to silently truncate to 31 bytes. Prepend '0' to make it a proper 64-char (32-byte) private key.
|
Addressed CodeRabbit feedback on the 63-char hex key: prepended |
Issue
The
subscribeToNewTransactionsintegration test inpackages/dapiis flaky — it intermittently fails with:This was blocking CI on unrelated PRs like #3089.
Root Cause
The test creates two addresses from
new PrivateKey()(random each run) and sets up a bloom filter for only the first address. Bloom filters are probabilistic — random addresses can occasionally produce hash collisions, causing the filter to match transactions sent toanotherAddresswhen it shouldn't.Important context: This test is fully synthetic — no live network data is involved:
beforeEachcreates local tx/block/instant-lock objects from scratchbloomFilterEmitterCollection.test()and.emit()Everything in the test is already deterministic (transactions, blocks, instant locks, bloom filter parameters) — except the private keys.
new PrivateKey()was the sole non-deterministic input, generating random addresses each run. Occasionally those random addresses would collide in the bloom filter, causing a false positive and a test failure.Fix
Replace random private keys with fixed, deterministic hex keys that are verified not to collide under
BloomFilter.create(1, 0.0001). This eliminates the source of non-determinism while preserving the test's intent (verifying that only matching transactions pass through the filter).This makes the last non-deterministic input deterministic, so the entire test is now fully reproducible across runs. Bloom filters remain probabilistic in production; this just ensures the test fixtures don't accidentally trigger that probabilism.
1 file changed, 5 insertions, 2 deletions.
Validation
Summary by CodeRabbit