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.

46 lines
1.1 KiB

  1. package mock_test
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/stretchr/testify/require"
  6. data "github.com/tendermint/go-wire/data"
  7. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  8. "github.com/tendermint/tendermint/rpc/client/mock"
  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. LatestBlockHash: data.Bytes("block"),
  16. LatestAppHash: data.Bytes("app"),
  17. LatestBlockHeight: 10,
  18. }},
  19. }
  20. r := mock.NewStatusRecorder(m)
  21. require.Equal(0, len(r.Calls))
  22. // make sure response works proper
  23. status, err := r.Status()
  24. require.Nil(err, "%+v", err)
  25. assert.EqualValues("block", status.LatestBlockHash)
  26. assert.EqualValues(10, status.LatestBlockHeight)
  27. // make sure recorder works properly
  28. require.Equal(1, len(r.Calls))
  29. rs := r.Calls[0]
  30. assert.Equal("status", rs.Name)
  31. assert.Nil(rs.Args)
  32. assert.Nil(rs.Error)
  33. require.NotNil(rs.Response)
  34. st, ok := rs.Response.(*ctypes.ResultStatus)
  35. require.True(ok)
  36. assert.EqualValues("block", st.LatestBlockHash)
  37. assert.EqualValues(10, st.LatestBlockHeight)
  38. }