@graphprotocol/graph-cli 0.37.4 → 0.37.5
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/dist/bin.js +6 -0
- package/dist/cli.js +26 -0
- package/dist/codegen/schema.js +244 -0
- package/dist/codegen/schema.test.js +455 -0
- package/dist/codegen/template.js +66 -0
- package/dist/codegen/types/conversions.js +335 -0
- package/dist/codegen/types/index.js +71 -0
- package/dist/codegen/types/index.test.js +563 -0
- package/dist/codegen/typescript.js +200 -0
- package/dist/codegen/util.js +40 -0
- package/dist/codegen/util.test.js +93 -0
- package/dist/command-helpers/abi.js +76 -0
- package/dist/command-helpers/auth.js +76 -0
- package/dist/command-helpers/compiler.js +66 -0
- package/dist/command-helpers/data-sources.js +29 -0
- package/dist/command-helpers/fs.js +9 -0
- package/dist/command-helpers/gluegun.js +48 -0
- package/dist/command-helpers/ipfs.js +5 -0
- package/dist/command-helpers/jsonrpc.js +27 -0
- package/dist/command-helpers/network.js +90 -0
- package/dist/command-helpers/network.test.js +86 -0
- package/dist/command-helpers/node.js +40 -0
- package/dist/command-helpers/scaffold.js +110 -0
- package/dist/command-helpers/spinner.js +80 -0
- package/dist/command-helpers/studio.js +14 -0
- package/dist/command-helpers/studio.test.js +41 -0
- package/dist/command-helpers/subgraph.js +22 -0
- package/dist/command-helpers/version.js +66 -0
- package/dist/command-helpers/version.test.js +186 -0
- package/dist/commands/add.js +187 -0
- package/dist/commands/auth.js +122 -0
- package/dist/commands/build.js +136 -0
- package/dist/commands/codegen.js +128 -0
- package/dist/commands/create.js +94 -0
- package/dist/commands/deploy.js +335 -0
- package/dist/commands/init.js +800 -0
- package/dist/commands/local.js +380 -0
- package/dist/commands/remove.js +95 -0
- package/dist/commands/test.js +293 -0
- package/dist/compiler/asc.js +83 -0
- package/dist/compiler/index.js +466 -0
- package/dist/debug.js +16 -0
- package/dist/migrations/mapping_api_version_0_0_1.js +83 -0
- package/dist/migrations/mapping_api_version_0_0_2.js +83 -0
- package/dist/migrations/mapping_api_version_0_0_3.js +83 -0
- package/dist/migrations/mapping_api_version_0_0_4.js +85 -0
- package/dist/migrations/mapping_api_version_0_0_5.js +85 -0
- package/dist/migrations/spec_version_0_0_2.js +45 -0
- package/dist/migrations/spec_version_0_0_3.js +50 -0
- package/dist/migrations/util/load-manifest.js +16 -0
- package/dist/migrations/util/versions.js +28 -0
- package/dist/migrations.js +54 -0
- package/dist/protocols/arweave/manifest.graphql +57 -0
- package/dist/protocols/arweave/scaffold/manifest.js +18 -0
- package/dist/protocols/arweave/scaffold/mapping.js +52 -0
- package/dist/protocols/arweave/subgraph.js +23 -0
- package/dist/protocols/contract.js +2 -0
- package/dist/protocols/cosmos/manifest.graphql +76 -0
- package/dist/protocols/cosmos/scaffold/manifest.js +15 -0
- package/dist/protocols/cosmos/scaffold/mapping.js +38 -0
- package/dist/protocols/cosmos/subgraph.js +28 -0
- package/dist/protocols/ethereum/abi.js +138 -0
- package/dist/protocols/ethereum/codegen/abi.js +474 -0
- package/dist/protocols/ethereum/codegen/abi.test.js +325 -0
- package/dist/protocols/ethereum/codegen/template.js +52 -0
- package/dist/protocols/ethereum/contract.js +22 -0
- package/dist/protocols/ethereum/manifest.graphql +94 -0
- package/dist/protocols/ethereum/scaffold/manifest.js +32 -0
- package/dist/protocols/ethereum/scaffold/mapping.js +65 -0
- package/dist/protocols/ethereum/subgraph.js +172 -0
- package/dist/protocols/ethereum/type-generator.js +123 -0
- package/dist/protocols/index.js +266 -0
- package/dist/protocols/ipfs/codegen/file_template.js +53 -0
- package/dist/protocols/near/contract.js +41 -0
- package/dist/protocols/near/manifest.graphql +64 -0
- package/dist/protocols/near/scaffold/manifest.js +16 -0
- package/dist/protocols/near/scaffold/mapping.js +38 -0
- package/dist/protocols/near/subgraph.js +23 -0
- package/dist/protocols/subgraph.js +2 -0
- package/dist/protocols/substreams/manifest.graphql +45 -0
- package/dist/protocols/substreams/scaffold/manifest.js +12 -0
- package/dist/protocols/substreams/subgraph.js +23 -0
- package/dist/scaffold/cosmos.test.js +82 -0
- package/dist/scaffold/ethereum.test.js +496 -0
- package/dist/scaffold/index.js +133 -0
- package/dist/scaffold/mapping.js +57 -0
- package/dist/scaffold/near.test.js +85 -0
- package/dist/scaffold/schema.js +86 -0
- package/dist/scaffold/tests.js +179 -0
- package/dist/schema.js +54 -0
- package/dist/subgraph.js +243 -0
- package/dist/type-generator.js +225 -0
- package/dist/validation/contract.js +44 -0
- package/dist/validation/index.js +10 -0
- package/dist/validation/manifest.js +266 -0
- package/dist/validation/schema.js +768 -0
- package/dist/validation/schema.test.js +35 -0
- package/dist/watcher.js +79 -0
- package/package.json +1 -1
|
@@ -0,0 +1,563 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const codegen = __importStar(require("."));
|
|
27
|
+
describe('ethereum.Value -> AssemblyScript', () => {
|
|
28
|
+
// Scalar values
|
|
29
|
+
test('address -> Address', () => {
|
|
30
|
+
expect(codegen.ethereumToAsc('x', 'address')).toBe('x.toAddress()');
|
|
31
|
+
expect(codegen.ascTypeForEthereum('address')).toBe('Address');
|
|
32
|
+
});
|
|
33
|
+
test('bool -> boolean', () => {
|
|
34
|
+
expect(codegen.ethereumToAsc('x', 'bool')).toBe('x.toBoolean()');
|
|
35
|
+
expect(codegen.ascTypeForEthereum('bool')).toBe('boolean');
|
|
36
|
+
});
|
|
37
|
+
test('byte -> Bytes', () => {
|
|
38
|
+
expect(codegen.ethereumToAsc('x', 'byte')).toBe('x.toBytes()');
|
|
39
|
+
expect(codegen.ascTypeForEthereum('byte')).toBe('Bytes');
|
|
40
|
+
});
|
|
41
|
+
test('bytes -> Bytes', () => {
|
|
42
|
+
expect(codegen.ethereumToAsc('x', 'bytes')).toBe('x.toBytes()');
|
|
43
|
+
expect(codegen.ascTypeForEthereum('bytes')).toBe('Bytes');
|
|
44
|
+
});
|
|
45
|
+
test('bytes0 (invalid)', () => {
|
|
46
|
+
expect(() => codegen.ethereumToAsc('x', 'bytes0')).toThrow();
|
|
47
|
+
expect(() => codegen.ascTypeForEthereum('bytes0')).toThrow();
|
|
48
|
+
});
|
|
49
|
+
test('bytes1..32 -> Bytes', () => {
|
|
50
|
+
for (let i = 1; i <= 32; i++) {
|
|
51
|
+
expect(codegen.ethereumToAsc('x', `bytes${i}`)).toBe('x.toBytes()');
|
|
52
|
+
expect(codegen.ascTypeForEthereum(`bytes${i}`)).toBe('Bytes');
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
test('bytes33 (invalid)', () => {
|
|
56
|
+
expect(() => codegen.ethereumToAsc('x', 'bytes33')).toThrow();
|
|
57
|
+
expect(() => codegen.ascTypeForEthereum('bytes33')).toThrow();
|
|
58
|
+
});
|
|
59
|
+
test('int8..32, uint8..uint24 -> i32', () => {
|
|
60
|
+
for (let i = 8; i <= 32; i += 8) {
|
|
61
|
+
expect(codegen.ethereumToAsc('x', `int${i}`)).toBe('x.toI32()');
|
|
62
|
+
expect(codegen.ascTypeForEthereum(`int${i}`)).toBe('i32');
|
|
63
|
+
}
|
|
64
|
+
for (let i = 8; i <= 24; i += 8) {
|
|
65
|
+
expect(codegen.ethereumToAsc('x', `uint${i}`)).toBe('x.toI32()');
|
|
66
|
+
expect(codegen.ascTypeForEthereum(`uint${i}`)).toBe('i32');
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
test('uint32 -> BigInt', () => {
|
|
70
|
+
expect(codegen.ethereumToAsc('x', `uint32`)).toBe('x.toBigInt()');
|
|
71
|
+
expect(codegen.ascTypeForEthereum('uint32')).toBe('BigInt');
|
|
72
|
+
});
|
|
73
|
+
test('(u)int40..256 -> BigInt', () => {
|
|
74
|
+
for (let i = 40; i <= 256; i += 8) {
|
|
75
|
+
expect(codegen.ethereumToAsc('x', `int${i}`)).toBe('x.toBigInt()');
|
|
76
|
+
expect(codegen.ethereumToAsc('x', `uint${i}`)).toBe('x.toBigInt()');
|
|
77
|
+
expect(codegen.ascTypeForEthereum(`int${i}`)).toBe('BigInt');
|
|
78
|
+
expect(codegen.ascTypeForEthereum(`uint${i}`)).toBe('BigInt');
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
test('string -> String', () => {
|
|
82
|
+
expect(codegen.ethereumToAsc('x', 'string')).toBe('x.toString()');
|
|
83
|
+
expect(codegen.ascTypeForEthereum('string')).toBe('string');
|
|
84
|
+
});
|
|
85
|
+
// Array values
|
|
86
|
+
test('address[*] -> Array<Address>', () => {
|
|
87
|
+
expect(codegen.ethereumToAsc('x', 'address[]')).toBe('x.toAddressArray()');
|
|
88
|
+
expect(codegen.ethereumToAsc('x', 'address[1]')).toBe('x.toAddressArray()');
|
|
89
|
+
expect(codegen.ethereumToAsc('x', 'address[123]')).toBe('x.toAddressArray()');
|
|
90
|
+
expect(codegen.ascTypeForEthereum('address[]')).toBe('Array<Address>');
|
|
91
|
+
expect(codegen.ascTypeForEthereum('address[1]')).toBe('Array<Address>');
|
|
92
|
+
expect(codegen.ascTypeForEthereum('address[123]')).toBe('Array<Address>');
|
|
93
|
+
});
|
|
94
|
+
test('bool[*] -> Array<boolean>', () => {
|
|
95
|
+
expect(codegen.ethereumToAsc('x', 'bool[]')).toBe('x.toBooleanArray()');
|
|
96
|
+
expect(codegen.ethereumToAsc('x', 'bool[5]')).toBe('x.toBooleanArray()');
|
|
97
|
+
expect(codegen.ethereumToAsc('x', 'bool[275]')).toBe('x.toBooleanArray()');
|
|
98
|
+
expect(codegen.ascTypeForEthereum('bool[]')).toBe('Array<boolean>');
|
|
99
|
+
expect(codegen.ascTypeForEthereum('bool[5]')).toBe('Array<boolean>');
|
|
100
|
+
expect(codegen.ascTypeForEthereum('bool[275]')).toBe('Array<boolean>');
|
|
101
|
+
});
|
|
102
|
+
test('byte[*] -> Array<Bytes>', () => {
|
|
103
|
+
expect(codegen.ethereumToAsc('x', 'byte[]')).toBe('x.toBytesArray()');
|
|
104
|
+
expect(codegen.ethereumToAsc('x', 'byte[7]')).toBe('x.toBytesArray()');
|
|
105
|
+
expect(codegen.ethereumToAsc('x', 'byte[553]')).toBe('x.toBytesArray()');
|
|
106
|
+
expect(codegen.ascTypeForEthereum('byte[]')).toBe('Array<Bytes>');
|
|
107
|
+
expect(codegen.ascTypeForEthereum('byte[7]')).toBe('Array<Bytes>');
|
|
108
|
+
expect(codegen.ascTypeForEthereum('byte[553]')).toBe('Array<Bytes>');
|
|
109
|
+
});
|
|
110
|
+
test('bytes[*] -> Array<Bytes>', () => {
|
|
111
|
+
expect(codegen.ethereumToAsc('x', 'bytes[]')).toBe('x.toBytesArray()');
|
|
112
|
+
expect(codegen.ethereumToAsc('x', 'bytes[14]')).toBe('x.toBytesArray()');
|
|
113
|
+
expect(codegen.ethereumToAsc('x', 'bytes[444]')).toBe('x.toBytesArray()');
|
|
114
|
+
expect(codegen.ascTypeForEthereum('bytes[]')).toBe('Array<Bytes>');
|
|
115
|
+
expect(codegen.ascTypeForEthereum('bytes[14]')).toBe('Array<Bytes>');
|
|
116
|
+
expect(codegen.ascTypeForEthereum('bytes[444]')).toBe('Array<Bytes>');
|
|
117
|
+
});
|
|
118
|
+
test('bytes0[*] (invalid)', () => {
|
|
119
|
+
expect(() => codegen.ethereumToAsc('x', 'bytes0[]')).toThrow();
|
|
120
|
+
expect(() => codegen.ethereumToAsc('x', 'bytes0[83]')).toThrow();
|
|
121
|
+
expect(() => codegen.ethereumToAsc('x', 'bytes0[123]')).toThrow();
|
|
122
|
+
expect(() => codegen.ascTypeForEthereum('bytes0[]')).toThrow();
|
|
123
|
+
expect(() => codegen.ascTypeForEthereum('bytes0[83]')).toThrow();
|
|
124
|
+
expect(() => codegen.ascTypeForEthereum('bytes0[123]')).toThrow();
|
|
125
|
+
});
|
|
126
|
+
test('bytes1..32[*] -> Array<Bytes>', () => {
|
|
127
|
+
for (let i = 1; i <= 32; i++) {
|
|
128
|
+
expect(codegen.ethereumToAsc('x', `bytes${i}[]`)).toBe('x.toBytesArray()');
|
|
129
|
+
expect(codegen.ethereumToAsc('x', `bytes${i}[7]`)).toBe('x.toBytesArray()');
|
|
130
|
+
expect(codegen.ethereumToAsc('x', `bytes${i}[432]`)).toBe('x.toBytesArray()');
|
|
131
|
+
expect(codegen.ascTypeForEthereum(`bytes${i}[]`)).toBe('Array<Bytes>');
|
|
132
|
+
expect(codegen.ascTypeForEthereum(`bytes${i}[7]`)).toBe('Array<Bytes>');
|
|
133
|
+
expect(codegen.ascTypeForEthereum(`bytes${i}[432]`)).toBe('Array<Bytes>');
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
test('bytes33[*] (invalid)', () => {
|
|
137
|
+
expect(() => codegen.ethereumToAsc('x', 'bytes33[]')).toThrow();
|
|
138
|
+
expect(() => codegen.ethereumToAsc('x', 'bytes33[58]')).toThrow();
|
|
139
|
+
expect(() => codegen.ethereumToAsc('x', 'bytes33[394]')).toThrow();
|
|
140
|
+
expect(() => codegen.ascTypeForEthereum('bytes33[]')).toThrow();
|
|
141
|
+
expect(() => codegen.ascTypeForEthereum('bytes33[58]')).toThrow();
|
|
142
|
+
expect(() => codegen.ascTypeForEthereum('bytes33[394]')).toThrow();
|
|
143
|
+
});
|
|
144
|
+
test('int8..32[*], uint8..24[*] -> Array<i32>', () => {
|
|
145
|
+
for (let i = 8; i <= 32; i += 8) {
|
|
146
|
+
expect(codegen.ethereumToAsc('x', `int${i}[]`)).toBe('x.toI32Array()');
|
|
147
|
+
expect(codegen.ethereumToAsc('x', `int${i}[6]`)).toBe('x.toI32Array()');
|
|
148
|
+
expect(codegen.ethereumToAsc('x', `int${i}[4638]`)).toBe('x.toI32Array()');
|
|
149
|
+
expect(codegen.ascTypeForEthereum(`int${i}[]`)).toBe('Array<i32>');
|
|
150
|
+
expect(codegen.ascTypeForEthereum(`int${i}[6]`)).toBe('Array<i32>');
|
|
151
|
+
expect(codegen.ascTypeForEthereum(`int${i}[4638]`)).toBe('Array<i32>');
|
|
152
|
+
}
|
|
153
|
+
for (let i = 8; i <= 24; i += 8) {
|
|
154
|
+
expect(codegen.ethereumToAsc('x', `uint${i}[]`)).toBe('x.toI32Array()');
|
|
155
|
+
expect(codegen.ethereumToAsc('x', `uint${i}[6]`)).toBe('x.toI32Array()');
|
|
156
|
+
expect(codegen.ethereumToAsc('x', `uint${i}[593]`)).toBe('x.toI32Array()');
|
|
157
|
+
expect(codegen.ascTypeForEthereum(`uint${i}[]`)).toBe('Array<i32>');
|
|
158
|
+
expect(codegen.ascTypeForEthereum(`uint${i}[6]`)).toBe('Array<i32>');
|
|
159
|
+
expect(codegen.ascTypeForEthereum(`uint${i}[593]`)).toBe('Array<i32>');
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
test('uint32[*] -> Array<BigInt>', () => {
|
|
163
|
+
expect(codegen.ethereumToAsc('x', `uint32[]`)).toBe('x.toBigIntArray()');
|
|
164
|
+
expect(codegen.ethereumToAsc('x', `uint32[6]`)).toBe('x.toBigIntArray()');
|
|
165
|
+
expect(codegen.ethereumToAsc('x', `uint32[593]`)).toBe('x.toBigIntArray()');
|
|
166
|
+
expect(codegen.ascTypeForEthereum(`uint32[]`)).toBe('Array<BigInt>');
|
|
167
|
+
expect(codegen.ascTypeForEthereum(`uint32[6]`)).toBe('Array<BigInt>');
|
|
168
|
+
expect(codegen.ascTypeForEthereum(`uint32[593]`)).toBe('Array<BigInt>');
|
|
169
|
+
});
|
|
170
|
+
test('(u)int40..256[*] -> Array<BigInt>', () => {
|
|
171
|
+
for (let i = 40; i <= 256; i += 8) {
|
|
172
|
+
expect(codegen.ethereumToAsc('x', `int${i}[]`)).toBe('x.toBigIntArray()');
|
|
173
|
+
expect(codegen.ethereumToAsc('x', `int${i}[7]`)).toBe('x.toBigIntArray()');
|
|
174
|
+
expect(codegen.ethereumToAsc('x', `int${i}[6833]`)).toBe('x.toBigIntArray()');
|
|
175
|
+
expect(codegen.ascTypeForEthereum(`int${i}[]`)).toBe('Array<BigInt>');
|
|
176
|
+
expect(codegen.ascTypeForEthereum(`int${i}[7]`)).toBe('Array<BigInt>');
|
|
177
|
+
expect(codegen.ascTypeForEthereum(`int${i}[6833]`)).toBe('Array<BigInt>');
|
|
178
|
+
expect(codegen.ethereumToAsc('x', `uint${i}[]`)).toBe('x.toBigIntArray()');
|
|
179
|
+
expect(codegen.ethereumToAsc('x', `uint${i}[23]`)).toBe('x.toBigIntArray()');
|
|
180
|
+
expect(codegen.ethereumToAsc('x', `uint${i}[467]`)).toBe('x.toBigIntArray()');
|
|
181
|
+
expect(codegen.ascTypeForEthereum(`uint${i}[]`)).toBe('Array<BigInt>');
|
|
182
|
+
expect(codegen.ascTypeForEthereum(`uint${i}[23]`)).toBe('Array<BigInt>');
|
|
183
|
+
expect(codegen.ascTypeForEthereum(`uint${i}[467]`)).toBe('Array<BigInt>');
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
test('string[*] -> Array<string>', () => {
|
|
187
|
+
expect(codegen.ethereumToAsc('x', 'string[]')).toBe('x.toStringArray()');
|
|
188
|
+
expect(codegen.ethereumToAsc('x', 'string[4]')).toBe('x.toStringArray()');
|
|
189
|
+
expect(codegen.ethereumToAsc('x', 'string[754]')).toBe('x.toStringArray()');
|
|
190
|
+
expect(codegen.ascTypeForEthereum('string[]')).toBe('Array<string>');
|
|
191
|
+
expect(codegen.ascTypeForEthereum('string[4]')).toBe('Array<string>');
|
|
192
|
+
expect(codegen.ascTypeForEthereum('string[754]')).toBe('Array<string>');
|
|
193
|
+
});
|
|
194
|
+
// Multi dimensional arrays
|
|
195
|
+
test('address[*][*] -> Array<Array<Address>>', () => {
|
|
196
|
+
expect(codegen.ethereumToAsc('x', 'address[][]')).toBe('x.toAddressMatrix()');
|
|
197
|
+
expect(codegen.ethereumToAsc('x', 'address[5][]')).toBe('x.toAddressMatrix()');
|
|
198
|
+
expect(codegen.ethereumToAsc('x', 'address[][4]')).toBe('x.toAddressMatrix()');
|
|
199
|
+
expect(codegen.ethereumToAsc('x', 'address[1][2]')).toBe('x.toAddressMatrix()');
|
|
200
|
+
expect(codegen.ethereumToAsc('x', 'address[123][321]')).toBe('x.toAddressMatrix()');
|
|
201
|
+
expect(codegen.ascTypeForEthereum('address[][]')).toBe('Array<Array<Address>>');
|
|
202
|
+
expect(codegen.ascTypeForEthereum('address[5][]')).toBe('Array<Array<Address>>');
|
|
203
|
+
expect(codegen.ascTypeForEthereum('address[][4]')).toBe('Array<Array<Address>>');
|
|
204
|
+
expect(codegen.ascTypeForEthereum('address[1][2]')).toBe('Array<Array<Address>>');
|
|
205
|
+
expect(codegen.ascTypeForEthereum('address[123][321]')).toBe('Array<Array<Address>>');
|
|
206
|
+
});
|
|
207
|
+
test('bool[*][*] -> Array<Array<boolean>>', () => {
|
|
208
|
+
expect(codegen.ethereumToAsc('x', 'bool[][]')).toBe('x.toBooleanMatrix()');
|
|
209
|
+
expect(codegen.ethereumToAsc('x', 'bool[1][]')).toBe('x.toBooleanMatrix()');
|
|
210
|
+
expect(codegen.ethereumToAsc('x', 'bool[][3]')).toBe('x.toBooleanMatrix()');
|
|
211
|
+
expect(codegen.ethereumToAsc('x', 'bool[5][2]')).toBe('x.toBooleanMatrix()');
|
|
212
|
+
expect(codegen.ethereumToAsc('x', 'bool[275][572]')).toBe('x.toBooleanMatrix()');
|
|
213
|
+
expect(codegen.ascTypeForEthereum('bool[][]')).toBe('Array<Array<boolean>>');
|
|
214
|
+
expect(codegen.ascTypeForEthereum('bool[1][]')).toBe('Array<Array<boolean>>');
|
|
215
|
+
expect(codegen.ascTypeForEthereum('bool[][3]')).toBe('Array<Array<boolean>>');
|
|
216
|
+
expect(codegen.ascTypeForEthereum('bool[5][2]')).toBe('Array<Array<boolean>>');
|
|
217
|
+
expect(codegen.ascTypeForEthereum('bool[275][572]')).toBe('Array<Array<boolean>>');
|
|
218
|
+
});
|
|
219
|
+
test('byte[*][*] -> Array<Array<Bytes>>', () => {
|
|
220
|
+
expect(codegen.ethereumToAsc('x', 'byte[][]')).toBe('x.toBytesMatrix()');
|
|
221
|
+
expect(codegen.ethereumToAsc('x', 'byte[7][]')).toBe('x.toBytesMatrix()');
|
|
222
|
+
expect(codegen.ethereumToAsc('x', 'byte[][8]')).toBe('x.toBytesMatrix()');
|
|
223
|
+
expect(codegen.ethereumToAsc('x', 'byte[553][355]')).toBe('x.toBytesMatrix()');
|
|
224
|
+
expect(codegen.ascTypeForEthereum('byte[][]')).toBe('Array<Array<Bytes>>');
|
|
225
|
+
expect(codegen.ascTypeForEthereum('byte[7][]')).toBe('Array<Array<Bytes>>');
|
|
226
|
+
expect(codegen.ascTypeForEthereum('byte[][8]')).toBe('Array<Array<Bytes>>');
|
|
227
|
+
expect(codegen.ascTypeForEthereum('byte[553][355]')).toBe('Array<Array<Bytes>>');
|
|
228
|
+
});
|
|
229
|
+
test('bytes[*][*] -> Array<Array<Bytes>>', () => {
|
|
230
|
+
expect(codegen.ethereumToAsc('x', 'bytes[][]')).toBe('x.toBytesMatrix()');
|
|
231
|
+
expect(codegen.ethereumToAsc('x', 'bytes[14][]')).toBe('x.toBytesMatrix()');
|
|
232
|
+
expect(codegen.ethereumToAsc('x', 'bytes[][41]')).toBe('x.toBytesMatrix()');
|
|
233
|
+
expect(codegen.ethereumToAsc('x', 'bytes[444][555]')).toBe('x.toBytesMatrix()');
|
|
234
|
+
expect(codegen.ascTypeForEthereum('bytes[][]')).toBe('Array<Array<Bytes>>');
|
|
235
|
+
expect(codegen.ascTypeForEthereum('bytes[14][]')).toBe('Array<Array<Bytes>>');
|
|
236
|
+
expect(codegen.ascTypeForEthereum('bytes[][41]')).toBe('Array<Array<Bytes>>');
|
|
237
|
+
expect(codegen.ascTypeForEthereum('bytes[444][555]')).toBe('Array<Array<Bytes>>');
|
|
238
|
+
});
|
|
239
|
+
test('bytes0[*][*] (invalid)', () => {
|
|
240
|
+
expect(() => codegen.ethereumToAsc('x', 'bytes0[][]')).toThrow();
|
|
241
|
+
expect(() => codegen.ethereumToAsc('x', 'bytes0[83][]')).toThrow();
|
|
242
|
+
expect(() => codegen.ethereumToAsc('x', 'bytes0[][83]')).toThrow();
|
|
243
|
+
expect(() => codegen.ethereumToAsc('x', 'bytes0[123][321]')).toThrow();
|
|
244
|
+
expect(() => codegen.ascTypeForEthereum('bytes0[][]')).toThrow();
|
|
245
|
+
expect(() => codegen.ascTypeForEthereum('bytes0[83][]')).toThrow();
|
|
246
|
+
expect(() => codegen.ascTypeForEthereum('bytes0[][83]')).toThrow();
|
|
247
|
+
expect(() => codegen.ascTypeForEthereum('bytes0[123][321]')).toThrow();
|
|
248
|
+
});
|
|
249
|
+
test('bytes1..32[*][*] -> Array<Array<Bytes>>', () => {
|
|
250
|
+
for (let i = 1; i <= 32; i++) {
|
|
251
|
+
expect(codegen.ethereumToAsc('x', `bytes${i}[][]`)).toBe('x.toBytesMatrix()');
|
|
252
|
+
expect(codegen.ethereumToAsc('x', `bytes${i}[7][]`)).toBe('x.toBytesMatrix()');
|
|
253
|
+
expect(codegen.ethereumToAsc('x', `bytes${i}[][7]`)).toBe('x.toBytesMatrix()');
|
|
254
|
+
expect(codegen.ethereumToAsc('x', `bytes${i}[432][234]`)).toBe('x.toBytesMatrix()');
|
|
255
|
+
expect(codegen.ascTypeForEthereum(`bytes${i}[][]`)).toBe('Array<Array<Bytes>>');
|
|
256
|
+
expect(codegen.ascTypeForEthereum(`bytes${i}[6][]`)).toBe('Array<Array<Bytes>>');
|
|
257
|
+
expect(codegen.ascTypeForEthereum(`bytes${i}[][7]`)).toBe('Array<Array<Bytes>>');
|
|
258
|
+
expect(codegen.ascTypeForEthereum(`bytes${i}[432][234]`)).toBe('Array<Array<Bytes>>');
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
test('bytes33[*][*] (invalid)', () => {
|
|
262
|
+
expect(() => codegen.ethereumToAsc('x', 'bytes33[][]')).toThrow();
|
|
263
|
+
expect(() => codegen.ethereumToAsc('x', 'bytes33[58][]')).toThrow();
|
|
264
|
+
expect(() => codegen.ethereumToAsc('x', 'bytes33[][85]')).toThrow();
|
|
265
|
+
expect(() => codegen.ethereumToAsc('x', 'bytes33[394][493]')).toThrow();
|
|
266
|
+
expect(() => codegen.ascTypeForEthereum('bytes33[][]')).toThrow();
|
|
267
|
+
expect(() => codegen.ascTypeForEthereum('bytes33[58][]')).toThrow();
|
|
268
|
+
expect(() => codegen.ascTypeForEthereum('bytes33[][85]')).toThrow();
|
|
269
|
+
expect(() => codegen.ascTypeForEthereum('bytes33[394][493]')).toThrow();
|
|
270
|
+
});
|
|
271
|
+
test('int8..32[*][*], uint8..24[*][*] -> Array<Array<i32>>', () => {
|
|
272
|
+
for (let i = 8; i <= 32; i += 8) {
|
|
273
|
+
expect(codegen.ethereumToAsc('x', `int${i}[][]`)).toBe('x.toI32Matrix()');
|
|
274
|
+
expect(codegen.ethereumToAsc('x', `int${i}[6][]`)).toBe('x.toI32Matrix()');
|
|
275
|
+
expect(codegen.ethereumToAsc('x', `int${i}[][6]`)).toBe('x.toI32Matrix()');
|
|
276
|
+
expect(codegen.ethereumToAsc('x', `int${i}[4638][8364]`)).toBe('x.toI32Matrix()');
|
|
277
|
+
expect(codegen.ascTypeForEthereum(`int${i}[][]`)).toBe('Array<Array<i32>>');
|
|
278
|
+
expect(codegen.ascTypeForEthereum(`int${i}[6][]`)).toBe('Array<Array<i32>>');
|
|
279
|
+
expect(codegen.ascTypeForEthereum(`int${i}[][6]`)).toBe('Array<Array<i32>>');
|
|
280
|
+
expect(codegen.ascTypeForEthereum(`int${i}[4638][8364]`)).toBe('Array<Array<i32>>');
|
|
281
|
+
}
|
|
282
|
+
for (let i = 8; i <= 24; i += 8) {
|
|
283
|
+
expect(codegen.ethereumToAsc('x', `uint${i}[][]`)).toBe('x.toI32Matrix()');
|
|
284
|
+
expect(codegen.ethereumToAsc('x', `uint${i}[6][]`)).toBe('x.toI32Matrix()');
|
|
285
|
+
expect(codegen.ethereumToAsc('x', `uint${i}[][6]`)).toBe('x.toI32Matrix()');
|
|
286
|
+
expect(codegen.ethereumToAsc('x', `uint${i}[593][395]`)).toBe('x.toI32Matrix()');
|
|
287
|
+
expect(codegen.ascTypeForEthereum(`uint${i}[][]`)).toBe('Array<Array<i32>>');
|
|
288
|
+
expect(codegen.ascTypeForEthereum(`uint${i}[6][]`)).toBe('Array<Array<i32>>');
|
|
289
|
+
expect(codegen.ascTypeForEthereum(`uint${i}[][6]`)).toBe('Array<Array<i32>>');
|
|
290
|
+
expect(codegen.ascTypeForEthereum(`uint${i}[593][395]`)).toBe('Array<Array<i32>>');
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
test('uint32[*][*] -> Array<Array<BigInt>>', () => {
|
|
294
|
+
expect(codegen.ethereumToAsc('x', `uint32[][]`)).toBe('x.toBigIntMatrix()');
|
|
295
|
+
expect(codegen.ethereumToAsc('x', `uint32[6][]`)).toBe('x.toBigIntMatrix()');
|
|
296
|
+
expect(codegen.ethereumToAsc('x', `uint32[][6]`)).toBe('x.toBigIntMatrix()');
|
|
297
|
+
expect(codegen.ethereumToAsc('x', `uint32[593][395]`)).toBe('x.toBigIntMatrix()');
|
|
298
|
+
expect(codegen.ascTypeForEthereum(`uint32[][]`)).toBe('Array<Array<BigInt>>');
|
|
299
|
+
expect(codegen.ascTypeForEthereum(`uint32[6][]`)).toBe('Array<Array<BigInt>>');
|
|
300
|
+
expect(codegen.ascTypeForEthereum(`uint32[][5]`)).toBe('Array<Array<BigInt>>');
|
|
301
|
+
expect(codegen.ascTypeForEthereum(`uint32[593][395]`)).toBe('Array<Array<BigInt>>');
|
|
302
|
+
});
|
|
303
|
+
test('(u)int40..256[*][*] -> Array<Array<BigInt>>', () => {
|
|
304
|
+
for (let i = 40; i <= 256; i += 8) {
|
|
305
|
+
expect(codegen.ethereumToAsc('x', `int${i}[][]`)).toBe('x.toBigIntMatrix()');
|
|
306
|
+
expect(codegen.ethereumToAsc('x', `int${i}[7][]`)).toBe('x.toBigIntMatrix()');
|
|
307
|
+
expect(codegen.ethereumToAsc('x', `int${i}[][7]`)).toBe('x.toBigIntMatrix()');
|
|
308
|
+
expect(codegen.ethereumToAsc('x', `int${i}[6833][3386]`)).toBe('x.toBigIntMatrix()');
|
|
309
|
+
expect(codegen.ascTypeForEthereum(`int${i}[][]`)).toBe('Array<Array<BigInt>>');
|
|
310
|
+
expect(codegen.ascTypeForEthereum(`int${i}[7][]`)).toBe('Array<Array<BigInt>>');
|
|
311
|
+
expect(codegen.ascTypeForEthereum(`int${i}[][7]`)).toBe('Array<Array<BigInt>>');
|
|
312
|
+
expect(codegen.ascTypeForEthereum(`int${i}[6833][3386]`)).toBe('Array<Array<BigInt>>');
|
|
313
|
+
expect(codegen.ethereumToAsc('x', `uint${i}[][]`)).toBe('x.toBigIntMatrix()');
|
|
314
|
+
expect(codegen.ethereumToAsc('x', `uint${i}[23][]`)).toBe('x.toBigIntMatrix()');
|
|
315
|
+
expect(codegen.ethereumToAsc('x', `uint${i}[][32]`)).toBe('x.toBigIntMatrix()');
|
|
316
|
+
expect(codegen.ethereumToAsc('x', `uint${i}[467][764]`)).toBe('x.toBigIntMatrix()');
|
|
317
|
+
expect(codegen.ascTypeForEthereum(`uint${i}[][]`)).toBe('Array<Array<BigInt>>');
|
|
318
|
+
expect(codegen.ascTypeForEthereum(`uint${i}[23][]`)).toBe('Array<Array<BigInt>>');
|
|
319
|
+
expect(codegen.ascTypeForEthereum(`uint${i}[][32]`)).toBe('Array<Array<BigInt>>');
|
|
320
|
+
expect(codegen.ascTypeForEthereum(`uint${i}[467][764]`)).toBe('Array<Array<BigInt>>');
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
test('string[*][*] -> Array<Array<string>>', () => {
|
|
324
|
+
expect(codegen.ethereumToAsc('x', 'string[][]')).toBe('x.toStringMatrix()');
|
|
325
|
+
expect(codegen.ethereumToAsc('x', 'string[4][]')).toBe('x.toStringMatrix()');
|
|
326
|
+
expect(codegen.ethereumToAsc('x', 'string[][3]')).toBe('x.toStringMatrix()');
|
|
327
|
+
expect(codegen.ethereumToAsc('x', 'string[754][457]')).toBe('x.toStringMatrix()');
|
|
328
|
+
expect(codegen.ascTypeForEthereum('string[][]')).toBe('Array<Array<string>>');
|
|
329
|
+
expect(codegen.ascTypeForEthereum('string[4][]')).toBe('Array<Array<string>>');
|
|
330
|
+
expect(codegen.ascTypeForEthereum('string[][3]')).toBe('Array<Array<string>>');
|
|
331
|
+
expect(codegen.ascTypeForEthereum('string[754][457]')).toBe('Array<Array<string>>');
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
describe('AssemblyScript -> ethereum.Value', () => {
|
|
335
|
+
// Scalar values
|
|
336
|
+
test('Address -> address', () => {
|
|
337
|
+
expect(codegen.ethereumFromAsc('x', 'address')).toBe('ethereum.Value.fromAddress(x)');
|
|
338
|
+
});
|
|
339
|
+
test('boolean -> bool', () => {
|
|
340
|
+
expect(codegen.ethereumFromAsc('x', 'bool')).toBe('ethereum.Value.fromBoolean(x)');
|
|
341
|
+
});
|
|
342
|
+
test('Bytes -> byte', () => {
|
|
343
|
+
expect(codegen.ethereumFromAsc('x', 'byte')).toBe('ethereum.Value.fromFixedBytes(x)');
|
|
344
|
+
});
|
|
345
|
+
test('Bytes -> bytes', () => {
|
|
346
|
+
expect(codegen.ethereumFromAsc('x', 'bytes')).toBe('ethereum.Value.fromBytes(x)');
|
|
347
|
+
});
|
|
348
|
+
test('Bytes -> bytes0 (invalid)', () => {
|
|
349
|
+
expect(() => codegen.ethereumFromAsc('x', 'bytes0')).toThrow();
|
|
350
|
+
});
|
|
351
|
+
test('Bytes -> bytes1..32', () => {
|
|
352
|
+
for (let i = 1; i <= 32; i++) {
|
|
353
|
+
expect(codegen.ethereumFromAsc('x', `bytes${i}`)).toBe('ethereum.Value.fromFixedBytes(x)');
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
test('Bytes -> bytes33 (invalid)', () => {
|
|
357
|
+
expect(() => codegen.ethereumFromAsc('x', 'bytes33')).toThrow();
|
|
358
|
+
});
|
|
359
|
+
test('i32 -> int8..32, uint8..24', () => {
|
|
360
|
+
for (let i = 8; i <= 32; i += 8) {
|
|
361
|
+
expect(codegen.ethereumFromAsc('x', `int${i}`)).toBe(`ethereum.Value.fromI32(x)`);
|
|
362
|
+
}
|
|
363
|
+
for (let i = 8; i <= 24; i += 8) {
|
|
364
|
+
expect(codegen.ethereumFromAsc('x', `uint${i}`)).toBe(`ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(x))`);
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
test('BigInt -> uint32', () => {
|
|
368
|
+
expect(codegen.ethereumFromAsc('x', `uint32`)).toBe(`ethereum.Value.fromUnsignedBigInt(x)`);
|
|
369
|
+
});
|
|
370
|
+
test('BigInt -> (u)int40..256', () => {
|
|
371
|
+
for (let i = 40; i <= 256; i += 8) {
|
|
372
|
+
expect(codegen.ethereumFromAsc('x', `int${i}`)).toBe(`ethereum.Value.fromSignedBigInt(x)`);
|
|
373
|
+
expect(codegen.ethereumFromAsc('x', `uint${i}`)).toBe(`ethereum.Value.fromUnsignedBigInt(x)`);
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
test('String -> string', () => {
|
|
377
|
+
expect(codegen.ethereumFromAsc('x', 'string')).toBe('ethereum.Value.fromString(x)');
|
|
378
|
+
});
|
|
379
|
+
// Array values
|
|
380
|
+
test('Array<Address> -> address[*]', () => {
|
|
381
|
+
expect(codegen.ethereumFromAsc('x', 'address[]')).toBe('ethereum.Value.fromAddressArray(x)');
|
|
382
|
+
expect(codegen.ethereumFromAsc('x', 'address[1]')).toBe('ethereum.Value.fromAddressArray(x)');
|
|
383
|
+
expect(codegen.ethereumFromAsc('x', 'address[123]')).toBe('ethereum.Value.fromAddressArray(x)');
|
|
384
|
+
});
|
|
385
|
+
test('Array<boolean> -> bool[*]', () => {
|
|
386
|
+
expect(codegen.ethereumFromAsc('x', 'bool[]')).toBe('ethereum.Value.fromBooleanArray(x)');
|
|
387
|
+
expect(codegen.ethereumFromAsc('x', 'bool[5]')).toBe('ethereum.Value.fromBooleanArray(x)');
|
|
388
|
+
expect(codegen.ethereumFromAsc('x', 'bool[275]')).toBe('ethereum.Value.fromBooleanArray(x)');
|
|
389
|
+
});
|
|
390
|
+
test('Array<Bytes> -> byte[*]', () => {
|
|
391
|
+
expect(codegen.ethereumFromAsc('x', 'byte[]')).toBe('ethereum.Value.fromFixedBytesArray(x)');
|
|
392
|
+
expect(codegen.ethereumFromAsc('x', 'byte[7]')).toBe('ethereum.Value.fromFixedBytesArray(x)');
|
|
393
|
+
expect(codegen.ethereumFromAsc('x', 'byte[553]')).toBe('ethereum.Value.fromFixedBytesArray(x)');
|
|
394
|
+
});
|
|
395
|
+
test('Array<Bytes> -> bytes[*]', () => {
|
|
396
|
+
expect(codegen.ethereumFromAsc('x', 'bytes[]')).toBe('ethereum.Value.fromBytesArray(x)');
|
|
397
|
+
expect(codegen.ethereumFromAsc('x', 'bytes[14]')).toBe('ethereum.Value.fromBytesArray(x)');
|
|
398
|
+
expect(codegen.ethereumFromAsc('x', 'bytes[444]')).toBe('ethereum.Value.fromBytesArray(x)');
|
|
399
|
+
});
|
|
400
|
+
test('bytes0[*] (invalid)', () => {
|
|
401
|
+
expect(() => codegen.ethereumFromAsc('x', 'bytes0[]')).toThrow();
|
|
402
|
+
expect(() => codegen.ethereumFromAsc('x', 'bytes0[83]')).toThrow();
|
|
403
|
+
expect(() => codegen.ethereumFromAsc('x', 'bytes0[123]')).toThrow();
|
|
404
|
+
});
|
|
405
|
+
test('Array<Bytes> -> bytes1..32[*]', () => {
|
|
406
|
+
for (let i = 1; i <= 32; i++) {
|
|
407
|
+
expect(codegen.ethereumFromAsc('x', `bytes${i}[]`)).toBe('ethereum.Value.fromFixedBytesArray(x)');
|
|
408
|
+
expect(codegen.ethereumFromAsc('x', `bytes${i}[7]`)).toBe('ethereum.Value.fromFixedBytesArray(x)');
|
|
409
|
+
expect(codegen.ethereumFromAsc('x', `bytes${i}[432]`)).toBe('ethereum.Value.fromFixedBytesArray(x)');
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
test('bytes33[*] (invalid)', () => {
|
|
413
|
+
expect(() => codegen.ethereumFromAsc('x', 'bytes33[]')).toThrow();
|
|
414
|
+
expect(() => codegen.ethereumFromAsc('x', 'bytes33[58]')).toThrow();
|
|
415
|
+
expect(() => codegen.ethereumFromAsc('x', 'bytes33[394]')).toThrow();
|
|
416
|
+
});
|
|
417
|
+
test('Array<i32> -> int8..32[*], uint8..24[*]', () => {
|
|
418
|
+
for (let i = 8; i <= 32; i += 8) {
|
|
419
|
+
expect(codegen.ethereumFromAsc('x', `int${i}[]`)).toBe('ethereum.Value.fromI32Array(x)');
|
|
420
|
+
expect(codegen.ethereumFromAsc('x', `int${i}[6]`)).toBe('ethereum.Value.fromI32Array(x)');
|
|
421
|
+
expect(codegen.ethereumFromAsc('x', `int${i}[4638]`)).toBe('ethereum.Value.fromI32Array(x)');
|
|
422
|
+
}
|
|
423
|
+
for (let i = 8; i <= 24; i += 8) {
|
|
424
|
+
expect(codegen.ethereumFromAsc('x', `uint${i}[]`)).toBe('ethereum.Value.fromI32Array(x)');
|
|
425
|
+
expect(codegen.ethereumFromAsc('x', `uint${i}[6]`)).toBe('ethereum.Value.fromI32Array(x)');
|
|
426
|
+
expect(codegen.ethereumFromAsc('x', `uint${i}[593]`)).toBe('ethereum.Value.fromI32Array(x)');
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
test('Array<BigInt> -> uint32[*]', () => {
|
|
430
|
+
expect(codegen.ethereumFromAsc('x', `uint32[]`)).toBe('ethereum.Value.fromUnsignedBigIntArray(x)');
|
|
431
|
+
expect(codegen.ethereumFromAsc('x', `uint32[6]`)).toBe('ethereum.Value.fromUnsignedBigIntArray(x)');
|
|
432
|
+
expect(codegen.ethereumFromAsc('x', `uint32[593]`)).toBe('ethereum.Value.fromUnsignedBigIntArray(x)');
|
|
433
|
+
});
|
|
434
|
+
test('Array<BigInt> -> (u)int40..256[*]', () => {
|
|
435
|
+
for (let i = 40; i <= 256; i += 8) {
|
|
436
|
+
expect(codegen.ethereumFromAsc('x', `int${i}[]`)).toBe('ethereum.Value.fromSignedBigIntArray(x)');
|
|
437
|
+
expect(codegen.ethereumFromAsc('x', `int${i}[7]`)).toBe('ethereum.Value.fromSignedBigIntArray(x)');
|
|
438
|
+
expect(codegen.ethereumFromAsc('x', `int${i}[6833]`)).toBe('ethereum.Value.fromSignedBigIntArray(x)');
|
|
439
|
+
expect(codegen.ethereumFromAsc('x', `uint${i}[]`)).toBe('ethereum.Value.fromUnsignedBigIntArray(x)');
|
|
440
|
+
expect(codegen.ethereumFromAsc('x', `uint${i}[23]`)).toBe('ethereum.Value.fromUnsignedBigIntArray(x)');
|
|
441
|
+
expect(codegen.ethereumFromAsc('x', `uint${i}[467]`)).toBe('ethereum.Value.fromUnsignedBigIntArray(x)');
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
test('Array<String> -> string[*]', () => {
|
|
445
|
+
expect(codegen.ethereumFromAsc('x', 'string[]')).toBe('ethereum.Value.fromStringArray(x)');
|
|
446
|
+
expect(codegen.ethereumFromAsc('x', 'string[4]')).toBe('ethereum.Value.fromStringArray(x)');
|
|
447
|
+
expect(codegen.ethereumFromAsc('x', 'string[754]')).toBe('ethereum.Value.fromStringArray(x)');
|
|
448
|
+
});
|
|
449
|
+
// Multidimensional arrays
|
|
450
|
+
test('Array<Array<Address>> -> address[*][*]', () => {
|
|
451
|
+
expect(codegen.ethereumFromAsc('x', 'address[][]')).toBe('ethereum.Value.fromAddressMatrix(x)');
|
|
452
|
+
expect(codegen.ethereumFromAsc('x', 'address[1][]')).toBe('ethereum.Value.fromAddressMatrix(x)');
|
|
453
|
+
expect(codegen.ethereumFromAsc('x', 'address[][2]')).toBe('ethereum.Value.fromAddressMatrix(x)');
|
|
454
|
+
expect(codegen.ethereumFromAsc('x', 'address[123][321]')).toBe('ethereum.Value.fromAddressMatrix(x)');
|
|
455
|
+
});
|
|
456
|
+
test('Array<Array<boolean>> -> bool[*][*]', () => {
|
|
457
|
+
expect(codegen.ethereumFromAsc('x', 'bool[][]')).toBe('ethereum.Value.fromBooleanMatrix(x)');
|
|
458
|
+
expect(codegen.ethereumFromAsc('x', 'bool[5][]')).toBe('ethereum.Value.fromBooleanMatrix(x)');
|
|
459
|
+
expect(codegen.ethereumFromAsc('x', 'bool[][5]')).toBe('ethereum.Value.fromBooleanMatrix(x)');
|
|
460
|
+
expect(codegen.ethereumFromAsc('x', 'bool[275][572]')).toBe('ethereum.Value.fromBooleanMatrix(x)');
|
|
461
|
+
});
|
|
462
|
+
test('Array<Array<Bytes>> -> byte[*][*]', () => {
|
|
463
|
+
expect(codegen.ethereumFromAsc('x', 'byte[][]')).toBe('ethereum.Value.fromFixedBytesMatrix(x)');
|
|
464
|
+
expect(codegen.ethereumFromAsc('x', 'byte[7][]')).toBe('ethereum.Value.fromFixedBytesMatrix(x)');
|
|
465
|
+
expect(codegen.ethereumFromAsc('x', 'byte[][6]')).toBe('ethereum.Value.fromFixedBytesMatrix(x)');
|
|
466
|
+
expect(codegen.ethereumFromAsc('x', 'byte[553][355]')).toBe('ethereum.Value.fromFixedBytesMatrix(x)');
|
|
467
|
+
});
|
|
468
|
+
test('Array<Array<Bytes>> -> bytes[*][*]', () => {
|
|
469
|
+
expect(codegen.ethereumFromAsc('x', 'bytes[][]')).toBe('ethereum.Value.fromBytesMatrix(x)');
|
|
470
|
+
expect(codegen.ethereumFromAsc('x', 'bytes[14][]')).toBe('ethereum.Value.fromBytesMatrix(x)');
|
|
471
|
+
expect(codegen.ethereumFromAsc('x', 'bytes[][41]')).toBe('ethereum.Value.fromBytesMatrix(x)');
|
|
472
|
+
expect(codegen.ethereumFromAsc('x', 'bytes[444][333]')).toBe('ethereum.Value.fromBytesMatrix(x)');
|
|
473
|
+
});
|
|
474
|
+
test('bytes0[*][*] (invalid)', () => {
|
|
475
|
+
expect(() => codegen.ethereumFromAsc('x', 'bytes0[][]')).toThrow();
|
|
476
|
+
expect(() => codegen.ethereumFromAsc('x', 'bytes0[83][]')).toThrow();
|
|
477
|
+
expect(() => codegen.ethereumFromAsc('x', 'bytes0[][38]')).toThrow();
|
|
478
|
+
expect(() => codegen.ethereumFromAsc('x', 'bytes0[123][321]')).toThrow();
|
|
479
|
+
});
|
|
480
|
+
test('Array<Array<Bytes>> -> bytes1..32[*][*]', () => {
|
|
481
|
+
for (let i = 1; i <= 32; i++) {
|
|
482
|
+
expect(codegen.ethereumFromAsc('x', `bytes${i}[][]`)).toBe('ethereum.Value.fromFixedBytesMatrix(x)');
|
|
483
|
+
expect(codegen.ethereumFromAsc('x', `bytes${i}[7][]`)).toBe('ethereum.Value.fromFixedBytesMatrix(x)');
|
|
484
|
+
expect(codegen.ethereumFromAsc('x', `bytes${i}[][7]`)).toBe('ethereum.Value.fromFixedBytesMatrix(x)');
|
|
485
|
+
expect(codegen.ethereumFromAsc('x', `bytes${i}[432][234]`)).toBe('ethereum.Value.fromFixedBytesMatrix(x)');
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
test('bytes33[*][*] (invalid)', () => {
|
|
489
|
+
expect(() => codegen.ethereumFromAsc('x', 'bytes33[][]')).toThrow();
|
|
490
|
+
expect(() => codegen.ethereumFromAsc('x', 'bytes33[58][]')).toThrow();
|
|
491
|
+
expect(() => codegen.ethereumFromAsc('x', 'bytes33[][85]')).toThrow();
|
|
492
|
+
expect(() => codegen.ethereumFromAsc('x', 'bytes33[394][493]')).toThrow();
|
|
493
|
+
});
|
|
494
|
+
test('Array<Array<i32>> -> int8..32[*][*], uint8..24[*][*]', () => {
|
|
495
|
+
for (let i = 8; i <= 32; i += 8) {
|
|
496
|
+
expect(codegen.ethereumFromAsc('x', `int${i}[][]`)).toBe('ethereum.Value.fromI32Matrix(x)');
|
|
497
|
+
expect(codegen.ethereumFromAsc('x', `int${i}[6][]`)).toBe('ethereum.Value.fromI32Matrix(x)');
|
|
498
|
+
expect(codegen.ethereumFromAsc('x', `int${i}[][5]`)).toBe('ethereum.Value.fromI32Matrix(x)');
|
|
499
|
+
expect(codegen.ethereumFromAsc('x', `int${i}[4638][8364]`)).toBe('ethereum.Value.fromI32Matrix(x)');
|
|
500
|
+
}
|
|
501
|
+
for (let i = 8; i <= 24; i += 8) {
|
|
502
|
+
expect(codegen.ethereumFromAsc('x', `uint${i}[][]`)).toBe('ethereum.Value.fromI32Matrix(x)');
|
|
503
|
+
expect(codegen.ethereumFromAsc('x', `uint${i}[6][]`)).toBe('ethereum.Value.fromI32Matrix(x)');
|
|
504
|
+
expect(codegen.ethereumFromAsc('x', `uint${i}[][5]`)).toBe('ethereum.Value.fromI32Matrix(x)');
|
|
505
|
+
expect(codegen.ethereumFromAsc('x', `uint${i}[593][395]`)).toBe('ethereum.Value.fromI32Matrix(x)');
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
test('Array<Array<BigInt>> -> uint32[*][*]', () => {
|
|
509
|
+
expect(codegen.ethereumFromAsc('x', `uint32[][]`)).toBe('ethereum.Value.fromUnsignedBigIntMatrix(x)');
|
|
510
|
+
expect(codegen.ethereumFromAsc('x', `uint32[6][]`)).toBe('ethereum.Value.fromUnsignedBigIntMatrix(x)');
|
|
511
|
+
expect(codegen.ethereumFromAsc('x', `uint32[][5]`)).toBe('ethereum.Value.fromUnsignedBigIntMatrix(x)');
|
|
512
|
+
expect(codegen.ethereumFromAsc('x', `uint32[593][395]`)).toBe('ethereum.Value.fromUnsignedBigIntMatrix(x)');
|
|
513
|
+
});
|
|
514
|
+
test('Array<Array<BigInt>> -> (u)int40..256[*][*]', () => {
|
|
515
|
+
for (let i = 40; i <= 256; i += 8) {
|
|
516
|
+
expect(codegen.ethereumFromAsc('x', `int${i}[][]`)).toBe('ethereum.Value.fromSignedBigIntMatrix(x)');
|
|
517
|
+
expect(codegen.ethereumFromAsc('x', `int${i}[8][]`)).toBe('ethereum.Value.fromSignedBigIntMatrix(x)');
|
|
518
|
+
expect(codegen.ethereumFromAsc('x', `int${i}[][7]`)).toBe('ethereum.Value.fromSignedBigIntMatrix(x)');
|
|
519
|
+
expect(codegen.ethereumFromAsc('x', `int${i}[6833][3386]`)).toBe('ethereum.Value.fromSignedBigIntMatrix(x)');
|
|
520
|
+
expect(codegen.ethereumFromAsc('x', `uint${i}[][]`)).toBe('ethereum.Value.fromUnsignedBigIntMatrix(x)');
|
|
521
|
+
expect(codegen.ethereumFromAsc('x', `uint${i}[23][]`)).toBe('ethereum.Value.fromUnsignedBigIntMatrix(x)');
|
|
522
|
+
expect(codegen.ethereumFromAsc('x', `uint${i}[][32]`)).toBe('ethereum.Value.fromUnsignedBigIntMatrix(x)');
|
|
523
|
+
expect(codegen.ethereumFromAsc('x', `uint${i}[467][764]`)).toBe('ethereum.Value.fromUnsignedBigIntMatrix(x)');
|
|
524
|
+
}
|
|
525
|
+
});
|
|
526
|
+
test('Array<Array<String>> -> string[*][*]', () => {
|
|
527
|
+
expect(codegen.ethereumFromAsc('x', 'string[]')).toBe('ethereum.Value.fromStringArray(x)');
|
|
528
|
+
expect(codegen.ethereumFromAsc('x', 'string[4]')).toBe('ethereum.Value.fromStringArray(x)');
|
|
529
|
+
expect(codegen.ethereumFromAsc('x', 'string[754]')).toBe('ethereum.Value.fromStringArray(x)');
|
|
530
|
+
});
|
|
531
|
+
});
|
|
532
|
+
describe('Value -> AssemblyScript', () => {
|
|
533
|
+
test('BigDecimal -> BigDecimal', () => {
|
|
534
|
+
expect(codegen.valueToAsc('x', 'BigDecimal')).toBe('x.toBigDecimal()');
|
|
535
|
+
});
|
|
536
|
+
test('[BigDecimal] -> Array<BigDecimal>', () => {
|
|
537
|
+
expect(codegen.valueToAsc('x', '[BigDecimal]')).toBe('x.toBigDecimalArray()');
|
|
538
|
+
});
|
|
539
|
+
test('String -> string', () => {
|
|
540
|
+
expect(codegen.valueToAsc('x', 'string')).toBe('x.toString()');
|
|
541
|
+
});
|
|
542
|
+
test('[String] -> Array<string>', () => {
|
|
543
|
+
expect(codegen.valueToAsc('x', '[String]')).toBe('x.toStringArray()');
|
|
544
|
+
});
|
|
545
|
+
});
|
|
546
|
+
describe('AssemblyScript -> Value', () => {
|
|
547
|
+
test('BigDecimal -> BigDecimal', () => {
|
|
548
|
+
expect(codegen.valueFromAsc('x', 'BigDecimal')).toBe('Value.fromBigDecimal(x)');
|
|
549
|
+
expect(codegen.valueTypeForAsc('BigDecimal')).toBe('BigDecimal');
|
|
550
|
+
});
|
|
551
|
+
test('Array<BigDecimal> -> [BigDecimal]', () => {
|
|
552
|
+
expect(codegen.valueFromAsc('x', '[BigDecimal]')).toBe('Value.fromBigDecimalArray(x)');
|
|
553
|
+
expect(codegen.valueTypeForAsc('Array<BigDecimal>')).toBe('[BigDecimal]');
|
|
554
|
+
});
|
|
555
|
+
test('string -> String', () => {
|
|
556
|
+
expect(codegen.valueFromAsc('x', 'String')).toBe('Value.fromString(x)');
|
|
557
|
+
expect(codegen.valueTypeForAsc('string')).toBe('String');
|
|
558
|
+
});
|
|
559
|
+
test('Array<string> -> [String]', () => {
|
|
560
|
+
expect(codegen.valueFromAsc('x', '[String]')).toBe('Value.fromStringArray(x)');
|
|
561
|
+
expect(codegen.valueTypeForAsc('Array<string>')).toBe('[String]');
|
|
562
|
+
});
|
|
563
|
+
});
|