Skip to content

Commit

Permalink
*: Upgrade build target to es2020, upgrade dependencies
Browse files Browse the repository at this point in the history
- Fix issues arising after Node version upgrade
- Update CLI and attestation tests
- Improve type specifications to work with more recent ts versions
  • Loading branch information
fordN committed Jan 4, 2024
1 parent 95c1f06 commit 2646571
Show file tree
Hide file tree
Showing 21 changed files with 2,883 additions and 1,512 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,10 @@
},
"engines": {
"node": ">=12.22.0"
},
"jest": {
"transformIgnorePatterns": [
"node_modules/(?!@thi.ng)"
]
}
}
2 changes: 1 addition & 1 deletion packages/indexer-agent/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"target": "es2015",
"target": "es2020",
"module": "commonjs",
"declaration": true,
"sourceMap": true,
Expand Down
5 changes: 4 additions & 1 deletion packages/indexer-cli/src/__tests__/indexer/cost.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cliTest, setup, seed, teardown } from '../util'
import { cliTest, setup, seed, teardown, connect } from '../util'
import path from 'path'

const baseDir = path.join(__dirname, '..')
Expand Down Expand Up @@ -185,6 +185,9 @@ describe('Indexer cost tests', () => {
})

describe('Without indexer management server', () => {
beforeAll(async () => {
await connect()
})
cliTest(
'Indexer cost set - not connected',
[
Expand Down
5 changes: 4 additions & 1 deletion packages/indexer-cli/src/__tests__/indexer/rules.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cliTest, setup, seed, teardown, deleteFromAllTables } from '../util'
import { cliTest, connect, setup, seed, teardown, deleteFromAllTables } from '../util'
import path from 'path'

const baseDir = path.join(__dirname, '..')
Expand Down Expand Up @@ -683,6 +683,9 @@ describe('Indexer rules tests', () => {
})

describe('Without indexer management server', () => {
beforeAll(async () => {
await connect()
})
cliTest(
'Indexer rules start - not connected',
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[Network] request to http://localhost:18000/ failed, reason: connect ECONNREFUSED 127.0.0.1:18000
[Network] request to http://127.0.0.1:18000/ failed, reason: connect ECONNREFUSED 127.0.0.1:18000
11 changes: 11 additions & 0 deletions packages/indexer-cli/src/__tests__/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,17 @@ export const setup = async () => {
process.on('SIGINT', shutdownIndexerManagementServer)
}

// Simply setup connection config
export const connect = async () => {
const command = ['indexer', 'connect', 'http://127.0.0.1:18000']
const { exitCode, stderr, stdout } = await runIndexerCli(command, process.cwd())
if (exitCode == 1) {
console.error(stderr)
console.log(stdout)
throw Error(`Setup failed: indexer rules or cost set command failed: ${command}`)
}
}

// Set global, deployment, and subgraph based test rules and cost model
export const seed = async () => {
const commands: string[][] = [
Expand Down
2 changes: 1 addition & 1 deletion packages/indexer-cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"target": "es2015",
"target": "es2020",
"module": "commonjs",
"composite": false,
"declaration": false,
Expand Down
1 change: 1 addition & 0 deletions packages/indexer-common/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
forceExit: true,
testEnvironment: 'node',
testPathIgnorePatterns: ['/node_modules/', '/dist/', '/.yalc', 'util.ts'],
transformIgnorePatterns: ['!node_modules/'],
globals: {
__DATABASE__: {
host: process.env.POSTGRES_TEST_HOST || bail('POSTGRES_TEST_HOST is not defined'),
Expand Down
20 changes: 14 additions & 6 deletions packages/indexer-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@types/lodash.xor": "^4.5.7",
"@urql/core": "2.4.4",
"@urql/exchange-execute": "1.2.2",
"axios": "0.26.1",
"axios": "1.6.2",
"body-parser": "1.20.2",
"cors": "2.8.5",
"ethers": "5.7.0",
Expand All @@ -53,10 +53,11 @@
"p-timeout": "4.1.0",
"parsimmon": "^1.18.1",
"sequelize": "6.33.0",
"ts-custom-error": "^3.2.0",
"ts-custom-error": "^3.3.1",
"zod": "^3.21.4"
},
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.23.3",
"@types/cors": "2.8.14",
"@types/express": "4.17.17",
"@types/jest": "29.5.4",
Expand All @@ -66,10 +67,11 @@
"@types/ngeohash": "0.6.4",
"@types/node": "20.6.1",
"@types/parsimmon": "^1.10.6",
"@typescript-eslint/eslint-plugin": "6.7.0",
"@typescript-eslint/parser": "6.7.0",
"eslint": "8.49.0",
"eslint-config-prettier": "8.5.0",
"@typescript-eslint/eslint-plugin": "6.13.2",
"@typescript-eslint/parser": "6.13.2",
"babel-cli": "^6.26.0",
"eslint": "8.55.0",
"eslint-config-prettier": "9.1.0",
"jest": "<30.0.0-0",
"prettier": "3.0.3",
"ts-jest": "29.1.1",
Expand All @@ -81,5 +83,11 @@
"@ethersproject/bignumber": "5.7.0",
"@urql/exchange-execute/@urql/core": "2.4.4"
},
"babel": {
"presets": [],
"plugins": [
"transform-es2015-modules-commonjs"
]
},
"gitHead": "972ab96774007b2aee15b1da169d2ff4be9f9d27"
}
10 changes: 5 additions & 5 deletions packages/indexer-common/src/graph-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
IndexerErrorCode,
} from './errors'
import { BlockPointer, ChainIndexingStatus, IndexingStatus } from './types'
import pRetry from 'p-retry'
import pRetry, { Options } from 'p-retry'
import axios, { AxiosInstance } from 'axios'
import fetch from 'isomorphic-fetch'

Expand Down Expand Up @@ -114,7 +114,7 @@ export class GraphNode {
err: err.message,
})
},
} as pRetry.Options,
} as Options,
)
} catch (error) {
const err = indexerError(IndexerErrorCode.IE024, error)
Expand Down Expand Up @@ -468,7 +468,7 @@ export class GraphNode {
err: err.message,
})
},
} as pRetry.Options)
} as Options)
} catch (error) {
const err = indexerError(IndexerErrorCode.IE018, error)
this.logger.error(`Failed to query indexing status API`, {
Expand Down Expand Up @@ -542,7 +542,7 @@ export class GraphNode {
err: err.message,
})
},
} as pRetry.Options,
} as Options,
)
} catch (error) {
const err = indexerError(IndexerErrorCode.IE019, error)
Expand Down Expand Up @@ -607,7 +607,7 @@ export class GraphNode {
err: err.message,
})
},
} as pRetry.Options,
} as Options,
)
} catch (error) {
const err = indexerError(IndexerErrorCode.IE070, error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,12 +470,17 @@ describe('Cost models', () => {
model: '',
variables: JSON.stringify({}),
}
const expected = {
deployment: '0x0000000000000000000000000000000000000000000000000000000000000000',
model: null,
variables: JSON.stringify({}),
}

await client.mutation(SET_COST_MODEL_MUTATION, { costModel: input }).toPromise()

await expect(client.query(GET_COST_MODELS_QUERY).toPromise()).resolves.toHaveProperty(
'data.costModels',
[input],
[expected],
)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class AllocationManager {
try {
return await this.confirmActionExecution(receipt, action)
} catch (error) {
let transaction = undefined
let transaction: string | undefined = undefined
if (typeof receipt == 'object') {
transaction = receipt.transactionHash ?? undefined
}
Expand Down
6 changes: 3 additions & 3 deletions packages/indexer-common/src/indexer-management/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
import { BigNumber } from 'ethers'
import gql from 'graphql-tag'
import { providers, utils, Wallet } from 'ethers'
import pRetry from 'p-retry'
import pRetry, { Options } from 'p-retry'
import { IndexerOptions } from '../network-specification'
import pMap from 'p-map'

Expand Down Expand Up @@ -579,7 +579,7 @@ export class NetworkMonitor {
}

async subgraphDeployments(): Promise<SubgraphDeployment[]> {
const deployments = []
const deployments: SubgraphDeployment[] = []
const queryProgress = {
lastCreatedAt: 0,
first: 10,
Expand Down Expand Up @@ -797,7 +797,7 @@ Please submit an issue at https://github.com/graphprotocol/block-oracle/issues/n
err: err.message,
})
},
} as pRetry.Options)
} as Options)
} catch (err) {
if (err instanceof indexerError) {
throw err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,13 @@ export default {
const [model] = await models.CostModel.findOrBuild({
where: { deployment: update.deployment },
})
model.deployment = costModel.deployment || model.deployment
model.model =
costModel.model !== null && costModel.model !== undefined
? costModel.model
: model.model
// logger.info('Fetched current model', { current: model, update })
// model.set('deployment', update.deployment || model.deployment)
// // model.set('model', update.model || model.model)
// model.model = update.model || model.model
// logger.info('Merged models', { now: model })
model.deployment = update.deployment || model.deployment
model.model = update.model || model.model

// Update the model variables (fall back to current value if unchanged)
let variables = update.variables || model.variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const testURL = async (
url: string,
tests: Test[],
): Promise<{ url: string; ok: boolean; tests: TestResult[] }> => {
const results = []
const results: TestResult[] = []

for (const test of tests) {
const cmd = test.test(url)
Expand Down
4 changes: 2 additions & 2 deletions packages/indexer-common/src/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { providers, Wallet } from 'ethers'
import { strict as assert } from 'assert'
import geohash from 'ngeohash'

import pRetry from 'p-retry'
import pRetry, { Options } from 'p-retry'
import { resolveChainId } from './indexer-management'
import { monitorEthBalance } from './utils'
import { QueryFeeModels } from './query-fees'
Expand Down Expand Up @@ -412,7 +412,7 @@ export class Network {
throw error
}
},
{ retries: 5 } as pRetry.Options,
{ retries: 5 } as Options,
)
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/indexer-common/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"target": "es2015",
"target": "es2020",
"module": "commonjs",
"declaration": true,
"sourceMap": true,
"esModuleInterop": true,
"strict": true,
"noImplicitAny": false,
"composite": true,
"lib": [
"esnext.asynciterable",
Expand Down
17 changes: 15 additions & 2 deletions packages/indexer-native/lib/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe("Native Functions", () => {
await expect(verifyReceipt(receipt1Tampered)).resolves.toEqual(false);
});

test("Attestation", async () => {
test("Create attestation", async () => {
// Taken from the attestation test in common-ts
const mnemonic =
"coyote tattoo slush ball cluster culture bleak news when action cover effort";
Expand Down Expand Up @@ -78,13 +78,26 @@ describe("Native Functions", () => {
await expect(
signer.createAttestation("request", "response"),
).resolves.toEqual(expected);
});

test("Fail to initialize signer", async () => {
// Taken from the attestation test in common-ts
const mnemonic =
"coyote tattoo slush ball cluster culture bleak news when action cover effort";

const subgraphDeploymentID = utils.hexlify(
bs58.decode("QmTXzATwNfgGVukV1fX2T6xw9f6LAYRVWpsdXyRWzUR2H9").slice(2),
);
const privateKey = Wallet.fromMnemonic(mnemonic).privateKey;

const chainId = 1;

// Ensure throwing errors works at least in one case when a parameter cannot be deserialized
expect(
() =>
new NativeAttestationSigner(
chainId,
"0xab",
"0xbad",
privateKey,
subgraphDeploymentID,
),
Expand Down
4 changes: 2 additions & 2 deletions packages/indexer-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
},
"dependencies": {
"@graphprotocol/common-ts": "2.0.9",
"@mapbox/node-pre-gyp": "1.0.10",
"cargo-cp-artifact": "0.1.7",
"@mapbox/node-pre-gyp": "1.0.11",
"cargo-cp-artifact": "0.1.8",
"node-pre-gyp-github": "1.4.4"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/indexer-service/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"target": "es2015",
"target": "es2020",
"module": "commonjs",
"declaration": true,
"sourceMap": true,
Expand Down
Loading

0 comments on commit 2646571

Please sign in to comment.