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.

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