mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 18:30:45 +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
|
return &rpc.Subscription{}, rpc.ErrNotificationsUnsupported
|
||||||
}
|
}
|
||||||
|
|
||||||
rpcSub := notifier.CreateSubscription()
|
var (
|
||||||
|
rpcSub = notifier.CreateSubscription()
|
||||||
txs := make(chan []*types.Transaction, 128)
|
txs = make(chan []*types.Transaction, 128)
|
||||||
pendingTxSub := api.events.SubscribePendingTxs(txs)
|
pendingTxSub = api.events.SubscribePendingTxs(txs)
|
||||||
|
)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer pendingTxSub.Unsubscribe()
|
defer pendingTxSub.Unsubscribe()
|
||||||
|
|
@ -261,10 +262,11 @@ func (api *FilterAPI) NewHeads(ctx context.Context) (*rpc.Subscription, error) {
|
||||||
return &rpc.Subscription{}, rpc.ErrNotificationsUnsupported
|
return &rpc.Subscription{}, rpc.ErrNotificationsUnsupported
|
||||||
}
|
}
|
||||||
|
|
||||||
rpcSub := notifier.CreateSubscription()
|
var (
|
||||||
|
rpcSub = notifier.CreateSubscription()
|
||||||
headers := make(chan *types.Header)
|
headers = make(chan *types.Header)
|
||||||
headersSub := api.events.SubscribeNewHeads(headers)
|
headersSub = api.events.SubscribeNewHeads(headers)
|
||||||
|
)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer headersSub.Unsubscribe()
|
defer headersSub.Unsubscribe()
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@ import (
|
||||||
"math/big"
|
"math/big"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum"
|
"github.com/ethereum/go-ethereum"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
|
@ -420,11 +419,11 @@ func testSubscribePendingTransactions(t *testing.T, client *rpc.Client) {
|
||||||
ethcl := ethclient.NewClient(client)
|
ethcl := ethclient.NewClient(client)
|
||||||
|
|
||||||
// Subscribe to Transactions
|
// Subscribe to Transactions
|
||||||
ch1 := make(chan common.Hash, 128)
|
ch1 := make(chan common.Hash)
|
||||||
ec.SubscribePendingTransactions(context.Background(), ch1)
|
ec.SubscribePendingTransactions(context.Background(), ch1)
|
||||||
|
|
||||||
// Subscribe to Transactions
|
// Subscribe to Transactions
|
||||||
ch2 := make(chan *types.Transaction, 128)
|
ch2 := make(chan *types.Transaction)
|
||||||
ec.SubscribeFullPendingTransactions(context.Background(), ch2)
|
ec.SubscribeFullPendingTransactions(context.Background(), ch2)
|
||||||
|
|
||||||
// Send a transaction
|
// Send a transaction
|
||||||
|
|
@ -453,23 +452,14 @@ func testSubscribePendingTransactions(t *testing.T, client *rpc.Client) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
// Check that the transaction was sent over the channel
|
// Check that the transaction was sent over the channel
|
||||||
timeout := 10 * time.Second
|
hash := <-ch1
|
||||||
select {
|
if hash != signedTx.Hash() {
|
||||||
case hash := <-ch1:
|
t.Fatalf("Invalid tx hash received, got %v, want %v", hash, signedTx.Hash())
|
||||||
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")
|
|
||||||
}
|
}
|
||||||
// Check that the transaction was sent over the channel
|
// Check that the transaction was sent over the channel
|
||||||
select {
|
tx = <-ch2
|
||||||
case tx := <-ch2:
|
if tx.Hash() != signedTx.Hash() {
|
||||||
if tx.Hash() != signedTx.Hash() {
|
t.Fatalf("Invalid tx hash received, got %v, want %v", 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")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue