prysm-pulse/validator/keymanager/remote-web3signer/v1/requests_test.go
Raul Jordan d077483577
Add V3 Suffix to All Prysm Packages (#11083)
* v3 import renamings

* tidy

* fmt

* rev

* Update beacon-chain/core/epoch/precompute/reward_penalty_test.go

* Update beacon-chain/core/helpers/validators_test.go

* Update beacon-chain/db/alias.go

* Update beacon-chain/db/alias.go

* Update beacon-chain/db/alias.go

* Update beacon-chain/db/iface/BUILD.bazel

* Update beacon-chain/db/kv/kv.go

* Update beacon-chain/db/kv/state.go

* Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go

* Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go

* Update beacon-chain/sync/initial-sync/service.go

* fix deps

* fix bad replacements

* fix bad replacements

* change back

* gohashtree version

* fix deps

Co-authored-by: Nishant Das <nishdas93@gmail.com>
Co-authored-by: Potuz <potuz@prysmaticlabs.com>
2022-08-16 12:20:13 +00:00

448 lines
12 KiB
Go

package v1_test
import (
"reflect"
"testing"
"github.com/ethereum/go-ethereum/common/hexutil"
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
validatorpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1/validator-client"
"github.com/prysmaticlabs/prysm/v3/testing/require"
v1 "github.com/prysmaticlabs/prysm/v3/validator/keymanager/remote-web3signer/v1"
"github.com/prysmaticlabs/prysm/v3/validator/keymanager/remote-web3signer/v1/mock"
)
func TestGetAggregateAndProofSignRequest(t *testing.T) {
type args struct {
request *validatorpb.SignRequest
genesisValidatorsRoot []byte
}
tests := []struct {
name string
args args
want *v1.AggregateAndProofSignRequest
wantErr bool
}{
{
name: "Happy Path Test",
args: args{
request: mock.GetMockSignRequest("AGGREGATE_AND_PROOF"),
genesisValidatorsRoot: make([]byte, fieldparams.RootLength),
},
want: mock.MockAggregateAndProofSignRequest(),
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := v1.GetAggregateAndProofSignRequest(tt.args.request, tt.args.genesisValidatorsRoot)
if (err != nil) != tt.wantErr {
t.Errorf("GetAggregateAndProofSignRequest() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetAggregateAndProofSignRequest() got = %v, want %v", got, tt.want)
}
})
}
}
func TestGetAggregationSlotSignRequest(t *testing.T) {
type args struct {
request *validatorpb.SignRequest
genesisValidatorsRoot []byte
}
tests := []struct {
name string
args args
want *v1.AggregationSlotSignRequest
wantErr bool
}{
{
name: "Happy Path Test",
args: args{
request: mock.GetMockSignRequest("AGGREGATION_SLOT"),
genesisValidatorsRoot: make([]byte, fieldparams.RootLength),
},
want: mock.MockAggregationSlotSignRequest(),
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := v1.GetAggregationSlotSignRequest(tt.args.request, tt.args.genesisValidatorsRoot)
if (err != nil) != tt.wantErr {
t.Errorf("GetAggregationSlotSignRequest() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetAggregationSlotSignRequest() got = %v, want %v", got, tt.want)
}
})
}
}
func TestGetAttestationSignRequest(t *testing.T) {
type args struct {
request *validatorpb.SignRequest
genesisValidatorsRoot []byte
}
tests := []struct {
name string
args args
want *v1.AttestationSignRequest
wantErr bool
}{
{
name: "Happy Path Test",
args: args{
request: mock.GetMockSignRequest("ATTESTATION"),
genesisValidatorsRoot: make([]byte, fieldparams.RootLength),
},
want: mock.MockAttestationSignRequest(),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := v1.GetAttestationSignRequest(tt.args.request, tt.args.genesisValidatorsRoot)
if (err != nil) != tt.wantErr {
t.Errorf("GetAttestationSignRequest() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetAttestationSignRequest() got = %v, want %v", got, tt.want)
}
})
}
}
func TestGetBlockSignRequest(t *testing.T) {
type args struct {
request *validatorpb.SignRequest
genesisValidatorsRoot []byte
}
tests := []struct {
name string
args args
want *v1.BlockSignRequest
wantErr bool
}{
{
name: "Happy Path Test",
args: args{
request: mock.GetMockSignRequest("BLOCK"),
genesisValidatorsRoot: make([]byte, fieldparams.RootLength),
},
want: mock.MockBlockSignRequest(),
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := v1.GetBlockSignRequest(tt.args.request, tt.args.genesisValidatorsRoot)
if (err != nil) != tt.wantErr {
t.Errorf("GetBlockSignRequest() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetBlockSignRequest() got = %v, want %v", got, tt.want)
}
})
}
}
func TestGetBlockV2AltairSignRequest(t *testing.T) {
type args struct {
request *validatorpb.SignRequest
genesisValidatorsRoot []byte
}
tests := []struct {
name string
args args
want *v1.BlockAltairSignRequest
wantErr bool
}{
{
name: "Happy Path Test",
args: args{
request: mock.GetMockSignRequest("BLOCK_V2"),
genesisValidatorsRoot: make([]byte, fieldparams.RootLength),
},
want: mock.MockBlockV2AltairSignRequest(),
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := v1.GetBlockAltairSignRequest(tt.args.request, tt.args.genesisValidatorsRoot)
if (err != nil) != tt.wantErr {
t.Errorf("GetBlockAltairSignRequest() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetBlockAltairSignRequest() got = %v, want %v", got, tt.want)
}
})
}
}
func TestGetRandaoRevealSignRequest(t *testing.T) {
type args struct {
request *validatorpb.SignRequest
genesisValidatorsRoot []byte
}
tests := []struct {
name string
args args
want *v1.RandaoRevealSignRequest
wantErr bool
}{
{
name: "Happy Path Test",
args: args{
request: mock.GetMockSignRequest("RANDAO_REVEAL"),
genesisValidatorsRoot: make([]byte, fieldparams.RootLength),
},
want: mock.MockRandaoRevealSignRequest(),
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := v1.GetRandaoRevealSignRequest(tt.args.request, tt.args.genesisValidatorsRoot)
if (err != nil) != tt.wantErr {
t.Errorf("GetRandaoRevealSignRequest() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetRandaoRevealSignRequest() got = %v, want %v", got, tt.want)
}
})
}
}
func TestGetSyncCommitteeContributionAndProofSignRequest(t *testing.T) {
type args struct {
request *validatorpb.SignRequest
genesisValidatorsRoot []byte
}
tests := []struct {
name string
args args
want *v1.SyncCommitteeContributionAndProofSignRequest
wantErr bool
}{
{
name: "Happy Path Test",
args: args{
request: mock.GetMockSignRequest("SYNC_COMMITTEE_CONTRIBUTION_AND_PROOF"),
genesisValidatorsRoot: make([]byte, fieldparams.RootLength),
},
want: mock.MockSyncCommitteeContributionAndProofSignRequest(),
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := v1.GetSyncCommitteeContributionAndProofSignRequest(tt.args.request, tt.args.genesisValidatorsRoot)
if (err != nil) != tt.wantErr {
t.Errorf("GetSyncCommitteeContributionAndProofSignRequest() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetSyncCommitteeContributionAndProofSignRequest() got = %v, want %v", got, tt.want)
}
})
}
}
func TestGetSyncCommitteeMessageSignRequest(t *testing.T) {
type args struct {
request *validatorpb.SignRequest
genesisValidatorsRoot []byte
}
tests := []struct {
name string
args args
want *v1.SyncCommitteeMessageSignRequest
wantErr bool
}{
{
name: "Happy Path Test",
args: args{
request: mock.GetMockSignRequest("SYNC_COMMITTEE_MESSAGE"),
genesisValidatorsRoot: make([]byte, fieldparams.RootLength),
},
want: mock.MockSyncCommitteeMessageSignRequest(),
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := v1.GetSyncCommitteeMessageSignRequest(tt.args.request, tt.args.genesisValidatorsRoot)
if (err != nil) != tt.wantErr {
t.Errorf("GetSyncCommitteeMessageSignRequest() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetSyncCommitteeMessageSignRequest() got = %v, want %v", got, tt.want)
}
})
}
}
func TestGetSyncCommitteeSelectionProofSignRequest(t *testing.T) {
type args struct {
request *validatorpb.SignRequest
genesisValidatorsRoot []byte
}
tests := []struct {
name string
args args
want *v1.SyncCommitteeSelectionProofSignRequest
wantErr bool
}{
{
name: "Happy Path Test",
args: args{
request: mock.GetMockSignRequest("SYNC_COMMITTEE_SELECTION_PROOF"),
genesisValidatorsRoot: make([]byte, fieldparams.RootLength),
},
want: mock.MockSyncCommitteeSelectionProofSignRequest(),
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := v1.GetSyncCommitteeSelectionProofSignRequest(tt.args.request, tt.args.genesisValidatorsRoot)
if (err != nil) != tt.wantErr {
t.Errorf("GetSyncCommitteeSelectionProofSignRequest() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetSyncCommitteeSelectionProofSignRequest() got = %v, want %v", got, tt.want)
}
})
}
}
func TestGetVoluntaryExitSignRequest(t *testing.T) {
type args struct {
request *validatorpb.SignRequest
genesisValidatorsRoot []byte
}
tests := []struct {
name string
args args
want *v1.VoluntaryExitSignRequest
wantErr bool
}{
{
name: "Happy Path Test",
args: args{
request: mock.GetMockSignRequest("VOLUNTARY_EXIT"),
genesisValidatorsRoot: make([]byte, fieldparams.RootLength),
},
want: mock.MockVoluntaryExitSignRequest(),
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := v1.GetVoluntaryExitSignRequest(tt.args.request, tt.args.genesisValidatorsRoot)
if (err != nil) != tt.wantErr {
t.Errorf("GetVoluntaryExitSignRequest() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetVoluntaryExitSignRequest() got = %v, want %v", got, tt.want)
}
})
}
}
func TestGetBlockBellatrixSignRequest(t *testing.T) {
type args struct {
request *validatorpb.SignRequest
genesisValidatorsRoot []byte
}
tests := []struct {
name string
args args
want *v1.BlockBellatrixSignRequest
wantErr bool
}{
{
name: "Happy Path Test non blinded",
args: args{
request: mock.GetMockSignRequest("BLOCK_V2_BELLATRIX"),
genesisValidatorsRoot: make([]byte, fieldparams.RootLength),
},
want: mock.MockBlockV2BellatrixSignRequest(func(t *testing.T) []byte {
bytevalue, err := hexutil.Decode("0xcd7c49966ebe72b1214e6d4733adf6bf06935c5fbc3b3ad08e84e3085428b82f")
require.NoError(t, err)
return bytevalue
}(t)),
wantErr: false,
},
{
name: "Happy Path Test blinded",
args: args{
request: mock.GetMockSignRequest("BLOCK_V2_BLINDED_BELLATRIX"),
genesisValidatorsRoot: make([]byte, fieldparams.RootLength),
},
want: mock.MockBlockV2BellatrixSignRequest(func(t *testing.T) []byte {
bytevalue, err := hexutil.Decode("0xbabb9c2d10dd3f16dc50e31fd6eb270c9c5e95a6dcb5a1eb34389ef28194285b")
require.NoError(t, err)
return bytevalue
}(t)),
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := v1.GetBlockBellatrixSignRequest(tt.args.request, tt.args.genesisValidatorsRoot)
if (err != nil) != tt.wantErr {
t.Errorf("GetBlockBellatrixSignRequest() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetBlockAltairSignRequest() got = %v, want %v", got, tt.want)
}
})
}
}
func TestGetValidatorRegistrationSignRequest(t *testing.T) {
type args struct {
request *validatorpb.SignRequest
}
tests := []struct {
name string
args args
want *v1.ValidatorRegistrationSignRequest
wantErr bool
}{
{
name: "Happy Path Test",
args: args{
request: mock.GetMockSignRequest("VALIDATOR_REGISTRATION"),
},
want: mock.MockValidatorRegistrationSignRequest(),
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := v1.GetValidatorRegistrationSignRequest(tt.args.request)
if (err != nil) != tt.wantErr {
t.Errorf("GetValidatorRegistrationSignRequest() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetValidatorRegistrationSignRequest() got = %v, want %v", got, tt.want)
}
})
}
}