github.com/status-im/status-go@v1.1.0/transactions/fake/txservice.go (about)

     1  package fake
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/golang/mock/gomock"
     7  
     8  	"github.com/ethereum/go-ethereum/common"
     9  	"github.com/ethereum/go-ethereum/common/hexutil"
    10  	"github.com/ethereum/go-ethereum/rpc"
    11  )
    12  
    13  // NewTestServer returns a mocked test server
    14  func NewTestServer(ctrl *gomock.Controller) (*rpc.Server, *MockPublicTransactionPoolAPI) {
    15  	srv := rpc.NewServer()
    16  	svc := NewMockPublicTransactionPoolAPI(ctrl)
    17  	if err := srv.RegisterName("eth", svc); err != nil {
    18  		panic(err)
    19  	}
    20  	return srv, svc
    21  }
    22  
    23  // CallArgs copied from module go-ethereum/internal/ethapi
    24  type CallArgs struct {
    25  	From     common.Address  `json:"from"`
    26  	To       *common.Address `json:"to"`
    27  	Gas      hexutil.Uint64  `json:"gas"`
    28  	GasPrice hexutil.Big     `json:"gasPrice"`
    29  	Value    hexutil.Big     `json:"value"`
    30  	Data     hexutil.Bytes   `json:"data"`
    31  }
    32  
    33  // PublicTransactionPoolAPI used to generate mock by mockgen util.
    34  // This was done because PublicTransactionPoolAPI is located in internal/ethapi module
    35  // and there is no easy way to generate mocks from internal modules.
    36  type PublicTransactionPoolAPI interface {
    37  	GasPrice(ctx context.Context) (*hexutil.Big, error)
    38  	EstimateGas(ctx context.Context, args CallArgs) (hexutil.Uint64, error)
    39  	GetTransactionCount(ctx context.Context, address common.Address, blockNr rpc.BlockNumber) (*hexutil.Uint64, error)
    40  	SendRawTransaction(ctx context.Context, encodedTx hexutil.Bytes) (common.Hash, error)
    41  }