github.com/vipernet-xyz/tm@v0.34.24/rpc/client/mock/status.go (about)

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