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.

52 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. var (
  11. _ client.StatusClient = (*StatusMock)(nil)
  12. _ client.StatusClient = (*StatusRecorder)(nil)
  13. )
  14. func (m *StatusMock) Status() (*ctypes.ResultStatus, error) {
  15. res, err := m.GetResponse(nil)
  16. if err != nil {
  17. return nil, err
  18. }
  19. return res.(*ctypes.ResultStatus), nil
  20. }
  21. // StatusRecorder can wrap another type (StatusMock, full client)
  22. // and record the status calls
  23. type StatusRecorder struct {
  24. Client client.StatusClient
  25. Calls []Call
  26. }
  27. func NewStatusRecorder(client client.StatusClient) *StatusRecorder {
  28. return &StatusRecorder{
  29. Client: client,
  30. Calls: []Call{},
  31. }
  32. }
  33. func (r *StatusRecorder) addCall(call Call) {
  34. r.Calls = append(r.Calls, call)
  35. }
  36. func (r *StatusRecorder) Status() (*ctypes.ResultStatus, error) {
  37. res, err := r.Client.Status()
  38. r.addCall(Call{
  39. Name: "status",
  40. Response: res,
  41. Error: err,
  42. })
  43. return res, err
  44. }