Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions packages/indexer-common/src/__tests__/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,61 @@ describe('Action Validation', () => {
expect(isValidActionInput(missingDeploymentID)).toBe(false)
})

test('validates PRESENT_POI action', () => {
const validPresentPOI: ActionInput = {
...baseAction,
type: ActionType.PRESENT_POI,
deploymentID: 'Qmtest',
allocationID: '0x1234567890123456789012345678901234567890',
} as ActionInput

expect(isValidActionInput(validPresentPOI)).toBe(true)

// Missing allocationID
const missingAllocationID: ActionInput = {
...baseAction,
type: ActionType.PRESENT_POI,
deploymentID: 'Qmtest',
} as ActionInput

expect(isValidActionInput(missingAllocationID)).toBe(false)

// Missing deploymentID
const missingDeploymentID: ActionInput = {
...baseAction,
type: ActionType.PRESENT_POI,
allocationID: '0x1234567890123456789012345678901234567890',
} as ActionInput

expect(isValidActionInput(missingDeploymentID)).toBe(false)

// With POI provided, must also have publicPOI and poiBlockNumber
const withPoiButMissingPublicPOI = {
...baseAction,
type: ActionType.PRESENT_POI,
deploymentID: 'Qmtest',
allocationID: '0x1234567890123456789012345678901234567890',
poi: '0x' + 'ab'.repeat(32),
isLegacy: false,
}

expect(isValidActionInput(withPoiButMissingPublicPOI)).toBe(false)

// With all POI fields provided
const withAllPoiFields = {
...baseAction,
type: ActionType.PRESENT_POI,
deploymentID: 'Qmtest',
allocationID: '0x1234567890123456789012345678901234567890',
poi: '0x' + 'ab'.repeat(32),
publicPOI: '0x' + 'cd'.repeat(32),
poiBlockNumber: 12345,
isLegacy: false,
}

expect(isValidActionInput(withAllPoiFields)).toBe(true)
})

test('validates common required fields (source, reason, status, priority)', () => {
// Missing status
const missingStatus = {
Expand Down
23 changes: 19 additions & 4 deletions packages/indexer-common/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ export const isValidActionInput = (
'allocationID' in variableToCheck &&
'amount' in variableToCheck
break
case ActionType.PRESENT_POI:
hasActionParams =
'deploymentID' in variableToCheck && 'allocationID' in variableToCheck

if (!variableToCheck.isLegacy && variableToCheck.poi !== undefined) {
hasActionParams =
hasActionParams &&
'poi' in variableToCheck &&
'publicPOI' in variableToCheck &&
'poiBlockNumber' in variableToCheck
}
break
}
return (
hasActionParams &&
Expand Down Expand Up @@ -164,11 +176,14 @@ export const validateActionInputs = async (
)
}

// Unallocate, reallocate, and resize actions must target an active allocationID
// Unallocate, reallocate, resize, and presentPOI actions must target an active allocationID
if (
[ActionType.UNALLOCATE, ActionType.REALLOCATE, ActionType.RESIZE].includes(
action.type,
)
[
ActionType.UNALLOCATE,
ActionType.REALLOCATE,
ActionType.RESIZE,
ActionType.PRESENT_POI,
].includes(action.type)
) {
// allocationID must belong to active allocation
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import {
invalidReallocateAction,
invalidUnallocateAction,
queuedAllocateAction,
queuedResizeAction,
queuedPresentPOIAction,
subgraphDeployment1,
subgraphDeployment2,
subgraphDeployment3,
Expand Down Expand Up @@ -871,4 +873,38 @@ describe.skip('Actions', () => {
.toPromise(),
).resolves.toHaveProperty('data.updateActions', updatedExpecteds)
})

test('Queue and retrieve resize action', async () => {
const inputAction = queuedResizeAction
const expected = await actionInputToExpected(inputAction, 1)

await expect(
client.mutation(QUEUE_ACTIONS_MUTATION, { actions: [inputAction] }).toPromise(),
).resolves.toHaveProperty('data.queueActions', [expected])

await expect(
client
.query(ACTIONS_QUERY, {
filter: { status: ActionStatus.QUEUED, type: ActionType.RESIZE },
})
.toPromise(),
).resolves.toHaveProperty('data.actions', [expected])
})

test('Queue and retrieve presentPOI action', async () => {
const inputAction = queuedPresentPOIAction
const expected = await actionInputToExpected(inputAction, 1)

await expect(
client.mutation(QUEUE_ACTIONS_MUTATION, { actions: [inputAction] }).toPromise(),
).resolves.toHaveProperty('data.queueActions', [expected])

await expect(
client
.query(ACTIONS_QUERY, {
filter: { status: ActionStatus.QUEUED, type: ActionType.PRESENT_POI },
})
.toPromise(),
).resolves.toHaveProperty('data.actions', [expected])
})
})
12 changes: 12 additions & 0 deletions packages/indexer-common/src/indexer-management/__tests__/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,15 @@ export const queuedResizeAction = {
priority: 0,
protocolNetwork: 'arbitrum-sepolia',
} as ActionInput

export const queuedPresentPOIAction = {
status: ActionStatus.QUEUED,
type: ActionType.PRESENT_POI,
deploymentID: subgraphDeployment1,
allocationID: '0x8f63930129e585c69482b56390a09b6b176f4a4c',
force: false,
source: 'indexerAgent',
reason: 'indexingRule',
priority: 0,
protocolNetwork: 'arbitrum-sepolia',
} as ActionInput
Loading