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.

55 lines
1.2 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "strconv"
  6. "strings"
  7. "testing"
  8. "github.com/tendermint/abci/client"
  9. "github.com/tendermint/abci/server"
  10. "github.com/tendermint/abci/types"
  11. )
  12. func TestChainAware(t *testing.T) {
  13. app := NewChainAwareApplication()
  14. // Start the listener
  15. srv, err := server.NewServer("unix://test.sock", "socket", app)
  16. if err != nil {
  17. t.Fatal(err)
  18. }
  19. defer srv.Stop()
  20. // Connect to the socket
  21. client, err := abcicli.NewSocketClient("unix://test.sock", false)
  22. if err != nil {
  23. log.Fatal(fmt.Sprintf("Error starting socket client: %v", err.Error()))
  24. }
  25. client.Start()
  26. defer client.Stop()
  27. n := uint64(5)
  28. hash := []byte("fake block hash")
  29. header := &types.Header{}
  30. for i := uint64(0); i < n; i++ {
  31. client.BeginBlockSync(hash, header)
  32. client.EndBlockSync(i)
  33. client.CommitSync()
  34. }
  35. r := app.Query(types.RequestQuery{})
  36. spl := strings.Split(string(r.Value), ",")
  37. if len(spl) != 2 {
  38. t.Fatal("expected %d,%d ; got %s", n, n, string(r.Value))
  39. }
  40. beginCount, _ := strconv.Atoi(spl[0])
  41. endCount, _ := strconv.Atoi(spl[1])
  42. if uint64(beginCount) != n {
  43. t.Fatalf("expected beginCount of %d, got %d", n, beginCount)
  44. } else if uint64(endCount) != n {
  45. t.Fatalf("expected endCount of %d, got %d", n, endCount)
  46. }
  47. }