diff --git a/cmd/counter/main.go b/cmd/counter/main.go new file mode 100644 index 000000000..36485996e --- /dev/null +++ b/cmd/counter/main.go @@ -0,0 +1,22 @@ +package main + +import ( + . "github.com/tendermint/go-common" + "github.com/tendermint/tmsp/example" + "github.com/tendermint/tmsp/server" +) + +func main() { + + // Start the listener + _, err := server.StartListener("tcp://127.0.0.1:8080", example.NewCounterApplication()) + if err != nil { + Exit(err.Error()) + } + + // Wait forever + TrapSignal(func() { + // Cleanup + }) + +} diff --git a/cmd/tmsp/cli.go b/cmd/tmsp/cli.go index aa5a5a8b8..242ffa60f 100644 --- a/cmd/tmsp/cli.go +++ b/cmd/tmsp/cli.go @@ -4,6 +4,7 @@ import ( "bufio" "encoding/hex" "fmt" + "io" "net" "os" "strings" @@ -30,6 +31,13 @@ func main() { }, } app.Commands = []cli.Command{ + { + Name: "batch", + Usage: "Run a batch of tmsp commands against an application", + Action: func(c *cli.Context) { + cmdBatch(app, c) + }, + }, { Name: "console", Usage: "Start an interactive tmsp console for multiple commands", @@ -98,6 +106,23 @@ func before(c *cli.Context) error { //-------------------------------------------------------------------------------- +func cmdBatch(app *cli.App, c *cli.Context) { + bufReader := bufio.NewReader(os.Stdin) + for { + line, more, err := bufReader.ReadLine() + if more { + Exit("input line is too long") + } else if err == io.EOF { + break + } else if err != nil { + Exit(err.Error()) + } + args := []string{"tmsp"} + args = append(args, strings.Split(string(line), " ")...) + app.Run(args) + } +} + func cmdConsole(app *cli.App, c *cli.Context) { for { fmt.Printf("> ") @@ -134,7 +159,7 @@ func cmdSetOption(c *cli.Context) { if err != nil { Exit(err.Error()) } - fmt.Printf("Set option %s = %s\n", args[0], args[1]) + fmt.Printf("%s=%s\n", args[0], args[1]) } // Append a new tx to application @@ -166,7 +191,7 @@ func cmdGetHash(c *cli.Context) { if err != nil { Exit(err.Error()) } - fmt.Println("Got hash:", Fmt("%X", res.(types.ResponseGetHash).Hash)) + fmt.Printf("%X\n", res.(types.ResponseGetHash).Hash) } // Commit the application state diff --git a/example/counter.go b/example/counter.go index 870d5a808..d4b0e4776 100644 --- a/example/counter.go +++ b/example/counter.go @@ -69,7 +69,7 @@ func (appC *CounterAppContext) AppendTx(tx []byte) ([]types.Event, types.RetCode func (appC *CounterAppContext) GetHash() ([]byte, types.RetCode) { hash := make([]byte, 32) - binary.PutVarint(hash, int64(appC.hashCount)) + binary.PutVarint(hash, int64(appC.txCount)) appC.hashCount += 1 return hash, 0 } diff --git a/test.sh b/test.sh new file mode 100644 index 000000000..00c1f2037 --- /dev/null +++ b/test.sh @@ -0,0 +1,100 @@ +#! /bin/bash + +# Make sure the tmsp cli can connect to the dummy +echo "Dummy test ..." +dummy &> /dev/null & +PID=`echo $!` +sleep 1 +RESULT_HASH=`tmsp get_hash` +if [[ "$RESULT_HASH" != "" ]]; then + echo "Expected nothing but got: $RESULT_HASH" + exit 1 +fi +echo "... Pass!" +echo "" + +# Add a tx, get hash, commit, get hash +# hashes should be non-empty and identical +echo "Dummy batch test ..." +OUTPUT=`(tmsp batch) < /dev/null & +PID=`echo $!` +sleep 1 +OUTPUT=`(tmsp batch) <