From 1aae07cee4271af02e2fe1e730006ba71e7eb601 Mon Sep 17 00:00:00 2001 From: Silas Davis <silas@monax.io> Date: Wed, 27 Jun 2018 20:56:54 +0200 Subject: [PATCH] Improve solidity fixture handling Signed-off-by: Silas Davis <silas@monax.io> --- Makefile | 18 +++++++++++++++--- .../integration/transactor_server_test.go | 4 ++-- rpc/test/helpers.go | 5 +---- rpc/test/strange_loop.go | 3 --- rpc/test/strange_loop.sh | 5 ----- rpc/test/strange_loop.sol.go | 5 +++++ rpc/v0/integration/v0_test.go | 6 +++--- scripts/solc_compile_go.sh | 17 +++++++++++++++++ 8 files changed, 43 insertions(+), 20 deletions(-) delete mode 100644 rpc/test/strange_loop.go delete mode 100755 rpc/test/strange_loop.sh create mode 100644 rpc/test/strange_loop.sol.go create mode 100755 scripts/solc_compile_go.sh diff --git a/Makefile b/Makefile index fb80bce1..86ad8624 100644 --- a/Makefile +++ b/Makefile @@ -16,9 +16,14 @@ BOSMARMOT_PROJECT := github.com/monax/bosmarmot BOSMARMOT_GOPATH := ${REPO}/.gopath_bos BOSMARMOT_CHECKOUT := ${BOSMARMOT_GOPATH}/src/${BOSMARMOT_PROJECT} -PROTO_FILES = $(shell find . -type f -name '*.proto') +# Protobuf generated go files +PROTO_FILES = $(shell find . -path ./vendor -prune -o -type f -name '*.proto') PROTO_GO_FILES = $(patsubst %.proto, %.pb.go, $(PROTO_FILES)) +# Our own Go files containing the compiled bytecode of solidity files as a constant +SOLIDITY_FILES = $(shell find . -path ./vendor -prune -o -type f -name '*.sol') +SOLIDITY_GO_FILES = $(patsubst %.sol, %.sol.go, $(SOLIDITY_FILES)) + ### Formatting, linting and vetting # check the code for style standards; currently enforces go formatting. @@ -146,7 +151,6 @@ build_race_db: build_race_client: go build -race -o ${REPO}/bin/burrow-client ./client/cmd/burrow-client - # Get the Bosmarmot code .PHONY: bos bos: ./scripts/deps/bos.sh @@ -164,7 +168,15 @@ docker_build: check commit_hash ### Testing github.com/hyperledger/burrow -# test burrow +# Solidity fixtures +%.sol.go: %.sol scripts/solc_compile_go.sh + scripts/solc_compile_go.sh $< $@ + +.PHONY: solidity +solidity: $(SOLIDITY_GO_FILES) + +# Test + .PHONY: test test: check @go test ${PACKAGES_NOVENDOR} diff --git a/rpc/rpctransactor/integration/transactor_server_test.go b/rpc/rpctransactor/integration/transactor_server_test.go index c48cb128..80c79df9 100644 --- a/rpc/rpctransactor/integration/transactor_server_test.go +++ b/rpc/rpctransactor/integration/transactor_server_test.go @@ -67,7 +67,7 @@ func TestTransactCreate(t *testing.T) { create, err := cli.Transact(context.Background(), &pbtransactor.TransactParam{ InputAccount: inputAccount(i), Address: nil, - Data: test.StrangeLoopBytecode, + Data: test.Bytecode_strange_loop, Fee: 2, GasLimit: 10000, }) @@ -89,7 +89,7 @@ func BenchmarkTransactCreateContract(b *testing.B) { create, err := cli.Transact(context.Background(), &pbtransactor.TransactParam{ InputAccount: inputAccount(i), Address: nil, - Data: test.StrangeLoopBytecode, + Data: test.Bytecode_strange_loop, Fee: 2, GasLimit: 10000, }) diff --git a/rpc/test/helpers.go b/rpc/test/helpers.go index 18ded24e..e994045b 100644 --- a/rpc/test/helpers.go +++ b/rpc/test/helpers.go @@ -12,12 +12,9 @@ import ( "github.com/hyperledger/burrow/rpc" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/tmthrgd/go-hex" "google.golang.org/grpc" ) -var StrangeLoopBytecode = hex.MustDecodeString(strangeLoopBytecodeHex) - // Recursive call count for UpsieDownsie() function call from strange_loop.sol // Equals initial call, then depth from 17 -> 34, one for the bounce, then depth from 34 -> 23, // so... (I didn't say it had to make sense): @@ -75,7 +72,7 @@ func CreateContract(t testing.TB, cli pbtransactor.TransactorClient, create, err := cli.TransactAndHold(context.Background(), &pbtransactor.TransactParam{ InputAccount: inputAccount, Address: nil, - Data: StrangeLoopBytecode, + Data: Bytecode_strange_loop, Fee: 2, GasLimit: 10000, }) diff --git a/rpc/test/strange_loop.go b/rpc/test/strange_loop.go deleted file mode 100644 index 230de1cc..00000000 --- a/rpc/test/strange_loop.go +++ /dev/null @@ -1,3 +0,0 @@ -package test - -const strangeLoopBytecodeHex = "60606040526017600055602260015560116002556001600360006101000a81548160ff021916908315150217905550341561003957600080fd5b610369806100486000396000f300606060405260043610610041576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063ebb384dd14610046575b600080fd5b341561005157600080fd5b61005961006f565b6040518082815260200191505060405180910390f35b60006002549050600360009054906101000a900460ff161561021f57600154600254121561017e576002600081548092919060010191905055506002547f55707369652100000000000000000000000000000000000000000000000000007f3ff0b1eac80ecf8e93d1a2d7982a9230f8ea7693439fd548687b08a5e292b09760405160405180910390a360025490503073ffffffffffffffffffffffffffffffffffffffff1663ebb384dd6040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401602060405180830381600087803b151561016157600080fd5b5af1151561016e57600080fd5b505050604051805190505061021a565b6000600360006101000a81548160ff02191690831515021790555060025490503073ffffffffffffffffffffffffffffffffffffffff1663ebb384dd6040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401602060405180830381600087803b151561020157600080fd5b5af1151561020e57600080fd5b50505060405180519050505b610339565b600054600254131561031357600260008154809291906001900391905055506002547f446f776e736965210000000000000000000000000000000000000000000000007f3ff0b1eac80ecf8e93d1a2d7982a9230f8ea7693439fd548687b08a5e292b09760405160405180910390a360025490503073ffffffffffffffffffffffffffffffffffffffff1663ebb384dd6040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401602060405180830381600087803b15156102f657600080fd5b5af1151561030357600080fd5b5050506040518051905050610338565b6001600360006101000a81548160ff021916908315150217905550600254905061033a565b5b5b905600a165627a7a723058204852911519ec7080301770f04ea7bf39ba1e2d71b4988eb1df310378ac767f350029" diff --git a/rpc/test/strange_loop.sh b/rpc/test/strange_loop.sh deleted file mode 100755 index edbdf044..00000000 --- a/rpc/test/strange_loop.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -echo -e "package test\n\nconst strangeLoopBytecodeHex = \"$(solc --bin "$script_dir/strange_loop.sol" | tail -1)\"" > "${script_dir}/strange_loop.go" diff --git a/rpc/test/strange_loop.sol.go b/rpc/test/strange_loop.sol.go new file mode 100644 index 00000000..57a1f061 --- /dev/null +++ b/rpc/test/strange_loop.sol.go @@ -0,0 +1,5 @@ +package test + +import "github.com/tmthrgd/go-hex" + +var Bytecode_strange_loop = hex.MustDecodeString("60606040526017600055602260015560116002556001600360006101000a81548160ff021916908315150217905550341561003957600080fd5b610369806100486000396000f300606060405260043610610041576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063ebb384dd14610046575b600080fd5b341561005157600080fd5b61005961006f565b6040518082815260200191505060405180910390f35b60006002549050600360009054906101000a900460ff161561021f57600154600254121561017e576002600081548092919060010191905055506002547f55707369652100000000000000000000000000000000000000000000000000007f3ff0b1eac80ecf8e93d1a2d7982a9230f8ea7693439fd548687b08a5e292b09760405160405180910390a360025490503073ffffffffffffffffffffffffffffffffffffffff1663ebb384dd6040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401602060405180830381600087803b151561016157600080fd5b5af1151561016e57600080fd5b505050604051805190505061021a565b6000600360006101000a81548160ff02191690831515021790555060025490503073ffffffffffffffffffffffffffffffffffffffff1663ebb384dd6040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401602060405180830381600087803b151561020157600080fd5b5af1151561020e57600080fd5b50505060405180519050505b610339565b600054600254131561031357600260008154809291906001900391905055506002547f446f776e736965210000000000000000000000000000000000000000000000007f3ff0b1eac80ecf8e93d1a2d7982a9230f8ea7693439fd548687b08a5e292b09760405160405180910390a360025490503073ffffffffffffffffffffffffffffffffffffffff1663ebb384dd6040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401602060405180830381600087803b15156102f657600080fd5b5af1151561030357600080fd5b5050506040518051905050610338565b6001600360006101000a81548160ff021916908315150217905550600254905061033a565b5b5b905600a165627a7a723058202906ff200f065bf0b9e4f4d744be14a519f74f794b53a0ea5993280b38eeaf210029") diff --git a/rpc/v0/integration/v0_test.go b/rpc/v0/integration/v0_test.go index 3e57114c..563512eb 100644 --- a/rpc/v0/integration/v0_test.go +++ b/rpc/v0/integration/v0_test.go @@ -66,7 +66,7 @@ func TestTransactCreate(t *testing.T) { create, err := cli.Transact(v0.TransactParam{ InputAccount: inputAccount(i), Address: nil, - Data: test.StrangeLoopBytecode, + Data: test.Bytecode_strange_loop, Fee: 2, GasLimit: 10000, }) @@ -89,7 +89,7 @@ func BenchmarkTransactCreateContract(b *testing.B) { create, err := cli.Transact(v0.TransactParam{ InputAccount: inputAccount(i), Address: nil, - Data: test.StrangeLoopBytecode, + Data: test.Bytecode_strange_loop, Fee: 2, GasLimit: 10000, }) @@ -109,7 +109,7 @@ func TestTransactAndHold(t *testing.T) { create, err := cli.TransactAndHold(v0.TransactParam{ InputAccount: inputAccount(i), Address: nil, - Data: test.StrangeLoopBytecode, + Data: test.Bytecode_strange_loop, Fee: 2, GasLimit: 10000, }) diff --git a/scripts/solc_compile_go.sh b/scripts/solc_compile_go.sh new file mode 100755 index 00000000..997b7b08 --- /dev/null +++ b/scripts/solc_compile_go.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +solidity_file="$1" +solidity_name=$(basename $1) +go_file="$2" +package=$(basename $(dirname "$go_file")) +solidity_bin=$(solc --bin "$solidity_file" | tail -1) + +cat << GOFILE > "$go_file" +package ${package} + +import "github.com/tmthrgd/go-hex" + +var Bytecode_${solidity_name%%.sol} = hex.MustDecodeString("${solidity_bin}") +GOFILE + -- GitLab