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.

53 lines
1.2 KiB

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