cleanup cli, drop expr
This commit is contained in:
parent
2c21c7be89
commit
88f8141ab8
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue