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.

59 lines
1.7 KiB

  1. package mock_test
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "github.com/stretchr/testify/assert"
  7. "github.com/stretchr/testify/require"
  8. "github.com/tendermint/tendermint/libs/bytes"
  9. "github.com/tendermint/tendermint/rpc/client/mock"
  10. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  11. )
  12. func TestStatus(t *testing.T) {
  13. assert, require := assert.New(t), require.New(t)
  14. m := &mock.StatusMock{
  15. Call: mock.Call{
  16. Response: &ctypes.ResultStatus{
  17. SyncInfo: ctypes.SyncInfo{
  18. LatestBlockHash: bytes.HexBytes("block"),
  19. LatestAppHash: bytes.HexBytes("app"),
  20. LatestBlockHeight: 10,
  21. MaxPeerBlockHeight: 20,
  22. TotalSyncedTime: time.Second,
  23. RemainingTime: time.Minute,
  24. },
  25. }},
  26. }
  27. r := mock.NewStatusRecorder(m)
  28. require.Equal(0, len(r.Calls))
  29. // make sure response works proper
  30. status, err := r.Status(context.Background())
  31. require.Nil(err, "%+v", err)
  32. assert.EqualValues("block", status.SyncInfo.LatestBlockHash)
  33. assert.EqualValues(10, status.SyncInfo.LatestBlockHeight)
  34. assert.EqualValues(20, status.SyncInfo.MaxPeerBlockHeight)
  35. assert.EqualValues(time.Second, status.SyncInfo.TotalSyncedTime)
  36. assert.EqualValues(time.Minute, status.SyncInfo.RemainingTime)
  37. // make sure recorder works properly
  38. require.Equal(1, len(r.Calls))
  39. rs := r.Calls[0]
  40. assert.Equal("status", rs.Name)
  41. assert.Nil(rs.Args)
  42. assert.Nil(rs.Error)
  43. require.NotNil(rs.Response)
  44. st, ok := rs.Response.(*ctypes.ResultStatus)
  45. require.True(ok)
  46. assert.EqualValues("block", st.SyncInfo.LatestBlockHash)
  47. assert.EqualValues(10, st.SyncInfo.LatestBlockHeight)
  48. assert.EqualValues(20, st.SyncInfo.MaxPeerBlockHeight)
  49. assert.EqualValues(time.Second, status.SyncInfo.TotalSyncedTime)
  50. assert.EqualValues(time.Minute, status.SyncInfo.RemainingTime)
  51. }