2018-01-18 16:55:17 +00:00
|
|
|
package fake
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2024-09-20 09:08:11 +00:00
|
|
|
"go.uber.org/mock/gomock"
|
2020-01-02 09:10:19 +00:00
|
|
|
|
2018-01-18 16:55:17 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
|
|
"github.com/ethereum/go-ethereum/rpc"
|
|
|
|
)
|
|
|
|
|
2018-01-24 08:25:28 +00:00
|
|
|
// NewTestServer returns a mocked test server
|
2018-01-05 20:58:17 +00:00
|
|
|
func NewTestServer(ctrl *gomock.Controller) (*rpc.Server, *MockPublicTransactionPoolAPI) {
|
2018-01-18 16:55:17 +00:00
|
|
|
srv := rpc.NewServer()
|
2018-01-05 20:58:17 +00:00
|
|
|
svc := NewMockPublicTransactionPoolAPI(ctrl)
|
2018-01-18 16:55:17 +00:00
|
|
|
if err := srv.RegisterName("eth", svc); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return srv, svc
|
|
|
|
}
|
|
|
|
|
|
|
|
// CallArgs copied from module go-ethereum/internal/ethapi
|
|
|
|
type CallArgs struct {
|
|
|
|
From common.Address `json:"from"`
|
|
|
|
To *common.Address `json:"to"`
|
2018-02-27 10:39:30 +00:00
|
|
|
Gas hexutil.Uint64 `json:"gas"`
|
2018-01-18 16:55:17 +00:00
|
|
|
GasPrice hexutil.Big `json:"gasPrice"`
|
|
|
|
Value hexutil.Big `json:"value"`
|
|
|
|
Data hexutil.Bytes `json:"data"`
|
|
|
|
}
|
|
|
|
|
2018-01-24 08:25:28 +00:00
|
|
|
// PublicTransactionPoolAPI used to generate mock by mockgen util.
|
2018-01-18 16:55:17 +00:00
|
|
|
// This was done because PublicTransactionPoolAPI is located in internal/ethapi module
|
|
|
|
// and there is no easy way to generate mocks from internal modules.
|
2018-01-24 08:25:28 +00:00
|
|
|
type PublicTransactionPoolAPI interface {
|
2018-06-20 14:51:55 +00:00
|
|
|
GasPrice(ctx context.Context) (*hexutil.Big, error)
|
2018-02-27 10:39:30 +00:00
|
|
|
EstimateGas(ctx context.Context, args CallArgs) (hexutil.Uint64, error)
|
2018-01-18 16:55:17 +00:00
|
|
|
GetTransactionCount(ctx context.Context, address common.Address, blockNr rpc.BlockNumber) (*hexutil.Uint64, error)
|
|
|
|
SendRawTransaction(ctx context.Context, encodedTx hexutil.Bytes) (common.Hash, error)
|
|
|
|
}
|