git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: 92b25513d4a47b5f802137f167db1b71bb72a64b

Files: 92b25513d4a47b5f802137f167db1b71bb72a64b / tests / interfaceRunner.js

2630 bytesRaw
1const tape = require('tape')
2const fs = require('fs')
3const path = require('path')
4const Vertex = require('merkle-trie')
5const Address = require('../deps/address')
6const Block = require('../deps/block')
7const U256 = require('../deps/u256')
8// TODO remove fakeblockchain
9const fakeBlockChain = require('../fakeBlockChain.js')
10const Kernel = require('../index.js')
11const Message = require('../message.js')
12const common = require('../common.js')
13
14const dir = path.join(__dirname, '/interface')
15// get the test names
16let tests = fs.readdirSync(dir).filter((file) => file.endsWith('.wast'))
17// tests = ['sstore.wast']
18
19runTests(tests)
20
21function runTests (tests) {
22 for (let testName of tests) {
23 testName = testName.split('.')[0]
24 tape(testName, async (t) => {
25 // Compile Command
26 const rootVertex = new Vertex()
27 const code = fs.readFileSync(`${dir}/${testName}.wasm`)
28 const envData = JSON.parse(fs.readFileSync(`${dir}/${testName}.json`).toString())
29
30 for (let address in envData.state) {
31 const account = envData.state[address]
32 const accountVertex = new Vertex()
33
34 accountVertex.set('code', new Vertex({
35 value: code
36 }))
37
38 accountVertex.set('balance', new Vertex({
39 value: new Buffer(account.balance.slice(2), 'hex')
40 }))
41
42 for (let key in account.storage) {
43 accountVertex.set(['storage', ...new Buffer(key.slice(2), 'hex')], new Vertex({
44 value: new Buffer(account.storage[key].slice(2), 'hex')
45 }))
46 }
47
48 const path = ['accounts', address]
49 rootVertex.set(path, accountVertex)
50 }
51
52 const block = new Block()
53 block.header.coinbase = new Address(envData.coinbase)
54
55 rootVertex.set('block', new Vertex({
56 value: block
57 }))
58
59 rootVertex.set('blockchain', new Vertex({
60 value: fakeBlockChain
61 }))
62
63 const message = new Message()
64 // message.from = new Address()
65 message.to = ['accounts', envData.address, 'code']
66 message.origin = new Address(envData.origin)
67 message.data = new Buffer(envData.callData.slice(2), 'hex')
68 message.value = new U256(envData.callValue)
69 message.gas = 1000000
70
71 const callerState = await rootVertex.get(['accounts', envData.caller, 'code'])
72 const caller = new Kernel({state: callerState})
73 // try {
74 await caller.send(common.ROOT, message)
75 // } catch (e) {
76 // t.fail('Exception: ' + e)
77 // console.error('FAIL')
78 // console.error(e)
79 // } finally {
80 t.pass(testName)
81 // }
82 t.end()
83 })
84 }
85}
86

Built with git-ssb-web