fix: test to cover sequencing reactor#89
Conversation
WalkthroughThis PR refactors validator test construction and validation logic to use role-based voting powers (sequencer vs. attestor) instead of hardcoded constants and random values. Helper functions deterministically assign powers based on validator role, and proposer resolution logic adds nil-safety guards. ChangesRole-Based Validator Powers and Test Determinism
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
state/validation_test.go (2)
454-459: ⚡ Quick winMake the subtest’s precondition explicit.
The subtest name says “after last block time,” but
block.Timeis not set explicitly. On Line 458 this currently relies onmakeBlockbehavior. Set it directly to avoid brittle intent drift.Suggested patch
t.Run("block time after last block time passes without tolerance", func(t *testing.T) { height := int64(3) block, err := makeBlock(state, height, lastCommit) require.NoError(t, err) + block.Time = state.LastBlockTime.Add(time.Second) err = blockExec.ValidateBlock(state, block) require.NoError(t, err) })🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@state/validation_test.go` around lines 454 - 459, The subtest relies on makeBlock to set block.Time implicitly; make the precondition explicit by assigning block.Time to a value strictly after the state's last block time (e.g., state.LastBlockTime plus the validation tolerance and a small delta) before calling blockExec.ValidateBlock; update the test around makeBlock and ValidateBlock to set block.Time directly so the subtest name "after last block time passes without tolerance" cannot drift.
200-201: ⚡ Quick winTighten these assertions to the intended invalid-commit failure modes.
At Line 201 and Line 530,
require.Error(t, err)is too broad; unrelated failures would still pass. Please assert scenario-specific error type/message for each case so regressions stay diagnosable.Also applies to: 527-530
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@state/validation_test.go` around lines 200 - 201, The test currently calls blockExec.ValidateBlock(state, block) and only uses require.Error(t, err), which is too broad; replace those generic assertions at the two failing spots with scenario-specific checks: assert the error matches the expected sentinel or message for the invalid-commit case (e.g., use require.True(t, errors.Is(err, expectedErr)) if there is a sentinel error like ErrInvalidCommit, or require.ErrorContains(t, err, "invalid commit") / require.EqualError(t, err, "expected error string") to match the specific failure message), and import "errors" if using errors.Is; apply this change to the invocation of blockExec.ValidateBlock and the surrounding assertions so unrelated failures no longer pass silently.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@state/validation_test.go`:
- Around line 454-459: The subtest relies on makeBlock to set block.Time
implicitly; make the precondition explicit by assigning block.Time to a value
strictly after the state's last block time (e.g., state.LastBlockTime plus the
validation tolerance and a small delta) before calling blockExec.ValidateBlock;
update the test around makeBlock and ValidateBlock to set block.Time directly so
the subtest name "after last block time passes without tolerance" cannot drift.
- Around line 200-201: The test currently calls blockExec.ValidateBlock(state,
block) and only uses require.Error(t, err), which is too broad; replace those
generic assertions at the two failing spots with scenario-specific checks:
assert the error matches the expected sentinel or message for the invalid-commit
case (e.g., use require.True(t, errors.Is(err, expectedErr)) if there is a
sentinel error like ErrInvalidCommit, or require.ErrorContains(t, err, "invalid
commit") / require.EqualError(t, err, "expected error string") to match the
specific failure message), and import "errors" if using errors.Is; apply this
change to the invocation of blockExec.ValidateBlock and the surrounding
assertions so unrelated failures no longer pass silently.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f27a6c26-9eca-4f26-b759-e87d1f1c2dac
📒 Files selected for processing (9)
state/execution_test.gostate/helpers_test.gostate/rollback_test.gostate/state_test.gostate/store_test.gostate/validation_test.gotypes/validation.gotypes/validator_set.gotypes/validator_set_test.go
PR checklist
.changelog(we use unclog to manage our changelog)docs/orspec/) and code commentsSummary by CodeRabbit
Bug Fixes
Tests