test: Stage 3 CE144/CE145 codec edge cases#955
Merged
Conversation
HanaYukii
added a commit
that referenced
this pull request
Apr 27, 2026
Address review on PR #955: the test reads types.CoresCount as the loop upper bound but does not set tiny mode, so a prior test that mutates CoresCount without restoring would make this test see a non-tiny value and the test name no longer matches the behavior. Mirror the setupChainState pattern from stage 1 tests: types.SetTinyMode() // entry guard t.Cleanup(types.SetTinyMode) // restore after test Tested: go test -mod=mod -v -run "TestCE144Payload_TinyCoresFull" ./internal/networking/handler/ce/ # pass go test -mod=mod ./internal/networking/handler/ce/ # full pkg pass
HanaYukii
added a commit
that referenced
this pull request
Apr 27, 2026
Five additions per reviewer suggestions on PR #955: CE144: 1. TrancheNonZeroRoundtrip — tranche>0 evidence has a completely different shape from tranche=0 (per-work-report Bandersnatch sig + no-show list, vs. a single 96B sig). TinyCoresFull only exercised tranche=0; this covers the other shape end-to-end. CE145 Validate() symmetric rules (the test file previously only covered the Validity ∉ {0,1} case; the other 3 invariants now have one test each): 2. InvalidJudgmentRequiresGuarantee — Validity=0 + nil Guarantee 3. ValidJudgmentRejectsGuarantee — Validity=1 + non-nil Guarantee 4. BadGuaranteeFails — Validity=0 + Guarantee with too few signatures (insufficient_guarantees, GuaranteeMinCount=2) CE145 trailing bytes: 5. AcceptsTrailingBytes_CurrentBehavior — pins current behavior (decoder silently accepts garbage after a valid header). If a future change tightens to reject, this test must be updated to assert error instead. Comment in the test explains the intent. Tested: go test -mod=mod -v -run "TestCE14[45]Payload_..." ./internal/networking/handler/ce/ # 11 pass go test -mod=mod ./internal/networking/handler/ce/ # full pkg pass
11 new tests on top of existing ce144_test.go (10 happy-path / dispatch tests) and ce145_test.go (14 tests). CE144: - Decode of 10B (below 98B msg1 minimum) returns error. - Decode of valid encoded payload minus last 50B (evidence truncated) returns error. - Encode/Decode roundtrip with CoresCount work reports under tiny mode (lock + cleanup mirroring stage 1's setupChainState). - Encode/Decode roundtrip for tranche>0 evidence shape (per-work-report Bandersnatch sig + no-show list, distinct from tranche=0 single sig). CE145 Validate symmetric rules (4 invariants in ce145.go:280-292; existing tests cover only #1, this PR adds #2–#4): - Validity ∉ {0, 1} rejected (= 2). - Validity = 0 with nil Guarantee rejected. - Validity = 1 with non-nil Guarantee rejected. - Validity = 0 with too-few-signatures Guarantee rejected (below GuaranteeMinCount = 2). CE145 Decode edges: - 50B short input returns error containing "expected". - Encoded invalid-judgment payload minus last 30B (guarantee truncated) returns error. - Trailing bytes after a valid header silently accepted; pins current behavior so a future tightening to reject is a deliberate change (test comment explains the intent). Tested in WSL: go test -mod=mod -v -run "TestCE14[45]Payload_..." ./internal/networking/handler/ce/ # 11 pass go test -mod=mod ./internal/networking/handler/ce/ # full pkg pass
55b0fb3 to
9b77703
Compare
This was referenced Jun 10, 2026
- CE144 TrancheNonZeroRoundtrip: drop the tiny-mode lock; the test fixes the work-report count at 2 and never reads types.CoresCount, so it does not depend on tiny mode. - Explain the byte-chop sizes in the CE144 truncated-evidence and CE145 truncated-guarantee tests so the magic numbers are self-justifying. - Pin the Validity == 0 trailing-bytes path too: decodeGuaranteeBytes consumes exactly count signature entries and ignores the remainder, mirroring the existing Validity == 1 pinning test.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tests (11) — CE144/CE145 codec edge cases (#931 stage 3)
CE144Payload.DecodeCE144Payload.DecodeCE144Payload.Encode/DecodeCoresCountwork reportsCE144Payload.Encode/DecodeCE145Payload.ValidateValidity = 2rejectedCE145Payload.ValidateValidity = 0+ nil Guarantee rejectedCE145Payload.ValidateValidity = 1+ non-nil Guarantee rejectedCE145Payload.ValidateValidity = 0+ Guarantee with too few signatures rejectedCE145Payload.Decode"expected"CE145Payload.DecodeCE145Payload.DecodeBuilds on existing 10 + 14 tests in
ce144_test.go/ce145_test.go; no overlap with main.Roundtrip tests (
TinyCoresFull,TrancheNonZeroRoundtrip) lock tiny mode for the duration of the test, mirroring stage 1'ssetupChainStateso the loop bound / shape does not depend on test ordering.Tested
```bash
go test -mod=mod -v -run "TestCE14[45]Payload_(Decode_|Tiny|Invalid|TrancheNonZero|Validate_)" ./internal/networking/handler/ce/ # 11 pass
go test -mod=mod ./internal/networking/handler/ce/ # full pkg pass
```
WSL only.