Commit 81bc698eafe0e2013602fe8f6e9aae6fe7b0ee7b
updated tests
wanderer committed on 7/15/2016, 5:33:15 PMParent: 0edfe5b10a3a58691d782ae18e443689a66cf95d
Files changed
index.js | ||
---|---|---|
@@ -19,10 +19,10 @@ | ||
19 | 19 | this.state = nameState |
20 | 20 | } |
21 | 21 | |
22 | 22 | // handles running code. |
23 | - static codeHandler (code, environment = new Environment()) { | |
24 | - const ethInterface = new Interface(environment) | |
23 | + static codeHandler (code, ethInterface = new Interface()) { | |
24 | + // const ethInterface = new Interface(environment) | |
25 | 25 | const instance = Wasm.instantiateModule(code, { |
26 | 26 | 'ethereum': ethInterface |
27 | 27 | }) |
28 | 28 | ethInterface.setModule(instance) |
@@ -35,11 +35,9 @@ | ||
35 | 35 | // loads code from the merkle trie and delegates the message |
36 | 36 | // Detects if code is EVM or WASM |
37 | 37 | // Detects if the code injection is needed |
38 | 38 | // Detects if transcompilation is needed |
39 | - static callHandler (path, data, environment) { | |
40 | - // const instance = Wasm.instantiateModule(code, interface) | |
41 | - // interface.setModule(instance) | |
39 | + static callHandler (path, data, environment = new Environment()) { | |
42 | 40 | // return instance |
43 | 41 | } |
44 | 42 | |
45 | 43 | // run tx |
interface.js | ||
---|---|---|
@@ -1,8 +1,9 @@ | ||
1 | 1 | /** |
2 | 2 | * This is the Ethereum interface that is exposed to the WASM instance which |
3 | 3 | * enables to interact with the Ethereum Environment |
4 | 4 | */ |
5 | +const Environment = require('./environment.js') | |
5 | 6 | const constants = require('./constants.js') |
6 | 7 | |
7 | 8 | // function.bind is not working corretly whith Wasm imports. So instead create |
8 | 9 | // a global for now. TODO REMOVE |
@@ -18,9 +19,9 @@ | ||
18 | 19 | memPrint () { |
19 | 20 | console.log((new Uint8Array(MOD.exports.memory)).toString()) |
20 | 21 | } |
21 | 22 | |
22 | - constructor (environment) { | |
23 | + constructor (environment = new Environment()) { | |
23 | 24 | ENV = this.environment = environment |
24 | 25 | } |
25 | 26 | |
26 | 27 | setModule (mod) { |
package.json | ||
---|---|---|
@@ -3,9 +3,9 @@ | ||
3 | 3 | "version": "0.0.0", |
4 | 4 | "description": "This is a JS prototype of the eWASM kernal.", |
5 | 5 | "scripts": { |
6 | 6 | "lint": "standard", |
7 | - "test": "node --expose-wasm ./tests/runner.js" | |
7 | + "test": "node --expose-wasm ./tests/interfaceRunner.js" | |
8 | 8 | }, |
9 | 9 | "repository": { |
10 | 10 | "type": "git", |
11 | 11 | "url": "git+https://github.com/ethereumjs/ewasm-kernel.git" |
tests/address.json | ||
---|---|---|
@@ -1,3 +1,0 @@ | ||
1 | -{ | |
2 | - "address": [93,72,193,1,137,4,161,114,136,104,41,187,189,156,111,74,45,6,196,123] | |
3 | -} |
tests/interface/address.json | ||
---|---|---|
@@ -1,0 +1,3 @@ | ||
1 | +{ | |
2 | + "address": [93,72,193,1,137,4,161,114,136,104,41,187,189,156,111,74,45,6,196,123] | |
3 | +} |
tests/interface/address.wast | ||
---|---|---|
@@ -1,0 +1,18 @@ | ||
1 | +;; starts with an address of 5d48c1018904a172886829bbbd9c6f4a2d06c47b | |
2 | +(module | |
3 | + (memory 1) | |
4 | + | |
5 | + (import $address "ethereum" "address" (param i32)) | |
6 | + (export "test" 0) | |
7 | + (export "a" memory) | |
8 | + (func | |
9 | + (block | |
10 | + ;; loads the address into memory | |
11 | + (call_import $address (i32.const 0)) | |
12 | + (if (i64.eq (i64.load (i32.const 0)) (i64.const 0x72a1048901c1485d)) ;; big enden | |
13 | + (return) | |
14 | + ) | |
15 | + (unreachable) | |
16 | + ) | |
17 | + ) | |
18 | +) |
tests/interface/balance.json | ||
---|---|---|
@@ -1,0 +1,9 @@ | ||
1 | +{ | |
2 | + "accounts": [ | |
3 | + [ | |
4 | + [93, 72, 193, 1, 137, 4, 161, 114, 136, 104, 41, 187, 189, 156, 111, 74, 45, 6, 196, 123], { | |
5 | + "balance": [100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] | |
6 | + } | |
7 | + ] | |
8 | + ] | |
9 | +} |
tests/interface/balance.wast | ||
---|---|---|
@@ -1,0 +1,19 @@ | ||
1 | +;; address of 5d48c1018904a172886829bbbd9c6f4a2d06c47b has a balance of 100 | |
2 | +(module | |
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" "balance" (param i32 i32)) | |
5 | + (export "a" memory) | |
6 | + (export "test" 0) | |
7 | + (func | |
8 | + (block | |
9 | + (call_import $balance (i32.const 0) (i32.const 0)) | |
10 | + (if (i64.eq (i64.load (i32.const 0)) (i64.const 100)) | |
11 | + (if (i64.eq (i64.load (i32.const 8)) (i64.const 0)) | |
12 | + (return) | |
13 | + ) | |
14 | + ) | |
15 | + (unreachable) | |
16 | + ) | |
17 | + ) | |
18 | +) | |
19 | + |
tests/interface/basic_gas_ops.wast | ||
---|---|---|
@@ -1,0 +1,40 @@ | ||
1 | +;; starts with 1000 gas | |
2 | +(module | |
3 | + (import $addGas "ethereum" "addGas" (param i32)) | |
4 | + (import $gasUsed "ethereum" "gasUsed" (result i64)) | |
5 | + (import $gasLeft "ethereum" "gasLeft" (result i64)) | |
6 | + | |
7 | + (export "test" 0) | |
8 | + (func | |
9 | + ;; test adding gas | |
10 | + (block | |
11 | + (call_import $addGas (i32.const 1)) | |
12 | + (if (i64.eq (call_import $gasUsed) (i64.const 1)) | |
13 | + (return) | |
14 | + ) | |
15 | + (unreachable) | |
16 | + ) | |
17 | + (block | |
18 | + (call_import $addGas (i32.const 1)) | |
19 | + (if (i64.eq (call_import $gasUsed) (i64.const 2)) | |
20 | + (return) | |
21 | + ) | |
22 | + (unreachable) | |
23 | + ) | |
24 | + ;; should disregard negative values | |
25 | + (block | |
26 | + (call_import $addGas (i32.const -1)) | |
27 | + (if (i64.eq (call_import $gasUsed) (i64.const 2)) | |
28 | + (return) | |
29 | + ) | |
30 | + (unreachable) | |
31 | + ) | |
32 | + ;; gas left | |
33 | + (block | |
34 | + (if (i64.eq (call_import $gasLeft) (i64.const 998)) | |
35 | + (return) | |
36 | + ) | |
37 | + (unreachable) | |
38 | + ) | |
39 | + ) | |
40 | +) |
tests/interface/callDataSize.json | ||
---|---|---|
@@ -1,0 +1,3 @@ | ||
1 | +{ | |
2 | + "callData": "596f75206172652077616974696e6720666f7220746865207265766f6c7574696f6e3f204c657420697420626521204d79206f776e20626567616e2061206c6f6e672074696d652061676f21205768656e20796f752077696c6c2062652072656164792e2e2e4920776f6ee2809974206d696e6420676f696e6720616c6f6e67207769746820796f7520666f722061207768696c652e20427574207768656e20796f75e280996c6c2073746f702c2049207368616c6c20636f6e74696e7565206f6e206d7920696e73616e6520616e6420747269756d7068616e742077617920746f776172642074686520677265617420616e64207375626c696d6520636f6e7175657374206f6620746865206e6f7468696e6721" | |
3 | +} |
tests/interface/callDataSize.wast | ||
---|---|---|
@@ -1,0 +1,14 @@ | ||
1 | +(module | |
2 | + (memory 1000) | |
3 | + (import $callDataSize "ethereum" "callDataSize" (result i64)) | |
4 | + | |
5 | + (export "test" 0) | |
6 | + (func | |
7 | + (block | |
8 | + (if (i64.eq (call_import $callDataSize) (i64.const 277)) | |
9 | + (return) | |
10 | + ) | |
11 | + (unreachable) | |
12 | + ) | |
13 | + ) | |
14 | +) |
tests/interface/callValue.wast | ||
---|---|---|
@@ -1,0 +1,19 @@ | ||
1 | +;; call value of 100 | |
2 | +(module | |
3 | + (memory 1) | |
4 | + (import $callValue "ethereum" "callValue" (param i32)) | |
5 | + | |
6 | + (export "a" memory) | |
7 | + (export "test" 0) | |
8 | + (func | |
9 | + (block | |
10 | + (call_import $callValue (i32.const 0)) | |
11 | + (if (i64.eq (i64.load (i32.const 0)) (i64.const 100)) | |
12 | + (if (i64.eq (i64.load (i32.const 8)) (i64.const 0)) | |
13 | + (return) | |
14 | + ) | |
15 | + ) | |
16 | + (unreachable) | |
17 | + ) | |
18 | + ) | |
19 | +) |
tests/interface/caller.json | ||
---|---|---|
@@ -1,0 +1,3 @@ | ||
1 | +{ | |
2 | + "caller": [93,72,193,1,137,4,161,114,136,104,41,187,189,156,111,74,45,6,196,123] | |
3 | +} |
tests/interface/caller.wast | ||
---|---|---|
@@ -1,0 +1,18 @@ | ||
1 | +;; starts with an caller of 5d48c1018904a172886829bbbd9c6f4a2d06c47b | |
2 | +(module | |
3 | + (memory 1) | |
4 | + (import $caller "ethereum" "caller" (param i32)) | |
5 | + | |
6 | + (export "test" 0) | |
7 | + (export "a" memory) | |
8 | + (func | |
9 | + (block | |
10 | + ;; loads the caller into memory | |
11 | + (call_import $caller (i32.const 0)) | |
12 | + (if (i64.eq (i64.load (i32.const 0)) (i64.const 0x72a1048901c1485d)) | |
13 | + (return) | |
14 | + ) | |
15 | + (unreachable) | |
16 | + ) | |
17 | + ) | |
18 | +) |
tests/interface/default_enviroment.json | ||
---|---|---|
@@ -1,0 +1,15 @@ | ||
1 | +enviroment: { | |
2 | + gasCounter: 0, | |
3 | + gas: 0, | |
4 | + gasPrice: 0, | |
5 | + gasLimit: 0, | |
6 | + address: [], | |
7 | + origin: [], | |
8 | + coinbase: [], | |
9 | + difficulty: [], | |
10 | + caller: [], | |
11 | + callValue: [], | |
12 | + callData: [], | |
13 | + code: [], | |
14 | + logs: [] | |
15 | +} |
tests/interface/origin.json | ||
---|---|---|
@@ -1,0 +1,3 @@ | ||
1 | +{ | |
2 | + "origin": [93,72,193,1,137,4,161,114,136,104,41,187,189,156,111,74,45,6,196,123] | |
3 | +} |
tests/interface/origin.wast | ||
---|---|---|
@@ -1,0 +1,18 @@ | ||
1 | +;; starts with an origin of 5d48c1018904a172886829bbbd9c6f4a2d06c47b | |
2 | +(module | |
3 | + (memory 1) | |
4 | + (import $origin "ethereum" "origin" (param i32)) | |
5 | + | |
6 | + (export "test" 0) | |
7 | + (export "a" memory) | |
8 | + (func | |
9 | + (block | |
10 | + ;; loads the address into memory | |
11 | + (call_import $origin (i32.const 0)) | |
12 | + (if (i64.eq (i64.load (i32.const 0)) (i64.const 0x72a1048901c1485d)) | |
13 | + (return) | |
14 | + ) | |
15 | + (unreachable) | |
16 | + ) | |
17 | + ) | |
18 | +) |
tests/interface/sstore.wast | ||
---|---|---|
@@ -1,0 +1,24 @@ | ||
1 | +;; starts with an caller of 5d48c1018904a172886829bbbd9c6f4a2d06c47b | |
2 | +(module | |
3 | + (memory 1) | |
4 | + (import $sstore "ethereum" "sstore" (param i32 i32)) | |
5 | + (import $sload "ethereum" "sload" (param i32 i32)) | |
6 | + | |
7 | + (export "test" 0) | |
8 | + (export "a" memory) | |
9 | + (func | |
10 | + (local $temp i64) | |
11 | + (block | |
12 | + ;; should roundtrip store and load a value from storage | |
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)) | |
16 | + (set_local $temp | |
17 | + (i64.load (i32.const 64))) | |
18 | + | |
19 | + (if (i64.eq (i64.load (i32.const 0)) (i64.const 173553719826446289)) | |
20 | + (return)) | |
21 | + (unreachable) | |
22 | + ) | |
23 | + ) | |
24 | +) |
tests/address.wast | ||
---|---|---|
@@ -1,18 +1,0 @@ | ||
1 | -;; starts with an address of 5d48c1018904a172886829bbbd9c6f4a2d06c47b | |
2 | -(module | |
3 | - (memory 1) | |
4 | - | |
5 | - (import $address "ethereum" "address" (param i32)) | |
6 | - (export "test" 0) | |
7 | - (export "a" memory) | |
8 | - (func | |
9 | - (block | |
10 | - ;; loads the address into memory | |
11 | - (call_import $address (i32.const 0)) | |
12 | - (if (i64.eq (i64.load (i32.const 0)) (i64.const 0x72a1048901c1485d)) ;; big enden | |
13 | - (return) | |
14 | - ) | |
15 | - (unreachable) | |
16 | - ) | |
17 | - ) | |
18 | -) |
tests/interfaceRunner.js | ||
---|---|---|
@@ -1,0 +1,38 @@ | ||
1 | +'use strict' | |
2 | +const tape = require('tape') | |
3 | +const fs = require('fs') | |
4 | +const cp = require('child_process') | |
5 | + | |
6 | +const Environment = require('../environment.js') | |
7 | +const Interface = require('../interface.js') | |
8 | +const dir = __dirname + '/interface' | |
9 | +// get the test names | |
10 | +let tests = fs.readdirSync(dir).filter((file) => file.endsWith('.wast')) | |
11 | +// tests = ['balance.wast'] | |
12 | +// run the tests | |
13 | +for (let testName of tests) { | |
14 | + testName = testName.split('.')[0] | |
15 | + tape(testName, (t) => { | |
16 | + // Compile Command | |
17 | + cp.execSync(`${__dirname}/../../evm-wasm-transcompiler/deps/sexpr-wasm-prototype/out/sexpr-wasm ${dir}/${testName}.wast -o ${dir}/${testName}.wasm`) | |
18 | + const buffer = fs.readFileSync(`${dir}/${testName}.wasm`) | |
19 | + const envData = fs.readFileSync(`${dir}/${testName}.json`) | |
20 | + | |
21 | + const environment = new Environment(envData) | |
22 | + const ethInterface = new Interface(environment) | |
23 | + | |
24 | + try { | |
25 | + const mod = Wasm.instantiateModule(buffer, {'ethereum': ethInterface}) | |
26 | + ethInterface.setModule(mod) | |
27 | + // ethInterface.address(0) | |
28 | + // console.log(ethInterface.environment); | |
29 | + mod.exports.test() | |
30 | + } catch (e) { | |
31 | + console.error('FAIL') | |
32 | + console.error(e) | |
33 | + } finally { | |
34 | + console.log('done') | |
35 | + } | |
36 | + t.end() | |
37 | + }) | |
38 | +} |
tests/balance.json | ||
---|---|---|
@@ -1,9 +1,0 @@ | ||
1 | -{ | |
2 | - "accounts": [ | |
3 | - [ | |
4 | - [93, 72, 193, 1, 137, 4, 161, 114, 136, 104, 41, 187, 189, 156, 111, 74, 45, 6, 196, 123], { | |
5 | - "balance": [100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] | |
6 | - } | |
7 | - ] | |
8 | - ] | |
9 | -} |
tests/balance.wast | ||
---|---|---|
@@ -1,19 +1,0 @@ | ||
1 | -;; address of 5d48c1018904a172886829bbbd9c6f4a2d06c47b has a balance of 100 | |
2 | -(module | |
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" "balance" (param i32 i32)) | |
5 | - (export "a" memory) | |
6 | - (export "test" 0) | |
7 | - (func | |
8 | - (block | |
9 | - (call_import $balance (i32.const 0) (i32.const 0)) | |
10 | - (if (i64.eq (i64.load (i32.const 0)) (i64.const 100)) | |
11 | - (if (i64.eq (i64.load (i32.const 8)) (i64.const 0)) | |
12 | - (return) | |
13 | - ) | |
14 | - ) | |
15 | - (unreachable) | |
16 | - ) | |
17 | - ) | |
18 | -) | |
19 | - |
tests/basic_gas_ops.wast | ||
---|---|---|
@@ -1,40 +1,0 @@ | ||
1 | -;; starts with 1000 gas | |
2 | -(module | |
3 | - (import $addGas "ethereum" "addGas" (param i32)) | |
4 | - (import $gasUsed "ethereum" "gasUsed" (result i64)) | |
5 | - (import $gasLeft "ethereum" "gasLeft" (result i64)) | |
6 | - | |
7 | - (export "test" 0) | |
8 | - (func | |
9 | - ;; test adding gas | |
10 | - (block | |
11 | - (call_import $addGas (i32.const 1)) | |
12 | - (if (i64.eq (call_import $gasUsed) (i64.const 1)) | |
13 | - (return) | |
14 | - ) | |
15 | - (unreachable) | |
16 | - ) | |
17 | - (block | |
18 | - (call_import $addGas (i32.const 1)) | |
19 | - (if (i64.eq (call_import $gasUsed) (i64.const 2)) | |
20 | - (return) | |
21 | - ) | |
22 | - (unreachable) | |
23 | - ) | |
24 | - ;; should disregard negative values | |
25 | - (block | |
26 | - (call_import $addGas (i32.const -1)) | |
27 | - (if (i64.eq (call_import $gasUsed) (i64.const 2)) | |
28 | - (return) | |
29 | - ) | |
30 | - (unreachable) | |
31 | - ) | |
32 | - ;; gas left | |
33 | - (block | |
34 | - (if (i64.eq (call_import $gasLeft) (i64.const 998)) | |
35 | - (return) | |
36 | - ) | |
37 | - (unreachable) | |
38 | - ) | |
39 | - ) | |
40 | -) |
tests/callDataSize.json | ||
---|---|---|
@@ -1,3 +1,0 @@ | ||
1 | -{ | |
2 | - "callData": "596f75206172652077616974696e6720666f7220746865207265766f6c7574696f6e3f204c657420697420626521204d79206f776e20626567616e2061206c6f6e672074696d652061676f21205768656e20796f752077696c6c2062652072656164792e2e2e4920776f6ee2809974206d696e6420676f696e6720616c6f6e67207769746820796f7520666f722061207768696c652e20427574207768656e20796f75e280996c6c2073746f702c2049207368616c6c20636f6e74696e7565206f6e206d7920696e73616e6520616e6420747269756d7068616e742077617920746f776172642074686520677265617420616e64207375626c696d6520636f6e7175657374206f6620746865206e6f7468696e6721" | |
3 | -} |
tests/callDataSize.wast | ||
---|---|---|
@@ -1,14 +1,0 @@ | ||
1 | -(module | |
2 | - (memory 1000) | |
3 | - (import $callDataSize "ethereum" "callDataSize" (result i64)) | |
4 | - | |
5 | - (export "test" 0) | |
6 | - (func | |
7 | - (block | |
8 | - (if (i64.eq (call_import $callDataSize) (i64.const 277)) | |
9 | - (return) | |
10 | - ) | |
11 | - (unreachable) | |
12 | - ) | |
13 | - ) | |
14 | -) |
tests/callValue.wast | ||
---|---|---|
@@ -1,19 +1,0 @@ | ||
1 | -;; call value of 100 | |
2 | -(module | |
3 | - (memory 1) | |
4 | - (import $callValue "ethereum" "callValue" (param i32)) | |
5 | - | |
6 | - (export "a" memory) | |
7 | - (export "test" 0) | |
8 | - (func | |
9 | - (block | |
10 | - (call_import $callValue (i32.const 0)) | |
11 | - (if (i64.eq (i64.load (i32.const 0)) (i64.const 100)) | |
12 | - (if (i64.eq (i64.load (i32.const 8)) (i64.const 0)) | |
13 | - (return) | |
14 | - ) | |
15 | - ) | |
16 | - (unreachable) | |
17 | - ) | |
18 | - ) | |
19 | -) |
tests/caller.json | ||
---|---|---|
@@ -1,3 +1,0 @@ | ||
1 | -{ | |
2 | - "caller": [93,72,193,1,137,4,161,114,136,104,41,187,189,156,111,74,45,6,196,123] | |
3 | -} |
tests/caller.wast | ||
---|---|---|
@@ -1,18 +1,0 @@ | ||
1 | -;; starts with an caller of 5d48c1018904a172886829bbbd9c6f4a2d06c47b | |
2 | -(module | |
3 | - (memory 1) | |
4 | - (import $caller "ethereum" "caller" (param i32)) | |
5 | - | |
6 | - (export "test" 0) | |
7 | - (export "a" memory) | |
8 | - (func | |
9 | - (block | |
10 | - ;; loads the caller into memory | |
11 | - (call_import $caller (i32.const 0)) | |
12 | - (if (i64.eq (i64.load (i32.const 0)) (i64.const 0x72a1048901c1485d)) | |
13 | - (return) | |
14 | - ) | |
15 | - (unreachable) | |
16 | - ) | |
17 | - ) | |
18 | -) |
tests/default_enviroment.json | ||
---|---|---|
@@ -1,15 +1,0 @@ | ||
1 | -enviroment: { | |
2 | - gasCounter: 0, | |
3 | - gas: 0, | |
4 | - gasPrice: 0, | |
5 | - gasLimit: 0, | |
6 | - address: [], | |
7 | - origin: [], | |
8 | - coinbase: [], | |
9 | - difficulty: [], | |
10 | - caller: [], | |
11 | - callValue: [], | |
12 | - callData: [], | |
13 | - code: [], | |
14 | - logs: [] | |
15 | -} |
tests/origin.json | ||
---|---|---|
@@ -1,3 +1,0 @@ | ||
1 | -{ | |
2 | - "origin": [93,72,193,1,137,4,161,114,136,104,41,187,189,156,111,74,45,6,196,123] | |
3 | -} |
tests/origin.wast | ||
---|---|---|
@@ -1,18 +1,0 @@ | ||
1 | -;; starts with an origin of 5d48c1018904a172886829bbbd9c6f4a2d06c47b | |
2 | -(module | |
3 | - (memory 1) | |
4 | - (import $origin "ethereum" "origin" (param i32)) | |
5 | - | |
6 | - (export "test" 0) | |
7 | - (export "a" memory) | |
8 | - (func | |
9 | - (block | |
10 | - ;; loads the address into memory | |
11 | - (call_import $origin (i32.const 0)) | |
12 | - (if (i64.eq (i64.load (i32.const 0)) (i64.const 0x72a1048901c1485d)) | |
13 | - (return) | |
14 | - ) | |
15 | - (unreachable) | |
16 | - ) | |
17 | - ) | |
18 | -) |
tests/runner.js | ||
---|---|---|
@@ -1,39 +1,0 @@ | ||
1 | -'use strict' | |
2 | -const tape = require('tape') | |
3 | -const fs = require('fs') | |
4 | -const cp = require('child_process') | |
5 | - | |
6 | -// This | |
7 | -const Environment = require('../environment.js') | |
8 | -const Interface = require('../interface.js') | |
9 | -// console.log('tes1 11') | |
10 | -// get the test names | |
11 | -let tests = fs.readdirSync(__dirname).filter((file) => file.endsWith('.wast')) | |
12 | -// tests = ['balance.wast'] | |
13 | -// run the tests | |
14 | -for (let testName of tests) { | |
15 | - testName = testName.split('.')[0] | |
16 | - tape(testName, (t) => { | |
17 | - // Compile Command | |
18 | - cp.execSync(`${__dirname}/../../evm-wasm-transcompiler/deps/sexpr-wasm-prototype/out/sexpr-wasm ${__dirname}/${testName}.wast -o ${__dirname}/${testName}.wasm`) | |
19 | - const buffer = fs.readFileSync(`${__dirname}/${testName}.wasm`) | |
20 | - const envData = fs.readFileSync(`${__dirname}/${testName}.json`) | |
21 | - | |
22 | - const environment = new Environment(envData) | |
23 | - const ethInterface = new Interface(environment) | |
24 | - | |
25 | - try { | |
26 | - const mod = Wasm.instantiateModule(buffer, {'ethereum': ethInterface}) | |
27 | - ethInterface.setModule(mod) | |
28 | - // ethInterface.address(0) | |
29 | - // console.log(ethInterface.environment); | |
30 | - mod.exports.test() | |
31 | - } catch (e) { | |
32 | - console.error('FAIL') | |
33 | - console.error(e) | |
34 | - } finally { | |
35 | - console.log('done') | |
36 | - } | |
37 | - t.end() | |
38 | - }) | |
39 | -} |
tests/sstore.wast | ||
---|---|---|
@@ -1,24 +1,0 @@ | ||
1 | -;; starts with an caller of 5d48c1018904a172886829bbbd9c6f4a2d06c47b | |
2 | -(module | |
3 | - (memory 1) | |
4 | - (import $sstore "ethereum" "sstore" (param i32 i32)) | |
5 | - (import $sload "ethereum" "sload" (param i32 i32)) | |
6 | - | |
7 | - (export "test" 0) | |
8 | - (export "a" memory) | |
9 | - (func | |
10 | - (local $temp i64) | |
11 | - (block | |
12 | - ;; should roundtrip store and load a value from storage | |
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)) | |
16 | - (set_local $temp | |
17 | - (i64.load (i32.const 64))) | |
18 | - | |
19 | - (if (i64.eq (i64.load (i32.const 0)) (i64.const 173553719826446289)) | |
20 | - (return)) | |
21 | - (unreachable) | |
22 | - ) | |
23 | - ) | |
24 | -) |
Built with git-ssb-web