Browse Source

Merge branch 'server-test' into develop

pull/1780/head
Ethan Buchman 7 years ago
parent
commit
cfa14074df
6 changed files with 205 additions and 3 deletions
  1. +44
    -0
      README.md
  2. +2
    -3
      client/grpc_client.go
  3. +60
    -0
      cmd/abci-cli/abci-cli.go
  4. +98
    -0
      tests/server/client.go
  5. +0
    -0
      tests/test_cli/test.sh
  6. +1
    -0
      tests/tests.go

+ 44
- 0
README.md View File

@ -195,3 +195,47 @@ Here, we describe the requests and responses as function arguments and return va
#### Flush
* __Usage__:<br/>
* Signals that messages queued on the client should be flushed to the server. It is called periodically by the client implementation to ensure asynchronous requests are actually sent, and is called immediately to make a synchronous request, which returns when the Flush response comes back.
# Implementation
We provide three implementations of the ABCI in Go:
1. ABCI-socket
2. GRPC
3. Golang in-process
## Socket
ABCI is best implemented as a streaming protocol.
The socket implementation provides for asynchronous, ordered message passing over unix or tcp.
Messages are serialized using Protobuf3 and length-prefixed.
Protobuf3 doesn't have an official length-prefix standard, so we use our own. The first byte represents the length of the big-endian encoded length.
For example, if the Protobuf3 encoded ABCI message is `0xDEADBEEF` (4 bytes), the length-prefixed message is `0x0104DEADBEEF`. If the Protobuf3 encoded ABCI message is 65535 bytes long, the length-prefixed message would be like `0x02FFFF...`.
## GRPC
GRPC is an rpc framework native to Protocol Buffers with support in many languages.
Implementing the ABCI using GRPC can allow for faster prototyping, but is expected to be much slower than
the ordered, asynchronous socket protocol.
Note the length-prefixing used in the socket implementation does not apply for GRPC.
## In Process
The simplest implementation just uses function calls within Go.
This means ABCI applications written in Golang can be compiled with TendermintCore and run as a single binary.
# Tools and Apps
The `abci-cli` tool wraps any ABCI client and can be used for probing/testing an ABCI application.
See the [guide](https://tendermint.readthedocs.io/en/master/abci-cli.html) for more details.
Multiple example apps are included:
- the `counter` application, which illustrates nonce checking in txs
- the `dummy` application, which illustrates a simple key-value merkle tree
- the `dummy --persistent` application, which augments the dummy with persistence and validator set changes
When you are developing an implementation of the ABCI server in your favourite language, we provide the `abci-cli test`
command that allows you to run our tests against your own ABCI server. Please make sure that your server supports at least the TSP protocol, and optionally gRPC.

+ 2
- 3
client/grpc_client.go View File

@ -48,7 +48,6 @@ func (cli *grpcClient) OnStart() error {
return err
}
RETRY_LOOP:
for {
conn, err := grpc.Dial(cli.addr, grpc.WithInsecure(), grpc.WithDialer(dialerFunc))
if err != nil {
@ -83,8 +82,8 @@ func (cli *grpcClient) OnStop() {
cli.mtx.Lock()
defer cli.mtx.Unlock()
// TODO: how to close conn? its not a net.Conn and grpc doesn't expose a Close()
/*if cli.conn != nil {
cli.conn.Close()
/*if cli.client.conn != nil {
cli.client.conn.Close()
}*/
}


+ 60
- 0
cmd/abci-cli/abci-cli.go View File

@ -16,9 +16,11 @@ import (
"github.com/tendermint/tmlibs/log"
abcicli "github.com/tendermint/abci/client"
"github.com/tendermint/abci/example/code"
"github.com/tendermint/abci/example/counter"
"github.com/tendermint/abci/example/dummy"
"github.com/tendermint/abci/server"
servertest "github.com/tendermint/abci/tests/server"
"github.com/tendermint/abci/types"
"github.com/tendermint/abci/version"
)
@ -141,6 +143,7 @@ func addCommands() {
RootCmd.AddCommand(checkTxCmd)
RootCmd.AddCommand(commitCmd)
RootCmd.AddCommand(versionCmd)
RootCmd.AddCommand(testCmd)
addQueryFlags()
RootCmd.AddCommand(queryCmd)
@ -271,6 +274,16 @@ var dummyCmd = &cobra.Command{
},
}
var testCmd = &cobra.Command{
Use: "test",
Short: "Run integration tests",
Long: "",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
return cmdTest(cmd, args)
},
}
// Generates new Args array based off of previous call args to maintain flag persistence
func persistentArgs(line []byte) []string {
@ -287,6 +300,53 @@ func persistentArgs(line []byte) []string {
//--------------------------------------------------------------------------------
func or(err1 error, err2 error) error {
if err1 == nil {
return err2
} else {
return err1
}
}
func cmdTest(cmd *cobra.Command, args []string) error {
fmt.Println("Running tests")
var err error
err = servertest.InitChain(client)
fmt.Println("")
err = or(err, servertest.SetOption(client, "serial", "on"))
fmt.Println("")
err = or(err, servertest.Commit(client, nil))
fmt.Println("")
err = or(err, servertest.DeliverTx(client, []byte("abc"), code.CodeTypeBadNonce, nil))
fmt.Println("")
err = or(err, servertest.Commit(client, nil))
fmt.Println("")
err = or(err, servertest.DeliverTx(client, []byte{0x00}, code.CodeTypeOK, nil))
fmt.Println("")
err = or(err, servertest.Commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 1}))
fmt.Println("")
err = or(err, servertest.DeliverTx(client, []byte{0x00}, code.CodeTypeBadNonce, nil))
fmt.Println("")
err = or(err, servertest.DeliverTx(client, []byte{0x01}, code.CodeTypeOK, nil))
fmt.Println("")
err = or(err, servertest.DeliverTx(client, []byte{0x00, 0x02}, code.CodeTypeOK, nil))
fmt.Println("")
err = or(err, servertest.DeliverTx(client, []byte{0x00, 0x03}, code.CodeTypeOK, nil))
fmt.Println("")
err = or(err, servertest.DeliverTx(client, []byte{0x00, 0x00, 0x04}, code.CodeTypeOK, nil))
fmt.Println("")
err = or(err, servertest.DeliverTx(client, []byte{0x00, 0x00, 0x06}, code.CodeTypeBadNonce, nil))
fmt.Println("")
err = or(err, servertest.Commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 5}))
if err != nil {
return errors.New("Some checks didn't pass, please inspect stdout to see the exact failures.")
}
return nil
}
func cmdBatch(cmd *cobra.Command, args []string) error {
bufReader := bufio.NewReader(os.Stdin)
for {


+ 98
- 0
tests/server/client.go View File

@ -0,0 +1,98 @@
package testsuite
import (
"bytes"
"errors"
"fmt"
abcicli "github.com/tendermint/abci/client"
"github.com/tendermint/abci/types"
crypto "github.com/tendermint/go-crypto"
cmn "github.com/tendermint/tmlibs/common"
)
func InitChain(client abcicli.Client) error {
total := 10
vals := make([]*types.Validator, total)
for i := 0; i < total; i++ {
pubkey := crypto.GenPrivKeyEd25519FromSecret([]byte(cmn.Fmt("test%d", i))).PubKey().Bytes()
power := cmn.RandInt()
vals[i] = &types.Validator{pubkey, int64(power)}
}
_, err := client.InitChainSync(types.RequestInitChain{Validators: vals})
if err != nil {
fmt.Println("Failed test: InitChain - %v", err)
return err
}
fmt.Println("Passed test: InitChain")
return nil
}
func SetOption(client abcicli.Client, key, value string) error {
res, err := client.SetOptionSync(types.RequestSetOption{Key: key, Value: value})
log := res.GetLog()
if err != nil {
fmt.Println("Failed test: SetOption")
fmt.Printf("setting %v=%v: \nlog: %v", key, value, log)
fmt.Println("Failed test: SetOption")
return err
}
fmt.Println("Passed test: SetOption")
return nil
}
func Commit(client abcicli.Client, hashExp []byte) error {
res, err := client.CommitSync()
_, data := res.Code, res.Data
if err != nil {
fmt.Println("Failed test: Commit")
fmt.Printf("committing %v\nlog: %v", res.GetLog())
return err
}
if !bytes.Equal(data, hashExp) {
fmt.Println("Failed test: Commit")
fmt.Printf("Commit hash was unexpected. Got %X expected %X",
data.Bytes(), hashExp)
return errors.New("CommitTx failed")
}
fmt.Println("Passed test: Commit")
return nil
}
func DeliverTx(client abcicli.Client, txBytes []byte, codeExp uint32, dataExp []byte) error {
res, _ := client.DeliverTxSync(txBytes)
code, data, log := res.Code, res.Data, res.Log
if code != codeExp {
fmt.Println("Failed test: DeliverTx")
fmt.Printf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v",
code, codeExp, log)
return errors.New("DeliverTx error")
}
if !bytes.Equal(data, dataExp) {
fmt.Println("Failed test: DeliverTx")
fmt.Printf("DeliverTx response data was unexpected. Got %X expected %X",
data, dataExp)
return errors.New("DeliverTx error")
}
fmt.Println("Passed test: DeliverTx")
return nil
}
func CheckTx(client abcicli.Client, txBytes []byte, codeExp uint32, dataExp []byte) error {
res, _ := client.CheckTxSync(txBytes)
code, data, log := res.Code, res.Data, res.Log
if code != codeExp {
fmt.Println("Failed test: CheckTx")
fmt.Printf("CheckTx response code was unexpected. Got %v expected %v. Log: %v",
code, codeExp, log)
return errors.New("CheckTx")
}
if !bytes.Equal(data, dataExp) {
fmt.Println("Failed test: CheckTx")
fmt.Printf("CheckTx response data was unexpected. Got %X expected %X",
data, dataExp)
return errors.New("CheckTx")
}
fmt.Println("Passed test: CheckTx")
return nil
}

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


+ 1
- 0
tests/tests.go View File

@ -0,0 +1 @@
package tests

Loading…
Cancel
Save