git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 81bc698eafe0e2013602fe8f6e9aae6fe7b0ee7b

updated tests

wanderer committed on 7/15/2016, 5:33:15 PM
Parent: 0edfe5b10a3a58691d782ae18e443689a66cf95d

Files changed

index.jschanged
interface.jschanged
package.jsonchanged
tests/address.jsondeleted
tests/interface/address.jsonadded
tests/interface/address.wastadded
tests/interface/balance.jsonadded
tests/interface/balance.wastadded
tests/interface/basic_gas_ops.jsonadded
tests/interface/basic_gas_ops.wastadded
tests/interface/callDataSize.jsonadded
tests/interface/callDataSize.wastadded
tests/interface/callValue.jsonadded
tests/interface/callValue.wastadded
tests/interface/caller.jsonadded
tests/interface/caller.wastadded
tests/interface/default_enviroment.jsonadded
tests/interface/origin.jsonadded
tests/interface/origin.wastadded
tests/interface/sstore.jsonadded
tests/interface/sstore.wastadded
tests/address.wastdeleted
tests/interfaceRunner.jsadded
tests/balance.jsondeleted
tests/balance.wastdeleted
tests/basic_gas_ops.jsondeleted
tests/basic_gas_ops.wastdeleted
tests/callDataSize.jsondeleted
tests/callDataSize.wastdeleted
tests/callValue.jsondeleted
tests/callValue.wastdeleted
tests/caller.jsondeleted
tests/caller.wastdeleted
tests/default_enviroment.jsondeleted
tests/origin.jsondeleted
tests/origin.wastdeleted
tests/runner.jsdeleted
tests/sstore.jsondeleted
tests/sstore.wastdeleted
index.jsView
@@ -19,10 +19,10 @@
1919 this.state = nameState
2020 }
2121
2222 // 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)
2525 const instance = Wasm.instantiateModule(code, {
2626 'ethereum': ethInterface
2727 })
2828 ethInterface.setModule(instance)
@@ -35,11 +35,9 @@
3535 // loads code from the merkle trie and delegates the message
3636 // Detects if code is EVM or WASM
3737 // Detects if the code injection is needed
3838 // 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()) {
4240 // return instance
4341 }
4442
4543 // run tx
interface.jsView
@@ -1,8 +1,9 @@
11 /**
22 * This is the Ethereum interface that is exposed to the WASM instance which
33 * enables to interact with the Ethereum Environment
44 */
5+const Environment = require('./environment.js')
56 const constants = require('./constants.js')
67
78 // function.bind is not working corretly whith Wasm imports. So instead create
89 // a global for now. TODO REMOVE
@@ -18,9 +19,9 @@
1819 memPrint () {
1920 console.log((new Uint8Array(MOD.exports.memory)).toString())
2021 }
2122
22- constructor (environment) {
23+ constructor (environment = new Environment()) {
2324 ENV = this.environment = environment
2425 }
2526
2627 setModule (mod) {
package.jsonView
@@ -3,9 +3,9 @@
33 "version": "0.0.0",
44 "description": "This is a JS prototype of the eWASM kernal.",
55 "scripts": {
66 "lint": "standard",
7- "test": "node --expose-wasm ./tests/runner.js"
7+ "test": "node --expose-wasm ./tests/interfaceRunner.js"
88 },
99 "repository": {
1010 "type": "git",
1111 "url": "git+https://github.com/ethereumjs/ewasm-kernel.git"
tests/address.jsonView
@@ -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.jsonView
@@ -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.wastView
@@ -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.jsonView
@@ -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.wastView
@@ -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.jsonView
@@ -1,0 +1,3 @@
1+{
2+ "gas": 1000
3+}
tests/interface/basic_gas_ops.wastView
@@ -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.jsonView
@@ -1,0 +1,3 @@
1+{
2+ "callData": "596f75206172652077616974696e6720666f7220746865207265766f6c7574696f6e3f204c657420697420626521204d79206f776e20626567616e2061206c6f6e672074696d652061676f21205768656e20796f752077696c6c2062652072656164792e2e2e4920776f6ee2809974206d696e6420676f696e6720616c6f6e67207769746820796f7520666f722061207768696c652e20427574207768656e20796f75e280996c6c2073746f702c2049207368616c6c20636f6e74696e7565206f6e206d7920696e73616e6520616e6420747269756d7068616e742077617920746f776172642074686520677265617420616e64207375626c696d6520636f6e7175657374206f6620746865206e6f7468696e6721"
3+}
tests/interface/callDataSize.wastView
@@ -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.jsonView
@@ -1,0 +1,3 @@
1+{
2+ "callValue": [100]
3+}
tests/interface/callValue.wastView
@@ -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.jsonView
@@ -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.wastView
@@ -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.jsonView
@@ -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.jsonView
@@ -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.wastView
@@ -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.jsonView
@@ -1,0 +1,2 @@
1+{
2+}
tests/interface/sstore.wastView
@@ -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.wastView
@@ -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.jsView
@@ -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.jsonView
@@ -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.wastView
@@ -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.jsonView
@@ -1,3 +1,0 @@
1-{
2- "gas": 1000
3-}
tests/basic_gas_ops.wastView
@@ -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.jsonView
@@ -1,3 +1,0 @@
1-{
2- "callData": "596f75206172652077616974696e6720666f7220746865207265766f6c7574696f6e3f204c657420697420626521204d79206f776e20626567616e2061206c6f6e672074696d652061676f21205768656e20796f752077696c6c2062652072656164792e2e2e4920776f6ee2809974206d696e6420676f696e6720616c6f6e67207769746820796f7520666f722061207768696c652e20427574207768656e20796f75e280996c6c2073746f702c2049207368616c6c20636f6e74696e7565206f6e206d7920696e73616e6520616e6420747269756d7068616e742077617920746f776172642074686520677265617420616e64207375626c696d6520636f6e7175657374206f6620746865206e6f7468696e6721"
3-}
tests/callDataSize.wastView
@@ -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.jsonView
@@ -1,3 +1,0 @@
1-{
2- "callValue": [100]
3-}
tests/callValue.wastView
@@ -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.jsonView
@@ -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.wastView
@@ -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.jsonView
@@ -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.jsonView
@@ -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.wastView
@@ -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.jsView
@@ -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.jsonView
@@ -1,2 +1,0 @@
1-{
2-}
tests/sstore.wastView
@@ -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