|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | + |
| 3 | +import { ENSNamespaceIds } from "@ensnode/datasources"; |
| 4 | +import { PluginName } from "@ensnode/ensnode-sdk"; |
| 5 | + |
| 6 | +import { |
| 7 | + type EnsIndexerPublicConfigCompatibilityCheck, |
| 8 | + validateEnsIndexerPublicConfigCompatibility, |
| 9 | +} from "./compatibility"; |
| 10 | + |
| 11 | +describe("EnsIndexerConfig compatibility", () => { |
| 12 | + describe("validateEnsIndexerPublicConfigCompatibility()", () => { |
| 13 | + const config = { |
| 14 | + indexedChainIds: new Set([1, 10, 8453]), |
| 15 | + labelSet: { |
| 16 | + labelSetId: "test-label-set", |
| 17 | + labelSetVersion: 1, |
| 18 | + }, |
| 19 | + isSubgraphCompatible: false, |
| 20 | + namespace: ENSNamespaceIds.Mainnet, |
| 21 | + plugins: [PluginName.Subgraph, PluginName.Basenames, PluginName.ThreeDNS], |
| 22 | + } satisfies EnsIndexerPublicConfigCompatibilityCheck; |
| 23 | + |
| 24 | + it("does not throw error when 'configA' and 'configB' are equal", () => { |
| 25 | + const configA = structuredClone(config); |
| 26 | + const configB = structuredClone(config); |
| 27 | + |
| 28 | + expect(() => |
| 29 | + validateEnsIndexerPublicConfigCompatibility(configA, configB), |
| 30 | + ).not.toThrowError(); |
| 31 | + }); |
| 32 | + |
| 33 | + it("throws error when 'configA.indexedChainIds' differ from 'configB.indexedChainIds'", () => { |
| 34 | + const configA = structuredClone(config); |
| 35 | + |
| 36 | + const configB = structuredClone(config); |
| 37 | + configB.indexedChainIds.delete(8453); |
| 38 | + |
| 39 | + expect(() => validateEnsIndexerPublicConfigCompatibility(configA, configB)).toThrowError( |
| 40 | + /'indexedChainIds' must be compatible. Stored Config 'indexedChainIds': '1, 10, 8453'. Current Config 'indexedChainIds': '1, 10'/i, |
| 41 | + ); |
| 42 | + }); |
| 43 | + |
| 44 | + it("throws error when 'configA.isSubgraphCompatible' is not same as 'configB.isSubgraphCompatible'", () => { |
| 45 | + const configA = structuredClone(config); |
| 46 | + |
| 47 | + const configB = { |
| 48 | + ...structuredClone(config), |
| 49 | + isSubgraphCompatible: !configA.isSubgraphCompatible, |
| 50 | + } satisfies EnsIndexerPublicConfigCompatibilityCheck; |
| 51 | + |
| 52 | + expect(() => validateEnsIndexerPublicConfigCompatibility(configA, configB)).toThrowError( |
| 53 | + /'isSubgraphCompatible' flag must be compatible. Stored Config 'isSubgraphCompatible' flag: 'false'. Current Config 'isSubgraphCompatible' flag: 'true'/i, |
| 54 | + ); |
| 55 | + }); |
| 56 | + |
| 57 | + it("throws error when 'configA.namespace' is not same as 'configB.namespace'", () => { |
| 58 | + const configA = structuredClone(config); |
| 59 | + |
| 60 | + const configB = { |
| 61 | + ...structuredClone(config), |
| 62 | + namespace: ENSNamespaceIds.Sepolia, |
| 63 | + } satisfies EnsIndexerPublicConfigCompatibilityCheck; |
| 64 | + |
| 65 | + expect(() => validateEnsIndexerPublicConfigCompatibility(configA, configB)).toThrowError( |
| 66 | + /'namespace' must be compatible. Stored Config 'namespace': 'mainnet'. Current Config 'namespace': 'sepolia'/i, |
| 67 | + ); |
| 68 | + }); |
| 69 | + |
| 70 | + it("throws error when 'configA.labelSet.labelSetId' is not same as 'configB.labelSet.labelSetId'", () => { |
| 71 | + const configA = structuredClone(config); |
| 72 | + |
| 73 | + const configB = { |
| 74 | + ...structuredClone(config), |
| 75 | + labelSet: { |
| 76 | + ...structuredClone(config.labelSet), |
| 77 | + labelSetId: "different-label-set", |
| 78 | + }, |
| 79 | + } satisfies EnsIndexerPublicConfigCompatibilityCheck; |
| 80 | + |
| 81 | + expect(() => validateEnsIndexerPublicConfigCompatibility(configA, configB)).toThrowError( |
| 82 | + /'labelSet.labelSetId' must be compatible. Stored Config 'labelSet.labelSetId': 'test-label-set'. Current Config 'labelSet.labelSetId': 'different-label-set'/i, |
| 83 | + ); |
| 84 | + }); |
| 85 | + |
| 86 | + it("throws error when 'configA.labelSet.labelSetVersion' is not same as 'configB.labelSet.labelSetVersion'", () => { |
| 87 | + const configA = structuredClone(config); |
| 88 | + |
| 89 | + const configB = { |
| 90 | + ...structuredClone(config), |
| 91 | + labelSet: { |
| 92 | + ...structuredClone(config.labelSet), |
| 93 | + labelSetVersion: config.labelSet.labelSetVersion + 1, |
| 94 | + }, |
| 95 | + } satisfies EnsIndexerPublicConfigCompatibilityCheck; |
| 96 | + |
| 97 | + expect(() => validateEnsIndexerPublicConfigCompatibility(configA, configB)).toThrowError( |
| 98 | + /'labelSet.labelSetVersion' must be compatible. Stored Config 'labelSet.labelSetVersion': '1'. Current Config 'labelSet.labelSetVersion': '2'/i, |
| 99 | + ); |
| 100 | + }); |
| 101 | + |
| 102 | + it("throws error when 'configA.plugins' differ from 'configB.plugins'", () => { |
| 103 | + const configA = structuredClone(config); |
| 104 | + |
| 105 | + const configB = structuredClone(config); |
| 106 | + configB.plugins.pop(); |
| 107 | + |
| 108 | + expect(() => validateEnsIndexerPublicConfigCompatibility(configA, configB)).toThrowError( |
| 109 | + /'plugins' must be compatible. Stored Config 'plugins': 'subgraph, basenames, threedns'. Current Config 'plugins': 'subgraph, basenames'/i, |
| 110 | + ); |
| 111 | + }); |
| 112 | + }); |
| 113 | +}); |
0 commit comments