@theqrl/hypc 0.0.2 → 0.3.1

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.
Files changed (60) hide show
  1. package/README.md +62 -15
  2. package/abi.js +17 -7
  3. package/bindings/compile.js +158 -31
  4. package/bindings/core.js +22 -6
  5. package/bindings/helpers.js +3 -4
  6. package/bindings/index.js +13 -6
  7. package/common/helpers.js +17 -3
  8. package/downloadCurrentVersion.js +20 -14
  9. package/formatters.js +2 -3
  10. package/hypc.js +91 -35
  11. package/hypjson.js +110 -1732
  12. package/linker.js +63 -32
  13. package/package.json +28 -28
  14. package/smtchecker.js +3 -1
  15. package/smtsolver.js +44 -17
  16. package/translate.js +4 -4
  17. package/verifyVersion.js +17 -7
  18. package/wrapper.js +305 -30
  19. package/build/clean.js +0 -6
  20. package/build/pack-publish-block.js +0 -10
  21. package/build/postbuild.js +0 -3
  22. package/contractA_hyp_A.bin +0 -1
  23. package/contractB_hyp_B.bin +0 -1
  24. package/importA_hyp_C.bin +0 -1
  25. package/importB_hyp_D.bin +0 -1
  26. package/libX_hyp_X.bin +0 -1
  27. package/libY_hyp_Y.bin +0 -1
  28. package/libZ_hyp_Z.bin +0 -1
  29. package/test/abi.js +0 -77
  30. package/test/cli.js +0 -245
  31. package/test/compiler.js +0 -791
  32. package/test/index.js +0 -36
  33. package/test/linker.js +0 -132
  34. package/test/resources/fixtureAsmJson.hyp +0 -8
  35. package/test/resources/fixtureAsmJson.json +0 -528
  36. package/test/resources/fixtureAsmJson.output +0 -101
  37. package/test/resources/fixtureIncorrectSource.hyp +0 -1
  38. package/test/resources/fixtureSmoke.hyp +0 -5
  39. package/test/resources/importA.hyp +0 -7
  40. package/test/resources/importB.hyp +0 -5
  41. package/test/resources/importCallback/base/contractA.hyp +0 -8
  42. package/test/resources/importCallback/base/contractB.hyp +0 -6
  43. package/test/resources/importCallback/contractC.hyp +0 -4
  44. package/test/resources/importCallback/includeA/libX.hyp +0 -4
  45. package/test/resources/importCallback/includeA/libY.hyp +0 -6
  46. package/test/resources/importCallback/includeA/utils.hyp +0 -4
  47. package/test/resources/importCallback/includeB/libZ.hyp +0 -4
  48. package/test/resources/smtChecker/loop.hyp +0 -8
  49. package/test/resources/smtChecker/smoke.hyp +0 -5
  50. package/test/resources/smtChecker/smoke_with_engine.hyp +0 -6
  51. package/test/resources/smtChecker/smoke_with_multi_engine.hyp +0 -8
  52. package/test/smtcallback.js +0 -221
  53. package/test/smtchecker.js +0 -83
  54. package/test/translate.js +0 -83
  55. package/test_resources_fixtureSmoke_hyp_C.abi +0 -1
  56. package/test_resources_fixtureSmoke_hyp_C.bin +0 -1
  57. package/test_resources_importA_hyp_C.bin +0 -1
  58. package/test_resources_importB_hyp_D.bin +0 -1
  59. package/tsconfig.json +0 -25
  60. package/utils_hyp_Utils.bin +0 -1
package/test/compiler.js DELETED
@@ -1,791 +0,0 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const assert_1 = __importDefault(require("assert"));
30
- const tape_1 = __importDefault(require("tape"));
31
- const semver = __importStar(require("semver"));
32
- const tmp = __importStar(require("tmp"));
33
- const __1 = __importDefault(require("../"));
34
- const linker_1 = __importDefault(require("../linker"));
35
- const child_process_1 = require("child_process");
36
- const wrapper_1 = __importDefault(require("../wrapper"));
37
- const noRemoteVersions = (process.argv.indexOf('--no-remote-versions') >= 0);
38
- function runTests(hypc, versionText) {
39
- console.log(`Running tests with ${versionText} ${hypc.version()}`);
40
- function resplitFileNameOnFirstColon(fileName, contractName) {
41
- (0, assert_1.default)(!contractName.includes(':'));
42
- const contractNameComponents = fileName.split(':');
43
- const truncatedFileName = contractNameComponents.shift();
44
- contractNameComponents.push(contractName);
45
- return [truncatedFileName, contractNameComponents.join(':')];
46
- }
47
- function getBytecode(output, fileName, contractName) {
48
- try {
49
- const outputContract = output.contracts[fileName + ':' + contractName];
50
- return outputContract.bytecode;
51
- }
52
- catch (e) {
53
- return '';
54
- }
55
- }
56
- function getBytecodeStandard(output, fileName, contractName) {
57
- try {
58
- const outputFile = output.contracts[fileName];
59
- return outputFile[contractName].zvm.bytecode.object;
60
- }
61
- catch (e) {
62
- return '';
63
- }
64
- }
65
- function getGasEstimate(output, fileName, contractName) {
66
- try {
67
- // TODO (cyyber): Condition looks odd.
68
- if (semver.gt(hypc.semver(), '0.4.10') && semver.gt(hypc.semver(), '0.4.20')) {
69
- [fileName, contractName] = resplitFileNameOnFirstColon(fileName, contractName);
70
- }
71
- const outputFile = output.contracts[fileName];
72
- return outputFile[contractName].zvm.gasEstimates;
73
- }
74
- catch (e) {
75
- return '';
76
- }
77
- }
78
- function expectError(output, errorType, message) {
79
- if (output.errors) {
80
- for (const errorIndex in output.errors) {
81
- const error = output.errors[errorIndex];
82
- if (error.type === errorType) {
83
- if (message) {
84
- if (error.message.match(message) !== null) {
85
- return true;
86
- }
87
- }
88
- else {
89
- return true;
90
- }
91
- }
92
- }
93
- }
94
- return false;
95
- }
96
- function expectNoError(output) {
97
- if (output.errors) {
98
- for (const errorIndex in output.errors) {
99
- const error = output.errors[errorIndex];
100
- if (error.severity === 'error') {
101
- return false;
102
- }
103
- }
104
- }
105
- return true;
106
- }
107
- (0, tape_1.default)(versionText, function (t) {
108
- const tape = t.test;
109
- tape('Version and license', function (t) {
110
- t.test('check version', function (st) {
111
- st.equal(typeof hypc.version(), 'string');
112
- st.end();
113
- });
114
- t.test('check semver', function (st) {
115
- st.equal(typeof hypc.semver(), 'string');
116
- st.end();
117
- });
118
- t.test('check license', function (st) {
119
- st.ok(typeof hypc.license() === 'undefined' || typeof hypc.license() === 'string');
120
- st.end();
121
- });
122
- });
123
- tape('Compilation', function (t) {
124
- t.test('single files can be compiled (using lowlevel API)', function (st) {
125
- if (typeof hypc.lowlevel.compileSingle !== 'function') {
126
- st.skip('Low-level compileSingle interface not implemented by this compiler version.');
127
- st.end();
128
- return;
129
- }
130
- const output = JSON.parse(hypc.lowlevel.compileSingle('contract A { function g() public {} }'));
131
- st.ok('contracts' in output);
132
- const bytecode = getBytecode(output, '', 'A');
133
- st.ok(typeof bytecode === 'string');
134
- st.ok(bytecode.length > 0);
135
- st.end();
136
- });
137
- t.test('invalid source code fails properly (using lowlevel API)', function (st) {
138
- if (typeof hypc.lowlevel.compileSingle !== 'function') {
139
- st.skip('Low-level compileSingle interface not implemented by this compiler version.');
140
- st.end();
141
- return;
142
- }
143
- const output = JSON.parse(hypc.lowlevel.compileSingle('contract x { this is an invalid contract }'));
144
- st.plan(3);
145
- st.ok('errors' in output);
146
- // Check if the ParserError exists, but allow others too
147
- st.ok(output.errors.length >= 1);
148
- for (const error in output.errors) {
149
- // Error should be something like:
150
- // ParserError
151
- // Error: Expected identifier
152
- // Parser error: Expected identifier
153
- if (output.errors[error].indexOf('ParserError') !== -1 ||
154
- output.errors[error].indexOf('Error: Expected identifier') !== -1 ||
155
- output.errors[error].indexOf('Parser error: Expected identifier') !== -1 ||
156
- output.errors[error].indexOf(': Expected identifier') !== -1 // 0.4.12
157
- ) {
158
- st.ok(true);
159
- }
160
- }
161
- st.end();
162
- });
163
- t.test('multiple files can be compiled (using lowlevel API)', function (st) {
164
- // <0.1.6 doesn't have this
165
- if (typeof hypc.lowlevel.compileMulti !== 'function') {
166
- st.skip('Low-level compileMulti interface not implemented by this compiler version.');
167
- st.end();
168
- return;
169
- }
170
- const input = {
171
- 'a.hyp': 'contract A { function f() public returns (uint) { return 7; } }',
172
- 'b.hyp': 'import "a.hyp"; contract B is A { function g() public { f(); } }'
173
- };
174
- const output = JSON.parse(hypc.lowlevel.compileMulti(JSON.stringify({ sources: input })));
175
- const B = getBytecode(output, 'b.hyp', 'B');
176
- st.ok(typeof B === 'string');
177
- st.ok(B.length > 0);
178
- const A = getBytecode(output, 'a.hyp', 'A');
179
- st.ok(typeof A === 'string');
180
- st.ok(A.length > 0);
181
- st.end();
182
- });
183
- t.test('lazy-loading callback works (using lowlevel API)', function (st) {
184
- // <0.2.1 doesn't have this
185
- if (typeof hypc.lowlevel.compileCallback !== 'function') {
186
- st.skip('Low-level compileCallback interface not implemented by this compiler version.');
187
- st.end();
188
- return;
189
- }
190
- const input = {
191
- 'b.hyp': 'import "a.hyp"; contract B is A { function g() public { f(); } }'
192
- };
193
- function findImports(path) {
194
- if (path === 'a.hyp') {
195
- return { contents: 'contract A { function f() public returns (uint) { return 7; } }' };
196
- }
197
- else {
198
- return { error: 'File not found' };
199
- }
200
- }
201
- const output = JSON.parse(hypc.lowlevel.compileCallback(JSON.stringify({ sources: input }), 0, { import: findImports }));
202
- const B = getBytecode(output, 'b.hyp', 'B');
203
- st.ok(typeof B === 'string');
204
- st.ok(B.length > 0);
205
- const A = getBytecode(output, 'a.hyp', 'A');
206
- st.ok(typeof A === 'string');
207
- st.ok(A.length > 0);
208
- st.end();
209
- });
210
- t.test('lazy-loading callback works (with file not found) (using lowlevel API)', function (st) {
211
- // <0.2.1 doesn't have this
212
- if (typeof hypc.lowlevel.compileCallback !== 'function') {
213
- st.skip('Low-level compileCallback interface not implemented by this compiler version.');
214
- st.end();
215
- return;
216
- }
217
- const input = {
218
- 'b.hyp': 'import "a.hyp"; contract B { function g() public { f(); } }'
219
- };
220
- function findImports(path) {
221
- return { error: 'File not found' };
222
- }
223
- const output = JSON.parse(hypc.lowlevel.compileCallback(JSON.stringify({ sources: input }), 0, { import: findImports }));
224
- st.plan(3);
225
- st.ok('errors' in output);
226
- // Check if the ParserError exists, but allow others too
227
- st.ok(output.errors.length >= 1);
228
- for (const error in output.errors) {
229
- // Error should be something like:
230
- // cont.hyp:1:1: ParserError: Source "lib.hyp" not found: File not found
231
- // cont.hyp:1:1: Error: Source "lib.hyp" not found: File not found
232
- if (output.errors[error].indexOf('Error') !== -1 && output.errors[error].indexOf('File not found') !== -1) {
233
- st.ok(true);
234
- }
235
- else if (output.errors[error].indexOf('not found: File not found') !== -1) {
236
- // 0.4.12 had its own weird way:
237
- // b.hyp:1:1: : Source "a.hyp" not found: File not found
238
- st.ok(true);
239
- }
240
- }
241
- st.end();
242
- });
243
- t.test('lazy-loading callback works (with exception) (using lowlevel API)', function (st) {
244
- // <0.2.1 doesn't have this
245
- if (typeof hypc.lowlevel.compileCallback !== 'function') {
246
- st.skip('Low-level compileCallback interface not implemented by this compiler version.');
247
- st.end();
248
- return;
249
- }
250
- const input = {
251
- 'b.hyp': 'import "a.hyp"; contract B { function g() public { f(); } }'
252
- };
253
- function findImports(path) {
254
- throw new Error('Could not implement this interface properly...');
255
- }
256
- st.throws(function () {
257
- hypc.lowlevel.compileCallback(JSON.stringify({ sources: input }), 0, { import: findImports });
258
- }, /^Error: Could not implement this interface properly.../);
259
- st.end();
260
- });
261
- t.test('lazy-loading callback fails properly (with invalid callback) (using lowlevel API)', function (st) {
262
- // <0.2.1 doesn't have this
263
- if (typeof hypc.lowlevel.compileCallback !== 'function') {
264
- st.skip('Low-level compileCallback interface not implemented by this compiler version.');
265
- st.end();
266
- return;
267
- }
268
- const input = {
269
- 'cont.hyp': 'import "lib.hyp"; contract x { function g() public { L.f(); } }'
270
- };
271
- st.throws(function () {
272
- hypc.lowlevel.compileCallback(JSON.stringify({ sources: input }), 0, 'this isn\'t a callback');
273
- }, /Invalid callback object specified./);
274
- st.end();
275
- });
276
- t.test('file import without lazy-loading callback fails properly (using lowlevel API)', function (st) {
277
- // <0.2.1 doesn't have this
278
- if (typeof hypc.lowlevel.compileCallback !== 'function') {
279
- st.skip('Low-level compileCallback interface not implemented by this compiler version.');
280
- st.end();
281
- return;
282
- }
283
- const input = {
284
- 'b.hyp': 'import "a.hyp"; contract B is A { function g() public { f(); } }'
285
- };
286
- const output = JSON.parse(hypc.lowlevel.compileCallback(JSON.stringify({ sources: input })));
287
- st.plan(3);
288
- st.ok('errors' in output);
289
- // Check if the ParserError exists, but allow others too
290
- st.ok(output.errors.length >= 1);
291
- for (const error in output.errors) {
292
- // Error should be something like:
293
- // cont.hyp:1:1: ParserError: Source "lib.hyp" not found: File import callback not supported
294
- // cont.hyp:1:1: Error: Source "lib.hyp" not found: File import callback not supported
295
- if (output.errors[error].indexOf('Error') !== -1 && output.errors[error].indexOf('File import callback not supported') !== -1) {
296
- st.ok(true);
297
- }
298
- else if (output.errors[error].indexOf('not found: File import callback not supported') !== -1) {
299
- // 0.4.12 had its own weird way:
300
- // b.hyp:1:1: : Source "a.hyp" not found: File import callback not supported
301
- st.ok(true);
302
- }
303
- }
304
- st.end();
305
- });
306
- t.test('compiling standard JSON (using lowlevel API)', function (st) {
307
- if (typeof hypc.lowlevel.compileStandard !== 'function') {
308
- st.skip('Low-level compileStandard interface not implemented by this compiler version.');
309
- st.end();
310
- return;
311
- }
312
- const input = {
313
- language: 'Hyperion',
314
- settings: {
315
- outputSelection: {
316
- '*': {
317
- '*': ['zvm.bytecode']
318
- }
319
- }
320
- },
321
- sources: {
322
- 'a.hyp': {
323
- content: 'contract A { function f() public returns (uint) { return 7; } }'
324
- },
325
- 'b.hyp': {
326
- content: 'import "a.hyp"; contract B is A { function g() public { f(); } }'
327
- }
328
- }
329
- };
330
- function bytecodeExists(output, fileName, contractName) {
331
- try {
332
- return output.contracts[fileName][contractName].zvm.bytecode.object.length > 0;
333
- }
334
- catch (e) {
335
- return false;
336
- }
337
- }
338
- const output = JSON.parse(hypc.lowlevel.compileStandard(JSON.stringify(input)));
339
- st.ok(bytecodeExists(output, 'a.hyp', 'A'));
340
- st.ok(bytecodeExists(output, 'b.hyp', 'B'));
341
- st.end();
342
- });
343
- t.test('invalid source code fails properly with standard JSON (using lowlevel API)', function (st) {
344
- if (typeof hypc.lowlevel.compileStandard !== 'function') {
345
- st.skip('Low-level compileStandard interface not implemented by this compiler version.');
346
- st.end();
347
- return;
348
- }
349
- const input = {
350
- language: 'Hyperion',
351
- settings: {
352
- outputSelection: {
353
- '*': {
354
- '*': ['zvm.bytecode']
355
- }
356
- }
357
- },
358
- sources: {
359
- 'x.hyp': {
360
- content: 'contract x { this is an invalid contract }'
361
- }
362
- }
363
- };
364
- const output = JSON.parse(hypc.lowlevel.compileStandard(JSON.stringify(input)));
365
- st.plan(3);
366
- st.ok('errors' in output);
367
- st.ok(output.errors.length >= 1);
368
- // Check if the ParserError exists, but allow others too
369
- for (const error in output.errors) {
370
- if (output.errors[error].type === 'ParserError') {
371
- st.ok(true);
372
- }
373
- }
374
- st.end();
375
- });
376
- t.test('compiling standard JSON (with callback) (using lowlevel API)', function (st) {
377
- if (typeof hypc.lowlevel.compileStandard !== 'function') {
378
- st.skip('Low-level compileStandard interface not implemented by this compiler version.');
379
- st.end();
380
- return;
381
- }
382
- const input = {
383
- language: 'Hyperion',
384
- settings: {
385
- outputSelection: {
386
- '*': {
387
- '*': ['zvm.bytecode']
388
- }
389
- }
390
- },
391
- sources: {
392
- 'b.hyp': {
393
- content: 'import "a.hyp"; contract B is A { function g() public { f(); } }'
394
- }
395
- }
396
- };
397
- function findImports(path) {
398
- if (path === 'a.hyp') {
399
- return { contents: 'contract A { function f() public returns (uint) { return 7; } }' };
400
- }
401
- else {
402
- return { error: 'File not found' };
403
- }
404
- }
405
- function bytecodeExists(output, fileName, contractName) {
406
- try {
407
- return output.contracts[fileName][contractName].zvm.bytecode.object.length > 0;
408
- }
409
- catch (e) {
410
- return false;
411
- }
412
- }
413
- const output = JSON.parse(hypc.lowlevel.compileStandard(JSON.stringify(input), { import: findImports }));
414
- console.log(JSON.stringify(input));
415
- st.ok(bytecodeExists(output, 'a.hyp', 'A'));
416
- st.ok(bytecodeExists(output, 'b.hyp', 'B'));
417
- st.end();
418
- });
419
- t.test('compiling standard JSON (single file)', function (st) {
420
- const input = {
421
- language: 'Hyperion',
422
- settings: {
423
- outputSelection: {
424
- '*': {
425
- '*': ['zvm.bytecode', 'zvm.gasEstimates']
426
- }
427
- }
428
- },
429
- sources: {
430
- 'c.hyp': {
431
- content: 'contract C { function g() public { } function h() internal {} }'
432
- }
433
- }
434
- };
435
- const output = JSON.parse(hypc.compile(JSON.stringify(input)));
436
- st.ok(expectNoError(output));
437
- const C = getBytecodeStandard(output, 'c.hyp', 'C');
438
- st.ok(typeof C === 'string');
439
- st.ok(C.length > 0);
440
- const CGas = getGasEstimate(output, 'c.hyp', 'C');
441
- st.ok(typeof CGas === 'object');
442
- st.ok(typeof CGas.creation === 'object');
443
- st.ok(typeof CGas.creation.codeDepositCost === 'string');
444
- st.ok(typeof CGas.external === 'object');
445
- st.ok(typeof CGas.external['g()'] === 'string');
446
- st.ok(typeof CGas.internal === 'object');
447
- st.ok(typeof CGas.internal['h()'] === 'string');
448
- st.end();
449
- });
450
- t.test('compiling standard JSON (multiple files)', function (st) {
451
- // <0.1.6 doesn't have this
452
- if (!hypc.features.multipleInputs) {
453
- st.skip('Not supported by hypc');
454
- st.end();
455
- return;
456
- }
457
- const input = {
458
- language: 'Hyperion',
459
- settings: {
460
- outputSelection: {
461
- '*': {
462
- '*': ['zvm.bytecode', 'zvm.gasEstimates']
463
- }
464
- }
465
- },
466
- sources: {
467
- 'a.hyp': {
468
- content: 'contract A { function f() public returns (uint) { return 7; } }'
469
- },
470
- 'b.hyp': {
471
- content: 'import "a.hyp"; contract B is A { function g() public { f(); } function h() internal {} }'
472
- }
473
- }
474
- };
475
- const output = JSON.parse(hypc.compile(JSON.stringify(input)));
476
- st.ok(expectNoError(output));
477
- const B = getBytecodeStandard(output, 'b.hyp', 'B');
478
- st.ok(typeof B === 'string');
479
- st.ok(B.length > 0);
480
- st.ok(Object.keys(linker_1.default.findLinkReferences(B)).length === 0);
481
- const BGas = getGasEstimate(output, 'b.hyp', 'B');
482
- st.ok(typeof BGas === 'object');
483
- st.ok(typeof BGas.creation === 'object');
484
- st.ok(typeof BGas.creation.codeDepositCost === 'string');
485
- st.ok(typeof BGas.external === 'object');
486
- st.ok(typeof BGas.external['g()'] === 'string');
487
- st.ok(typeof BGas.internal === 'object');
488
- st.ok(typeof BGas.internal['h()'] === 'string');
489
- const A = getBytecodeStandard(output, 'a.hyp', 'A');
490
- st.ok(typeof A === 'string');
491
- st.ok(A.length > 0);
492
- st.end();
493
- });
494
- t.test('compiling standard JSON (abstract contract)', function (st) {
495
- // <0.1.6 doesn't have this
496
- if (!hypc.features.multipleInputs) {
497
- st.skip('Not supported by hypc');
498
- st.end();
499
- return;
500
- }
501
- const source = 'abstract contract C { function f() public virtual; }';
502
- const input = {
503
- language: 'Hyperion',
504
- settings: {
505
- outputSelection: {
506
- '*': {
507
- '*': ['zvm.bytecode', 'zvm.gasEstimates']
508
- }
509
- }
510
- },
511
- sources: {
512
- 'c.hyp': {
513
- content: source
514
- }
515
- }
516
- };
517
- const output = JSON.parse(hypc.compile(JSON.stringify(input)));
518
- st.ok(expectNoError(output));
519
- const C = getBytecodeStandard(output, 'c.hyp', 'C');
520
- st.ok(typeof C === 'string');
521
- st.ok(C.length === 0);
522
- st.end();
523
- });
524
- t.test('compiling standard JSON (with imports)', function (st) {
525
- // <0.2.1 doesn't have this
526
- if (!hypc.features.importCallback) {
527
- st.skip('Not supported by hypc');
528
- st.end();
529
- return;
530
- }
531
- const input = {
532
- language: 'Hyperion',
533
- settings: {
534
- outputSelection: {
535
- '*': {
536
- '*': ['zvm.bytecode']
537
- }
538
- }
539
- },
540
- sources: {
541
- 'b.hyp': {
542
- content: 'import "a.hyp"; contract B is A { function g() public { f(); } }'
543
- }
544
- }
545
- };
546
- function findImports(path) {
547
- if (path === 'a.hyp') {
548
- return { contents: 'contract A { function f() public returns (uint) { return 7; } }' };
549
- }
550
- else {
551
- return { error: 'File not found' };
552
- }
553
- }
554
- const output = JSON.parse(hypc.compile(JSON.stringify(input), { import: findImports }));
555
- st.ok(expectNoError(output));
556
- const A = getBytecodeStandard(output, 'a.hyp', 'A');
557
- st.ok(typeof A === 'string');
558
- st.ok(A.length > 0);
559
- const B = getBytecodeStandard(output, 'b.hyp', 'B');
560
- st.ok(typeof B === 'string');
561
- st.ok(B.length > 0);
562
- st.ok(Object.keys(linker_1.default.findLinkReferences(B)).length === 0);
563
- st.end();
564
- });
565
- t.test('compiling standard JSON (using libraries)', function (st) {
566
- // <0.1.6 doesn't have this
567
- if (!hypc.features.multipleInputs) {
568
- st.skip('Not supported by hypc');
569
- st.end();
570
- return;
571
- }
572
- const input = {
573
- language: 'Hyperion',
574
- settings: {
575
- libraries: {
576
- 'lib.hyp': {
577
- L: 'Z4200000000000000000000000000000000000001'
578
- }
579
- },
580
- outputSelection: {
581
- '*': {
582
- '*': ['zvm.bytecode']
583
- }
584
- }
585
- },
586
- sources: {
587
- 'lib.hyp': {
588
- content: 'library L { function f() public returns (uint) { return 7; } }'
589
- },
590
- 'a.hyp': {
591
- content: 'import "lib.hyp"; contract A { function g() public { L.f(); } }'
592
- }
593
- }
594
- };
595
- const output = JSON.parse(hypc.compile(JSON.stringify(input)));
596
- st.ok(expectNoError(output));
597
- const A = getBytecodeStandard(output, 'a.hyp', 'A');
598
- st.ok(typeof A === 'string');
599
- st.ok(A.length > 0);
600
- st.ok(Object.keys(linker_1.default.findLinkReferences(A)).length === 0);
601
- const L = getBytecodeStandard(output, 'lib.hyp', 'L');
602
- st.ok(typeof L === 'string');
603
- st.ok(L.length > 0);
604
- st.end();
605
- });
606
- t.test('compiling standard JSON (with warning >=0.0.1)', function (st) {
607
- const input = {
608
- language: 'Hyperion',
609
- settings: {
610
- outputSelection: {
611
- '*': {
612
- '*': ['zvm.bytecode']
613
- }
614
- }
615
- },
616
- sources: {
617
- 'c.hyp': {
618
- content: 'contract C { function f() public { } }'
619
- }
620
- }
621
- };
622
- const output = JSON.parse(hypc.compile(JSON.stringify(input)));
623
- st.ok(expectError(output, 'Warning', 'Source file does not specify required compiler version!'));
624
- st.end();
625
- });
626
- t.test('compiling standard JSON (using libraries) (using lowlevel API)', function (st) {
627
- if (typeof hypc.lowlevel.compileStandard !== 'function') {
628
- st.skip('Low-level compileStandard interface not implemented by this compiler version.');
629
- st.end();
630
- return;
631
- }
632
- const input = {
633
- language: 'Hyperion',
634
- settings: {
635
- libraries: {
636
- 'lib.hyp': {
637
- L: 'Z4200000000000000000000000000000000000001'
638
- }
639
- },
640
- outputSelection: {
641
- '*': {
642
- '*': ['zvm.bytecode']
643
- }
644
- }
645
- },
646
- sources: {
647
- 'lib.hyp': {
648
- content: 'library L { function f() public returns (uint) { return 7; } }'
649
- },
650
- 'a.hyp': {
651
- content: 'import "lib.hyp"; contract A { function g() public { L.f(); } }'
652
- }
653
- }
654
- };
655
- const output = JSON.parse(hypc.lowlevel.compileStandard(JSON.stringify(input)));
656
- st.ok(expectNoError(output));
657
- const A = getBytecodeStandard(output, 'a.hyp', 'A');
658
- st.ok(typeof A === 'string');
659
- st.ok(A.length > 0);
660
- st.ok(Object.keys(linker_1.default.findLinkReferences(A)).length === 0);
661
- const L = getBytecodeStandard(output, 'lib.hyp', 'L');
662
- st.ok(typeof L === 'string');
663
- st.ok(L.length > 0);
664
- st.end();
665
- });
666
- t.test('compiling standard JSON (invalid JSON)', function (st) {
667
- const output = JSON.parse(hypc.compile('{invalid'));
668
- // TODO: change wrapper to output matching error
669
- st.ok(expectError(output, 'JSONError', 'Line 1, Column 2\n Missing \'}\' or object member name') || expectError(output, 'JSONError', 'Invalid JSON supplied:'));
670
- st.end();
671
- });
672
- t.test('compiling standard JSON (invalid language)', function (st) {
673
- const output = JSON.parse(hypc.compile('{"language":"InvalidHyperion","sources":{"cont.hyp":{"content":""}}}'));
674
- st.ok(expectError(output, 'JSONError', 'supported as a language.') && expectError(output, 'JSONError', '"Hyperion"'));
675
- st.end();
676
- });
677
- t.test('compiling standard JSON (no sources)', function (st) {
678
- const output = JSON.parse(hypc.compile('{"language":"Hyperion"}'));
679
- st.ok(expectError(output, 'JSONError', 'No input sources specified.'));
680
- st.end();
681
- });
682
- t.test('compiling standard JSON (multiple sources on old compiler)', function (st) {
683
- const output = JSON.parse(hypc.compile('{"language":"Hyperion","sources":{"cont.hyp":{"content":"import \\"lib.hyp\\";"},"lib.hyp":{"content":""}}}'));
684
- if (hypc.features.multipleInputs) {
685
- st.ok(expectNoError(output));
686
- }
687
- else {
688
- st.ok(expectError(output, 'JSONError', 'Multiple sources provided, but compiler only supports single input.') || expectError(output, 'Parser error', 'Parser error: Source not found.'));
689
- }
690
- st.end();
691
- });
692
- t.test('compiling standard JSON (file names containing symbols)', function (st) {
693
- const input = {
694
- language: 'Hyperion',
695
- settings: {
696
- outputSelection: {
697
- '*': {
698
- '*': ['zvm.bytecode']
699
- }
700
- }
701
- },
702
- sources: {
703
- '!@#$%^&*()_+-=[]{}\\|"\';:~`<>,.?/': {
704
- content: 'contract C {}'
705
- }
706
- }
707
- };
708
- const output = JSON.parse(hypc.compile(JSON.stringify(input)));
709
- st.ok(expectNoError(output));
710
- const C = getBytecodeStandard(output, '!@#$%^&*()_+-=[]{}\\|"\';:~`<>,.?/', 'C');
711
- st.ok(typeof C === 'string');
712
- st.ok(C.length > 0);
713
- st.end();
714
- });
715
- t.test('compiling standard JSON (file names containing multiple semicolons)', function (st) {
716
- const input = {
717
- language: 'Hyperion',
718
- settings: {
719
- outputSelection: {
720
- '*': {
721
- '*': ['zvm.bytecode']
722
- }
723
- }
724
- },
725
- sources: {
726
- 'a:b:c:d:e:f:G.hyp': {
727
- content: 'contract G {}'
728
- }
729
- }
730
- };
731
- const output = JSON.parse(hypc.compile(JSON.stringify(input)));
732
- st.ok(expectNoError(output));
733
- const G = getBytecodeStandard(output, 'a:b:c:d:e:f:G.hyp', 'G');
734
- st.ok(typeof G === 'string');
735
- st.ok(G.length > 0);
736
- st.end();
737
- });
738
- });
739
- });
740
- // Only run on the latest version.
741
- if (versionText === 'latest' && !noRemoteVersions) {
742
- (0, tape_1.default)('Loading Legacy Versions', function (t) {
743
- t.test('loading remote version - development snapshot', function (st) {
744
- // getting the development snapshot
745
- st.plan(2);
746
- hypc.loadRemoteVersion('latest', function (err, hypcSnapshot) {
747
- if (err) {
748
- st.plan(1);
749
- st.skip('Network error - skipping remote loading test');
750
- st.end();
751
- return;
752
- }
753
- const input = {
754
- language: 'Hyperion',
755
- settings: {
756
- outputSelection: {
757
- '*': {
758
- '*': ['zvm.bytecode']
759
- }
760
- }
761
- },
762
- sources: {
763
- 'cont.hyp': {
764
- content: 'contract x { function g() public {} }'
765
- }
766
- }
767
- };
768
- const output = JSON.parse(hypcSnapshot.compile(JSON.stringify(input)));
769
- const x = getBytecodeStandard(output, 'cont.hyp', 'x');
770
- st.ok(typeof x === 'string');
771
- st.ok(x.length > 0);
772
- });
773
- });
774
- });
775
- }
776
- }
777
- runTests(__1.default, 'latest');
778
- if (!noRemoteVersions) {
779
- // New compiler interface features 0.0.1
780
- const versions = [
781
- 'v0.0.1+commit.360d2d0'
782
- ];
783
- for (let version in versions) {
784
- version = versions[version];
785
- // NOTE: The temporary directory will be removed on process exit.
786
- const tempDir = tmp.dirSync({ unsafeCleanup: true, prefix: 'hypc-js-compiler-test-' }).name;
787
- (0, child_process_1.execSync)(`curl -L -o ${tempDir}/${version}.js https://binaries.theqrl.org/bin/hypjson-${version}.js`);
788
- const newHypc = (0, wrapper_1.default)(require(`${tempDir}/${version}.js`));
789
- runTests(newHypc, version);
790
- }
791
- }