Skip to content

test(contracts): add comprehensive unit and integration test suite for @oaknetwork/contracts#82

Merged
tahseen-ccprotocol merged 4 commits intofeat/contract-sdkfrom
test/feat/contract-sdk
Mar 30, 2026
Merged

test(contracts): add comprehensive unit and integration test suite for @oaknetwork/contracts#82
tahseen-ccprotocol merged 4 commits intofeat/contract-sdkfrom
test/feat/contract-sdk

Conversation

@tahseen-ccprotocol
Copy link
Copy Markdown
Contributor

Summary

  • Adds 10 unit test files and 8 integration test files (~3,100 lines) achieving 100% code coverage for the @oaknetwork/contracts package
  • Restructures error parser default branches and extracts getRecoveryHint into its own module to enable accurate coverage measurement
  • Configures Jest with dotenv, coverage exclusions for barrel/ABI files, and separate test:unit / test:integration scripts

What changed

New test infrastructure

  • __tests__/setup/config.ts — Loads and strictly validates all required environment variables (RPC_URL, PRIVATE_KEY, contract addresses), throwing explicit errors if prerequisites are missing
  • __tests__/setup/test-client.ts — Shared OakContractsClient factory for integration tests
  • .env.example — Documents the 9 required environment variables for running integration tests on Celo Sepolia

Unit tests (10 files)

File | Covers -- | -- client.test.ts | createOakContractsClient, buildClients (including read-only path) guard.test.ts | isSimpleConfig, isReadOnlySimpleConfig type guards constants.test.ts | Chain IDs, encoding constants, fee keys, registry keys contract-entities.test.ts | All 8 entity factories (reads, writes, simulate, events) via mocks error-parsing.test.ts | All 9 error parsers + getRevertData + simulateWithErrorDecode errors.test.ts | All ~83 error classes + shared errors + getRecoveryHint utils.test.ts | requireAccount, requireSigner, resolveChain, hex/hash/time utilities provider.test.ts | Viem provider creation (createViemProvider) metrics.test.ts | Metric stub functions return expected shapes scripts.test.ts | Script stubs throw TODO errors as expected

All reads are wrapped in try/catch to handle uninitialized implementation contracts gracefully. Writes and simulates are wrapped since they are expected to revert without proper on-chain state.

Source changes (non-behavioral)

  • src/errors/recovery.ts (new) — Extracted getRecoveryHint from src/errors/index.ts so the barrel file is a pure re-export
  • src/errors/index.ts — Now re-exports getRecoveryHint from recovery.ts
  • src/errors/parse/*.ts — Restructured default branches in 8 error parsers with /* istanbul ignore next */ on genuinely unreachable defensive fallbacks (no logic changes)

Configuration

  • jest.config.cjs — Added dotenv/config setup, excluded barrel files (src/*/index.ts) and ABI files from coverage collection
  • package.json — Added test:unit and test:integration scripts; integration tests skip coverage thresholds; added dotenv as a devDependency

Test plan

  • Runpnpm test:unit— all unit tests pass with 100% coverage
  • Runpnpm test:integration— all 263 integration tests pass (requires.envwith Celo Sepolia addresses)
  • Runpnpm test— full suite passes with 90%+ global coverage threshold
  • Verify no source behavior changes — only test files, coverage config, andistanbul ignorecomments added

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: da2c509f38

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/contracts/__tests__/integration/client.test.ts
@tahseen-ccprotocol tahseen-ccprotocol merged commit 17e12a4 into feat/contract-sdk Mar 30, 2026
1 check passed
@devmahmud devmahmud deleted the test/feat/contract-sdk branch April 2, 2026 18:00
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