git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: 439177b212e72f0e65ae91c034b8d4d8c9c85d9a

Files: 439177b212e72f0e65ae91c034b8d4d8c9c85d9a / tests / interfaceRunner.js

1758 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 environment.callHandler = testContract.callHandler.bind(testContract)
33
34 try {
35 const mod = Wasm.instantiateModule(buffer, {
36 'ethereum': ethInterface.exportTable,
37 'debug': debugInterface.exportTable
38 })
39 ethInterface.setModule(mod)
40 debugInterface.setModule(mod)
41 mod.exports.test()
42 } catch (e) {
43 t.fail('Exception: ' + e)
44 console.error('FAIL')
45 console.error(e)
46 } finally {
47 t.pass(testName)
48 console.log('done')
49 }
50 t.end()
51 })
52}
53

Built with git-ssb-web