You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
1.9 KiB

8 years ago
8 years ago
8 years ago
8 years ago
7 years ago
7 years ago
7 years ago
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "os"
  6. "os/exec"
  7. "time"
  8. "github.com/tendermint/tendermint/abci/example/code"
  9. "github.com/tendermint/tendermint/abci/types"
  10. )
  11. var abciType string
  12. func init() {
  13. abciType = os.Getenv("ABCI")
  14. if abciType == "" {
  15. abciType = "socket"
  16. }
  17. }
  18. func main() {
  19. testCounter()
  20. }
  21. const (
  22. maxABCIConnectTries = 10
  23. )
  24. func ensureABCIIsUp(typ string, n int) error {
  25. var err error
  26. cmdString := "abci-cli echo hello"
  27. if typ == "grpc" {
  28. cmdString = "abci-cli --abci grpc echo hello"
  29. }
  30. for i := 0; i < n; i++ {
  31. cmd := exec.Command("bash", "-c", cmdString)
  32. _, err = cmd.CombinedOutput()
  33. if err == nil {
  34. break
  35. }
  36. <-time.After(500 * time.Millisecond)
  37. }
  38. return err
  39. }
  40. func testCounter() {
  41. abciApp := os.Getenv("ABCI_APP")
  42. if abciApp == "" {
  43. panic("No ABCI_APP specified")
  44. }
  45. fmt.Printf("Running %s test with abci=%s\n", abciApp, abciType)
  46. cmd := exec.Command("bash", "-c", fmt.Sprintf("abci-cli %s", abciApp))
  47. cmd.Stdout = os.Stdout
  48. if err := cmd.Start(); err != nil {
  49. log.Fatalf("starting %q err: %v", abciApp, err)
  50. }
  51. defer cmd.Wait()
  52. defer cmd.Process.Kill()
  53. if err := ensureABCIIsUp(abciType, maxABCIConnectTries); err != nil {
  54. log.Fatalf("echo failed: %v", err)
  55. }
  56. client := startClient(abciType)
  57. defer client.Stop()
  58. setOption(client, "serial", "on")
  59. commit(client, nil)
  60. deliverTx(client, []byte("abc"), code.CodeTypeBadNonce, nil)
  61. commit(client, nil)
  62. deliverTx(client, []byte{0x00}, types.CodeTypeOK, nil)
  63. commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 1})
  64. deliverTx(client, []byte{0x00}, code.CodeTypeBadNonce, nil)
  65. deliverTx(client, []byte{0x01}, types.CodeTypeOK, nil)
  66. deliverTx(client, []byte{0x00, 0x02}, types.CodeTypeOK, nil)
  67. deliverTx(client, []byte{0x00, 0x03}, types.CodeTypeOK, nil)
  68. deliverTx(client, []byte{0x00, 0x00, 0x04}, types.CodeTypeOK, nil)
  69. deliverTx(client, []byte{0x00, 0x00, 0x06}, code.CodeTypeBadNonce, nil)
  70. commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 5})
  71. }