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

test(taiko-client): introduce TestTxPoolContentWithMinTip test case #18285

Merged
merged 12 commits into from
Oct 24, 2024
44 changes: 44 additions & 0 deletions packages/taiko-client/internal/testutils/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,50 @@ func SignatureFromRSV(r, s string, v byte) []byte {
return append(append(hexutil.MustDecode(r), hexutil.MustDecode(s)...), v)
}

func SendDynamicFeeTxWithNonce(
client *rpc.EthClient,
priv *ecdsa.PrivateKey,
nonce uint64,
to *common.Address,
value *big.Int,
data []byte,
) (*types.Transaction, error) {
head, err := client.HeaderByNumber(context.Background(), nil)
if err != nil {
return nil, err
}

auth, err := bind.NewKeyedTransactorWithChainID(priv, client.ChainID)
if err != nil {
return nil, err
}

gasTipCap, err := client.SuggestGasTipCap(context.Background())
if err != nil {
return nil, err
}

tx, err := auth.Signer(auth.From, types.NewTx(&types.DynamicFeeTx{
To: to,
Nonce: nonce,
Value: value,
GasTipCap: gasTipCap,
GasFeeCap: new(big.Int).Add(
gasTipCap,
new(big.Int).Mul(head.BaseFee, big.NewInt(2)),
),
Gas: 2100_000,
Data: data,
}))
if err != nil {
return nil, err
}
if err = client.SendTransaction(context.Background(), tx); err != nil {
return nil, err
}
return tx, nil
}

// SendDynamicFeeTx sends a dynamic transaction, used for tests.
func SendDynamicFeeTx(
client *rpc.EthClient,
Expand Down
85 changes: 85 additions & 0 deletions packages/taiko-client/proposer/proposer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package proposer

import (
"context"
"crypto/ecdsa"
"math/big"
"os"
"testing"
"time"

"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -119,6 +121,89 @@ func (s *ProposerTestSuite) SetupTest() {
s.cancel = cancel
}

func (s *ProposerTestSuite) TestTxPoolContentWithMinTip() {
if os.Getenv("L2_NODE") == "l2_reth" {
s.T().Skip()
}
skList := []string{
"0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d", // 0x70997970C51812dc3A010C7d01b50e0d17dc79C8
"0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a", // 0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC
"0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6", // 0x90F79bf6EB2c4f870365E785982E1f101E93b906
"0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a", // 0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65
"0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba", // 0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc
}

var (
p = s.p
privs []*ecdsa.PrivateKey
l2Cli = s.RPCClient.L2
chainID = l2Cli.ChainID
)

for _, sk := range skList {
priv, err := crypto.ToECDSA(common.FromHex(sk))
s.Nil(err)
privs = append(privs, priv)
}

for _, priv := range privs {
auth, err := bind.NewKeyedTransactorWithChainID(priv, chainID)
s.Nil(err)
nonce, err := l2Cli.PendingNonceAt(context.Background(), auth.From)
s.Nil(err)
for i := 0; i < 300; i++ {
_, err = testutils.SendDynamicFeeTxWithNonce(s.RPCClient.L2, priv, nonce+uint64(i), &auth.From, big.NewInt(1), nil)
s.Nil(err)
}
}

for _, testCase := range []struct {
blockMaxGasLimit uint32
blockMaxTxListBytes uint64
maxTransactionsLists uint64

txLengthList []int
}{
{
p.protocolConfigs.BlockMaxGasLimit,
rpc.BlockMaxTxListBytes,
p.MaxProposedTxListsPerEpoch,
[]int{1500},
},
{
p.protocolConfigs.BlockMaxGasLimit,
rpc.BlockMaxTxListBytes,
p.MaxProposedTxListsPerEpoch * 5,
[]int{1500},
},
{
p.protocolConfigs.BlockMaxGasLimit / 50,
rpc.BlockMaxTxListBytes,
200,
[]int{129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 81},
},
} {
res, err := s.RPCClient.GetPoolContent(
context.Background(),
p.proposerAddress,
testCase.blockMaxGasLimit,
testCase.blockMaxTxListBytes,
p.LocalAddresses,
testCase.maxTransactionsLists,
0,
p.chainConfig,
)
s.Nil(err)

s.GreaterOrEqual(int(testCase.maxTransactionsLists), len(res))
for i, txsLen := range testCase.txLengthList {
s.Equal(txsLen, res[i].TxList.Len())
s.GreaterOrEqual(uint64(testCase.blockMaxGasLimit), res[i].EstimatedGasUsed)
s.GreaterOrEqual(testCase.blockMaxTxListBytes, res[i].BytesLength)
}
}
}

func (s *ProposerTestSuite) TestProposeTxLists() {
p := s.p
ctx := p.ctx
Expand Down
Loading