Skip to content

Commit

Permalink
fix TestSetupValidatorsExporter
Browse files Browse the repository at this point in the history
  • Loading branch information
nkryuchkov committed Oct 15, 2024
1 parent cac920e commit 0476e21
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
25 changes: 16 additions & 9 deletions operator/validator/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/base64"
"encoding/hex"
"fmt"
"slices"
"sync"
"testing"
"time"
Expand All @@ -29,6 +30,7 @@ import (
ibftstorage "github.com/ssvlabs/ssv/ibft/storage"
"github.com/ssvlabs/ssv/logging"
"github.com/ssvlabs/ssv/network"
"github.com/ssvlabs/ssv/network/commons"
"github.com/ssvlabs/ssv/networkconfig"
operatordatastore "github.com/ssvlabs/ssv/operator/datastore"
"github.com/ssvlabs/ssv/operator/keys"
Expand Down Expand Up @@ -192,15 +194,14 @@ func TestSetupValidatorsExporter(t *testing.T) {
testCases := []struct {
name string
shareStorageListResponse []*types.SSVShare
expectMetadataFetch bool
syncHighestDecidedResponse error
getValidatorDataResponse error
}{
{"no shares of non committee", nil, false, nil, nil},
{"set up non committee validators", sharesWithMetadata, false, nil, nil},
{"set up non committee validators without metadata", sharesWithoutMetadata, false, nil, nil},
{"fail to sync highest decided", sharesWithMetadata, false, errors.New("failed to sync highest decided"), nil},
{"fail to update validators metadata", sharesWithMetadata, false, nil, errors.New("could not update all validators")},
{"no shares of non committee", nil, nil, nil},
{"set up non committee validators", sharesWithMetadata, nil, nil},
{"set up non committee validators without metadata", sharesWithoutMetadata, nil, nil},
{"fail to sync highest decided", sharesWithMetadata, errors.New("failed to sync highest decided"), nil},
{"fail to update validators metadata", sharesWithMetadata, nil, errors.New("could not update all validators")},
}

for _, tc := range testCases {
Expand All @@ -210,6 +211,14 @@ func TestSetupValidatorsExporter(t *testing.T) {
defer ctrl.Finish()
mockValidatorsMap := validators.New(context.TODO())

var subnets []byte
for _, share := range sharesWithMetadata {
subnets = append(subnets, byte(commons.ValidatorSubnet(hex.EncodeToString(share.ValidatorPubKey[:]))))
}
slices.Sort(subnets)

network.EXPECT().ActiveSubnets().Return(subnets).AnyTimes()

if tc.shareStorageListResponse == nil {
sharesStorage.EXPECT().List(gomock.Any(), gomock.Any()).Return(tc.shareStorageListResponse).Times(1)
} else {
Expand All @@ -229,9 +238,7 @@ func TestSetupValidatorsExporter(t *testing.T) {
}
}
}).AnyTimes()
if tc.expectMetadataFetch {
bc.EXPECT().GetValidatorData(gomock.Any()).Return(bcResponse, tc.getValidatorDataResponse).Times(1)
}
bc.EXPECT().GetValidatorData(gomock.Any()).Return(bcResponse, tc.getValidatorDataResponse).AnyTimes()
bc.EXPECT().GetBeaconNetwork().Return(networkconfig.Mainnet.Beacon.GetBeaconNetwork()).AnyTimes()
sharesStorage.EXPECT().UpdateValidatorsMetadata(gomock.Any()).Return(nil).AnyTimes()
recipientStorage.EXPECT().GetRecipientData(gomock.Any(), gomock.Any()).Return(recipientData, true, nil).AnyTimes()
Expand Down
27 changes: 14 additions & 13 deletions operator/validator/mocks/controller.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0476e21

Please sign in to comment.