Skip to content

Commit 8fd9503

Browse files
MoonBoi9001claude
andcommitted
test(actions): add unit tests for PRESENT_POI action type
Add tests for the new PRESENT_POI action type covering: - Building action input with correct structure - POI parameter normalization (zero values) - Block number validation - Required field validation - Database action insertion and querying - Filter generation for action queries Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent f555e5b commit 8fd9503

File tree

2 files changed

+153
-0
lines changed

2 files changed

+153
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import { ActionStatus, ActionType } from '@graphprotocol/indexer-common'
2+
import { buildActionInput, validateActionInput } from '../actions'
3+
4+
describe('buildActionInput', () => {
5+
test('builds PRESENT_POI action input with correct structure', async () => {
6+
const result = await buildActionInput(
7+
ActionType.PRESENT_POI,
8+
{
9+
targetDeployment: 'QmTest123',
10+
param1: '0xallocationId',
11+
param2: '0x' + 'ab'.repeat(32), // poi
12+
param3: 'false', // force
13+
param4: '12345', // blockNumber
14+
param5: '0x' + 'cd'.repeat(32), // publicPOI
15+
param6: undefined,
16+
},
17+
'test',
18+
'test',
19+
ActionStatus.QUEUED,
20+
0,
21+
'arbitrum-sepolia',
22+
)
23+
expect(result.type).toBe(ActionType.PRESENT_POI)
24+
expect(result.deploymentID).toBe('QmTest123')
25+
expect(result.allocationID).toBe('0xallocationId')
26+
expect(result.poiBlockNumber).toBe(12345)
27+
})
28+
29+
test('normalizes zero POI values for PRESENT_POI', async () => {
30+
const result = await buildActionInput(
31+
ActionType.PRESENT_POI,
32+
{
33+
targetDeployment: 'QmTest123',
34+
param1: '0xallocationId',
35+
param2: '0', // poi = '0'
36+
param3: 'false',
37+
param4: undefined,
38+
param5: '0x0', // publicPOI = '0x0'
39+
param6: undefined,
40+
},
41+
'test',
42+
'test',
43+
ActionStatus.QUEUED,
44+
0,
45+
'arbitrum-sepolia',
46+
)
47+
const zeroPOI = '0x' + '00'.repeat(32)
48+
expect(result.poi).toBe(zeroPOI)
49+
expect(result.publicPOI).toBe(zeroPOI)
50+
expect(result.force).toBe(false)
51+
expect(result.allocationID).toBe('0xallocationId')
52+
expect(result.poiBlockNumber).toBeUndefined()
53+
})
54+
})
55+
56+
describe('validateActionInput', () => {
57+
test('validates PRESENT_POI with required fields', async () => {
58+
await expect(
59+
validateActionInput(ActionType.PRESENT_POI, {
60+
targetDeployment: 'QmTest123',
61+
param1: '0xallocationId',
62+
param2: undefined,
63+
param3: undefined,
64+
param4: undefined,
65+
param5: undefined,
66+
param6: undefined,
67+
}),
68+
).resolves.not.toThrow()
69+
})
70+
71+
test('rejects PRESENT_POI with invalid block number', async () => {
72+
await expect(
73+
buildActionInput(
74+
ActionType.PRESENT_POI,
75+
{
76+
targetDeployment: 'QmTest123',
77+
param1: '0xallocationId',
78+
param2: undefined,
79+
param3: undefined,
80+
param4: 'not-a-number', // invalid blockNumber
81+
param5: undefined,
82+
param6: undefined,
83+
},
84+
'test',
85+
'test',
86+
ActionStatus.QUEUED,
87+
0,
88+
'arbitrum-sepolia',
89+
),
90+
).rejects.toThrow('Invalid block number: not-a-number')
91+
})
92+
93+
test('rejects PRESENT_POI missing allocationID', async () => {
94+
await expect(
95+
validateActionInput(ActionType.PRESENT_POI, {
96+
targetDeployment: 'QmTest123',
97+
param1: undefined, // missing allocationID
98+
param2: undefined,
99+
param3: undefined,
100+
param4: undefined,
101+
param5: undefined,
102+
param6: undefined,
103+
}),
104+
).rejects.toThrow()
105+
})
106+
})

packages/indexer-common/src/indexer-management/__tests__/helpers.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ import {
2929
resolveChainId,
3030
SubgraphDeployment,
3131
getTestProvider,
32+
IndexingStatusCode,
3233
} from '@graphprotocol/indexer-common'
34+
import { encodeCollectData } from '../allocations'
3335
import { mockLogger, mockProvider } from '../../__tests__/subgraph.test'
3436
import { hexlify, Provider } from 'ethers'
3537
import {
@@ -293,7 +295,52 @@ describe('Actions', () => {
293295
}),
294296
).resolves.toHaveLength(1)
295297
})
298+
299+
test('Insert and fetch PRESENT_POI action', async () => {
300+
const action = {
301+
status: ActionStatus.QUEUED,
302+
type: ActionType.PRESENT_POI,
303+
deploymentID: 'QmQ44hgrWWt3Qf2X9XEX2fPyTbmQbChxwNm5c1t4mhKpGt',
304+
allocationID: '0x1234567890123456789012345678901234567890',
305+
force: false,
306+
source: 'indexerAgent',
307+
reason: 'test',
308+
priority: 0,
309+
protocolNetwork: 'eip155:421614',
310+
isLegacy: false,
311+
}
312+
await models.Action.upsert(action)
313+
await expect(
314+
ActionManager.fetchActions(models, null, { type: ActionType.PRESENT_POI }),
315+
).resolves.toHaveLength(1)
316+
})
317+
318+
test('Generate where options for PRESENT_POI', () => {
319+
const filter = {
320+
status: ActionStatus.QUEUED,
321+
type: ActionType.PRESENT_POI,
322+
}
323+
expect(actionFilterToWhereOptions(filter)).toEqual({
324+
[Op.and]: [{ status: 'queued' }, { type: 'present_poi' }],
325+
})
326+
})
296327
})
328+
329+
describe('Encoding', () => {
330+
test('encodeCollectData encodes POI data correctly', () => {
331+
const allocationId = '0x1234567890123456789012345678901234567890'
332+
const poiData = {
333+
poi: '0x' + 'ab'.repeat(32),
334+
publicPOI: '0x' + 'cd'.repeat(32),
335+
blockNumber: 12345,
336+
indexingStatus: IndexingStatusCode.Healthy,
337+
}
338+
const result = encodeCollectData(allocationId, poiData)
339+
expect(result).toMatch(/^0x/)
340+
expect(result.length).toBeGreaterThan(2)
341+
})
342+
})
343+
297344
describe('Types', () => {
298345
test('Fail to resolve chain id', () => {
299346
expect(() => resolveChainId('arbitrum')).toThrow(

0 commit comments

Comments
 (0)