Skip to content

test: add core API coverage for translation registry - #384

Merged
Osuochasam merged 1 commit into
Open-audit-foundation:mainfrom
ScriptedBro:test/registry-core-api-coverage
Jul 25, 2026
Merged

test: add core API coverage for translation registry#384
Osuochasam merged 1 commit into
Open-audit-foundation:mainfrom
ScriptedBro:test/registry-core-api-coverage

Conversation

@ScriptedBro

Copy link
Copy Markdown
Contributor

Add comprehensive test suite for Translation Registry core API

Closes #382

Summary

Adds lib/translator/tests/registry.test.ts with 29 tests covering the core public API of the Translation Registry — the most critical module in the project. Achieves 90.97% line coverage on lib/translator/registry.ts as measured by vitest --coverage.

What changed

  • New file: lib/translator/tests/registry.test.ts (29 tests, 641 lines)
  • Dependencies: Added @vitest/coverage-v8@3.2.7 for coverage reporting

Test coverage

Area Tests What's covered
translateEvent 5 Known SAC transfer, unregistered contract fallback, blueprint matches rejection, blueprint translate returning null
translateEvents 3 Mixed batch processing, property-based robustness (never throws on any input shape), error handling via translateEventSafe catch block
translateWithCache 6 Redis hit returns cached result, Redis miss triggers store, persisted fields with defined status, persisted fields with default status, skip caching when txHash/id missing, skip when Redis disabled
registerBlueprint 2 New contract becomes translatable, merging second schema with ledger-based selection
registerUpgrade 3 New schema selected for post-upgrade ledgers, old schema for pre-upgrade, cache cleared only for the upgraded contract, no-op for unregistered contracts
matchesEventCriteria 7 contractId match, topic equals (exact), topic includes (case-insensitive), topic decodedName, combined criteria, empty criteria, out-of-range topic index
Registry helpers 4 hasBlueprint, getRegisteredContracts, getBlueprintCount

Coverage results

 % Coverage report from v8
 File         | % Stmts | % Branch | % Funcs | % Lines
 registry.ts  |   90.97 |    75.35 |   92.30 |   90.97

Verification

  • All 29 new tests pass
  • All 8 existing registry tests pass (registry.fallback.test.ts, registry.resolution-cache.test.ts, registry.versioning.test.ts)
  • 37/37 tests green

Uncovered lines (8.93%)

  • Lines 400, 408: console.warn inside the blueprint null-check branch (defensive unreachable — schema.blueprint is always set by resolveSchema)
  • Lines 418-428: unknownEventNoBlueprintApplicable path (requires a schema with a null blueprint, which cannot occur via buildRegistry or registerBlueprint)
  • Line 617: Array.isArray(existing) guard in registerBlueprint (defensive branch — REGISTRY is typed as Map<string, ContractRegistryEntry>, never stores arrays)

- translateEvent for known SAC transfer and unregistered contract fallback
- translateEvents batch processing and property-based robustness
- translateWithCache Redis integration and persisted field paths
- registerBlueprint runtime registration and schema merging
- registerUpgrade version selection and cache invalidation
- matchesEventCriteria all three topic matching strategies
- achieves 90.97% line coverage on lib/translator/registry.ts
@Osuochasam
Osuochasam merged commit 550228d into Open-audit-foundation:main Jul 25, 2026
2 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.

Write a comprehensive test suite for the Translation Registry core covering translateEvent, registerBlueprint, registerUpgrade, and matchesEventCriteria

2 participants