git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit c2c35a4216304056cc0acac26cf1f3791353f429

passing tests :)

wanderer committed on 3/1/2017, 3:32:30 PM
Parent: 60b86f48100a3b8a9db14f54689cabe117acdff3

Files changed

EVMinterface.jschanged
defaultAgent.jschanged
stateInterface.jschanged
tests/interfaceRunner.jschanged
wasmAgent.jschanged
EVMinterface.jsView
@@ -128,17 +128,17 @@
128128 */
129129 getBalance (addressOffset, offset, cbIndex) {
130130 this.takeGas(20)
131131
132- const path = [common.PARENT, '0x' + new Buffer(this.getMemory(addressOffset, ADDRESS_SIZE_BYTES)).toString('hex')]
133- const opPromise = this.kernel.send(common.PARENT, new Message({
132+ const path = [common.PARENT, common.PARENT, '0x' + new Buffer(this.getMemory(addressOffset, ADDRESS_SIZE_BYTES)).toString('hex')]
133+ const opPromise = this.kernel.send(new Message({
134134 to: path,
135135 data: {
136136 getValue: 'balance'
137137 },
138138 sync: true
139139 }))
140- .catch(() => new U256(0))
140+ .catch(() => new Buffer([]))
141141
142142 this.api.pushOpsQueue(opPromise, cbIndex, balance => {
143143 this.setMemory(offset, U128_SIZE_BYTES, new U256(balance).toMemory(U128_SIZE_BYTES))
144144 })
@@ -152,9 +152,9 @@
152152 */
153153 getTxOrigin (offset) {
154154 this.takeGas(2)
155155
156- const origin = new Buffer(this.message.from[1].slice(2), 'hex')
156+ const origin = new Buffer(this.message.from[2].slice(2), 'hex')
157157 this.setMemory(offset, ADDRESS_SIZE_BYTES, origin)
158158 }
159159
160160 /**
@@ -311,9 +311,9 @@
311311 */
312312 getBlockHash (number, offset, cbOffset) {
313313 this.takeGas(20)
314314
315- const diff = this.block.number - number
315+ const diff = this.message.block.number - number
316316 let opPromise
317317
318318 if (diff > 256 || diff <= 0) {
319319 opPromise = Promise.resolve(new U256(0))
@@ -333,9 +333,9 @@
333333 */
334334 getBlockCoinbase (offset) {
335335 this.takeGas(2)
336336
337- this.setMemory(offset, ADDRESS_SIZE_BYTES, this.block.header.coinbase)
337+ this.setMemory(offset, ADDRESS_SIZE_BYTES, this.message.block.header.coinbase)
338338 }
339339
340340 /**
341341 * Get the block’s timestamp.
@@ -343,9 +343,9 @@
343343 */
344344 getBlockTimestamp () {
345345 this.takeGas(2)
346346
347- return this.block.timestamp
347+ return this.message.block.timestamp
348348 }
349349
350350 /**
351351 * Get the block’s number.
@@ -353,9 +353,9 @@
353353 */
354354 getBlockNumber () {
355355 this.takeGas(2)
356356
357- return this.block.number
357+ return this.message.block.number
358358 }
359359
360360 /**
361361 * Get the block’s difficulty.
@@ -363,9 +363,9 @@
363363 */
364364 getBlockDifficulty (offset) {
365365 this.takeGas(2)
366366
367- this.setMemory(offset, U256_SIZE_BYTES, this.block.difficulty.toMemory())
367+ this.setMemory(offset, U256_SIZE_BYTES, this.message.block.difficulty.toMemory())
368368 }
369369
370370 /**
371371 * Get the block’s gas limit.
@@ -552,28 +552,28 @@
552552 * @param {interger} valueOffset the memory offset to load the value from
553553 */
554554 storageStore (pathOffset, valueOffset, cbIndex) {
555555 this.takeGas(5000)
556- const path = [new Buffer(this.getMemory(pathOffset, U256_SIZE_BYTES)).toString('hex')]
556+ const key = new Buffer(this.getMemory(pathOffset, U256_SIZE_BYTES)).toString('hex')
557557 // copy the value
558558 const value = this.getMemory(valueOffset, U256_SIZE_BYTES).slice(0)
559559 const valIsZero = value.every((i) => i === 0)
560- const opPromise = this.kernel.getValue(path)
560+ const opPromise = this.kernel.stateInterface.get(key)
561561 .then(vertex => vertex.value)
562562 .catch(() => null)
563563
564564 this.api.pushOpsQueue(opPromise, cbIndex, oldValue => {
565565 if (valIsZero && oldValue) {
566566 // delete a value
567567 this.results.gasRefund += 15000
568- this.kernel.deleteValue(path)
568+ this.kernel.storageInterface.del(key)
569569 } else {
570570 if (!valIsZero && !oldValue) {
571571 // creating a new value
572572 this.takeGas(15000)
573573 }
574574 // update
575- this.kernel.setValue(path, new Vertex({
575+ this.kernel.stateInterface.set(key, new Vertex({
576576 value: value
577577 }))
578578 }
579579 })
@@ -587,11 +587,11 @@
587587 storageLoad (pathOffset, resultOffset, cbIndex) {
588588 this.takeGas(50)
589589
590590 // convert the path to an array
591- const path = [new Buffer(this.getMemory(pathOffset, U256_SIZE_BYTES)).toString('hex')]
591+ const key = new Buffer(this.getMemory(pathOffset, U256_SIZE_BYTES)).toString('hex')
592592 // get the value from the state
593- const opPromise = this.kernel.getValue(path)
593+ const opPromise = this.kernel.stateInterface.get(key)
594594 .then(vertex => vertex.value)
595595 .catch(() => new Uint8Array(32))
596596
597597 this.api.pushOpsQueue(opPromise, cbIndex, value => {
defaultAgent.jsView
@@ -2,7 +2,8 @@
22 const to = message.to[message.hops]
33 if (to) {
44 return kernel.send(message)
55 } else if (message.data.getValue) {
6+ console.log('get value')
67 return (await kernel.state.get(message.data.getValue)).value
78 }
89 }
stateInterface.jsView
@@ -13,8 +13,8 @@
1313 get (name) {
1414 return this.state.get([name])
1515 }
1616
17- delete (name) {
17+ del (name) {
1818 return this.state.del([name])
1919 }
2020 }
tests/interfaceRunner.jsView
@@ -13,9 +13,9 @@
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 = ['call.wast']
17+// tests = ['sstore.wast']
1818
1919 runTests(tests)
2020
2121 function runTests (tests) {
@@ -48,32 +48,26 @@
4848 const path = ['accounts', address]
4949 rootVertex.set(path, accountVertex)
5050 }
5151
52- const block = new Block()
53- block.header.coinbase = new Address(envData.coinbase)
54-
55- rootVertex.set('block', new Vertex({
56- value: block
57- }))
58-
5952 rootVertex.set('blockchain', new Vertex({
6053 value: fakeBlockChain
6154 }))
6255
56+ const block = new Block()
57+ block.header.coinbase = new Address(envData.coinbase)
58+
6359 const message = new Message()
6460 message.to = ['accounts', envData.caller, common.PARENT, envData.address, 'code']
6561 message.data = new Buffer(envData.callData.slice(2), 'hex')
6662 message.value = new U256(envData.callValue)
6763 message.gas = 1000000
64+ message.block = block
65+ message.blockchain = fakeBlockChain
6866
69- try {
70- await hypervisor.send(message)
71- } catch (e) {
72- t.fail('Exception: ' + e)
73- } finally {
74- t.pass(testName)
75- }
67+ const results = await hypervisor.send(message)
68+ // console.log(results)
69+ t.equals(results.exception, undefined)
7670 t.end()
7771 })
7872 }
7973 }
wasmAgent.jsView
@@ -17,10 +17,10 @@
1717 function buildImports (kernelApi, kernel, imports) {
1818 const importMap = {}
1919 for (const Import of imports) {
2020 const response = responses[Import.name] = {}
21- const newIterface = new Import(kernelApi, message, response)
22- importMap[Import.name] = newIterface.exports
21+ const newInterface = new Import(kernelApi, message, response)
22+ importMap[Import.name] = newInterface.exports
2323 }
2424 return importMap
2525 }
2626

Built with git-ssb-web