Skip to content

tests: add tests to ensapi using ens-test-env#1873

Open
sevenzing wants to merge 4 commits intomainfrom
ll/rest-api-tests
Open

tests: add tests to ensapi using ens-test-env#1873
sevenzing wants to merge 4 commits intomainfrom
ll/rest-api-tests

Conversation

@sevenzing
Copy link
Copy Markdown
Contributor

Summary

  • Add integration tests for the ENSApi resolution endpoints (resolve-primary-name, resolve-primary-names, resolve-records)
  • Minor updates docker-compose.yml: add build section to build images locally, also added RPC_URL_15658733 because without it running indexer with ens-test-env results in fail with error like failed to make request to localhost:8545

Why

  • Improve confidence in the REST API by covering real requests 👍


Pre-Review Checklist (Blocking)

  • This PR does not introduce significant changes and is low-risk to review quickly.
  • Relevant changesets are included (or are not required)

@sevenzing sevenzing requested a review from a team as a code owner April 5, 2026 20:04
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 5, 2026

🦋 Changeset detected

Latest commit: 5e8221e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 24 packages
Name Type
ensapi Patch
ensindexer Patch
ensadmin Patch
ensrainbow Patch
fallback-ensapi Patch
enssdk Patch
enscli Patch
enskit Patch
ensskills Patch
@ensnode/datasources Patch
@ensnode/ensrainbow-sdk Patch
@ensnode/ensdb-sdk Patch
@ensnode/ensnode-react Patch
@ensnode/ensnode-sdk Patch
@ensnode/ponder-sdk Patch
@ensnode/ponder-subgraph Patch
@ensnode/shared-configs Patch
@docs/ensnode Patch
@docs/ensrainbow Patch
@docs/mintlify Patch
@namehash/ens-referrals Patch
@namehash/namehash-ui Patch
@ensnode/enskit-react-example Patch
@ensnode/integration-test-env Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Apr 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
admin.ensnode.io Ready Ready Preview, Comment Apr 15, 2026 10:15am
ensnode.io Ready Ready Preview, Comment Apr 15, 2026 10:15am
ensrainbow.io Ready Ready Preview, Comment Apr 15, 2026 10:15am

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 5, 2026

Warning

Rate limit exceeded

@sevenzing has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 47 minutes and 32 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 47 minutes and 32 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 52813f57-a50b-4bed-b918-25ce54ec04d6

📥 Commits

Reviewing files that changed from the base of the PR and between f331be7 and 5e8221e.

📒 Files selected for processing (5)
  • apps/ensapi/src/lib/handlers/params.schema.ts
  • docs/docs.ensnode.io/ensapi-openapi.json
  • packages/ensnode-sdk/src/internal.ts
  • packages/ensnode-sdk/src/shared/devnet-accounts.ts
  • packages/enssdk/src/lib/ids.ts
📝 Walkthrough

Walkthrough

This PR adds integration tests for resolution API endpoints (resolve-records, resolve-primary-name, resolve-primary-names) while refactoring shared validation schemas. It introduces centralized devnet account constants in ensnode-sdk and updates existing tests to use these shared constants.

Changes

Cohort / File(s) Summary
Changesets Metadata
.changeset/sparkly-mangos-tease.md
New changeset entry marking ensapi package for patch release with integration tests added for resolution APIs.
Resolution API Routes
apps/ensapi/src/handlers/api/resolution/resolution-api.routes.ts
Refactored resolveRecordsRoute query schema to use shared params.resolveRecordsQuery definition instead of inline construction and transformation logic.
Resolution API Integration Tests
apps/ensapi/src/handlers/api/resolution/resolve-*.integration.test.ts
Added three new Vitest integration test suites for GET /api/resolve/records/{name}, /primary-name/{address}/{chainId}, and /primary-names/{address} endpoints, exercising successful resolution scenarios, acceleration behavior, input validation with HTTP 400 error responses, and edge cases like invalid addresses and chain IDs.
Query Schema Definitions
apps/ensapi/src/lib/handlers/params.schema.ts
Refactored selection schema into selectionFields and toSelection() helper function; introduced new exported resolveRecordsQuery schema combining selection, trace, and accelerate parameters with centralized transformation logic.
Shared Devnet Account Constants
packages/ensnode-sdk/src/shared/devnet-accounts.ts, packages/ensnode-sdk/src/internal.ts
Created new module exporting normalized devnet account constants (DEVNET_DEPLOYER, DEVNET_OWNER, DEVNET_USER, DEVNET_USER2) and re-exported from internal SDK barrel file.
Test Updates
apps/ensapi/src/omnigraph-api/schema/account.integration.test.ts
Updated GraphQL account integration tests to import and use shared devnet account constants from ensnode-sdk instead of locally derived values.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

javascript

Poem

🐰 With whiskers twitched and nose in code,
New tests are woven, schemas gleaned,
Devnet accounts now widely shared,
Resolution flows, all fine-tuned and squared!
Hop, test, refactor—progress made!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'tests: add tests to ensapi using ens-test-env' accurately summarizes the main change: adding integration tests for ENSApi endpoints using the ens-test-env testing environment.
Description check ✅ Passed The PR description covers the required template sections: Summary (with 2 clear bullets), Why (motivation provided), and completed Pre-Review Checklist. All essential information is present and well-organized.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ll/rest-api-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 5, 2026

Greptile Summary

This PR adds integration tests for the three ENSApi resolution endpoints (resolve-primary-name, resolve-primary-names, resolve-records) using a live ens-test-env Anvil chain, and consolidates previously duplicated devnet account constants into a shared devnet-accounts.ts module. It also includes a clean refactor of params.schema.ts that extracts the inline transform into a reusable toSelection helper and a dedicated resolveRecordsQuery schema — as a useful side-effect this eliminates the old pattern of calling .parse() inside a transform (which would throw instead of gracefully adding to ctx.issues). The OpenAPI spec is also corrected to reflect boolean for the name query parameter.

Confidence Score: 5/5

Safe to merge — changes are additive (new tests + shared constants) with a clean params refactor and no behavioral regressions.

All findings are P2 (one unused export). The params.schema.ts refactor is strictly better than the old approach and the integration test coverage is solid.

No files require special attention.

Important Files Changed

Filename Overview
apps/ensapi/src/lib/handlers/params.schema.ts Refactors the inline transform into a shared toSelection helper and adds resolveRecordsQuery, eliminating the unsafe .parse() call inside a transform that would have thrown rather than adding to ctx.issues.
packages/ensnode-sdk/src/shared/devnet-accounts.ts New shared module exporting the four well-known ens-test-env Anvil accounts; consolidates previously duplicated local constants across test files. DEVNET_USER2 is exported but currently unused in any test file.
apps/ensapi/src/handlers/api/resolution/resolve-records.integration.test.ts New integration tests for the records resolution endpoint covering addresses, texts, aliases, empty selection, normalisation, and duplicate/invalid coin type validation.
apps/ensapi/src/handlers/api/resolution/resolve-primary-name.integration.test.ts New integration tests for the primary-name resolution endpoint covering valid addresses, the accelerate flag, and invalid input error shapes.
apps/ensapi/src/handlers/api/resolution/resolve-primary-names.integration.test.ts New integration tests for the primary-names (multi-chain) endpoint covering default query, chainIds filtering, and invalid input validation errors.
apps/ensapi/src/omnigraph-api/schema/account.integration.test.ts Replaces locally-defined address constants with the new shared DEVNET_DEPLOYER, DEVNET_OWNER, and DEVNET_USER exports; no logic changes.
docs/docs.ensnode.io/ensapi-openapi.json Corrects the name query parameter type from "string" to "boolean" in the OpenAPI spec for the resolve-records route, matching the actual boolstring schema.

Sequence Diagram

sequenceDiagram
    participant Test as Integration Test
    participant ENSApi as ENSApi (Hono)
    participant Params as params.schema.ts
    participant Handler as Resolution Handler

    Test->>ENSApi: GET /api/resolve/records/:name?addresses=60
    ENSApi->>Params: resolveRecordsQuery.parse(query)
    Params->>Params: toSelection(fields, ctx)
    alt Selection is empty
        Params-->>ENSApi: ZodError "Selection cannot be empty."
        ENSApi-->>Test: 400 Invalid Input
    else Selection valid
        Params-->>ENSApi: { selection, trace, accelerate }
        ENSApi->>Handler: resolveRecords(name, selection, ...)
        Handler-->>ENSApi: { records, accelerationRequested, ... }
        ENSApi-->>Test: 200 { records: { addresses: { 60: "0x..." } }, ... }
    end

    Test->>ENSApi: GET /api/resolve/primary-name/:address/:chainId
    ENSApi->>Params: parse(address, chainId)
    Params-->>ENSApi: { address, chainId }
    ENSApi->>Handler: resolvePrimaryName(address, chainId, ...)
    Handler-->>ENSApi: { name: null, accelerationRequested, ... }
    ENSApi-->>Test: 200 { name: null, ... }

    Test->>ENSApi: GET /api/resolve/primary-names/:address?chainIds=1
    ENSApi->>Params: parse(address, chainIds)
    Params-->>ENSApi: { address, chainIds: [1] }
    ENSApi->>Handler: resolvePrimaryNames(address, chainIds, ...)
    Handler-->>ENSApi: { names: { "1": null }, ... }
    ENSApi-->>Test: 200 { names: { "1": null }, ... }
Loading

Reviews (2): Last reviewed commit: "lint + openspec generate" | Re-trigger Greptile

Comment thread apps/ensapi/src/test/integration/resolution-api-client.ts Outdated
Comment thread apps/ensapi/src/handlers/api/resolution/resolve-records.integration.test.ts Outdated
Comment thread apps/ensapi/src/handlers/api/resolution/resolve-records.integration.test.ts Outdated
@vercel vercel bot temporarily deployed to Preview – ensrainbow.io April 6, 2026 08:46 Inactive
@vercel vercel bot temporarily deployed to Preview – admin.ensnode.io April 6, 2026 08:46 Inactive
@vercel vercel bot temporarily deployed to Preview – ensnode.io April 6, 2026 08:46 Inactive
@sevenzing sevenzing changed the title Ll/rest api tests tests: add tests to ensapi using ens-test-env Apr 6, 2026
Copy link
Copy Markdown
Member

@lightwalker-eth lightwalker-eth left a comment

Choose a reason for hiding this comment

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

@sevenzing Hey cool to see this. Reviewed and shared some suggestions appreciate your advice.

Comment thread docker-compose.yml Outdated
Comment thread docker-compose.yml Outdated
Comment thread docker-compose.yml Outdated
Comment thread docker-compose.yml
Comment thread .changeset/sparkly-mangos-tease.md Outdated
Comment thread apps/ensapi/src/handlers/api/resolution/resolve-primary-names.integration.test.ts Outdated
Comment thread apps/ensapi/src/handlers/api/resolution/resolve-records.integration.test.ts Outdated
Comment thread apps/ensapi/src/handlers/api/resolution/resolve-records.integration.test.ts Outdated
Comment thread apps/ensapi/src/handlers/api/resolution/resolve-primary-name.integration.test.ts Outdated
Comment thread apps/ensapi/src/handlers/api/resolution/resolve-primary-names.integration.test.ts Outdated
Comment thread apps/ensapi/src/handlers/api/resolution/resolve-records.integration.test.ts Outdated
Comment thread apps/ensapi/src/handlers/api/resolution/resolve-records.integration.test.ts Outdated
Comment thread docker-compose.yml Outdated
Comment thread docker-compose.yml Outdated
Comment thread docker-compose.yml Outdated
const selection = params.selection.parse(selectionParams);
return { selection, trace, accelerate };
}),
query: params.resolveRecordsQuery,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this solves problem with 500 in https://api.alpha.ensnode.io/api/resolve/records/vitalik.eth

root problem is that .parse throws error inside .transform - not zod style

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@sevenzing Nice fix!

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@apps/ensapi/src/handlers/api/resolution/resolve-primary-names.integration.test.ts`:
- Around line 95-97: The fetch in the test (the call that builds
`${BASE_URL}/api/resolve/primary-names/${address}${query ? \`?\${query}\` :
""}`) can hang if the local service is down; wrap the request with an
AbortController, create a timeout (e.g., using setTimeout) that calls
controller.abort() after a short period (e.g., a few seconds), pass
controller.signal to fetch, and clear the timeout once fetch resolves to avoid
leaking timers; apply the same pattern wherever similar fetches are used in
tests like resolve-records.integration.test.ts and
resolve-primary-name.integration.test.ts.

In `@packages/ensnode-sdk/src/shared/devnet-accounts.ts`:
- Line 4: Typo in the module comment: replace the word "user" with "use" in the
top-of-file comment that reads "You can user `docker compose up devnet` to see
actual data in devnet" so it becomes "You can use `docker compose up devnet` to
see actual data in devnet"; update that comment in
packages/ensnode-sdk/src/shared/devnet-accounts.ts (the module header comment)
to fix the spelling.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 42ac76ab-6a5a-4042-afa0-19934647813a

📥 Commits

Reviewing files that changed from the base of the PR and between 1782b56 and f331be7.

📒 Files selected for processing (9)
  • .changeset/sparkly-mangos-tease.md
  • apps/ensapi/src/handlers/api/resolution/resolution-api.routes.ts
  • apps/ensapi/src/handlers/api/resolution/resolve-primary-name.integration.test.ts
  • apps/ensapi/src/handlers/api/resolution/resolve-primary-names.integration.test.ts
  • apps/ensapi/src/handlers/api/resolution/resolve-records.integration.test.ts
  • apps/ensapi/src/lib/handlers/params.schema.ts
  • apps/ensapi/src/omnigraph-api/schema/account.integration.test.ts
  • packages/ensnode-sdk/src/internal.ts
  • packages/ensnode-sdk/src/shared/devnet-accounts.ts

Comment thread packages/ensnode-sdk/src/shared/devnet-accounts.ts Outdated
@lightwalker-eth
Copy link
Copy Markdown
Member

@greptile

Copy link
Copy Markdown
Member

@lightwalker-eth lightwalker-eth left a comment

Choose a reason for hiding this comment

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

@sevenzing Great to see this! Shared some small suggestions please take the lead to merge when ready 👍

@@ -39,7 +36,7 @@ describe("Account.domains", () => {
`;

it("returns domains owned by the default owner", async () => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
it("returns domains owned by the default owner", async () => {
it("returns domains owned by the devnet owner", async () => {

Goal: Align with variable name update

const selection = params.selection.parse(selectionParams);
return { selection, trace, accelerate };
}),
query: params.resolveRecordsQuery,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@sevenzing Nice fix!

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.

ENSAPI: handling errors

3 participants