Skip to content

Commit 8f7a995

Browse files
committed
common: fix ipfs manifest crawler test
1 parent 9203e22 commit 8f7a995

File tree

1 file changed

+38
-9
lines changed

1 file changed

+38
-9
lines changed

packages/indexer-common/src/__tests__/ipfs.test.ts

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ function mockManifestHash(input: string): string {
1515
}
1616

1717
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')
2021

2122
describe(SubgraphManifestResolver, () => {
2223
let ipfs: SubgraphManifestResolver
@@ -54,7 +55,7 @@ describe(SubgraphManifestResolver, () => {
5455
name: "root"
5556
graft:
5657
base: ${DEP_1}
57-
block: 4
58+
block: 1000
5859
`,
5960
)
6061
manifestMap.set(
@@ -64,29 +65,55 @@ describe(SubgraphManifestResolver, () => {
6465
name: "dep1"
6566
graft:
6667
base: ${DEP_2}
67-
block: 5
68+
block: 550
6869
`,
6970
)
7071
manifestMap.set(
7172
DEP_2,
7273
`
7374
specVersion: "0.0.2"
7475
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"
7586
`,
7687
)
7788

7889
beforeAll(async () => {
7990
// 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+
82101
// Example: Respond with different data based on the CID
83102
if (manifestMap.has(cid)) {
84103
res.send(manifestMap.get(cid))
85104
} else {
86105
console.log(`CID not found: ${cid}`)
87-
res.status(404).send()
106+
res.status(404).send('Not Found')
88107
}
89108
})
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+
90117
// Start server and bind to a random port
91118
server = await new Promise((resolve, reject) => {
92119
const s = app.listen(0, () => {
@@ -146,8 +173,10 @@ describe(SubgraphManifestResolver, () => {
146173
expect(manifest).toEqual({
147174
root: new SubgraphDeploymentID(DEP_ROOT_HASH),
148175
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 },
151180
],
152181
})
153182
})

0 commit comments

Comments
 (0)