mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
7f56ac6355
* Massive code cleanup * fix test issues * remove GetGenesis mock expectations * unused receiver * rename unused params Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
81 lines
2.4 KiB
Go
81 lines
2.4 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/golang/mock/gomock"
|
|
"github.com/pkg/errors"
|
|
"github.com/prysmaticlabs/prysm/config/params"
|
|
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/testing/require"
|
|
)
|
|
|
|
func TestSubmitValidatorRegistration(t *testing.T) {
|
|
_, m, validatorKey, finish := setup(t)
|
|
defer finish()
|
|
|
|
ctx := context.Background()
|
|
require.NoError(t, nil, SubmitValidatorRegistration(ctx, m.validatorClient, m.signfunc, []*ethpb.ValidatorRegistrationV1{}))
|
|
|
|
reg := ðpb.ValidatorRegistrationV1{
|
|
FeeRecipient: bytesutil.PadTo([]byte("fee"), 20),
|
|
GasLimit: 123456,
|
|
Timestamp: uint64(time.Now().Unix()),
|
|
Pubkey: validatorKey.PublicKey().Marshal(),
|
|
}
|
|
regs := []*ethpb.ValidatorRegistrationV1{reg}
|
|
|
|
m.validatorClient.EXPECT().
|
|
SubmitValidatorRegistration(gomock.Any(), ðpb.SignedValidatorRegistrationsV1{
|
|
Messages: []*ethpb.SignedValidatorRegistrationV1{
|
|
{Message: reg,
|
|
Signature: params.BeaconConfig().ZeroHash[:]},
|
|
},
|
|
}).
|
|
Return(nil, nil)
|
|
require.NoError(t, nil, SubmitValidatorRegistration(ctx, m.validatorClient, m.signfunc, regs))
|
|
}
|
|
|
|
func TestSubmitValidatorRegistration_CantSign(t *testing.T) {
|
|
_, m, validatorKey, finish := setup(t)
|
|
defer finish()
|
|
|
|
ctx := context.Background()
|
|
reg := ðpb.ValidatorRegistrationV1{
|
|
FeeRecipient: bytesutil.PadTo([]byte("fee"), 20),
|
|
GasLimit: 123456,
|
|
Timestamp: uint64(time.Now().Unix()),
|
|
Pubkey: validatorKey.PublicKey().Marshal(),
|
|
}
|
|
regs := []*ethpb.ValidatorRegistrationV1{reg}
|
|
|
|
m.validatorClient.EXPECT().
|
|
SubmitValidatorRegistration(gomock.Any(), ðpb.SignedValidatorRegistrationsV1{
|
|
Messages: []*ethpb.SignedValidatorRegistrationV1{
|
|
{Message: reg,
|
|
Signature: params.BeaconConfig().ZeroHash[:]},
|
|
},
|
|
}).
|
|
Return(nil, errors.New("could not sign"))
|
|
require.ErrorContains(t, "could not sign", SubmitValidatorRegistration(ctx, m.validatorClient, m.signfunc, regs))
|
|
}
|
|
|
|
func Test_signValidatorRegistration(t *testing.T) {
|
|
_, m, validatorKey, finish := setup(t)
|
|
defer finish()
|
|
|
|
ctx := context.Background()
|
|
reg := ðpb.ValidatorRegistrationV1{
|
|
FeeRecipient: bytesutil.PadTo([]byte("fee"), 20),
|
|
GasLimit: 123456,
|
|
Timestamp: uint64(time.Now().Unix()),
|
|
Pubkey: validatorKey.PublicKey().Marshal(),
|
|
}
|
|
_, err := signValidatorRegistration(ctx, m.signfunc, reg)
|
|
require.NoError(t, err)
|
|
|
|
}
|