Files: 000f34b577eb112f2692b0c577052f065087f96c / tests / interfaceRunner.js
1419 bytesRaw
1 | |
2 | const tape = require('tape') |
3 | const fs = require('fs') |
4 | const cp = require('child_process') |
5 | |
6 | const Kernel = require('../index.js') |
7 | const Environment = require('../environment.js') |
8 | const Interface = require('../interface.js') |
9 | const dir = __dirname + '/interface' |
10 | // get the test names |
11 | let tests = fs.readdirSync(dir).filter((file) => file.endsWith('.wast')) |
12 | // tests = ['balance.wast'] |
13 | // run the tests |
14 | for (let testName of tests) { |
15 | testName = testName.split('.')[0] |
16 | tape(testName, (t) => { |
17 | // Compile Command |
18 | cp.execSync(`${__dirname}/../../evm-wasm-transcompiler/deps/sexpr-wasm-prototype/out/sexpr-wasm ${dir}/${testName}.wast -o ${dir}/${testName}.wasm`) |
19 | const buffer = fs.readFileSync(`${dir}/${testName}.wasm`) |
20 | const envData = fs.readFileSync(`${dir}/${testName}.json`) |
21 | const ethereum = new Kernel(new Environment(envData)) |
22 | |
23 | // manually `callHander` |
24 | const environment = new Environment(envData) |
25 | environment.parent = ethereum |
26 | const testContract = new Kernel(environment) |
27 | const ethInterface = new Interface(environment, testContract) |
28 | |
29 | try { |
30 | const mod = Wasm.instantiateModule(buffer, {'ethereum': ethInterface}) |
31 | ethInterface.setModule(mod) |
32 | mod.exports.test() |
33 | } catch (e) { |
34 | t.fail() |
35 | console.error('FAIL') |
36 | console.error(e) |
37 | } finally { |
38 | t.pass(testName) |
39 | console.log('done') |
40 | } |
41 | t.end() |
42 | }) |
43 | } |
44 |
Built with git-ssb-web