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.

54 lines
1.1 KiB

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