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