Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions ethclient/gethclient/gethclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"math/big"
"strings"
"testing"
"time"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -413,12 +414,20 @@ func testSubscribePendingTransactions(t *testing.T, client *rpc.Client) {

// Subscribe to Transactions
ch1 := make(chan common.Hash)
ec.SubscribePendingTransactions(context.Background(), ch1)
sub1, err := ec.SubscribePendingTransactions(context.Background(), ch1)
if err != nil {
t.Fatalf("Failed to subscribe to pending transactions: %v", err)
}
defer sub1.Unsubscribe()

// Subscribe to Transactions
ch2 := make(chan *types.Transaction)
ec.SubscribeFullPendingTransactions(context.Background(), ch2)

sub2, err := ec.SubscribeFullPendingTransactions(context.Background(), ch2)
if err != nil {
t.Fatalf("Failed to subscribe to full pending transactions: %v", err)
}
defer sub2.Unsubscribe()
time.Sleep(100 * time.Millisecond)
// Send a transaction
chainID, err := ethcl.ChainID(context.Background())
if err != nil {
Expand All @@ -445,14 +454,26 @@ func testSubscribePendingTransactions(t *testing.T, client *rpc.Client) {
t.Fatal(err)
}
// Check that the transaction was sent over the channel
hash := <-ch1
if hash != signedTx.Hash() {
t.Fatalf("Invalid tx hash received, got %v, want %v", hash, signedTx.Hash())
select {
case hash := <-ch1:
if hash != signedTx.Hash() {
t.Fatalf("Invalid tx hash received, got %v, want %v", hash, signedTx.Hash())
}
case err := <-sub1.Err():
t.Fatalf("Subscription error: %v", err)
case <-time.After(5 * time.Second):
t.Fatal("Timeout waiting for pending transaction hash")
}
// Check that the transaction was sent over the channel
tx = <-ch2
if tx.Hash() != signedTx.Hash() {
t.Fatalf("Invalid tx hash received, got %v, want %v", tx.Hash(), signedTx.Hash())
select {
case tx = <-ch2:
if tx.Hash() != signedTx.Hash() {
t.Fatalf("Invalid tx hash received, got %v, want %v", tx.Hash(), signedTx.Hash())
}
case err := <-sub2.Err():
t.Fatalf("Subscription error: %v", err)
case <-time.After(5 * time.Second):
t.Fatal("Timeout waiting for full pending transaction")
}
}

Expand Down
Loading