test: move test to unit test

This commit is contained in:
healthykim 2025-12-10 17:06:04 +09:00
parent 266efa10fb
commit 89f0cbc18a
2 changed files with 29 additions and 58 deletions

View file

@ -21,7 +21,6 @@ import (
"crypto/rand" "crypto/rand"
"errors" "errors"
"fmt" "fmt"
"os"
"reflect" "reflect"
"sync" "sync"
"time" "time"
@ -87,7 +86,6 @@ func (s *Suite) EthTests() []utesting.Test {
{Name: "LargeTxRequest", Fn: s.TestLargeTxRequest, Slow: true}, {Name: "LargeTxRequest", Fn: s.TestLargeTxRequest, Slow: true},
{Name: "Transaction", Fn: s.TestTransaction}, {Name: "Transaction", Fn: s.TestTransaction},
{Name: "InvalidTxs", Fn: s.TestInvalidTxs}, {Name: "InvalidTxs", Fn: s.TestInvalidTxs},
{Name: "InvalidMetadata", Fn: s.TestInvalidMetadata},
{Name: "NewPooledTxs", Fn: s.TestNewPooledTxs}, {Name: "NewPooledTxs", Fn: s.TestNewPooledTxs},
{Name: "BlobViolations", Fn: s.TestBlobViolations}, {Name: "BlobViolations", Fn: s.TestBlobViolations},
{Name: "TestBlobTxWithoutSidecar", Fn: s.TestBlobTxWithoutSidecar}, {Name: "TestBlobTxWithoutSidecar", Fn: s.TestBlobTxWithoutSidecar},
@ -886,62 +884,6 @@ the transactions using a GetPooledTransactions request.`)
} }
} }
func (s *Suite) TestInvalidMetadata(t *utesting.T) {
t.Log(`This test announces transactions to the node and expects it not to fetch
transaction hash with wrong/unsupported metadata.`)
// 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,
}
tx, err := s.chain.SignTx(from, types.NewTx(inner))
if err != nil {
t.Fatalf("failed to sign tx: err")
}
conn, err := s.dial()
if err != nil {
t.Fatalf("dial failed: %v", err)
}
defer conn.Close()
if err = conn.peer(s.chain, nil); err != nil {
t.Fatalf("peering failed: %v", err)
}
ann := eth.NewPooledTransactionHashesPacket{Types: []byte{0x09}, Sizes: []uint32{uint32(tx.Size())}, Hashes: []common.Hash{tx.Hash()}}
err = conn.Write(ethProto, eth.NewPooledTransactionHashesMsg, ann)
if err != nil {
t.Fatalf("failed to write to connection: %v", err)
}
conn.SetReadDeadline(time.Now().Add(timeout))
msg, err := conn.ReadEth()
if err != nil && !errors.Is(err, os.ErrDeadlineExceeded) {
t.Fatalf("unexpected err: %v", err)
}
if err == nil {
switch msg := msg.(type) {
case *eth.GetPooledTransactionsPacket:
t.Fatalf("Transaction announcements with invalid metadata should be ignored")
case *eth.NewPooledTransactionHashesPacket:
return
case *eth.TransactionsPacket:
return
default:
t.Fatalf("unexpected %s", pretty.Sdump(msg))
}
}
}
func makeSidecar(data ...byte) *types.BlobTxSidecar { func makeSidecar(data ...byte) *types.BlobTxSidecar {
var ( var (
blobs = make([]kzg4844.Blob, len(data)) blobs = make([]kzg4844.Blob, len(data))

View file

@ -1908,6 +1908,35 @@ func TestTransactionFetcherDropAlternates(t *testing.T) {
}) })
} }
func TestTransactionFetcherWrongMetadata(t *testing.T) {
testTransactionFetcherParallel(t, txFetcherTest{
init: func() *TxFetcher {
return NewTxFetcher(
func(_ common.Hash, kind byte) error {
switch kind {
case types.LegacyTxType, types.AccessListTxType, types.DynamicFeeTxType, types.BlobTxType, types.SetCodeTxType:
return nil
}
return types.ErrTxTypeNotSupported
},
func(txs []*types.Transaction) []error {
return make([]error, len(txs))
},
func(string, []common.Hash) error { return nil },
nil,
)
},
steps: []interface{}{
doTxNotify{peer: "A", hashes: []common.Hash{{0x01}, {0x02}}, types: []byte{0xff, types.LegacyTxType}, sizes: []uint32{111, 222}},
isWaiting(map[string][]announce{
"A": {
{common.Hash{0x02}, types.LegacyTxType, 222},
},
}),
},
})
}
func testTransactionFetcherParallel(t *testing.T, tt txFetcherTest) { func testTransactionFetcherParallel(t *testing.T, tt txFetcherTest) {
t.Parallel() t.Parallel()
testTransactionFetcher(t, tt) testTransactionFetcher(t, tt)