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.

48 lines
1.2 KiB

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