tendermint/abci/tests/test_app/main.go

85 lines
1.9 KiB
Go
Raw Normal View History

2016-07-23 15:54:58 -07:00
package main
import (
"fmt"
"log"
2016-07-23 15:54:58 -07:00
"os"
"os/exec"
"time"
2016-07-23 15:54:58 -07:00
2018-06-21 21:59:02 -07:00
"github.com/tendermint/tendermint/abci/example/code"
"github.com/tendermint/tendermint/abci/types"
2016-07-23 15:54:58 -07:00
)
2017-01-12 12:47:55 -08:00
var abciType string
2016-07-23 15:54:58 -07:00
func init() {
2017-01-12 12:47:55 -08:00
abciType = os.Getenv("ABCI")
if abciType == "" {
abciType = "socket"
2016-07-23 15:54:58 -07:00
}
}
func main() {
testCounter()
}
2017-11-27 23:24:17 -08:00
const (
maxABCIConnectTries = 10
)
func ensureABCIIsUp(typ string, n int) error {
var err error
2017-11-27 23:24:17 -08:00
cmdString := "abci-cli echo hello"
if typ == "grpc" {
cmdString = "abci-cli --abci grpc echo hello"
}
for i := 0; i < n; i++ {
2017-11-27 23:48:00 -08:00
cmd := exec.Command("bash", "-c", cmdString) // nolint: gas
_, err = cmd.CombinedOutput()
if err == nil {
break
}
2017-11-27 23:24:17 -08:00
<-time.After(500 * time.Millisecond)
}
return err
}
2016-07-23 15:54:58 -07:00
func testCounter() {
2017-01-12 12:47:55 -08:00
abciApp := os.Getenv("ABCI_APP")
if abciApp == "" {
panic("No ABCI_APP specified")
2016-07-23 15:54:58 -07:00
}
2017-01-12 12:47:55 -08:00
fmt.Printf("Running %s test with abci=%s\n", abciApp, abciType)
2017-11-27 23:48:00 -08:00
cmd := exec.Command("bash", "-c", fmt.Sprintf("abci-cli %s", abciApp)) // nolint: gas
cmd.Stdout = os.Stdout
if err := cmd.Start(); err != nil {
log.Fatalf("starting %q err: %v", abciApp, err)
}
defer cmd.Wait()
defer cmd.Process.Kill()
2017-11-27 23:24:17 -08:00
if err := ensureABCIIsUp(abciType, maxABCIConnectTries); err != nil {
log.Fatalf("echo failed: %v", err)
}
client := startClient(abciType)
2016-07-23 15:54:58 -07:00
defer client.Stop()
setOption(client, "serial", "on")
commit(client, nil)
2017-11-30 11:29:12 -08:00
deliverTx(client, []byte("abc"), code.CodeTypeBadNonce, nil)
commit(client, nil)
2017-11-30 11:29:12 -08:00
deliverTx(client, []byte{0x00}, types.CodeTypeOK, nil)
commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 1})
2017-11-30 11:29:12 -08:00
deliverTx(client, []byte{0x00}, code.CodeTypeBadNonce, nil)
deliverTx(client, []byte{0x01}, types.CodeTypeOK, nil)
deliverTx(client, []byte{0x00, 0x02}, types.CodeTypeOK, nil)
deliverTx(client, []byte{0x00, 0x03}, types.CodeTypeOK, nil)
deliverTx(client, []byte{0x00, 0x00, 0x04}, types.CodeTypeOK, nil)
deliverTx(client, []byte{0x00, 0x00, 0x06}, code.CodeTypeBadNonce, nil)
commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 5})
2016-07-23 15:54:58 -07:00
}