git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit c0ffdd0e09232954459f879b99db0b4192eded09

fix api tests

wanderer committed on 4/4/2017, 4:23:59 PM
Parent: a12fcbf698618cd91b74a1da931067ede4b57f45

Files changed

tests/apiTests.jschanged
tests/interfaceRunner.jschanged
tests/apiTests.jsView
@@ -1,9 +1,9 @@
11 const tape = require('tape')
22 const Hypervisor = require('../hypervisor.js')
33 const Message = require('primea-message')
4+const Graph = require('ipld-graph-builder')
45 const IPFS = require('ipfs')
5-const Graph = require('ipld-graph-builder')
66
77 const ipfs = new IPFS()
88 const graph = new Graph(ipfs)
99
tests/interfaceRunner.jsView
@@ -1,7 +1,7 @@
11 const tape = require('tape')
22 const fs = require('fs')
3-const Vertex = require('ipld-graph-builder')
3+const Graph = require('ipld-graph-builder')
44 const Block = require('../deps/block')
55 const U128 = require('fixed-bn.js').U128
66 const Address = require('fixed-bn.js').Address
77 // TODO remove fakeblockchain
@@ -9,62 +9,47 @@
99 const Hypervisor = require('../hypervisor.js')
1010 const Message = require('primea-message')
1111 const common = require('../common')
1212 const EVMinterface = require('../EVMinterface.js')
13+const IPFS = require('ipfs')
1314
15+const ipfs = new IPFS()
16+const graph = new Graph(ipfs)
17+
1418 const dir = `${__dirname}/interface`
1519 // get the test names
1620 let tests = fs.readdirSync(dir).filter((file) => file.endsWith('.wast'))
17-runTests(tests)
21+// tests = ['address.js']
1822
23+ipfs.on('start', async () => {
24+ runTests(tests)
25+})
26+
1927 function runTests (tests) {
20- for (let testName of tests) {
21- testName = testName.split('.')[0]
22- tape(testName, async (t) => {
23- const hypervisor = new Hypervisor(new Vertex(), [EVMinterface])
24- const rootVertex = hypervisor.state
28+ tape('EVM interface tests', async(t) => {
29+ for (let testName of tests) {
30+ t.comment(testName)
31+ testName = testName.split('.')[0]
32+ const hypervisor = new Hypervisor(graph, {}, [EVMinterface])
33+ const envData = JSON.parse(fs.readFileSync(`${dir}/${testName}.json`).toString())
2534 const code = fs.readFileSync(`${dir}/${testName}.wasm`)
26- const envData = JSON.parse(fs.readFileSync(`${dir}/${testName}.json`).toString())
35+ envData.state[envData.address].code = code
2736
28- for (let address in envData.state) {
29- const account = envData.state[address]
30- const accountVertex = new Vertex()
31-
32- accountVertex.set('code', new Vertex({
33- value: code
34- }))
35-
36- accountVertex.set('balance', new Vertex({
37- value: new Buffer(account.balance.slice(2), 'hex')
38- }))
39-
40- for (let key in account.storage) {
41- accountVertex.set(['storage', ...new Buffer(key.slice(2), 'hex')], new Vertex({
42- value: new Buffer(account.storage[key].slice(2), 'hex')
43- }))
44- }
45-
46- const path = ['accounts', address]
47- rootVertex.set(path, accountVertex)
48- }
49-
50- rootVertex.set('blockchain', new Vertex({
51- value: fakeBlockChain
52- }))
53-
5437 const block = new Block()
5538 block.header.coinbase = new Address(envData.coinbase)
5639
57- const message = new Message()
58- message.to = ['accounts', envData.caller, common.PARENT, envData.address, 'code']
40+ const message = new Message({
41+ to: `/accounts/${envData.caller}/${common.PARENT}/${envData.address}/code`
42+ })
5943 message.data = new Buffer(envData.callData.slice(2), 'hex')
6044 message.value = new U128(envData.callValue)
6145 message.gas = envData.gasLeft
6246 message.block = block
6347 message.blockchain = fakeBlockChain
6448
6549 const results = await hypervisor.send(message)
6650 t.equals(results.exception, undefined)
67- t.end()
68- })
69- }
51+ }
52+ t.end()
53+ process.exit()
54+ })
7055 }

Built with git-ssb-web