git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: 1a185b3db4ac0da687a162b105af596d0975680a

Files: 1a185b3db4ac0da687a162b105af596d0975680a / tests / interfaceRunner.js

2309 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// tests = ['callDataCopy.wast']
15
16runTests(tests)
17
18function runTests (tests) {
19 for (let testName of tests) {
20 testName = testName.split('.')[0]
21 tape(testName, async (t) => {
22 // Compile Command
23
24 const rootVertex = new Vertex()
25 const code = fs.readFileSync(`${dir}/${testName}.wasm`)
26 const envData = JSON.parse(fs.readFileSync(`${dir}/${testName}.json`).toString())
27
28 envData.caller = new Address(envData.caller)
29 envData.address = new Address(envData.address)
30 envData.coinbase = new Address(envData.coinbase)
31 envData.origin = new Address(envData.origin)
32 envData.callData = new Buffer(envData.callData.slice(2), 'hex')
33 envData.callValue = new U256(envData.callValue)
34
35 for (let address in envData.state) {
36 const account = envData.state[address]
37 const accountVertex = new Vertex()
38
39 accountVertex.set('code', new Vertex({
40 value: new Buffer(account.code.slice(2), 'hex')
41 }))
42
43 accountVertex.set('balance', new Vertex({
44 value: new Buffer(account.balance.slice(2), 'hex')
45 }))
46
47 for (let key in account.storage) {
48 accountVertex.set(['storage', ...new Buffer(key.slice(2), 'hex')], new Vertex({
49 value: new Buffer(account.storage[key].slice(2), 'hex')
50 }))
51 }
52
53 const path = [...new Buffer(address.slice(2), 'hex')]
54 rootVertex.set(path, accountVertex)
55 }
56
57 envData.state = await rootVertex.get([...envData.address.toBuffer()])
58 const kernel = new Kernel({code: code})
59 const env = new Environment(envData)
60
61 try {
62 await kernel.run(env)
63 } catch (e) {
64 t.fail('Exception: ' + e)
65 console.error('FAIL')
66 console.error(e)
67 } finally {
68 t.pass(testName)
69 console.log('done')
70 }
71 t.end()
72 })
73 }
74}
75

Built with git-ssb-web