@graphprotocol/graph-cli 0.78.1-alpha-20240719162222-79f5d23 → 0.79.0-alpha-20240719161244-295ff94

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 CHANGED
@@ -1,20 +1,13 @@
1
1
  # @graphprotocol/graph-cli
2
2
 
3
- ## 0.78.1-alpha-20240719162222-79f5d23
3
+ ## 0.79.0-alpha-20240719161244-295ff94
4
4
 
5
- ### Patch Changes
6
-
7
- - [#1549](https://github.com/graphprotocol/graph-tooling/pull/1549)
8
- [`017c69c`](https://github.com/graphprotocol/graph-tooling/commit/017c69c3690c1fdcc9745beaae93e2f26dedd590)
9
- Thanks [@YassinEldeeb](https://github.com/YassinEldeeb)! - dependencies updates:
10
-
11
- - Removed dependency
12
- [`binary-install-raw@0.0.13` ↗︎](https://www.npmjs.com/package/binary-install-raw/v/0.0.13)
13
- (from `dependencies`)
5
+ ### Minor Changes
14
6
 
15
- - [#1549](https://github.com/graphprotocol/graph-tooling/pull/1549)
16
- [`bfab548`](https://github.com/graphprotocol/graph-tooling/commit/bfab54829df78907f2b3935d49dff1f6c6f261f0)
17
- Thanks [@YassinEldeeb](https://github.com/YassinEldeeb)! - test
7
+ - [#1696](https://github.com/graphprotocol/graph-tooling/pull/1696)
8
+ [`295ff94`](https://github.com/graphprotocol/graph-tooling/commit/295ff94d305c753ccf18a350342d5c5ef841ffc8)
9
+ Thanks [@alinobrasil](https://github.com/alinobrasil)! - added rpc & explorer urls for sei,
10
+ gravity (mainnet & testnet), etherlink (mainnet)
18
11
 
19
12
  ## 0.78.0
20
13
 
package/README.md CHANGED
@@ -18,7 +18,8 @@ As of today, the command line interface supports the following commands:
18
18
  the system's keychain.
19
19
  - `graph local` — Runs tests against a [Graph Node](https://github.com/graphprotocol/graph-node)
20
20
  test environment (using Ganache by default).
21
- - `graph test` — Runs tests against the subgraph.
21
+ - `graph test` — Downloads and runs the [Matchstick](https://github.com/LimeChain/matchstick) rust
22
+ binary in order to test a subgraph.
22
23
  - `graph add` - Adds a new datasource to the yaml file and writes the necessary changes to other
23
24
  files - schema.graphql, abi and mapping.
24
25
  - `graph publish` - Publishes the subgraph to the Graph Network.
@@ -237,10 +237,18 @@ const getEtherscanLikeAPIUrl = (network) => {
237
237
  return `https://api-cardona-zkevm.polygonscan.com/api`;
238
238
  case 'sei-mainnet':
239
239
  return `https://seitrace.com/pacific-1/api`;
240
+ case 'sei-atlantic':
241
+ return `https://seitrace.com/atlantic-2/api`;
240
242
  case 'rootstock':
241
243
  return 'https://rootstock.blockscout.com/api';
242
244
  case 'iotex':
243
245
  return 'https://index.iotexscan.io/api';
246
+ case 'gravity-mainnet':
247
+ return 'https://explorer.gravity.xyz/api';
248
+ case 'gravity-testnet':
249
+ return 'https://explorer-sepolia.gravity.xyz/api';
250
+ case 'etherlink-mainnet':
251
+ return 'https://explorer.etherlink.com/api';
244
252
  default:
245
253
  return `https://api-${network}.etherscan.io/api`;
246
254
  }
@@ -353,10 +361,18 @@ const getPublicRPCEndpoint = (network) => {
353
361
  return `https://rpc.cardona.zkevm-rpc.com`;
354
362
  case 'sei-mainnet':
355
363
  return `https://evm-rpc.sei-apis.com`;
364
+ case 'sei-atlantic':
365
+ return `https://evm-rpc-testnet.sei-apis.com`;
356
366
  case 'rootstock':
357
367
  return 'https://public-node.rsk.co';
358
368
  case 'iotex':
359
369
  return 'https://iotexrpc.com';
370
+ case 'gravity-mainnet':
371
+ return 'https://rpc.gravity.xyz/';
372
+ case 'gravity-testnet':
373
+ return 'https://rpc-sepolia.gravity.xyz';
374
+ case 'etherlink-mainnet':
375
+ return 'https://node.mainnet.etherlink.com';
360
376
  default:
361
377
  throw new Error(`Unknown network: ${network}`);
362
378
  }
@@ -7,6 +7,7 @@ export default class TestCommand extends Command {
7
7
  static flags: {
8
8
  help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
9
9
  coverage: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
10
+ docker: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
10
11
  force: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
11
12
  logs: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
12
13
  recompile: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
@@ -1,62 +1,21 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
4
  };
28
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const child_process_1 = require("child_process");
7
+ const os_1 = __importDefault(require("os"));
29
8
  const path_1 = __importDefault(require("path"));
9
+ const binary_install_raw_1 = require("binary-install-raw");
30
10
  const gluegun_1 = require("gluegun");
31
11
  const js_yaml_1 = __importDefault(require("js-yaml"));
32
- // This'd import the N-API bindings based on the OS and architecture
12
+ const semver_1 = __importDefault(require("semver"));
33
13
  const core_1 = require("@oclif/core");
34
- const child_process_1 = require("child_process");
14
+ const constants_1 = require("../constants");
15
+ const fetch_1 = __importDefault(require("../fetch"));
35
16
  class TestCommand extends core_1.Command {
36
17
  async run() {
37
- const { args: { datasource }, flags: { coverage, force, logs, recompile, version }, } = await this.parse(TestCommand);
38
- // Ensure PostgreSQL 14 is installed
39
- try {
40
- const versionOutput = (0, child_process_1.execSync)('psql --version').toString();
41
- const versionMatch = versionOutput.match(/\b14\.\d+/);
42
- if (!versionMatch) {
43
- this.error(`PostgreSQL version 14 is required. Detected version: ${versionOutput}`, {
44
- exit: 1,
45
- });
46
- }
47
- }
48
- catch (error) {
49
- this.error(`PostgreSQL version 14 is required. It seems PostgreSQL is not installed.\n
50
- To install PostgreSQL 14:\n
51
- On Linux (Ubuntu/Debian based):
52
- sudo apt update
53
- sudo apt install -y postgresql-14
54
-
55
- On macOS:
56
- brew install postgresql@14`, {
57
- exit: 1,
58
- });
59
- }
18
+ const { args: { datasource }, flags: { coverage, docker, force, logs, recompile, version }, } = await this.parse(TestCommand);
60
19
  let testsDir = './tests';
61
20
  // Check if matchstick.yaml config exists
62
21
  if (gluegun_1.filesystem.exists('matchstick.yaml')) {
@@ -80,13 +39,36 @@ class TestCommand extends core_1.Command {
80
39
  testsDir,
81
40
  cachePath,
82
41
  coverage,
42
+ docker,
83
43
  force,
84
44
  logs,
85
45
  recompile,
86
46
  version,
87
47
  latestVersion: getLatestVersionFromCache(cachePath),
88
48
  };
89
- runNapi.bind(this)(datasource, opts);
49
+ // Fetch the latest version tag if version is not specified with -v/--version or if the version is not cached
50
+ if (opts.force || (!opts.version && !opts.latestVersion)) {
51
+ this.log('Fetching latest version tag...');
52
+ const result = await (0, fetch_1.default)('https://api.github.com/repos/LimeChain/matchstick/releases/latest', {
53
+ headers: {
54
+ ...constants_1.GRAPH_CLI_SHARED_HEADERS,
55
+ },
56
+ });
57
+ const json = await result.json();
58
+ opts.latestVersion = json.tag_name;
59
+ gluegun_1.filesystem.file(opts.cachePath, {
60
+ content: {
61
+ version: json.tag_name,
62
+ timestamp: Date.now(),
63
+ },
64
+ });
65
+ }
66
+ if (opts.docker) {
67
+ runDocker.bind(this)(datasource, opts);
68
+ }
69
+ else {
70
+ runBinary.bind(this)(datasource, opts);
71
+ }
90
72
  }
91
73
  }
92
74
  TestCommand.description = 'Runs rust binary for subgraph testing.';
@@ -101,8 +83,12 @@ TestCommand.flags = {
101
83
  summary: 'Run the tests in coverage mode.',
102
84
  char: 'c',
103
85
  }),
86
+ docker: core_1.Flags.boolean({
87
+ summary: 'Run the tests in a docker container (Note: Please execute from the root folder of the subgraph).',
88
+ char: 'd',
89
+ }),
104
90
  force: core_1.Flags.boolean({
105
- summary: 'Binary - overwrites folder + file when downloading.',
91
+ summary: 'Binary - overwrites folder + file when downloading. Docker - rebuilds the docker image.',
106
92
  char: 'f',
107
93
  }),
108
94
  logs: core_1.Flags.boolean({
@@ -131,23 +117,186 @@ function getLatestVersionFromCache(cachePath) {
131
117
  }
132
118
  return null;
133
119
  }
134
- async function runNapi(datasource, opts) {
120
+ async function runBinary(datasource, opts) {
121
+ const coverageOpt = opts.coverage;
122
+ const forceOpt = opts.force;
123
+ const logsOpt = opts.logs;
124
+ const versionOpt = opts.version;
125
+ const latestVersion = opts.latestVersion;
126
+ const recompileOpt = opts.recompile;
127
+ const platform = await getPlatform.bind(this)(versionOpt || latestVersion, logsOpt);
128
+ const url = `https://github.com/LimeChain/matchstick/releases/download/${versionOpt || latestVersion}/${platform}`;
129
+ if (logsOpt) {
130
+ this.log(`Download link: ${url}`);
131
+ }
132
+ const binary = new binary_install_raw_1.Binary(platform, url, versionOpt || latestVersion);
133
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
134
+ forceOpt ? await binary.install(true) : await binary.install(false);
135
135
  const args = [];
136
- if (opts.coverage)
137
- args.push('--coverage');
138
- if (opts.recompile)
139
- args.push('--recompile');
136
+ if (coverageOpt)
137
+ args.push('-c');
138
+ if (recompileOpt)
139
+ args.push('-r');
140
140
  if (datasource)
141
141
  args.push(datasource);
142
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
143
+ args.length > 0 ? binary.run(...args) : binary.run();
144
+ }
145
+ async function getPlatform(matchstickVersion, logsOpt) {
146
+ const type = os_1.default.type();
147
+ const arch = os_1.default.arch();
148
+ const cpuCore = os_1.default.cpus()[0];
149
+ const isAppleSilicon = arch === 'arm64' && /Apple (M1|M2|M3|processor)/.test(cpuCore.model);
150
+ const linuxInfo = type === 'Linux' ? await getLinuxInfo.bind(this)() : {};
151
+ const linuxDistro = linuxInfo.name;
152
+ const release = linuxInfo.version || os_1.default.release();
153
+ const majorVersion = parseInt(linuxInfo.version || '', 10) || semver_1.default.major(release);
154
+ if (logsOpt) {
155
+ this.log(`OS type: ${linuxDistro || type}\nOS arch: ${arch}\nOS release: ${release}\nOS major version: ${majorVersion}\nCPU model: ${cpuCore.model}`);
156
+ }
157
+ if (arch === 'x64' || isAppleSilicon) {
158
+ if (semver_1.default.gt(matchstickVersion, '0.5.4')) {
159
+ if (type === 'Darwin') {
160
+ if (isAppleSilicon) {
161
+ return 'binary-macos-12-m1';
162
+ }
163
+ return 'binary-macos-12';
164
+ }
165
+ if (type === 'Linux' && majorVersion === 22) {
166
+ return 'binary-linux-22';
167
+ }
168
+ }
169
+ else {
170
+ if (type === 'Darwin') {
171
+ if (majorVersion === 18 || majorVersion === 19) {
172
+ return 'binary-macos-10.15';
173
+ }
174
+ if (isAppleSilicon) {
175
+ return 'binary-macos-11-m1';
176
+ }
177
+ return 'binary-macos-11';
178
+ }
179
+ if (type === 'Linux') {
180
+ return majorVersion === 18
181
+ ? 'binary-linux-18'
182
+ : majorVersion === 22
183
+ ? 'binary-linux-22'
184
+ : 'binary-linux-20';
185
+ }
186
+ }
187
+ }
188
+ throw new Error(`Unsupported platform: ${type} ${arch} ${majorVersion}`);
189
+ }
190
+ async function getLinuxInfo() {
191
+ try {
192
+ const result = await gluegun_1.system.run("cat /etc/*-release | grep -E '(^VERSION|^NAME)='", {
193
+ trim: true,
194
+ });
195
+ const infoArray = result
196
+ .replace(/['"]+/g, '')
197
+ .split('\n')
198
+ .map(p => p.split('='));
199
+ const linuxInfo = {};
200
+ for (const val of infoArray) {
201
+ linuxInfo[val[0].toLowerCase()] = val[1];
202
+ }
203
+ return linuxInfo;
204
+ }
205
+ catch (error) {
206
+ this.error(`Error fetching the Linux version:\n${error}`, { exit: 1 });
207
+ }
208
+ }
209
+ async function runDocker(datasource, opts) {
210
+ const coverageOpt = opts.coverage;
211
+ const forceOpt = opts.force;
212
+ const versionOpt = opts.version;
213
+ const latestVersion = opts.latestVersion;
214
+ const recompileOpt = opts.recompile;
215
+ // Remove binary-install-raw binaries, because docker has permission issues
216
+ // when building the docker images
217
+ gluegun_1.filesystem.remove('./node_modules/binary-install-raw/bin');
218
+ // Get current working directory
219
+ const current_folder = gluegun_1.filesystem.cwd();
220
+ // Declate dockerfilePath with default location
221
+ const dockerfilePath = path_1.default.join(opts.testsDir, '.docker/Dockerfile');
222
+ // Check if the Dockerfil already exists
223
+ const dockerfileExists = gluegun_1.filesystem.exists(dockerfilePath);
224
+ // Generate the Dockerfile only if it doesn't exists,
225
+ // version flag and/or force flag is passed.
226
+ if (!dockerfileExists || versionOpt || forceOpt) {
227
+ await dockerfile.bind(this)(dockerfilePath, versionOpt, latestVersion);
228
+ }
229
+ // Run a command to check if matchstick image already exists
230
+ (0, child_process_1.exec)('docker images -q matchstick', (_error, stdout, _stderr) => {
231
+ // Collect all(if any) flags and options that have to be passed to the matchstick binary
232
+ let testArgs = '';
233
+ if (coverageOpt)
234
+ testArgs = testArgs + ' -c';
235
+ if (recompileOpt)
236
+ testArgs = testArgs + ' -r';
237
+ if (datasource)
238
+ testArgs = testArgs + ' ' + datasource;
239
+ // Build the `docker run` command options and flags
240
+ const dockerRunOpts = [
241
+ 'run',
242
+ '-it',
243
+ '--rm',
244
+ '--mount',
245
+ `type=bind,source=${current_folder},target=/matchstick`,
246
+ ];
247
+ if (testArgs !== '') {
248
+ dockerRunOpts.push('-e');
249
+ dockerRunOpts.push(`ARGS=${testArgs.trim()}`);
250
+ }
251
+ dockerRunOpts.push('matchstick');
252
+ // If a matchstick image does not exists, the command returns an empty string,
253
+ // else it'll return the image ID. Skip `docker build` if an image already exists
254
+ // Delete current image(if any) and rebuild.
255
+ // Use spawn() and {stdio: 'inherit'} so we can see the logs in real time.
256
+ if (!dockerfileExists || stdout === '' || versionOpt || forceOpt) {
257
+ if (stdout !== '') {
258
+ (0, child_process_1.exec)('docker image rm matchstick', (_error, stdout, _stderr) => {
259
+ this.log(`Remove matchstick image result:\n${stdout}`);
260
+ });
261
+ }
262
+ // Build a docker image. If the process has executed successfully
263
+ // run a container from that image.
264
+ (0, child_process_1.spawn)('docker', ['build', '-f', dockerfilePath, '-t', 'matchstick', '.'], {
265
+ stdio: 'inherit',
266
+ }).on('close', code => {
267
+ if (code === 0) {
268
+ (0, child_process_1.spawn)('docker', dockerRunOpts, { stdio: 'inherit' });
269
+ }
270
+ });
271
+ }
272
+ else {
273
+ this.log('Docker image already exists. Skipping `docker build` command...');
274
+ // Run the container from the existing matchstick docker image
275
+ (0, child_process_1.spawn)('docker', dockerRunOpts, { stdio: 'inherit' });
276
+ }
277
+ });
278
+ }
279
+ // Downloads Dockerfile template from the demo-subgraph repo
280
+ // Replaces the placeholders with their respective values
281
+ async function dockerfile(dockerfilePath, versionOpt, latestVersion) {
282
+ const spinner = gluegun_1.print.spin('Generating Dockerfile...');
142
283
  try {
143
- // Dynamically import runTests only after PostgreSQL check
144
- const { runTests } = await Promise.resolve().then(() => __importStar(require('@graphprotocol/graph-tooling-napi-utils/mod/testing')));
145
- // Call the N-API function
146
- runTests(args);
284
+ // Fetch the Dockerfile template content from the demo-subgraph repo
285
+ const content = await (0, fetch_1.default)('https://raw.githubusercontent.com/LimeChain/demo-subgraph/main/Dockerfile').then(response => {
286
+ if (response.ok) {
287
+ return response.text();
288
+ }
289
+ throw new Error(`Status Code: ${response.status}, with error: ${response.statusText}`);
290
+ });
291
+ // Write the Dockerfile
292
+ gluegun_1.filesystem.write(dockerfilePath, content);
293
+ // Replaces the version placeholders
294
+ await gluegun_1.patching.replace(dockerfilePath, '<MATCHSTICK_VERSION>', versionOpt || latestVersion || 'unknown');
147
295
  }
148
296
  catch (error) {
149
- this.error(`Error running tests:\n${error.message}`, {
297
+ this.error(`A problem occurred while generating the Dockerfile:\n${error.message}`, {
150
298
  exit: 1,
151
299
  });
152
300
  }
301
+ spinner.succeed('Successfully generated Dockerfile.');
153
302
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.78.1-alpha-20240719162222-79f5d23",
2
+ "version": "0.79.0-alpha-20240719161244-295ff94",
3
3
  "commands": {
4
4
  "add": {
5
5
  "id": "add",
@@ -880,11 +880,18 @@
880
880
  "summary": "Run the tests in coverage mode.",
881
881
  "allowNo": false
882
882
  },
883
+ "docker": {
884
+ "name": "docker",
885
+ "type": "boolean",
886
+ "char": "d",
887
+ "summary": "Run the tests in a docker container (Note: Please execute from the root folder of the subgraph).",
888
+ "allowNo": false
889
+ },
883
890
  "force": {
884
891
  "name": "force",
885
892
  "type": "boolean",
886
893
  "char": "f",
887
- "summary": "Binary - overwrites folder + file when downloading.",
894
+ "summary": "Binary - overwrites folder + file when downloading. Docker - rebuilds the docker image.",
888
895
  "allowNo": false
889
896
  },
890
897
  "logs": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphprotocol/graph-cli",
3
- "version": "0.78.1-alpha-20240719162222-79f5d23",
3
+ "version": "0.79.0-alpha-20240719161244-295ff94",
4
4
  "description": "CLI for building for and deploying to The Graph",
5
5
  "license": "(Apache-2.0 OR MIT)",
6
6
  "engines": {
@@ -25,6 +25,7 @@
25
25
  "@oclif/plugin-not-found": "^2.4.0",
26
26
  "@whatwg-node/fetch": "^0.8.4",
27
27
  "assemblyscript": "0.19.23",
28
+ "binary-install-raw": "0.0.13",
28
29
  "chalk": "3.0.0",
29
30
  "chokidar": "3.5.3",
30
31
  "debug": "4.3.4",
@@ -45,8 +46,7 @@
45
46
  "tmp-promise": "3.0.3",
46
47
  "web3-eth-abi": "1.7.0",
47
48
  "which": "2.0.2",
48
- "yaml": "1.10.2",
49
- "@graphprotocol/graph-tooling-napi-utils": "0.0.5"
49
+ "yaml": "1.10.2"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@types/debug": "^4.1.7",