@graphprotocol/graph-cli 0.37.3 → 0.37.4
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 +8 -0
- package/package.json +5 -1
- package/babel.config.js +0 -3
- package/jest.config.js +0 -175
- package/src/bin.ts +0 -6
- package/src/cli.ts +0 -30
- package/src/codegen/schema.test.ts +0 -460
- package/src/codegen/schema.ts +0 -299
- package/src/codegen/template.ts +0 -45
- package/src/codegen/types/conversions.ts +0 -358
- package/src/codegen/types/index.test.ts +0 -715
- package/src/codegen/types/index.ts +0 -111
- package/src/codegen/typescript.ts +0 -224
- package/src/codegen/util.test.ts +0 -112
- package/src/codegen/util.ts +0 -54
- package/src/command-helpers/abi.ts +0 -99
- package/src/command-helpers/auth.ts +0 -46
- package/src/command-helpers/compiler.ts +0 -60
- package/src/command-helpers/data-sources.ts +0 -36
- package/src/command-helpers/fs.ts +0 -5
- package/src/command-helpers/gluegun.ts +0 -52
- package/src/command-helpers/ipfs-http-client.d.ts +0 -1
- package/src/command-helpers/ipfs.ts +0 -3
- package/src/command-helpers/jsonrpc.ts +0 -22
- package/src/command-helpers/network.test.ts +0 -85
- package/src/command-helpers/network.ts +0 -133
- package/src/command-helpers/node.ts +0 -46
- package/src/command-helpers/scaffold.ts +0 -174
- package/src/command-helpers/spinner.ts +0 -60
- package/src/command-helpers/studio.test.ts +0 -84
- package/src/command-helpers/studio.ts +0 -25
- package/src/command-helpers/subgraph.ts +0 -21
- package/src/command-helpers/version.test.ts +0 -241
- package/src/command-helpers/version.ts +0 -53
- package/src/commands/add.ts +0 -220
- package/src/commands/auth.ts +0 -138
- package/src/commands/binary-install-raw.d.ts +0 -1
- package/src/commands/build.ts +0 -147
- package/src/commands/codegen.ts +0 -123
- package/src/commands/create.ts +0 -109
- package/src/commands/deploy.ts +0 -388
- package/src/commands/init.ts +0 -1060
- package/src/commands/local.ts +0 -539
- package/src/commands/remove.ts +0 -110
- package/src/commands/test.ts +0 -369
- package/src/compiler/asc.ts +0 -77
- package/src/compiler/index.ts +0 -677
- package/src/debug.ts +0 -15
- package/src/migrations/mapping_api_version_0_0_1.ts +0 -75
- package/src/migrations/mapping_api_version_0_0_2.ts +0 -75
- package/src/migrations/mapping_api_version_0_0_3.ts +0 -75
- package/src/migrations/mapping_api_version_0_0_4.ts +0 -77
- package/src/migrations/mapping_api_version_0_0_5.ts +0 -77
- package/src/migrations/spec_version_0_0_2.ts +0 -24
- package/src/migrations/spec_version_0_0_3.ts +0 -29
- package/src/migrations/util/load-manifest.ts +0 -10
- package/src/migrations/util/versions.ts +0 -27
- package/src/migrations.ts +0 -33
- package/src/protocols/arweave/manifest.graphql +0 -57
- package/src/protocols/arweave/scaffold/manifest.ts +0 -14
- package/src/protocols/arweave/scaffold/mapping.ts +0 -49
- package/src/protocols/arweave/subgraph.ts +0 -22
- package/src/protocols/contract.ts +0 -9
- package/src/protocols/cosmos/manifest.graphql +0 -76
- package/src/protocols/cosmos/scaffold/manifest.ts +0 -11
- package/src/protocols/cosmos/scaffold/mapping.ts +0 -35
- package/src/protocols/cosmos/subgraph.ts +0 -27
- package/src/protocols/ethereum/abi.ts +0 -153
- package/src/protocols/ethereum/codegen/abi.test.ts +0 -330
- package/src/protocols/ethereum/codegen/abi.ts +0 -719
- package/src/protocols/ethereum/codegen/template.ts +0 -41
- package/src/protocols/ethereum/contract.ts +0 -24
- package/src/protocols/ethereum/manifest.graphql +0 -94
- package/src/protocols/ethereum/scaffold/manifest.ts +0 -28
- package/src/protocols/ethereum/scaffold/mapping.ts +0 -76
- package/src/protocols/ethereum/subgraph.ts +0 -189
- package/src/protocols/ethereum/type-generator.ts +0 -191
- package/src/protocols/index.ts +0 -287
- package/src/protocols/ipfs/codegen/file_template.ts +0 -43
- package/src/protocols/near/contract.ts +0 -47
- package/src/protocols/near/manifest.graphql +0 -64
- package/src/protocols/near/scaffold/manifest.ts +0 -13
- package/src/protocols/near/scaffold/mapping.ts +0 -35
- package/src/protocols/near/subgraph.ts +0 -22
- package/src/protocols/subgraph.ts +0 -12
- package/src/protocols/substreams/manifest.graphql +0 -45
- package/src/protocols/substreams/scaffold/manifest.ts +0 -8
- package/src/protocols/substreams/subgraph.ts +0 -22
- package/src/scaffold/cosmos.test.ts +0 -83
- package/src/scaffold/ethereum.test.ts +0 -512
- package/src/scaffold/index.ts +0 -172
- package/src/scaffold/mapping.ts +0 -44
- package/src/scaffold/near.test.ts +0 -86
- package/src/scaffold/schema.ts +0 -89
- package/src/scaffold/tests.ts +0 -217
- package/src/schema.ts +0 -26
- package/src/subgraph.ts +0 -302
- package/src/type-generator.ts +0 -266
- package/src/validation/contract.ts +0 -51
- package/src/validation/index.ts +0 -5
- package/src/validation/manifest.ts +0 -360
- package/src/validation/schema.test.ts +0 -38
- package/src/validation/schema.ts +0 -957
- package/src/watcher.ts +0 -96
- package/tests/cli/globalSetup.ts +0 -8
- package/tests/cli/globalTeardown.ts +0 -8
- package/tests/cli/init/ethereum/abis/Marketplace.json +0 -408
- package/tests/cli/init/ethereum/abis/OverloadedElements.json +0 -91
- package/tests/cli/init/ethereum/abis/SoloMargin.json +0 -2729
- package/tests/cli/init/ethereum/from-contract-with-abi-and-structs.stderr +0 -14
- package/tests/cli/init/ethereum/from-contract-with-abi-and-structs.stdout +0 -12
- package/tests/cli/init/ethereum/from-contract-with-abi.stderr +0 -14
- package/tests/cli/init/ethereum/from-contract-with-abi.stdout +0 -12
- package/tests/cli/init/ethereum/from-contract-with-overloaded-elements.stderr +0 -14
- package/tests/cli/init/ethereum/from-contract-with-overloaded-elements.stdout +0 -12
- package/tests/cli/init/ethereum/from-contract.stderr +0 -16
- package/tests/cli/init/ethereum/from-contract.stdout +0 -12
- package/tests/cli/init/ethereum/from-example.stderr +0 -12
- package/tests/cli/init/ethereum/from-example.stdout +0 -12
- package/tests/cli/init/near/from-contract.stderr +0 -14
- package/tests/cli/init/near/from-contract.stdout +0 -12
- package/tests/cli/init.test.ts +0 -157
- package/tests/cli/spawn-command.d.ts +0 -7
- package/tests/cli/util.ts +0 -132
- package/tests/cli/validation/abi-not-found/Abi.json +0 -7
- package/tests/cli/validation/abi-not-found/mapping.ts +0 -0
- package/tests/cli/validation/abi-not-found/schema.graphql +0 -3
- package/tests/cli/validation/abi-not-found/subgraph.yaml +0 -42
- package/tests/cli/validation/abi-not-found copy.stderr +0 -13
- package/tests/cli/validation/big-decimal-is-valid/Abi.json +0 -7
- package/tests/cli/validation/big-decimal-is-valid/mapping.ts +0 -0
- package/tests/cli/validation/big-decimal-is-valid/schema.graphql +0 -4
- package/tests/cli/validation/big-decimal-is-valid/subgraph.yaml +0 -23
- package/tests/cli/validation/call-function-not-found/Abi.json +0 -57
- package/tests/cli/validation/call-function-not-found/mapping.ts +0 -0
- package/tests/cli/validation/call-function-not-found/schema.graphql +0 -3
- package/tests/cli/validation/call-function-not-found/subgraph.yaml +0 -22
- package/tests/cli/validation/call-function-not-found.stderr +0 -10
- package/tests/cli/validation/call-handler-with-tuple/Abi.json +0 -24
- package/tests/cli/validation/call-handler-with-tuple/generated/schema.ts +0 -44
- package/tests/cli/validation/call-handler-with-tuple/mapping.ts +0 -0
- package/tests/cli/validation/call-handler-with-tuple/schema.graphql +0 -3
- package/tests/cli/validation/call-handler-with-tuple/subgraph.yaml +0 -22
- package/tests/cli/validation/call-handler-with-tuple.stderr +0 -24
- package/tests/cli/validation/conflicting-network-names/Abi.json +0 -7
- package/tests/cli/validation/conflicting-network-names/mapping.ts +0 -0
- package/tests/cli/validation/conflicting-network-names/schema.graphql +0 -3
- package/tests/cli/validation/conflicting-network-names/subgraph.yaml +0 -41
- package/tests/cli/validation/conflicting-network-names.stderr +0 -10
- package/tests/cli/validation/conflicting-protocol-names/Abi.json +0 -7
- package/tests/cli/validation/conflicting-protocol-names/mapping.ts +0 -0
- package/tests/cli/validation/conflicting-protocol-names/schema.graphql +0 -3
- package/tests/cli/validation/conflicting-protocol-names/subgraph.yaml +0 -41
- package/tests/cli/validation/conflicting-protocol-names.stderr +0 -10
- package/tests/cli/validation/derived-from-target-type-missing/Abi.json +0 -6
- package/tests/cli/validation/derived-from-target-type-missing/mapping.ts +0 -0
- package/tests/cli/validation/derived-from-target-type-missing/schema.graphql +0 -4
- package/tests/cli/validation/derived-from-target-type-missing/subgraph.yaml +0 -22
- package/tests/cli/validation/derived-from-target-type-missing.stderr +0 -5
- package/tests/cli/validation/derived-from-with-interface/Gravity.json +0 -1
- package/tests/cli/validation/derived-from-with-interface/mapping.ts +0 -22
- package/tests/cli/validation/derived-from-with-interface/schema.graphql +0 -19
- package/tests/cli/validation/derived-from-with-interface/subgraph.yaml +0 -25
- package/tests/cli/validation/duplicate-data-source-name/Abi.json +0 -7
- package/tests/cli/validation/duplicate-data-source-name/mapping.ts +0 -0
- package/tests/cli/validation/duplicate-data-source-name/schema.graphql +0 -4
- package/tests/cli/validation/duplicate-data-source-name/subgraph.yaml +0 -40
- package/tests/cli/validation/duplicate-data-source-name.stderr +0 -5
- package/tests/cli/validation/duplicate-template-name/Abi.json +0 -7
- package/tests/cli/validation/duplicate-template-name/mapping.ts +0 -0
- package/tests/cli/validation/duplicate-template-name/schema.graphql +0 -4
- package/tests/cli/validation/duplicate-template-name/subgraph.yaml +0 -59
- package/tests/cli/validation/duplicate-template-name.stderr +0 -5
- package/tests/cli/validation/entity-field-args/Abi.json +0 -7
- package/tests/cli/validation/entity-field-args/mapping.ts +0 -0
- package/tests/cli/validation/entity-field-args/schema.graphql +0 -4
- package/tests/cli/validation/entity-field-args/subgraph.yaml +0 -22
- package/tests/cli/validation/entity-field-args.stderr +0 -5
- package/tests/cli/validation/ethereum-contract-without-handlers/Abi.json +0 -7
- package/tests/cli/validation/ethereum-contract-without-handlers/mapping.ts +0 -0
- package/tests/cli/validation/ethereum-contract-without-handlers/schema.graphql +0 -3
- package/tests/cli/validation/ethereum-contract-without-handlers/subgraph.yaml +0 -19
- package/tests/cli/validation/ethereum-contract-without-handlers.stderr +0 -6
- package/tests/cli/validation/event-not-found/Abi.json +0 -7
- package/tests/cli/validation/event-not-found/mapping.ts +0 -0
- package/tests/cli/validation/event-not-found/schema.graphql +0 -3
- package/tests/cli/validation/event-not-found/subgraph.yaml +0 -40
- package/tests/cli/validation/event-not-found.stderr +0 -12
- package/tests/cli/validation/example-values-found/Abi.json +0 -7
- package/tests/cli/validation/example-values-found/generated/ExampleSubgraph/ExampleContract.ts +0 -35
- package/tests/cli/validation/example-values-found/generated/schema.ts +0 -44
- package/tests/cli/validation/example-values-found/mapping.ts +0 -0
- package/tests/cli/validation/example-values-found/schema.graphql +0 -3
- package/tests/cli/validation/example-values-found/subgraph.yaml +0 -24
- package/tests/cli/validation/example-values-found.stderr +0 -34
- package/tests/cli/validation/invalid-abis/InvalidAbi.json +0 -1
- package/tests/cli/validation/invalid-abis/mapping.ts +0 -0
- package/tests/cli/validation/invalid-abis/schema.graphql +0 -3
- package/tests/cli/validation/invalid-abis/subgraph.yaml +0 -22
- package/tests/cli/validation/invalid-abis.stderr +0 -5
- package/tests/cli/validation/invalid-contract-addresses/Abi.json +0 -7
- package/tests/cli/validation/invalid-contract-addresses/mapping.ts +0 -0
- package/tests/cli/validation/invalid-contract-addresses/schema.graphql +0 -3
- package/tests/cli/validation/invalid-contract-addresses/subgraph.yaml +0 -58
- package/tests/cli/validation/invalid-contract-addresses.stderr +0 -14
- package/tests/cli/validation/invalid-data-source-template/mapping.ts +0 -0
- package/tests/cli/validation/invalid-data-source-template/schema.graphql +0 -3
- package/tests/cli/validation/invalid-data-source-template/subgraph.yaml +0 -32
- package/tests/cli/validation/invalid-data-source-template.stderr +0 -30
- package/tests/cli/validation/invalid-entity-field-types/Abi.json +0 -7
- package/tests/cli/validation/invalid-entity-field-types/mapping.ts +0 -0
- package/tests/cli/validation/invalid-entity-field-types/schema.graphql +0 -157
- package/tests/cli/validation/invalid-entity-field-types/subgraph.yaml +0 -22
- package/tests/cli/validation/invalid-entity-field-types.stderr +0 -148
- package/tests/cli/validation/invalid-fulltext-directive/Abi.json +0 -7
- package/tests/cli/validation/invalid-fulltext-directive/mapping.ts +0 -0
- package/tests/cli/validation/invalid-fulltext-directive/schema.graphql +0 -140
- package/tests/cli/validation/invalid-fulltext-directive/subgraph.yaml +0 -22
- package/tests/cli/validation/invalid-fulltext-directive.stderr +0 -32
- package/tests/cli/validation/invalid-graphql-schema/Abi.json +0 -7
- package/tests/cli/validation/invalid-graphql-schema/mapping.ts +0 -0
- package/tests/cli/validation/invalid-graphql-schema/schema.graphql +0 -8
- package/tests/cli/validation/invalid-graphql-schema/subgraph.yaml +0 -22
- package/tests/cli/validation/invalid-graphql-schema.stderr +0 -25
- package/tests/cli/validation/invalid-manifest/subgraph.yaml +0 -13
- package/tests/cli/validation/invalid-manifest-cannot-infer-protocol/subgraph.yaml +0 -12
- package/tests/cli/validation/invalid-manifest-cannot-infer-protocol.stderr +0 -5
- package/tests/cli/validation/invalid-manifest.stderr +0 -28
- package/tests/cli/validation/missing-entity-id/Abi.json +0 -7
- package/tests/cli/validation/missing-entity-id/mapping.ts +0 -0
- package/tests/cli/validation/missing-entity-id/schema.graphql +0 -3
- package/tests/cli/validation/missing-entity-id/subgraph.yaml +0 -22
- package/tests/cli/validation/missing-entity-id/types/ExampleSubgraph/ExampleContract.ts +0 -35
- package/tests/cli/validation/missing-entity-id/types/schema.ts +0 -27
- package/tests/cli/validation/missing-entity-id.stderr +0 -5
- package/tests/cli/validation/missing-or-invalid-derived-from-fields/Abi.json +0 -7
- package/tests/cli/validation/missing-or-invalid-derived-from-fields/mapping.ts +0 -0
- package/tests/cli/validation/missing-or-invalid-derived-from-fields/schema.graphql +0 -40
- package/tests/cli/validation/missing-or-invalid-derived-from-fields/subgraph.yaml +0 -22
- package/tests/cli/validation/missing-or-invalid-derived-from-fields.stderr +0 -10
- package/tests/cli/validation/missing-or-invalid-derived-from-fields.stdout +0 -0
- package/tests/cli/validation/near-is-valid/mapping.ts +0 -0
- package/tests/cli/validation/near-is-valid/schema.graphql +0 -8
- package/tests/cli/validation/near-is-valid/subgraph.yaml +0 -30
- package/tests/cli/validation/nested-template-nice-error/Abi.json +0 -7
- package/tests/cli/validation/nested-template-nice-error/mapping.ts +0 -0
- package/tests/cli/validation/nested-template-nice-error/schema.graphql +0 -3
- package/tests/cli/validation/nested-template-nice-error/subgraph.yaml +0 -35
- package/tests/cli/validation/nested-template-nice-error.stderr +0 -5
- package/tests/cli/validation/no-network-names/Abi.json +0 -7
- package/tests/cli/validation/no-network-names/mapping.ts +0 -0
- package/tests/cli/validation/no-network-names/schema.graphql +0 -3
- package/tests/cli/validation/no-network-names/subgraph.yaml +0 -40
- package/tests/cli/validation/no-network-names.stderr +0 -34
- package/tests/cli/validation/source-without-address-is-valid/Abi.json +0 -7
- package/tests/cli/validation/source-without-address-is-valid/generated/ExampleSubgraph/ExampleContract.ts +0 -35
- package/tests/cli/validation/source-without-address-is-valid/mapping.ts +0 -0
- package/tests/cli/validation/source-without-address-is-valid/schema.graphql +0 -3
- package/tests/cli/validation/source-without-address-is-valid/subgraph.yaml +0 -23
- package/tests/cli/validation/source-without-address-is-valid.stderr +0 -24
- package/tests/cli/validation/topic0-is-valid/Abi.json +0 -7
- package/tests/cli/validation/topic0-is-valid/mapping.ts +0 -0
- package/tests/cli/validation/topic0-is-valid/schema.graphql +0 -4
- package/tests/cli/validation/topic0-is-valid/subgraph.yaml +0 -24
- package/tests/cli/validation.test.ts +0 -226
- package/tsconfig.build.json +0 -4
- package/tsconfig.json +0 -19
package/src/commands/test.ts
DELETED
|
@@ -1,369 +0,0 @@
|
|
|
1
|
-
import { exec, spawn } from 'child_process';
|
|
2
|
-
import os from 'os';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { Binary } from 'binary-install-raw';
|
|
5
|
-
import chalk from 'chalk';
|
|
6
|
-
import { filesystem, GluegunToolbox, patching, print, system } from 'gluegun';
|
|
7
|
-
import yaml from 'js-yaml';
|
|
8
|
-
import fetch from 'node-fetch';
|
|
9
|
-
import semver from 'semver';
|
|
10
|
-
import { fixParameters } from '../command-helpers/gluegun';
|
|
11
|
-
|
|
12
|
-
const HELP = `
|
|
13
|
-
${chalk.bold('graph test')} ${chalk.dim('[options]')} ${chalk.bold('<datasource>')}
|
|
14
|
-
|
|
15
|
-
${chalk.dim('Options:')}
|
|
16
|
-
-c, --coverage Run the tests in coverage mode
|
|
17
|
-
-d, --docker Run the tests in a docker container(Note: Please execute from the root folder of the subgraph)
|
|
18
|
-
-f --force Binary - overwrites folder + file when downloading. Docker - rebuilds the docker image
|
|
19
|
-
-h, --help Show usage information
|
|
20
|
-
-l, --logs Logs to the console information about the OS, CPU model and download url (debugging purposes)
|
|
21
|
-
-r, --recompile Force-recompile tests
|
|
22
|
-
-v, --version <tag> Choose the version of the rust binary that you want to be downloaded/used
|
|
23
|
-
`;
|
|
24
|
-
|
|
25
|
-
export interface TestOptions {
|
|
26
|
-
coverage?: boolean;
|
|
27
|
-
docker?: boolean;
|
|
28
|
-
force?: boolean;
|
|
29
|
-
help?: boolean;
|
|
30
|
-
logs?: boolean;
|
|
31
|
-
recompile?: boolean;
|
|
32
|
-
version?: string;
|
|
33
|
-
// not a cli arg
|
|
34
|
-
testsFolder: string;
|
|
35
|
-
cachePath: string;
|
|
36
|
-
latestVersion?: string;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export default {
|
|
40
|
-
description: 'Runs rust binary for subgraph testing',
|
|
41
|
-
run: async (toolbox: GluegunToolbox) => {
|
|
42
|
-
// Read CLI parameters
|
|
43
|
-
const { c, coverage, d, docker, f, force, h, help, l, logs, r, recompile, v, version } =
|
|
44
|
-
toolbox.parameters.options;
|
|
45
|
-
|
|
46
|
-
const testsFolder = './tests';
|
|
47
|
-
const opts: TestOptions = {
|
|
48
|
-
testsFolder,
|
|
49
|
-
cachePath: path.join(testsFolder, '.latest.json'),
|
|
50
|
-
};
|
|
51
|
-
// Support both long and short option variants
|
|
52
|
-
opts.coverage = coverage || c;
|
|
53
|
-
opts.docker = docker || d;
|
|
54
|
-
opts.force = force || f;
|
|
55
|
-
opts.help = help || h;
|
|
56
|
-
opts.logs = logs || l;
|
|
57
|
-
opts.recompile = recompile || r;
|
|
58
|
-
opts.version = version || v;
|
|
59
|
-
// Fix if a boolean flag (e.g -c, --coverage) has an argument
|
|
60
|
-
try {
|
|
61
|
-
fixParameters(toolbox.parameters, {
|
|
62
|
-
h,
|
|
63
|
-
help,
|
|
64
|
-
c,
|
|
65
|
-
coverage,
|
|
66
|
-
d,
|
|
67
|
-
docker,
|
|
68
|
-
f,
|
|
69
|
-
force,
|
|
70
|
-
l,
|
|
71
|
-
logs,
|
|
72
|
-
r,
|
|
73
|
-
recompile,
|
|
74
|
-
});
|
|
75
|
-
} catch (e) {
|
|
76
|
-
print.error(e.message);
|
|
77
|
-
process.exitCode = 1;
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const datasource = toolbox.parameters.first || toolbox.parameters.array?.[0];
|
|
82
|
-
// Show help text if requested
|
|
83
|
-
if (opts.help) {
|
|
84
|
-
print.info(HELP);
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Check if matchstick.yaml config exists
|
|
89
|
-
if (filesystem.exists('matchstick.yaml')) {
|
|
90
|
-
try {
|
|
91
|
-
// Load the config
|
|
92
|
-
const config = await yaml.load(filesystem.read('matchstick.yaml', 'utf8')!);
|
|
93
|
-
|
|
94
|
-
// Check if matchstick.yaml and testsFolder not null
|
|
95
|
-
if (config?.testsFolder) {
|
|
96
|
-
// assign test folder from matchstick.yaml if present
|
|
97
|
-
opts.testsFolder = config.testsFolder;
|
|
98
|
-
}
|
|
99
|
-
} catch (error) {
|
|
100
|
-
print.info(
|
|
101
|
-
'A problem occurred while reading matchstick.yaml. Please attend to the errors below:',
|
|
102
|
-
);
|
|
103
|
-
print.error(error.message);
|
|
104
|
-
process.exit(1);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
setVersionFromCache(opts);
|
|
109
|
-
|
|
110
|
-
// Fetch the latest version tag if version is not specified with -v/--version or if the version is not cached
|
|
111
|
-
if (opts.force || (!opts.version && !opts.latestVersion)) {
|
|
112
|
-
print.info('Fetching latest version tag');
|
|
113
|
-
const result = await fetch(
|
|
114
|
-
'https://api.github.com/repos/LimeChain/matchstick/releases/latest',
|
|
115
|
-
);
|
|
116
|
-
const json = await result.json();
|
|
117
|
-
opts.latestVersion = json.tag_name;
|
|
118
|
-
|
|
119
|
-
filesystem.file(opts.cachePath, {
|
|
120
|
-
content: {
|
|
121
|
-
version: json.tag_name,
|
|
122
|
-
timestamp: Date.now(),
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (opts.docker) {
|
|
128
|
-
runDocker(datasource, opts);
|
|
129
|
-
} else {
|
|
130
|
-
runBinary(datasource, opts);
|
|
131
|
-
}
|
|
132
|
-
},
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
async function setVersionFromCache(opts: TestOptions) {
|
|
136
|
-
if (filesystem.exists(opts.cachePath) == 'file') {
|
|
137
|
-
const cached = filesystem.read(opts.cachePath, 'json');
|
|
138
|
-
// Get the cache age in days
|
|
139
|
-
const cacheAge = (Date.now() - cached.timestamp) / (1000 * 60 * 60 * 24);
|
|
140
|
-
// If cache age is less than 1 day, use the cached version
|
|
141
|
-
if (cacheAge < 1) {
|
|
142
|
-
opts.latestVersion = cached.version;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
async function runBinary(datasource: string | undefined, opts: TestOptions) {
|
|
148
|
-
const coverageOpt = opts.coverage;
|
|
149
|
-
const forceOpt = opts.force;
|
|
150
|
-
const logsOpt = opts.logs;
|
|
151
|
-
const versionOpt = opts.version;
|
|
152
|
-
const latestVersion = opts.latestVersion;
|
|
153
|
-
const recompileOpt = opts.recompile;
|
|
154
|
-
|
|
155
|
-
const platform = await getPlatform(logsOpt);
|
|
156
|
-
|
|
157
|
-
const url = `https://github.com/LimeChain/matchstick/releases/download/${
|
|
158
|
-
versionOpt || latestVersion
|
|
159
|
-
}/${platform}`;
|
|
160
|
-
|
|
161
|
-
if (logsOpt) {
|
|
162
|
-
print.info(`Download link: ${url}`);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const binary = new Binary(platform, url, versionOpt || latestVersion);
|
|
166
|
-
forceOpt ? await binary.install(true) : await binary.install(false);
|
|
167
|
-
const args = [];
|
|
168
|
-
|
|
169
|
-
if (coverageOpt) args.push('-c');
|
|
170
|
-
if (recompileOpt) args.push('-r');
|
|
171
|
-
if (datasource) args.push(datasource);
|
|
172
|
-
args.length > 0 ? binary.run(...args) : binary.run();
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
async function getPlatform(logsOpt: boolean | undefined) {
|
|
176
|
-
const type = os.type();
|
|
177
|
-
const arch = os.arch();
|
|
178
|
-
const cpuCore = os.cpus()[0];
|
|
179
|
-
const isAppleSilicon = arch === 'arm64' && /Apple (M1|M2|processor)/.test(cpuCore.model);
|
|
180
|
-
const linuxInfo = type === 'Linux' ? await getLinuxInfo() : {};
|
|
181
|
-
const linuxDistro = linuxInfo.name;
|
|
182
|
-
const release = linuxInfo.version || os.release();
|
|
183
|
-
const majorVersion = parseInt(linuxInfo.version || '', 10) || semver.major(release);
|
|
184
|
-
|
|
185
|
-
if (logsOpt) {
|
|
186
|
-
print.info(
|
|
187
|
-
`OS type: ${
|
|
188
|
-
linuxDistro || type
|
|
189
|
-
}\nOS arch: ${arch}\nOS release: ${release}\nOS major version: ${majorVersion}\nCPU model: ${
|
|
190
|
-
cpuCore.model
|
|
191
|
-
}`,
|
|
192
|
-
);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if (arch === 'x64' || isAppleSilicon) {
|
|
196
|
-
if (type === 'Darwin') {
|
|
197
|
-
if (majorVersion === 18 || majorVersion === 19) {
|
|
198
|
-
return 'binary-macos-10.15'; // GitHub dropped support for macOS 10.14 in Actions, but it seems 10.15 binary works on 10.14 too
|
|
199
|
-
}
|
|
200
|
-
if (isAppleSilicon) {
|
|
201
|
-
return 'binary-macos-11-m1';
|
|
202
|
-
}
|
|
203
|
-
return 'binary-macos-11';
|
|
204
|
-
}
|
|
205
|
-
if (type === 'Linux') {
|
|
206
|
-
if (majorVersion === 18) {
|
|
207
|
-
return 'binary-linux-18';
|
|
208
|
-
}
|
|
209
|
-
if (majorVersion === 22) {
|
|
210
|
-
return 'binary-linux-22';
|
|
211
|
-
}
|
|
212
|
-
return 'binary-linux-20';
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
throw new Error(`Unsupported platform: ${type} ${arch} ${majorVersion}`);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* The result of running `cat /etc/*-release | grep -E '(^VERSION|^NAME)='`
|
|
221
|
-
*
|
|
222
|
-
* May look like this:
|
|
223
|
-
* ```sh
|
|
224
|
-
* NAME="Ubuntu"
|
|
225
|
-
* VERSION="16.04.7 LTS (Xenial Xerus)"
|
|
226
|
-
* ```
|
|
227
|
-
*/
|
|
228
|
-
interface LinuxInfo {
|
|
229
|
-
name?: string;
|
|
230
|
-
version?: string;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
async function getLinuxInfo(): Promise<LinuxInfo> {
|
|
234
|
-
try {
|
|
235
|
-
const result = await system.run("cat /etc/*-release | grep -E '(^VERSION|^NAME)='", {
|
|
236
|
-
trim: true,
|
|
237
|
-
});
|
|
238
|
-
const infoArray = result
|
|
239
|
-
.replace(/['"]+/g, '')
|
|
240
|
-
.split('\n')
|
|
241
|
-
.map(p => p.split('='));
|
|
242
|
-
const linuxInfo: LinuxInfo = {};
|
|
243
|
-
|
|
244
|
-
infoArray.forEach(val => {
|
|
245
|
-
linuxInfo[val[0].toLowerCase() as keyof LinuxInfo] = val[1];
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
return linuxInfo;
|
|
249
|
-
} catch (error) {
|
|
250
|
-
print.error(`Error fetching the Linux version:\n ${error}`);
|
|
251
|
-
process.exit(1);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
async function runDocker(datasource: string | undefined, opts: TestOptions) {
|
|
256
|
-
const coverageOpt = opts.coverage;
|
|
257
|
-
const forceOpt = opts.force;
|
|
258
|
-
const versionOpt = opts.version;
|
|
259
|
-
const latestVersion = opts.latestVersion;
|
|
260
|
-
const recompileOpt = opts.recompile;
|
|
261
|
-
|
|
262
|
-
// Remove binary-install-raw binaries, because docker has permission issues
|
|
263
|
-
// when building the docker images
|
|
264
|
-
filesystem.remove('./node_modules/binary-install-raw/bin');
|
|
265
|
-
|
|
266
|
-
// Get current working directory
|
|
267
|
-
const current_folder = filesystem.cwd();
|
|
268
|
-
|
|
269
|
-
// Declate dockerfilePath with default location
|
|
270
|
-
const dockerfilePath = path.join(opts.testsFolder || 'tests', '.docker/Dockerfile');
|
|
271
|
-
|
|
272
|
-
// Check if the Dockerfil already exists
|
|
273
|
-
const dockerfileExists = filesystem.exists(dockerfilePath);
|
|
274
|
-
|
|
275
|
-
// Generate the Dockerfile only if it doesn't exists,
|
|
276
|
-
// version flag and/or force flag is passed.
|
|
277
|
-
if (!dockerfileExists || versionOpt || forceOpt) {
|
|
278
|
-
await dockerfile(dockerfilePath, versionOpt, latestVersion);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// Run a command to check if matchstick image already exists
|
|
282
|
-
exec('docker images -q matchstick', (_error, stdout, _stderr) => {
|
|
283
|
-
// Collect all(if any) flags and options that have to be passed to the matchstick binary
|
|
284
|
-
let testArgs = '';
|
|
285
|
-
if (coverageOpt) testArgs = testArgs + ' -c';
|
|
286
|
-
if (recompileOpt) testArgs = testArgs + ' -r';
|
|
287
|
-
if (datasource) testArgs = testArgs + ' ' + datasource;
|
|
288
|
-
|
|
289
|
-
// Build the `docker run` command options and flags
|
|
290
|
-
const dockerRunOpts = [
|
|
291
|
-
'run',
|
|
292
|
-
'-it',
|
|
293
|
-
'--rm',
|
|
294
|
-
'--mount',
|
|
295
|
-
`type=bind,source=${current_folder},target=/matchstick`,
|
|
296
|
-
];
|
|
297
|
-
|
|
298
|
-
if (testArgs !== '') {
|
|
299
|
-
dockerRunOpts.push('-e');
|
|
300
|
-
dockerRunOpts.push(`ARGS=${testArgs.trim()}`);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
dockerRunOpts.push('matchstick');
|
|
304
|
-
|
|
305
|
-
// If a matchstick image does not exists, the command returns an empty string,
|
|
306
|
-
// else it'll return the image ID. Skip `docker build` if an image already exists
|
|
307
|
-
// Delete current image(if any) and rebuild.
|
|
308
|
-
// Use spawn() and {stdio: 'inherit'} so we can see the logs in real time.
|
|
309
|
-
if (!dockerfileExists || stdout === '' || versionOpt || forceOpt) {
|
|
310
|
-
if (stdout !== '') {
|
|
311
|
-
exec('docker image rm matchstick', (_error, stdout, _stderr) => {
|
|
312
|
-
print.info(chalk.bold(`Removing matchstick image\n${stdout}`));
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
|
-
// Build a docker image. If the process has executed successfully
|
|
316
|
-
// run a container from that image.
|
|
317
|
-
spawn('docker', ['build', '-f', dockerfilePath, '-t', 'matchstick', '.'], {
|
|
318
|
-
stdio: 'inherit',
|
|
319
|
-
}).on('close', code => {
|
|
320
|
-
if (code === 0) {
|
|
321
|
-
spawn('docker', dockerRunOpts, { stdio: 'inherit' });
|
|
322
|
-
}
|
|
323
|
-
});
|
|
324
|
-
} else {
|
|
325
|
-
print.info('Docker image already exists. Skipping `docker build` command.');
|
|
326
|
-
// Run the container from the existing matchstick docker image
|
|
327
|
-
spawn('docker', dockerRunOpts, { stdio: 'inherit' });
|
|
328
|
-
}
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// Downloads Dockerfile template from the demo-subgraph repo
|
|
333
|
-
// Replaces the placeholders with their respective values
|
|
334
|
-
async function dockerfile(
|
|
335
|
-
dockerfilePath: string,
|
|
336
|
-
versionOpt: string | undefined,
|
|
337
|
-
latestVersion: string | undefined,
|
|
338
|
-
) {
|
|
339
|
-
const spinner = print.spin('Generating Dockerfile...');
|
|
340
|
-
|
|
341
|
-
try {
|
|
342
|
-
// Fetch the Dockerfile template content from the demo-subgraph repo
|
|
343
|
-
const content = await fetch(
|
|
344
|
-
'https://raw.githubusercontent.com/LimeChain/demo-subgraph/main/Dockerfile',
|
|
345
|
-
).then(response => {
|
|
346
|
-
if (response.ok) {
|
|
347
|
-
return response.text();
|
|
348
|
-
}
|
|
349
|
-
throw new Error(`Status Code: ${response.status}, with error: ${response.statusText}`);
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
// Write the Dockerfile
|
|
353
|
-
filesystem.write(dockerfilePath, content);
|
|
354
|
-
|
|
355
|
-
// Replaces the version placeholders
|
|
356
|
-
await patching.replace(
|
|
357
|
-
dockerfilePath,
|
|
358
|
-
'<MATCHSTICK_VERSION>',
|
|
359
|
-
versionOpt || latestVersion || 'unknown',
|
|
360
|
-
);
|
|
361
|
-
} catch (error) {
|
|
362
|
-
spinner.fail(
|
|
363
|
-
`A problem occurred while generating the Dockerfile. Please attend to the errors below:\n ${error.message}`,
|
|
364
|
-
);
|
|
365
|
-
process.exit(1);
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
spinner.succeed('Successfully generated Dockerfile.');
|
|
369
|
-
}
|
package/src/compiler/asc.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import * as asc from 'assemblyscript/cli/asc';
|
|
2
|
-
|
|
3
|
-
const createExitHandler = (inputFile: string) => () => {
|
|
4
|
-
throw new Error(`The AssemblyScript compiler crashed when compiling this file: '${inputFile}'
|
|
5
|
-
Suggestion: try to comment the whole file and uncomment it little by little while re-running the graph-cli until you isolate the line where the problem happens.
|
|
6
|
-
Also, please contact us so we can make the CLI better by handling errors like this. You can reach out in any of these links:
|
|
7
|
-
- Discord channel: https://discord.gg/eM8CA6WA9r
|
|
8
|
-
- Github issues: https://github.com/graphprotocol/graph-cli/issues`);
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const setupExitHandler = (exitHandler: (code: number) => void) =>
|
|
12
|
-
process.addListener('exit', exitHandler);
|
|
13
|
-
|
|
14
|
-
const removeExitHandler = (exitHandler: (code: number) => void) =>
|
|
15
|
-
process.removeListener('exit', exitHandler);
|
|
16
|
-
|
|
17
|
-
// Important note, the `asc.main` callback function parameter is synchronous,
|
|
18
|
-
// that's why this function doesn't need to be `async` and the throw works properly.
|
|
19
|
-
const assemblyScriptCompiler = (argv: string[], options: asc.APIOptions) =>
|
|
20
|
-
asc.main(argv, options, err => {
|
|
21
|
-
if (err) {
|
|
22
|
-
throw err;
|
|
23
|
-
}
|
|
24
|
-
return 0;
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const compilerDefaults = {
|
|
28
|
-
stdout: process.stdout,
|
|
29
|
-
stderr: process.stdout,
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
// You MUST call this function once before compiling anything.
|
|
33
|
-
// Internally it just delegates to the AssemblyScript compiler
|
|
34
|
-
// which just delegates to the binaryen lib.
|
|
35
|
-
export const ready = async () => {
|
|
36
|
-
await asc.ready;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export interface CompileOptions {
|
|
40
|
-
inputFile: string;
|
|
41
|
-
global: string;
|
|
42
|
-
baseDir: string;
|
|
43
|
-
libs: string;
|
|
44
|
-
outputFile: string;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// For now this function doesn't check if `asc` is ready, because
|
|
48
|
-
// it requires an asynchronous wait. Whenever you call this function,
|
|
49
|
-
// it doesn't matter how many times, just make sure you call `ready`
|
|
50
|
-
// once before everything..
|
|
51
|
-
export const compile = ({ inputFile, global, baseDir, libs, outputFile }: CompileOptions) => {
|
|
52
|
-
const exitHandler = createExitHandler(inputFile);
|
|
53
|
-
|
|
54
|
-
setupExitHandler(exitHandler);
|
|
55
|
-
|
|
56
|
-
const compilerArgs = [
|
|
57
|
-
'--explicitStart',
|
|
58
|
-
'--exportRuntime',
|
|
59
|
-
'--runtime',
|
|
60
|
-
'stub',
|
|
61
|
-
inputFile,
|
|
62
|
-
global,
|
|
63
|
-
'--baseDir',
|
|
64
|
-
baseDir,
|
|
65
|
-
'--lib',
|
|
66
|
-
libs,
|
|
67
|
-
'--outFile',
|
|
68
|
-
outputFile,
|
|
69
|
-
'--optimize',
|
|
70
|
-
'--debug',
|
|
71
|
-
];
|
|
72
|
-
|
|
73
|
-
assemblyScriptCompiler(compilerArgs, compilerDefaults);
|
|
74
|
-
|
|
75
|
-
// only if compiler succeded, that is, when the line above doesn't throw
|
|
76
|
-
removeExitHandler(exitHandler);
|
|
77
|
-
};
|