Commit 5548f3620a5008e9db6bdfac769a29fd4616c5f4
fix all tests
wanderer committed on 11/22/2016, 2:02:40 AMParent: e0e6608f9df71b679e52c4d0916732e4e8201fc2
Files changed
EVMinterface.js | ||
---|---|---|
@@ -336,9 +336,9 @@ | ||
336 | 336 | */ |
337 | 337 | getBlockCoinbase (offset) { |
338 | 338 | this.takeGas(2) |
339 | 339 | |
340 | - this.setMemory(offset, ADDRESS_SIZE_BYTES, this.kernel.environment.block.coinbase.toMemory()) | |
340 | + this.setMemory(offset, ADDRESS_SIZE_BYTES, this.kernel.environment.coinbase.toMemory()) | |
341 | 341 | } |
342 | 342 | |
343 | 343 | /** |
344 | 344 | * Get the block’s timestamp. |
@@ -460,15 +460,15 @@ | ||
460 | 460 | * @param {integer} gas |
461 | 461 | * @return {integer} Returns 1 or 0 depending on if the VM trapped on the message or not |
462 | 462 | */ |
463 | 463 | _call (gasHigh, gasLow, addressOffset, valueOffset, dataOffset, dataLength, resultOffset, resultLength, cbIndex) { |
464 | + this.takeGas(40) | |
465 | + | |
464 | 466 | const gas = from64bit(gasHigh, gasLow) |
465 | 467 | // Load the params from mem |
466 | 468 | const address = [...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES)] |
467 | 469 | const value = new U256(this.getMemory(valueOffset, U128_SIZE_BYTES)) |
468 | 470 | |
469 | - this.takeGas(40) | |
470 | - | |
471 | 471 | // Special case for non-zero value; why does this exist? |
472 | 472 | if (!value.isZero()) { |
473 | 473 | this.takeGas(9000 - 2300 + gas) |
474 | 474 | this.takeGas(-gas) |
environment.js | ||
---|---|---|
@@ -30,24 +30,11 @@ | ||
30 | 30 | // more output calls |
31 | 31 | returnValue: new Uint8Array(), |
32 | 32 | state: new Vertex({store: new Store()}) |
33 | 33 | } |
34 | - // this.environment.addAccount(identityContract, {}) | |
35 | - // this.environment.addAccount(meteringContract, {}) | |
36 | - // this.environment.addAccount(transcompilerContract, {}) | |
37 | - | |
38 | 34 | Object.assign(this, defaults, data) |
39 | 35 | } |
40 | 36 | |
41 | - // addAccount (address, trie) { | |
42 | - // let account = new Vertex() | |
43 | - // account.set('nonce', trie.nonce || new U256(0)) | |
44 | - // account.set('balance', trie.balance || new U256(0)) | |
45 | - // account.set('code', trie.code || new Uint8Array()) | |
46 | - // account.set('storage', trie.storage || new Map()) | |
47 | - // this.state.set(address.toString(), account) | |
48 | - // } | |
49 | - | |
50 | 37 | isAccountPresent (address) { |
51 | 38 | // const account = this.state.get(address.toString()) |
52 | 39 | // if (account) { |
53 | 40 | // return true |
package.json | ||
---|---|---|
@@ -4,8 +4,9 @@ | ||
4 | 4 | "description": "This is a JS prototype of the eWASM kernal.", |
5 | 5 | "scripts": { |
6 | 6 | "lint": "standard", |
7 | 7 | "test": "node --expose-wasm ./tests/interfaceRunner.js" |
8 | + "build": "node ./tests/buildTests.js" | |
8 | 9 | }, |
9 | 10 | "repository": { |
10 | 11 | "type": "git", |
11 | 12 | "url": "git+https://github.com/ewasm/ewasm-kernel.git" |
testEnvironment.js | ||
---|---|---|
@@ -1,9 +1,8 @@ | ||
1 | 1 | const Environment = require('./environment.js') |
2 | 2 | const fakeBlockchain = require('./fakeBlockChain') |
3 | 3 | |
4 | 4 | module.exports = class TestEnvironment extends Environment { |
5 | - | |
6 | 5 | async getBlockHash (height) { |
7 | 6 | return fakeBlockchain.getBlock(height).hash() |
8 | 7 | } |
9 | 8 | } |
tests/interface/address.json | ||
---|---|---|
@@ -1,3 +1,13 @@ | ||
1 | 1 | { |
2 | + "callValue": "0x00", | |
3 | + "callData": "0x00", | |
4 | + "state": { | |
5 | + "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b": { | |
6 | + "balance": "0x056bc75e2d63100000", | |
7 | + "code": "0x00", | |
8 | + "nonce": "0x00" | |
9 | + } | |
10 | + }, | |
11 | + "coinbase": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b", | |
2 | 12 | "address": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b" |
3 | 13 | } |
tests/interface/address.wast | ||
---|---|---|
@@ -2,15 +2,15 @@ | ||
2 | 2 | (module |
3 | 3 | (memory 1) |
4 | 4 | |
5 | 5 | (import $address "ethereum" "getAddress" (param i32)) |
6 | - (export "test" 0) | |
6 | + (export "main" 0) | |
7 | 7 | (export "a" memory) |
8 | 8 | (func |
9 | 9 | (block |
10 | 10 | ;; loads the address into memory |
11 | 11 | (call_import $address (i32.const 0)) |
12 | - (if (i64.eq (i64.load (i32.const 0)) (i64.const 0xbd9c6f4a2d06c47b)) | |
12 | + (if (i64.eq (i64.load (i32.const 0)) (i64.const 0x72a1048901c1485d)) | |
13 | 13 | (return) |
14 | 14 | ) |
15 | 15 | (unreachable) |
16 | 16 | ) |
tests/interface/balance.json | ||
---|---|---|
@@ -1,9 +1,13 @@ | ||
1 | 1 | { |
2 | - "accounts": [ | |
3 | - [ | |
4 | - "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b", { | |
5 | - "balance": "0x056bc75e2d63100000" | |
2 | + "callValue": "0x00", | |
3 | + "callData": "0x00", | |
4 | + "state": { | |
5 | + "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b": { | |
6 | + "balance": "0x056bc75e2d63100000", | |
7 | + "code": "0x00", | |
8 | + "nonce": "0x00" | |
6 | 9 | } |
7 | - ] | |
8 | - ] | |
10 | + }, | |
11 | + "coinbase": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b", | |
12 | + "address": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b" | |
9 | 13 | } |
tests/interface/balance.wast | ||
---|---|---|
@@ -1,17 +1,19 @@ | ||
1 | 1 | ;; address of 5d48c1018904a172886829bbbd9c6f4a2d06c47b has a balance of 0x056bc75e2d63100000 (100 ETH) |
2 | 2 | (module |
3 | - (memory 1 (segment 0 "\7b\c4\06\2d\4a\6f\9c\bd\bb\29\68\88\72\a1\04\89\01\c1\48\5d")) | |
4 | - (import $balance "ethereum" "getBalance" (param i32 i32)) | |
3 | + (memory 1 (segment 0 "\5d\48\c1\01\89\04\a1\72\88\68\29\bb\bd\9c\6f\4a\2d\06\c4\7b")) | |
4 | + (import $balance "ethereum" "getBalance" (param i32 i32 i32)) | |
5 | 5 | (export "a" memory) |
6 | - (export "test" 0) | |
6 | + (export "main" 0) | |
7 | 7 | (func |
8 | + (call_import $balance (i32.const 0) (i32.const 0) (i32.const 1)) | |
9 | + ) | |
10 | + | |
11 | + (export "1" 1) | |
12 | + (func | |
8 | 13 | (block |
9 | - (call_import $balance (i32.const 0) (i32.const 0)) | |
10 | - (if (i64.eq (i64.load (i32.const 0)) (i64.const 0x6bc75e2d63100000)) | |
11 | - (if (i64.eq (i64.load (i32.const 8)) (i64.const 0x05)) | |
12 | - (return) | |
13 | - ) | |
14 | + (if (i64.eq (i64.load (i32.const 0)) (i64.const 0x0500000000000000)) | |
15 | + (return) | |
14 | 16 | ) |
15 | 17 | (unreachable) |
16 | 18 | ) |
17 | 19 | ) |
tests/interface/basic_gas_ops.json | ||
---|---|---|
@@ -1,3 +1,14 @@ | ||
1 | 1 | { |
2 | + "callValue": "0x00", | |
3 | + "callData": "0x00", | |
4 | + "state": { | |
5 | + "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b": { | |
6 | + "balance": "0x056bc75e2d63100000", | |
7 | + "code": "0x00", | |
8 | + "nonce": "0x00" | |
9 | + } | |
10 | + }, | |
11 | + "coinbase": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b", | |
12 | + "address": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b", | |
2 | 13 | "gasLeft": 1000 |
3 | 14 | } |
tests/interface/call.json | ||
---|---|---|
@@ -1,3 +1,13 @@ | ||
1 | 1 | { |
2 | + "callValue": "0x00", | |
3 | + "callData": "0x00", | |
4 | + "state": { | |
5 | + "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b": { | |
6 | + "balance": "0x056bc75e2d63100000", | |
7 | + "code": "0x00", | |
8 | + "nonce": "0x00" | |
9 | + } | |
10 | + }, | |
11 | + "coinbase": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b", | |
2 | 12 | "address": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b" |
3 | 13 | } |
tests/interface/call.wast | ||
---|---|---|
@@ -1,11 +1,11 @@ | ||
1 | 1 | ;; starts with an address of 5d48c1018904a172886829bbbd9c6f4a2d06c47b |
2 | 2 | (module |
3 | 3 | (memory 1) |
4 | 4 | |
5 | - (import $call "ethereum" "call" (param i32 i32 i32 i32 i32 i32 i32) (result i32)) | |
6 | - (export "test" 0) | |
5 | + (import $call "ethereum" "call" (param i32 i32 i32 i32 i32 i32 i32 i32) (result i32)) | |
7 | 6 | (export "a" memory) |
7 | + (export "main" 0) | |
8 | 8 | (func |
9 | 9 | (block |
10 | 10 | ;; Memory layout: |
11 | 11 | ;; 0 - 20 bytes: address (4) |
@@ -13,13 +13,16 @@ | ||
13 | 13 | ;; 52 - 56 bytes: data (0x42004200) |
14 | 14 | ;; 56 - 60 bytes: result |
15 | 15 | (i32.store (i32.const 0) (i32.const 0x4)) |
16 | 16 | (i32.store (i32.const 52) (i32.const 0x42004200)) |
17 | - (if (i32.eq (call_import $call (i32.const 2000) (i32.const 0) (i32.const 20) (i32.const 52) (i32.const 4) (i32.const 56) (i32.const 4)) (i32.const 0)) | |
18 | - (if (i32.eq (i32.load (i32.const 56)) (i32.const 0x42004200)) | |
19 | - (return) | |
20 | - ) | |
21 | - ) | |
22 | - (unreachable) | |
17 | + (call_import $call (i32.const 2000) (i32.const 0) (i32.const 20) (i32.const 52) (i32.const 4) (i32.const 56) (i32.const 4) (i32.const 1)) | |
23 | 18 | ) |
24 | 19 | ) |
20 | + | |
21 | + (export "1" 1) | |
22 | + (func (param $result i32) | |
23 | + (if (i32.eq (i32.const 1) (get_local $result)) | |
24 | + (return) | |
25 | + ) | |
26 | + (unreachable) | |
27 | + ) | |
25 | 28 | ) |
tests/interface/callDataCopy.json | ||
---|---|---|
@@ -1,3 +1,13 @@ | ||
1 | 1 | { |
2 | - "callData": "596f75206172652077616974696e6720666f7220746865207265766f6c7574696f6e3f204c657420697420626521204d79206f776e20626567616e2061206c6f6e672074696d652061676f21205768656e20796f752077696c6c2062652072656164792e2e2e4920776f6ee2809974206d696e6420676f696e6720616c6f6e67207769746820796f7520666f722061207768696c652e20427574207768656e20796f75e280996c6c2073746f702c2049207368616c6c20636f6e74696e7565206f6e206d7920696e73616e6520616e6420747269756d7068616e742077617920746f776172642074686520677265617420616e64207375626c696d6520636f6e7175657374206f6620746865206e6f7468696e6721" | |
2 | + "callValue": "0x00", | |
3 | + "callData": "0x596f75206172652077616974696e6720666f7220746865207265766f6c7574696f6e3f204c657420697420626521204d79206f776e20626567616e2061206c6f6e672074696d652061676f21205768656e20796f752077696c6c2062652072656164792e2e2e4920776f6ee2809974206d696e6420676f696e6720616c6f6e67207769746820796f7520666f722061207768696c652e20427574207768656e20796f75e280996c6c2073746f702c2049207368616c6c20636f6e74696e7565206f6e206d7920696e73616e6520616e6420747269756d7068616e742077617920746f776172642074686520677265617420616e64207375626c696d6520636f6e7175657374206f6620746865206e6f7468696e6721", | |
4 | + "state": { | |
5 | + "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b": { | |
6 | + "balance": "0x056bc75e2d63100000", | |
7 | + "code": "0x00", | |
8 | + "nonce": "0x00" | |
9 | + } | |
10 | + }, | |
11 | + "coinbase": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b", | |
12 | + "address": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b" | |
3 | 13 | } |
tests/interface/callDataCopy.wast | ||
---|---|---|
@@ -3,13 +3,12 @@ | ||
3 | 3 | (memory 1) |
4 | 4 | (import $callDataCopy "ethereum" "callDataCopy" (param i32 i32 i32)) |
5 | 5 | |
6 | 6 | (export "memory" memory) |
7 | - (export "test" 0) | |
7 | + (export "main" 0) | |
8 | 8 | (func |
9 | 9 | (block |
10 | 10 | (call_import $callDataCopy (i32.const 0) (i32.const 0) (i32.const 8)) |
11 | - | |
12 | 11 | (if (i64.eq (i64.load (i32.const 0)) (i64.const 0x2065726120756f59)) |
13 | 12 | (return) |
14 | 13 | ) |
15 | 14 | (unreachable) |
tests/interface/callDataSize.json | ||
---|---|---|
@@ -1,3 +1,13 @@ | ||
1 | 1 | { |
2 | - "callData": "596f75206172652077616974696e6720666f7220746865207265766f6c7574696f6e3f204c657420697420626521204d79206f776e20626567616e2061206c6f6e672074696d652061676f21205768656e20796f752077696c6c2062652072656164792e2e2e4920776f6ee2809974206d696e6420676f696e6720616c6f6e67207769746820796f7520666f722061207768696c652e20427574207768656e20796f75e280996c6c2073746f702c2049207368616c6c20636f6e74696e7565206f6e206d7920696e73616e6520616e6420747269756d7068616e742077617920746f776172642074686520677265617420616e64207375626c696d6520636f6e7175657374206f6620746865206e6f7468696e6721" | |
2 | + "callValue": "0x00", | |
3 | + "callData": "0x596f75206172652077616974696e6720666f7220746865207265766f6c7574696f6e3f204c657420697420626521204d79206f776e20626567616e2061206c6f6e672074696d652061676f21205768656e20796f752077696c6c2062652072656164792e2e2e4920776f6ee2809974206d696e6420676f696e6720616c6f6e67207769746820796f7520666f722061207768696c652e20427574207768656e20796f75e280996c6c2073746f702c2049207368616c6c20636f6e74696e7565206f6e206d7920696e73616e6520616e6420747269756d7068616e742077617920746f776172642074686520677265617420616e64207375626c696d6520636f6e7175657374206f6620746865206e6f7468696e6721", | |
4 | + "state": { | |
5 | + "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b": { | |
6 | + "balance": "0x056bc75e2d63100000", | |
7 | + "code": "0x00", | |
8 | + "nonce": "0x00" | |
9 | + } | |
10 | + }, | |
11 | + "coinbase": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b", | |
12 | + "address": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b" | |
3 | 13 | } |
tests/interface/callDataSize.wast | ||
---|---|---|
@@ -1,9 +1,9 @@ | ||
1 | 1 | (module |
2 | 2 | (memory 1) |
3 | 3 | (import $callDataSize "ethereum" "getCallDataSize" (result i64)) |
4 | 4 | |
5 | - (export "test" 0) | |
5 | + (export "main" 0) | |
6 | 6 | (func |
7 | 7 | (block |
8 | 8 | (if (i64.eq (call_import $callDataSize) (i64.const 277)) |
9 | 9 | (return) |
tests/interface/callValue.json | ||
---|---|---|
@@ -1,3 +1,13 @@ | ||
1 | 1 | { |
2 | - "callValue": "0x056bc75e2d63100000" | |
2 | + "callValue": "0x056bc75e2d63100000", | |
3 | + "callData": "0x596f75206172652077616974696e6720666f7220746865207265766f6c7574696f6e3f204c657420697420626521204d79206f776e20626567616e2061206c6f6e672074696d652061676f21205768656e20796f752077696c6c2062652072656164792e2e2e4920776f6ee2809974206d696e6420676f696e6720616c6f6e67207769746820796f7520666f722061207768696c652e20427574207768656e20796f75e280996c6c2073746f702c2049207368616c6c20636f6e74696e7565206f6e206d7920696e73616e6520616e6420747269756d7068616e742077617920746f776172642074686520677265617420616e64207375626c696d6520636f6e7175657374206f6620746865206e6f7468696e6721", | |
4 | + "state": { | |
5 | + "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b": { | |
6 | + "balance": "0x056bc75e2d63100000", | |
7 | + "code": "0x00", | |
8 | + "nonce": "0x00" | |
9 | + } | |
10 | + }, | |
11 | + "coinbase": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b", | |
12 | + "address": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b" | |
3 | 13 | } |
tests/interface/callValue.wast | ||
---|---|---|
@@ -3,16 +3,14 @@ | ||
3 | 3 | (memory 1) |
4 | 4 | (import $callValue "ethereum" "getCallValue" (param i32)) |
5 | 5 | |
6 | 6 | (export "a" memory) |
7 | - (export "test" 0) | |
7 | + (export "main" 0) | |
8 | 8 | (func |
9 | 9 | (block |
10 | 10 | (call_import $callValue (i32.const 0)) |
11 | - (if (i64.eq (i64.load (i32.const 0)) (i64.const 0x6bc75e2d63100000)) | |
12 | - (if (i64.eq (i64.load (i32.const 8)) (i64.const 0x05)) | |
13 | - (return) | |
14 | - ) | |
11 | + (if (i64.eq (i64.load (i32.const 0)) (i64.const 0x0500000000000000)) | |
12 | + (return) | |
15 | 13 | ) |
16 | 14 | (unreachable) |
17 | 15 | ) |
18 | 16 | ) |
tests/interface/caller.json | ||
---|---|---|
@@ -1,3 +1,14 @@ | ||
1 | 1 | { |
2 | - "caller": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b" | |
2 | + "callValue": "0x00", | |
3 | + "callData": "0x00", | |
4 | + "state": { | |
5 | + "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b": { | |
6 | + "balance": "0x056bc75e2d63100000", | |
7 | + "code": "0x00", | |
8 | + "nonce": "0x00" | |
9 | + } | |
10 | + }, | |
11 | + "caller": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b", | |
12 | + "coinbase": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b", | |
13 | + "address": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b" | |
3 | 14 | } |
tests/interface/caller.wast | ||
---|---|---|
@@ -2,15 +2,15 @@ | ||
2 | 2 | (module |
3 | 3 | (memory 1) |
4 | 4 | (import $caller "ethereum" "getCaller" (param i32)) |
5 | 5 | |
6 | - (export "test" 0) | |
6 | + (export "main" 0) | |
7 | 7 | (export "a" memory) |
8 | 8 | (func |
9 | 9 | (block |
10 | 10 | ;; loads the caller into memory |
11 | 11 | (call_import $caller (i32.const 0)) |
12 | - (if (i64.eq (i64.load (i32.const 0)) (i64.const 0xbd9c6f4a2d06c47b)) | |
12 | + (if (i64.eq (i64.load (i32.const 0)) (i64.const 0x72a1048901c1485d)) | |
13 | 13 | (return) |
14 | 14 | ) |
15 | 15 | (unreachable) |
16 | 16 | ) |
tests/interface/coinbase.json | ||
---|---|---|
@@ -1,5 +1,13 @@ | ||
1 | 1 | { |
2 | - "block": { | |
3 | - "coinbase": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b" | |
4 | - } | |
2 | + "callValue": "0x00", | |
3 | + "callData": "0x00", | |
4 | + "state": { | |
5 | + "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b": { | |
6 | + "balance": "0x056bc75e2d63100000", | |
7 | + "code": "0x00", | |
8 | + "nonce": "0x00" | |
9 | + } | |
10 | + }, | |
11 | + "coinbase": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b", | |
12 | + "address": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b" | |
5 | 13 | } |
tests/interface/coinbase.wast | ||
---|---|---|
@@ -2,15 +2,15 @@ | ||
2 | 2 | (module |
3 | 3 | (memory 1) |
4 | 4 | |
5 | 5 | (import $coinbase "ethereum" "getBlockCoinbase" (param i32)) |
6 | - (export "test" 0) | |
6 | + (export "main" 0) | |
7 | 7 | (export "a" memory) |
8 | 8 | (func |
9 | 9 | (block |
10 | 10 | ;; loads the coinbase into memory |
11 | 11 | (call_import $coinbase (i32.const 0)) |
12 | - (if (i64.eq (i64.load (i32.const 0)) (i64.const 0xbd9c6f4a2d06c47b)) | |
12 | + (if (i64.eq (i64.load (i32.const 0)) (i64.const 0x72a1048901c1485d)) | |
13 | 13 | (return) |
14 | 14 | ) |
15 | 15 | (unreachable) |
16 | 16 | ) |
tests/interface/origin.json | ||
---|---|---|
@@ -1,3 +1,14 @@ | ||
1 | 1 | { |
2 | - "origin": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b" | |
2 | + "callValue": "0x00", | |
3 | + "callData": "0x00", | |
4 | + "state": { | |
5 | + "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b": { | |
6 | + "balance": "0x056bc75e2d63100000", | |
7 | + "code": "0x00", | |
8 | + "nonce": "0x00" | |
9 | + } | |
10 | + }, | |
11 | + "origin": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b", | |
12 | + "coinbase": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b", | |
13 | + "address": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b" | |
3 | 14 | } |
tests/interface/origin.wast | ||
---|---|---|
@@ -2,15 +2,15 @@ | ||
2 | 2 | (module |
3 | 3 | (memory 1) |
4 | 4 | (import $origin "ethereum" "getTxOrigin" (param i32)) |
5 | 5 | |
6 | - (export "test" 0) | |
6 | + (export "main" 0) | |
7 | 7 | (export "a" memory) |
8 | 8 | (func |
9 | 9 | (block |
10 | 10 | ;; loads the address into memory |
11 | 11 | (call_import $origin (i32.const 0)) |
12 | - (if (i64.eq (i64.load (i32.const 0)) (i64.const 0xbd9c6f4a2d06c47b)) | |
12 | + (if (i64.eq (i64.load (i32.const 0)) (i64.const 0x72a1048901c1485d)) | |
13 | 13 | (return) |
14 | 14 | ) |
15 | 15 | (unreachable) |
16 | 16 | ) |
tests/interface/sstore.json | ||
---|---|---|
@@ -1,2 +1,14 @@ | ||
1 | 1 | { |
2 | + "callValue": "0x00", | |
3 | + "callData": "0x00", | |
4 | + "state": { | |
5 | + "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b": { | |
6 | + "balance": "0x056bc75e2d63100000", | |
7 | + "code": "0x00", | |
8 | + "nonce": "0x00" | |
9 | + } | |
10 | + }, | |
11 | + "origin": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b", | |
12 | + "coinbase": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b", | |
13 | + "address": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b" | |
2 | 14 | } |
tests/interface/sstore.wast | ||
---|---|---|
@@ -1,28 +1,33 @@ | ||
1 | 1 | ;; starts with an caller of 5d48c1018904a172886829bbbd9c6f4a2d06c47b |
2 | 2 | (module |
3 | 3 | (memory 1) |
4 | - (import $sstore "ethereum" "storageStore" (param i32 i32)) | |
5 | - (import $sload "ethereum" "storageLoad" (param i32 i32)) | |
4 | + (import $sstore "ethereum" "storageStore" (param i32 i32 i32)) | |
5 | + (import $sload "ethereum" "storageLoad" (param i32 i32 i32)) | |
6 | 6 | |
7 | - (export "test" 0) | |
7 | + (export "main" 0) | |
8 | 8 | (export "a" memory) |
9 | 9 | (func |
10 | 10 | (local $temp i64) |
11 | 11 | (block |
12 | 12 | ;; should roundtrip store and load a value from storage |
13 | 13 | (i64.store (i32.const 0) (i64.const 173553719826446289)) |
14 | - (call_import $sstore (i32.const 64) (i32.const 0)) | |
15 | - (call_import $sload (i32.const 64) (i32.const 64)) | |
14 | + (call_import $sstore (i32.const 64) (i32.const 0) (i32.const 1)) | |
15 | + ) | |
16 | + ) | |
16 | 17 | |
18 | + (export "1" 1) | |
19 | + (func | |
20 | + (block | |
21 | + (call_import $sload (i32.const 64) (i32.const 64) (i32.const 2)) | |
22 | + ) | |
23 | + ) | |
24 | + | |
25 | + (export "2" 2) | |
26 | + (func | |
27 | + (block | |
17 | 28 | (if (i64.ne (i64.load (i32.const 64)) (i64.const 173553719826446289)) |
18 | 29 | (unreachable)) |
19 | 30 | |
20 | - (i64.store (i32.const 128) (i64.const 173553719826446289)) | |
21 | - (call_import $sstore (i32.const 64) (i32.const 128)) | |
22 | - (i64.store (i32.const 128) (i64.const 173559826446289)) | |
23 | - (call_import $sload (i32.const 64) (i32.const 64)) | |
24 | - (if (i64.ne (i64.load (i32.const 64)) (i64.const 173553719826446289)) | |
25 | - (unreachable)) | |
26 | 31 | ) |
27 | 32 | ) |
28 | 33 | ) |
tests/interface/address.wasm | ||
---|---|---|
@@ -1,0 +1,3 @@ | ||
1 | + asm type@ @ import ethereum | |
2 | +getAddressfunctionmemoryexport maincode + ݐ������� h | |
3 | + |
tests/interface/balance.wasm | ||
---|---|---|
@@ -1,0 +1,6 @@ | ||
1 | + asm type | |
2 | +@ @ import ethereum | |
3 | +getBalancefunctionmemoryexport | |
4 | + main1code% | |
5 | + + ��������h | |
6 | +data ]H���r�h)���oJ-�{ |
tests/interface/basic_gas_ops.wasm | ||
---|---|---|
@@ -1,0 +1,4 @@ | ||
1 | + asm type@ @ @ import' ethereumuseGasethereum | |
2 | +getGasLeftfunctionexport testcode)' �M | |
3 | + �M | |
4 | + |
tests/interface/call.wasm | ||
---|---|---|
@@ -1,0 +1,2 @@ | ||
1 | + asm type@@ @ import ethereumcallfunctionmemoryexport | |
2 | + main1code7) 3 4����3 � 48 M |
tests/interface/callDataCopy.wasm | ||
---|---|---|
@@ -1,0 +1,3 @@ | ||
1 | + asm type | |
2 | +@ @ import ethereumcallDataCopyfunctionmemoryexport maincode#! + ��Ճ��ܲ h | |
3 | + |
tests/interface/callDataSize.wasm | ||
---|---|---|
@@ -1,0 +1,2 @@ | ||
1 | + asm type@ @ import ethereumgetCallDataSizefunctionmemory export maincode �h | |
2 | + |
tests/interface/callValue.wasm | ||
---|---|---|
@@ -1,0 +1,2 @@ | ||
1 | + asm type@ @ import ethereumgetCallValuefunctionmemoryexport maincode + ��������h | |
2 | + |
tests/interface/caller.wasm | ||
---|---|---|
@@ -1,0 +1,2 @@ | ||
1 | + asm type@ @ import ethereum getCallerfunctionmemoryexport maincode + ݐ������� h | |
2 | + |
tests/interface/coinbase.wasm | ||
---|---|---|
@@ -1,0 +1,2 @@ | ||
1 | + asm type@ @ import ethereumgetBlockCoinbasefunctionmemoryexport maincode + ݐ������� h | |
2 | + |
tests/interface/origin.wasm | ||
---|---|---|
@@ -1,0 +1,2 @@ | ||
1 | + asm type@ @ import ethereumgetTxOriginfunctionmemoryexport maincode + ݐ������� h | |
2 | + |
tests/interface/sstore.wasm | ||
---|---|---|
@@ -1,0 +1,3 @@ | ||
1 | + asm type | |
2 | +@ @ import. ethereumstorageStore ethereumstorageLoadfunctionmemoryexport main12codeG ���݄ƥ�4 � � � � + ���݄ƥ�i | |
3 | + |
tests/interfaceRunner.js | ||
---|---|---|
@@ -1,52 +1,74 @@ | ||
1 | -'use strict' | |
2 | 1 | const tape = require('tape') |
3 | 2 | const fs = require('fs') |
4 | -const cp = require('child_process') | |
5 | 3 | const path = require('path') |
4 | +const Vertex = require('merkle-trie') | |
5 | +const Address = require('../deps/address') | |
6 | +const U256 = require('../deps/u256') | |
6 | 7 | |
7 | 8 | const Kernel = require('../index.js') |
8 | -const TestEnvironment = require('../testEnvironment.js') | |
9 | -const Interface = require('../interface.js') | |
10 | -const DebugInterface = require('../debugInterface.js') | |
9 | +const Environment = require('../testEnvironment.js') | |
11 | 10 | |
12 | 11 | const dir = path.join(__dirname, '/interface') |
13 | 12 | // get the test names |
14 | 13 | let tests = fs.readdirSync(dir).filter((file) => file.endsWith('.wast')) |
15 | -// tests = ['balance.wast'] | |
16 | -// run the tests | |
17 | -for (let testName of tests) { | |
18 | - testName = testName.split('.')[0] | |
19 | - tape(testName, (t) => { | |
20 | - // Compile Command | |
21 | - cp.execSync(`${__dirname}/../tools/sexpr-wasm-prototype/out/sexpr-wasm ${dir}/${testName}.wast -o ${dir}/${testName}.wasm`) | |
22 | - const buffer = fs.readFileSync(`${dir}/${testName}.wasm`) | |
23 | - const envData = fs.readFileSync(`${dir}/${testName}.json`).toString() | |
24 | - const ethereum = new Kernel(new TestEnvironment(envData)) | |
14 | +// tests = ['callDataCopy.wast'] | |
25 | 15 | |
26 | - // manually `callHander` | |
27 | - const environment = new TestEnvironment(envData) | |
28 | - environment.parent = ethereum | |
29 | - const testContract = new Kernel(environment) | |
30 | - const ethInterface = new Interface(environment, testContract) | |
31 | - const debugInterface = new DebugInterface() | |
32 | - environment.callHandler = testContract.callHandler.bind(testContract) | |
16 | +runTests(tests) | |
33 | 17 | |
34 | - try { | |
35 | - const mod = Wasm.instantiateModule(buffer, { | |
36 | - 'ethereum': ethInterface.exportTable, | |
37 | - 'debug': debugInterface.exportTable | |
38 | - }) | |
39 | - ethInterface.setModule(mod) | |
40 | - debugInterface.setModule(mod) | |
41 | - mod.exports.test() | |
42 | - } catch (e) { | |
43 | - t.fail('Exception: ' + e) | |
44 | - console.error('FAIL') | |
45 | - console.error(e) | |
46 | - } finally { | |
47 | - t.pass(testName) | |
48 | - console.log('done') | |
49 | - } | |
50 | - t.end() | |
51 | - }) | |
18 | +function runTests (tests) { | |
19 | + for (let testName of tests) { | |
20 | + testName = testName.split('.')[0] | |
21 | + tape(testName, async (t) => { | |
22 | + // Compile Command | |
23 | + | |
24 | + const rootVertex = new Vertex() | |
25 | + const code = fs.readFileSync(`${dir}/${testName}.wasm`) | |
26 | + const envData = JSON.parse(fs.readFileSync(`${dir}/${testName}.json`).toString()) | |
27 | + | |
28 | + envData.caller = new Address(envData.caller) | |
29 | + envData.address = new Address(envData.address) | |
30 | + envData.coinbase = new Address(envData.coinbase) | |
31 | + envData.origin = new Address(envData.origin) | |
32 | + envData.callData = new Buffer(envData.callData.slice(2), 'hex') | |
33 | + envData.callValue = new U256(envData.callValue) | |
34 | + | |
35 | + for (let address in envData.state) { | |
36 | + const account = envData.state[address] | |
37 | + const accountVertex = new Vertex() | |
38 | + | |
39 | + accountVertex.set('code', new Vertex({ | |
40 | + value: new Buffer(account.code.slice(2), 'hex') | |
41 | + })) | |
42 | + | |
43 | + accountVertex.set('balance', new Vertex({ | |
44 | + value: new Buffer(account.balance.slice(2), 'hex') | |
45 | + })) | |
46 | + | |
47 | + for (let key in account.storage) { | |
48 | + accountVertex.set(['storage', ...new Buffer(key.slice(2), 'hex')], new Vertex({ | |
49 | + value: new Buffer(account.storage[key].slice(2), 'hex') | |
50 | + })) | |
51 | + } | |
52 | + | |
53 | + const path = [...new Buffer(address.slice(2), 'hex')] | |
54 | + rootVertex.set(path, accountVertex) | |
55 | + } | |
56 | + | |
57 | + envData.state = await rootVertex.get([...envData.address.toBuffer()]) | |
58 | + const kernel = new Kernel({code: code}) | |
59 | + const env = new Environment(envData) | |
60 | + | |
61 | + try { | |
62 | + await kernel.run(env) | |
63 | + } catch (e) { | |
64 | + t.fail('Exception: ' + e) | |
65 | + console.error('FAIL') | |
66 | + console.error(e) | |
67 | + } finally { | |
68 | + t.pass(testName) | |
69 | + console.log('done') | |
70 | + } | |
71 | + t.end() | |
72 | + }) | |
73 | + } | |
52 | 74 | } |
tests/buildTests.js | ||
---|---|---|
@@ -1,0 +1,14 @@ | ||
1 | +const fs = require('fs') | |
2 | +const cp = require('child_process') | |
3 | +const path = require('path') | |
4 | + | |
5 | +const dir = path.join(__dirname, '/interface') | |
6 | +// get the test names | |
7 | +let tests = fs.readdirSync(dir).filter((file) => file.endsWith('.wast')) | |
8 | +// tests = ['balance.wast'] | |
9 | +// run the tests | |
10 | +for (let testName of tests) { | |
11 | + testName = testName.split('.')[0] | |
12 | + // Compile Command | |
13 | + cp.execSync(`${__dirname}/../tools/sexpr-wasm-prototype/out/sexpr-wasm ${dir}/${testName}.wast -o ${dir}/${testName}.wasm`) | |
14 | +} |
Built with git-ssb-web