Skip to content

test: Achieve 80% unit test coverage across lib/translator/ and add contract blueprint validation tests #229

Description

@grantfox-oss

Body:
Summary
The Translation Registry in lib/translator/ is the most critical part of Open-Audit — it is responsible for converting raw Stellar XDR events into human-readable output. Despite its importance, test coverage for this module is incomplete, and there are no automated tests that validate the correctness of community-contributed blueprints in lib/translator/blueprints/. This creates a risk that broken translations get merged and silently produce incorrect output.
Required work

  1. Unit tests for lib/translator/registry.ts — covering:

Known contract ID returns the correct blueprint
Unknown contract ID returns a graceful fallback (untranslated raw event, no throw)
Blueprint template interpolation with all supported field types (address, amount, asset code, timestamp)
Malformed XDR input is handled without crashing
Translation output matches the exact string format documented in CONTRIBUTING.md

  1. Unit tests for lib/translator/secure-xdr-parser.ts — covering:

Valid XDR hex returns { success: true, value: ... }
Deeply nested XDR (depth > MAX) returns { success: false } with a descriptive error
Oversized payload (> 10MB) is rejected before parsing begins
Parsing timeout fires correctly for an intentionally slow mock
Each ScVal type (address, int128, string, bool, vec, map) parses to its expected output

  1. Blueprint schema validation tests — for every file in lib/translator/blueprints/:

Each blueprint exports the required fields: contractId, events (array), each event has topic, template, and fields
Field references in template (e.g. {from}, {amount}) all exist in the fields array — no dangling references
No two blueprints register the same contractId
Run this as a Vitest test so CI catches invalid blueprints on every PR

  1. Add a coverage threshold to vitest.config.ts:
    tscoverage: {
    thresholds: {
    'lib/translator/**': { lines: 80, functions: 80, branches: 75 }
    }
    }
    Acceptance criteria

npm test passes with coverage ≥ 80% lines and functions across lib/translator/
Blueprint validation test catches a deliberately broken blueprint (add one as a fixture, assert the test fails, then remove it)
All existing tests continue to pass
CI workflow runs coverage check and fails the build if threshold is not met

Metadata

Metadata

Assignees

No one assigned

    Labels

    Official CampaignCampaign: Official CampaignbugSomething isn't workingdocumentationImprovements or additions to documentation

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions