Skip to content

Commit

Permalink
Use raw Bool for JSON responses, better web3 testing harness (#456)
Browse files Browse the repository at this point in the history
* data, driver, web3: Int and Bool are valid JSON

* web3: "true" => true

* tests/web3/eth_newBlockFilter: add test of non-existent filter

* Makefile, tests/web3: handle diffing output in Makefile

* .gitignore: ignore temporary output

* tests/web3: update expected output
  • Loading branch information
ehildenb authored Aug 23, 2019
1 parent 0dccd01 commit 26de1dd
Show file tree
Hide file tree
Showing 29 changed files with 22 additions and 22 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
/package/pkg
/package/src
/media/*.pdf
/tests/web3/*.out.json
/tests/web3/*/*.out.json
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,8 @@ tests/web3/no-shutdown/%: KEVM_WEB3_ARGS=

tests/%.run-web3: tests/%.in.json
tests/web3/runtest.sh $< tests/$*.out.json $(KEVM_WEB3_ARGS)
$(CHECK) tests/$*.expected.json tests/$*.out.json
rm -rf tests/$*.out.json

tests/%.parse: tests/%
$(TEST) kast --backend $(TEST_CONCRETE_BACKEND) $< kast > $@-out
Expand Down
2 changes: 1 addition & 1 deletion data.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Writing a JSON-ish parser in K takes 6 lines.
```k
syntax JSONList ::= List{JSON,","}
syntax JSONKey ::= String | Int
syntax JSON ::= String | Int
syntax JSON ::= String | Int | Bool
| JSONKey ":" JSON
| "{" JSONList "}"
| "[" JSONList "]"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions tests/web3/eth_newBlockFilter.expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"jsonrpc":"2.0","id":1,"result":"0x0"},{"jsonrpc":"2.0","id":2,"result":"0x1"},{"jsonrpc":"2.0","id":3,"result":true},{"jsonrpc":"2.0","id":4,"result":true},{"jsonrpc":"2.0","id":4,"result":false}]
9 changes: 5 additions & 4 deletions tests/web3/eth_newBlockFilter.in.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[{"jsonrpc":"2.0", "method":"eth_newBlockFilter", "params":[], "id":1},
{"jsonrpc":"2.0", "method":"eth_newBlockFilter", "params":[], "id":2},
{"jsonrpc":"2.0", "method":"eth_uninstallFilter", "params":["0x0"], "id":3},
{"jsonrpc":"2.0", "method":"eth_uninstallFilter", "params":["0x1"], "id":4}]
[{"jsonrpc":"2.0", "method":"eth_newBlockFilter", "params":[], "id":1},
{"jsonrpc":"2.0", "method":"eth_newBlockFilter", "params":[], "id":2},
{"jsonrpc":"2.0", "method":"eth_uninstallFilter", "params":["0x0"], "id":3},
{"jsonrpc":"2.0", "method":"eth_uninstallFilter", "params":["0x1"], "id":4},
{"jsonrpc":"2.0", "method":"eth_uninstallFilter", "params":["0x2"], "id":4}]
1 change: 0 additions & 1 deletion tests/web3/eth_newBlockFilter.out.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"jsonrpc":"2.0","id":1,"result":"0x0"}{"jsonrpc":"2.0","id":2,"result":"100"}{"jsonrpc":"2.0","id":3,"result":"300"}{"jsonrpc":"2.0","id":4,"result":"true"}{"jsonrpc":"2.0","id":5,"result":"350"}
{"jsonrpc":"2.0","id":1,"result":"0x0"}{"jsonrpc":"2.0","id":2,"result":"100"}{"jsonrpc":"2.0","id":3,"result":"300"}{"jsonrpc":"2.0","id":4,"result":true}{"jsonrpc":"2.0","id":5,"result":"350"}
1 change: 1 addition & 0 deletions tests/web3/evm_revert.expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"jsonrpc":"2.0","id":1,"result":"0x0"}{"jsonrpc":"2.0","id":2,"result":"0x1"}{"jsonrpc":"2.0","id":3,"result":true}{"jsonrpc":"2.0","id":4,"result":"0x1"}
1 change: 0 additions & 1 deletion tests/web3/evm_revert.out.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"jsonrpc":"2.0","id":1,"result":"0x0"}{"jsonrpc":"2.0","id":2,"result":"0x1"}{"jsonrpc":"2.0","id":3,"result":"0x2"}{"jsonrpc":"2.0","id":4,"result":"true"}{"jsonrpc":"2.0","id":5,"result":"0x1"}
{"jsonrpc":"2.0","id":1,"result":"0x0"}{"jsonrpc":"2.0","id":2,"result":"0x1"}{"jsonrpc":"2.0","id":3,"result":"0x2"}{"jsonrpc":"2.0","id":4,"result":true}{"jsonrpc":"2.0","id":5,"result":"0x1"}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 2 additions & 9 deletions tests/web3/runtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,11 @@ PORT=$(tests/web3/get_port.py)
kevm_client_pid="$!"
while ! netcat -z 127.0.0.1 "$PORT"; do sleep 0.1; done

# Feed input in, store output in tmp file
tmp_output_file="$(mktemp)"
trap "rm -rf $tmp_output_file" INT TERM EXIT
cat "$input_file" | netcat 127.0.0.1 "$PORT" -q 0 > "$tmp_output_file"
# Feed input in, store output in supplied file
cat "$input_file" | netcat 127.0.0.1 "$PORT" -q 0 > "$output_file"

./kevm web3-send "$PORT" 'firefly_shutdown'
echo
timeout 20 tail --pid="$kevm_client_pid" -f /dev/null || true
pkill -P "$kevm_client_pid" kevm-client || true
timeout 20 tail --pid="$kevm_client_pid" -f /dev/null || true

exit_code='0'
git --no-pager diff --no-index "$output_file" "$tmp_output_file" || exit_code="$?"

exit "$exit_code"
10 changes: 6 additions & 4 deletions web3.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ module WEB3
<web3response> .List </web3response>
</kevm-client>
syntax JSON ::= Bool | "null" | "undef"
| #getJSON ( JSONKey , JSON ) [function]
syntax JSON ::= "null" | "undef"
// --------------------------------
syntax JSON ::= #getJSON ( JSONKey , JSON ) [function]
// ------------------------------------------------------
rule #getJSON( KEY, { KEY : J, _ } ) => J
rule #getJSON( _, { .JSONList } ) => undef
Expand Down Expand Up @@ -305,7 +307,7 @@ module WEB3
syntax KItem ::= "#evm_revert"
// ------------------------------
rule <k> #evm_revert => #sendResponse( "result" : "true" ) ... </k>
rule <k> #evm_revert => #sendResponse( "result" : true ) ... </k>
<params> [ .JSONList ] </params>
<snapshots> ... ( ListItem(NETWORKSTATE) => .List ) </snapshots>
<network> ( _ => NETWORKSTATE ) </network>
Expand Down Expand Up @@ -344,7 +346,7 @@ module WEB3
rule <k> #eth_uninstallFilter ... </k>
<params> [ (DATA => #parseHexWord(DATA)), .JSONList ] </params>
rule <k> #eth_uninstallFilter => #sendResponse ( "result": "true" ) ... </k>
rule <k> #eth_uninstallFilter => #sendResponse ( "result": true ) ... </k>
<params> [ FILTID, .JSONList ] </params>
<filters>
( <filter>
Expand Down

0 comments on commit 26de1dd

Please sign in to comment.