Browse Source

better testing. cli test for tutorial

pull/1780/head
Ethan Buchman 9 years ago
parent
commit
3b329039d8
12 changed files with 191 additions and 67 deletions
  1. +1
    -1
      Makefile
  2. +2
    -1
      README.md
  3. +8
    -0
      tests/test.sh
  4. +11
    -51
      tests/test_app/app.go
  5. +48
    -0
      tests/test_app/main.go
  6. +17
    -0
      tests/test_app/test.sh
  7. +10
    -0
      tests/test_cli/ex1.tmsp
  8. +31
    -0
      tests/test_cli/ex1.tmsp.out
  9. +8
    -0
      tests/test_cli/ex2.tmsp
  10. +26
    -0
      tests/test_cli/ex2.tmsp.out
  11. +29
    -0
      tests/test_cli/test.sh
  12. +0
    -14
      tests/test_counter/test.sh

+ 1
- 1
Makefile View File

@ -10,7 +10,7 @@ install: get_deps
test:
go test github.com/tendermint/tmsp/...
bash tests/test_counter/test.sh
bash tests/test.sh
get_deps:
go get -d github.com/tendermint/tmsp/...

+ 2
- 1
README.md View File

@ -18,7 +18,7 @@ This repository holds a number of important pieces:
- `types/types.proto`
- the protobuf file definig TMSP message types, and the optional grpc interface.
- use `protoc --go_out=plugins=grpc:./types types/types.proto` to generate the `types/types.pb.go` file
- use `protoc --go_out=plugins=grpc:. types.proto` to from the `types` dir to generate the `types/types.pb.go` file
- see `protoc --help` and [the grpc docs](www.grpc.io/docs) for examples and details of other languages
- golang implementation of TMSP client and server
@ -29,6 +29,7 @@ This repository holds a number of important pieces:
- `cmd/tmsp-cli`
- command line tool wrapping the client for probing/testing a TMSP application
- use `tmsp-cli --version` to get the TMSP version
- examples:
- the `cmd/counter` application, which illustrates nonce checking in txs


+ 8
- 0
tests/test.sh View File

@ -0,0 +1,8 @@
#! /bin/bash
# test the counter using a go test script
bash tests/test_app/test.sh
# test the cli against the examples in the tutorial at tendermint.com
bash tests/test_cli/test.sh

tests/test_counter/test_counter.go → tests/test_app/app.go View File


+ 48
- 0
tests/test_app/main.go View File

@ -0,0 +1,48 @@
package main
import (
"fmt"
"os"
"github.com/tendermint/tmsp/types"
)
var tmspType string
func init() {
tmspType = os.Getenv("TMSP")
if tmspType == "" {
tmspType = "socket"
}
}
func main() {
testCounter()
}
func testCounter() {
tmspApp := os.Getenv("TMSP_APP")
if tmspApp == "" {
panic("No TMSP_APP specified")
}
fmt.Printf("Running %s test with tmsp=%s\n", tmspApp, tmspType)
appProc := StartApp(tmspApp)
defer appProc.StopProcess(true)
client := StartClient(tmspType)
defer client.Stop()
SetOption(client, "serial", "on")
Commit(client, nil)
AppendTx(client, []byte("abc"), types.CodeType_BadNonce, nil)
Commit(client, nil)
AppendTx(client, []byte{0x00}, types.CodeType_OK, nil)
Commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 1})
AppendTx(client, []byte{0x00}, types.CodeType_BadNonce, nil)
AppendTx(client, []byte{0x01}, types.CodeType_OK, nil)
AppendTx(client, []byte{0x00, 0x02}, types.CodeType_OK, nil)
AppendTx(client, []byte{0x00, 0x03}, types.CodeType_OK, nil)
AppendTx(client, []byte{0x00, 0x00, 0x04}, types.CodeType_OK, nil)
AppendTx(client, []byte{0x00, 0x00, 0x06}, types.CodeType_BadNonce, nil)
Commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 5})
}

+ 17
- 0
tests/test_app/test.sh View File

@ -0,0 +1,17 @@
#! /bin/bash
set -e
# These tests spawn the counter app and server by execing the TMSP_APP command and run some simple client tests against it
ROOT=$GOPATH/src/github.com/tendermint/tmsp/tests/test_app
cd $ROOT
# test golang counter
TMSP_APP="counter" go run *.go
# test golang counter via grpc
TMSP_APP="counter -tmsp=grpc" TMSP="grpc" go run *.go
# test nodejs counter
# TODO: fix node app
#TMSP_APP="node $GOPATH/src/github.com/tendermint/js-tmsp/example/app.js" go test -test.run TestCounter

+ 10
- 0
tests/test_cli/ex1.tmsp View File

@ -0,0 +1,10 @@
echo hello
info
commit
append_tx abc
info
commit
query abc
append_tx def=xyz
commit
query def

+ 31
- 0
tests/test_cli/ex1.tmsp.out View File

@ -0,0 +1,31 @@
> echo hello
-> data: {hello}
> info
-> data: {size:0}
> commit
> append_tx abc
-> code: OK
> info
-> data: {size:1}
> commit
-> data: {750502FC7E84BBD788ED589624F06CFA871845D1}
> query abc
-> code: OK
-> data: {Index=0 value=abc exists=true}
> append_tx def=xyz
-> code: OK
> commit
-> data: {76393B8A182E450286B0694C629ECB51B286EFD5}
> query def
-> code: OK
-> data: {Index=1 value=xyz exists=true}

+ 8
- 0
tests/test_cli/ex2.tmsp View File

@ -0,0 +1,8 @@
set_option serial on
check_tx 0x00
check_tx 0xff
append_tx 0x00
check_tx 0x00
append_tx 0x01
append_tx 0x04
info

+ 26
- 0
tests/test_cli/ex2.tmsp.out View File

@ -0,0 +1,26 @@
> set_option serial on
-> data: {serial=on}
> check_tx 0x00
-> code: OK
> check_tx 0xff
-> code: OK
> append_tx 0x00
-> code: OK
> check_tx 0x00
-> code: BadNonce
-> log: Invalid nonce. Expected >= 1, got 0
> append_tx 0x01
-> code: OK
> append_tx 0x04
-> code: BadNonce
-> log: Invalid nonce. Expected 2, got 4
> info
-> data: {hashes:0, txs:2}

+ 29
- 0
tests/test_cli/test.sh View File

@ -0,0 +1,29 @@
#! /bin/bash
function testExample() {
N=$1
INPUT=$2
APP=$3
echo "Example $N"
$APP &> /dev/null &
sleep 2
tmsp-cli --verbose batch < $INPUT > "${INPUT}.out.new"
killall "$APP" > /dev/null
pre=`shasum < "${INPUT}.out"`
post=`shasum < "${INPUT}.out.new"`
if [[ "$pre" != "$post" ]]; then
echo "You broke the tutorial"
exit 1
fi
rm "${INPUT}".out.new
}
testExample 1 tests/test_cli/ex1.tmsp dummy
testExample 2 tests/test_cli/ex2.tmsp counter
echo ""
echo "PASS"

+ 0
- 14
tests/test_counter/test.sh View File

@ -1,14 +0,0 @@
# 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
# TODO: fix node app
#COUNTER_APP="node $GOPATH/src/github.com/tendermint/js-tmsp/example/app.js" go run test_counter.go

Loading…
Cancel
Save