Commit a925d24ca2819ab0d5702e2877d76981bcd7b285
added SSTORE test of different offset
wanderer committed on 7/20/2016, 10:13:59 PMParent: a1cbfac008b122511f7f6be08a5e1dc164c4a9ad
Files changed
index.js | changed |
interface.js | changed |
tests/interface/sstore.wast | changed |
index.js | ||
---|---|---|
@@ -20,12 +20,12 @@ | ||
20 | 20 | } |
21 | 21 | |
22 | 22 | // handles running code. |
23 | 23 | static codeHandler (code, ethInterface = new Interface()) { |
24 | - // const ethInterface = new Interface(environment) | |
25 | 24 | const instance = Wasm.instantiateModule(code, { |
26 | 25 | 'ethereum': ethInterface |
27 | 26 | }) |
27 | + | |
28 | 28 | ethInterface.setModule(instance) |
29 | 29 | if (instance.exports.main) { |
30 | 30 | instance.exports.main() |
31 | 31 | } |
@@ -39,16 +39,16 @@ | ||
39 | 39 | static callHandler (path, data, environment = new Environment()) { |
40 | 40 | // return instance |
41 | 41 | } |
42 | 42 | |
43 | - // run tx | |
44 | - runTx (tx, environment) { | |
43 | + // run tx; the tx message handler | |
44 | + runTx (tx, environment = new Environment()) { | |
45 | 45 | // verify tx then send to call Handler |
46 | 46 | this.callHandler(tx, environment) |
47 | 47 | } |
48 | 48 | |
49 | - // run block | |
50 | - runBlock (block, environment) { | |
49 | + // run block; the block message handler | |
50 | + runBlock (block, environment = new Environment()) { | |
51 | 51 | // verify block then run each tx |
52 | 52 | block.tx.forEach((tx) => { |
53 | 53 | this.runTx(tx, environment) |
54 | 54 | }) |
interface.js | ||
---|---|---|
@@ -315,10 +315,10 @@ | ||
315 | 315 | * @param {interger} pathOffest the memory offset to load the the path from |
316 | 316 | * @param {interger} valueOffset the memory offset to load the value from |
317 | 317 | */ |
318 | 318 | 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) | |
321 | 321 | ENV.state.set(path, value) |
322 | 322 | } |
323 | 323 | |
324 | 324 | /** |
@@ -326,11 +326,11 @@ | ||
326 | 326 | * @param {interger} pathOffest the memory offset to load the the path from |
327 | 327 | * @param {interger} resultOffset the memory offset to load the value from |
328 | 328 | */ |
329 | 329 | sload (pathOffest, resultOffset) { |
330 | - const path = new Uint8Array(MOD.exports.memory, pathOffest, pathOffest + 32) | |
330 | + const path = new Uint8Array(MOD.exports.memory, pathOffest, 32) | |
331 | 331 | 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) | |
333 | 333 | memory.set(result) |
334 | 334 | } |
335 | 335 | |
336 | 336 | /** |
tests/interface/sstore.wast | ||
---|---|---|
@@ -12,13 +12,16 @@ | ||
12 | 12 | ;; should roundtrip store and load a value from storage |
13 | 13 | (i64.store (i32.const 0) (i64.const 173553719826446289)) |
14 | 14 | (call_import $sstore (i32.const 64) (i32.const 0)) |
15 | 15 | (call_import $sload (i32.const 64) (i32.const 64)) |
16 | - (set_local $temp | |
17 | - (i64.load (i32.const 64))) | |
18 | 16 | |
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)) | |
22 | 25 | ) |
23 | 26 | ) |
24 | 27 | ) |
Built with git-ssb-web