git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: 6c9a7f1801d055fef0ca11b55a4047a6360bccd6

Files: 6c9a7f1801d055fef0ca11b55a4047a6360bccd6 / tests / interfaceRunner.js

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

Built with git-ssb-web