Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 0 additions & 4 deletions container/slice/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,6 @@ func NotSlot(a, b []primitives.Slot) []primitives.Slot {
return set
}

// IsInSlots returns true if a is in b and False otherwise.
func IsInSlots(a primitives.Slot, b []primitives.Slot) bool {
return slices.Contains(b, a)
}

// Unique returns an array with duplicates filtered based on the type given
func Unique[T comparable](a []T) []T {
Expand Down
46 changes: 25 additions & 21 deletions container/slice/slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"reflect"
"sort"
"testing"
"slices"

"github.com/OffchainLabs/prysm/v6/consensus-types/primitives"
"github.com/OffchainLabs/prysm/v6/container/slice"
Expand Down Expand Up @@ -281,13 +282,14 @@ func TestIsInUint64(t *testing.T) {
{4, []uint64{2, 3, 5, 4, 6}, true},
{100, []uint64{2, 3, 5, 4, 6}, false},
}
for _, tt := range testCases {
result := slice.IsInUint64(tt.a, tt.b)
if result != tt.result {
t.Errorf("IsIn(%d, %v)=%v, wanted: %v",
tt.a, tt.b, result, tt.result)
}
}
for _, tt := range testCases {
// Use standard library slices.Contains instead of a thin wrapper.
result := slices.Contains(tt.b, tt.a)
if result != tt.result {
t.Errorf("IsIn(%d, %v)=%v, wanted: %v",
tt.a, tt.b, result, tt.result)
}
}
}

func TestIsInInt64(t *testing.T) {
Expand All @@ -301,13 +303,14 @@ func TestIsInInt64(t *testing.T) {
{4, []int64{2, 3, 5, 4, 6}, true},
{100, []int64{2, 3, 5, 4, 6}, false},
}
for _, tt := range testCases {
result := slice.IsInInt64(tt.a, tt.b)
if result != tt.result {
t.Errorf("IsIn(%d, %v)=%v, wanted: %v",
tt.a, tt.b, result, tt.result)
}
}
for _, tt := range testCases {
// Use standard library slices.Contains instead of a thin wrapper.
result := slices.Contains(tt.b, tt.a)
if result != tt.result {
t.Errorf("IsIn(%d, %v)=%v, wanted: %v",
tt.a, tt.b, result, tt.result)
}
}
}

func TestUnionByteSlices(t *testing.T) {
Expand Down Expand Up @@ -580,13 +583,14 @@ func TestIsInSlots(t *testing.T) {
{4, []primitives.Slot{2, 3, 5, 4, 6}, true},
{100, []primitives.Slot{2, 3, 5, 4, 6}, false},
}
for _, tt := range testCases {
result := slice.IsInSlots(tt.a, tt.b)
if result != tt.result {
t.Errorf("IsIn(%d, %v)=%v, wanted: %v",
tt.a, tt.b, result, tt.result)
}
}
for _, tt := range testCases {
// Use standard library slices.Contains instead of a thin wrapper.
result := slices.Contains(tt.b, tt.a)
if result != tt.result {
t.Errorf("IsIn(%d, %v)=%v, wanted: %v",
tt.a, tt.b, result, tt.result)
}
}
}

func TestUnique(t *testing.T) {
Expand Down
14 changes: 8 additions & 6 deletions testing/endtoend/evaluators/slashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package evaluators
import (
"context"
"fmt"
"slices"

"github.com/OffchainLabs/prysm/v6/beacon-chain/core/signing"
fieldparams "github.com/OffchainLabs/prysm/v6/config/fieldparams"
Expand Down Expand Up @@ -196,12 +197,13 @@ func proposeDoubleBlock(_ *e2eTypes.EvaluationContext, conns ...*grpc.ClientConn
}

var proposerIndex primitives.ValidatorIndex
for i, duty := range duties.CurrentEpochDuties {
if slice.IsInSlots(chainHead.HeadSlot-1, duty.ProposerSlots) {
proposerIndex = primitives.ValidatorIndex(i)
break
}
}
for i, duty := range duties.CurrentEpochDuties {
// Use standard library slices.Contains instead of a thin wrapper.
if slices.Contains(duty.ProposerSlots, chainHead.HeadSlot-1) {
proposerIndex = primitives.ValidatorIndex(i)
break
}
}

validatorNum := int(params.BeaconConfig().MinGenesisActiveValidatorCount)
beaconNodeNum := e2e.TestParams.BeaconNodeCount
Expand Down