11import type { Address } from "viem" ;
22import { beforeEach , describe , expect , it , vi } from "vitest" ;
33
4- import { ENSNodeClient } from "./client" ;
5- import { ClientError } from "./client-error" ;
6- import { DEFAULT_ENSNODE_API_URL_MAINNET , getDefaultEnsNodeUrl } from "./deployments" ;
7- import { ENSNamespaceIds , type Name } from "./ens" ;
8- import { deserializeENSApiPublicConfig , type SerializedENSApiPublicConfig } from "./ensapi" ;
4+ import { ENSNamespaceIds , type Name } from "../ens" ;
5+ import { PluginName } from "../ensindexer/config/types" ;
6+ import {
7+ ChainIndexingConfigTypeIds ,
8+ ChainIndexingStatusIds ,
9+ } from "../indexing-status/chain-indexing-status-snapshot" ;
10+ import { CrossChainIndexingStrategyIds } from "../indexing-status/cross-chain-indexing-status-snapshot" ;
11+ import { OmnichainIndexingStatusIds } from "../indexing-status/omnichain-indexing-status-snapshot" ;
12+ import type { SerializedOmnichainIndexingStatusSnapshotFollowing } from "../indexing-status/serialize/omnichain-indexing-status-snapshot" ;
13+ import type { ResolverRecordsSelection } from "../resolution" ;
914import {
1015 deserializeIndexingStatusResponse ,
1116 type ErrorResponse ,
@@ -15,16 +20,12 @@ import {
1520 type ResolvePrimaryNamesResponse ,
1621 type SerializedIndexingStatusResponseOk ,
1722 serializeIndexingStatusResponse ,
18- } from "./ensapi/api" ;
19- import { PluginName } from "./ensindexer/config/types" ;
20- import {
21- ChainIndexingConfigTypeIds ,
22- ChainIndexingStatusIds ,
23- } from "./indexing-status/chain-indexing-status-snapshot" ;
24- import { CrossChainIndexingStrategyIds } from "./indexing-status/cross-chain-indexing-status-snapshot" ;
25- import { OmnichainIndexingStatusIds } from "./indexing-status/omnichain-indexing-status-snapshot" ;
26- import type { SerializedOmnichainIndexingStatusSnapshotFollowing } from "./indexing-status/serialize/omnichain-indexing-status-snapshot" ;
27- import type { ResolverRecordsSelection } from "./resolution" ;
23+ } from "./api" ;
24+ import { ENSApiClient } from "./client" ;
25+ import { ClientError } from "./client-error" ;
26+ import { deserializeENSApiPublicConfig } from "./config/deserialize" ;
27+ import type { SerializedENSApiPublicConfig } from "./config/serialized-types" ;
28+ import { DEFAULT_ENSNODE_API_URL_MAINNET , getDefaultEnsNodeUrl } from "./deployments" ;
2829
2930const EXAMPLE_NAME : Name = "example.eth" ;
3031const EXAMPLE_ADDRESS : Address = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045" ;
@@ -201,29 +202,29 @@ const _EXAMPLE_INDEXING_STATUS_FOLLOWING_RESPONSE: IndexingStatusResponse =
201202const mockFetch = vi . fn ( ) ;
202203global . fetch = mockFetch ;
203204
204- describe ( "ENSNodeClient " , ( ) => {
205+ describe ( "ENSApiClient " , ( ) => {
205206 beforeEach ( ( ) => {
206207 mockFetch . mockClear ( ) ;
207208 } ) ;
208209
209210 describe ( "constructor and options" , ( ) => {
210211 it ( "should use default options when none provided" , ( ) => {
211- const client = new ENSNodeClient ( ) ;
212+ const client = new ENSApiClient ( ) ;
212213 const options = client . getOptions ( ) ;
213214
214215 expect ( options ) . toEqual ( { url : getDefaultEnsNodeUrl ( ENSNamespaceIds . Mainnet ) } ) ;
215216 } ) ;
216217
217218 it ( "should merge provided options with defaults" , ( ) => {
218219 const customUrl = new URL ( "https://custom.api.com" ) ;
219- const client = new ENSNodeClient ( { url : customUrl } ) ;
220+ const client = new ENSApiClient ( { url : customUrl } ) ;
220221 const options = client . getOptions ( ) ;
221222
222223 expect ( options ) . toEqual ( { url : customUrl } ) ;
223224 } ) ;
224225
225226 it ( "should return frozen options object" , ( ) => {
226- const client = new ENSNodeClient ( ) ;
227+ const client = new ENSApiClient ( ) ;
227228 const options = client . getOptions ( ) ;
228229
229230 expect ( Object . isFrozen ( options ) ) . toBe ( true ) ;
@@ -236,7 +237,7 @@ describe("ENSNodeClient", () => {
236237 const mockResponse = { records : EXAMPLE_RECORDS_RESPONSE } ;
237238 mockFetch . mockResolvedValueOnce ( { ok : true , json : async ( ) => mockResponse } ) ;
238239
239- const client = new ENSNodeClient ( ) ;
240+ const client = new ENSApiClient ( ) ;
240241 const response = await client . resolveRecords ( EXAMPLE_NAME , EXAMPLE_SELECTION ) ;
241242
242243 const expectedUrl = new URL (
@@ -254,7 +255,7 @@ describe("ENSNodeClient", () => {
254255 const mockResponse = { records : EXAMPLE_RECORDS_RESPONSE , trace : [ ] } ;
255256 mockFetch . mockResolvedValueOnce ( { ok : true , json : async ( ) => mockResponse } ) ;
256257
257- const client = new ENSNodeClient ( ) ;
258+ const client = new ENSApiClient ( ) ;
258259 const response = await client . resolveRecords ( EXAMPLE_NAME , EXAMPLE_SELECTION , {
259260 trace : true ,
260261 } ) ;
@@ -274,7 +275,7 @@ describe("ENSNodeClient", () => {
274275 it ( "should throw error when API returns error" , async ( ) => {
275276 mockFetch . mockResolvedValueOnce ( { ok : false , json : async ( ) => EXAMPLE_ERROR_RESPONSE } ) ;
276277
277- const client = new ENSNodeClient ( ) ;
278+ const client = new ENSApiClient ( ) ;
278279 await expect ( client . resolveRecords ( EXAMPLE_NAME , EXAMPLE_SELECTION ) ) . rejects . toThrowError (
279280 ClientError ,
280281 ) ;
@@ -288,7 +289,7 @@ describe("ENSNodeClient", () => {
288289 json : async ( ) => EXAMPLE_PRIMARY_NAME_RESPONSE ,
289290 } ) ;
290291
291- const client = new ENSNodeClient ( ) ;
292+ const client = new ENSApiClient ( ) ;
292293 const response = await client . resolvePrimaryName ( EXAMPLE_ADDRESS , 1 ) ;
293294
294295 const expectedUrl = new URL (
@@ -304,7 +305,7 @@ describe("ENSNodeClient", () => {
304305 const mockResponse = { name : EXAMPLE_NAME , trace : [ ] } ;
305306 mockFetch . mockResolvedValueOnce ( { ok : true , json : async ( ) => mockResponse } ) ;
306307
307- const client = new ENSNodeClient ( ) ;
308+ const client = new ENSApiClient ( ) ;
308309 const response = await client . resolvePrimaryName ( EXAMPLE_ADDRESS , 1 , { trace : true } ) ;
309310
310311 const expectedUrl = new URL (
@@ -323,7 +324,7 @@ describe("ENSNodeClient", () => {
323324 json : async ( ) => EXAMPLE_PRIMARY_NAME_RESPONSE ,
324325 } ) ;
325326
326- const client = new ENSNodeClient ( ) ;
327+ const client = new ENSApiClient ( ) ;
327328 await client . resolvePrimaryName ( EXAMPLE_ADDRESS , 1 , { accelerate : true } ) ;
328329
329330 const expectedUrl = new URL (
@@ -338,7 +339,7 @@ describe("ENSNodeClient", () => {
338339 it ( "should throw error when API returns error" , async ( ) => {
339340 mockFetch . mockResolvedValueOnce ( { ok : false , json : async ( ) => EXAMPLE_ERROR_RESPONSE } ) ;
340341
341- const client = new ENSNodeClient ( ) ;
342+ const client = new ENSApiClient ( ) ;
342343 await expect ( client . resolvePrimaryName ( EXAMPLE_ADDRESS , 1 ) ) . rejects . toThrowError ( ClientError ) ;
343344 } ) ;
344345 } ) ;
@@ -350,7 +351,7 @@ describe("ENSNodeClient", () => {
350351 json : async ( ) => EXAMPLE_PRIMARY_NAMES_RESPONSE ,
351352 } ) ;
352353
353- const client = new ENSNodeClient ( ) ;
354+ const client = new ENSApiClient ( ) ;
354355 const response = await client . resolvePrimaryNames ( EXAMPLE_ADDRESS ) ;
355356
356357 const expectedUrl = new URL (
@@ -368,7 +369,7 @@ describe("ENSNodeClient", () => {
368369 json : async ( ) => EXAMPLE_PRIMARY_NAMES_RESPONSE ,
369370 } ) ;
370371
371- const client = new ENSNodeClient ( ) ;
372+ const client = new ENSApiClient ( ) ;
372373 await client . resolvePrimaryNames ( EXAMPLE_ADDRESS , { chainIds : [ 1 , 10 ] } ) ;
373374
374375 const expectedUrl = new URL (
@@ -384,7 +385,7 @@ describe("ENSNodeClient", () => {
384385 const mockResponse = { ...EXAMPLE_PRIMARY_NAMES_RESPONSE , trace : [ ] } ;
385386 mockFetch . mockResolvedValueOnce ( { ok : true , json : async ( ) => mockResponse } ) ;
386387
387- const client = new ENSNodeClient ( ) ;
388+ const client = new ENSApiClient ( ) ;
388389 const response = await client . resolvePrimaryNames ( EXAMPLE_ADDRESS , { trace : true } ) ;
389390
390391 const expectedUrl = new URL (
@@ -403,7 +404,7 @@ describe("ENSNodeClient", () => {
403404 json : async ( ) => EXAMPLE_PRIMARY_NAMES_RESPONSE ,
404405 } ) ;
405406
406- const client = new ENSNodeClient ( ) ;
407+ const client = new ENSApiClient ( ) ;
407408 await client . resolvePrimaryNames ( EXAMPLE_ADDRESS , { accelerate : true } ) ;
408409
409410 const expectedUrl = new URL (
@@ -418,7 +419,7 @@ describe("ENSNodeClient", () => {
418419 it ( "should throw error when API returns error" , async ( ) => {
419420 mockFetch . mockResolvedValueOnce ( { ok : false , json : async ( ) => EXAMPLE_ERROR_RESPONSE } ) ;
420421
421- const client = new ENSNodeClient ( ) ;
422+ const client = new ENSApiClient ( ) ;
422423 await expect ( client . resolvePrimaryNames ( EXAMPLE_ADDRESS ) ) . rejects . toThrowError ( ClientError ) ;
423424 } ) ;
424425 } ) ;
@@ -429,7 +430,7 @@ describe("ENSNodeClient", () => {
429430 const requestUrl = new URL ( `/api/config` , DEFAULT_ENSNODE_API_URL_MAINNET ) ;
430431 const serializedMockedResponse = EXAMPLE_CONFIG_RESPONSE ;
431432 const mockedResponse = deserializeENSApiPublicConfig ( serializedMockedResponse ) ;
432- const client = new ENSNodeClient ( ) ;
433+ const client = new ENSApiClient ( ) ;
433434
434435 mockFetch . mockResolvedValueOnce ( {
435436 ok : true ,
@@ -444,7 +445,7 @@ describe("ENSNodeClient", () => {
444445 it ( "should throw error when API returns error" , async ( ) => {
445446 mockFetch . mockResolvedValueOnce ( { ok : false , json : async ( ) => EXAMPLE_ERROR_RESPONSE } ) ;
446447
447- const client = new ENSNodeClient ( ) ;
448+ const client = new ENSApiClient ( ) ;
448449
449450 await expect ( client . config ( ) ) . rejects . toThrow ( / F e t c h i n g E N S N o d e C o n f i g F a i l e d / i) ;
450451 } ) ;
@@ -456,7 +457,7 @@ describe("ENSNodeClient", () => {
456457 const requestUrl = new URL ( `/api/indexing-status` , DEFAULT_ENSNODE_API_URL_MAINNET ) ;
457458 const mockedResponse = EXAMPLE_INDEXING_STATUS_BACKFILL_RESPONSE ;
458459
459- const client = new ENSNodeClient ( ) ;
460+ const client = new ENSApiClient ( ) ;
460461
461462 mockFetch . mockResolvedValueOnce ( {
462463 ok : true ,
@@ -470,7 +471,7 @@ describe("ENSNodeClient", () => {
470471
471472 it ( "should throw error when API returns error other than 503 error" , async ( ) => {
472473 // arrange
473- const client = new ENSNodeClient ( ) ;
474+ const client = new ENSApiClient ( ) ;
474475
475476 mockFetch . mockResolvedValueOnce ( { ok : false , json : async ( ) => EXAMPLE_ERROR_RESPONSE } ) ;
476477
0 commit comments