test(blockassembly): fix TestHandleReorgWithInvalidBlock_Integration on main#714
Conversation
…ck test TestHandleReorgWithInvalidBlock_Integration was failing on main after bsv-blockchain#545 landed. The test uses NewBlockchainDaemon which does not run the BlockValidation service, so when InvalidateBlock sets mined_set=false on the affected blocks, nothing reacts to the BlockMinedUnset notification to re-set mined_set=true. BA's reset() then blocks in waitForBlockMinedSet until its retry budget exhausts — well past the test's 15s Eventually window — and the test times out. Capture the hashes returned by InvalidateBlock and call SetBlockMinedSet on each to simulate BlockValidation's async reaction. This unblocks reset() and lets the test exercise what it's actually verifying: that handleReorg returns ErrBlockAssemblyReset after fallback reset so BA settles on the new chain tip. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
🤖 Claude Code Review Status: Complete No issues found. SummaryThis test-only change correctly addresses the test timeout issue by simulating BlockValidation's async response to InvalidateBlock. The approach is accurate:
The implementation correctly uses range iteration over the returned slice and passes pointer to each hash element to SetBlockMinedSet, matching the expected signature. |
Benchmark Comparison ReportBaseline: Current: Summary
All benchmark results (sec/op)
Threshold: >10% with p < 0.05 | Generated: 2026-04-16 21:34 UTC |
…ck test TestHandleReorgWithInvalidBlock_Integration (added in bsv-blockchain#545) fails on this branch and on main because the test setup does not run the BlockValidation service. InvalidateBlock sets mined_set=false and emits BlockMinedUnset, which BlockValidation normally consumes to re-set mined_set=true. With no BlockValidation running, BA's reset() blocks in waitForBlockMinedSet until its retry budget exhausts — past the test's 15s Eventually window. Capture the hashes returned by InvalidateBlock and call SetBlockMinedSet on each to simulate BlockValidation's async reaction. This change duplicates the fix on main in bsv-blockchain#714 to unblock CI on this PR before bsv-blockchain#714 is merged and rolled forward. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|



Summary
Follow-up to #545.
TestHandleReorgWithInvalidBlock_Integrationhas been failing onmainconsistently since the merge (see runs 24533201543, 24532254759, 24529039544).Root cause
The test uses
nodehelpers.NewBlockchainDaemon, which spins up the blockchain service but not BlockValidation.InvalidateBlocksetsmined_set=falseon the affected blocks and emits aBlockMinedUnsetnotification that BlockValidation normally consumes to re-setmined_set=true. With no BlockValidation running, nothing replies to the notification.The
reset()path added in #691 then blocks inwaitForBlockMinedSetuntil its retry budget is exhausted — far longer than the test's 15sEventuallywindow — so the test times out before BA can settle on chain B.Error from CI:
Fix
Capture the hashes returned by
InvalidateBlockand callSetBlockMinedSeton each, simulating BlockValidation's async reaction. This is a test-only change — no production code touched.Test plan
go test -count=1 -run '^TestHandleReorgWithInvalidBlock_Integration$' ./services/blockassembly/passes 3/3 runs locallygo vet ./services/blockassembly/...clean🤖 Generated with Claude Code