Skip to content

Commit

Permalink
./kevm web3-send allows sending files as well (#617)
Browse files Browse the repository at this point in the history
* kevm: allow passing entire JSON files in as input to web3-send

* tests/web3/runtest.sh: use ./kevm web3-send for testing

* kevm: add -s to curl command

* kevm: formatting

* kevm: declare local variable web3_file

* Makefile: better dependency management for proxygen
  • Loading branch information
ehildenb authored and rv-jenkins committed Dec 12, 2019
1 parent 7680572 commit 0176314
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 30 deletions.
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export LUA_PATH
OPAM ?= opam

.PHONY: all clean clean-submodules distclean install uninstall \
deps all-deps llvm-deps haskell-deps repo-deps k-deps ocaml-deps plugin-deps libsecp256k1 libff \
deps all-deps llvm-deps haskell-deps repo-deps k-deps ocaml-deps plugin-deps libsecp256k1 libff proxygen \
build build-all build-ocaml build-java build-node build-haskell build-llvm build-web3 \
defn java-defn ocaml-defn node-defn web3-defn haskell-defn llvm-defn \
split-tests \
Expand Down Expand Up @@ -72,11 +72,13 @@ clean-submodules: distclean
# Non-K Dependencies
# ------------------

libsecp256k1_out:=$(LIBRARY_PATH)/pkgconfig/libsecp256k1.pc
libff_out:=$(LIBRARY_PATH)/libff.a
libsecp256k1_out := $(LIBRARY_PATH)/pkgconfig/libsecp256k1.pc
libff_out := $(LIBRARY_PATH)/libff.a
proxygen_out := $(DEPS_DIR)/proxygen/proxygen/_build/proxygen/lib/libproxygen.a

libsecp256k1: $(libsecp256k1_out)
libff: $(libff_out)
libff: $(libff_out)
proxygen: $(proxygen_out)

$(DEPS_DIR)/secp256k1/autogen.sh:
git submodule update --init --recursive -- $(DEPS_DIR)/secp256k1
Expand Down Expand Up @@ -111,8 +113,7 @@ $(libff_out): $(DEPS_DIR)/libff/CMakeLists.txt
&& make -s -j4 \
&& make install

.PHONY: proxygen
proxygen:
$(proxygen_out):
git submodule update --init --recursive -- deps/proxygen
cd deps/proxygen/proxygen && ./build.sh --no-jemalloc --no-install-dependencies
cd deps/proxygen/proxygen/_build && make install
Expand Down Expand Up @@ -337,7 +338,7 @@ $(web3_dir)/web3-kompiled/definition.kore: $(web3_files)
$(KOMPILE_OPTS)

.PHONY: $(web3_kompiled)
$(web3_kompiled): $(web3_dir)/web3-kompiled/definition.kore $(libff_out) proxygen
$(web3_kompiled): $(web3_dir)/web3-kompiled/definition.kore $(libff_out) $(proxygen_out)
@mkdir -p $(web3_dir)/build
cd $(web3_dir)/build && cmake $(CURDIR)/cmake/client -DCMAKE_BUILD_TYPE=${SEMANTICS_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} && $(MAKE)

Expand Down
49 changes: 28 additions & 21 deletions kevm
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,21 @@ run_web3() {
}

run_web3_send() {
local web3_port web3_method web3_params
web3_port="$1" ; shift
web3_method="$1" ; shift

join_args() {
local IFS=','
echo "$*"
}
web3_params="$(join_args "$@")"
local web3_port web3_method web3_params web3_file
web3_port="$1" ; shift

curl -X POST --data '{"jsonrpc": "2.0", "id": 1, "method": "'"$web3_method"'", "params": ['"$web3_params"']}' 127.0.0.1:"$web3_port"
if [[ -f "$1" ]]; then
web3_file="$1" ; shift
curl -s -X POST 127.0.0.1:$web3_port --data @$web3_file
else
web3_method="$1" ; shift
join_args() {
local IFS=','
echo "$*"
}
web3_params="$(join_args "$@")"
curl -s -X POST --data '{"jsonrpc": "2.0", "id": 1, "method": "'"$web3_method"'", "params": ['"$web3_params"']}' 127.0.0.1:"$web3_port"
fi
}

run_web3_ganache() {
Expand All @@ -120,16 +124,16 @@ run_web3_ganache() {
$0 web3 "$web3_port" "$@" &
while ! netcat -z 127.0.0.1 "$web3_port" ; do sleep 0.1; done
notif 'Generating accounts'
$0 web3-send "$web3_port" firefly_addAccount {'"key":"0xdc7e9a7c64933ab893160b79d099c254d274e1c40c6df6d5239e1a623e3d6de1", "balance":"0x56BC75E2D63100000"'}
$0 web3-send "$web3_port" firefly_addAccount {'"key":"0x6e2687f9732d970c6b1d5baa3dff26c4af36257552bc17df737afbc00ca70de2", "balance":"0x56BC75E2D63100000"'}
$0 web3-send "$web3_port" firefly_addAccount {'"key":"0xd34d8e873da77217abaef9424a7d87fce351b603920c7f5288d7701c5f148860", "balance":"0x56BC75E2D63100000"'}
$0 web3-send "$web3_port" firefly_addAccount {'"key":"0x976b5ec9253759d4a2746c37597841beba57527123dc3db2165b637adce58bcb", "balance":"0x56BC75E2D63100000"'}
$0 web3-send "$web3_port" firefly_addAccount {'"key":"0x23dff7ac7981167eb5386e51c3d6d2e3ca9dc219315749b2058d0a2d1e21625e", "balance":"0x56BC75E2D63100000"'}
$0 web3-send "$web3_port" firefly_addAccount {'"key":"0xe040e4bf96d8c9d3a8d1ffb22b30ed4b0a79a25342d656c5a8e2784b0fab752f", "balance":"0x56BC75E2D63100000"'}
$0 web3-send "$web3_port" firefly_addAccount {'"key":"0x13abddd7d94165fc46bed2cad6b0b14cd0267a85f70ad5c26cce82c609e0bf87", "balance":"0x56BC75E2D63100000"'}
$0 web3-send "$web3_port" firefly_addAccount {'"key":"0x0e29f7d6984bb47d60db479212ca56af516705b07d8753b474bd7f0db8bc1921", "balance":"0x56BC75E2D63100000"'}
$0 web3-send "$web3_port" firefly_addAccount {'"key":"0xea7fe1480e9ab71c261c5e1e727f36482f84dbdb07dbf8c8e9f767dcecf87568", "balance":"0x56BC75E2D63100000"'}
$0 web3-send "$web3_port" firefly_addAccount {'"key":"0x5f9addbbf41ae2e3d6cb7b07ffabf2c5ff6edc3a38c9dd64a9afd23df02ad7ee", "balance":"0x56BC75E2D63100000"'}
$0 web3-send "$web3_port" firefly_addAccount '{"key":"0xdc7e9a7c64933ab893160b79d099c254d274e1c40c6df6d5239e1a623e3d6de1", "balance":"0x56BC75E2D63100000"}'
$0 web3-send "$web3_port" firefly_addAccount '{"key":"0x6e2687f9732d970c6b1d5baa3dff26c4af36257552bc17df737afbc00ca70de2", "balance":"0x56BC75E2D63100000"}'
$0 web3-send "$web3_port" firefly_addAccount '{"key":"0xd34d8e873da77217abaef9424a7d87fce351b603920c7f5288d7701c5f148860", "balance":"0x56BC75E2D63100000"}'
$0 web3-send "$web3_port" firefly_addAccount '{"key":"0x976b5ec9253759d4a2746c37597841beba57527123dc3db2165b637adce58bcb", "balance":"0x56BC75E2D63100000"}'
$0 web3-send "$web3_port" firefly_addAccount '{"key":"0x23dff7ac7981167eb5386e51c3d6d2e3ca9dc219315749b2058d0a2d1e21625e", "balance":"0x56BC75E2D63100000"}'
$0 web3-send "$web3_port" firefly_addAccount '{"key":"0xe040e4bf96d8c9d3a8d1ffb22b30ed4b0a79a25342d656c5a8e2784b0fab752f", "balance":"0x56BC75E2D63100000"}'
$0 web3-send "$web3_port" firefly_addAccount '{"key":"0x13abddd7d94165fc46bed2cad6b0b14cd0267a85f70ad5c26cce82c609e0bf87", "balance":"0x56BC75E2D63100000"}'
$0 web3-send "$web3_port" firefly_addAccount '{"key":"0x0e29f7d6984bb47d60db479212ca56af516705b07d8753b474bd7f0db8bc1921", "balance":"0x56BC75E2D63100000"}'
$0 web3-send "$web3_port" firefly_addAccount '{"key":"0xea7fe1480e9ab71c261c5e1e727f36482f84dbdb07dbf8c8e9f767dcecf87568", "balance":"0x56BC75E2D63100000"}'
$0 web3-send "$web3_port" firefly_addAccount '{"key":"0x5f9addbbf41ae2e3d6cb7b07ffabf2c5ff6edc3a38c9dd64a9afd23df02ad7ee", "balance":"0x56BC75E2D63100000"}'
$0 web3-send "$web3_port" firefly_genesisBlock

}
Expand Down Expand Up @@ -241,7 +245,7 @@ if [[ "$run_command" == 'help' ]] || [[ "$run_command" == '--help' ]] ; then
$0 search [--backend (java|haskell)] <pgm> <pattern> <K arg>*
$0 web3 [--debug|--dump] <port>
$0 web3-ganache [--debug|--dump] <port>
$0 web3-send <port> <web3 method> <web3 params>
$0 web3-send <port> [<web3_method> <web3_params>|<web3_file>]
$0 klab-run <pgm> <K arg>*
$0 klab-prove <spec> <K arg>* -m <def_module>
$0 klab-view <spec>
Expand Down Expand Up @@ -270,6 +274,9 @@ if [[ "$run_command" == 'help' ]] || [[ "$run_command" == '--help' ]] ; then
<pattern> is the configuration pattern to search for.
<port> is the port to listen on for Web3 JSON RPC requests.
<def_module> is the module to take as axioms when doing verification.
<web3_method> is the specific web3 method to call.
<web3_params> is an optional list of parameters to pass to the <web3_method>.
<web3_file> specifies a JSON file to feed as input into the web3 server.
klab-view: Make sure that the 'klab/bin' directory is on your PATH to use this option.
"
Expand Down
4 changes: 2 additions & 2 deletions tests/web3/runtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ kevm_client_pid="$!"
while (! netcat -z 127.0.0.1 "$PORT") ; do sleep 0.1; done

# Feed input in, store output in supplied file
curl -s -X POST 127.0.0.1:"$PORT" --data @"$input_file" | jq . > "$output_file"

./kevm web3-send "$PORT" "$input_file" | jq . > "$output_file"
./kevm web3-send "$PORT" 'firefly_shutdown'

echo
timeout 8 tail --pid="$kevm_client_pid" -f /dev/null || true
pkill -P "$kevm_client_pid" kevm-client || true
Expand Down

0 comments on commit 0176314

Please sign in to comment.