Skip to content

test: Stage 3 CE144/CE145 codec edge cases#955

Merged
YCC3741 merged 2 commits into
mainfrom
feat/audit-stage3
Jun 14, 2026
Merged

test: Stage 3 CE144/CE145 codec edge cases#955
YCC3741 merged 2 commits into
mainfrom
feat/audit-stage3

Conversation

@HanaYukii

@HanaYukii HanaYukii commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Tests (11) — CE144/CE145 codec edge cases (#931 stage 3)

Function Cases
CE144Payload.Decode 10B (below 98B msg1 minimum) returns error
CE144Payload.Decode encoded minus last 50B (evidence truncated) returns error
CE144Payload.Encode/Decode tiny-mode roundtrip with CoresCount work reports
CE144Payload.Encode/Decode tranche>0 roundtrip (per-work-report Bandersnatch sig + no-show list shape)
CE145Payload.Validate Validity = 2 rejected
CE145Payload.Validate Validity = 0 + nil Guarantee rejected
CE145Payload.Validate Validity = 1 + non-nil Guarantee rejected
CE145Payload.Validate Validity = 0 + Guarantee with too few signatures rejected
CE145Payload.Decode 50B returns error containing "expected"
CE145Payload.Decode encoded minus last 30B (guarantee truncated) returns error
CE145Payload.Decode trailing bytes silently accepted (pins current behavior; see comment in test)

Builds 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's setupChainState so 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.

@HanaYukii HanaYukii self-assigned this Apr 27, 2026
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 HanaYukii requested review from YCC3741 and yu2C April 27, 2026 09:20
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

@YCC3741 YCC3741 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

NICE. LGTM.

- 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.
@YCC3741 YCC3741 merged commit 0dab387 into main Jun 14, 2026
8 checks passed
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