p2p: refactor to use slices.Delete

Signed-off-by: alex9long <alex9long@outlook.com>
This commit is contained in:
alex9long 2025-08-12 22:57:11 +08:00
parent 43b2aac33c
commit 1b63f65ba8
2 changed files with 3 additions and 2 deletions

View file

@ -182,7 +182,7 @@ func (t *pingRecorder) waitPing(timeout time.Duration) *enode.Node {
} }
if len(t.pinged) > 0 { if len(t.pinged) > 0 {
n := t.pinged[0] n := t.pinged[0]
t.pinged = append(t.pinged[:0], t.pinged[1:]...) t.pinged = slices.Delete(t.pinged, 0, 1)
return n return n
} }
t.cond.Wait() t.cond.Wait()

View file

@ -28,6 +28,7 @@ import (
"net" "net"
"net/netip" "net/netip"
"reflect" "reflect"
"slices"
"sync" "sync"
"testing" "testing"
"time" "time"
@ -348,7 +349,7 @@ func TestUDPv4_findnodeMultiReply(t *testing.T) {
// check that the sent neighbors are all returned by findnode // check that the sent neighbors are all returned by findnode
select { select {
case result := <-resultc: case result := <-resultc:
want := append(list[:2], list[3:]...) want := slices.Delete(list, 2, 3)
if !reflect.DeepEqual(result, want) { if !reflect.DeepEqual(result, want) {
t.Errorf("neighbors mismatch:\n got: %v\n want: %v", result, want) t.Errorf("neighbors mismatch:\n got: %v\n want: %v", result, want)
} }