@graphprotocol/graph-cli 0.37.3-alpha-20230112194037-d504a83 → 0.37.3-alpha-20230112195908-6a078ea
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/dist/commands/deploy.js +10 -5
- package/dist/commands/local.js +13 -16
- package/package.json +1 -2
- package/src/commands/auth.ts +1 -1
- package/src/commands/{deploy.js → deploy.ts} +36 -9
- package/src/commands/{local.js → local.ts} +60 -31
package/CHANGELOG.md
CHANGED
package/dist/commands/deploy.js
CHANGED
|
@@ -34,8 +34,6 @@ const compiler_1 = require("../command-helpers/compiler");
|
|
|
34
34
|
const gluegun_1 = require("../command-helpers/gluegun");
|
|
35
35
|
const jsonrpc_1 = require("../command-helpers/jsonrpc");
|
|
36
36
|
const node_1 = require("../command-helpers/node");
|
|
37
|
-
const spinner_1 = require("../command-helpers/spinner");
|
|
38
|
-
const subgraph_1 = require("../command-helpers/subgraph");
|
|
39
37
|
const ipfs_1 = require("../command-helpers/ipfs");
|
|
40
38
|
const version_1 = require("../command-helpers/version");
|
|
41
39
|
const DataSourcesExtractor = __importStar(require("../command-helpers/data-sources"));
|
|
@@ -94,7 +92,7 @@ exports.default = {
|
|
|
94
92
|
description: 'Deploys the subgraph to a Graph node',
|
|
95
93
|
run: async (toolbox) => {
|
|
96
94
|
// Obtain tools
|
|
97
|
-
|
|
95
|
+
const { filesystem, print } = toolbox;
|
|
98
96
|
// Parse CLI parameters
|
|
99
97
|
let { product, studio, deployKey, accessToken, versionLabel, l, g, h, i, help, ipfs, headers, hdr, node, o, outputDir, skipMigrations, w, watch, debugFork, network, networkFile, } = toolbox.parameters.options;
|
|
100
98
|
// Support both long and short option variants
|
|
@@ -247,7 +245,7 @@ exports.default = {
|
|
|
247
245
|
versionLabel = inputs.versionLabel;
|
|
248
246
|
}
|
|
249
247
|
let requestUrl = new URL(node);
|
|
250
|
-
|
|
248
|
+
const client = (0, jsonrpc_1.createJsonRpcClient)(requestUrl);
|
|
251
249
|
// Exit with an error code if the client couldn't be created
|
|
252
250
|
if (!client) {
|
|
253
251
|
process.exitCode = 1;
|
|
@@ -259,6 +257,7 @@ exports.default = {
|
|
|
259
257
|
}
|
|
260
258
|
deployKey = await (0, auth_1.identifyDeployKey)(node, deployKey);
|
|
261
259
|
if (deployKey !== undefined && deployKey !== null) {
|
|
260
|
+
// @ts-expect-error options property seems to exist
|
|
262
261
|
client.options.headers = { Authorization: 'Bearer ' + deployKey };
|
|
263
262
|
}
|
|
264
263
|
let deploySubgraph = async (ipfsHash) => {
|
|
@@ -269,7 +268,13 @@ exports.default = {
|
|
|
269
268
|
ipfs_hash: ipfsHash,
|
|
270
269
|
version_label: versionLabel,
|
|
271
270
|
debug_fork: debugFork,
|
|
272
|
-
}, async (
|
|
271
|
+
}, async (
|
|
272
|
+
// @ts-expect-error TODO: why are the arguments not typed?
|
|
273
|
+
requestError,
|
|
274
|
+
// @ts-expect-error TODO: why are the arguments not typed?
|
|
275
|
+
jsonRpcError,
|
|
276
|
+
// @ts-expect-error TODO: why are the arguments not typed?
|
|
277
|
+
res) => {
|
|
273
278
|
if (jsonRpcError) {
|
|
274
279
|
spinner.fail(`Failed to deploy to Graph node ${requestUrl}: ${jsonRpcError.message}`);
|
|
275
280
|
// Provide helpful advice when the subgraph has not been created yet
|
package/dist/commands/local.js
CHANGED
|
@@ -8,10 +8,9 @@ const docker_compose_1 = __importDefault(require("docker-compose"));
|
|
|
8
8
|
const http_1 = __importDefault(require("http"));
|
|
9
9
|
const net_1 = __importDefault(require("net"));
|
|
10
10
|
const tmp_promise_1 = __importDefault(require("tmp-promise"));
|
|
11
|
-
const dockerode_1 = __importDefault(require("dockerode"));
|
|
12
11
|
const path_1 = __importDefault(require("path"));
|
|
13
12
|
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
14
|
-
const
|
|
13
|
+
const child_process_1 = require("child_process");
|
|
15
14
|
const gluegun_1 = require("../command-helpers/gluegun");
|
|
16
15
|
const spinner_1 = require("../command-helpers/spinner");
|
|
17
16
|
// Clean up temporary files even when an uncaught exception occurs
|
|
@@ -37,7 +36,7 @@ exports.default = {
|
|
|
37
36
|
description: 'Runs local tests against a Graph Node environment (using Ganache by default)',
|
|
38
37
|
run: async (toolbox) => {
|
|
39
38
|
// Obtain tools
|
|
40
|
-
|
|
39
|
+
const { filesystem, print } = toolbox;
|
|
41
40
|
// Parse CLI parameters
|
|
42
41
|
let { composeFile, ethereumLogs, h, help, nodeImage, nodeLogs, skipWaitForEthereum, skipWaitForIpfs, skipWaitForPostgres, standaloneNode, standaloneNodeArgs, timeout, } = toolbox.parameters.options;
|
|
43
42
|
// Support both short and long option variants
|
|
@@ -63,8 +62,6 @@ exports.default = {
|
|
|
63
62
|
return;
|
|
64
63
|
}
|
|
65
64
|
let testCommand = params[0];
|
|
66
|
-
// Create Docker client
|
|
67
|
-
let docker = new dockerode_1.default();
|
|
68
65
|
// Obtain the Docker Compose file for services that the tests run against
|
|
69
66
|
composeFile =
|
|
70
67
|
composeFile ||
|
|
@@ -203,11 +200,11 @@ const indent = (indentation, str) => str
|
|
|
203
200
|
// Remove whitespace from empty lines
|
|
204
201
|
.map(s => s.replace(/^\s+$/g, ''))
|
|
205
202
|
.join('\n');
|
|
206
|
-
const configureTestEnvironment = async (toolbox, tempdir, composeFile, nodeImage) => await (0, spinner_1.withSpinner)(`Configure test environment`, `Failed to configure test environment`, `Warnings configuring test environment`, async (
|
|
203
|
+
const configureTestEnvironment = async (toolbox, tempdir, composeFile, nodeImage) => await (0, spinner_1.withSpinner)(`Configure test environment`, `Failed to configure test environment`, `Warnings configuring test environment`, async () => {
|
|
207
204
|
// Temporary compose file
|
|
208
205
|
let tempComposeFile = path_1.default.join(tempdir, 'compose', 'docker-compose.yml');
|
|
209
206
|
// Copy the compose file to the temporary directory
|
|
210
|
-
|
|
207
|
+
toolbox.filesystem.copy(composeFile, tempComposeFile);
|
|
211
208
|
// Substitute the graph-node image with the custom one, if appropriate
|
|
212
209
|
if (nodeImage) {
|
|
213
210
|
await toolbox.patching.replace(tempComposeFile, 'graphprotocol/graph-node:latest', nodeImage);
|
|
@@ -249,7 +246,7 @@ const waitForTestEnvironment = async ({ skipWaitForEthereum, skipWaitForIpfs, sk
|
|
|
249
246
|
else {
|
|
250
247
|
await waitFor(timeout, async () => new Promise((resolve, reject) => {
|
|
251
248
|
http_1.default
|
|
252
|
-
.get('http://localhost:15001/api/v0/version',
|
|
249
|
+
.get('http://localhost:15001/api/v0/version', () => {
|
|
253
250
|
resolve();
|
|
254
251
|
})
|
|
255
252
|
.on('error', e => {
|
|
@@ -265,7 +262,7 @@ const waitForTestEnvironment = async ({ skipWaitForEthereum, skipWaitForIpfs, sk
|
|
|
265
262
|
else {
|
|
266
263
|
await waitFor(timeout, async () => new Promise((resolve, reject) => {
|
|
267
264
|
http_1.default
|
|
268
|
-
.get('http://localhost:18545',
|
|
265
|
+
.get('http://localhost:18545', () => {
|
|
269
266
|
resolve();
|
|
270
267
|
})
|
|
271
268
|
.on('error', e => {
|
|
@@ -292,7 +289,7 @@ const waitForTestEnvironment = async ({ skipWaitForEthereum, skipWaitForIpfs, sk
|
|
|
292
289
|
(0, spinner_1.step)(spinner, 'Postgres is up');
|
|
293
290
|
}
|
|
294
291
|
});
|
|
295
|
-
const stopTestEnvironment = async (tempdir) => await (0, spinner_1.withSpinner)(`Stop test environment`, `Failed to stop test environment`, `Warnings stopping test environment`, async (
|
|
292
|
+
const stopTestEnvironment = async (tempdir) => await (0, spinner_1.withSpinner)(`Stop test environment`, `Failed to stop test environment`, `Warnings stopping test environment`, async () => {
|
|
296
293
|
// Our containers do not respond quickly to the SIGTERM which `down` tries before timing out
|
|
297
294
|
// and killing them, so speed things up by sending a SIGKILL right away.
|
|
298
295
|
try {
|
|
@@ -329,7 +326,7 @@ const startGraphNode = async (standaloneNode, standaloneNodeArgs, nodeOutputChun
|
|
|
329
326
|
};
|
|
330
327
|
let args = standaloneNodeArgs ? standaloneNodeArgs.split(' ') : defaultArgs;
|
|
331
328
|
let env = { ...defaultEnv, ...process.env };
|
|
332
|
-
let nodeProcess = spawn(standaloneNode, args, {
|
|
329
|
+
let nodeProcess = (0, child_process_1.spawn)(standaloneNode, args, {
|
|
333
330
|
cwd: process.cwd(),
|
|
334
331
|
env,
|
|
335
332
|
});
|
|
@@ -342,14 +339,14 @@ const startGraphNode = async (standaloneNode, standaloneNodeArgs, nodeOutputChun
|
|
|
342
339
|
// Return the node child process
|
|
343
340
|
return nodeProcess;
|
|
344
341
|
});
|
|
345
|
-
const waitForGraphNode = async (timeout) => await (0, spinner_1.withSpinner)(`Wait for Graph node`, `Failed to wait for Graph node`, `Warnings waiting for Graph node`, async (
|
|
342
|
+
const waitForGraphNode = async (timeout) => await (0, spinner_1.withSpinner)(`Wait for Graph node`, `Failed to wait for Graph node`, `Warnings waiting for Graph node`, async () => {
|
|
346
343
|
await waitFor(timeout, async () => new Promise((resolve, reject) => {
|
|
347
344
|
http_1.default
|
|
348
345
|
.get('http://localhost:18000', { timeout }, () => resolve())
|
|
349
346
|
.on('error', e => reject(e));
|
|
350
347
|
}));
|
|
351
348
|
});
|
|
352
|
-
const stopGraphNode = async (nodeProcess) => await (0, spinner_1.withSpinner)(`Stop Graph node`, `Failed to stop Graph node`, `Warnings stopping Graph node`, async (
|
|
349
|
+
const stopGraphNode = async (nodeProcess) => await (0, spinner_1.withSpinner)(`Stop Graph node`, `Failed to stop Graph node`, `Warnings stopping Graph node`, async () => {
|
|
353
350
|
nodeProcess.kill(9);
|
|
354
351
|
});
|
|
355
352
|
const collectGraphNodeLogs = async (tempdir, standaloneNode, nodeOutputChunks) => {
|
|
@@ -373,9 +370,9 @@ const collectEthereumLogs = async (tempdir) => {
|
|
|
373
370
|
});
|
|
374
371
|
return (0, strip_ansi_1.default)(logs.out.trim()).replace(/ethereum_1 \| /g, '');
|
|
375
372
|
};
|
|
376
|
-
const runTests = async (testCommand) => await (0, spinner_1.withSpinner)(`Run tests`, `Failed to run tests`, `Warnings running tests`, async (
|
|
377
|
-
|
|
378
|
-
let testProcess = spawn(`${testCommand}`, { shell: true });
|
|
373
|
+
const runTests = async (testCommand) => await (0, spinner_1.withSpinner)(`Run tests`, `Failed to run tests`, `Warnings running tests`, async () => new Promise(resolve => {
|
|
374
|
+
const output = [];
|
|
375
|
+
let testProcess = (0, child_process_1.spawn)(`${testCommand}`, { shell: true });
|
|
379
376
|
testProcess.stdout.on('data', data => output.push(Buffer.from(data)));
|
|
380
377
|
testProcess.stderr.on('data', data => output.push(Buffer.from(data)));
|
|
381
378
|
testProcess.on('close', code => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphprotocol/graph-cli",
|
|
3
|
-
"version": "0.37.3-alpha-
|
|
3
|
+
"version": "0.37.3-alpha-20230112195908-6a078ea",
|
|
4
4
|
"license": "(Apache-2.0 OR MIT)",
|
|
5
5
|
"description": "CLI for building for and deploying to The Graph",
|
|
6
6
|
"main": "dist/cli.js",
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
"chokidar": "3.5.1",
|
|
16
16
|
"debug": "4.3.1",
|
|
17
17
|
"docker-compose": "0.23.4",
|
|
18
|
-
"dockerode": "2.5.8",
|
|
19
18
|
"fs-extra": "9.0.0",
|
|
20
19
|
"glob": "7.1.6",
|
|
21
20
|
"gluegun": "https://github.com/edgeandnode/gluegun#v4.3.1-pin-colors-dep",
|
package/src/commands/auth.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
const URL = require('url').URL
|
|
2
2
|
import chalk from 'chalk'
|
|
3
3
|
import path from 'path'
|
|
4
|
+
import { GluegunToolbox } from 'gluegun'
|
|
4
5
|
|
|
5
6
|
import { identifyDeployKey } from '../command-helpers/auth'
|
|
6
7
|
import { createCompiler } from '../command-helpers/compiler'
|
|
7
8
|
import { fixParameters } from '../command-helpers/gluegun'
|
|
8
9
|
import { createJsonRpcClient } from '../command-helpers/jsonrpc'
|
|
9
10
|
import { chooseNodeUrl } from '../command-helpers/node'
|
|
10
|
-
import { withSpinner } from '../command-helpers/spinner'
|
|
11
|
-
import { validateSubgraphName } from '../command-helpers/subgraph'
|
|
12
11
|
import { DEFAULT_IPFS_URL } from '../command-helpers/ipfs'
|
|
13
12
|
import {
|
|
14
13
|
assertManifestApiVersion,
|
|
@@ -43,7 +42,27 @@ Options:
|
|
|
43
42
|
--network-file <path> Networks config file path (default: "./networks.json")
|
|
44
43
|
`
|
|
45
44
|
|
|
46
|
-
|
|
45
|
+
export interface DeployOptions {
|
|
46
|
+
product?: 'subgraph-studio' | 'hosted-service'
|
|
47
|
+
studio?: boolean
|
|
48
|
+
node?: string
|
|
49
|
+
deployKey?: string
|
|
50
|
+
versionLabel?: string
|
|
51
|
+
help?: boolean
|
|
52
|
+
ipfs?: string
|
|
53
|
+
headers?: Record<string, string>
|
|
54
|
+
debugFork?: boolean
|
|
55
|
+
outputDir?: string
|
|
56
|
+
skipMigrations?: boolean
|
|
57
|
+
watch?: boolean
|
|
58
|
+
network?: string
|
|
59
|
+
networkFile?: string
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const processForm = async (
|
|
63
|
+
toolbox: GluegunToolbox,
|
|
64
|
+
{ product, studio, node, versionLabel }: DeployOptions,
|
|
65
|
+
) => {
|
|
47
66
|
const questions = [
|
|
48
67
|
{
|
|
49
68
|
type: 'select',
|
|
@@ -74,9 +93,9 @@ const processForm = async (toolbox, { product, studio, node, versionLabel }) =>
|
|
|
74
93
|
|
|
75
94
|
export default {
|
|
76
95
|
description: 'Deploys the subgraph to a Graph node',
|
|
77
|
-
run: async toolbox => {
|
|
96
|
+
run: async (toolbox: GluegunToolbox) => {
|
|
78
97
|
// Obtain tools
|
|
79
|
-
|
|
98
|
+
const { filesystem, print } = toolbox
|
|
80
99
|
|
|
81
100
|
// Parse CLI parameters
|
|
82
101
|
let {
|
|
@@ -121,7 +140,7 @@ export default {
|
|
|
121
140
|
return
|
|
122
141
|
}
|
|
123
142
|
|
|
124
|
-
let subgraphName, manifest
|
|
143
|
+
let subgraphName: string, manifest: string
|
|
125
144
|
try {
|
|
126
145
|
;[subgraphName, manifest] = fixParameters(toolbox.parameters, {
|
|
127
146
|
h,
|
|
@@ -271,7 +290,7 @@ export default {
|
|
|
271
290
|
}
|
|
272
291
|
|
|
273
292
|
let requestUrl = new URL(node)
|
|
274
|
-
|
|
293
|
+
const client = createJsonRpcClient(requestUrl)
|
|
275
294
|
|
|
276
295
|
// Exit with an error code if the client couldn't be created
|
|
277
296
|
if (!client) {
|
|
@@ -285,10 +304,11 @@ export default {
|
|
|
285
304
|
}
|
|
286
305
|
deployKey = await identifyDeployKey(node, deployKey)
|
|
287
306
|
if (deployKey !== undefined && deployKey !== null) {
|
|
307
|
+
// @ts-expect-error options property seems to exist
|
|
288
308
|
client.options.headers = { Authorization: 'Bearer ' + deployKey }
|
|
289
309
|
}
|
|
290
310
|
|
|
291
|
-
let deploySubgraph = async ipfsHash => {
|
|
311
|
+
let deploySubgraph = async (ipfsHash: string) => {
|
|
292
312
|
let spinner = print.spin(`Deploying to Graph node ${requestUrl}`)
|
|
293
313
|
// `Failed to deploy to Graph node ${requestUrl}`,
|
|
294
314
|
client.request(
|
|
@@ -299,7 +319,14 @@ export default {
|
|
|
299
319
|
version_label: versionLabel,
|
|
300
320
|
debug_fork: debugFork,
|
|
301
321
|
},
|
|
302
|
-
async (
|
|
322
|
+
async (
|
|
323
|
+
// @ts-expect-error TODO: why are the arguments not typed?
|
|
324
|
+
requestError,
|
|
325
|
+
// @ts-expect-error TODO: why are the arguments not typed?
|
|
326
|
+
jsonRpcError,
|
|
327
|
+
// @ts-expect-error TODO: why are the arguments not typed?
|
|
328
|
+
res,
|
|
329
|
+
) => {
|
|
303
330
|
if (jsonRpcError) {
|
|
304
331
|
spinner.fail(
|
|
305
332
|
`Failed to deploy to Graph node ${requestUrl}: ${jsonRpcError.message}`,
|
|
@@ -3,10 +3,10 @@ import compose from 'docker-compose'
|
|
|
3
3
|
import http from 'http'
|
|
4
4
|
import net from 'net'
|
|
5
5
|
import tmp from 'tmp-promise'
|
|
6
|
-
import Docker from 'dockerode'
|
|
7
6
|
import path from 'path'
|
|
8
7
|
import stripAnsi from 'strip-ansi'
|
|
9
|
-
|
|
8
|
+
import { spawn, ChildProcess } from 'child_process'
|
|
9
|
+
import { GluegunToolbox } from 'gluegun'
|
|
10
10
|
|
|
11
11
|
import { fixParameters } from '../command-helpers/gluegun'
|
|
12
12
|
import { step, withSpinner } from '../command-helpers/spinner'
|
|
@@ -32,12 +32,26 @@ Options:
|
|
|
32
32
|
--timeout Time to wait for service containers. (optional, defaults to 120000 milliseconds)
|
|
33
33
|
`
|
|
34
34
|
|
|
35
|
+
export interface LocalOptions {
|
|
36
|
+
help?: boolean
|
|
37
|
+
nodeLogs?: boolean
|
|
38
|
+
ethereumLogs?: boolean
|
|
39
|
+
composeFile?: string
|
|
40
|
+
nodeImage?: string
|
|
41
|
+
standaloneNode?: string
|
|
42
|
+
standaloneNodeArgs?: string
|
|
43
|
+
skipWaitForIpfs?: boolean
|
|
44
|
+
skipWaitForEthereum?: boolean
|
|
45
|
+
skipWaitForPostgres?: boolean
|
|
46
|
+
timeout?: number
|
|
47
|
+
}
|
|
48
|
+
|
|
35
49
|
export default {
|
|
36
50
|
description:
|
|
37
51
|
'Runs local tests against a Graph Node environment (using Ganache by default)',
|
|
38
|
-
run: async toolbox => {
|
|
52
|
+
run: async (toolbox: GluegunToolbox) => {
|
|
39
53
|
// Obtain tools
|
|
40
|
-
|
|
54
|
+
const { filesystem, print } = toolbox
|
|
41
55
|
|
|
42
56
|
// Parse CLI parameters
|
|
43
57
|
let {
|
|
@@ -83,9 +97,6 @@ export default {
|
|
|
83
97
|
|
|
84
98
|
let testCommand = params[0]
|
|
85
99
|
|
|
86
|
-
// Create Docker client
|
|
87
|
-
let docker = new Docker()
|
|
88
|
-
|
|
89
100
|
// Obtain the Docker Compose file for services that the tests run against
|
|
90
101
|
composeFile =
|
|
91
102
|
composeFile ||
|
|
@@ -141,7 +152,7 @@ export default {
|
|
|
141
152
|
|
|
142
153
|
// Bring up Graph Node separately, if a standalone node is used
|
|
143
154
|
let nodeProcess
|
|
144
|
-
let nodeOutputChunks = []
|
|
155
|
+
let nodeOutputChunks: Buffer[] = []
|
|
145
156
|
if (standaloneNode) {
|
|
146
157
|
try {
|
|
147
158
|
nodeProcess = await startGraphNode(
|
|
@@ -245,7 +256,7 @@ export default {
|
|
|
245
256
|
/**
|
|
246
257
|
* Indents all lines of a string
|
|
247
258
|
*/
|
|
248
|
-
const indent = (indentation, str) =>
|
|
259
|
+
const indent = (indentation: string, str: string) =>
|
|
249
260
|
str
|
|
250
261
|
.split('\n')
|
|
251
262
|
.map(s => `${indentation}${s}`)
|
|
@@ -253,17 +264,22 @@ const indent = (indentation, str) =>
|
|
|
253
264
|
.map(s => s.replace(/^\s+$/g, ''))
|
|
254
265
|
.join('\n')
|
|
255
266
|
|
|
256
|
-
const configureTestEnvironment = async (
|
|
267
|
+
const configureTestEnvironment = async (
|
|
268
|
+
toolbox: GluegunToolbox,
|
|
269
|
+
tempdir: string,
|
|
270
|
+
composeFile: string,
|
|
271
|
+
nodeImage: string,
|
|
272
|
+
) =>
|
|
257
273
|
await withSpinner(
|
|
258
274
|
`Configure test environment`,
|
|
259
275
|
`Failed to configure test environment`,
|
|
260
276
|
`Warnings configuring test environment`,
|
|
261
|
-
async
|
|
277
|
+
async () => {
|
|
262
278
|
// Temporary compose file
|
|
263
279
|
let tempComposeFile = path.join(tempdir, 'compose', 'docker-compose.yml')
|
|
264
280
|
|
|
265
281
|
// Copy the compose file to the temporary directory
|
|
266
|
-
|
|
282
|
+
toolbox.filesystem.copy(composeFile, tempComposeFile)
|
|
267
283
|
|
|
268
284
|
// Substitute the graph-node image with the custom one, if appropriate
|
|
269
285
|
if (nodeImage) {
|
|
@@ -276,9 +292,9 @@ const configureTestEnvironment = async (toolbox, tempdir, composeFile, nodeImage
|
|
|
276
292
|
},
|
|
277
293
|
)
|
|
278
294
|
|
|
279
|
-
const waitFor = async (timeout, testFn) => {
|
|
295
|
+
const waitFor = async (timeout: number, testFn: () => void) => {
|
|
280
296
|
let deadline = Date.now() + timeout
|
|
281
|
-
let error = undefined
|
|
297
|
+
let error: Error | undefined = undefined
|
|
282
298
|
return new Promise((resolve, reject) => {
|
|
283
299
|
const check = async () => {
|
|
284
300
|
if (Date.now() > deadline) {
|
|
@@ -298,7 +314,7 @@ const waitFor = async (timeout, testFn) => {
|
|
|
298
314
|
})
|
|
299
315
|
}
|
|
300
316
|
|
|
301
|
-
const startTestEnvironment = async tempdir =>
|
|
317
|
+
const startTestEnvironment = async (tempdir: string) =>
|
|
302
318
|
await withSpinner(
|
|
303
319
|
`Start test environment`,
|
|
304
320
|
`Failed to start test environment`,
|
|
@@ -316,6 +332,11 @@ const waitForTestEnvironment = async ({
|
|
|
316
332
|
skipWaitForIpfs,
|
|
317
333
|
skipWaitForPostgres,
|
|
318
334
|
timeout,
|
|
335
|
+
}: {
|
|
336
|
+
skipWaitForEthereum: boolean
|
|
337
|
+
skipWaitForIpfs: boolean
|
|
338
|
+
skipWaitForPostgres: boolean
|
|
339
|
+
timeout: number
|
|
319
340
|
}) =>
|
|
320
341
|
await withSpinner(
|
|
321
342
|
`Wait for test environment`,
|
|
@@ -331,7 +352,7 @@ const waitForTestEnvironment = async ({
|
|
|
331
352
|
async () =>
|
|
332
353
|
new Promise((resolve, reject) => {
|
|
333
354
|
http
|
|
334
|
-
.get('http://localhost:15001/api/v0/version',
|
|
355
|
+
.get('http://localhost:15001/api/v0/version', () => {
|
|
335
356
|
resolve()
|
|
336
357
|
})
|
|
337
358
|
.on('error', e => {
|
|
@@ -351,7 +372,7 @@ const waitForTestEnvironment = async ({
|
|
|
351
372
|
async () =>
|
|
352
373
|
new Promise((resolve, reject) => {
|
|
353
374
|
http
|
|
354
|
-
.get('http://localhost:18545',
|
|
375
|
+
.get('http://localhost:18545', () => {
|
|
355
376
|
resolve()
|
|
356
377
|
})
|
|
357
378
|
.on('error', e => {
|
|
@@ -386,12 +407,12 @@ const waitForTestEnvironment = async ({
|
|
|
386
407
|
},
|
|
387
408
|
)
|
|
388
409
|
|
|
389
|
-
const stopTestEnvironment = async tempdir =>
|
|
410
|
+
const stopTestEnvironment = async (tempdir: string) =>
|
|
390
411
|
await withSpinner(
|
|
391
412
|
`Stop test environment`,
|
|
392
413
|
`Failed to stop test environment`,
|
|
393
414
|
`Warnings stopping test environment`,
|
|
394
|
-
async
|
|
415
|
+
async () => {
|
|
395
416
|
// Our containers do not respond quickly to the SIGTERM which `down` tries before timing out
|
|
396
417
|
// and killing them, so speed things up by sending a SIGKILL right away.
|
|
397
418
|
try {
|
|
@@ -404,7 +425,11 @@ const stopTestEnvironment = async tempdir =>
|
|
|
404
425
|
},
|
|
405
426
|
)
|
|
406
427
|
|
|
407
|
-
const startGraphNode = async (
|
|
428
|
+
const startGraphNode = async (
|
|
429
|
+
standaloneNode: string,
|
|
430
|
+
standaloneNodeArgs: string,
|
|
431
|
+
nodeOutputChunks: Buffer[],
|
|
432
|
+
): Promise<ChildProcess> =>
|
|
408
433
|
await withSpinner(
|
|
409
434
|
`Start Graph node`,
|
|
410
435
|
`Failed to start Graph node`,
|
|
@@ -455,16 +480,16 @@ const startGraphNode = async (standaloneNode, standaloneNodeArgs, nodeOutputChun
|
|
|
455
480
|
},
|
|
456
481
|
)
|
|
457
482
|
|
|
458
|
-
const waitForGraphNode = async timeout =>
|
|
483
|
+
const waitForGraphNode = async (timeout: number) =>
|
|
459
484
|
await withSpinner(
|
|
460
485
|
`Wait for Graph node`,
|
|
461
486
|
`Failed to wait for Graph node`,
|
|
462
487
|
`Warnings waiting for Graph node`,
|
|
463
|
-
async
|
|
488
|
+
async () => {
|
|
464
489
|
await waitFor(
|
|
465
490
|
timeout,
|
|
466
491
|
async () =>
|
|
467
|
-
new Promise((resolve, reject) => {
|
|
492
|
+
new Promise<void>((resolve, reject) => {
|
|
468
493
|
http
|
|
469
494
|
.get('http://localhost:18000', { timeout }, () => resolve())
|
|
470
495
|
.on('error', e => reject(e))
|
|
@@ -473,17 +498,21 @@ const waitForGraphNode = async timeout =>
|
|
|
473
498
|
},
|
|
474
499
|
)
|
|
475
500
|
|
|
476
|
-
const stopGraphNode = async nodeProcess =>
|
|
501
|
+
const stopGraphNode = async (nodeProcess: ChildProcess) =>
|
|
477
502
|
await withSpinner(
|
|
478
503
|
`Stop Graph node`,
|
|
479
504
|
`Failed to stop Graph node`,
|
|
480
505
|
`Warnings stopping Graph node`,
|
|
481
|
-
async
|
|
506
|
+
async () => {
|
|
482
507
|
nodeProcess.kill(9)
|
|
483
508
|
},
|
|
484
509
|
)
|
|
485
510
|
|
|
486
|
-
const collectGraphNodeLogs = async (
|
|
511
|
+
const collectGraphNodeLogs = async (
|
|
512
|
+
tempdir: string,
|
|
513
|
+
standaloneNode: string,
|
|
514
|
+
nodeOutputChunks: Buffer[],
|
|
515
|
+
) => {
|
|
487
516
|
if (standaloneNode) {
|
|
488
517
|
// Pull the logs from the captured output
|
|
489
518
|
return stripAnsi(Buffer.concat(nodeOutputChunks).toString('utf-8'))
|
|
@@ -497,7 +526,7 @@ const collectGraphNodeLogs = async (tempdir, standaloneNode, nodeOutputChunks) =
|
|
|
497
526
|
}
|
|
498
527
|
}
|
|
499
528
|
|
|
500
|
-
const collectEthereumLogs = async tempdir => {
|
|
529
|
+
const collectEthereumLogs = async (tempdir: string) => {
|
|
501
530
|
let logs = await compose.logs('ethereum', {
|
|
502
531
|
follow: false,
|
|
503
532
|
cwd: path.join(tempdir, 'compose'),
|
|
@@ -505,14 +534,14 @@ const collectEthereumLogs = async tempdir => {
|
|
|
505
534
|
return stripAnsi(logs.out.trim()).replace(/ethereum_1 \| /g, '')
|
|
506
535
|
}
|
|
507
536
|
|
|
508
|
-
const runTests = async testCommand =>
|
|
537
|
+
const runTests = async (testCommand: string) =>
|
|
509
538
|
await withSpinner(
|
|
510
539
|
`Run tests`,
|
|
511
540
|
`Failed to run tests`,
|
|
512
541
|
`Warnings running tests`,
|
|
513
|
-
async
|
|
514
|
-
new Promise(
|
|
515
|
-
|
|
542
|
+
async () =>
|
|
543
|
+
new Promise(resolve => {
|
|
544
|
+
const output: Buffer[] = []
|
|
516
545
|
let testProcess = spawn(`${testCommand}`, { shell: true })
|
|
517
546
|
testProcess.stdout.on('data', data => output.push(Buffer.from(data)))
|
|
518
547
|
testProcess.stderr.on('data', data => output.push(Buffer.from(data)))
|