Skip to content

Commit

Permalink
update dataposter test to support *ethclient.Client
Browse files Browse the repository at this point in the history
  • Loading branch information
ganeshvanahalli committed Sep 9, 2024
1 parent 09fe200 commit 070a43a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 58 deletions.
4 changes: 2 additions & 2 deletions arbnode/dataposter/data_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/ethereum/go-ethereum/consensus/misc/eip4844"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto/kzg4844"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
Expand All @@ -39,7 +40,6 @@ import (
"github.com/offchainlabs/nitro/arbnode/dataposter/noop"
"github.com/offchainlabs/nitro/arbnode/dataposter/slice"
"github.com/offchainlabs/nitro/arbnode/dataposter/storage"
"github.com/offchainlabs/nitro/arbutil"
"github.com/offchainlabs/nitro/util/arbmath"
"github.com/offchainlabs/nitro/util/blobs"
"github.com/offchainlabs/nitro/util/headerreader"
Expand Down Expand Up @@ -69,7 +69,7 @@ var (
type DataPoster struct {
stopwaiter.StopWaiter
headerReader *headerreader.HeaderReader
client arbutil.L1Interface
client *ethclient.Client
auth *bind.TransactOpts
signer signerFn
config ConfigFetcher
Expand Down
63 changes: 27 additions & 36 deletions arbnode/dataposter/dataposter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ package dataposter

import (
"context"
"errors"
"fmt"
"math/big"
"testing"
"time"

"github.com/Knetic/govaluate"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
Expand Down Expand Up @@ -152,46 +153,36 @@ func TestMaxFeeCapFormulaCalculation(t *testing.T) {
}
}

type stubL1Client struct {
type stubL1ClientInterface struct {
senderNonce uint64
suggestedGasTipCap *big.Int

// Define most of the required methods that aren't used by feeAndTipCaps
backends.SimulatedBackend
}

func (c *stubL1Client) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error) {
return c.senderNonce, nil
}

func (c *stubL1Client) SuggestGasTipCap(ctx context.Context) (*big.Int, error) {
return c.suggestedGasTipCap, nil
}

// Not used but we need to define
func (c *stubL1Client) BlockNumber(ctx context.Context) (uint64, error) {
return 0, nil
}

func (c *stubL1Client) CallContractAtHash(ctx context.Context, msg ethereum.CallMsg, blockHash common.Hash) ([]byte, error) {
return []byte{}, nil
}

func (c *stubL1Client) CodeAtHash(ctx context.Context, address common.Address, blockHash common.Hash) ([]byte, error) {
return []byte{}, nil
func (c *stubL1ClientInterface) CallContext(ctx_in context.Context, result interface{}, method string, args ...interface{}) error {
switch method {
case "eth_getTransactionCount":
ptr, ok := result.(*hexutil.Uint64)
if !ok {
return errors.New("result is not a *hexutil.Uint64")
}
*ptr = hexutil.Uint64(c.senderNonce)
case "eth_maxPriorityFeePerGas":
ptr, ok := result.(*hexutil.Big)
if !ok {
return errors.New("result is not a *hexutil.Big")
}
*ptr = hexutil.Big(*c.suggestedGasTipCap)
}
return nil
}

func (c *stubL1Client) ChainID(ctx context.Context) (*big.Int, error) {
func (c *stubL1ClientInterface) EthSubscribe(ctx context.Context, channel interface{}, args ...interface{}) (*rpc.ClientSubscription, error) {
return nil, nil
}

func (c *stubL1Client) Client() rpc.ClientInterface {
func (c *stubL1ClientInterface) BatchCallContext(ctx context.Context, b []rpc.BatchElem) error {
return nil
}

func (c *stubL1Client) TransactionSender(ctx context.Context, tx *types.Transaction, block common.Hash, index uint) (common.Address, error) {
return common.Address{}, nil
}
func (c *stubL1ClientInterface) Close() {}

func TestFeeAndTipCaps_EnoughBalance_NoBacklog_NoUnconfirmed_BlobTx(t *testing.T) {
conf := func() *DataPosterConfig {
Expand Down Expand Up @@ -223,10 +214,10 @@ func TestFeeAndTipCaps_EnoughBalance_NoBacklog_NoUnconfirmed_BlobTx(t *testing.T
extraBacklog: func() uint64 { return 0 },
balance: big.NewInt(0).Mul(big.NewInt(params.Ether), big.NewInt(10)),
usingNoOpStorage: false,
client: &stubL1Client{
client: ethclient.NewClient(&stubL1ClientInterface{
senderNonce: 1,
suggestedGasTipCap: big.NewInt(2 * params.GWei),
},
}),
auth: &bind.TransactOpts{
From: common.Address{},
},
Expand Down Expand Up @@ -354,10 +345,10 @@ func TestFeeAndTipCaps_RBF_RisingBlobFee_FallingBaseFee(t *testing.T) {
extraBacklog: func() uint64 { return 0 },
balance: big.NewInt(0).Mul(big.NewInt(params.Ether), big.NewInt(10)),
usingNoOpStorage: false,
client: &stubL1Client{
client: ethclient.NewClient(&stubL1ClientInterface{
senderNonce: 1,
suggestedGasTipCap: big.NewInt(2 * params.GWei),
},
}),
auth: &bind.TransactOpts{
From: common.Address{},
},
Expand Down
15 changes: 0 additions & 15 deletions arbutil/wait_for_l1.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,12 @@ import (
"math/big"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rpc"
)

type L1Interface interface {
bind.ContractBackend
bind.BlockHashContractCaller
ethereum.ChainReader
ethereum.ChainStateReader
ethereum.TransactionReader
TransactionSender(ctx context.Context, tx *types.Transaction, block common.Hash, index uint) (common.Address, error)
BlockNumber(ctx context.Context) (uint64, error)
PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error)
ChainID(ctx context.Context) (*big.Int, error)
Client() rpc.ClientInterface
}

func SendTxAsCall(ctx context.Context, client *ethclient.Client, tx *types.Transaction, from common.Address, blockNum *big.Int, unlimitedGas bool) ([]byte, error) {
var gas uint64
if unlimitedGas {
Expand Down
6 changes: 3 additions & 3 deletions staker/rollup_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ type RollupWatcher struct {
*rollupgen.RollupUserLogic
address common.Address
fromBlock *big.Int
client WatcherL1Interface
client RollupWatcherL1Interface
baseCallOpts bind.CallOpts
unSupportedL3Method atomic.Bool
}

type WatcherL1Interface interface {
type RollupWatcherL1Interface interface {
bind.ContractBackend
HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error)
}

func NewRollupWatcher(address common.Address, client WatcherL1Interface, callOpts bind.CallOpts) (*RollupWatcher, error) {
func NewRollupWatcher(address common.Address, client RollupWatcherL1Interface, callOpts bind.CallOpts) (*RollupWatcher, error) {
con, err := rollupgen.NewRollupUserLogic(address, client)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions staker/txbuilder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ type ValidatorWalletInterface interface {
// Builder combines any transactions sent to it via SendTransaction into one batch,
// which is then sent to the validator wallet.
// This lets the validator make multiple atomic transactions.
// This inherits from an eth client so it can be used as an L1Interface,
// where it transparently intercepts calls to SendTransaction and queues them for the next batch.
// This inherits from an ethclient.Client so it can be used to transparently
// intercept calls to SendTransaction and queue them for the next batch.
type Builder struct {
*ethclient.Client
transactions []*types.Transaction
Expand Down

0 comments on commit 070a43a

Please sign in to comment.