Files: e0a962d924b51e646934cc30ae1c50df8f1ef31a / tests / interfaceRunner.js
2348 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 = ['accounts', ...new Buffer(address.slice(2), 'hex')] |
53 | rootVertex.set(path, accountVertex) |
54 | } |
55 | |
56 | envData.state = await rootVertex.get(['accounts', ...envData.address.toBuffer()]) |
57 | const kernel = new Kernel({ |
58 | code: code |
59 | }) |
60 | const env = new Environment(envData) |
61 | |
62 | try { |
63 | await kernel.run(env) |
64 | } catch (e) { |
65 | t.fail('Exception: ' + e) |
66 | console.error('FAIL') |
67 | console.error(e) |
68 | } finally { |
69 | t.pass(testName) |
70 | console.log('done') |
71 | } |
72 | t.end() |
73 | }) |
74 | } |
75 | } |
76 |
Built with git-ssb-web