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.

85 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. 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 cmd.Wait()
  53. defer cmd.Process.Kill()
  54. if err := ensureABCIIsUp(abciType, maxABCIConnectTries); err != nil {
  55. log.Fatalf("echo failed: %v", err)
  56. }
  57. client := startClient(abciType)
  58. defer client.Stop()
  59. setOption(client, "serial", "on")
  60. commit(client, nil)
  61. deliverTx(client, []byte("abc"), code.CodeTypeBadNonce, nil)
  62. commit(client, nil)
  63. deliverTx(client, []byte{0x00}, types.CodeTypeOK, nil)
  64. commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 1})
  65. deliverTx(client, []byte{0x00}, code.CodeTypeBadNonce, nil)
  66. deliverTx(client, []byte{0x01}, types.CodeTypeOK, nil)
  67. deliverTx(client, []byte{0x00, 0x02}, types.CodeTypeOK, nil)
  68. deliverTx(client, []byte{0x00, 0x03}, types.CodeTypeOK, nil)
  69. deliverTx(client, []byte{0x00, 0x00, 0x04}, types.CodeTypeOK, nil)
  70. deliverTx(client, []byte{0x00, 0x00, 0x06}, code.CodeTypeBadNonce, nil)
  71. commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 5})
  72. }