git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: 5f3238f523d36fc8df666fb57dcef2f8ecdd2a37

Files: 5f3238f523d36fc8df666fb57dcef2f8ecdd2a37 / tests / interfaceRunner.js

2275 bytesRaw
1const tape = require('tape')
2const fs = require('fs')
3const path = require('path')
4const Vertex = require('merkle-trie')
5const Address = require('../deps/address')
6const U256 = require('../deps/u256')
7
8const Kernel = require('../index.js')
9const Environment = require('../testEnvironment.js')
10
11const dir = path.join(__dirname, '/interface')
12// get the test names
13let tests = fs.readdirSync(dir).filter((file) => file.endsWith('.wast'))
14
15runTests(tests)
16
17function runTests (tests) {
18 for (let testName of tests) {
19 testName = testName.split('.')[0]
20 tape(testName, async (t) => {
21 // Compile Command
22 const rootVertex = new Vertex()
23 const code = fs.readFileSync(`${dir}/${testName}.wasm`)
24 const envData = JSON.parse(fs.readFileSync(`${dir}/${testName}.json`).toString())
25
26 envData.caller = new Address(envData.caller)
27 envData.address = new Address(envData.address)
28 envData.coinbase = new Address(envData.coinbase)
29 envData.origin = new Address(envData.origin)
30 envData.callData = new Buffer(envData.callData.slice(2), 'hex')
31 envData.callValue = new U256(envData.callValue)
32
33 for (let address in envData.state) {
34 const account = envData.state[address]
35 const accountVertex = new Vertex()
36
37 accountVertex.set('code', new Vertex({
38 value: new Buffer(account.code.slice(2), 'hex')
39 }))
40
41 accountVertex.set('balance', new Vertex({
42 value: new Buffer(account.balance.slice(2), 'hex')
43 }))
44
45 for (let key in account.storage) {
46 accountVertex.set(['storage', ...new Buffer(key.slice(2), 'hex')], new Vertex({
47 value: new Buffer(account.storage[key].slice(2), 'hex')
48 }))
49 }
50
51 const path = [...new Buffer(address.slice(2), 'hex')]
52 rootVertex.set(path, accountVertex)
53 }
54
55 envData.state = await rootVertex.get([...envData.address.toBuffer()])
56 const kernel = new Kernel({code: code})
57 const env = new Environment(envData)
58
59 try {
60 await kernel.run(env)
61 } catch (e) {
62 t.fail('Exception: ' + e)
63 console.error('FAIL')
64 console.error(e)
65 } finally {
66 t.pass(testName)
67 console.log('done')
68 }
69 t.end()
70 })
71 }
72}
73

Built with git-ssb-web