mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
eth/filters: use var() blocks; revert test changes
Co-authored-by: s1na <1591639+s1na@users.noreply.github.com>
This commit is contained in:
parent
58696fa2ae
commit
397320bc2a
2 changed files with 18 additions and 26 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue