Skip to content

Commit

Permalink
Add SuggestGasTipCap to test client implementation
Browse files Browse the repository at this point in the history
SuggestGasTipCap was added to ethereum client in ethereum/go-ethereum@7a7abe3
We need to include it in client interface implementation we use in
tests.
  • Loading branch information
nkuba committed Aug 30, 2021
1 parent fde9f18 commit 83a8d6e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
15 changes: 14 additions & 1 deletion pkg/chain/ethereum/ethutil/rate_limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package ethutil
import (
"context"
"fmt"
"math/big"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/keep-network/keep-common/pkg/rate"
"math/big"
)

type rateLimiter struct {
Expand Down Expand Up @@ -96,6 +97,18 @@ func (rl *rateLimiter) SuggestGasPrice(
return rl.EthereumClient.SuggestGasPrice(ctx)
}

func (rl *rateLimiter) SuggestGasTipCap(
ctx context.Context,
) (*big.Int, error) {
err := rl.Limiter.AcquirePermit()
if err != nil {
return nil, fmt.Errorf("cannot acquire rate limiter permit: [%v]", err)
}
defer rl.Limiter.ReleasePermit()

return rl.EthereumClient.SuggestGasTipCap(ctx)
}

func (rl *rateLimiter) EstimateGas(
ctx context.Context,
call ethereum.CallMsg,
Expand Down
24 changes: 20 additions & 4 deletions pkg/chain/ethereum/ethutil/rate_limiter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package ethutil

import (
"context"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/keep-network/keep-common/pkg/rate"
"math/big"
"strings"
"sync"
"testing"
"time"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/keep-network/keep-common/pkg/rate"
)

func TestRateLimiter(t *testing.T) {
Expand Down Expand Up @@ -365,6 +366,13 @@ func (mec *mockEthereumClient) SuggestGasPrice(
return nil, nil
}

func (mec *mockEthereumClient) SuggestGasTipCap(
ctx context.Context,
) (*big.Int, error) {
mec.mockRequest()
return nil, nil
}

func (mec *mockEthereumClient) EstimateGas(
ctx context.Context,
call ethereum.CallMsg,
Expand Down Expand Up @@ -530,6 +538,14 @@ func getTests(
return err
},
},
"test SuggestGasTipCap": {
function: func() error {
_, err := client.SuggestGasTipCap(
context.Background(),
)
return err
},
},
"test EstimateGas": {
function: func() error {
_, err := client.EstimateGas(
Expand Down

0 comments on commit 83a8d6e

Please sign in to comment.