mirror of
https://github.com/status-im/status-go.git
synced 2025-01-10 22:56:40 +00:00
653da5bcd0
Currently it is quite easy to introduce concurrency issues while working with transaction object. For example, race issue will exist every time while transaction is processed in a separate goroutine and caller will try to check for an error before event to Done channel is sent. This change removes all the data that is updated on transaction and leaves it with ID, Args and Context (which is not used at the moment). Signed-off-by: Dmitry Shulyak <yashulyak@gmail.com>
42 lines
1.4 KiB
Go
42 lines
1.4 KiB
Go
package fake
|
|
|
|
import (
|
|
"context"
|
|
"math/big"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
"github.com/ethereum/go-ethereum/rpc"
|
|
"github.com/golang/mock/gomock"
|
|
)
|
|
|
|
// 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.Big `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) (*big.Int, error)
|
|
EstimateGas(ctx context.Context, args CallArgs) (*hexutil.Big, error)
|
|
GetTransactionCount(ctx context.Context, address common.Address, blockNr rpc.BlockNumber) (*hexutil.Uint64, error)
|
|
SendRawTransaction(ctx context.Context, encodedTx hexutil.Bytes) (common.Hash, error)
|
|
}
|