-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathconversions.test.ts
More file actions
113 lines (101 loc) · 3.55 KB
/
conversions.test.ts
File metadata and controls
113 lines (101 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { describe, expect, it } from "vitest";
import { ENSNamespaceIds } from "@ensnode/datasources";
import { PluginName } from "../../ensindexer/config/types";
import { deserializeEnsApiPublicConfig } from "./deserialize";
import { serializeEnsApiPublicConfig } from "./serialize";
import type { SerializedEnsApiPublicConfig } from "./serialized-types";
import type { EnsApiPublicConfig } from "./types";
const MOCK_ENSAPI_PUBLIC_CONFIG = {
versionInfo: {
ensApi: "1.9.0",
ensNormalize: "1.11.1",
},
theGraphFallback: {
canFallback: false,
reason: "no-api-key",
},
ensIndexerPublicConfig: {
namespace: ENSNamespaceIds.Mainnet,
databaseSchemaName: "ensapi",
ensRainbowPublicConfig: {
version: "0.36.0",
labelSet: { labelSetId: "subgraph", highestLabelSetVersion: 0 },
recordsCount: 100,
},
indexedChainIds: new Set([1]),
isSubgraphCompatible: false,
labelSet: { labelSetId: "subgraph", labelSetVersion: 0 },
plugins: [PluginName.Subgraph],
versionInfo: {
ensDb: "0.36.0",
ensIndexer: "0.36.0",
ensNormalize: "1.1.1",
nodejs: "20.0.0",
ponder: "0.5.0",
},
},
} satisfies EnsApiPublicConfig;
const MOCK_SERIALIZED_ENSAPI_PUBLIC_CONFIG = serializeEnsApiPublicConfig(MOCK_ENSAPI_PUBLIC_CONFIG);
describe("ENSApi Config Serialization/Deserialization", () => {
describe("serializeEnsApiPublicConfig", () => {
it("serializes ENSAPI public config correctly", () => {
const result = serializeEnsApiPublicConfig(MOCK_ENSAPI_PUBLIC_CONFIG);
expect(result).toEqual({
versionInfo: {
ensApi: "1.9.0",
ensNormalize: "1.11.1",
},
theGraphFallback: {
canFallback: false,
reason: "no-api-key",
},
ensIndexerPublicConfig: {
namespace: ENSNamespaceIds.Mainnet,
databaseSchemaName: "ensapi",
ensRainbowPublicConfig: {
version: "0.36.0",
labelSet: { labelSetId: "subgraph", highestLabelSetVersion: 0 },
recordsCount: 100,
},
indexedChainIds: [1],
isSubgraphCompatible: false,
labelSet: { labelSetId: "subgraph", labelSetVersion: 0 },
plugins: [PluginName.Subgraph],
versionInfo: {
ensDb: "0.36.0",
ensIndexer: "0.36.0",
ensNormalize: "1.1.1",
nodejs: "20.0.0",
ponder: "0.5.0",
},
},
} satisfies SerializedEnsApiPublicConfig);
});
});
describe("deserializeEnsApiPublicConfig", () => {
it("deserializes ENSAPI public config correctly", () => {
const serialized = serializeEnsApiPublicConfig(MOCK_ENSAPI_PUBLIC_CONFIG);
const result = deserializeEnsApiPublicConfig(serialized);
expect(result).toEqual(MOCK_ENSAPI_PUBLIC_CONFIG);
});
it("handles validation errors with custom value label", () => {
const invalidConfig = {
...MOCK_SERIALIZED_ENSAPI_PUBLIC_CONFIG,
versionInfo: {
ensApi: "",
ensNormalize: "",
},
};
expect(() => deserializeEnsApiPublicConfig(invalidConfig, "testConfig")).toThrow(
/testConfig.versionInfo.ensApi/,
);
});
});
describe("round-trip conversion", () => {
it("maintains data integrity through serialize -> deserialize cycle", () => {
const serialized = serializeEnsApiPublicConfig(MOCK_ENSAPI_PUBLIC_CONFIG);
const deserialized = deserializeEnsApiPublicConfig(serialized);
expect(deserialized).toStrictEqual(MOCK_ENSAPI_PUBLIC_CONFIG);
});
});
});