From 88f8141ab872a688702706c4ca73008a1d6b0985 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Fri, 1 Jul 2016 20:22:58 -0400 Subject: [PATCH] cleanup cli, drop expr --- cmd/tmsp-cli/tmsp-cli.go | 35 +++++++++++------------- example/dummy/dummy.go | 1 + tests/test.sh | 12 -------- tests/test_counter/test.sh | 13 +++++++++ tests/{ => test_counter}/test_counter.go | 0 5 files changed, 30 insertions(+), 31 deletions(-) delete mode 100755 tests/test.sh create mode 100755 tests/test_counter/test.sh rename tests/{ => test_counter}/test_counter.go (100%) diff --git a/cmd/tmsp-cli/tmsp-cli.go b/cmd/tmsp-cli/tmsp-cli.go index 373266ef..f3097911 100644 --- a/cmd/tmsp-cli/tmsp-cli.go +++ b/cmd/tmsp-cli/tmsp-cli.go @@ -2,6 +2,7 @@ package main import ( "bufio" + "encoding/hex" "errors" "fmt" "io" @@ -10,7 +11,6 @@ import ( "github.com/codegangsta/cli" . "github.com/tendermint/go-common" - "github.com/tendermint/go-wire/expr" "github.com/tendermint/tmsp/client" "github.com/tendermint/tmsp/types" ) @@ -195,12 +195,7 @@ func cmdAppendTx(c *cli.Context) error { if len(args) != 1 { return errors.New("Command append_tx takes 1 argument") } - txExprString := c.Args()[0] - txBytes, err := expr.Compile(txExprString) - if err != nil { - return err - } - + txBytes := stringOrHexToBytes(c.Args()[0]) res := client.AppendTxSync(txBytes) printResponse(res, string(res.Data), true) return nil @@ -212,12 +207,7 @@ func cmdCheckTx(c *cli.Context) error { if len(args) != 1 { return errors.New("Command check_tx takes 1 argument") } - txExprString := c.Args()[0] - txBytes, err := expr.Compile(txExprString) - if err != nil { - return err - } - + txBytes := stringOrHexToBytes(c.Args()[0]) res := client.CheckTxSync(txBytes) printResponse(res, string(res.Data), true) return nil @@ -236,12 +226,7 @@ func cmdQuery(c *cli.Context) error { if len(args) != 1 { return errors.New("Command query takes 1 argument") } - queryExprString := args[0] - queryBytes, err := expr.Compile(queryExprString) - if err != nil { - return err - } - + queryBytes := stringOrHexToBytes(c.Args()[0]) res := client.QuerySync(queryBytes) printResponse(res, string(res.Data), true) return nil @@ -264,3 +249,15 @@ func printResponse(res types.Result, s string, printCode bool) { } } + +// NOTE: s is interpreted as a string unless prefixed with 0x +func stringOrHexToBytes(s string) []byte { + if len(s) > 2 && s[:2] == "0x" { + b, err := hex.DecodeString(s[2:]) + if err != nil { + fmt.Println("Error decoding hex argument:", err.Error()) + } + return b + } + return []byte(s) +} diff --git a/example/dummy/dummy.go b/example/dummy/dummy.go index 3fa237f0..ca3a8c03 100644 --- a/example/dummy/dummy.go +++ b/example/dummy/dummy.go @@ -28,6 +28,7 @@ func (app *DummyApplication) SetOption(key string, value string) (log string) { return "" } +// tx is either "key=value" or just arbitrary bytes func (app *DummyApplication) AppendTx(tx []byte) types.Result { parts := strings.Split(string(tx), "=") if len(parts) == 2 { diff --git a/tests/test.sh b/tests/test.sh deleted file mode 100755 index ebdab0c8..00000000 --- a/tests/test.sh +++ /dev/null @@ -1,12 +0,0 @@ - -ROOT=$GOPATH/src/github.com/tendermint/tmsp -cd $ROOT - -# test golang counter -COUNTER_APP="counter" go run $ROOT/tests/test_counter.go - -# test golang counter via grpc -COUNTER_APP="counter -tmsp=grpc" go run $ROOT/tests/test_counter.go -tmsp=grpc - -# test nodejs counter -COUNTER_APP="node ../js-tmsp/example/app.js" go run $ROOT/tests/test_counter.go diff --git a/tests/test_counter/test.sh b/tests/test_counter/test.sh new file mode 100755 index 00000000..c1a0f58b --- /dev/null +++ b/tests/test_counter/test.sh @@ -0,0 +1,13 @@ +# These tests spawn the counter app and server by execing the COUNTER_APP command and run some simple client tests against it + +ROOT=$GOPATH/src/github.com/tendermint/tmsp/tests/test_counter +cd $ROOT + +# test golang counter +COUNTER_APP="counter" go run test_counter.go + +# test golang counter via grpc +COUNTER_APP="counter -tmsp=grpc" go run test_counter.go -tmsp=grpc + +# test nodejs counter +COUNTER_APP="node $GOPATH/src/github.com/tendermint/js-tmsp/example/app.js" go run test_counter.go diff --git a/tests/test_counter.go b/tests/test_counter/test_counter.go similarity index 100% rename from tests/test_counter.go rename to tests/test_counter/test_counter.go