From 8357326db011b1b30bc13392423e953a815d95cf Mon Sep 17 00:00:00 2001 From: Krzysztof Jurewicz Date: Fri, 20 Oct 2017 18:44:37 +0200 Subject: [PATCH] Fix test command --- cmd/abci-cli/abci-cli.go | 43 ++++++++++++++++++++++++---------------- tests/server/client.go | 39 ++++++++++++++++-------------------- 2 files changed, 43 insertions(+), 39 deletions(-) diff --git a/cmd/abci-cli/abci-cli.go b/cmd/abci-cli/abci-cli.go index 9e8e86b9..3ee454aa 100644 --- a/cmd/abci-cli/abci-cli.go +++ b/cmd/abci-cli/abci-cli.go @@ -16,6 +16,7 @@ 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" @@ -274,10 +275,10 @@ var dummyCmd = &cobra.Command{ } var testCmd = &cobra.Command{ - Use: "test", + Use: "test", Short: "Run integration tests", - Long: "", - Args: cobra.ExactArgs(0), + Long: "", + Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) error { return cmdTest(cmd, args) }, @@ -299,6 +300,14 @@ 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") @@ -306,34 +315,34 @@ func cmdTest(cmd *cobra.Command, args []string) error { err = servertest.InitChain(client) fmt.Println("") - err = servertest.SetOption(client, "serial", "on") + err = or(err, servertest.SetOption(client, "serial", "on")) fmt.Println("") - err = servertest.Commit(client, nil) + err = or(err, servertest.Commit(client, nil)) fmt.Println("") - err = servertest.DeliverTx(client, []byte("abc"), types.CodeType_BadNonce, nil) + err = or(err, servertest.DeliverTx(client, []byte("abc"), code.CodeTypeBadNonce, nil)) fmt.Println("") - err = servertest.Commit(client, nil) + err = or(err, servertest.Commit(client, nil)) fmt.Println("") - err = servertest.DeliverTx(client, []byte{0x00}, types.CodeType_OK, nil) + err = or(err, servertest.DeliverTx(client, []byte{0x00}, code.CodeTypeOK, nil)) fmt.Println("") - err = servertest.Commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 1}) + err = or(err, servertest.Commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 1})) fmt.Println("") - err = servertest.DeliverTx(client, []byte{0x00}, types.CodeType_BadNonce, nil) + err = or(err, servertest.DeliverTx(client, []byte{0x00}, code.CodeTypeBadNonce, nil)) fmt.Println("") - err = servertest.DeliverTx(client, []byte{0x01}, types.CodeType_OK, nil) + err = or(err, servertest.DeliverTx(client, []byte{0x01}, code.CodeTypeOK, nil)) fmt.Println("") - err = servertest.DeliverTx(client, []byte{0x00, 0x02}, types.CodeType_OK, nil) + err = or(err, servertest.DeliverTx(client, []byte{0x00, 0x02}, code.CodeTypeOK, nil)) fmt.Println("") - err = servertest.DeliverTx(client, []byte{0x00, 0x03}, types.CodeType_OK, nil) + err = or(err, servertest.DeliverTx(client, []byte{0x00, 0x03}, code.CodeTypeOK, nil)) fmt.Println("") - err = servertest.DeliverTx(client, []byte{0x00, 0x00, 0x04}, types.CodeType_OK, nil) + err = or(err, servertest.DeliverTx(client, []byte{0x00, 0x00, 0x04}, code.CodeTypeOK, nil)) fmt.Println("") - err = servertest.DeliverTx(client, []byte{0x00, 0x00, 0x06}, types.CodeType_BadNonce, nil) + err = or(err, servertest.DeliverTx(client, []byte{0x00, 0x00, 0x06}, code.CodeTypeBadNonce, nil)) fmt.Println("") - err = servertest.Commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 5}) + 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 use the cli to see the exact failures.") + return errors.New("Some checks didn't pass, please inspect stdout to see the exact failures.") } return nil } diff --git a/tests/server/client.go b/tests/server/client.go index 502e4e8e..f1757fe1 100644 --- a/tests/server/client.go +++ b/tests/server/client.go @@ -17,9 +17,9 @@ func InitChain(client abcicli.Client) error { 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, uint64(power)} + vals[i] = &types.Validator{pubkey, int64(power)} } - err := client.InitChainSync(vals) + _, err := client.InitChainSync(types.RequestInitChain{Validators: vals}) if err != nil { fmt.Println("Failed test: InitChain - %v", err) return err @@ -29,38 +29,38 @@ func InitChain(client abcicli.Client) error { } func SetOption(client abcicli.Client, key, value string) error { - res := client.SetOptionSync(key, value) - _, _, log := res.Code, res.Data, res.Log - if res.IsErr() { + 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 errors.New(res.Error()) + return err } fmt.Println("Passed test: SetOption") return nil } func Commit(client abcicli.Client, hashExp []byte) error { - res := client.CommitSync() - _, data, log := res.Code, res.Data, res.Log - if res.IsErr() { + res, err := client.CommitSync() + _, data := res.Code, res.Data + if err != nil { fmt.Println("Failed test: Commit") - fmt.Printf("committing %v\nlog: %v", log) - return errors.New(res.Error()) + fmt.Printf("committing %v\nlog: %v", res.GetLog()) + return err } - if !bytes.Equal(res.Data, hashExp) { + if !bytes.Equal(data, hashExp) { fmt.Println("Failed test: Commit") fmt.Printf("Commit hash was unexpected. Got %X expected %X", - data, hashExp) + data.Bytes(), hashExp) return errors.New("CommitTx failed") } fmt.Println("Passed test: Commit") return nil } -func DeliverTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, dataExp []byte) error { - res := client.DeliverTxSync(txBytes) +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") @@ -78,14 +78,9 @@ func DeliverTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, da return nil } -func CheckTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, dataExp []byte) error { - res := client.CheckTxSync(txBytes) +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 res.IsErr() { - fmt.Println("Failed test: CheckTx") - fmt.Printf("checking tx %X: %v\nlog: %v", txBytes, log) - return errors.New(res.Error()) - } if code != codeExp { fmt.Println("Failed test: CheckTx") fmt.Printf("CheckTx response code was unexpected. Got %v expected %v. Log: %v",