git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: 63c9d288b4797cd12ec12e080e84ed2559b14e63

Files: 63c9d288b4797cd12ec12e080e84ed2559b14e63 / tests / interfaceRunner.js

1433 bytesRaw
1'use strict'
2const tape = require('tape')
3const fs = require('fs')
4const cp = require('child_process')
5
6const Kernel = require('../index.js')
7const Environment = require('../environment.js')
8const Interface = require('../interface.js')
9const dir = __dirname + '/interface'
10// get the test names
11let tests = fs.readdirSync(dir).filter((file) => file.endsWith('.wast'))
12// tests = ['balance.wast']
13// run the tests
14for (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.exportTable })
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