package ssz_static import ( "context" "errors" "testing" fssz "github.com/prysmaticlabs/fastssz" state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" 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, "capella", unmarshalledSSZ, customHtr) } func customHtr(t *testing.T, htrs []common.HTR, object interface{}) []common.HTR { switch object.(type) { case *ethpb.BeaconStateCapella: htrs = append(htrs, func(s interface{}) ([32]byte, error) { beaconState, err := state_native.InitializeFromProtoCapella(s.(*ethpb.BeaconStateCapella)) 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.ExecutionPayloadCapella{} case "ExecutionPayloadHeader": obj = &enginev1.ExecutionPayloadHeaderCapella{} case "Attestation": obj = ðpb.Attestation{} case "AttestationData": obj = ðpb.AttestationData{} case "AttesterSlashing": obj = ðpb.AttesterSlashing{} case "AggregateAndProof": obj = ðpb.AggregateAttestationAndProof{} case "BeaconBlock": obj = ðpb.BeaconBlockCapella{} case "BeaconBlockBody": obj = ðpb.BeaconBlockBodyCapella{} case "BeaconBlockHeader": obj = ðpb.BeaconBlockHeader{} case "BeaconState": obj = ðpb.BeaconStateCapella{} case "Checkpoint": obj = ðpb.Checkpoint{} case "Deposit": obj = ðpb.Deposit{} case "DepositMessage": obj = ðpb.DepositMessage{} case "DepositData": obj = ðpb.Deposit_Data{} case "Eth1Data": obj = ðpb.Eth1Data{} case "Eth1Block": t.Skip("Unused type") return nil, nil case "Fork": obj = ðpb.Fork{} case "ForkData": obj = ðpb.ForkData{} case "HistoricalBatch": obj = ðpb.HistoricalBatch{} case "IndexedAttestation": obj = ðpb.IndexedAttestation{} case "LightClientHeader": t.Skip("not a beacon node type, this is a light node type") return nil, nil case "PendingAttestation": obj = ðpb.PendingAttestation{} case "ProposerSlashing": obj = ðpb.ProposerSlashing{} case "SignedAggregateAndProof": obj = ðpb.SignedAggregateAttestationAndProof{} case "SignedBeaconBlock": obj = ðpb.SignedBeaconBlockCapella{} case "SignedBeaconBlockHeader": obj = ðpb.SignedBeaconBlockHeader{} case "SignedVoluntaryExit": obj = ðpb.SignedVoluntaryExit{} case "SigningData": obj = ðpb.SigningData{} case "Validator": obj = ðpb.Validator{} case "VoluntaryExit": obj = ðpb.VoluntaryExit{} case "SyncCommitteeMessage": obj = ðpb.SyncCommitteeMessage{} case "SyncCommitteeContribution": obj = ðpb.SyncCommitteeContribution{} case "ContributionAndProof": obj = ðpb.ContributionAndProof{} case "SignedContributionAndProof": obj = ðpb.SignedContributionAndProof{} case "SyncAggregate": obj = ðpb.SyncAggregate{} case "SyncAggregatorSelectionData": obj = ðpb.SyncAggregatorSelectionData{} case "SyncCommittee": obj = ðpb.SyncCommittee{} case "HistoricalSummary": obj = ðpb.HistoricalSummary{} case "LightClientOptimisticUpdate": t.Skip("not a beacon node type, this is a light node type") return nil, nil case "LightClientFinalityUpdate": t.Skip("not a beacon node type, this is a light node type") return nil, nil case "LightClientBootstrap": t.Skip("not a beacon node type, this is a light node type") return nil, nil 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 = ðpb.PowBlock{} case "Withdrawal": obj = &enginev1.Withdrawal{} case "BLSToExecutionChange": obj = ðpb.BLSToExecutionChange{} case "SignedBLSToExecutionChange": obj = ðpb.SignedBLSToExecutionChange{} 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 }