Skip to content

test(protocol): catch the missed mutants and fix the bugs they found - #101

Draft
astrovm wants to merge 1 commit into
mainfrom
test/mutants-95
Draft

astrovm wants to merge 1 commit into
mainfrom
test/mutants-95

Conversation

@astrovm

@astrovm astrovm commented Nov 29, 2026

Copy link
Copy Markdown
Member

The weekly mutation run listed 316 missed mutants in Issue #95: 303 in the TypeScript package and 13 in the Rust crate. This PR adds tests for the real gaps and rewrites code where a mutant could not change behavior. Mutants that no test can catch are marked with a reason. The tests also found two bugs, and this PR fixes them.

Closes #95

Bugs found

  1. uintSchema (EVM HTTP) threw a SyntaxError for text such as "1a" instead of returning a parse failure. Zod 4 runs .refine even after .regex fails, and BigInt("1a") throws. The regex now has { abort: true }.
  2. The base58 schemas for addresses and signatures decoded the whole input before they checked its length. Base58 decoding is quadratic: 100 000 characters took 3.3 s, and now take 0.1 ms. .max(44, { abort: true }) and .max(88, { abort: true }) stop first. A test checks that very long input is rejected in under 250 ms.

How each finding is handled

Area Fix
src/common base58 and hex checks hasBase58DecodedLength counts bytes with no loops: leading 1s plus the hex length of the decoded number. BASE58_PATTERN is gone (the decode rejects other characters). New tests: byte counts, leading zeros, an address whose top byte is 0x01, bad characters, the issue messages, and Hex32 anchors.
src/common HTTP client The unresolved-parameter check is /:[A-Za-z]/. The body is JSON.stringify(body), which is undefined for an endpoint without one. New tests: accept and content-type headers, a missing base URL, numbers, paths without a leading slash, loose record queries, null params and queries, error fields, and plain-text errors.
src/contracts/events New tests decode every field of every event and each refund layout, check the error texts, and cover the program log parser: whole-line anchors, depths 1 to 64, frame replacement, completions that pop only their own frame, failed: lines, padded base64, and payloads under 8 bytes. Number.isSafeInteger is gone: \d+ always gives a whole number, and Infinity fails depth > 64. Two mutants are marked: an extra first stack entry and depth + 1 keep the same top frame.
src/evm/http.ts New tests/evm-http.test.ts covers every schema: address and uint anchors, the 2^256 limit, token symbols and decimals, metadata limits, duplicate tokens (also by case), proofs, private joins, authorizations, game responses and game pages. Upper case finds the same duplicate symbols as lower case, so that mutant is marked.
src/amounts BigInt("") is 0n, so the `
src/oracle, src/web/verification.ts, src/solana/plans/contract-adapter.ts Checks that the type checker needs but that cannot change the result are marked with the reason. The SOL stake check is tokenAmount === undefined || tokenAmount <= 0n.
scripts/check-coverage.ts exclude uses ?.some. LCOV line data is read with one anchored regex (DA:<line>,<hits>[,<checksum>]). git ls-files output needs no backslash replacement and is already sorted. A path outside the root matches no tracked file, so its special case is gone. New tests: scope roots, globs, trackedFiles, extra LCOV records, data outside a record, a missing end_of_record, several extensions and several missing files.
scripts/check-evm-upstream.ts, scripts/check-package-version.ts Read JSON with Bun.file().json(). The npm error check reads .error.code directly, so output without an error object throws like plain text. The main-script checks are marked: tests import these files.
Rust address.rs !(32..=44).contains(&len) (the clippy form). New cases: exactly 16 seeds and a 32-byte seed are allowed.
Rust amounts.rs Zero padding uses format!("{digits:0>width$}"). New cases: 0.5, 0.123, 1.234.
Rust contracts.rs data.starts_with(&GAME_ACCOUNT) replaces the length and slice check. New cases: short data, free space after the participants, and a participant count past the data.
Rust events.rs New test: a known discriminator with no fields is an error. depth - 1 → depth + 1 or depth / 1 in get_trusted_program_data is excluded in .cargo/mutants.toml, for the same reason as in TypeScript.
Rust plans.rs, validators.rs New tests: refunds never wrap SOL, and is_base64_transaction accepts 16 384 characters but not more.

All changes

  1. src/common/index.ts: the two bug fixes above, the loop-free byte count, the simpler parameter check and the request body.
  2. src/evm/http.ts: { abort: true } on the uint regex.
  3. src/contracts/events/index.ts: no Number.isSafeInteger; two marked mutants.
  4. src/amounts/index.ts, src/oracle/index.ts, src/web/verification.ts, src/solana/plans/contract-adapter.ts: the small rewrites and marks in the table.
  5. scripts/check-coverage.ts, scripts/check-evm-upstream.ts, scripts/check-package-version.ts: the rewrites in the table.
  6. crates/timba-protocol/src/{address,amounts,contracts,events,plans,validators}.rs: rewrites and tests.
  7. .cargo/mutants.toml: one exclusion with its reason.
  8. Tests: new tests/evm-http.test.ts; more cases in scripts/check-coverage.test.ts and in the amounts, client, events, package-version, protocol, randomness, Solana adapter, plans and token-program, token-policy, verification and workflow tests.
  9. dist/: rebuilt.
  10. Version 0.18.4 in package.json, Cargo.toml, Cargo.lock and the README tag, because the latest release is v0.18.3.

Done when

  • bun run format:check, bun run typecheck, bun test (207 pass), check:rust-fixtures and the 100% line coverage gate pass on 560ec14.
  • cargo fmt --check, cargo clippy --all-features --all-targets -D warnings and cargo test --all-features pass on 560ec14.
  • StrykerJS on all 19 files of the issue: 1323 killed, 0 survived, 0 without coverage, 0 timeouts; 23 marked with a reason.
  • cargo-mutants on every function of the 13 Rust rows: 60 of 60 caught.
  • CI passes.
  • Agent review.

Review

Pending.

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.

Missed mutants

1 participant