@graphprotocol/graph-cli 0.23.0-alpha.0 → 0.24.0-alpha.0
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/README.md +83 -0
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/.travis.yml +4 -0
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/chain/ethereum.ts +10 -16
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/chain/near.ts +402 -0
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/collections.ts +125 -4
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/eager_offset.ts +2 -1
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/json.ts +14 -0
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/numbers.ts +58 -16
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/value.ts +2 -5
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/global/global.ts +108 -0
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/helper-functions.ts +5 -5
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/index.ts +6 -15
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/package.json +5 -2
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/test/bigInt.ts +138 -108
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/test/bytes.ts +31 -20
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/test/test.js +120 -88
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/tsconfig.json +2 -2
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/types/tsconfig.base.json +3 -0
- package/examples/basic-event-handlers/package.json +1 -1
- package/examples/basic-event-handlers/yarn.lock +4 -4
- package/examples/example-subgraph/package.json +1 -1
- package/examples/example-subgraph/yarn.lock +4 -4
- package/jest.config.js +2 -2
- package/package.json +2 -6
- package/src/commands/init.js +31 -3
- package/src/commands/test.js +37 -27
- package/src/migrations/mapping_api_version_0_0_5.js +74 -0
- package/src/scaffold.js +18 -2
- package/tests/cli/globalSetup.js +6 -0
- package/tests/cli/globalTeardown.js +6 -0
- package/tests/cli/init.test.js +1 -1
- package/tests/cli/util.js +17 -8
|
@@ -3,112 +3,142 @@ import { ByteArray, Bytes } from 'temp_lib/index'
|
|
|
3
3
|
|
|
4
4
|
// Test some BigInt methods.
|
|
5
5
|
export function testBigInt(): void {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
6
|
+
let minusFiveBytes = new ByteArray(2)
|
|
7
|
+
minusFiveBytes[0] = 251
|
|
8
|
+
minusFiveBytes[1] = 255
|
|
9
|
+
let minusFive = BigInt.fromSignedBytes(Bytes.fromByteArray(minusFiveBytes))
|
|
10
|
+
assert(minusFive == BigInt.fromI32(-5))
|
|
11
|
+
assert(!minusFive.isZero() && minusFive.isI32())
|
|
12
|
+
assert(minusFiveBytes.toU32() == 65531)
|
|
13
|
+
assert(minusFiveBytes.toI32() == -5)
|
|
14
|
+
|
|
15
|
+
let fiveBytes = new ByteArray(2)
|
|
16
|
+
fiveBytes[0] = 5
|
|
17
|
+
fiveBytes[1] = 0
|
|
18
|
+
let five = BigInt.fromSignedBytes(Bytes.fromByteArray(fiveBytes))
|
|
19
|
+
assert(!five.isZero() && five.isI32())
|
|
20
|
+
assert(five == BigInt.fromI32(5))
|
|
21
|
+
assert(five != minusFive)
|
|
22
|
+
assert(five == BigInt.fromUnsignedBytes(Bytes.fromUint8Array(fiveBytes.subarray(0, 1))))
|
|
23
|
+
assert(fiveBytes.toU32() == 5)
|
|
24
|
+
assert(fiveBytes.toI32() == 5)
|
|
25
|
+
|
|
26
|
+
let x = new ByteArray(1)
|
|
27
|
+
x[0] = 255
|
|
28
|
+
assert(BigInt.fromUnsignedBytes(Bytes.fromByteArray(x)) == BigInt.fromI32(255))
|
|
29
|
+
|
|
30
|
+
let zero = BigInt.fromSignedBytes(Bytes.fromByteArray(new ByteArray(0)))
|
|
31
|
+
assert(zero.isZero() && zero.isI32())
|
|
32
|
+
assert(zero != five)
|
|
33
|
+
assert(zero != minusFive)
|
|
34
|
+
assert(minusFive < zero && minusFive <= zero)
|
|
35
|
+
assert(five > zero && five >= zero)
|
|
36
|
+
|
|
37
|
+
let aI32 = 77123455
|
|
38
|
+
let a = BigInt.fromI32(aI32)
|
|
39
|
+
assert(a == a && a.isI32() && a.toI32() == aI32)
|
|
40
|
+
|
|
41
|
+
let bI32 = 48294181
|
|
42
|
+
let b = BigInt.fromI32(bI32)
|
|
43
|
+
assert(b == b && b.isI32() && b.toI32() == bI32)
|
|
44
|
+
assert(b < a && b <= a)
|
|
45
|
+
|
|
46
|
+
aI32 = 9292928
|
|
47
|
+
a = BigInt.fromI32(9292928)
|
|
48
|
+
assert(a == a && a.isI32() && a.toI32() == aI32)
|
|
49
|
+
assert(a < b && a <= b)
|
|
50
|
+
|
|
51
|
+
bI32 = -9717735
|
|
52
|
+
b = BigInt.fromI32(bI32)
|
|
53
|
+
assert(b == b && b.isI32() && b.toI32() == bI32)
|
|
54
|
+
assert(b < a && b <= a)
|
|
55
|
+
|
|
56
|
+
aI32 = 53499369
|
|
57
|
+
a = BigInt.fromI32(aI32)
|
|
58
|
+
assert(a == a && a.isI32() && a.toI32() == aI32)
|
|
59
|
+
assert(b < a && b <= a)
|
|
60
|
+
|
|
61
|
+
bI32 = 10242178
|
|
62
|
+
b = BigInt.fromI32(bI32)
|
|
63
|
+
assert(b == b && b.isI32() && b.toI32() == bI32)
|
|
64
|
+
assert(b < a && b <= a)
|
|
65
|
+
|
|
66
|
+
a = BigInt.fromI32(1000)
|
|
67
|
+
b = BigInt.fromI32(900)
|
|
68
|
+
assert(b < a && b <= a)
|
|
69
|
+
|
|
70
|
+
a = BigInt.fromI32(123)
|
|
71
|
+
b = BigInt.fromI32(124)
|
|
72
|
+
assert(a < b && a <= b)
|
|
73
|
+
assert(b > a && b >= a)
|
|
74
|
+
|
|
75
|
+
a = BigInt.fromI32(I32.MIN_VALUE)
|
|
76
|
+
b = BigInt.fromI32(I32.MAX_VALUE)
|
|
77
|
+
assert(a < b && a <= b)
|
|
78
|
+
assert(b > a && b >= a)
|
|
79
|
+
assert(a.toI32() == -2147483648)
|
|
80
|
+
assert(b.toI32() == 2147483647)
|
|
81
|
+
|
|
82
|
+
a = BigInt.fromU32(U32.MIN_VALUE)
|
|
83
|
+
b = BigInt.fromU32(U32.MAX_VALUE)
|
|
84
|
+
let c = BigInt.fromU32(0)
|
|
85
|
+
assert(a < b && a <= b, `a: ${a.toU32()}, b: ${b.toU32()}`)
|
|
86
|
+
assert(b > a && b >= a, `a: ${a.toU32()}, b: ${b.toU32()}`)
|
|
87
|
+
assert(a.toU32() == 0, `Actual value ${a.toU32()}`)
|
|
88
|
+
assert(b.toU32() == 4294967295, `Actual value ${b.toU32()}`)
|
|
89
|
+
assert(c.toU32() == 0, `Actual value ${c.toU32()}`)
|
|
90
|
+
|
|
91
|
+
a = BigInt.fromI64(I64.MIN_VALUE)
|
|
92
|
+
b = BigInt.fromI64(I64.MAX_VALUE)
|
|
93
|
+
c = BigInt.fromI64(0)
|
|
94
|
+
assert(a < b && a <= b, `a: ${a.toU64()}, b: ${b.toU64()}`)
|
|
95
|
+
assert(b > a && b >= a, `a: ${a.toU64()}, b: ${b.toU64()}`)
|
|
96
|
+
assert(a.toI64() == -9223372036854775808, `Actual value ${a.toI64()}`)
|
|
97
|
+
assert(b.toI64() == 9223372036854775807, `Actual value ${b.toI64()}`)
|
|
98
|
+
assert(c.toI64() == 0, `Actual value ${c.toI64()}`)
|
|
99
|
+
|
|
100
|
+
a = BigInt.fromU64(U64.MIN_VALUE)
|
|
101
|
+
b = BigInt.fromU64(U64.MAX_VALUE)
|
|
102
|
+
c = BigInt.fromU64(0)
|
|
103
|
+
assert(a < b && a <= b, `a: ${a.toU64()}, b: ${b.toU64()}`)
|
|
104
|
+
assert(b > a && b >= a, `a: ${a.toU64()}, b: ${b.toU64()}`)
|
|
105
|
+
assert(a.toU64() == 0, `Actual value ${a.toU64()}`)
|
|
106
|
+
assert(b.toU64() == 18446744073709551615, `Actual value ${b.toU64()}`)
|
|
107
|
+
assert(c.toU64() == 0, `Actual value ${c.toU64()}`)
|
|
108
|
+
|
|
109
|
+
// This is 8071860 in binary.
|
|
110
|
+
let blockNumber = new ByteArray(3)
|
|
111
|
+
blockNumber[0] = 180
|
|
112
|
+
blockNumber[1] = 42
|
|
113
|
+
blockNumber[2] = 123
|
|
114
|
+
let blockNumberBigInt = BigInt.fromByteArray(blockNumber)
|
|
115
|
+
let latestBlock = BigInt.fromI32(8200001)
|
|
116
|
+
assert(!blockNumberBigInt.gt(latestBlock))
|
|
117
|
+
|
|
118
|
+
let longArray = new ByteArray(5)
|
|
119
|
+
longArray[0] = 251
|
|
120
|
+
longArray[1] = 255
|
|
121
|
+
longArray[2] = 251
|
|
122
|
+
longArray[3] = 255
|
|
123
|
+
longArray[4] = 0
|
|
124
|
+
assert(longArray.toU32() == 4294705147)
|
|
125
|
+
assert(longArray.toI32() == 4294705147)
|
|
126
|
+
|
|
127
|
+
let bytes = Bytes.fromHexString('0x56696b746f726961')
|
|
128
|
+
assert((bytes[0] = 0x56))
|
|
129
|
+
assert((bytes[1] = 0x69))
|
|
130
|
+
assert((bytes[2] = 0x6b))
|
|
131
|
+
assert((bytes[3] = 0x74))
|
|
132
|
+
assert((bytes[4] = 0x6f))
|
|
133
|
+
assert((bytes[5] = 0x72))
|
|
134
|
+
assert((bytes[6] = 0x69))
|
|
135
|
+
assert((bytes[7] = 0x61))
|
|
136
|
+
|
|
137
|
+
assert(ByteArray.fromI32(1) == ByteArray.fromI32(1))
|
|
138
|
+
assert(ByteArray.fromI32(1) != ByteArray.fromI32(2))
|
|
139
|
+
|
|
140
|
+
assert(
|
|
141
|
+
Bytes.fromUTF8('Hello, World!') ==
|
|
142
|
+
ByteArray.fromHexString('0x48656c6c6f2c20576f726c6421'),
|
|
143
|
+
)
|
|
114
144
|
}
|
|
@@ -1,26 +1,37 @@
|
|
|
1
1
|
import { ByteArray, Bytes } from 'temp_lib/index'
|
|
2
2
|
|
|
3
3
|
// Test some Bytes methods.
|
|
4
|
-
export function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
export function testBytesWithByteArray(): void {
|
|
5
|
+
let longArray = new ByteArray(5)
|
|
6
|
+
longArray[0] = 251
|
|
7
|
+
longArray[1] = 255
|
|
8
|
+
longArray[2] = 251
|
|
9
|
+
longArray[3] = 255
|
|
10
|
+
longArray[4] = 0
|
|
11
|
+
assert(longArray.toU32() == 4294705147)
|
|
12
|
+
assert(longArray.toI32() == 4294705147)
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
let bytes = Bytes.fromHexString('0x56696b746f726961')
|
|
15
|
+
assert((bytes[0] = 0x56))
|
|
16
|
+
assert((bytes[1] = 0x69))
|
|
17
|
+
assert((bytes[2] = 0x6b))
|
|
18
|
+
assert((bytes[3] = 0x74))
|
|
19
|
+
assert((bytes[4] = 0x6f))
|
|
20
|
+
assert((bytes[5] = 0x72))
|
|
21
|
+
assert((bytes[6] = 0x69))
|
|
22
|
+
assert((bytes[7] = 0x61))
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
assert(ByteArray.fromI32(1) == ByteArray.fromI32(1))
|
|
25
|
+
assert(ByteArray.fromI32(1) != ByteArray.fromI32(2))
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function testBytesFromUTF8(): void {
|
|
29
|
+
// [123, 32, 34, 104, 101, 108, 108, 111, 34, 58, 32, 34, 119, 111, 114, 108, 100, 34, 32, 125]
|
|
30
|
+
let str = '{ "hello": "world" }'
|
|
31
|
+
|
|
32
|
+
let bytes = Bytes.fromUTF8(str)
|
|
33
|
+
|
|
34
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
35
|
+
assert(bytes[i] == str.charCodeAt(i))
|
|
36
|
+
}
|
|
26
37
|
}
|
|
@@ -1,105 +1,137 @@
|
|
|
1
1
|
const fs = require('fs')
|
|
2
2
|
const asc = require('assemblyscript/cli/asc')
|
|
3
|
+
const path = require('path')
|
|
4
|
+
const { StringDecoder } = require('string_decoder')
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
// index.ts
|
|
6
|
-
|
|
7
|
-
fs.
|
|
8
|
-
|
|
6
|
+
async function main() {
|
|
7
|
+
// Copy index.ts to a temporary subdirectory so that asc doesn't put all the
|
|
8
|
+
// index.ts exports in the global namespace.
|
|
9
|
+
if (!fs.existsSync('test/temp_lib')) {
|
|
10
|
+
fs.mkdirSync('test/temp_lib')
|
|
11
|
+
}
|
|
9
12
|
|
|
10
|
-
if (!fs.existsSync('test/temp_out')) {
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
+
if (!fs.existsSync('test/temp_out')) {
|
|
14
|
+
fs.mkdirSync('test/temp_out')
|
|
15
|
+
}
|
|
13
16
|
|
|
14
|
-
if (!fs.existsSync('test/temp_lib/chain')) {
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
+
if (!fs.existsSync('test/temp_lib/chain')) {
|
|
18
|
+
fs.mkdirSync('test/temp_lib/chain')
|
|
19
|
+
}
|
|
17
20
|
|
|
18
|
-
if (!fs.existsSync('test/temp_lib/common')) {
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
+
if (!fs.existsSync('test/temp_lib/common')) {
|
|
22
|
+
fs.mkdirSync('test/temp_lib/common')
|
|
23
|
+
}
|
|
21
24
|
|
|
22
|
-
fs.copyFileSync('common/
|
|
23
|
-
fs.copyFileSync('common/
|
|
24
|
-
fs.copyFileSync('common/
|
|
25
|
-
fs.copyFileSync('common/
|
|
26
|
-
fs.copyFileSync('common/
|
|
27
|
-
fs.copyFileSync('common/
|
|
28
|
-
fs.copyFileSync('common/value.ts', 'test/temp_lib/common/value.ts')
|
|
29
|
-
fs.copyFileSync('chain/ethereum.ts', 'test/temp_lib/chain/ethereum.ts')
|
|
30
|
-
fs.copyFileSync('
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
console.log('aborted')
|
|
36
|
-
console.log('message', message)
|
|
37
|
-
console.log('fileName', fileName)
|
|
38
|
-
console.log('lineNumber', lineNumber)
|
|
39
|
-
console.log('columnNumber', columnNumber)
|
|
40
|
-
},
|
|
41
|
-
}
|
|
25
|
+
fs.copyFileSync('common/collections.ts', 'test/temp_lib/common/collections.ts')
|
|
26
|
+
fs.copyFileSync('common/conversion.ts', 'test/temp_lib/common/conversion.ts')
|
|
27
|
+
fs.copyFileSync('common/datasource.ts', 'test/temp_lib/common/datasource.ts')
|
|
28
|
+
fs.copyFileSync('common/eager_offset.ts', 'test/temp_lib/common/eager_offset.ts')
|
|
29
|
+
fs.copyFileSync('common/json.ts', 'test/temp_lib/common/json.ts')
|
|
30
|
+
fs.copyFileSync('common/numbers.ts', 'test/temp_lib/common/numbers.ts')
|
|
31
|
+
fs.copyFileSync('common/value.ts', 'test/temp_lib/common/value.ts')
|
|
32
|
+
fs.copyFileSync('chain/ethereum.ts', 'test/temp_lib/chain/ethereum.ts')
|
|
33
|
+
fs.copyFileSync('chain/near.ts', 'test/temp_lib/chain/near.ts')
|
|
34
|
+
fs.copyFileSync('index.ts', 'test/temp_lib/index.ts')
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
const outputWasmPath = 'test/temp_out/test.wasm'
|
|
42
38
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
fs.rmdirSync('test/temp_lib/chain')
|
|
77
|
-
fs.rmdirSync('test/temp_lib')
|
|
78
|
-
fs.unlinkSync('test/temp_out/test.wasm')
|
|
79
|
-
fs.rmdirSync('test/temp_out')
|
|
80
|
-
throw e
|
|
39
|
+
const promises = {}
|
|
40
|
+
promises['bigInt'] = testFile('test/bigInt.ts', outputWasmPath)
|
|
41
|
+
promises['bytes'] = testFile('test/bytes.ts', outputWasmPath)
|
|
42
|
+
promises['entity'] = testFile('test/entity.ts', outputWasmPath)
|
|
43
|
+
|
|
44
|
+
const entries = Object.entries(promises)
|
|
45
|
+
const results = await Promise.allSettled(entries.map((entry) => entry[1]))
|
|
46
|
+
const failures = Object.fromEntries(
|
|
47
|
+
results
|
|
48
|
+
.map((result, index) => [entries[index][0], result])
|
|
49
|
+
.filter(([index, result]) => result.status === 'rejected'),
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
if (Object.keys(failures).length > 0) {
|
|
53
|
+
throw failures
|
|
54
|
+
}
|
|
55
|
+
} finally {
|
|
56
|
+
fs.unlinkSync('test/temp_lib/common/collections.ts')
|
|
57
|
+
fs.unlinkSync('test/temp_lib/common/conversion.ts')
|
|
58
|
+
fs.unlinkSync('test/temp_lib/common/datasource.ts')
|
|
59
|
+
fs.unlinkSync('test/temp_lib/common/eager_offset.ts')
|
|
60
|
+
fs.unlinkSync('test/temp_lib/common/json.ts')
|
|
61
|
+
fs.unlinkSync('test/temp_lib/common/numbers.ts')
|
|
62
|
+
fs.unlinkSync('test/temp_lib/common/value.ts')
|
|
63
|
+
fs.rmdirSync('test/temp_lib/common')
|
|
64
|
+
fs.unlinkSync('test/temp_lib/chain/ethereum.ts')
|
|
65
|
+
fs.unlinkSync('test/temp_lib/chain/near.ts')
|
|
66
|
+
fs.rmdirSync('test/temp_lib/chain')
|
|
67
|
+
fs.unlinkSync('test/temp_lib/index.ts')
|
|
68
|
+
fs.rmdirSync('test/temp_lib')
|
|
69
|
+
fs.unlinkSync('test/temp_out/test.wasm')
|
|
70
|
+
fs.rmdirSync('test/temp_out')
|
|
71
|
+
}
|
|
81
72
|
}
|
|
82
73
|
|
|
83
|
-
function testFile(
|
|
84
|
-
|
|
85
|
-
|
|
74
|
+
async function testFile(sourceFile, outputWasmPath) {
|
|
75
|
+
console.log(`Compiling test file ${sourceFile} to WASM...`)
|
|
76
|
+
if (
|
|
77
|
+
asc.main([
|
|
78
|
+
'--explicitStart',
|
|
79
|
+
'--exportRuntime',
|
|
80
|
+
'--importMemory',
|
|
81
|
+
'--runtime',
|
|
82
|
+
'stub',
|
|
83
|
+
sourceFile,
|
|
84
|
+
'--lib',
|
|
85
|
+
'test',
|
|
86
|
+
'-b',
|
|
87
|
+
outputWasmPath,
|
|
88
|
+
]) != 0
|
|
89
|
+
) {
|
|
90
|
+
throw Error('Failed to compile')
|
|
86
91
|
}
|
|
87
|
-
let test_wasm = new Uint8Array(fs.readFileSync(output_path))
|
|
88
92
|
|
|
89
|
-
|
|
90
|
-
|
|
93
|
+
const wasmCode = new Uint8Array(fs.readFileSync(outputWasmPath))
|
|
94
|
+
const memory = new WebAssembly.Memory({ initial: 1, maximum: 1 })
|
|
95
|
+
const module = await WebAssembly.instantiate(wasmCode, {
|
|
96
|
+
env: {
|
|
97
|
+
memory,
|
|
98
|
+
abort: function (messagePtr, fileNamePtr, lineNumber, columnNumber) {
|
|
99
|
+
let fileSource = path.join(__dirname, '..', sourceFile)
|
|
100
|
+
let message = 'assertion failure'
|
|
101
|
+
if (messagePtr !== 0) {
|
|
102
|
+
message += `: ${getString(memory, messagePtr)}`
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
throw new Error(`${message} (${fileSource}:${lineNumber}:${columnNumber})`)
|
|
106
|
+
},
|
|
107
|
+
},
|
|
91
108
|
conversion: {
|
|
92
109
|
'typeConversion.bytesToHex': function () {},
|
|
93
110
|
},
|
|
94
|
-
}).then((module) => {
|
|
95
|
-
// Call AS start explicitly
|
|
96
|
-
module.instance.exports._start()
|
|
97
|
-
|
|
98
|
-
for (const [testName, testFn] of Object.entries(module.instance.exports)) {
|
|
99
|
-
if (typeof testFn === 'function' && testName.startsWith('test')) {
|
|
100
|
-
console.log(`Running "${testName}"...`)
|
|
101
|
-
testFn()
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
111
|
})
|
|
112
|
+
|
|
113
|
+
// Call AS start explicitly
|
|
114
|
+
module.instance.exports._start()
|
|
115
|
+
|
|
116
|
+
console.log(`Running "${sourceFile}" tests...`)
|
|
117
|
+
for (const [testName, testFn] of Object.entries(module.instance.exports)) {
|
|
118
|
+
if (typeof testFn === 'function' && testName.startsWith('test')) {
|
|
119
|
+
console.log(`Running "${testName}"...`)
|
|
120
|
+
testFn()
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function getString(memory, addr) {
|
|
126
|
+
let byteCount = Buffer.from(new Uint8Array(memory.buffer, addr - 4, 4)).readInt32LE()
|
|
127
|
+
let buffer = new Uint8Array(memory.buffer, addr, byteCount)
|
|
128
|
+
let encoder = new StringDecoder('utf16le')
|
|
129
|
+
|
|
130
|
+
return encoder.write(buffer)
|
|
105
131
|
}
|
|
132
|
+
|
|
133
|
+
main().catch((error) => {
|
|
134
|
+
console.error('Test suite failed', error)
|
|
135
|
+
|
|
136
|
+
process.exit(1)
|
|
137
|
+
})
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"deploy-test": "../../bin/graph deploy test/basic-event-handlers --version-label v0.0.1 --ipfs http://localhost:15001 --node http://127.0.0.1:18020"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"@graphprotocol/graph-ts": "0.
|
|
12
|
+
"@graphprotocol/graph-ts": "0.24.0-alpha.0",
|
|
13
13
|
"apollo-fetch": "^0.7.0"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
# yarn lockfile v1
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
"@graphprotocol/graph-ts@0.
|
|
6
|
-
version "0.
|
|
7
|
-
resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.
|
|
8
|
-
integrity sha512-
|
|
5
|
+
"@graphprotocol/graph-ts@0.24.0-alpha.0":
|
|
6
|
+
version "0.24.0-alpha.0"
|
|
7
|
+
resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.24.0-alpha.0.tgz#8fe2b09a123adc5a65c82b823a1cb2d99f3cce2b"
|
|
8
|
+
integrity sha512-PLhTMlFMoLZpTqJlKH5f+5VRN3yWmXfssVwWk7uauVeY8IuAWjWB3RNubS574q9uf0QjPKOacekXY5EKRWOzEA==
|
|
9
9
|
dependencies:
|
|
10
10
|
assemblyscript "0.19.10"
|
|
11
11
|
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
# yarn lockfile v1
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
"@graphprotocol/graph-ts@0.
|
|
6
|
-
version "0.
|
|
7
|
-
resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.
|
|
8
|
-
integrity sha512-
|
|
5
|
+
"@graphprotocol/graph-ts@0.24.0-alpha.0":
|
|
6
|
+
version "0.24.0-alpha.0"
|
|
7
|
+
resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.24.0-alpha.0.tgz#8fe2b09a123adc5a65c82b823a1cb2d99f3cce2b"
|
|
8
|
+
integrity sha512-PLhTMlFMoLZpTqJlKH5f+5VRN3yWmXfssVwWk7uauVeY8IuAWjWB3RNubS574q9uf0QjPKOacekXY5EKRWOzEA==
|
|
9
9
|
dependencies:
|
|
10
10
|
assemblyscript "0.19.10"
|
|
11
11
|
|
package/jest.config.js
CHANGED
|
@@ -49,10 +49,10 @@ module.exports = {
|
|
|
49
49
|
// forceCoverageMatch: [],
|
|
50
50
|
|
|
51
51
|
// A path to a module which exports an async function that is triggered once before all test suites
|
|
52
|
-
|
|
52
|
+
globalSetup: './tests/cli/globalSetup',
|
|
53
53
|
|
|
54
54
|
// A path to a module which exports an async function that is triggered once after all test suites
|
|
55
|
-
|
|
55
|
+
globalTeardown: './tests/cli/globalTeardown',
|
|
56
56
|
|
|
57
57
|
// A set of global variables that need to be available in all test environments
|
|
58
58
|
// globals: {},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphprotocol/graph-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0-alpha.0",
|
|
4
4
|
"description": "CLI for building for and deploying to The Graph",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"assemblyscript": "0.19.10",
|
|
@@ -40,10 +40,6 @@
|
|
|
40
40
|
"scripts": {
|
|
41
41
|
"test": "jest --verbose",
|
|
42
42
|
"test:init": "jest tests/cli/init.test.js --verbose",
|
|
43
|
-
"test:validation": "jest tests/cli/validation.test.js --verbose"
|
|
44
|
-
"release:patch": "npm version patch && npm publish && git push origin master && git push --tags",
|
|
45
|
-
"release:minor": "npm version minor && npm publish && git push origin master && git push --tags",
|
|
46
|
-
"release:alpha:minor": "npm version preminor --preid alpha && npm publish --tag alpha && git push origin master && git push --tags",
|
|
47
|
-
"release:alpha:prerelease": "npm version prerelease --preid alpha && npm publish --tag alpha && git push origin master && git push --tags"
|
|
43
|
+
"test:validation": "jest tests/cli/validation.test.js --verbose"
|
|
48
44
|
}
|
|
49
45
|
}
|