|
1 | 1 | import { |
2 | 2 | Agent, |
| 3 | + addIndexingPaymentsSubgraphToTarget, |
3 | 4 | convertSubgraphBasedRulesToDeploymentBased, |
4 | 5 | consolidateAllocationDecisions, |
5 | 6 | resolveTargetDeployments, |
@@ -472,3 +473,107 @@ describe('reconcileDeploymentAllocationAction', () => { |
472 | 473 | expect(operator.presentPOIForAllocations).not.toHaveBeenCalled() |
473 | 474 | }) |
474 | 475 | }) |
| 476 | + |
| 477 | +describe('addIndexingPaymentsSubgraphToTarget function', () => { |
| 478 | + const paymentsDeployment = new SubgraphDeploymentID( |
| 479 | + 'QmddSbatCN1XmufoBm1bBwPx4L3FtuMAMHUNNBSPzrgL2a', |
| 480 | + ) |
| 481 | + |
| 482 | + it('pushes the deployment when enableDips is true and deployment is defined', () => { |
| 483 | + const target: SubgraphDeploymentID[] = [] |
| 484 | + addIndexingPaymentsSubgraphToTarget(true, paymentsDeployment, target) |
| 485 | + expect(target.map(d => d.bytes32)).toContain(paymentsDeployment.bytes32) |
| 486 | + }) |
| 487 | + |
| 488 | + it('does nothing when enableDips is false', () => { |
| 489 | + const target: SubgraphDeploymentID[] = [] |
| 490 | + addIndexingPaymentsSubgraphToTarget(false, paymentsDeployment, target) |
| 491 | + expect(target).toHaveLength(0) |
| 492 | + }) |
| 493 | + |
| 494 | + it('does nothing when deployment is undefined', () => { |
| 495 | + const target: SubgraphDeploymentID[] = [] |
| 496 | + addIndexingPaymentsSubgraphToTarget(true, undefined, target) |
| 497 | + expect(target).toHaveLength(0) |
| 498 | + }) |
| 499 | + |
| 500 | + it('does not duplicate an already-present deployment', () => { |
| 501 | + const target: SubgraphDeploymentID[] = [paymentsDeployment] |
| 502 | + addIndexingPaymentsSubgraphToTarget(true, paymentsDeployment, target) |
| 503 | + expect(target).toHaveLength(1) |
| 504 | + }) |
| 505 | +}) |
| 506 | + |
| 507 | +describe('reconcileDeployments indexing-payments carve-out wiring', () => { |
| 508 | + const paymentsDeployment = new SubgraphDeploymentID( |
| 509 | + 'QmddSbatCN1XmufoBm1bBwPx4L3FtuMAMHUNNBSPzrgL2a', |
| 510 | + ) |
| 511 | + |
| 512 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 513 | + const mockLogger: any = { |
| 514 | + child: jest.fn().mockReturnThis(), |
| 515 | + info: jest.fn(), |
| 516 | + debug: jest.fn(), |
| 517 | + warn: jest.fn(), |
| 518 | + error: jest.fn(), |
| 519 | + trace: jest.fn(), |
| 520 | + } |
| 521 | + |
| 522 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 523 | + function createAgentUnderTest(network: any) { |
| 524 | + const agent = Object.create(Agent.prototype) |
| 525 | + agent.logger = mockLogger |
| 526 | + agent.offchainSubgraphs = [] |
| 527 | + agent.multiNetworks = { |
| 528 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 529 | + map: async (fn: any) => Promise.all([fn({ network })]), |
| 530 | + } |
| 531 | + agent.graphNode = { |
| 532 | + subgraphDeploymentsAssignments: jest.fn().mockResolvedValue([]), |
| 533 | + ensure: jest.fn().mockResolvedValue(undefined), |
| 534 | + pause: jest.fn().mockResolvedValue(undefined), |
| 535 | + } |
| 536 | + return agent |
| 537 | + } |
| 538 | + |
| 539 | + it('schedules the indexing-payments deployment for indexing when DIPS is enabled', async () => { |
| 540 | + const agent = createAgentUnderTest({ |
| 541 | + networkSubgraph: { deployment: undefined }, |
| 542 | + specification: { indexerOptions: { enableDips: true } }, |
| 543 | + indexingPaymentsSubgraph: { deployment: { id: paymentsDeployment } }, |
| 544 | + }) |
| 545 | + |
| 546 | + await agent.reconcileDeployments([], [], []) |
| 547 | + |
| 548 | + const ensureCalls = agent.graphNode.ensure.mock.calls |
| 549 | + const ensuredDeployments = ensureCalls.map( |
| 550 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 551 | + (call: any[]) => (call[1] as SubgraphDeploymentID).bytes32, |
| 552 | + ) |
| 553 | + expect(ensuredDeployments).toContain(paymentsDeployment.bytes32) |
| 554 | + }) |
| 555 | + |
| 556 | + it('does not schedule the indexing-payments deployment when DIPS is disabled', async () => { |
| 557 | + const agent = createAgentUnderTest({ |
| 558 | + networkSubgraph: { deployment: undefined }, |
| 559 | + specification: { indexerOptions: { enableDips: false } }, |
| 560 | + indexingPaymentsSubgraph: { deployment: { id: paymentsDeployment } }, |
| 561 | + }) |
| 562 | + |
| 563 | + await agent.reconcileDeployments([], [], []) |
| 564 | + |
| 565 | + expect(agent.graphNode.ensure).not.toHaveBeenCalled() |
| 566 | + }) |
| 567 | + |
| 568 | + it('does not schedule the indexing-payments deployment when deployment is undefined', async () => { |
| 569 | + const agent = createAgentUnderTest({ |
| 570 | + networkSubgraph: { deployment: undefined }, |
| 571 | + specification: { indexerOptions: { enableDips: true } }, |
| 572 | + indexingPaymentsSubgraph: { deployment: undefined }, |
| 573 | + }) |
| 574 | + |
| 575 | + await agent.reconcileDeployments([], [], []) |
| 576 | + |
| 577 | + expect(agent.graphNode.ensure).not.toHaveBeenCalled() |
| 578 | + }) |
| 579 | +}) |
0 commit comments