prysm-pulse/testing/spectest/shared/bellatrix/ssz_static/ssz_static.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

129 lines
3.8 KiB
Go

package ssz_static
import (
"context"
"errors"
"testing"
fssz "github.com/prysmaticlabs/fastssz"
v3 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v3"
enginev1 "github.com/prysmaticlabs/prysm/v3/proto/engine/v1"
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v3/testing/require"
common "github.com/prysmaticlabs/prysm/v3/testing/spectest/shared/common/ssz_static"
)
// RunSSZStaticTests executes "ssz_static" tests.
func RunSSZStaticTests(t *testing.T, config string) {
common.RunSSZStaticTests(t, config, "bellatrix", unmarshalledSSZ, customHtr)
}
func customHtr(t *testing.T, htrs []common.HTR, object interface{}) []common.HTR {
switch object.(type) {
case *ethpb.BeaconStateBellatrix:
htrs = append(htrs, func(s interface{}) ([32]byte, error) {
beaconState, err := v3.InitializeFromProto(s.(*ethpb.BeaconStateBellatrix))
require.NoError(t, err)
return beaconState.HashTreeRoot(context.Background())
})
}
return htrs
}
// unmarshalledSSZ unmarshalls serialized input.
func unmarshalledSSZ(t *testing.T, serializedBytes []byte, folderName string) (interface{}, error) {
var obj interface{}
switch folderName {
case "ExecutionPayload":
obj = &enginev1.ExecutionPayload{}
case "ExecutionPayloadHeader":
obj = &enginev1.ExecutionPayloadHeader{}
case "Attestation":
obj = &ethpb.Attestation{}
case "AttestationData":
obj = &ethpb.AttestationData{}
case "AttesterSlashing":
obj = &ethpb.AttesterSlashing{}
case "AggregateAndProof":
obj = &ethpb.AggregateAttestationAndProof{}
case "BeaconBlock":
obj = &ethpb.BeaconBlockBellatrix{}
case "BeaconBlockBody":
obj = &ethpb.BeaconBlockBodyBellatrix{}
case "BeaconBlockHeader":
obj = &ethpb.BeaconBlockHeader{}
case "BeaconState":
obj = &ethpb.BeaconStateBellatrix{}
case "Checkpoint":
obj = &ethpb.Checkpoint{}
case "Deposit":
obj = &ethpb.Deposit{}
case "DepositMessage":
obj = &ethpb.DepositMessage{}
case "DepositData":
obj = &ethpb.Deposit_Data{}
case "Eth1Data":
obj = &ethpb.Eth1Data{}
case "Eth1Block":
t.Skip("Unused type")
return nil, nil
case "Fork":
obj = &ethpb.Fork{}
case "ForkData":
obj = &ethpb.ForkData{}
case "HistoricalBatch":
obj = &ethpb.HistoricalBatch{}
case "IndexedAttestation":
obj = &ethpb.IndexedAttestation{}
case "PendingAttestation":
obj = &ethpb.PendingAttestation{}
case "ProposerSlashing":
obj = &ethpb.ProposerSlashing{}
case "SignedAggregateAndProof":
obj = &ethpb.SignedAggregateAttestationAndProof{}
case "SignedBeaconBlock":
obj = &ethpb.SignedBeaconBlockBellatrix{}
case "SignedBeaconBlockHeader":
obj = &ethpb.SignedBeaconBlockHeader{}
case "SignedVoluntaryExit":
obj = &ethpb.SignedVoluntaryExit{}
case "SigningData":
obj = &ethpb.SigningData{}
case "Validator":
obj = &ethpb.Validator{}
case "VoluntaryExit":
obj = &ethpb.VoluntaryExit{}
case "SyncCommitteeMessage":
obj = &ethpb.SyncCommitteeMessage{}
case "SyncCommitteeContribution":
obj = &ethpb.SyncCommitteeContribution{}
case "ContributionAndProof":
obj = &ethpb.ContributionAndProof{}
case "SignedContributionAndProof":
obj = &ethpb.SignedContributionAndProof{}
case "SyncAggregate":
obj = &ethpb.SyncAggregate{}
case "SyncAggregatorSelectionData":
obj = &ethpb.SyncAggregatorSelectionData{}
case "SyncCommittee":
obj = &ethpb.SyncCommittee{}
case "LightClientSnapshot":
t.Skip("not a beacon node type, this is a light node type")
return nil, nil
case "LightClientUpdate":
t.Skip("not a beacon node type, this is a light node type")
return nil, nil
case "PowBlock":
obj = &ethpb.PowBlock{}
default:
return nil, errors.New("type not found")
}
var err error
if o, ok := obj.(fssz.Unmarshaler); ok {
err = o.UnmarshalSSZ(serializedBytes)
} else {
err = errors.New("could not unmarshal object, not a fastssz compatible object")
}
return obj, err
}