Commit 9bb00a66c6590ce780568e10d649be74c66ce1e6
fix basic interface tests
wanderer committed on 2/27/2017, 2:07:20 PMParent: cfba6fdcb78b4019f623639fbd7dfecaacb4ab1c
Files changed
EVMinterface.js | changed |
defaultAgent.js | changed |
hypervisor.js | changed |
index.js | changed |
message.js | changed |
tests/interfaceRunner.js | changed |
EVMinterface.js | ||
---|---|---|
@@ -34,10 +34,10 @@ | ||
34 | 34 | }) |
35 | 35 | } |
36 | 36 | |
37 | 37 | async initialize () { |
38 | - this.block = await this.kernel.send(common.ROOT, common.getterMessage('block')) | |
39 | - this.blockchain = await this.kernel.send(common.ROOT, common.getterMessage('blockchain')) | |
38 | + this.block = await this.kernel.send(common.getterMessage('block', [common.ROOT])) | |
39 | + this.blockchain = await this.kernel.send(common.getterMessage('blockchain', [common.ROOT])) | |
40 | 40 | } |
41 | 41 | |
42 | 42 | static get name () { |
43 | 43 | return 'ethereum' |
@@ -244,9 +244,8 @@ | ||
244 | 244 | codeCopy (resultOffset, codeOffset, length, cbIndex) { |
245 | 245 | this.takeGas(3 + Math.ceil(length / 32) * 3) |
246 | 246 | |
247 | 247 | // wait for all the prevouse async ops to finish before running the callback |
248 | - // console.log(this.kernel) | |
249 | 248 | this.api.pushOpsQueue(this.kernel.code, cbIndex, code => { |
250 | 249 | if (code.length) { |
251 | 250 | code = code.slice(codeOffset, codeOffset + length) |
252 | 251 | this.setMemory(resultOffset, length, code) |
defaultAgent.js | ||
---|---|---|
@@ -1,6 +1,6 @@ | ||
1 | 1 | exports.run = async (message, kernel) => { |
2 | - const to = message.to[message.hops - 1] | |
2 | + const to = message.to[message.hops] | |
3 | 3 | if (to) { |
4 | 4 | return kernel.send(message) |
5 | 5 | } else if (message.data.getValue) { |
6 | 6 | return (await kernel.state.get(message.data.getValue)).value |
hypervisor.js | ||
---|---|---|
@@ -26,9 +26,10 @@ | ||
26 | 26 | })) |
27 | 27 | } |
28 | 28 | |
29 | 29 | send (message) { |
30 | - return this.root.send(message) | |
30 | + this.root.send(message) | |
31 | + return message.result() | |
31 | 32 | } |
32 | 33 | |
33 | 34 | async get (path) { |
34 | 35 | let lastKernel = this.root |
index.js | ||
---|---|---|
@@ -57,8 +57,9 @@ | ||
57 | 57 | this._state = 'running' |
58 | 58 | try { |
59 | 59 | result = await this._vm.run(message, this, imports) || {} |
60 | 60 | } catch (e) { |
61 | + console.log(e) | |
61 | 62 | result = { |
62 | 63 | exception: true |
63 | 64 | } |
64 | 65 | } |
@@ -66,10 +67,11 @@ | ||
66 | 67 | // failed messages |
67 | 68 | revert() |
68 | 69 | } else if (message.atomic) { |
69 | 70 | // messages |
70 | - message.finished().then(vmError => { | |
71 | - if (vmError) { | |
71 | + message._finish(result) | |
72 | + message.result().then(result => { | |
73 | + if (result.execption) { | |
72 | 74 | revert() |
73 | 75 | } else { |
74 | 76 | this.runNextMessage(0) |
75 | 77 | } |
@@ -81,16 +83,18 @@ | ||
81 | 83 | return result |
82 | 84 | } |
83 | 85 | |
84 | 86 | async send (message) { |
87 | + // replace root with parent path to root | |
85 | 88 | let portName = message.nextPort() |
86 | - message.addVistedKernel(message) | |
87 | - this.lastMessage = message | |
88 | - // replace root with parent path to root | |
89 | 89 | if (portName === common.ROOT) { |
90 | + message.to.shift() | |
91 | + message.to = new Array(this.path.length).fill(common.PARENT).concat(message.to) | |
90 | 92 | portName = common.PARENT |
91 | - message.to = new Array(this.path.length).fill(common.PARENT).concat(message.to) | |
92 | 93 | } |
94 | + message.addVistedKernel(message) | |
95 | + this.lastMessage = message | |
96 | + // console.log(portName, message) | |
93 | 97 | const port = await this.ports.get(portName) |
94 | 98 | // save the atomic messages for possible reverts |
95 | 99 | if (message.atomic) { |
96 | 100 | this._sentAtomicMessages.push(message) |
message.js | ||
---|---|---|
@@ -14,17 +14,24 @@ | ||
14 | 14 | } |
15 | 15 | Object.assign(this, defaults, opts) |
16 | 16 | this.hops = 0 |
17 | 17 | this._vistedKernels = [] |
18 | + this._resultPromise = new Promise((resolve, reject) => { | |
19 | + this._resolve = resolve | |
20 | + }) | |
18 | 21 | } |
19 | 22 | |
20 | - finished () { | |
23 | + _finish (result) { | |
21 | 24 | if (this.atomic) { |
22 | 25 | this._vistedKernels.pop() |
26 | + if (!this._vistedKernels.length) { | |
27 | + this._resolve(result) | |
28 | + } | |
23 | 29 | } |
24 | - return new Promise((resolve, reject) => { | |
30 | + } | |
25 | 31 | |
26 | - }) | |
32 | + result () { | |
33 | + return this._resultPromise | |
27 | 34 | } |
28 | 35 | |
29 | 36 | nextPort () { |
30 | 37 | return this.to[this.hops++] |
tests/interfaceRunner.js | ||
---|---|---|
@@ -6,25 +6,25 @@ | ||
6 | 6 | const Block = require('../deps/block') |
7 | 7 | const U256 = require('../deps/u256') |
8 | 8 | // TODO remove fakeblockchain |
9 | 9 | const fakeBlockChain = require('../fakeBlockChain.js') |
10 | -const Kernel = require('../index.js') | |
10 | +const Hypervisor = require('../hypervisor.js') | |
11 | 11 | const Message = require('../message.js') |
12 | 12 | const common = require('../common.js') |
13 | 13 | |
14 | 14 | const dir = path.join(__dirname, '/interface') |
15 | 15 | // get the test names |
16 | 16 | let tests = fs.readdirSync(dir).filter((file) => file.endsWith('.wast')) |
17 | -// tests = ['sstore.wast'] | |
17 | +// tests = ['address.wast'] | |
18 | 18 | |
19 | 19 | runTests(tests) |
20 | 20 | |
21 | 21 | function runTests (tests) { |
22 | 22 | for (let testName of tests) { |
23 | 23 | testName = testName.split('.')[0] |
24 | 24 | tape(testName, async (t) => { |
25 | - // Compile Command | |
26 | - const rootVertex = new Vertex() | |
25 | + const hypervisor = new Hypervisor() | |
26 | + const rootVertex = hypervisor.state | |
27 | 27 | const code = fs.readFileSync(`${dir}/${testName}.wasm`) |
28 | 28 | const envData = JSON.parse(fs.readFileSync(`${dir}/${testName}.json`).toString()) |
29 | 29 | |
30 | 30 | for (let address in envData.state) { |
@@ -66,12 +66,10 @@ | ||
66 | 66 | message.data = new Buffer(envData.callData.slice(2), 'hex') |
67 | 67 | message.value = new U256(envData.callValue) |
68 | 68 | message.gas = 1000000 |
69 | 69 | |
70 | - const callerState = await rootVertex.get(['accounts', envData.caller, 'code']) | |
71 | - const caller = new Kernel({state: callerState}) | |
72 | 70 | try { |
73 | - await caller.send(common.ROOT, message) | |
71 | + await hypervisor.send(message) | |
74 | 72 | } catch (e) { |
75 | 73 | t.fail('Exception: ' + e) |
76 | 74 | console.error('FAIL') |
77 | 75 | console.error(e) |
Built with git-ssb-web