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.

49 lines
1.3 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. },
  21. }},
  22. }
  23. r := mock.NewStatusRecorder(m)
  24. require.Equal(0, len(r.Calls))
  25. // make sure response works proper
  26. status, err := r.Status(context.Background())
  27. require.Nil(err, "%+v", err)
  28. assert.EqualValues("block", status.SyncInfo.LatestBlockHash)
  29. assert.EqualValues(10, status.SyncInfo.LatestBlockHeight)
  30. // make sure recorder works properly
  31. require.Equal(1, len(r.Calls))
  32. rs := r.Calls[0]
  33. assert.Equal("status", rs.Name)
  34. assert.Nil(rs.Args)
  35. assert.Nil(rs.Error)
  36. require.NotNil(rs.Response)
  37. st, ok := rs.Response.(*ctypes.ResultStatus)
  38. require.True(ok)
  39. assert.EqualValues("block", st.SyncInfo.LatestBlockHash)
  40. assert.EqualValues(10, st.SyncInfo.LatestBlockHeight)
  41. }