Skip to content

Commit

Permalink
fix related tests
Browse files Browse the repository at this point in the history
  • Loading branch information
olegshmuelov committed Aug 28, 2024
1 parent 8ea4975 commit 55dae0a
Showing 1 changed file with 48 additions and 6 deletions.
54 changes: 48 additions & 6 deletions message/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,48 @@ import (
"github.com/ssvlabs/ssv/storage/kv"
)

// Deep copy helper function for testing purposes only
func cloneSSVShare(original *ssvtypes.SSVShare) *ssvtypes.SSVShare {
if original == nil {
return nil
}

// Manually create a new instance of SSVShare
cloned := &ssvtypes.SSVShare{
Share: spectypes.Share{
ValidatorIndex: original.ValidatorIndex,
ValidatorPubKey: original.ValidatorPubKey,
SharePubKey: original.SharePubKey,
DomainType: original.DomainType,
FeeRecipientAddress: original.FeeRecipientAddress,
Graffiti: append([]byte(nil), original.Graffiti...), // Deep copy of slice
},
Metadata: ssvtypes.Metadata{
OwnerAddress: original.OwnerAddress,
Liquidated: original.Liquidated,
},
}

// Deep copy BeaconMetadata if needed
if original.BeaconMetadata != nil {
beaconMetadataCopy := *original.BeaconMetadata
cloned.Metadata.BeaconMetadata = &beaconMetadataCopy
}

// Deep copy Committee field, which is a slice of pointers
if original.Committee != nil {
cloned.Committee = make([]*spectypes.ShareMember, len(original.Committee))
for i, member := range original.Committee {
if member != nil {
memberCopy := *member // Deep copy each ShareMember
cloned.Committee[i] = &memberCopy
}
}
}

return cloned
}

func Test_ValidateSSVMessage(t *testing.T) {
ctrl := gomock.NewController(t)

Expand Down Expand Up @@ -71,21 +113,21 @@ func Test_ValidateSSVMessage(t *testing.T) {
beaconMetadata3 := beaconMetadata2
beaconMetadata3.Index = beaconMetadata2.Index + 1

share1 := *shares.active
share1 := cloneSSVShare(shares.active)
share1.BeaconMetadata = &beaconMetadata1
share2 := share1
share2 := cloneSSVShare(share1)
share2.ValidatorIndex = share1.ValidatorIndex + 1
share2.BeaconMetadata = &beaconMetadata2
share3 := share2
share3 := cloneSSVShare(share2)
share3.ValidatorIndex = share2.ValidatorIndex + 1
share3.BeaconMetadata = &beaconMetadata3
return &registrystorage.Committee{
ID: id,
Operators: committee,
Validators: []*ssvtypes.SSVShare{
&share1,
&share2,
&share3,
share1,
share2,
share3,
},
Indices: []phase0.ValidatorIndex{
share1.ValidatorIndex,
Expand Down

0 comments on commit 55dae0a

Please sign in to comment.