From 144ccf1c6022ca6e8e654253889e6bdcf44af9a5 Mon Sep 17 00:00:00 2001 From: jsvisa Date: Mon, 20 Oct 2025 23:58:40 +0800 Subject: [PATCH] internal: dry --- cmd/devp2p/internal/ethtest/suite.go | 39 +++++++--------------------- 1 file changed, 9 insertions(+), 30 deletions(-) diff --git a/cmd/devp2p/internal/ethtest/suite.go b/cmd/devp2p/internal/ethtest/suite.go index d41a67e8f6..d55087a1fe 100644 --- a/cmd/devp2p/internal/ethtest/suite.go +++ b/cmd/devp2p/internal/ethtest/suite.go @@ -1190,9 +1190,7 @@ func (s *Suite) testBadBlobTx(t *utesting.T, tx *types.Transaction, badTx *types } } -func (s *Suite) TestDuplicateTxs(t *utesting.T) { - t.Log(`This test sends a TransactionsMsg containing duplicate transactions and expects the node to disconnect.`) - +func (s *Suite) testDuplicateTxs(t *utesting.T, sendFunc func(*utesting.T, []*types.Transaction) error) { // Nudge client out of syncing mode to accept pending txs. if err := s.engine.sendForkchoiceUpdated(); err != nil { t.Fatalf("failed to send next block: %v", err) @@ -1214,37 +1212,18 @@ func (s *Suite) TestDuplicateTxs(t *utesting.T) { } txs := []*types.Transaction{tx, tx} - if err := s.sendDuplicateTxsInOneMsg(t, txs); err != nil { + if err := sendFunc(t, txs); err != nil { t.Fatal(err) } + s.chain.IncNonce(from, 1) +} + +func (s *Suite) TestDuplicateTxs(t *utesting.T) { + t.Log(`This test sends a TransactionsMsg containing duplicate transactions and expects the node to disconnect.`) + s.testDuplicateTxs(t, s.sendDuplicateTxsInOneMsg) } func (s *Suite) TestDuplicatePooledTxs(t *utesting.T) { t.Log(`This test announces transaction hashes to the node, then sends a PooledTransactionsMsg containing duplicate transactions and expects the node to disconnect.`) - - // Nudge client out of syncing mode to accept pending txs. - if err := s.engine.sendForkchoiceUpdated(); err != nil { - t.Fatalf("failed to send next block: %v", err) - } - - from, nonce := s.chain.GetSender(1) - inner := &types.DynamicFeeTx{ - ChainID: s.chain.config.ChainID, - Nonce: nonce, - GasTipCap: common.Big1, - GasFeeCap: s.chain.Head().BaseFee(), - Gas: 75000, - To: &common.Address{0xbb}, - Value: common.Big1, - } - tx, err := s.chain.SignTx(from, types.NewTx(inner)) - if err != nil { - t.Fatalf("failed to sign tx: %v", err) - } - - // Send the same transaction twice in the PooledTransactionsMsg. - txs := []*types.Transaction{tx, tx} - if err := s.sendDuplicatePooledTxsInOneMsg(t, txs); err != nil { - t.Fatal(err) - } + s.testDuplicateTxs(t, s.sendDuplicatePooledTxsInOneMsg) }