Skip to content

test(dapi): make transactionsFilter bloom-filter test deterministic#4023

Merged
QuantumExplorer merged 1 commit into
v4.1-devfrom
claude/hopeful-cohen-f7eb84
Jul 6, 2026
Merged

test(dapi): make transactionsFilter bloom-filter test deterministic#4023
QuantumExplorer merged 1 commit into
v4.1-devfrom
claude/hopeful-cohen-f7eb84

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Jul 6, 2026

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

The testTransactionAgainstFilter unit test "should not add outpoint to the filter if BLOOM_UPDATE_NONE flag is set in the filter" is flaky. It intermittently fails with:

AssertionError: expected true to be false

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. But testTransactionAgainstFilter also runs the transaction hash (checkHash) and the input outpoint txid:vout (checkInputs) through filter.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 expected false flips to true.

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_ONLY pub-key-hash, and multisig BLOOM_UPDATE_NONE cases).

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_modules weren'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-lib 0.22.0) in an isolated sandbox against an exact copy of the lib under test:

Version Runs Failures
Original (random keys) 200 2 (~1%) — flake reproduced
Fixed (this PR) 400 0

All 12 tests in the file pass. Reviewers can confirm in an installed tree with:

yarn workspace @dashevo/dapi test:unit

Breaking Changes

None.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Updated transaction filter tests to use fixed, reproducible key vectors instead of randomly generated keys.
    • Reduced occasional flaky failures by making address and public-key test inputs deterministic.
    • Kept all changes confined to test coverage; no production behavior was changed.

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>
@github-actions github-actions Bot added this to the v4.1.0 milestone Jul 6, 2026
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 34e9ad1f-5d77-4d58-8b1a-b61e1493ba6d

📥 Commits

Reviewing files that changed from the base of the PR and between f55b1ce and 9988b1c.

📒 Files selected for processing (1)
  • packages/dapi/test/unit/transactionsFilter/testTransactionAgainstFilter.spec.js

📝 Walkthrough

Walkthrough

This PR modifies a unit test file to replace randomly generated PrivateKey() instances with a fixed array of deterministic private keys, testPrivateKeys, used across address, pubkey, and multisig test scenarios. No production code or exported interfaces are changed.

Changes

Deterministic Test Key Vectors

Layer / File(s) Summary
Fixed key vector setup
packages/dapi/test/unit/transactionsFilter/testTransactionAgainstFilter.spec.js
Adds a testPrivateKeys array built from fixed private-key hex strings, with comments explaining the change avoids Bloom filter negative-assertion flakiness.
Apply fixed keys across test cases
packages/dapi/test/unit/transactionsFilter/testTransactionAgainstFilter.spec.js
Replaces ad-hoc new PrivateKey() calls with indexed testPrivateKeys entries across address-matching, script-matching, outpoint-update, and multisig pubkey tests.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Estimated code review effort: 1 (Trivial) | ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: making the transactionsFilter bloom-filter test deterministic.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/hopeful-cohen-f7eb84

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@thepastaclaw

thepastaclaw commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

✅ Review complete (commit 9988b1c)

@QuantumExplorer QuantumExplorer merged commit d4a91cd into v4.1-dev Jul 6, 2026
15 checks passed
@QuantumExplorer QuantumExplorer deleted the claude/hopeful-cohen-f7eb84 branch July 6, 2026 08:53

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

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.

2 participants