Skip to content

Commit 52751fe

Browse files
committed
Run test.ts after compilation
Fixes AssemblyScript#2
1 parent 5320733 commit 52751fe

File tree

4 files changed

+850
-999
lines changed

4 files changed

+850
-999
lines changed

tests/near-bindgen/test.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
const fs = require('fs');
3+
const loader = require('../../lib/loader');
4+
5+
(async function() {
6+
let module;
7+
module = loader.instantiateBuffer(fs.readFileSync('./test.wasm'), {
8+
env: {
9+
abort(msg, file, line, column) {
10+
if (module) {
11+
msg = module.getString(msg);
12+
file = module.getString(file);
13+
}
14+
console.log("abort called: %s %s:%s:%s", msg, file, line, column);
15+
},
16+
log(str) {
17+
if (module) {
18+
str = module.getString(str);
19+
}
20+
console.log(str);
21+
},
22+
return_value(ptr) {
23+
console.log("return_value", ptr);
24+
}
25+
}
26+
});
27+
28+
await module.runTest();
29+
})().catch(e => {
30+
console.error('Error during test execution:', e);
31+
process.exit(1);
32+
});

tests/near-bindgen/test.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/bin/sh
22
set -e
33
set -x
4-
BASEDIR=../../
4+
BASEDIR=../..
55
$BASEDIR/bin/asc main.ts --outFile main.wat --nearFile main_near.ts
66
prettier --write main_near.ts
77
$BASEDIR/bin/asc main_near.ts -o main_near.wat
88
diff -U 5 main_near.ts.expected main_near.ts
9-
$BASEDIR/bin/asc test.ts -o test.wasm --textFile test.wat
9+
$BASEDIR/bin/asc test.ts -o test.wasm --textFile test.wat --sourceMap
10+
node test.js
1011
diff -U 5 test.wat.expected test.wat

tests/near-bindgen/test.ts

+3-37
Original file line numberDiff line numberDiff line change
@@ -13,46 +13,12 @@ export function runTest(): void {
1313
original.flag = true;
1414
original.baz = "foo";
1515
let encoder: JSONEncoder = new JSONEncoder();
16+
encoder.pushObject(null);
1617
main.__near_encode_FooBar(original, encoder);
18+
encoder.popObject();
1719
let encoded = encoder.serialize();
18-
let decoded = main.__near_decode_FooBar(encoded, 0);
20+
let decoded = main.__near_decode_FooBar(encoded, null);
1921

2022
assert(original.foo == decoded.foo);
2123
assert(original.bar == decoded.bar);
22-
23-
let argsEncoder: JSONEncoder = new JSONEncoder();
24-
argsEncoder.setInteger("x", 1);
25-
argsEncoder.setInteger("y", 2);
26-
27-
let addBsonStr = bin2hex(argsEncoder.serialize());
28-
let expectedResultEncoder: JSONEncoder = new JSONEncoder();
29-
expectedResultEncoder.setInteger("result", 3);
30-
31-
/*
32-
let bsonResult = main.near_func_add(hex2bin(addBsonStr));
33-
34-
let bsonResultStr = bin2hex(bsonResult);
35-
let expectedBsonResultStr = bin2hex(expectedResultEncoder.serialize())
36-
assert(bsonResultStr == expectedBsonResultStr, bsonResultStr + "\n" + expectedBsonResultStr);
37-
*/
38-
}
39-
40-
function hex2bin(hex: string): Uint8Array {
41-
let bin = new Uint8Array(hex.length >>> 1);
42-
for (let i = 0, len = hex.length >>> 1; i < len; i++) {
43-
bin[i] = u32(parseInt(hex.substr(i << 1, 2), 16));
44-
}
45-
return bin;
46-
}
47-
48-
function bin2hex(bin: Uint8Array, uppercase: boolean = false): string {
49-
let hex = uppercase ? "0123456789ABCDEF" : "0123456789abcdef";
50-
let str = "";
51-
for (let i = 0, len = bin.length; i < len; i++) {
52-
str += hex.charAt((bin[i] >>> 4) & 0x0f) + hex.charAt(bin[i] & 0x0f);
53-
}
54-
return str;
5524
}
56-
57-
58-
runTest();

0 commit comments

Comments
 (0)