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.

52 lines
1.4 KiB

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