eth/fetcher: using slices.Contains (#29383)

pull/29443/head
cui 6 months ago committed by GitHub
parent 12dcc162d0
commit a83e57666d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 25
      eth/fetcher/tx_fetcher_test.go

@ -20,6 +20,7 @@ import (
"errors" "errors"
"math/big" "math/big"
"math/rand" "math/rand"
"slices"
"testing" "testing"
"time" "time"
@ -1823,12 +1824,12 @@ func testTransactionFetcher(t *testing.T, tt txFetcherTest) {
continue continue
} }
for _, hash := range hashes { for _, hash := range hashes {
if !containsHash(request.hashes, hash) { if !slices.Contains(request.hashes, hash) {
t.Errorf("step %d, peer %s: hash %x missing from requests", i, peer, hash) t.Errorf("step %d, peer %s: hash %x missing from requests", i, peer, hash)
} }
} }
for _, hash := range request.hashes { for _, hash := range request.hashes {
if !containsHash(hashes, hash) { if !slices.Contains(hashes, hash) {
t.Errorf("step %d, peer %s: hash %x extra in requests", i, peer, hash) t.Errorf("step %d, peer %s: hash %x extra in requests", i, peer, hash)
} }
} }
@ -1850,7 +1851,7 @@ func testTransactionFetcher(t *testing.T, tt txFetcherTest) {
for hash := range fetcher.fetching { for hash := range fetcher.fetching {
var found bool var found bool
for _, req := range fetcher.requests { for _, req := range fetcher.requests {
if containsHash(req.hashes, hash) { if slices.Contains(req.hashes, hash) {
found = true found = true
break break
} }
@ -1891,12 +1892,12 @@ func testTransactionFetcher(t *testing.T, tt txFetcherTest) {
continue continue
} }
for _, hash := range hashes { for _, hash := range hashes {
if !containsHash(request.hashes, hash) { if !slices.Contains(request.hashes, hash) {
t.Errorf("step %d, peer %s: hash %x missing from requests", i, peer, hash) t.Errorf("step %d, peer %s: hash %x missing from requests", i, peer, hash)
} }
} }
for _, hash := range request.hashes { for _, hash := range request.hashes {
if !containsHash(hashes, hash) { if !slices.Contains(hashes, hash) {
t.Errorf("step %d, peer %s: hash %x extra in requests", i, peer, hash) t.Errorf("step %d, peer %s: hash %x extra in requests", i, peer, hash)
} }
} }
@ -1909,7 +1910,7 @@ func testTransactionFetcher(t *testing.T, tt txFetcherTest) {
for _, ann := range announces { for _, ann := range announces {
var found bool var found bool
for _, hs := range step.fetching { for _, hs := range step.fetching {
if containsHash(hs, ann.hash) { if slices.Contains(hs, ann.hash) {
found = true found = true
break break
} }
@ -1925,7 +1926,7 @@ func testTransactionFetcher(t *testing.T, tt txFetcherTest) {
} }
} }
for hash := range fetcher.announced { for hash := range fetcher.announced {
if !containsHash(queued, hash) { if !slices.Contains(queued, hash) {
t.Errorf("step %d: hash %x extra in announced", i, hash) t.Errorf("step %d: hash %x extra in announced", i, hash)
} }
} }
@ -1984,16 +1985,6 @@ func containsHashInAnnounces(slice []announce, hash common.Hash) bool {
return false return false
} }
// containsHash returns whether a hash is contained within a hash slice.
func containsHash(slice []common.Hash, hash common.Hash) bool {
for _, have := range slice {
if have == hash {
return true
}
}
return false
}
// Tests that a transaction is forgotten after the timeout. // Tests that a transaction is forgotten after the timeout.
func TestTransactionForgotten(t *testing.T) { func TestTransactionForgotten(t *testing.T) {
fetcher := NewTxFetcher( fetcher := NewTxFetcher(

Loading…
Cancel
Save