@@ -2,71 +2,65 @@ import { vi } from "vitest";
22
33import type { EnsDbWriter } from "@ensnode/ensdb-sdk" ;
44import {
5+ ChainIndexingStatusIds ,
56 type CrossChainIndexingStatusSnapshot ,
67 CrossChainIndexingStrategyIds ,
7- type IndexingMetadataContext ,
8+ type IndexingMetadataContextInitialized ,
89 IndexingMetadataContextStatusCodes ,
910 OmnichainIndexingStatusIds ,
1011 type OmnichainIndexingStatusSnapshot ,
12+ RangeTypeIds ,
1113} from "@ensnode/ensnode-sdk" ;
1214
1315import { EnsDbWriterWorker } from "@/lib/ensdb-writer-worker/ensdb-writer-worker" ;
14- import type { IndexingStatusBuilder } from "@/lib/indexing-status -builder" ;
16+ import type { IndexingMetadataContextBuilder } from "@/lib/indexing-metadata-context-builder/indexing-metadata-context -builder" ;
1517
16- // Test fixture for stack info - minimal valid structure for tests
17- export const mockStackInfo = {
18- ensDb : { version : "1.0.0" } ,
19- ensIndexer : {
20- clientLabelSet : { labelSetId : "subgraph" , labelSetVersion : 0 } ,
21- } ,
22- ensRainbow : {
23- serverLabelSet : { labelSetId : "subgraph" , highestLabelSetVersion : 0 } ,
24- versionInfo : { ensRainbow : "1.0.0" } ,
25- } ,
26- } as any ;
18+ // Test fixtures for IndexingMetadataContext objects
2719
28- // Helper to create mock objects with consistent typing
29- export function createMockEnsDbWriter (
30- overrides : Partial < ReturnType < typeof baseEnsDbWriter > > = { } ,
31- ) : EnsDbWriter {
20+ export function createMockCrossChainSnapshot (
21+ overrides : Partial < CrossChainIndexingStatusSnapshot > = { } ,
22+ ) : CrossChainIndexingStatusSnapshot {
3223 return {
33- ...baseEnsDbWriter ( ) ,
24+ strategy : CrossChainIndexingStrategyIds . Omnichain ,
25+ slowestChainIndexingCursor : 100 ,
26+ snapshotTime : 200 ,
27+ omnichainSnapshot : {
28+ omnichainStatus : OmnichainIndexingStatusIds . Following ,
29+ omnichainIndexingCursor : 100 ,
30+ chains : new Map ( [
31+ [
32+ 1 ,
33+ {
34+ chainStatus : ChainIndexingStatusIds . Following ,
35+ latestIndexedBlock : { timestamp : 100 , number : 100 } ,
36+ latestKnownBlock : { timestamp : 200 , number : 200 } ,
37+ config : {
38+ rangeType : RangeTypeIds . LeftBounded ,
39+ startBlock : { timestamp : 0 , number : 0 } ,
40+ } ,
41+ } ,
42+ ] ,
43+ ] ) ,
44+ } ,
3445 ...overrides ,
35- } as unknown as EnsDbWriter ;
36- }
37-
38- export function baseEnsDbWriter ( ) {
39- return {
40- getIndexingMetadataContext : vi . fn ( ) . mockResolvedValue ( undefined ) ,
41- upsertIndexingMetadataContext : vi . fn ( ) . mockResolvedValue ( undefined ) ,
4246 } ;
4347}
4448
4549export function createMockIndexingMetadataContextInitialized (
46- overrides : Partial < IndexingMetadataContext > = { } ,
47- ) : IndexingMetadataContext {
50+ overrides : Partial < IndexingMetadataContextInitialized > = { } ,
51+ ) : IndexingMetadataContextInitialized {
4852 return {
4953 statusCode : IndexingMetadataContextStatusCodes . Initialized ,
5054 indexingStatus : createMockCrossChainSnapshot ( ) ,
51- stackInfo : mockStackInfo ,
55+ stackInfo : {
56+ ensDb : { versionInfo : { postgresql : "17.4" } } ,
57+ ensIndexer : { } as any ,
58+ ensRainbow : { } as any ,
59+ } ,
5260 ...overrides ,
5361 } ;
5462}
5563
56- export function createMockIndexingMetadataContextUninitialized ( ) : IndexingMetadataContext {
57- return {
58- statusCode : IndexingMetadataContextStatusCodes . Uninitialized ,
59- } ;
60- }
61-
62- export function createMockIndexingStatusBuilder (
63- resolvedSnapshot : OmnichainIndexingStatusSnapshot = createMockOmnichainSnapshot ( ) ,
64- ) : IndexingStatusBuilder {
65- return {
66- getOmnichainIndexingStatusSnapshot : vi . fn ( ) . mockResolvedValue ( resolvedSnapshot ) ,
67- } as unknown as IndexingStatusBuilder ;
68- }
69-
7064export function createMockOmnichainSnapshot (
7165 overrides : Partial < OmnichainIndexingStatusSnapshot > = { } ,
7266) : OmnichainIndexingStatusSnapshot {
@@ -78,24 +72,32 @@ export function createMockOmnichainSnapshot(
7872 } ;
7973}
8074
81- export function createMockCrossChainSnapshot (
82- overrides : Partial < CrossChainIndexingStatusSnapshot > = { } ,
83- ) : CrossChainIndexingStatusSnapshot {
75+ export function createMockEnsDbWriter (
76+ overrides : Partial < Pick < EnsDbWriter , "upsertIndexingMetadataContext" > > = { } ,
77+ ) : EnsDbWriter {
8478 return {
85- strategy : CrossChainIndexingStrategyIds . Omnichain ,
86- slowestChainIndexingCursor : 100 ,
87- snapshotTime : 200 ,
88- omnichainSnapshot : createMockOmnichainSnapshot ( ) ,
79+ upsertIndexingMetadataContext : vi . fn ( ) . mockResolvedValue ( undefined ) ,
8980 ...overrides ,
90- } ;
81+ } as unknown as EnsDbWriter ;
82+ }
83+
84+ export function createMockIndexingMetadataContextBuilder (
85+ resolvedContext : IndexingMetadataContextInitialized = createMockIndexingMetadataContextInitialized ( ) ,
86+ ) : IndexingMetadataContextBuilder {
87+ return {
88+ getIndexingMetadataContext : vi . fn ( ) . mockResolvedValue ( resolvedContext ) ,
89+ } as unknown as IndexingMetadataContextBuilder ;
9190}
9291
9392export function createMockEnsDbWriterWorker (
94- overrides : { ensDbClient ?: EnsDbWriter ; indexingStatusBuilder ?: IndexingStatusBuilder } = { } ,
93+ overrides : {
94+ ensDbClient ?: EnsDbWriter ;
95+ indexingMetadataContextBuilder ?: IndexingMetadataContextBuilder ;
96+ } = { } ,
9597) {
9698 const ensDbClient = overrides . ensDbClient ?? createMockEnsDbWriter ( ) ;
97- const indexingStatusBuilder =
98- overrides . indexingStatusBuilder ?? createMockIndexingStatusBuilder ( ) ;
99+ const indexingMetadataContextBuilder =
100+ overrides . indexingMetadataContextBuilder ?? createMockIndexingMetadataContextBuilder ( ) ;
99101
100- return new EnsDbWriterWorker ( ensDbClient , indexingStatusBuilder ) ;
102+ return new EnsDbWriterWorker ( ensDbClient , indexingMetadataContextBuilder ) ;
101103}
0 commit comments