@@ -15,8 +15,9 @@ function mockManifestHash(input: string): string {
15
15
}
16
16
17
17
const DEP_ROOT_HASH = mockManifestHash ( 'root' )
18
- const DEP_1 = mockManifestHash ( 'dep2' )
19
- const DEP_2 = mockManifestHash ( 'dep3' )
18
+ const DEP_1 = mockManifestHash ( 'dep1' )
19
+ const DEP_2 = mockManifestHash ( 'dep2' )
20
+ const DEP_3 = mockManifestHash ( 'dep3' )
20
21
21
22
describe ( SubgraphManifestResolver , ( ) => {
22
23
let ipfs : SubgraphManifestResolver
@@ -54,7 +55,7 @@ describe(SubgraphManifestResolver, () => {
54
55
name: "root"
55
56
graft:
56
57
base: ${ DEP_1 }
57
- block: 4
58
+ block: 1000
58
59
` ,
59
60
)
60
61
manifestMap . set (
@@ -64,29 +65,55 @@ describe(SubgraphManifestResolver, () => {
64
65
name: "dep1"
65
66
graft:
66
67
base: ${ DEP_2 }
67
- block: 5
68
+ block: 550
68
69
` ,
69
70
)
70
71
manifestMap . set (
71
72
DEP_2 ,
72
73
`
73
74
specVersion: "0.0.2"
74
75
name: "dep2"
76
+ graft:
77
+ base: ${ DEP_3 }
78
+ block: 250
79
+ ` ,
80
+ )
81
+ manifestMap . set (
82
+ DEP_3 ,
83
+ `
84
+ specVersion: "0.0.2"
85
+ name: "dep3"
75
86
` ,
76
87
)
77
88
78
89
beforeAll ( async ( ) => {
79
90
// Mock endpoint for IPFS CID requests
80
- app . get ( '/ipfs/:cid' , ( req : Request , res : Response ) => {
81
- const { cid } = req . params
91
+ app . post ( '/api/v0/cat' , ( req : Request , res : Response ) => {
92
+ const cid = req . query . arg as string
93
+ if ( ! cid ) {
94
+ const err = new Error ( 'CID parameter is required' )
95
+ res . status ( 400 )
96
+ return res . send ( err . message )
97
+ }
98
+
99
+ console . log ( `got cid ${ cid } ` )
100
+
82
101
// Example: Respond with different data based on the CID
83
102
if ( manifestMap . has ( cid ) ) {
84
103
res . send ( manifestMap . get ( cid ) )
85
104
} else {
86
105
console . log ( `CID not found: ${ cid } ` )
87
- res . status ( 404 ) . send ( )
106
+ res . status ( 404 ) . send ( 'Not Found' )
88
107
}
89
108
} )
109
+
110
+ // Handler for all other routes
111
+ app . use ( ( req : Request , res : Response , next ) => {
112
+ console . log ( `404: ${ req . url } , ${ req . method } ` )
113
+ res . status ( 404 ) . send ( 'Not Found' )
114
+ next ( )
115
+ } )
116
+
90
117
// Start server and bind to a random port
91
118
server = await new Promise ( ( resolve , reject ) => {
92
119
const s = app . listen ( 0 , ( ) => {
@@ -146,8 +173,10 @@ describe(SubgraphManifestResolver, () => {
146
173
expect ( manifest ) . toEqual ( {
147
174
root : new SubgraphDeploymentID ( DEP_ROOT_HASH ) ,
148
175
dependencies : [
149
- { base : new SubgraphDeploymentID ( DEP_1 ) , block : 4 } ,
150
- { base : new SubgraphDeploymentID ( DEP_2 ) , block : 5 } ,
176
+ // dependencies are fetched in oldest to newest order
177
+ { base : new SubgraphDeploymentID ( DEP_3 ) , block : 250 } ,
178
+ { base : new SubgraphDeploymentID ( DEP_2 ) , block : 550 } ,
179
+ { base : new SubgraphDeploymentID ( DEP_1 ) , block : 1000 } ,
151
180
] ,
152
181
} )
153
182
} )
0 commit comments