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.

45 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. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  7. "github.com/tendermint/tendermint/rpc/client/mock"
  8. )
  9. func TestStatus(t *testing.T) {
  10. assert, require := assert.New(t), require.New(t)
  11. m := &mock.StatusMock{
  12. Call: mock.Call{
  13. Response: &ctypes.ResultStatus{
  14. LatestBlockHash: []byte("block"),
  15. LatestAppHash: []byte("app"),
  16. LatestBlockHeight: 10,
  17. }},
  18. }
  19. r := mock.NewStatusRecorder(m)
  20. require.Equal(0, len(r.Calls))
  21. // make sure response works proper
  22. status, err := r.Status()
  23. require.Nil(err, "%+v", err)
  24. assert.EqualValues("block", status.LatestBlockHash)
  25. assert.EqualValues(10, status.LatestBlockHeight)
  26. // make sure recorder works properly
  27. require.Equal(1, len(r.Calls))
  28. rs := r.Calls[0]
  29. assert.Equal("status", rs.Name)
  30. assert.Nil(rs.Args)
  31. assert.Nil(rs.Error)
  32. require.NotNil(rs.Response)
  33. st, ok := rs.Response.(*ctypes.ResultStatus)
  34. require.True(ok)
  35. assert.EqualValues("block", st.LatestBlockHash)
  36. assert.EqualValues(10, st.LatestBlockHeight)
  37. }