Skip to content

Commit 4684fb4

Browse files
committed
Fix tests
1 parent e3ddda0 commit 4684fb4

2 files changed

Lines changed: 127 additions & 47 deletions

File tree

apps/ensapi/src/config/config.schema.test.ts

Lines changed: 126 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,111 @@ import packageJson from "@/../package.json" with { type: "json" };
22

33
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
44

5-
import { type ENSIndexerPublicConfig, PluginName } from "@ensnode/ensnode-sdk";
5+
import {
6+
ChainIndexingStatusIds,
7+
CrossChainIndexingStrategyIds,
8+
deserializeIndexingMetadataContext,
9+
type EnsRainbowPublicConfig,
10+
type IndexingMetadataContextInitialized,
11+
IndexingMetadataContextStatusCodes,
12+
OmnichainIndexingStatusIds,
13+
PluginName,
14+
RangeTypeIds,
15+
type SerializedCrossChainIndexingStatusSnapshot,
16+
type SerializedEnsDbPublicConfig,
17+
type SerializedEnsIndexerPublicConfig,
18+
type SerializedEnsIndexerStackInfo,
19+
type SerializedIndexingMetadataContextInitialized,
20+
} from "@ensnode/ensnode-sdk";
621
import type { RpcConfig } from "@ensnode/ensnode-sdk/internal";
722

23+
import { ensApiVersionInfo } from "@/lib/version-info";
24+
25+
const VALID_RPC_URL = "https://eth-sepolia.g.alchemy.com/v2/1234";
26+
27+
const ENSDB_PUBLIC_CONFIG = {
28+
versionInfo: {
29+
postgresql: "17.4",
30+
},
31+
} satisfies SerializedEnsDbPublicConfig;
32+
33+
const ENSINDEXER_PUBLIC_CONFIG = {
34+
namespace: "mainnet",
35+
ensIndexerSchemaName: "ensindexer_0",
36+
ensRainbowPublicConfig: {
37+
serverLabelSet: { labelSetId: "subgraph", highestLabelSetVersion: 0 },
38+
versionInfo: {
39+
ensRainbow: packageJson.version,
40+
},
41+
},
42+
indexedChainIds: [1],
43+
isSubgraphCompatible: false,
44+
clientLabelSet: { labelSetId: "subgraph", labelSetVersion: 0 },
45+
plugins: [PluginName.Subgraph],
46+
versionInfo: {
47+
ensDb: packageJson.version,
48+
ensIndexer: packageJson.version,
49+
ensNormalize: ensApiVersionInfo.ensNormalize,
50+
ponder: "0.8.0",
51+
},
52+
} satisfies SerializedEnsIndexerPublicConfig;
53+
54+
const ENSRAINBOW_PUBLIC_CONFIG = {
55+
serverLabelSet: { labelSetId: "subgraph", highestLabelSetVersion: 0 },
56+
versionInfo: {
57+
ensRainbow: packageJson.version,
58+
},
59+
} satisfies EnsRainbowPublicConfig;
60+
61+
const INDEXING_STATUS = {
62+
strategy: CrossChainIndexingStrategyIds.Omnichain,
63+
slowestChainIndexingCursor: 1777147427,
64+
snapshotTime: 1777147440,
65+
omnichainSnapshot: {
66+
omnichainStatus: OmnichainIndexingStatusIds.Following,
67+
chains: {
68+
"1": {
69+
chainStatus: ChainIndexingStatusIds.Following,
70+
config: {
71+
rangeType: RangeTypeIds.LeftBounded,
72+
startBlock: {
73+
timestamp: 1489165544,
74+
number: 3327417,
75+
},
76+
},
77+
latestIndexedBlock: {
78+
timestamp: 1777147427,
79+
number: 24959286,
80+
},
81+
latestKnownBlock: {
82+
timestamp: 1777147427,
83+
number: 24959286,
84+
},
85+
},
86+
},
87+
omnichainIndexingCursor: 1777147427,
88+
},
89+
} satisfies SerializedCrossChainIndexingStatusSnapshot;
90+
91+
const ENSINDEXER_STACK_INFO = {
92+
ensDb: ENSDB_PUBLIC_CONFIG,
93+
ensIndexer: ENSINDEXER_PUBLIC_CONFIG,
94+
ensRainbow: ENSRAINBOW_PUBLIC_CONFIG,
95+
} satisfies SerializedEnsIndexerStackInfo;
96+
97+
const INDEXING_METADATA_CONTEXT = {
98+
statusCode: IndexingMetadataContextStatusCodes.Initialized,
99+
indexingStatus: INDEXING_STATUS,
100+
stackInfo: ENSINDEXER_STACK_INFO,
101+
} satisfies SerializedIndexingMetadataContextInitialized;
102+
103+
const indexingMetadataContextInitialized = deserializeIndexingMetadataContext(
104+
INDEXING_METADATA_CONTEXT,
105+
) as IndexingMetadataContextInitialized;
106+
8107
vi.mock("@/lib/ensdb/singleton", () => ({
9108
ensDbClient: {
10-
getEnsIndexerPublicConfig: vi.fn(async () => ENSINDEXER_PUBLIC_CONFIG),
109+
getIndexingMetadataContext: vi.fn(async () => indexingMetadataContextInitialized),
11110
},
12111
}));
13112

@@ -22,7 +121,6 @@ import { buildConfigFromEnvironment, buildEnsApiPublicConfig } from "@/config/co
22121
import { ENSApi_DEFAULT_PORT } from "@/config/defaults";
23122
import type { EnsApiEnvironment } from "@/config/environment";
24123
import logger from "@/lib/logger";
25-
import { ensApiVersionInfo } from "@/lib/version-info";
26124

27125
vi.mock("@/lib/logger", () => ({
28126
default: {
@@ -31,44 +129,23 @@ vi.mock("@/lib/logger", () => ({
31129
},
32130
}));
33131

34-
const VALID_RPC_URL = "https://eth-sepolia.g.alchemy.com/v2/1234";
35-
36132
const BASE_ENV = {
37133
ENSDB_URL: "postgresql://user:password@localhost:5432/mydb",
134+
ENSINDEXER_SCHEMA_NAME: "ensindexer_0",
38135
RPC_URL_1: VALID_RPC_URL,
39136
} satisfies EnsApiEnvironment;
40137

41-
const ENSINDEXER_PUBLIC_CONFIG = {
42-
namespace: "mainnet",
43-
ensIndexerSchemaName: "ensindexer_0",
44-
ensRainbowPublicConfig: {
45-
serverLabelSet: { labelSetId: "subgraph", highestLabelSetVersion: 0 },
46-
versionInfo: {
47-
ensRainbow: packageJson.version,
48-
},
49-
},
50-
indexedChainIds: new Set([1]),
51-
isSubgraphCompatible: false,
52-
clientLabelSet: { labelSetId: "subgraph", labelSetVersion: 0 },
53-
plugins: [PluginName.Subgraph],
54-
versionInfo: {
55-
ensDb: packageJson.version,
56-
ensIndexer: packageJson.version,
57-
ensNormalize: ensApiVersionInfo.ensNormalize,
58-
ponder: "0.8.0",
59-
},
60-
} satisfies ENSIndexerPublicConfig;
61-
62138
describe("buildConfigFromEnvironment", () => {
63139
it("returns a valid config object using environment variables", async () => {
140+
const { ensIndexer: ensIndexerPublicConfig } = indexingMetadataContextInitialized.stackInfo;
64141
await expect(buildConfigFromEnvironment(BASE_ENV)).resolves.toStrictEqual({
65142
port: ENSApi_DEFAULT_PORT,
66143
ensDbUrl: BASE_ENV.ENSDB_URL,
144+
ensIndexerSchemaName: BASE_ENV.ENSINDEXER_SCHEMA_NAME,
67145
theGraphApiKey: undefined,
68146

69-
ensIndexerPublicConfig: ENSINDEXER_PUBLIC_CONFIG,
70-
namespace: ENSINDEXER_PUBLIC_CONFIG.namespace,
71-
ensIndexerSchemaName: ENSINDEXER_PUBLIC_CONFIG.ensIndexerSchemaName,
147+
ensIndexerPublicConfig,
148+
namespace: ensIndexerPublicConfig.namespace,
72149
rpcConfigs: new Map([
73150
[
74151
1,
@@ -153,12 +230,13 @@ describe("buildConfigFromEnvironment", () => {
153230

154231
describe("buildEnsApiPublicConfig", () => {
155232
it("returns a valid ENSApi public config with correct structure", () => {
156-
const mockConfig = {
233+
const { ensIndexer: ensIndexerPublicConfig } = indexingMetadataContextInitialized.stackInfo;
234+
const ensApiConfig = {
157235
port: ENSApi_DEFAULT_PORT,
158236
ensDbUrl: BASE_ENV.ENSDB_URL,
159-
ensIndexerPublicConfig: ENSINDEXER_PUBLIC_CONFIG,
160-
namespace: ENSINDEXER_PUBLIC_CONFIG.namespace,
161-
ensIndexerSchemaName: ENSINDEXER_PUBLIC_CONFIG.ensIndexerSchemaName,
237+
ensIndexerSchemaName: BASE_ENV.ENSINDEXER_SCHEMA_NAME,
238+
ensIndexerPublicConfig,
239+
namespace: ensIndexerPublicConfig.namespace,
162240
rpcConfigs: new Map([
163241
[
164242
1,
@@ -171,52 +249,54 @@ describe("buildEnsApiPublicConfig", () => {
171249
referralProgramEditionConfigSetUrl: undefined,
172250
};
173251

174-
const result = buildEnsApiPublicConfig(mockConfig);
252+
const result = buildEnsApiPublicConfig(ensApiConfig);
175253

176254
expect(result).toStrictEqual({
177255
versionInfo: ensApiVersionInfo,
178256
theGraphFallback: {
179257
canFallback: false,
180258
reason: "not-subgraph-compatible",
181259
},
182-
ensIndexerPublicConfig: ENSINDEXER_PUBLIC_CONFIG,
260+
ensIndexerPublicConfig,
183261
});
184262
});
185263

186264
it("preserves the complete ENSIndexer public config structure", () => {
187-
const mockConfig = {
265+
const { ensIndexer: ensIndexerPublicConfig } = indexingMetadataContextInitialized.stackInfo;
266+
const ensApiConfig = {
188267
port: ENSApi_DEFAULT_PORT,
189268
ensDbUrl: BASE_ENV.ENSDB_URL,
190-
ensIndexerPublicConfig: ENSINDEXER_PUBLIC_CONFIG,
191-
namespace: ENSINDEXER_PUBLIC_CONFIG.namespace,
192-
ensIndexerSchemaName: ENSINDEXER_PUBLIC_CONFIG.ensIndexerSchemaName,
269+
ensIndexerSchemaName: BASE_ENV.ENSINDEXER_SCHEMA_NAME,
270+
ensIndexerPublicConfig,
271+
namespace: ensIndexerPublicConfig.namespace,
193272
rpcConfigs: new Map(),
194273
referralProgramEditionConfigSetUrl: undefined,
195274
};
196275

197-
const result = buildEnsApiPublicConfig(mockConfig);
276+
const result = buildEnsApiPublicConfig(ensApiConfig);
198277

199278
// Verify that all ENSIndexer public config fields are preserved
200-
expect(result.ensIndexerPublicConfig).toStrictEqual(ENSINDEXER_PUBLIC_CONFIG);
279+
expect(result.ensIndexerPublicConfig).toStrictEqual(ensIndexerPublicConfig);
201280
});
202281

203282
it("includes the theGraphFallback and redacts api key", () => {
204-
const mockConfig = {
283+
const { ensIndexer: ensIndexerPublicConfig } = indexingMetadataContextInitialized.stackInfo;
284+
const ensApiConfig = {
205285
port: ENSApi_DEFAULT_PORT,
206286
ensDbUrl: BASE_ENV.ENSDB_URL,
287+
ensIndexerSchemaName: BASE_ENV.ENSINDEXER_SCHEMA_NAME,
207288
ensIndexerPublicConfig: {
208-
...ENSINDEXER_PUBLIC_CONFIG,
289+
...ensIndexerPublicConfig,
209290
plugins: ["subgraph"],
210291
isSubgraphCompatible: true,
211292
},
212-
namespace: ENSINDEXER_PUBLIC_CONFIG.namespace,
213-
ensIndexerSchemaName: ENSINDEXER_PUBLIC_CONFIG.ensIndexerSchemaName,
293+
namespace: ensIndexerPublicConfig.namespace,
214294
rpcConfigs: new Map(),
215295
referralProgramEditionConfigSetUrl: undefined,
216296
theGraphApiKey: "secret-api-key",
217297
};
218298

219-
const result = buildEnsApiPublicConfig(mockConfig);
299+
const result = buildEnsApiPublicConfig(ensApiConfig);
220300

221301
expect(result.theGraphFallback.canFallback).toBe(true);
222302
// discriminate the type...

apps/ensindexer/src/lib/indexing-engines/ponder.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ vi.mock("ponder:schema", () => ({
3636
ensIndexerSchema: {},
3737
}));
3838

39-
vi.mock("@/lib/indexing-engines/init-indexing-onchain-events", () => ({
39+
vi.mock("./init-indexing-onchain-events", () => ({
4040
initIndexingOnchainEvents: mockInitIndexingOnchainEvents,
4141
}));
4242

0 commit comments

Comments
 (0)