Skip to content

test: add table-driven Cosmos account tests - #14

Merged
Samarth208P merged 2 commits into
Samarth208P:mainfrom
Dhananjay-alt:test/cosmos-unit
Nov 21, 2026
Merged

Samarth208P merged 2 commits into
Samarth208P:mainfrom
Dhananjay-alt:test/cosmos-unit

Conversation

@Dhananjay-alt

Copy link
Copy Markdown
Contributor

Closes #2.

npm test never reached the success path in CosmosValidator. This adds the table-driven test suggested in the issue. It changes no library code, so nothing changes for users.

What's covered

tests/cosmos.test.ts has one table row per chain, with columns chain, account prefix, and whether 32-byte accounts are accepted.

  • Public result: for a 20-byte account on each of the five chains, the exact result is { valid: true, blockchain, details: { format: 'bech32', checksum: true } }.
  • 32-byte accounts: accepted on cosmos, osmosis and sei; rejected with INVALID_FORMAT on Injective and Celestia.
  • Cross-chain prefixes: every chain rejects the other four chains' prefixes.
  • Table guard: the table is checked against COSMOS_CHAINS, so adding a chain without a row fails.
  • Constructor: an unsupported chain identifier throws a RangeError.

Accounts are encoded with @scure/base (already a dev dependency), so the expected values don't depend on the decoder being tested.

Results

  • src/validators/cosmos.ts coverage: statements 81.8% → 100%, branches 68.8% → 100%.
  • 262 tests.
  • Overall coverage: statements 96.6%, branches 93.3%, functions 100%, lines 99.6%.
  • Locally on Linux, I ran a clean npm ci, npm run check and npm audit (0 vulnerabilities) on Node 22.23.5, 24.16.0 and 26.13.1, and npm run test:coverage on Node 24.16.0. All passed.
  • This repository's CI workflow ran on my fork for this exact commit (390b203), and all 7 jobs passed: package on Ubuntu and Windows with Node 22, 24 and 26 (Chrome stable), plus coverage. Run: https://github.com/Dhananjay-alt/validator0x/actions/runs/44905428079
  • Locally, the packed worker test ran in Playwright's Chromium because Chrome stable isn't installed on that machine. The fork CI run above used Chrome stable.

npm test never reached CosmosValidator's success path; valid accounts
were only checked by the separate differential suite. For each of the
five chains, assert the public result for a 20-byte account, whether
32-byte accounts are accepted (not on Injective or Celestia), and that
every other chain's prefix is rejected. Accounts are encoded with
@scure/base. Also cover the constructor's unsupported-chain RangeError.

cosmos.ts coverage: 81.8% -> 100% statements, 68.8% -> 100% branches.

Closes Samarth208P#2
Copilot AI balanced review requested due to automatic review settings November 21, 2026 12:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@Samarth208P
Samarth208P merged commit ac99ec0 into Samarth208P:main Nov 21, 2026
7 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.

test: CosmosValidator has no unit tests; the valid path is never reached by vitest

3 participants