mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-10 19:51:20 +00:00
Correct how AllValidatorsAreExited creates status request (#7758)
* fix and regression test * address feedback * gofmt * improve test -- feedback Co-authored-by: dv8silencer <15720668+dv8silencer@users.noreply.github.com>
This commit is contained in:
parent
9e9a913069
commit
b4bce7c726
@ -597,7 +597,8 @@ func (v *validator) AllValidatorsAreExited(ctx context.Context) (bool, error) {
|
||||
}
|
||||
var publicKeys [][]byte
|
||||
for _, key := range validatingKeys {
|
||||
publicKeys = append(publicKeys, key[:])
|
||||
copyKey := key
|
||||
publicKeys = append(publicKeys, copyKey[:])
|
||||
}
|
||||
request := ðpb.MultipleValidatorStatusRequest{
|
||||
PublicKeys: publicKeys,
|
||||
|
@ -1015,3 +1015,44 @@ func TestAllValidatorsAreExited_NotAllExited(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, false, exited)
|
||||
}
|
||||
|
||||
// TestAllValidatorsAreExited_CorrectRequest is a regression test that checks if the request contains the correct keys
|
||||
func TestAllValidatorsAreExited_CorrectRequest(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
client := mock.NewMockBeaconNodeValidatorClient(ctrl)
|
||||
|
||||
// Create two different public keys
|
||||
pubKey0 := [48]byte{1, 2, 3, 4}
|
||||
pubKey1 := [48]byte{6, 7, 8, 9}
|
||||
// This is the request expected from AllValidatorsAreExited()
|
||||
request := ðpb.MultipleValidatorStatusRequest{
|
||||
PublicKeys: [][]byte{
|
||||
pubKey0[:],
|
||||
pubKey1[:],
|
||||
},
|
||||
}
|
||||
statuses := []*ethpb.ValidatorStatusResponse{
|
||||
{Status: ethpb.ValidatorStatus_ACTIVE},
|
||||
{Status: ethpb.ValidatorStatus_EXITED},
|
||||
}
|
||||
|
||||
client.EXPECT().MultipleValidatorStatus(
|
||||
gomock.Any(), // ctx
|
||||
request, // request
|
||||
).Return(ðpb.MultipleValidatorStatusResponse{Statuses: statuses}, nil /*err*/)
|
||||
|
||||
keysMap := make(map[[48]byte]bls.SecretKey)
|
||||
// secretKey below is just filler and is used multiple times
|
||||
secretKeyBytes := [32]byte{1}
|
||||
secretKey, err := bls.SecretKeyFromBytes(secretKeyBytes[:])
|
||||
require.NoError(t, err)
|
||||
keysMap[pubKey0] = secretKey
|
||||
keysMap[pubKey1] = secretKey
|
||||
|
||||
// If AllValidatorsAreExited does not create the expected request, this test will fail
|
||||
v := validator{keyManager: &mockKeymanager{keysMap: keysMap}, validatorClient: client}
|
||||
exited, err := v.AllValidatorsAreExited(context.Background())
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, false, exited)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user