Skip to content

Commit

Permalink
common: fixed grafting tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tilacog committed Oct 25, 2023
1 parent 99a0d3c commit b45097a
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 17 deletions.
93 changes: 77 additions & 16 deletions packages/indexer-common/src/__tests__/grafting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,35 +66,96 @@ describe('discoverLineage function', () => {

test('should throw an error after maximum iteration count is reached', async () => {
const targetDeployment = new SubgraphDeploymentID(target)
expect(() =>
discoverLineage(
let threwError = false
try {
await discoverLineage(
fakeSubgraphManifestResolver,
targetDeployment,
2, // Set maxIterations to 2
),
).rejects.toThrow(
indexerError(
IndexerErrorCode.IE075,
)
} catch (err) {
expect(err.code).toStrictEqual(IndexerErrorCode.IE075)
expect(err.cause).toStrictEqual(
`Failed to find the graft root for target subgraph deployment (${target}) after 2 iterations.`,
),
)
)
threwError = true
}
expect(threwError).toBeTruthy()
})
})

describe('determineSubgraphDeploymentDecisions function', () => {
// beforeEach(() => {})

test('should throw an error if bases are not provided', () => {
const lineage: SubgraphLineageWithStatus = {
const subgraphLineage: SubgraphLineageWithStatus = {
target: new SubgraphDeploymentID(target),
bases: [],
}
expect(() => determineSubgraphDeploymentDecisions(lineage)).toThrow(
indexerError(
IndexerErrorCode.IE075,

let threwError = false
try {
determineSubgraphDeploymentDecisions(subgraphLineage)
} catch (err) {
expect(err.code).toStrictEqual(IndexerErrorCode.IE075)
expect(err.cause).toStrictEqual(
'Expected target subgraph to have at least one graft base.',
),
)
)

threwError = true
}
expect(threwError).toBeTruthy()
})

test('should return an empty array if a single base is still syncing and healthy', () => {
const subgraphLineage: SubgraphLineageWithStatus = {
target: new SubgraphDeploymentID(target),
bases: [
{
block: 10,
deployment: new SubgraphDeploymentID(base1),
indexingStatus: {
latestBlock: {
number: 5,
hash: 'foo',
},
health: 'healthy',
},
},
],
}
expect(determineSubgraphDeploymentDecisions(subgraphLineage)).toEqual([])
})

test('should throw an error if an unsynced base is unhealthy', () => {
const graftBase = new SubgraphDeploymentID(base1)
const subgraphLineage: SubgraphLineageWithStatus = {
target: new SubgraphDeploymentID(target),
bases: [
{
block: 10,
deployment: graftBase,
indexingStatus: {
latestBlock: {
number: 5,
hash: 'foo',
},
health: 'not-healthy',
},
},
],
}

let threwError = false
try {
determineSubgraphDeploymentDecisions(subgraphLineage)
} catch (err) {
expect(err.code).toStrictEqual(IndexerErrorCode.IE075)
expect(err.cause).toStrictEqual({
message: `Cannot deploy subgraph due to unhealthy graft base: ${graftBase.ipfsHash}`,
graftDependencies: subgraphLineage,
})
threwError = true
}
expect(threwError).toBeTruthy()
})

test('should return DEPLOY subgraph deployment decision if its single base has no indexing status', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/indexer-common/src/grafting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export function determineSubgraphDeploymentDecisions(
// Is it healthy?
if (graft.indexingStatus.health !== 'healthy') {
throw indexerError(IndexerErrorCode.IE075, {
message: `Cannot deploy subgraph due to unhealthy graft base: ${graft.deployment}`,
message: `Cannot deploy subgraph due to unhealthy graft base: ${graft.deployment.ipfsHash}`,
graftDependencies: subgraphLineage,
})
}
Expand Down

0 comments on commit b45097a

Please sign in to comment.