Skip to content

Commit

Permalink
operator/duties tests latest fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelkrolevets committed May 24, 2024
1 parent 472f800 commit ca61b0a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
17 changes: 11 additions & 6 deletions operator/duties/attester_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
spectypes "github.com/ssvlabs/ssv-spec/types"
"github.com/ssvlabs/ssv/operator/duties/dutystore"
"github.com/ssvlabs/ssv/operator/duties/mocks"
"github.com/ssvlabs/ssv/protocol/v2/blockchain/beacon"
"github.com/ssvlabs/ssv/protocol/v2/types"
)

func setupAttesterDutiesMock(s *Scheduler, dutiesMap *hashmap.Map[phase0.Epoch, []*eth2apiv1.AttesterDuty]) (chan struct{}, chan []*spectypes.BeaconDuty) {
Expand All @@ -27,20 +29,23 @@ func setupAttesterDutiesMock(s *Scheduler, dutiesMap *hashmap.Map[phase0.Epoch,
return duties, nil
}).AnyTimes()

getIndices := func(epoch phase0.Epoch) []phase0.ValidatorIndex {
getIndices := func(epoch phase0.Epoch) []*types.SSVShare {
uniqueIndices := make(map[phase0.ValidatorIndex]bool)

duties, _ := dutiesMap.Get(epoch)
for _, d := range duties {
uniqueIndices[d.ValidatorIndex] = true
}

indices := make([]phase0.ValidatorIndex, 0, len(uniqueIndices))
shares := make([]*types.SSVShare, 0, len(uniqueIndices))
for index := range uniqueIndices {
indices = append(indices, index)
share := &types.SSVShare{
Metadata: types.Metadata{BeaconMetadata: &beacon.ValidatorMetadata{Index: index}},
}
shares = append(shares, share)
}

return indices
return shares
}
s.ValidatorProvider.(*mocks.MockValidatorProvider).EXPECT().SelfParticipatingValidators(gomock.Any()).DoAndReturn(getIndices).AnyTimes()
s.ValidatorProvider.(*mocks.MockValidatorProvider).EXPECT().ParticipatingValidators(gomock.Any()).DoAndReturn(getIndices).AnyTimes()
Expand Down Expand Up @@ -69,7 +74,7 @@ func TestScheduler_Attester_Same_Slot(t *testing.T) {
scheduler, logger, ticker, timeout, cancel, schedulerPool, startFn := setupSchedulerAndMocks(t, handler, currentSlot)
fetchDutiesCall, executeDutiesCall := setupAttesterDutiesMock(scheduler, dutiesMap)
startFn()

handler.fetchCurrentEpoch = true
dutiesMap.Set(phase0.Epoch(0), []*eth2apiv1.AttesterDuty{
{
PubKey: phase0.BLSPubKey{1, 2, 3},
Expand Down Expand Up @@ -106,7 +111,7 @@ func TestScheduler_Attester_Diff_Slots(t *testing.T) {
scheduler, logger, ticker, timeout, cancel, schedulerPool, startFn := setupSchedulerAndMocks(t, handler, currentSlot)
fetchDutiesCall, executeDutiesCall := setupAttesterDutiesMock(scheduler, dutiesMap)
startFn()

handler.fetchCurrentEpoch = true
dutiesMap.Set(phase0.Epoch(0), []*eth2apiv1.AttesterDuty{
{
PubKey: phase0.BLSPubKey{1, 2, 3},
Expand Down
2 changes: 1 addition & 1 deletion operator/duties/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prysmaticlabs/prysm/v4/async/event"
"github.com/sourcegraph/conc/pool"
spectypes "github.com/ssvlabs/ssv-spec/types"
"go.uber.org/zap"

spectypes "github.com/ssvlabs/ssv-spec/types"
"github.com/ssvlabs/ssv/beacon/goclient"
"github.com/ssvlabs/ssv/logging"
"github.com/ssvlabs/ssv/logging/fields"
Expand Down
4 changes: 2 additions & 2 deletions operator/duties/sync_committee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
v1 "github.com/attestantio/go-eth2-client/api/v1"
"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/cornelk/hashmap"
spectypes "github.com/ssvlabs/ssv-spec/types"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"

spectypes "github.com/ssvlabs/ssv-spec/types"
"github.com/ssvlabs/ssv/operator/duties/dutystore"
"github.com/ssvlabs/ssv/operator/duties/mocks"
mocknetwork "github.com/ssvlabs/ssv/protocol/v2/blockchain/beacon/mocks"
Expand Down Expand Up @@ -73,7 +73,7 @@ func setupSyncCommitteeDutiesMock(s *Scheduler, dutiesMap *hashmap.Map[uint64, [
return indices
}

getDutiesBool := func(epoch phase0.Epoch, wait bool) []phase0.ValidatorIndex {
getDutiesBool := func(epoch phase0.Epoch) []phase0.ValidatorIndex {
return getDuties(epoch)
}

Expand Down

0 comments on commit ca61b0a

Please sign in to comment.