Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor indexer management API layer #859

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
2ca42af
common: setting up GraphQL using Yoga and Codegen preset
saihaj Feb 21, 2024
35a172f
port over code model resolvers
saihaj Feb 21, 2024
e1d205f
port over more queries
saihaj Feb 21, 2024
3cede5c
more resolvers
saihaj Feb 23, 2024
897a88f
mutations
saihaj Feb 23, 2024
dea58e4
format
saihaj Feb 23, 2024
3f474ea
remove generate types
saihaj Feb 23, 2024
86af179
new line
saihaj Feb 23, 2024
b2e122c
fix build
saihaj Feb 23, 2024
1be1651
scalars
saihaj Feb 23, 2024
6831577
mutation
saihaj Feb 23, 2024
465f04f
remove unused
saihaj Feb 23, 2024
145fce5
remove Mutation.updateAction
saihaj Feb 23, 2024
57abcb2
make progress
saihaj Mar 18, 2024
5c23d34
Merge branch 'main' into saihaj/cleanup-resolvers
saihaj Mar 25, 2024
87acf85
finally some tests start to run
saihaj Mar 25, 2024
a84aa2f
fix actions test
saihaj Mar 26, 2024
504543d
more tests
saihaj Mar 26, 2024
229561a
fix install
saihaj Mar 26, 2024
d4a3957
fix cost model tests
saihaj Mar 26, 2024
1192c13
fix indexing rule test
saihaj Mar 26, 2024
5e568f5
fix poi disputes tests
saihaj Mar 26, 2024
06afc5e
remove grit
saihaj Mar 26, 2024
35aacef
fix some ts issues
saihaj Mar 27, 2024
abf8757
style prettier
saihaj Mar 27, 2024
d677bce
make tsc happy
saihaj Mar 27, 2024
50270d3
enable typechecking in tests
saihaj Mar 27, 2024
ade172d
fix tests
saihaj Mar 27, 2024
37c62ae
fix more type issues
saihaj Mar 27, 2024
ea7c704
format command
saihaj Mar 28, 2024
98f6698
fix some
saihaj Apr 1, 2024
cffb378
fix more
saihaj Apr 1, 2024
94926f7
mostly there
saihaj Apr 1, 2024
16ae8b4
fix
saihaj Apr 2, 2024
a8c3e6c
fix tests
saihaj Apr 2, 2024
463271b
works
saihaj Apr 2, 2024
cfd775a
fix a test
saihaj Apr 2, 2024
a49e672
fix test
saihaj Apr 2, 2024
4d0a0d3
remove console log
saihaj Apr 2, 2024
97666a2
fix issue
saihaj Apr 2, 2024
bd75175
prettier
saihaj Apr 2, 2024
5ce8a0c
remove urql client from indexer common
saihaj Apr 3, 2024
16c3ca3
bring back some deps because of typings
saihaj Apr 3, 2024
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
90 changes: 60 additions & 30 deletions packages/indexer-agent/src/__tests__/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import {
consolidateAllocationDecisions,
} from '../agent'
import {
GeneratedGraphQLTypes,
INDEXING_RULE_GLOBAL,
IndexingDecisionBasis,
IndexingRuleAttributes,
SubgraphIdentifierType,
SubgraphVersion,
} from '@graphprotocol/indexer-common'
import { SubgraphDeploymentID } from '@graphprotocol/common-ts'
Expand All @@ -16,44 +14,56 @@ describe('Agent convenience function tests', () => {
const inputRules = [
{
identifier: INDEXING_RULE_GLOBAL,
identifierType: SubgraphIdentifierType.GROUP,
allocationAmount: '2300',
identifierType: 'group',
allocationAmount: BigInt(2300),
parallelAllocations: null,
maxAllocationPercentage: null,
minSignal: null,
maxSignal: null,
minStake: null,
minAverageQueryFees: null,
custom: null,
decisionBasis: IndexingDecisionBasis.RULES,
decisionBasis: 'rules',
autoRenewal: false,
requireSupported: false,
safety: false,
protocolNetwork: 'sepolia',
},
{
identifier: '0x0000000000000000000000000000000000000000-0',
identifierType: SubgraphIdentifierType.SUBGRAPH,
allocationAmount: '3000',
identifierType: 'subgraph',
allocationAmount: BigInt(3000),
parallelAllocations: null,
maxAllocationPercentage: null,
minSignal: null,
maxSignal: null,
minStake: null,
minAverageQueryFees: null,
custom: null,
decisionBasis: IndexingDecisionBasis.RULES,
decisionBasis: 'rules',
autoRenewal: false,
requireSupported: false,
safety: false,
protocolNetwork: 'sepolia',
},
{
identifier: 'QmZZtzZkfzCWMNrajxBf22q7BC9HzoT5iJUK3S8qA6zNZr',
identifierType: SubgraphIdentifierType.DEPLOYMENT,
allocationAmount: '12000',
identifierType: 'deployment',
allocationAmount: BigInt(12000),
parallelAllocations: null,
maxAllocationPercentage: null,
minSignal: null,
maxSignal: null,
minStake: null,
minAverageQueryFees: null,
custom: null,
decisionBasis: IndexingDecisionBasis.RULES,
decisionBasis: 'rules',
protocolNetwork: 'sepolia',
autoRenewal: false,
requireSupported: false,
safety: false,
},
] as IndexingRuleAttributes[]
] satisfies GeneratedGraphQLTypes.IndexingRule[]

const subgraphs = [
{
Expand All @@ -73,45 +83,57 @@ describe('Agent convenience function tests', () => {
const expectedRules = [
{
identifier: INDEXING_RULE_GLOBAL,
identifierType: SubgraphIdentifierType.GROUP,
allocationAmount: '2300',
identifierType: 'group',
allocationAmount: BigInt(2300),
parallelAllocations: null,
maxAllocationPercentage: null,
minSignal: null,
maxSignal: null,
minStake: null,
minAverageQueryFees: null,
custom: null,
decisionBasis: IndexingDecisionBasis.RULES,
decisionBasis: 'rules',
protocolNetwork: 'sepolia',
autoRenewal: false,
requireSupported: false,
safety: false,
},
{
identifier:
'0xc9d18c59e4aaf2c1f86dfef16fbdc0f81eae8ada58d87a23d2666c45704b8823',
identifierType: SubgraphIdentifierType.DEPLOYMENT,
allocationAmount: '3000',
identifierType: 'deployment',
allocationAmount: BigInt(3000),
parallelAllocations: null,
maxAllocationPercentage: null,
minSignal: null,
maxSignal: null,
minStake: null,
minAverageQueryFees: null,
custom: null,
decisionBasis: IndexingDecisionBasis.RULES,
decisionBasis: 'rules',
protocolNetwork: 'sepolia',
autoRenewal: false,
requireSupported: false,
safety: false,
},
{
identifier: 'QmZZtzZkfzCWMNrajxBf22q7BC9HzoT5iJUK3S8qA6zNZr',
identifierType: SubgraphIdentifierType.DEPLOYMENT,
allocationAmount: '12000',
identifierType: 'deployment',
allocationAmount: BigInt(12000),
parallelAllocations: null,
maxAllocationPercentage: null,
minSignal: null,
maxSignal: null,
minStake: null,
minAverageQueryFees: null,
custom: null,
decisionBasis: IndexingDecisionBasis.RULES,
decisionBasis: 'rules',
protocolNetwork: 'sepolia',
autoRenewal: false,
requireSupported: false,
safety: false,
},
] as IndexingRuleAttributes[]
] satisfies GeneratedGraphQLTypes.IndexingRule[]

expect(
convertSubgraphBasedRulesToDeploymentBased(inputRules, subgraphs, 1000),
Expand All @@ -122,31 +144,39 @@ describe('Agent convenience function tests', () => {
const inputRules = [
{
identifier: INDEXING_RULE_GLOBAL,
identifierType: SubgraphIdentifierType.GROUP,
allocationAmount: '2300',
identifierType: 'group',
allocationAmount: BigInt(2300),
parallelAllocations: null,
maxAllocationPercentage: null,
minSignal: null,
maxSignal: null,
minStake: null,
minAverageQueryFees: null,
custom: null,
decisionBasis: IndexingDecisionBasis.RULES,
decisionBasis: 'rules',
protocolNetwork: 'sepolia',
autoRenewal: false,
requireSupported: false,
safety: false,
},
{
identifier: 'QmZZtzZkfzCWMNrajxBf22q7BC9HzoT5iJUK3S8qA6zNZr',
identifierType: SubgraphIdentifierType.DEPLOYMENT,
allocationAmount: '12000',
identifierType: 'deployment',
allocationAmount: BigInt(12000),
parallelAllocations: null,
maxAllocationPercentage: null,
minSignal: null,
maxSignal: null,
minStake: null,
minAverageQueryFees: null,
custom: null,
decisionBasis: IndexingDecisionBasis.RULES,
decisionBasis: 'rules',
protocolNetwork: 'sepolia',
autoRenewal: false,
requireSupported: false,
safety: false,
},
] as IndexingRuleAttributes[]
] satisfies GeneratedGraphQLTypes.IndexingRule[]

const subgraphs = [
{
Expand Down
97 changes: 29 additions & 68 deletions packages/indexer-agent/src/__tests__/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import {
parseGRT,
} from '@graphprotocol/common-ts'
import {
createIndexerManagementClient,
defineIndexerManagementModels,
IndexerManagementClient,
IndexerManagementModels,
GraphNode,
Operator,
Expand All @@ -19,8 +17,8 @@ import {
QueryFeeModels,
defineQueryFeeModels,
MultiNetworks,
createIndexerManagementYogaClient,
} from '@graphprotocol/indexer-common'
import { BigNumber } from 'ethers'
import { Sequelize } from 'sequelize'

const TEST_DISPUTE_1: POIDisputeAttributes = {
Expand Down Expand Up @@ -66,52 +64,15 @@ const TEST_DISPUTE_2: POIDisputeAttributes = {
protocolNetwork: 'eip155:11155111',
}

const POI_DISPUTES_CONVERTERS_FROM_GRAPHQL: Record<
keyof POIDisputeAttributes,
(x: never) => string | BigNumber | number | undefined
> = {
allocationID: x => x,
subgraphDeploymentID: x => x,
allocationIndexer: x => x,
allocationAmount: x => x,
allocationProof: x => x,
closedEpoch: x => +x,
closedEpochStartBlockHash: x => x,
closedEpochStartBlockNumber: x => +x,
closedEpochReferenceProof: x => x,
previousEpochStartBlockHash: x => x,
previousEpochStartBlockNumber: x => +x,
previousEpochReferenceProof: x => x,
status: x => x,
protocolNetwork: x => x,
}

/**
* Parses a POI dispute returned from the indexer management GraphQL
* API into normalized form.
*/
const disputeFromGraphQL = (
dispute: Partial<POIDisputeAttributes>,
): POIDisputeAttributes => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const obj = {} as any
for (const [key, value] of Object.entries(dispute)) {
if (key === '__typename') {
continue
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
obj[key] = (POI_DISPUTES_CONVERTERS_FROM_GRAPHQL as any)[key](value)
}
return obj as POIDisputeAttributes
}

declare const __DATABASE__: never

let sequelize: Sequelize
let models: IndexerManagementModels
let queryFeeModels: QueryFeeModels
let logger: Logger
let indexerManagementClient: IndexerManagementClient
let indexerManagementClient: Awaited<
ReturnType<typeof createIndexerManagementYogaClient>
>
let graphNode: GraphNode
let operator: Operator
let metrics: Metrics
Expand Down Expand Up @@ -196,7 +157,7 @@ const setup = async () => {
(n: Network) => n.specification.networkIdentifier,
)

indexerManagementClient = await createIndexerManagementClient({
indexerManagementClient = await createIndexerManagementYogaClient({
models,
graphNode,
indexNodeIDs,
Expand Down Expand Up @@ -257,34 +218,34 @@ describe('Indexer tests', () => {
test('Store POI Disputes is idempotent', async () => {
const disputes: POIDisputeAttributes[] = [TEST_DISPUTE_1, TEST_DISPUTE_2]

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const expectedResult = disputes.map((dispute: Record<string, any>) => {
return disputeFromGraphQL(dispute)
})
await expect(operator.storePoiDisputes(disputes)).resolves.toEqual(
expectedResult,
)
await expect(operator.storePoiDisputes(disputes)).resolves.toEqual(
expectedResult,
)
await expect(operator.storePoiDisputes(disputes)).resolves.toEqual(
expectedResult,
)
const result1 = (await operator.storePoiDisputes(disputes)).map(a => ({
...a,
allocationAmount: a.allocationAmount.toString(),
}))
expect(result1).toEqual(disputes)
const result2 = (await operator.storePoiDisputes(disputes)).map(a => ({
...a,
allocationAmount: a.allocationAmount.toString(),
}))
expect(result2).toEqual(disputes)
const result3 = (await operator.storePoiDisputes(disputes)).map(a => ({
...a,
allocationAmount: a.allocationAmount.toString(),
}))
expect(result3).toEqual(disputes)
})

test('Fetch POIDisputes', async () => {
const disputes: POIDisputeAttributes[] = [TEST_DISPUTE_1, TEST_DISPUTE_2]

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const expectedResult = disputes.map((dispute: Record<string, any>) => {
return disputeFromGraphQL(dispute)
})
const expectedFilteredResult = [disputeFromGraphQL(TEST_DISPUTE_2)]
await expect(operator.storePoiDisputes(disputes)).resolves.toEqual(
expectedResult,
)
await expect(
operator.fetchPOIDisputes('potential', 205, 'eip155:11155111'),
).resolves.toEqual(expectedFilteredResult)
const result1 = (await operator.storePoiDisputes(disputes)).map(a => ({
...a,
allocationAmount: a.allocationAmount.toString(),
}))
expect(result1).toEqual(disputes)
const result2 = (
await operator.fetchPOIDisputes('potential', 205, 'eip155:11155111')
).map(a => ({ ...a, allocationAmount: a.allocationAmount.toString() }))
expect(result2).toEqual([TEST_DISPUTE_2])
})
})
Loading
Loading