internal: dry

This commit is contained in:
jsvisa 2025-10-20 23:58:40 +08:00
parent 107f54a05d
commit 144ccf1c60

View file

@ -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)
}