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.

95 lines
2.2 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. subCommand := fmt.Sprintf("abci-cli %s", abciApp)
  47. cmd := exec.Command("bash", "-c", subCommand)
  48. cmd.Stdout = os.Stdout
  49. if err := cmd.Start(); err != nil {
  50. log.Fatalf("starting %q err: %v", abciApp, err)
  51. }
  52. defer func() {
  53. if err := cmd.Process.Kill(); err != nil {
  54. log.Printf("error on process kill: %v", err)
  55. }
  56. if err := cmd.Wait(); err != nil {
  57. log.Printf("error while waiting for cmd to exit: %v", err)
  58. }
  59. }()
  60. if err := ensureABCIIsUp(abciType, maxABCIConnectTries); err != nil {
  61. log.Fatalf("echo failed: %v", err)
  62. }
  63. client := startClient(abciType)
  64. defer func() {
  65. if err := client.Stop(); err != nil {
  66. log.Printf("error trying client stop: %v", err)
  67. }
  68. }()
  69. setOption(client, "serial", "on")
  70. commit(client, nil)
  71. deliverTx(client, []byte("abc"), code.CodeTypeBadNonce, nil)
  72. commit(client, nil)
  73. deliverTx(client, []byte{0x00}, types.CodeTypeOK, nil)
  74. commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 1})
  75. deliverTx(client, []byte{0x00}, code.CodeTypeBadNonce, nil)
  76. deliverTx(client, []byte{0x01}, types.CodeTypeOK, nil)
  77. deliverTx(client, []byte{0x00, 0x02}, types.CodeTypeOK, nil)
  78. deliverTx(client, []byte{0x00, 0x03}, types.CodeTypeOK, nil)
  79. deliverTx(client, []byte{0x00, 0x00, 0x04}, types.CodeTypeOK, nil)
  80. deliverTx(client, []byte{0x00, 0x00, 0x06}, code.CodeTypeBadNonce, nil)
  81. commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 5})
  82. }