status-go/transactions/fake/txservice.go
Igor Sirotin c1dd9397f7
refactor_: remove generated files from source control (#5878)
* fix_: gitignore generated files

* chore_: delete generated files

* fix_: update go generate instructions

* feat(Makefile)_: clean-generated-files target

* feat(Makefile)_: `generate` target

* fix(Makefile)_: dependent generate target

* ci_: run generate, update docker file deps

* fix(Makefile)_: remove `clean-generated-files` target

* fix(Makefile)_: simpler GO_GENERATE_CMD arg

* fix_: temp workspace GO_GENERATE_FAST_DIR
2024-10-03 20:59:44 +01:00

44 lines
1.5 KiB
Go

package fake
//go:generate mockgen -package=fake -source=txservice.go -destination=mock.go
import (
"context"
"go.uber.org/mock/gomock"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/rpc"
)
// NewTestServer returns a mocked test server
func NewTestServer(ctrl *gomock.Controller) (*rpc.Server, *MockPublicTransactionPoolAPI) {
srv := rpc.NewServer()
svc := NewMockPublicTransactionPoolAPI(ctrl)
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"`
Gas hexutil.Uint64 `json:"gas"`
GasPrice hexutil.Big `json:"gasPrice"`
Value hexutil.Big `json:"value"`
Data hexutil.Bytes `json:"data"`
}
// PublicTransactionPoolAPI used to generate mock by mockgen util.
// This was done because PublicTransactionPoolAPI is located in internal/ethapi module
// and there is no easy way to generate mocks from internal modules.
type PublicTransactionPoolAPI interface {
GasPrice(ctx context.Context) (*hexutil.Big, error)
EstimateGas(ctx context.Context, args CallArgs) (hexutil.Uint64, error)
GetTransactionCount(ctx context.Context, address common.Address, blockNr rpc.BlockNumber) (*hexutil.Uint64, error)
SendRawTransaction(ctx context.Context, encodedTx hexutil.Bytes) (common.Hash, error)
}