@graphprotocol/graph-cli 0.30.1 → 0.30.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/package.json +1 -1
- package/src/command-helpers/abi.js +1 -0
- package/src/command-helpers/scaffold.js +2 -4
- package/src/commands/add.js +1 -1
- package/src/commands/init.js +1 -3
- package/src/commands/test.js +82 -55
- package/src/protocols/cosmos/scaffold/manifest.js +1 -1
- package/src/scaffold/cosmos.test.js +2 -2
- package/src/scaffold/ethereum.test.js +1 -2
- package/src/scaffold/index.js +1 -2
- package/src/scaffold/near.test.js +1 -2
package/package.json
CHANGED
|
@@ -59,6 +59,7 @@ const getEtherscanLikeAPIUrl = (network) => {
|
|
|
59
59
|
case "aurora": return `https://api.aurorascan.dev/api`
|
|
60
60
|
case "aurora-testnet": return `https://api-testnet.aurorascan.dev/api`
|
|
61
61
|
case "optimism-kovan": return `https://api-kovan-optimistic.etherscan.io/api`
|
|
62
|
+
case "optimism": return `https://api-optimistic.etherscan.io/api`
|
|
62
63
|
default: return `https://api-${network}.etherscan.io/api`
|
|
63
64
|
}
|
|
64
65
|
}
|
|
@@ -33,7 +33,6 @@ const generateScaffold = async (
|
|
|
33
33
|
subgraphName,
|
|
34
34
|
indexEvents,
|
|
35
35
|
contractName = 'Contract',
|
|
36
|
-
dataSourceName,
|
|
37
36
|
node,
|
|
38
37
|
},
|
|
39
38
|
spinner,
|
|
@@ -48,7 +47,6 @@ const generateScaffold = async (
|
|
|
48
47
|
network,
|
|
49
48
|
contractName,
|
|
50
49
|
subgraphName,
|
|
51
|
-
dataSourceName,
|
|
52
50
|
node,
|
|
53
51
|
})
|
|
54
52
|
|
|
@@ -81,12 +79,12 @@ const writeScaffold = async (scaffold, directory, spinner) => {
|
|
|
81
79
|
await writeScaffoldDirectory(scaffold, directory, spinner)
|
|
82
80
|
}
|
|
83
81
|
|
|
84
|
-
const writeABI = async (abi, contractName
|
|
82
|
+
const writeABI = async (abi, contractName) => {
|
|
85
83
|
let data = prettier.format(JSON.stringify(abi.data), {
|
|
86
84
|
parser: 'json',
|
|
87
85
|
})
|
|
88
86
|
|
|
89
|
-
await fs.writeFile(
|
|
87
|
+
await fs.writeFile(`./abis/${contractName}.json`, data, { encoding: 'utf-8' })
|
|
90
88
|
}
|
|
91
89
|
|
|
92
90
|
const writeSchema = async (abi, protocol, schemaPath, entities) => {
|
package/src/commands/add.js
CHANGED
|
@@ -95,7 +95,7 @@ module.exports = {
|
|
|
95
95
|
let { collisionEntities, onlyCollisions, abiData } = updateEventNamesOnCollision(ethabi, entities, contractName, mergeEntities)
|
|
96
96
|
ethabi.data = abiData
|
|
97
97
|
|
|
98
|
-
await writeABI(ethabi, contractName
|
|
98
|
+
await writeABI(ethabi, contractName)
|
|
99
99
|
await writeSchema(ethabi, protocol, result.getIn(['schema', 'file']), collisionEntities)
|
|
100
100
|
await writeMapping(ethabi, protocol, contractName, collisionEntities)
|
|
101
101
|
|
package/src/commands/init.js
CHANGED
|
@@ -179,7 +179,7 @@ const processInitForm = async (
|
|
|
179
179
|
//
|
|
180
180
|
// protocols that don't support contract
|
|
181
181
|
// - arweave
|
|
182
|
-
// -
|
|
182
|
+
// - cosmos
|
|
183
183
|
{
|
|
184
184
|
type: 'input',
|
|
185
185
|
name: 'contract',
|
|
@@ -718,7 +718,6 @@ const initSubgraphFromContract = async (
|
|
|
718
718
|
contract,
|
|
719
719
|
indexEvents,
|
|
720
720
|
contractName,
|
|
721
|
-
dataSourceName,
|
|
722
721
|
node,
|
|
723
722
|
studio,
|
|
724
723
|
product,
|
|
@@ -773,7 +772,6 @@ const initSubgraphFromContract = async (
|
|
|
773
772
|
contract,
|
|
774
773
|
indexEvents,
|
|
775
774
|
contractName,
|
|
776
|
-
dataSourceName,
|
|
777
775
|
node,
|
|
778
776
|
},
|
|
779
777
|
spinner,
|
package/src/commands/test.js
CHANGED
|
@@ -13,12 +13,12 @@ const HELP = `
|
|
|
13
13
|
${chalk.bold('graph test')} ${chalk.dim('[options]')} ${chalk.bold('<datasource>')}
|
|
14
14
|
|
|
15
15
|
${chalk.dim('Options:')}
|
|
16
|
-
-c, --coverage Run the tests in coverage mode
|
|
16
|
+
-c, --coverage Run the tests in coverage mode
|
|
17
17
|
-d, --docker Run the tests in a docker container(Note: Please execute from the root folder of the subgraph)
|
|
18
18
|
-f --force Binary - overwrites folder + file when downloading. Docker - rebuilds the docker image
|
|
19
19
|
-h, --help Show usage information
|
|
20
20
|
-l, --logs Logs to the console information about the OS, CPU model and download url (debugging purposes)
|
|
21
|
-
-r, --recompile Force-recompile tests
|
|
21
|
+
-r, --recompile Force-recompile tests
|
|
22
22
|
-v, --version <tag> Choose the version of the rust binary that you want to be downloaded/used
|
|
23
23
|
`
|
|
24
24
|
|
|
@@ -43,16 +43,16 @@ module.exports = {
|
|
|
43
43
|
version,
|
|
44
44
|
} = toolbox.parameters.options
|
|
45
45
|
|
|
46
|
-
let opts =
|
|
46
|
+
let opts = {}
|
|
47
47
|
// Support both long and short option variants
|
|
48
|
-
opts.
|
|
49
|
-
opts.
|
|
50
|
-
opts.
|
|
51
|
-
opts.
|
|
52
|
-
opts.
|
|
53
|
-
opts.
|
|
54
|
-
opts.
|
|
55
|
-
|
|
48
|
+
opts.coverage = coverage || c
|
|
49
|
+
opts.docker = docker || d
|
|
50
|
+
opts.force = force || f
|
|
51
|
+
opts.help = help || h
|
|
52
|
+
opts.logs = logs || l
|
|
53
|
+
opts.recompile = recompile || r
|
|
54
|
+
opts.version = version || v
|
|
55
|
+
opts.testsFolder = './tests'
|
|
56
56
|
// Fix if a boolean flag (e.g -c, --coverage) has an argument
|
|
57
57
|
try {
|
|
58
58
|
fixParameters(toolbox.parameters, {
|
|
@@ -76,18 +76,49 @@ module.exports = {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
let datasource = toolbox.parameters.first || toolbox.parameters.array[0]
|
|
79
|
-
|
|
80
79
|
// Show help text if requested
|
|
81
|
-
if (opts.
|
|
80
|
+
if (opts.help) {
|
|
82
81
|
print.info(HELP)
|
|
83
82
|
return
|
|
84
83
|
}
|
|
85
84
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
// Check if matchstick.yaml config exists
|
|
86
|
+
if(filesystem.exists('matchstick.yaml')) {
|
|
87
|
+
try {
|
|
88
|
+
// Load the config
|
|
89
|
+
let config = await yaml.load(filesystem.read('matchstick.yaml', 'utf8'))
|
|
90
|
+
|
|
91
|
+
// Check if matchstick.yaml and testsFolder not null
|
|
92
|
+
if(config && config.testsFolder) {
|
|
93
|
+
// assign test folder from matchstick.yaml if present
|
|
94
|
+
opts.testsFolder = config.testsFolder
|
|
95
|
+
}
|
|
96
|
+
} catch (error) {
|
|
97
|
+
print.info('A problem occurred while reading matchstick.yaml. Please attend to the errors below:')
|
|
98
|
+
print.error(error.message)
|
|
99
|
+
process.exit(1)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
opts.cachePath = path.join(opts.testsFolder, '.latest.json')
|
|
104
|
+
setVersionFromCache(opts)
|
|
105
|
+
|
|
106
|
+
// Fetch the latest version tag if version is not specified with -v/--version or if the version is not cached
|
|
107
|
+
if (opts.force || (!opts.version && !opts.latestVersion)) {
|
|
108
|
+
print.info("Fetching latest version tag")
|
|
109
|
+
let result = await fetch('https://api.github.com/repos/LimeChain/matchstick/releases/latest')
|
|
110
|
+
let json = await result.json()
|
|
111
|
+
opts.latestVersion = json.tag_name
|
|
112
|
+
|
|
113
|
+
filesystem.file(opts.cachePath, {
|
|
114
|
+
content: {
|
|
115
|
+
version: json.tag_name,
|
|
116
|
+
timestamp: Date.now()
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
}
|
|
89
120
|
|
|
90
|
-
if(opts.
|
|
121
|
+
if(opts.docker) {
|
|
91
122
|
runDocker(datasource, opts)
|
|
92
123
|
} else {
|
|
93
124
|
runBinary(datasource, opts)
|
|
@@ -95,13 +126,25 @@ module.exports = {
|
|
|
95
126
|
}
|
|
96
127
|
}
|
|
97
128
|
|
|
129
|
+
async function setVersionFromCache(opts) {
|
|
130
|
+
if(filesystem.exists(opts.cachePath) == 'file') {
|
|
131
|
+
let cached = filesystem.read(opts.cachePath, 'json')
|
|
132
|
+
// Get the cache age in days
|
|
133
|
+
let cacheAge = (Date.now() - cached.timestamp) / (1000 * 60 * 60 * 24)
|
|
134
|
+
// If cache age is less than 1 day, use the cached version
|
|
135
|
+
if (cacheAge < 1) {
|
|
136
|
+
opts.latestVersion = cached.version
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
98
141
|
async function runBinary(datasource, opts) {
|
|
99
|
-
let coverageOpt = opts.
|
|
100
|
-
let forceOpt = opts.
|
|
101
|
-
let logsOpt = opts.
|
|
102
|
-
let versionOpt = opts.
|
|
103
|
-
let latestVersion = opts.
|
|
104
|
-
let recompileOpt = opts.
|
|
142
|
+
let coverageOpt = opts.coverage
|
|
143
|
+
let forceOpt = opts.force
|
|
144
|
+
let logsOpt = opts.logs
|
|
145
|
+
let versionOpt = opts.version
|
|
146
|
+
let latestVersion = opts.latestVersion
|
|
147
|
+
let recompileOpt = opts.recompile
|
|
105
148
|
|
|
106
149
|
const platform = await getPlatform(logsOpt)
|
|
107
150
|
|
|
@@ -126,10 +169,10 @@ async function getPlatform(logsOpt) {
|
|
|
126
169
|
const arch = os.arch()
|
|
127
170
|
const cpuCore = os.cpus()[0]
|
|
128
171
|
const isM1 = (arch === 'arm64' && /Apple (M1|processor)/.test(cpuCore.model))
|
|
129
|
-
const linuxInfo = type === 'Linux' ? await getLinuxInfo() :
|
|
130
|
-
const linuxDistro = linuxInfo.
|
|
131
|
-
const release = linuxInfo.
|
|
132
|
-
const majorVersion = parseInt(linuxInfo.
|
|
172
|
+
const linuxInfo = type === 'Linux' ? await getLinuxInfo() : {}
|
|
173
|
+
const linuxDistro = linuxInfo.name
|
|
174
|
+
const release = linuxInfo.version || os.release()
|
|
175
|
+
const majorVersion = parseInt(linuxInfo.version, 10) || semver.major(release)
|
|
133
176
|
|
|
134
177
|
if (logsOpt) {
|
|
135
178
|
print.info(`OS type: ${linuxDistro || type}\nOS arch: ${arch}\nOS release: ${release}\nOS major version: ${majorVersion}\nCPU model: ${cpuCore.model}`)
|
|
@@ -148,6 +191,8 @@ async function getPlatform(logsOpt) {
|
|
|
148
191
|
} else if (type === 'Linux') {
|
|
149
192
|
if (majorVersion === 18) {
|
|
150
193
|
return 'binary-linux-18'
|
|
194
|
+
} if (majorVersion === 22) {
|
|
195
|
+
return 'binary-linux-22'
|
|
151
196
|
} else {
|
|
152
197
|
return 'binary-linux-20'
|
|
153
198
|
}
|
|
@@ -163,13 +208,13 @@ async function getLinuxInfo() {
|
|
|
163
208
|
try {
|
|
164
209
|
let result = await system.run("cat /etc/*-release | grep -E '(^VERSION|^NAME)='", {trim: true})
|
|
165
210
|
let infoArray = result.replace(/['"]+/g, '').split('\n').map(p => p.split('='))
|
|
166
|
-
let
|
|
211
|
+
let linuxInfo = {}
|
|
167
212
|
|
|
168
213
|
infoArray.forEach((val) => {
|
|
169
|
-
|
|
214
|
+
linuxInfo[val[0].toLowerCase()] = val[1]
|
|
170
215
|
});
|
|
171
216
|
|
|
172
|
-
return
|
|
217
|
+
return linuxInfo
|
|
173
218
|
} catch (error) {
|
|
174
219
|
print.error(`Error fetching the Linux version:\n ${error}`)
|
|
175
220
|
process.exit(1)
|
|
@@ -177,39 +222,21 @@ async function getLinuxInfo() {
|
|
|
177
222
|
}
|
|
178
223
|
|
|
179
224
|
async function runDocker(datasource, opts) {
|
|
180
|
-
let coverageOpt = opts.
|
|
181
|
-
let forceOpt = opts.
|
|
182
|
-
let versionOpt = opts.
|
|
183
|
-
let latestVersion = opts.
|
|
184
|
-
let recompileOpt = opts.
|
|
225
|
+
let coverageOpt = opts.coverage
|
|
226
|
+
let forceOpt = opts.force
|
|
227
|
+
let versionOpt = opts.version
|
|
228
|
+
let latestVersion = opts.latestVersion
|
|
229
|
+
let recompileOpt = opts.recompile
|
|
185
230
|
|
|
186
231
|
// Remove binary-install-raw binaries, because docker has permission issues
|
|
187
232
|
// when building the docker images
|
|
188
|
-
await filesystem.remove(
|
|
233
|
+
await filesystem.remove('./node_modules/binary-install-raw/bin')
|
|
189
234
|
|
|
190
235
|
// Get current working directory
|
|
191
236
|
let current_folder = await filesystem.cwd()
|
|
192
237
|
|
|
193
238
|
// Declate dockerfilePath with default location
|
|
194
|
-
let dockerfilePath =
|
|
195
|
-
|
|
196
|
-
// Check if matchstick.yaml config exists
|
|
197
|
-
if(filesystem.exists('matchstick.yaml')) {
|
|
198
|
-
try {
|
|
199
|
-
// Load the config
|
|
200
|
-
let config = await yaml.load(filesystem.read('matchstick.yaml', 'utf8'))
|
|
201
|
-
|
|
202
|
-
// Check if matchstick.yaml is not empty
|
|
203
|
-
if(config != null) {
|
|
204
|
-
// If a custom tests folder is declared update dockerfilePath
|
|
205
|
-
dockerfilePath = path.join(config.testsFolder || 'tests', '.docker/Dockerfile')
|
|
206
|
-
}
|
|
207
|
-
} catch (error) {
|
|
208
|
-
print.info('A problem occurred while reading matchstick.yaml. Please attend to the errors below:')
|
|
209
|
-
print.error(error.message)
|
|
210
|
-
process.exit(1)
|
|
211
|
-
}
|
|
212
|
-
}
|
|
239
|
+
let dockerfilePath = path.join(opts.testsFolder || 'tests', '.docker/Dockerfile')
|
|
213
240
|
|
|
214
241
|
// Check if the Dockerfil already exists
|
|
215
242
|
let dockerfileExists = filesystem.exists(dockerfilePath)
|
|
@@ -7,7 +7,7 @@ const protocol = new Protocol('cosmos')
|
|
|
7
7
|
const scaffoldOptions = {
|
|
8
8
|
protocol,
|
|
9
9
|
network: 'cosmoshub-4',
|
|
10
|
-
|
|
10
|
+
contractName: 'CosmosHub'
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
const scaffold = new Scaffold(scaffoldOptions)
|
|
@@ -33,7 +33,7 @@ dataSources:
|
|
|
33
33
|
- ExampleEntity
|
|
34
34
|
blockHandlers:
|
|
35
35
|
- handler: handleBlock
|
|
36
|
-
file: ./src/
|
|
36
|
+
file: ./src/contract.ts
|
|
37
37
|
`)
|
|
38
38
|
})
|
|
39
39
|
|
|
@@ -76,8 +76,7 @@ const scaffoldOptions = {
|
|
|
76
76
|
abi: TEST_ABI,
|
|
77
77
|
contract: '0xf87e31492faf9a91b02ee0deaad50d51d56d5d4d',
|
|
78
78
|
network: 'kovan',
|
|
79
|
-
contractName: 'Contract'
|
|
80
|
-
dataSourceName: 'Contract'
|
|
79
|
+
contractName: 'Contract'
|
|
81
80
|
}
|
|
82
81
|
|
|
83
82
|
const scaffold = new Scaffold(scaffoldOptions)
|
package/src/scaffold/index.js
CHANGED
|
@@ -26,7 +26,6 @@ module.exports = class Scaffold {
|
|
|
26
26
|
this.network = options.network
|
|
27
27
|
this.contractName = options.contractName
|
|
28
28
|
this.subgraphName = options.subgraphName
|
|
29
|
-
this.dataSourceName = options.dataSourceName
|
|
30
29
|
this.node = options.node
|
|
31
30
|
}
|
|
32
31
|
|
|
@@ -68,7 +67,7 @@ schema:
|
|
|
68
67
|
file: ./schema.graphql
|
|
69
68
|
dataSources:
|
|
70
69
|
- kind: ${this.protocol.name}
|
|
71
|
-
name: ${this.
|
|
70
|
+
name: ${this.contractName}
|
|
72
71
|
network: ${this.network}
|
|
73
72
|
source: ${protocolManifest.source(this)}
|
|
74
73
|
mapping: ${protocolManifest.mapping(this)}
|