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.

93 lines
2.1 KiB

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