mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-08 10:41:19 +00:00
d077483577
* 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>
129 lines
3.8 KiB
Go
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 = ðpb.Attestation{}
|
|
case "AttestationData":
|
|
obj = ðpb.AttestationData{}
|
|
case "AttesterSlashing":
|
|
obj = ðpb.AttesterSlashing{}
|
|
case "AggregateAndProof":
|
|
obj = ðpb.AggregateAttestationAndProof{}
|
|
case "BeaconBlock":
|
|
obj = ðpb.BeaconBlockBellatrix{}
|
|
case "BeaconBlockBody":
|
|
obj = ðpb.BeaconBlockBodyBellatrix{}
|
|
case "BeaconBlockHeader":
|
|
obj = ðpb.BeaconBlockHeader{}
|
|
case "BeaconState":
|
|
obj = ðpb.BeaconStateBellatrix{}
|
|
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 "PendingAttestation":
|
|
obj = ðpb.PendingAttestation{}
|
|
case "ProposerSlashing":
|
|
obj = ðpb.ProposerSlashing{}
|
|
case "SignedAggregateAndProof":
|
|
obj = ðpb.SignedAggregateAttestationAndProof{}
|
|
case "SignedBeaconBlock":
|
|
obj = ðpb.SignedBeaconBlockBellatrix{}
|
|
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 "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{}
|
|
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
|
|
}
|