@ -396,6 +396,59 @@ func TestTable_revalidateSyncRecord(t *testing.T) {
}
}
}
}
func TestNodesPush ( t * testing . T ) {
var target enode . ID
n1 := nodeAtDistance ( target , 255 , intIP ( 1 ) )
n2 := nodeAtDistance ( target , 254 , intIP ( 2 ) )
n3 := nodeAtDistance ( target , 253 , intIP ( 3 ) )
perm := [ ] [ ] * node {
{ n3 , n2 , n1 } ,
{ n3 , n1 , n2 } ,
{ n2 , n3 , n1 } ,
{ n2 , n1 , n3 } ,
{ n1 , n3 , n2 } ,
{ n1 , n2 , n3 } ,
}
// Insert all permutations into lists with size limit 3.
for _ , nodes := range perm {
list := nodesByDistance { target : target }
for _ , n := range nodes {
list . push ( n , 3 )
}
if ! slicesEqual ( list . entries , perm [ 0 ] , nodeIDEqual ) {
t . Fatal ( "not equal" )
}
}
// Insert all permutations into lists with size limit 2.
for _ , nodes := range perm {
list := nodesByDistance { target : target }
for _ , n := range nodes {
list . push ( n , 2 )
}
if ! slicesEqual ( list . entries , perm [ 0 ] [ : 2 ] , nodeIDEqual ) {
t . Fatal ( "not equal" )
}
}
}
func nodeIDEqual ( n1 , n2 * node ) bool {
return n1 . ID ( ) == n2 . ID ( )
}
func slicesEqual [ T any ] ( s1 , s2 [ ] T , check func ( e1 , e2 T ) bool ) bool {
if len ( s1 ) != len ( s2 ) {
return false
}
for i := range s1 {
if ! check ( s1 [ i ] , s2 [ i ] ) {
return false
}
}
return true
}
// gen wraps quick.Value so it's easier to use.
// gen wraps quick.Value so it's easier to use.
// it generates a random value of the given value's type.
// it generates a random value of the given value's type.
func gen ( typ interface { } , rand * rand . Rand ) interface { } {
func gen ( typ interface { } , rand * rand . Rand ) interface { } {