tests/interfaceRunner.jsView |
---|
1 | 1 | const tape = require('tape') |
2 | 2 | const fs = require('fs') |
3 | | -const Vertex = require('ipld-graph-builder') |
| 3 | +const Graph = require('ipld-graph-builder') |
4 | 4 | const Block = require('../deps/block') |
5 | 5 | const U128 = require('fixed-bn.js').U128 |
6 | 6 | const Address = require('fixed-bn.js').Address |
7 | 7 | |
9 | 9 | const Hypervisor = require('../hypervisor.js') |
10 | 10 | const Message = require('primea-message') |
11 | 11 | const common = require('../common') |
12 | 12 | const EVMinterface = require('../EVMinterface.js') |
| 13 | +const IPFS = require('ipfs') |
13 | 14 | |
| 15 | +const ipfs = new IPFS() |
| 16 | +const graph = new Graph(ipfs) |
| 17 | + |
14 | 18 | const dir = `${__dirname}/interface` |
15 | 19 | |
16 | 20 | let tests = fs.readdirSync(dir).filter((file) => file.endsWith('.wast')) |
17 | | -runTests(tests) |
| 21 | + |
18 | 22 | |
| 23 | +ipfs.on('start', async () => { |
| 24 | + runTests(tests) |
| 25 | +}) |
| 26 | + |
19 | 27 | 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()) |
25 | 34 | 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 |
27 | 36 | |
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 | | - |
54 | 37 | const block = new Block() |
55 | 38 | block.header.coinbase = new Address(envData.coinbase) |
56 | 39 | |
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 | + }) |
59 | 43 | message.data = new Buffer(envData.callData.slice(2), 'hex') |
60 | 44 | message.value = new U128(envData.callValue) |
61 | 45 | message.gas = envData.gasLeft |
62 | 46 | message.block = block |
63 | 47 | message.blockchain = fakeBlockChain |
64 | 48 | |
65 | 49 | const results = await hypervisor.send(message) |
66 | 50 | t.equals(results.exception, undefined) |
67 | | - t.end() |
68 | | - }) |
69 | | - } |
| 51 | + } |
| 52 | + t.end() |
| 53 | + process.exit() |
| 54 | + }) |
70 | 55 | } |