Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing methods in EthClient interface #332

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion common/ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,41 @@ type EthClient interface {
BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)
BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)
GetCurrentBlockNumber(ctx context.Context) (uint32, error)
BlockNumber(ctx context.Context) (uint64, error)
CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
CallContractAtHash(ctx context.Context, msg ethereum.CallMsg, blockHash common.Hash) ([]byte, error)
CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)
EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error)
FeeHistory(
ctx context.Context,
blockCount uint64,
lastBlock *big.Int,
rewardPercentiles []float64,
) (*ethereum.FeeHistory, error)
FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error)
HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error)
HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
NetworkID(ctx context.Context) (*big.Int, error)
NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)
PeerCount(ctx context.Context) (uint64, error)
PendingBalanceAt(ctx context.Context, account common.Address) (*big.Int, error)
PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error)
PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)
PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
PendingStorageAt(ctx context.Context, account common.Address, key common.Hash) ([]byte, error)
PendingTransactionCount(ctx context.Context) (uint, error)
SendTransaction(ctx context.Context, tx *types.Transaction) error
StorageAt(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error)
SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)
SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error)
SuggestGasPrice(ctx context.Context) (*big.Int, error)
SuggestGasTipCap(ctx context.Context) (*big.Int, error)
SyncProgress(ctx context.Context) (*ethereum.SyncProgress, error)
TransactionByHash(ctx context.Context, hash common.Hash) (tx *types.Transaction, isPending bool, err error)
TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error)
TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error)
TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
TransactionSender(ctx context.Context, tx *types.Transaction, block common.Hash, index uint) (common.Address, error)
GetLatestGasCaps(ctx context.Context) (gasTipCap, gasFeeCap *big.Int, err error)
EstimateGasPriceAndLimitAndSendTx(ctx context.Context, tx *types.Transaction, tag string, value *big.Int) (*types.Receipt, error)
UpdateGas(ctx context.Context, tx *types.Transaction, value, gasTipCap, gasFeeCap *big.Int) (*types.Transaction, error)
Expand Down
5 changes: 0 additions & 5 deletions common/geth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ func NewClient(config EthClientConfig, logger logging.Logger) (*EthClient, error
return c, err
}

func (c *EthClient) GetCurrentBlockNumber(ctx context.Context) (uint32, error) {
bn, err := c.Client.BlockNumber(ctx)
return uint32(bn), err
}

func (c *EthClient) GetAccountAddress() gethcommon.Address {
return c.AccountAddress
}
Expand Down
89 changes: 74 additions & 15 deletions common/mock/ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ type MockEthClient struct {

var _ dacommon.EthClient = (*MockEthClient)(nil)

func (mock *MockEthClient) GetCurrentBlockNumber(ctx context.Context) (uint32, error) {
args := mock.Called()
result := args.Get(0)
return result.(uint32), nil
}

func (mock *MockEthClient) GetAccountAddress() common.Address {
args := mock.Called()
result := args.Get(0)
Expand Down Expand Up @@ -61,12 +55,24 @@ func (mock *MockEthClient) BlockByNumber(ctx context.Context, number *big.Int) (
return result.(*types.Block), args.Error(1)
}

func (mock *MockEthClient) BlockNumber(ctx context.Context) (uint64, error) {
args := mock.Called()
result := args.Get(0)
return result.(uint64), nil
}

func (mock *MockEthClient) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) {
args := mock.Called()
result := args.Get(0)
return result.([]byte), args.Error(1)
}

func (mock *MockEthClient) CallContractAtHash(ctx context.Context, msg ethereum.CallMsg, blockHash common.Hash) ([]byte, error) {
args := mock.Called()
result := args.Get(0)
return result.([]byte), args.Error(1)
}

func (mock *MockEthClient) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) {
args := mock.Called()
result := args.Get(0)
Expand All @@ -79,6 +85,17 @@ func (mock *MockEthClient) EstimateGas(ctx context.Context, msg ethereum.CallMsg
return result.(uint64), args.Error(1)
}

func (mock *MockEthClient) FeeHistory(
ctx context.Context,
blockCount uint64,
lastBlock *big.Int,
rewardPercentiles []float64,
) (*ethereum.FeeHistory, error) {
args := mock.Called()
result := args.Get(0)
return result.(*ethereum.FeeHistory), args.Error(1)
}

func (mock *MockEthClient) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error) {
args := mock.Called(q)
result := args.Get(0)
Expand All @@ -97,12 +114,30 @@ func (mock *MockEthClient) HeaderByNumber(ctx context.Context, number *big.Int)
return result.(*types.Header), args.Error(1)
}

func (mock *MockEthClient) NetworkID(ctx context.Context) (*big.Int, error) {
args := mock.Called()
result := args.Get(0)
return result.(*big.Int), args.Error(1)
}

func (mock *MockEthClient) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error) {
args := mock.Called()
result := args.Get(0)
return result.(uint64), args.Error(1)
}

func (mock *MockEthClient) PeerCount(ctx context.Context) (uint64, error) {
args := mock.Called()
result := args.Get(0)
return result.(uint64), args.Error(1)
}

func (mock *MockEthClient) PendingBalanceAt(ctx context.Context, account common.Address) (*big.Int, error) {
args := mock.Called()
result := args.Get(0)
return result.(*big.Int), args.Error(1)
}

func (mock *MockEthClient) PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error) {
args := mock.Called()
result := args.Get(0)
Expand All @@ -121,6 +156,18 @@ func (mock *MockEthClient) PendingNonceAt(ctx context.Context, account common.Ad
return result.(uint64), args.Error(1)
}

func (mock *MockEthClient) PendingStorageAt(ctx context.Context, account common.Address, key common.Hash) ([]byte, error) {
args := mock.Called()
result := args.Get(0)
return result.([]byte), args.Error(1)
}

func (mock *MockEthClient) PendingTransactionCount(ctx context.Context) (uint, error) {
args := mock.Called()
result := args.Get(0)
return result.(uint), args.Error(1)
}

func (mock *MockEthClient) SendTransaction(ctx context.Context, tx *types.Transaction) error {
args := mock.Called()
return args.Error(0)
Expand Down Expand Up @@ -156,6 +203,12 @@ func (mock *MockEthClient) SuggestGasTipCap(ctx context.Context) (*big.Int, erro
return result.(*big.Int), args.Error(1)
}

func (mock *MockEthClient) SyncProgress(ctx context.Context) (*ethereum.SyncProgress, error) {
args := mock.Called()
result := args.Get(0)
return result.(*ethereum.SyncProgress), args.Error(1)
}

func (mock *MockEthClient) TransactionByHash(ctx context.Context, hash common.Hash) (tx *types.Transaction, isPending bool, err error) {
args := mock.Called(hash)
result1 := args.Get(0)
Expand Down Expand Up @@ -185,22 +238,19 @@ func (mock *MockEthClient) TransactionReceipt(ctx context.Context, txHash common
return result, args.Error(1)
}

func (mock *MockEthClient) TransactionSender(ctx context.Context, tx *types.Transaction, block common.Hash, index uint) (common.Address, error) {
args := mock.Called()
result := args.Get(0)
return result.(common.Address), args.Error(1)
}

func (mock *MockEthClient) GetLatestGasCaps(ctx context.Context) (gasTipCap, gasFeeCap *big.Int, err error) {
args := mock.Called()
result1 := args.Get(0)
result2 := args.Get(1)
return result1.(*big.Int), result2.(*big.Int), args.Error(2)
}

func (mock *MockEthClient) UpdateGas(ctx context.Context, tx *types.Transaction, value, gasTipCap, gasFeeCap *big.Int) (*types.Transaction, error) {
args := mock.Called()
var newTx *types.Transaction
if args.Get(0) != nil {
newTx = args.Get(0).(*types.Transaction)
}
return newTx, args.Error(1)
}

func (mock *MockEthClient) EstimateGasPriceAndLimitAndSendTx(ctx context.Context, tx *types.Transaction, tag string, value *big.Int) (*types.Receipt, error) {
args := mock.Called()
var result *types.Receipt
Expand All @@ -211,6 +261,15 @@ func (mock *MockEthClient) EstimateGasPriceAndLimitAndSendTx(ctx context.Context
return result, args.Error(1)
}

func (mock *MockEthClient) UpdateGas(ctx context.Context, tx *types.Transaction, value, gasTipCap, gasFeeCap *big.Int) (*types.Transaction, error) {
args := mock.Called()
var newTx *types.Transaction
if args.Get(0) != nil {
newTx = args.Get(0).(*types.Transaction)
}
return newTx, args.Error(1)
}

func (mock *MockEthClient) EnsureTransactionEvaled(ctx context.Context, tx *types.Transaction, tag string) (*types.Receipt, error) {
args := mock.Called()
var result *types.Receipt
Expand Down
3 changes: 2 additions & 1 deletion core/eth/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,8 @@ func (t *Transactor) CalculateOperatorChurnApprovalDigestHash(
}

func (t *Transactor) GetCurrentBlockNumber(ctx context.Context) (uint32, error) {
return t.EthClient.GetCurrentBlockNumber(ctx)
bn, err := t.EthClient.BlockNumber(ctx)
return uint32(bn), err
}

func (t *Transactor) GetQuorumCount(ctx context.Context, blockNumber uint32) (uint8, error) {
Expand Down
Loading