git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: 682f6674a0fc8dad41078c05d2dd54e7d71c0a42

Files: 682f6674a0fc8dad41078c05d2dd54e7d71c0a42 / tests / interfaceRunner.js

1684 bytesRaw
1'use strict'
2const tape = require('tape')
3const fs = require('fs')
4const cp = require('child_process')
5const path = require('path')
6
7const Kernel = require('../index.js')
8const TestEnvironment = require('../testEnvironment.js')
9const Interface = require('../interface.js')
10const DebugInterface = require('../debugInterface.js')
11
12const dir = path.join(__dirname, '/interface')
13// get the test names
14let tests = fs.readdirSync(dir).filter((file) => file.endsWith('.wast'))
15// tests = ['balance.wast']
16// run the tests
17for (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