|
2 | 2 | * Assumes a graph-node is running |
3 | 3 | */ |
4 | 4 |
|
5 | | -import * as supertest from 'supertest' |
6 | | -import * as express from 'express' |
7 | | -import { constants } from 'ethers' |
| 5 | +import supertest from 'supertest' |
| 6 | +import express from 'express' |
| 7 | +import { BigNumber, ethers, Wallet } from 'ethers' |
8 | 8 |
|
9 | | -import { createLogger, createMetrics } from '@graphprotocol/common-ts' |
| 9 | +import { |
| 10 | + connectContracts, |
| 11 | + connectDatabase, |
| 12 | + createLogger, |
| 13 | + createMetrics, |
| 14 | + NetworkContracts, |
| 15 | + toAddress, |
| 16 | +} from '@graphprotocol/common-ts' |
10 | 17 |
|
11 | | -import { createApp } from '..' |
| 18 | +import { createServer } from '..' |
12 | 19 | import { QueryProcessor } from '../../queries' |
| 20 | +import { ensureAttestationSigners, monitorEligibleAllocations } from '../../allocations' |
| 21 | +import { AllocationReceiptManager } from '../../query-fees' |
| 22 | +import { |
| 23 | + createIndexerManagementClient, |
| 24 | + defineIndexerManagementModels, |
| 25 | + defineQueryFeeModels, |
| 26 | + IndexerManagementClient, |
| 27 | + IndexerManagementModels, |
| 28 | + IndexingStatusResolver, |
| 29 | + NetworkSubgraph, |
| 30 | + QueryFeeModels, |
| 31 | +} from '@graphprotocol/indexer-common' |
| 32 | +import { Sequelize } from 'sequelize' |
13 | 33 |
|
14 | | -describe('Server', () => { |
15 | | - let app: express.Express |
| 34 | +// Make global Jest variable available |
| 35 | +// eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 36 | +declare const __DATABASE__: any |
| 37 | + |
| 38 | +let app: express.Express |
| 39 | +let sequelize: Sequelize |
| 40 | +let models: IndexerManagementModels |
| 41 | +let queryFeeModels: QueryFeeModels |
| 42 | +let address: string |
| 43 | +let contracts: NetworkContracts |
| 44 | +let indexingStatusResolver: IndexingStatusResolver |
| 45 | +let networkSubgraph: NetworkSubgraph |
| 46 | +let client: IndexerManagementClient |
| 47 | +let receiptManager: AllocationReceiptManager |
16 | 48 |
|
| 49 | +describe('Server', () => { |
17 | 50 | beforeAll(async () => { |
18 | | - const logger = createLogger({ name: 'server.test.ts' }) |
| 51 | + const logger = createLogger({ name: 'server.test.ts', level: 'trace' }) |
19 | 52 | const metrics = createMetrics() |
20 | 53 |
|
21 | | - app = await createApp({ |
| 54 | + sequelize = await connectDatabase(__DATABASE__) |
| 55 | + |
| 56 | + queryFeeModels = defineQueryFeeModels(sequelize) |
| 57 | + models = defineIndexerManagementModels(sequelize) |
| 58 | + address = '0x90f8bf6a479f320ead074411a4b0e7944ea8c9c1' |
| 59 | + contracts = await connectContracts(ethers.getDefaultProvider('rinkeby'), 4) |
| 60 | + await sequelize.sync({ force: true }) |
| 61 | + indexingStatusResolver = new IndexingStatusResolver({ |
| 62 | + logger: logger, |
| 63 | + statusEndpoint: 'http://localhost:8030/graphql', |
| 64 | + }) |
| 65 | + networkSubgraph = await NetworkSubgraph.create({ |
| 66 | + logger, |
| 67 | + endpoint: 'https://gateway.testnet.thegraph.com/network', |
| 68 | + deployment: undefined, |
| 69 | + }) |
| 70 | + |
| 71 | + client = await createIndexerManagementClient({ |
| 72 | + models, |
| 73 | + address, |
| 74 | + contracts, |
| 75 | + indexingStatusResolver, |
| 76 | + networkSubgraph, |
| 77 | + logger, |
| 78 | + defaults: { |
| 79 | + // This is just a dummy, since we're never writing to the management |
| 80 | + // client from the indexer service. |
| 81 | + globalIndexingRule: { |
| 82 | + allocationAmount: BigNumber.from('0'), |
| 83 | + }, |
| 84 | + }, |
| 85 | + features: { |
| 86 | + injectDai: true, |
| 87 | + }, |
| 88 | + }) |
| 89 | + |
| 90 | + receiptManager = new AllocationReceiptManager( |
| 91 | + sequelize, |
| 92 | + queryFeeModels, |
| 93 | + logger, |
| 94 | + toAddress(address), //update maybe |
| 95 | + ) |
| 96 | + |
| 97 | + const release = { |
| 98 | + version: '0.0.1', |
| 99 | + dependencies: { |
| 100 | + '@graphprotocol/common-ts': '1.8.0', |
| 101 | + }, |
| 102 | + } |
| 103 | + |
| 104 | + // Monitor indexer allocations that we may receive traffic for |
| 105 | + const allocations = monitorEligibleAllocations({ |
| 106 | + indexer: toAddress(address), |
| 107 | + logger, |
| 108 | + networkSubgraph, |
| 109 | + interval: 120_000, |
| 110 | + }) |
| 111 | + const wallet = Wallet.fromMnemonic( |
| 112 | + 'myth like bonus scare over problem client lizard pioneer submit female collect', |
| 113 | + ) |
| 114 | + |
| 115 | + // Ensure there is an attestation signer for every allocation |
| 116 | + const signers = ensureAttestationSigners({ |
| 117 | + logger, |
| 118 | + allocations, |
| 119 | + wallet, |
| 120 | + chainId: 4, |
| 121 | + disputeManagerAddress: contracts.disputeManager.address, |
| 122 | + }) |
| 123 | + |
| 124 | + const queryProcessor = new QueryProcessor({ |
| 125 | + logger: logger.child({ component: 'QueryProcessor' }), |
| 126 | + graphNode: 'http://localhost:8000/', |
| 127 | + metrics, |
| 128 | + receiptManager, |
| 129 | + signers, |
| 130 | + }) |
| 131 | + |
| 132 | + app = await createServer({ |
22 | 133 | logger, |
23 | 134 | port: 9600, |
24 | | - queryProcessor: new QueryProcessor({ |
25 | | - logger: logger.child({ component: 'QueryProcessor' }), |
26 | | - graphNode: 'http://localhost:9000/', |
27 | | - metrics, |
28 | | - receiptManager, |
29 | | - chainId: 1, |
30 | | - disputeManagerAddress: constants.AddressZero, |
31 | | - }), |
32 | | - graphNodeStatusEndpoint: 'http://localhost:9030/graphql', |
| 135 | + queryProcessor, |
| 136 | + graphNodeStatusEndpoint: 'http://localhost:8030/graphql', |
33 | 137 | metrics, |
34 | 138 | freeQueryAuthToken: '', |
| 139 | + indexerManagementClient: client, |
| 140 | + release, |
| 141 | + operatorPublicKey: wallet.publicKey, |
| 142 | + networkSubgraph, |
| 143 | + networkSubgraphAuthToken: 'superdupersecrettoken', |
| 144 | + serveNetworkSubgraph: false, |
35 | 145 | }) |
36 | 146 | }) |
37 | 147 |
|
38 | | - it('is ready to roll', async () => { |
39 | | - await supertest(app).get('/').expect(200) |
| 148 | + afterAll(async () => { |
| 149 | + await sequelize.drop({}) |
| 150 | + }) |
| 151 | + |
| 152 | + it('is ready to roll', done => { |
| 153 | + supertest(app).get('/').expect(200, done) |
| 154 | + //expect(response.body.message).toBe('ready to roll!') |
40 | 155 | }) |
41 | 156 | }) |
0 commit comments