git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit a925d24ca2819ab0d5702e2877d76981bcd7b285

added SSTORE test of different offset

wanderer committed on 7/20/2016, 10:13:59 PM
Parent: a1cbfac008b122511f7f6be08a5e1dc164c4a9ad

Files changed

index.jschanged
interface.jschanged
tests/interface/sstore.wastchanged
index.jsView
@@ -20,12 +20,12 @@
2020 }
2121
2222 // handles running code.
2323 static codeHandler (code, ethInterface = new Interface()) {
24- // const ethInterface = new Interface(environment)
2524 const instance = Wasm.instantiateModule(code, {
2625 'ethereum': ethInterface
2726 })
27+
2828 ethInterface.setModule(instance)
2929 if (instance.exports.main) {
3030 instance.exports.main()
3131 }
@@ -39,16 +39,16 @@
3939 static callHandler (path, data, environment = new Environment()) {
4040 // return instance
4141 }
4242
43- // run tx
44- runTx (tx, environment) {
43+ // run tx; the tx message handler
44+ runTx (tx, environment = new Environment()) {
4545 // verify tx then send to call Handler
4646 this.callHandler(tx, environment)
4747 }
4848
49- // run block
50- runBlock (block, environment) {
49+ // run block; the block message handler
50+ runBlock (block, environment = new Environment()) {
5151 // verify block then run each tx
5252 block.tx.forEach((tx) => {
5353 this.runTx(tx, environment)
5454 })
interface.jsView
@@ -315,10 +315,10 @@
315315 * @param {interger} pathOffest the memory offset to load the the path from
316316 * @param {interger} valueOffset the memory offset to load the value from
317317 */
318318 sstore (pathOffest, valueOffset) {
319- const path = new Uint8Array(MOD.exports.memory, pathOffest, pathOffest + 32)
320- const value = new Uint8Array(MOD.exports.memory, valueOffset, valueOffset + 32)
319+ const path = new Uint8Array(MOD.exports.memory, pathOffest, 32)
320+ const value = new Uint8Array(MOD.exports.memory, valueOffset, 32)
321321 ENV.state.set(path, value)
322322 }
323323
324324 /**
@@ -326,11 +326,11 @@
326326 * @param {interger} pathOffest the memory offset to load the the path from
327327 * @param {interger} resultOffset the memory offset to load the value from
328328 */
329329 sload (pathOffest, resultOffset) {
330- const path = new Uint8Array(MOD.exports.memory, pathOffest, pathOffest + 32)
330+ const path = new Uint8Array(MOD.exports.memory, pathOffest, 32)
331331 const result = ENV.state.getValue(path)
332- const memory = new Uint8Array(MOD.exports.memory, resultOffset, resultOffset + 32)
332+ const memory = new Uint8Array(MOD.exports.memory, resultOffset, 32)
333333 memory.set(result)
334334 }
335335
336336 /**
tests/interface/sstore.wastView
@@ -12,13 +12,16 @@
1212 ;; should roundtrip store and load a value from storage
1313 (i64.store (i32.const 0) (i64.const 173553719826446289))
1414 (call_import $sstore (i32.const 64) (i32.const 0))
1515 (call_import $sload (i32.const 64) (i32.const 64))
16- (set_local $temp
17- (i64.load (i32.const 64)))
1816
19- (if (i64.eq (i64.load (i32.const 0)) (i64.const 173553719826446289))
20- (return))
21- (unreachable)
17+ (if (i64.ne (i64.load (i32.const 64)) (i64.const 173553719826446289))
18+ (unreachable))
19+
20+ (i64.store (i32.const 128) (i64.const 173553719826446289))
21+ (call_import $sstore (i32.const 64) (i32.const 128))
22+ (call_import $sload (i32.const 64) (i32.const 64))
23+ (if (i64.ne (i64.load (i32.const 64)) (i64.const 173553719826446289))
24+ (unreachable))
2225 )
2326 )
2427 )

Built with git-ssb-web