git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 9bb00a66c6590ce780568e10d649be74c66ce1e6

fix basic interface tests

wanderer committed on 2/27/2017, 2:07:20 PM
Parent: cfba6fdcb78b4019f623639fbd7dfecaacb4ab1c

Files changed

EVMinterface.jschanged
defaultAgent.jschanged
hypervisor.jschanged
index.jschanged
message.jschanged
tests/interfaceRunner.jschanged
EVMinterface.jsView
@@ -34,10 +34,10 @@
3434 })
3535 }
3636
3737 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]))
4040 }
4141
4242 static get name () {
4343 return 'ethereum'
@@ -244,9 +244,8 @@
244244 codeCopy (resultOffset, codeOffset, length, cbIndex) {
245245 this.takeGas(3 + Math.ceil(length / 32) * 3)
246246
247247 // wait for all the prevouse async ops to finish before running the callback
248- // console.log(this.kernel)
249248 this.api.pushOpsQueue(this.kernel.code, cbIndex, code => {
250249 if (code.length) {
251250 code = code.slice(codeOffset, codeOffset + length)
252251 this.setMemory(resultOffset, length, code)
defaultAgent.jsView
@@ -1,6 +1,6 @@
11 exports.run = async (message, kernel) => {
2- const to = message.to[message.hops - 1]
2+ const to = message.to[message.hops]
33 if (to) {
44 return kernel.send(message)
55 } else if (message.data.getValue) {
66 return (await kernel.state.get(message.data.getValue)).value
hypervisor.jsView
@@ -26,9 +26,10 @@
2626 }))
2727 }
2828
2929 send (message) {
30- return this.root.send(message)
30+ this.root.send(message)
31+ return message.result()
3132 }
3233
3334 async get (path) {
3435 let lastKernel = this.root
index.jsView
@@ -57,8 +57,9 @@
5757 this._state = 'running'
5858 try {
5959 result = await this._vm.run(message, this, imports) || {}
6060 } catch (e) {
61+ console.log(e)
6162 result = {
6263 exception: true
6364 }
6465 }
@@ -66,10 +67,11 @@
6667 // failed messages
6768 revert()
6869 } else if (message.atomic) {
6970 // messages
70- message.finished().then(vmError => {
71- if (vmError) {
71+ message._finish(result)
72+ message.result().then(result => {
73+ if (result.execption) {
7274 revert()
7375 } else {
7476 this.runNextMessage(0)
7577 }
@@ -81,16 +83,18 @@
8183 return result
8284 }
8385
8486 async send (message) {
87+ // replace root with parent path to root
8588 let portName = message.nextPort()
86- message.addVistedKernel(message)
87- this.lastMessage = message
88- // replace root with parent path to root
8989 if (portName === common.ROOT) {
90+ message.to.shift()
91+ message.to = new Array(this.path.length).fill(common.PARENT).concat(message.to)
9092 portName = common.PARENT
91- message.to = new Array(this.path.length).fill(common.PARENT).concat(message.to)
9293 }
94+ message.addVistedKernel(message)
95+ this.lastMessage = message
96+ // console.log(portName, message)
9397 const port = await this.ports.get(portName)
9498 // save the atomic messages for possible reverts
9599 if (message.atomic) {
96100 this._sentAtomicMessages.push(message)
message.jsView
@@ -14,17 +14,24 @@
1414 }
1515 Object.assign(this, defaults, opts)
1616 this.hops = 0
1717 this._vistedKernels = []
18+ this._resultPromise = new Promise((resolve, reject) => {
19+ this._resolve = resolve
20+ })
1821 }
1922
20- finished () {
23+ _finish (result) {
2124 if (this.atomic) {
2225 this._vistedKernels.pop()
26+ if (!this._vistedKernels.length) {
27+ this._resolve(result)
28+ }
2329 }
24- return new Promise((resolve, reject) => {
30+ }
2531
26- })
32+ result () {
33+ return this._resultPromise
2734 }
2835
2936 nextPort () {
3037 return this.to[this.hops++]
tests/interfaceRunner.jsView
@@ -6,25 +6,25 @@
66 const Block = require('../deps/block')
77 const U256 = require('../deps/u256')
88 // TODO remove fakeblockchain
99 const fakeBlockChain = require('../fakeBlockChain.js')
10-const Kernel = require('../index.js')
10+const Hypervisor = require('../hypervisor.js')
1111 const Message = require('../message.js')
1212 const common = require('../common.js')
1313
1414 const dir = path.join(__dirname, '/interface')
1515 // get the test names
1616 let tests = fs.readdirSync(dir).filter((file) => file.endsWith('.wast'))
17-// tests = ['sstore.wast']
17+// tests = ['address.wast']
1818
1919 runTests(tests)
2020
2121 function runTests (tests) {
2222 for (let testName of tests) {
2323 testName = testName.split('.')[0]
2424 tape(testName, async (t) => {
25- // Compile Command
26- const rootVertex = new Vertex()
25+ const hypervisor = new Hypervisor()
26+ const rootVertex = hypervisor.state
2727 const code = fs.readFileSync(`${dir}/${testName}.wasm`)
2828 const envData = JSON.parse(fs.readFileSync(`${dir}/${testName}.json`).toString())
2929
3030 for (let address in envData.state) {
@@ -66,12 +66,10 @@
6666 message.data = new Buffer(envData.callData.slice(2), 'hex')
6767 message.value = new U256(envData.callValue)
6868 message.gas = 1000000
6969
70- const callerState = await rootVertex.get(['accounts', envData.caller, 'code'])
71- const caller = new Kernel({state: callerState})
7270 try {
73- await caller.send(common.ROOT, message)
71+ await hypervisor.send(message)
7472 } catch (e) {
7573 t.fail('Exception: ' + e)
7674 console.error('FAIL')
7775 console.error(e)

Built with git-ssb-web