git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 5548f3620a5008e9db6bdfac769a29fd4616c5f4

fix all tests

wanderer committed on 11/22/2016, 2:02:40 AM
Parent: e0e6608f9df71b679e52c4d0916732e4e8201fc2

Files changed

EVMinterface.jschanged
environment.jschanged
package.jsonchanged
testEnvironment.jschanged
tests/interface/address.jsonchanged
tests/interface/address.wastchanged
tests/interface/balance.jsonchanged
tests/interface/balance.wastchanged
tests/interface/basic_gas_ops.jsonchanged
tests/interface/call.jsonchanged
tests/interface/call.wastchanged
tests/interface/callDataCopy.jsonchanged
tests/interface/callDataCopy.wastchanged
tests/interface/callDataSize.jsonchanged
tests/interface/callDataSize.wastchanged
tests/interface/callValue.jsonchanged
tests/interface/callValue.wastchanged
tests/interface/caller.jsonchanged
tests/interface/caller.wastchanged
tests/interface/coinbase.jsonchanged
tests/interface/coinbase.wastchanged
tests/interface/origin.jsonchanged
tests/interface/origin.wastchanged
tests/interface/sstore.jsonchanged
tests/interface/sstore.wastchanged
tests/interface/address.wasmadded
tests/interface/balance.wasmadded
tests/interface/basic_gas_ops.wasmadded
tests/interface/call.wasmadded
tests/interface/callDataCopy.wasmadded
tests/interface/callDataSize.wasmadded
tests/interface/callValue.wasmadded
tests/interface/caller.wasmadded
tests/interface/coinbase.wasmadded
tests/interface/origin.wasmadded
tests/interface/sstore.wasmadded
tests/interfaceRunner.jschanged
tests/buildTests.jsadded
EVMinterface.jsView
@@ -336,9 +336,9 @@
336336 */
337337 getBlockCoinbase (offset) {
338338 this.takeGas(2)
339339
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())
341341 }
342342
343343 /**
344344 * Get the block’s timestamp.
@@ -460,15 +460,15 @@
460460 * @param {integer} gas
461461 * @return {integer} Returns 1 or 0 depending on if the VM trapped on the message or not
462462 */
463463 _call (gasHigh, gasLow, addressOffset, valueOffset, dataOffset, dataLength, resultOffset, resultLength, cbIndex) {
464+ this.takeGas(40)
465+
464466 const gas = from64bit(gasHigh, gasLow)
465467 // Load the params from mem
466468 const address = [...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES)]
467469 const value = new U256(this.getMemory(valueOffset, U128_SIZE_BYTES))
468470
469- this.takeGas(40)
470-
471471 // Special case for non-zero value; why does this exist?
472472 if (!value.isZero()) {
473473 this.takeGas(9000 - 2300 + gas)
474474 this.takeGas(-gas)
environment.jsView
@@ -30,24 +30,11 @@
3030 // more output calls
3131 returnValue: new Uint8Array(),
3232 state: new Vertex({store: new Store()})
3333 }
34- // this.environment.addAccount(identityContract, {})
35- // this.environment.addAccount(meteringContract, {})
36- // this.environment.addAccount(transcompilerContract, {})
37-
3834 Object.assign(this, defaults, data)
3935 }
4036
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-
5037 isAccountPresent (address) {
5138 // const account = this.state.get(address.toString())
5239 // if (account) {
5340 // return true
package.jsonView
@@ -4,8 +4,9 @@
44 "description": "This is a JS prototype of the eWASM kernal.",
55 "scripts": {
66 "lint": "standard",
77 "test": "node --expose-wasm ./tests/interfaceRunner.js"
8+ "build": "node ./tests/buildTests.js"
89 },
910 "repository": {
1011 "type": "git",
1112 "url": "git+https://github.com/ewasm/ewasm-kernel.git"
testEnvironment.jsView
@@ -1,9 +1,8 @@
11 const Environment = require('./environment.js')
22 const fakeBlockchain = require('./fakeBlockChain')
33
44 module.exports = class TestEnvironment extends Environment {
5-
65 async getBlockHash (height) {
76 return fakeBlockchain.getBlock(height).hash()
87 }
98 }
tests/interface/address.jsonView
@@ -1,3 +1,13 @@
11 {
2+ "callValue": "0x00",
3+ "callData": "0x00",
4+ "state": {
5+ "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b": {
6+ "balance": "0x056bc75e2d63100000",
7+ "code": "0x00",
8+ "nonce": "0x00"
9+ }
10+ },
11+ "coinbase": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b",
212 "address": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b"
313 }
tests/interface/address.wastView
@@ -2,15 +2,15 @@
22 (module
33 (memory 1)
44
55 (import $address "ethereum" "getAddress" (param i32))
6- (export "test" 0)
6+ (export "main" 0)
77 (export "a" memory)
88 (func
99 (block
1010 ;; loads the address into memory
1111 (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))
1313 (return)
1414 )
1515 (unreachable)
1616 )
tests/interface/balance.jsonView
@@ -1,9 +1,13 @@
11 {
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"
69 }
7- ]
8- ]
10+ },
11+ "coinbase": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b",
12+ "address": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b"
913 }
tests/interface/balance.wastView
@@ -1,17 +1,19 @@
11 ;; address of 5d48c1018904a172886829bbbd9c6f4a2d06c47b has a balance of 0x056bc75e2d63100000 (100 ETH)
22 (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))
55 (export "a" memory)
6- (export "test" 0)
6+ (export "main" 0)
77 (func
8+ (call_import $balance (i32.const 0) (i32.const 0) (i32.const 1))
9+ )
10+
11+ (export "1" 1)
12+ (func
813 (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)
1416 )
1517 (unreachable)
1618 )
1719 )
tests/interface/basic_gas_ops.jsonView
@@ -1,3 +1,14 @@
11 {
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",
213 "gasLeft": 1000
314 }
tests/interface/call.jsonView
@@ -1,3 +1,13 @@
11 {
2+ "callValue": "0x00",
3+ "callData": "0x00",
4+ "state": {
5+ "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b": {
6+ "balance": "0x056bc75e2d63100000",
7+ "code": "0x00",
8+ "nonce": "0x00"
9+ }
10+ },
11+ "coinbase": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b",
212 "address": "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b"
313 }
tests/interface/call.wastView
@@ -1,11 +1,11 @@
11 ;; starts with an address of 5d48c1018904a172886829bbbd9c6f4a2d06c47b
22 (module
33 (memory 1)
44
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))
76 (export "a" memory)
7+ (export "main" 0)
88 (func
99 (block
1010 ;; Memory layout:
1111 ;; 0 - 20 bytes: address (4)
@@ -13,13 +13,16 @@
1313 ;; 52 - 56 bytes: data (0x42004200)
1414 ;; 56 - 60 bytes: result
1515 (i32.store (i32.const 0) (i32.const 0x4))
1616 (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))
2318 )
2419 )
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+ )
2528 )
tests/interface/callDataCopy.jsonView
@@ -1,3 +1,13 @@
11 {
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"
313 }
tests/interface/callDataCopy.wastView
@@ -3,13 +3,12 @@
33 (memory 1)
44 (import $callDataCopy "ethereum" "callDataCopy" (param i32 i32 i32))
55
66 (export "memory" memory)
7- (export "test" 0)
7+ (export "main" 0)
88 (func
99 (block
1010 (call_import $callDataCopy (i32.const 0) (i32.const 0) (i32.const 8))
11-
1211 (if (i64.eq (i64.load (i32.const 0)) (i64.const 0x2065726120756f59))
1312 (return)
1413 )
1514 (unreachable)
tests/interface/callDataSize.jsonView
@@ -1,3 +1,13 @@
11 {
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"
313 }
tests/interface/callDataSize.wastView
@@ -1,9 +1,9 @@
11 (module
22 (memory 1)
33 (import $callDataSize "ethereum" "getCallDataSize" (result i64))
44
5- (export "test" 0)
5+ (export "main" 0)
66 (func
77 (block
88 (if (i64.eq (call_import $callDataSize) (i64.const 277))
99 (return)
tests/interface/callValue.jsonView
@@ -1,3 +1,13 @@
11 {
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"
313 }
tests/interface/callValue.wastView
@@ -3,16 +3,14 @@
33 (memory 1)
44 (import $callValue "ethereum" "getCallValue" (param i32))
55
66 (export "a" memory)
7- (export "test" 0)
7+ (export "main" 0)
88 (func
99 (block
1010 (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)
1513 )
1614 (unreachable)
1715 )
1816 )
tests/interface/caller.jsonView
@@ -1,3 +1,14 @@
11 {
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"
314 }
tests/interface/caller.wastView
@@ -2,15 +2,15 @@
22 (module
33 (memory 1)
44 (import $caller "ethereum" "getCaller" (param i32))
55
6- (export "test" 0)
6+ (export "main" 0)
77 (export "a" memory)
88 (func
99 (block
1010 ;; loads the caller into memory
1111 (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))
1313 (return)
1414 )
1515 (unreachable)
1616 )
tests/interface/coinbase.jsonView
@@ -1,5 +1,13 @@
11 {
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"
513 }
tests/interface/coinbase.wastView
@@ -2,15 +2,15 @@
22 (module
33 (memory 1)
44
55 (import $coinbase "ethereum" "getBlockCoinbase" (param i32))
6- (export "test" 0)
6+ (export "main" 0)
77 (export "a" memory)
88 (func
99 (block
1010 ;; loads the coinbase into memory
1111 (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))
1313 (return)
1414 )
1515 (unreachable)
1616 )
tests/interface/origin.jsonView
@@ -1,3 +1,14 @@
11 {
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"
314 }
tests/interface/origin.wastView
@@ -2,15 +2,15 @@
22 (module
33 (memory 1)
44 (import $origin "ethereum" "getTxOrigin" (param i32))
55
6- (export "test" 0)
6+ (export "main" 0)
77 (export "a" memory)
88 (func
99 (block
1010 ;; loads the address into memory
1111 (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))
1313 (return)
1414 )
1515 (unreachable)
1616 )
tests/interface/sstore.jsonView
@@ -1,2 +1,14 @@
11 {
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"
214 }
tests/interface/sstore.wastView
@@ -1,28 +1,33 @@
11 ;; starts with an caller of 5d48c1018904a172886829bbbd9c6f4a2d06c47b
22 (module
33 (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))
66
7- (export "test" 0)
7+ (export "main" 0)
88 (export "a" memory)
99 (func
1010 (local $temp i64)
1111 (block
1212 ;; should roundtrip store and load a value from storage
1313 (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+ )
1617
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
1728 (if (i64.ne (i64.load (i32.const 64)) (i64.const 173553719826446289))
1829 (unreachable))
1930
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))
2631 )
2732 )
2833 )
tests/interface/address.wasmView
@@ -1,0 +1,3 @@
1+asm type@@importethereum
2+getAddressfunctionmemoryexportmaincode +ݐ�������h 
3+
tests/interface/balance.wasmView
@@ -1,0 +1,6 @@
1+asm type
2+@@importethereum
3+getBalancefunctionmemoryexport
4+main1code%
5++��������h 
6+data]H���r�h)���oJ-�{
tests/interface/basic_gas_ops.wasmView
@@ -1,0 +1,4 @@
1+asm type @@@import'ethereumuseGasethereum
2+getGasLeftfunctionexporttestcode)'�M 
3+�M 
4+
tests/interface/call.wasmView
@@ -1,0 +1,2 @@
1+asm type@@@importethereumcallfunctionmemoryexport
2+main1code7)34����3�48 M 
tests/interface/callDataCopy.wasmView
@@ -1,0 +1,3 @@
1+asm type
2+@@importethereum callDataCopyfunctionmemoryexportmaincode#!+��Ճ��ܲ h 
3+
tests/interface/callDataSize.wasmView
@@ -1,0 +1,2 @@
1+asm type@@importethereumgetCallDataSizefunctionmemoryexportmaincode�h 
2+
tests/interface/callValue.wasmView
@@ -1,0 +1,2 @@
1+asm type@@importethereum getCallValuefunctionmemoryexportmaincode+��������h 
2+
tests/interface/caller.wasmView
@@ -1,0 +1,2 @@
1+asm type@@importethereum getCallerfunctionmemoryexportmaincode +ݐ�������h 
2+
tests/interface/coinbase.wasmView
@@ -1,0 +1,2 @@
1+asm type@@importethereumgetBlockCoinbasefunctionmemoryexportmaincode +ݐ�������h 
2+
tests/interface/origin.wasmView
@@ -1,0 +1,2 @@
1+asm type@@importethereum getTxOriginfunctionmemoryexportmaincode +ݐ�������h 
2+
tests/interface/sstore.wasmView
@@ -1,0 +1,3 @@
1+asm type
2+@@import.ethereum storageStoreethereum storageLoadfunctionmemoryexport main12codeG���݄ƥ�4����+���݄ƥ�i
3+
tests/interfaceRunner.jsView
@@ -1,52 +1,74 @@
1-'use strict'
21 const tape = require('tape')
32 const fs = require('fs')
4-const cp = require('child_process')
53 const path = require('path')
4+const Vertex = require('merkle-trie')
5+const Address = require('../deps/address')
6+const U256 = require('../deps/u256')
67
78 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')
1110
1211 const dir = path.join(__dirname, '/interface')
1312 // get the test names
1413 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']
2515
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)
3317
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+ }
5274 }
tests/buildTests.jsView
@@ -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