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