Browse Source

Merge pull request #160 from KrzysiekJ/test-cmd-short-circuit

Short-circuit assertions in test command
pull/1780/head
Zach 7 years ago
committed by GitHub
parent
commit
96c816f428
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 38 deletions
  1. +26
    -38
      cmd/abci-cli/abci-cli.go

+ 26
- 38
cmd/abci-cli/abci-cli.go View File

@ -299,49 +299,37 @@ func persistentArgs(line []byte) []string {
//--------------------------------------------------------------------------------
func or(err1 error, err2 error) error {
if err1 == nil {
return err2
func compose(fs []func() error) error {
if len(fs) == 0 {
return nil
} else {
return err1
err := fs[0]()
if err == nil {
return compose(fs[1:])
} else {
return err
}
}
}
func cmdTest(cmd *cobra.Command, args []string) error {
fmt.Println("Running tests")
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
return compose(
[]func() error{
func() error { return servertest.InitChain(client) },
func() error { return servertest.SetOption(client, "serial", "on") },
func() error { return servertest.Commit(client, nil) },
func() error { return servertest.DeliverTx(client, []byte("abc"), code.CodeTypeBadNonce, nil) },
func() error { return servertest.Commit(client, nil) },
func() error { return servertest.DeliverTx(client, []byte{0x00}, code.CodeTypeOK, nil) },
func() error { return servertest.Commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 1}) },
func() error { return servertest.DeliverTx(client, []byte{0x00}, code.CodeTypeBadNonce, nil) },
func() error { return servertest.DeliverTx(client, []byte{0x01}, code.CodeTypeOK, nil) },
func() error { return servertest.DeliverTx(client, []byte{0x00, 0x02}, code.CodeTypeOK, nil) },
func() error { return servertest.DeliverTx(client, []byte{0x00, 0x03}, code.CodeTypeOK, nil) },
func() error { return servertest.DeliverTx(client, []byte{0x00, 0x00, 0x04}, code.CodeTypeOK, nil) },
func() error { return servertest.DeliverTx(client, []byte{0x00, 0x00, 0x06}, code.CodeTypeBadNonce, nil) },
func() error { return servertest.Commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 5})},
})
}
func cmdBatch(cmd *cobra.Command, args []string) error {


Loading…
Cancel
Save