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.

54 lines
1.2 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. package main
  2. import (
  3. "strconv"
  4. "strings"
  5. "testing"
  6. . "github.com/tendermint/go-common"
  7. "github.com/tendermint/tmsp/client"
  8. "github.com/tendermint/tmsp/server"
  9. "github.com/tendermint/tmsp/types"
  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. defer srv.Stop()
  19. // Connect to the socket
  20. client, err := tmspcli.NewSocketClient("unix://test.sock", false)
  21. if err != nil {
  22. Exit(Fmt("Error starting socket client: %v", err.Error()))
  23. }
  24. client.Start()
  25. defer client.Stop()
  26. n := uint64(5)
  27. hash := []byte("fake block hash")
  28. header := &types.Header{}
  29. for i := uint64(0); i < n; i++ {
  30. client.BeginBlockSync(hash, header)
  31. client.EndBlockSync(i)
  32. client.CommitSync()
  33. }
  34. r := app.Query(nil)
  35. spl := strings.Split(string(r.Data), ",")
  36. if len(spl) != 2 {
  37. t.Fatal("expected %d,%d ; got %s", n, n, string(r.Data))
  38. }
  39. beginCount, _ := strconv.Atoi(spl[0])
  40. endCount, _ := strconv.Atoi(spl[1])
  41. if uint64(beginCount) != n {
  42. t.Fatalf("expected beginCount of %d, got %d", n, beginCount)
  43. } else if uint64(endCount) != n {
  44. t.Fatalf("expected endCount of %d, got %d", n, endCount)
  45. }
  46. }