From 397320bc2acf8daf3908b4d7cb9a61a9088c410e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Mar 2026 16:25:11 +0000 Subject: [PATCH] eth/filters: use var() blocks; revert test changes Co-authored-by: s1na <1591639+s1na@users.noreply.github.com> --- eth/filters/api.go | 18 +++++++++-------- ethclient/gethclient/gethclient_test.go | 26 ++++++++----------------- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/eth/filters/api.go b/eth/filters/api.go index 015622527e..2cb72dc114 100644 --- a/eth/filters/api.go +++ b/eth/filters/api.go @@ -187,10 +187,11 @@ func (api *FilterAPI) NewPendingTransactions(ctx context.Context, fullTx *bool) return &rpc.Subscription{}, rpc.ErrNotificationsUnsupported } - rpcSub := notifier.CreateSubscription() - - txs := make(chan []*types.Transaction, 128) - pendingTxSub := api.events.SubscribePendingTxs(txs) + var ( + rpcSub = notifier.CreateSubscription() + txs = make(chan []*types.Transaction, 128) + pendingTxSub = api.events.SubscribePendingTxs(txs) + ) go func() { defer pendingTxSub.Unsubscribe() @@ -261,10 +262,11 @@ func (api *FilterAPI) NewHeads(ctx context.Context) (*rpc.Subscription, error) { return &rpc.Subscription{}, rpc.ErrNotificationsUnsupported } - rpcSub := notifier.CreateSubscription() - - headers := make(chan *types.Header) - headersSub := api.events.SubscribeNewHeads(headers) + var ( + rpcSub = notifier.CreateSubscription() + headers = make(chan *types.Header) + headersSub = api.events.SubscribeNewHeads(headers) + ) go func() { defer headersSub.Unsubscribe() diff --git a/ethclient/gethclient/gethclient_test.go b/ethclient/gethclient/gethclient_test.go index 68d1b537c0..4d8ccfcb6f 100644 --- a/ethclient/gethclient/gethclient_test.go +++ b/ethclient/gethclient/gethclient_test.go @@ -23,7 +23,6 @@ import ( "math/big" "strings" "testing" - "time" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" @@ -420,11 +419,11 @@ func testSubscribePendingTransactions(t *testing.T, client *rpc.Client) { ethcl := ethclient.NewClient(client) // Subscribe to Transactions - ch1 := make(chan common.Hash, 128) + ch1 := make(chan common.Hash) ec.SubscribePendingTransactions(context.Background(), ch1) // Subscribe to Transactions - ch2 := make(chan *types.Transaction, 128) + ch2 := make(chan *types.Transaction) ec.SubscribeFullPendingTransactions(context.Background(), ch2) // Send a transaction @@ -453,23 +452,14 @@ func testSubscribePendingTransactions(t *testing.T, client *rpc.Client) { t.Fatal(err) } // Check that the transaction was sent over the channel - timeout := 10 * time.Second - select { - case hash := <-ch1: - if hash != signedTx.Hash() { - t.Fatalf("Invalid tx hash received, got %v, want %v", hash, signedTx.Hash()) - } - case <-time.After(timeout): - t.Fatal("Timed out waiting for pending tx hash notification") + hash := <-ch1 + if hash != signedTx.Hash() { + t.Fatalf("Invalid tx hash received, got %v, want %v", hash, signedTx.Hash()) } // Check that the transaction was sent over the channel - select { - case tx := <-ch2: - if tx.Hash() != signedTx.Hash() { - t.Fatalf("Invalid tx hash received, got %v, want %v", tx.Hash(), signedTx.Hash()) - } - case <-time.After(timeout): - t.Fatal("Timed out waiting for pending full tx notification") + tx = <-ch2 + if tx.Hash() != signedTx.Hash() { + t.Fatalf("Invalid tx hash received, got %v, want %v", tx.Hash(), signedTx.Hash()) } }