test: failing repros for confirmed v2-dev bugs (fixes to follow)#201
Open
MuncleUscles wants to merge 1 commit into
Open
test: failing repros for confirmed v2-dev bugs (fixes to follow)#201MuncleUscles wants to merge 1 commit into
MuncleUscles wants to merge 1 commit into
Conversation
Adds tests/bug-hunt-v2dev.test.ts: 12 tests, each reproducing a distinct
confirmed defect on the v2-dev (v0.6) integration branch. Every test is
expected to FAIL against current code and should pass once the underlying
bug is fixed. File:line and root cause are documented inline per block.
Wrong results:
- calldata toString(): map entries emitted with no separator ({"a":1"b":2})
- calldata toString(): per-byte hex not zero-padded (distinct bytes collide)
- toJsonSafeDeep(): shared (non-cyclic) references replaced with null
- createClient({endpoint}): mutates the shared chain-config singleton
- schema strictTypes: non-object accepted for struct param; float/NaN for int
- staking getValidatorInfo(): toHex() double-encodes already-hex extraCid
- vesting encodeExtraCid(): odd-length hex silently corrupted (0x123 -> 0x1230)
- isSuccessful(): always false for finalized studio/localnet transactions
Instability:
- calldata decode(): trusts attacker-supplied array/map counts (unbounded work)
- vesting exit: BigInt("") coerces empty shares to 0n and broadcasts
- staking: advertised isValidatorBelowMinStake helper missing at runtime
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017Xrmnk8SQeW3Aju4M7QHut
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
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.
What
Adds
tests/bug-hunt-v2dev.test.ts— 12 failing tests, each reproducing a distinct, confirmed defect onv2-dev(the v0.6 integration branch). This PR intentionally contains no fixes; the tests are the deliverable so a follow-up change can be validated against them. Every test documents thefile:lineand root cause inline.All 114 pre-existing tests still pass; only these 12 new tests fail.
Wrong results
toString()src/abi/calldata/string.ts:8-16{"a":1"b":2}(array branch adds,; the map branch doesn't). Corrupts thereadablefield of decoded receipts.toString()src/abi/calldata/string.ts:48-52, 62-66b.toString(16)with nopadStart(2,"0")→[0x01,0x02]and[0x12]both renderb#12; addresses render with <40 hex chars.toJsonSafeDeep()src/utils/jsonifier.ts:~90-94seen.add(value)is never released, so a DAG (same object referenced twice) has its 2nd occurrence replaced withnull. Reachable fromreadContractoutput.createClient({endpoint})src/client/client.ts:~132-135chainConfig.rpcUrls.default.http = [endpoint]mutates the shared imported chain singleton in place; one client's endpoint override leaks into every other client (and latercreateClient()calls).strictTypessrc/contracts/schema.ts:101-113if (isPlainObject(value)); a non-object scalar falls through toreturn trueand is accepted as a struct.strictTypessrc/contracts/schema.ts:55'int'accepts anytypeof === "number", so1.5/NaNpass validation and then crash later insidecalldata.encode.getValidatorInfo()src/staking/actions.ts:473toHex(identityRaw.extraCid)double-encodes — viem already returnsbytesas hex, so0xdeadbeefbecomes0x30786465616462656566(hex of the ASCII"0xdeadbeef"). Breaks the SDK's ownsetIdentity→getValidatorInforound-trip.encodeExtraCid()src/vesting/actions.ts:95-99startsWith("0x")cast with noisHex/even-length check; an odd-length CID is silently right-padded by viem (0x123→0x1230) and written on-chain with no error.isSuccessful()src/transactions/actions.ts:68-86executionResultName === FINISHED_WITH_RETURN, derived only fromtxExecutionResult(Name)— fields the studio/localnetgetTransactionpath never populates. A finalized, successful studio tx is reported as unsuccessful.Instability
decode()src/abi/calldata/decoder.ts:52-73TYPE_ARR/TYPE_MAPelement counts are taken straight off the wire and drive awhile/sliceloop with no bound against remaining bytes. A tiny malformed payload forces multi-second allocation before erroring (a fixed impl should reject in O(1)). Relevant becausedecode()runs on consensus/validator-supplied bytes.src/vesting/actions.ts:310, 362BigInt(options.shares)turns""into0n, silently signing & broadcasting a zero-share exit instead of rejecting the input.src/staking/actions.ts:550a338ad5advertised the helper asisValidatorBelowMinStake, but it's implemented asisValidatorBelowMin, so the documented name is missing at runtime (caller getsis not a function). It is also absent from theStakingActionstype.Why
These were surfaced by a focused bug hunt across the recent v0.6 work (calldata, fees/transactions, staking, vesting, accounts/contracts, utils/client). Each one can produce silently wrong results or client instability. Landing the repros first lets the fix PR be verified objectively.
Testing done
vitest run→ 114 pre-existing tests pass, the 12 new tests fail on their intended assertions (no harness errors).vitest --typecheck→ the new file typechecks clean (all reds are assertions).createClientsingleton-mutation test restoreslocalnetin afinally, so it does not pollute the rest of the run.Decisions made
encodeExtraCid/ the double-encode are internal, tests exercise them black-box through the public actions and decode the resulting calldata.accountActions.transfer(src/accounts/actions.ts:95) unconditionally callswaitForTransactionReceipt, but every other send lane returns early onchain.isStudio(seesrc/contracts/actions.ts:2363-2367). On a Studio localnet there is no EVM receipt, so a transfer would block ~180s then throw. No test is included because the correct fix is genuinely ambiguous (reject Studio early vs. synthesize a receipt — the method's return type isTransactionReceipt) and could not be reproduced against a live Studio backend.Position 42 is out of boundsRLP stderr intransactions.test.ts(benign —decodeInputDatacatches it and returnsnull); fee/budget math vs. the studio reference; call-key derivation; v0.6 enum remaps; vesting ABI signatures vs. the on-chain contracts.Checks
Reviewing tips
Read the inline comments in
tests/bug-hunt-v2dev.test.ts— eachdescribeblock names thefile:lineand root cause, and each assertion notes the actual (buggy) value it observes today.User facing release notes
None yet — this PR only adds failing regression tests. User-facing notes will accompany the fixes.
🤖 Generated with Claude Code
Generated by Claude Code