mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-26 13:18:57 +00:00
95c140b512
* Add client registration methods * Mocken * Run mockgen * Fix bad tests * Fix rest of the tests * Tests * Fix time tests Co-authored-by: james-prysm <90280386+james-prysm@users.noreply.github.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
136 lines
4.5 KiB
Go
136 lines
4.5 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"
|
|
"google.golang.org/protobuf/types/known/emptypb"
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
)
|
|
|
|
func TestSubmitValidatorRegistration(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(),
|
|
}
|
|
|
|
ti := ×tamppb.Timestamp{}
|
|
m.nodeClient.EXPECT().
|
|
GetGenesis(gomock.Any(), &emptypb.Empty{}).
|
|
Return(ðpb.Genesis{GenesisTime: ti}, nil)
|
|
|
|
m.validatorClient.EXPECT().DomainData(
|
|
gomock.Any(), // ctx
|
|
ðpb.DomainRequest{Domain: params.BeaconConfig().DomainApplicationBuilder[:]},
|
|
).Times(1).Return(ðpb.DomainResponse{SignatureDomain: make([]byte, 32)}, nil /*err*/)
|
|
|
|
m.validatorClient.EXPECT().
|
|
SubmitValidatorRegistration(gomock.Any(), ðpb.SignedValidatorRegistrationV1{
|
|
Message: reg,
|
|
Signature: params.BeaconConfig().ZeroHash[:],
|
|
}).
|
|
Return(nil, nil)
|
|
require.NoError(t, nil, SubmitValidatorRegistration(ctx, m.validatorClient, m.nodeClient, m.signfunc, reg))
|
|
}
|
|
|
|
func TestSubmitValidatorRegistration_InvalidDomain(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(),
|
|
}
|
|
|
|
genesisTime := ×tamppb.Timestamp{}
|
|
m.nodeClient.EXPECT().
|
|
GetGenesis(gomock.Any(), &emptypb.Empty{}).
|
|
Return(ðpb.Genesis{GenesisTime: genesisTime}, nil)
|
|
|
|
m.validatorClient.EXPECT().DomainData(
|
|
gomock.Any(), // ctx
|
|
ðpb.DomainRequest{Domain: params.BeaconConfig().DomainApplicationBuilder[:]},
|
|
).Times(1).Return(ðpb.DomainResponse{SignatureDomain: make([]byte, 32)}, errors.New(domainDataErr))
|
|
|
|
require.ErrorContains(t, domainDataErr, SubmitValidatorRegistration(ctx, m.validatorClient, m.nodeClient, m.signfunc, reg))
|
|
}
|
|
|
|
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(),
|
|
}
|
|
|
|
genesisTime := ×tamppb.Timestamp{}
|
|
m.nodeClient.EXPECT().
|
|
GetGenesis(gomock.Any(), &emptypb.Empty{}).
|
|
Return(ðpb.Genesis{GenesisTime: genesisTime}, nil)
|
|
|
|
m.validatorClient.EXPECT().DomainData(
|
|
gomock.Any(), // ctx
|
|
ðpb.DomainRequest{Domain: params.BeaconConfig().DomainApplicationBuilder[:]},
|
|
).Times(1).Return(ðpb.DomainResponse{SignatureDomain: make([]byte, 32)}, nil /*err*/)
|
|
|
|
m.validatorClient.EXPECT().
|
|
SubmitValidatorRegistration(gomock.Any(), ðpb.SignedValidatorRegistrationV1{
|
|
Message: reg,
|
|
Signature: params.BeaconConfig().ZeroHash[:],
|
|
}).
|
|
Return(nil, errors.New("could not sign"))
|
|
require.ErrorContains(t, "could not submit signed registration to beacon node", SubmitValidatorRegistration(ctx, m.validatorClient, m.nodeClient, m.signfunc, reg))
|
|
}
|
|
|
|
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(),
|
|
}
|
|
m.validatorClient.EXPECT().DomainData(
|
|
gomock.Any(), // ctx
|
|
ðpb.DomainRequest{Domain: params.BeaconConfig().DomainApplicationBuilder[:]},
|
|
).Times(1).Return(ðpb.DomainResponse{SignatureDomain: make([]byte, 32)}, nil /*err*/)
|
|
_, err := signValidatorRegistration(
|
|
ctx,
|
|
1,
|
|
m.validatorClient, m.signfunc, reg)
|
|
require.NoError(t, err)
|
|
|
|
m.validatorClient.EXPECT().DomainData(
|
|
gomock.Any(), // ctx
|
|
ðpb.DomainRequest{Domain: params.BeaconConfig().DomainApplicationBuilder[:]},
|
|
).Times(1).Return(nil, errors.New(domainDataErr) /*err*/)
|
|
_, err = signValidatorRegistration(
|
|
ctx,
|
|
1,
|
|
m.validatorClient, m.signfunc, reg)
|
|
require.ErrorContains(t, domainDataErr, err)
|
|
}
|