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.

55 lines
1.1 KiB

  1. package mock
  2. import (
  3. "github.com/tendermint/tendermint/rpc/client"
  4. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  5. )
  6. // StatusMock returns the result specified by the Call
  7. type StatusMock struct {
  8. Call
  9. }
  10. func (m *StatusMock) _assertStatusClient() client.StatusClient {
  11. return m
  12. }
  13. func (m *StatusMock) Status() (*ctypes.ResultStatus, error) {
  14. res, err := m.GetResponse(nil)
  15. if err != nil {
  16. return nil, err
  17. }
  18. return res.(*ctypes.ResultStatus), nil
  19. }
  20. // StatusRecorder can wrap another type (StatusMock, full client)
  21. // and record the status calls
  22. type StatusRecorder struct {
  23. Client client.StatusClient
  24. Calls []Call
  25. }
  26. func NewStatusRecorder(client client.StatusClient) *StatusRecorder {
  27. return &StatusRecorder{
  28. Client: client,
  29. Calls: []Call{},
  30. }
  31. }
  32. func (r *StatusRecorder) _assertStatusClient() client.StatusClient {
  33. return r
  34. }
  35. func (r *StatusRecorder) addCall(call Call) {
  36. r.Calls = append(r.Calls, call)
  37. }
  38. func (r *StatusRecorder) Status() (*ctypes.ResultStatus, error) {
  39. res, err := r.Client.Status()
  40. r.addCall(Call{
  41. Name: "status",
  42. Response: res,
  43. Error: err,
  44. })
  45. return res, err
  46. }