mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 04:47:18 +00:00
e770f0fe1f
* switching signing root type to hexutil.byte * more signing root changes * more conversions for types * adding bitfield parsing * fixing linting * fixing bitfield parsing
603 lines
17 KiB
Go
603 lines
17 KiB
Go
package v1_test
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/go-bitfield"
|
|
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
|
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
|
v1 "github.com/prysmaticlabs/prysm/validator/keymanager/remote-web3signer/v1"
|
|
"github.com/prysmaticlabs/prysm/validator/keymanager/remote-web3signer/v1/mock"
|
|
)
|
|
|
|
func TestMapAggregateAndProof(t *testing.T) {
|
|
type args struct {
|
|
from *ethpb.AggregateAttestationAndProof
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want *v1.AggregateAndProof
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "HappyPathTest",
|
|
args: args{
|
|
from: ðpb.AggregateAttestationAndProof{
|
|
AggregatorIndex: 0,
|
|
Aggregate: ðpb.Attestation{
|
|
AggregationBits: bitfield.Bitlist{0b1101},
|
|
Data: ðpb.AttestationData{
|
|
BeaconBlockRoot: make([]byte, fieldparams.RootLength),
|
|
Source: ðpb.Checkpoint{
|
|
Root: make([]byte, fieldparams.RootLength),
|
|
},
|
|
Target: ðpb.Checkpoint{
|
|
Root: make([]byte, fieldparams.RootLength),
|
|
},
|
|
},
|
|
Signature: make([]byte, 96),
|
|
},
|
|
SelectionProof: make([]byte, fieldparams.BLSSignatureLength),
|
|
},
|
|
},
|
|
want: &v1.AggregateAndProof{
|
|
AggregatorIndex: "0",
|
|
Aggregate: mock.MockAttestation(),
|
|
SelectionProof: make([]byte, fieldparams.BLSSignatureLength),
|
|
},
|
|
wantErr: false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := v1.MapAggregateAndProof(tt.args.from)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("MapAggregateAndProof() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got.Aggregate, tt.want.Aggregate) {
|
|
t.Errorf("MapAggregateAndProof() got = %v, want %v", got.Aggregate, tt.want.Aggregate)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestMapAttestation(t *testing.T) {
|
|
type args struct {
|
|
attestation *ethpb.Attestation
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want *v1.Attestation
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "HappyPathTest",
|
|
args: args{
|
|
attestation: ðpb.Attestation{
|
|
AggregationBits: bitfield.Bitlist{0b1101},
|
|
Data: ðpb.AttestationData{
|
|
BeaconBlockRoot: make([]byte, fieldparams.RootLength),
|
|
Source: ðpb.Checkpoint{
|
|
Root: make([]byte, fieldparams.RootLength),
|
|
},
|
|
Target: ðpb.Checkpoint{
|
|
Root: make([]byte, fieldparams.RootLength),
|
|
},
|
|
},
|
|
Signature: make([]byte, 96),
|
|
},
|
|
},
|
|
want: mock.MockAttestation(),
|
|
wantErr: false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := v1.MapAttestation(tt.args.attestation)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("MapAttestation() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("MapAttestation() got = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestMapAttestationData(t *testing.T) {
|
|
type args struct {
|
|
data *ethpb.AttestationData
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want *v1.AttestationData
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "HappyPathTest",
|
|
args: args{
|
|
data: ðpb.AttestationData{
|
|
BeaconBlockRoot: make([]byte, fieldparams.RootLength),
|
|
Source: ðpb.Checkpoint{
|
|
Root: make([]byte, fieldparams.RootLength),
|
|
},
|
|
Target: ðpb.Checkpoint{
|
|
Root: make([]byte, fieldparams.RootLength),
|
|
},
|
|
},
|
|
},
|
|
want: mock.MockAttestation().Data,
|
|
wantErr: false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := v1.MapAttestationData(tt.args.data)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("MapAttestationData() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("MapAttestationData() got = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestMapAttesterSlashing(t *testing.T) {
|
|
type args struct {
|
|
slashing *ethpb.AttesterSlashing
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want *v1.AttesterSlashing
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "HappyPathTest",
|
|
args: args{
|
|
slashing: ðpb.AttesterSlashing{
|
|
Attestation_1: ðpb.IndexedAttestation{
|
|
AttestingIndices: []uint64{0, 1, 2},
|
|
Data: ðpb.AttestationData{
|
|
BeaconBlockRoot: make([]byte, fieldparams.RootLength),
|
|
Source: ðpb.Checkpoint{
|
|
Root: make([]byte, fieldparams.RootLength),
|
|
},
|
|
Target: ðpb.Checkpoint{
|
|
Root: make([]byte, fieldparams.RootLength),
|
|
},
|
|
},
|
|
Signature: make([]byte, fieldparams.BLSSignatureLength),
|
|
},
|
|
Attestation_2: ðpb.IndexedAttestation{
|
|
AttestingIndices: []uint64{0, 1, 2},
|
|
Data: ðpb.AttestationData{
|
|
BeaconBlockRoot: make([]byte, fieldparams.RootLength),
|
|
Source: ðpb.Checkpoint{
|
|
Root: make([]byte, fieldparams.RootLength),
|
|
},
|
|
Target: ðpb.Checkpoint{
|
|
Root: make([]byte, fieldparams.RootLength),
|
|
},
|
|
},
|
|
Signature: make([]byte, fieldparams.BLSSignatureLength),
|
|
},
|
|
},
|
|
},
|
|
want: &v1.AttesterSlashing{
|
|
Attestation1: mock.MockIndexedAttestation(),
|
|
Attestation2: mock.MockIndexedAttestation(),
|
|
},
|
|
wantErr: false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := v1.MapAttesterSlashing(tt.args.slashing)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("MapAttesterSlashing() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got.Attestation1, tt.want.Attestation1) {
|
|
t.Errorf("MapAttesterSlashing() got = %v, want %v", got.Attestation1, tt.want.Attestation1)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestMapBeaconBlockAltair(t *testing.T) {
|
|
type args struct {
|
|
block *ethpb.BeaconBlockAltair
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want *v1.BeaconBlockAltair
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "Happy Path Test",
|
|
args: args{
|
|
block: ðpb.BeaconBlockAltair{
|
|
Slot: 0,
|
|
ProposerIndex: 0,
|
|
ParentRoot: make([]byte, fieldparams.RootLength),
|
|
StateRoot: make([]byte, fieldparams.RootLength),
|
|
Body: ðpb.BeaconBlockBodyAltair{
|
|
RandaoReveal: make([]byte, 32),
|
|
Eth1Data: ðpb.Eth1Data{
|
|
DepositRoot: make([]byte, fieldparams.RootLength),
|
|
DepositCount: 0,
|
|
BlockHash: make([]byte, 32),
|
|
},
|
|
Graffiti: make([]byte, 32),
|
|
ProposerSlashings: []*ethpb.ProposerSlashing{
|
|
{
|
|
Header_1: ðpb.SignedBeaconBlockHeader{
|
|
Header: ðpb.BeaconBlockHeader{
|
|
Slot: 0,
|
|
ProposerIndex: 0,
|
|
ParentRoot: make([]byte, fieldparams.RootLength),
|
|
StateRoot: make([]byte, fieldparams.RootLength),
|
|
BodyRoot: make([]byte, fieldparams.RootLength),
|
|
},
|
|
Signature: make([]byte, fieldparams.BLSSignatureLength),
|
|
},
|
|
Header_2: ðpb.SignedBeaconBlockHeader{
|
|
Header: ðpb.BeaconBlockHeader{
|
|
Slot: 0,
|
|
ProposerIndex: 0,
|
|
ParentRoot: make([]byte, fieldparams.RootLength),
|
|
StateRoot: make([]byte, fieldparams.RootLength),
|
|
BodyRoot: make([]byte, fieldparams.RootLength),
|
|
},
|
|
Signature: make([]byte, fieldparams.BLSSignatureLength),
|
|
},
|
|
},
|
|
},
|
|
AttesterSlashings: []*ethpb.AttesterSlashing{
|
|
{
|
|
Attestation_1: ðpb.IndexedAttestation{
|
|
AttestingIndices: []uint64{0, 1, 2},
|
|
Data: ðpb.AttestationData{
|
|
BeaconBlockRoot: make([]byte, fieldparams.RootLength),
|
|
Source: ðpb.Checkpoint{
|
|
Root: make([]byte, fieldparams.RootLength),
|
|
},
|
|
Target: ðpb.Checkpoint{
|
|
Root: make([]byte, fieldparams.RootLength),
|
|
},
|
|
},
|
|
Signature: make([]byte, fieldparams.BLSSignatureLength),
|
|
},
|
|
Attestation_2: ðpb.IndexedAttestation{
|
|
AttestingIndices: []uint64{0, 1, 2},
|
|
Data: ðpb.AttestationData{
|
|
BeaconBlockRoot: make([]byte, fieldparams.RootLength),
|
|
Source: ðpb.Checkpoint{
|
|
Root: make([]byte, fieldparams.RootLength),
|
|
},
|
|
Target: ðpb.Checkpoint{
|
|
Root: make([]byte, fieldparams.RootLength),
|
|
},
|
|
},
|
|
Signature: make([]byte, fieldparams.BLSSignatureLength),
|
|
},
|
|
},
|
|
},
|
|
Attestations: []*ethpb.Attestation{
|
|
{
|
|
AggregationBits: bitfield.Bitlist{0b1101},
|
|
Data: ðpb.AttestationData{
|
|
BeaconBlockRoot: make([]byte, fieldparams.RootLength),
|
|
Source: ðpb.Checkpoint{
|
|
Root: make([]byte, fieldparams.RootLength),
|
|
},
|
|
Target: ðpb.Checkpoint{
|
|
Root: make([]byte, fieldparams.RootLength),
|
|
},
|
|
},
|
|
Signature: make([]byte, 96),
|
|
},
|
|
},
|
|
Deposits: []*ethpb.Deposit{
|
|
{
|
|
Proof: [][]byte{[]byte("A")},
|
|
Data: ðpb.Deposit_Data{
|
|
PublicKey: make([]byte, fieldparams.BLSPubkeyLength),
|
|
WithdrawalCredentials: make([]byte, 32),
|
|
Amount: 0,
|
|
Signature: make([]byte, fieldparams.BLSSignatureLength),
|
|
},
|
|
},
|
|
},
|
|
VoluntaryExits: []*ethpb.SignedVoluntaryExit{
|
|
{
|
|
Exit: ðpb.VoluntaryExit{
|
|
Epoch: 0,
|
|
ValidatorIndex: 0,
|
|
},
|
|
Signature: make([]byte, fieldparams.BLSSignatureLength),
|
|
},
|
|
},
|
|
SyncAggregate: ðpb.SyncAggregate{
|
|
SyncCommitteeSignature: make([]byte, fieldparams.BLSSignatureLength),
|
|
SyncCommitteeBits: mock.MockSyncComitteeBits(),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
want: mock.MockBeaconBlockAltair(),
|
|
wantErr: false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := v1.MapBeaconBlockAltair(tt.args.block)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("MapBeaconBlockAltair() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got.Body, tt.want.Body) {
|
|
t.Errorf("MapBeaconBlockAltair() got = %v, want %v", got.Body.SyncAggregate, tt.want.Body.SyncAggregate)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestMapBeaconBlockBody(t *testing.T) {
|
|
type args struct {
|
|
body *ethpb.BeaconBlockBody
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want *v1.BeaconBlockBody
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "Happy Path Test",
|
|
args: args{
|
|
body: ðpb.BeaconBlockBody{
|
|
RandaoReveal: make([]byte, 32),
|
|
Eth1Data: ðpb.Eth1Data{
|
|
DepositRoot: make([]byte, fieldparams.RootLength),
|
|
DepositCount: 0,
|
|
BlockHash: make([]byte, 32),
|
|
},
|
|
Graffiti: make([]byte, 32),
|
|
ProposerSlashings: []*ethpb.ProposerSlashing{
|
|
{
|
|
Header_1: ðpb.SignedBeaconBlockHeader{
|
|
Header: ðpb.BeaconBlockHeader{
|
|
Slot: 0,
|
|
ProposerIndex: 0,
|
|
ParentRoot: make([]byte, fieldparams.RootLength),
|
|
StateRoot: make([]byte, fieldparams.RootLength),
|
|
BodyRoot: make([]byte, fieldparams.RootLength),
|
|
},
|
|
Signature: make([]byte, fieldparams.BLSSignatureLength),
|
|
},
|
|
Header_2: ðpb.SignedBeaconBlockHeader{
|
|
Header: ðpb.BeaconBlockHeader{
|
|
Slot: 0,
|
|
ProposerIndex: 0,
|
|
ParentRoot: make([]byte, fieldparams.RootLength),
|
|
StateRoot: make([]byte, fieldparams.RootLength),
|
|
BodyRoot: make([]byte, fieldparams.RootLength),
|
|
},
|
|
Signature: make([]byte, fieldparams.BLSSignatureLength),
|
|
},
|
|
},
|
|
},
|
|
AttesterSlashings: []*ethpb.AttesterSlashing{
|
|
{
|
|
Attestation_1: ðpb.IndexedAttestation{
|
|
AttestingIndices: []uint64{0, 1, 2},
|
|
Data: ðpb.AttestationData{
|
|
BeaconBlockRoot: make([]byte, fieldparams.RootLength),
|
|
Source: ðpb.Checkpoint{
|
|
Root: make([]byte, fieldparams.RootLength),
|
|
},
|
|
Target: ðpb.Checkpoint{
|
|
Root: make([]byte, fieldparams.RootLength),
|
|
},
|
|
},
|
|
Signature: make([]byte, fieldparams.BLSSignatureLength),
|
|
},
|
|
Attestation_2: ðpb.IndexedAttestation{
|
|
AttestingIndices: []uint64{0, 1, 2},
|
|
Data: ðpb.AttestationData{
|
|
BeaconBlockRoot: make([]byte, fieldparams.RootLength),
|
|
Source: ðpb.Checkpoint{
|
|
Root: make([]byte, fieldparams.RootLength),
|
|
},
|
|
Target: ðpb.Checkpoint{
|
|
Root: make([]byte, fieldparams.RootLength),
|
|
},
|
|
},
|
|
Signature: make([]byte, fieldparams.BLSSignatureLength),
|
|
},
|
|
},
|
|
},
|
|
Attestations: []*ethpb.Attestation{
|
|
{
|
|
AggregationBits: bitfield.Bitlist{0b1101},
|
|
Data: ðpb.AttestationData{
|
|
BeaconBlockRoot: make([]byte, fieldparams.RootLength),
|
|
Source: ðpb.Checkpoint{
|
|
Root: make([]byte, fieldparams.RootLength),
|
|
},
|
|
Target: ðpb.Checkpoint{
|
|
Root: make([]byte, fieldparams.RootLength),
|
|
},
|
|
},
|
|
Signature: make([]byte, 96),
|
|
},
|
|
},
|
|
Deposits: []*ethpb.Deposit{
|
|
{
|
|
Proof: [][]byte{[]byte("A")},
|
|
Data: ðpb.Deposit_Data{
|
|
PublicKey: make([]byte, fieldparams.BLSPubkeyLength),
|
|
WithdrawalCredentials: make([]byte, 32),
|
|
Amount: 0,
|
|
Signature: make([]byte, fieldparams.BLSSignatureLength),
|
|
},
|
|
},
|
|
},
|
|
VoluntaryExits: []*ethpb.SignedVoluntaryExit{
|
|
{
|
|
Exit: ðpb.VoluntaryExit{
|
|
Epoch: 0,
|
|
ValidatorIndex: 0,
|
|
},
|
|
Signature: make([]byte, fieldparams.BLSSignatureLength),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
want: mock.MockBeaconBlockBody(),
|
|
wantErr: false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := v1.MapBeaconBlockBody(tt.args.body)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("MapBeaconBlockBody() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("MapBeaconBlockBody() got = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestMapContributionAndProof(t *testing.T) {
|
|
type args struct {
|
|
contribution *ethpb.ContributionAndProof
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want *v1.ContributionAndProof
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "Happy Path Test",
|
|
args: args{
|
|
contribution: ðpb.ContributionAndProof{
|
|
AggregatorIndex: 0,
|
|
Contribution: ðpb.SyncCommitteeContribution{
|
|
Slot: 0,
|
|
BlockRoot: make([]byte, fieldparams.RootLength),
|
|
SubcommitteeIndex: 0,
|
|
AggregationBits: mock.MockAggregationBits(),
|
|
Signature: make([]byte, fieldparams.BLSSignatureLength),
|
|
},
|
|
SelectionProof: make([]byte, fieldparams.BLSSignatureLength),
|
|
},
|
|
},
|
|
want: mock.MockContributionAndProof(),
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := v1.MapContributionAndProof(tt.args.contribution)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("MapContributionAndProof() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("MapContributionAndProof() got = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestMapForkInfo(t *testing.T) {
|
|
type args struct {
|
|
slot types.Slot
|
|
genesisValidatorsRoot []byte
|
|
}
|
|
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want *v1.ForkInfo
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "Happy Path Test",
|
|
args: args{
|
|
slot: 0,
|
|
genesisValidatorsRoot: make([]byte, fieldparams.RootLength),
|
|
},
|
|
want: mock.MockForkInfo(),
|
|
wantErr: false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := v1.MapForkInfo(tt.args.slot, tt.args.genesisValidatorsRoot)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("MapForkInfo() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("MapForkInfo() got = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestMapSyncAggregatorSelectionData(t *testing.T) {
|
|
type args struct {
|
|
data *ethpb.SyncAggregatorSelectionData
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want *v1.SyncAggregatorSelectionData
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "Happy Path Test",
|
|
args: args{
|
|
data: ðpb.SyncAggregatorSelectionData{
|
|
Slot: 0,
|
|
SubcommitteeIndex: 0,
|
|
},
|
|
},
|
|
want: &v1.SyncAggregatorSelectionData{
|
|
Slot: "0",
|
|
SubcommitteeIndex: "0",
|
|
},
|
|
wantErr: false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := v1.MapSyncAggregatorSelectionData(tt.args.data)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("MapSyncAggregatorSelectionData() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("MapSyncAggregatorSelectionData() got = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|