mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Add Gloas protobuf definitions with spec tests (#15601)
* Add Gloas protobuf definitions with spec tests * Potuz's feedback * Update comment * Update final commits for fastssz and go-bitfield * Sync with develop offchain labs go bitfield changes * Update deps.bzl Co-authored-by: Preston Van Loon <pvanloon@offchainlabs.com> * Update deps.bzl Co-authored-by: Preston Van Loon <pvanloon@offchainlabs.com> * Gazelle fix build --------- Co-authored-by: Preston Van Loon <pvanloon@offchainlabs.com>
This commit is contained in:
@@ -200,6 +200,7 @@ go_test(
|
||||
"fulu__sanity__blocks_test.go",
|
||||
"fulu__sanity__slots_test.go",
|
||||
"fulu__ssz_static__ssz_static_test.go",
|
||||
"gloas__ssz_static__ssz_static_test.go",
|
||||
"phase0__epoch_processing__effective_balance_updates_test.go",
|
||||
"phase0__epoch_processing__epoch_processing_test.go",
|
||||
"phase0__epoch_processing__eth1_data_reset_test.go",
|
||||
@@ -277,6 +278,7 @@ go_test(
|
||||
"//testing/spectest/shared/fulu/rewards:go_default_library",
|
||||
"//testing/spectest/shared/fulu/sanity:go_default_library",
|
||||
"//testing/spectest/shared/fulu/ssz_static:go_default_library",
|
||||
"//testing/spectest/shared/gloas/ssz_static:go_default_library",
|
||||
"//testing/spectest/shared/phase0/epoch_processing:go_default_library",
|
||||
"//testing/spectest/shared/phase0/finality:go_default_library",
|
||||
"//testing/spectest/shared/phase0/operations:go_default_library",
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package mainnet
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/OffchainLabs/prysm/v6/testing/spectest/shared/gloas/ssz_static"
|
||||
)
|
||||
|
||||
func TestMainnet_Gloas_SSZStatic(t *testing.T) {
|
||||
ssz_static.RunSSZStaticTests(t, "mainnet")
|
||||
}
|
||||
@@ -206,6 +206,7 @@ go_test(
|
||||
"fulu__sanity__blocks_test.go",
|
||||
"fulu__sanity__slots_test.go",
|
||||
"fulu__ssz_static__ssz_static_test.go",
|
||||
"gloas__ssz_static__ssz_static_test.go",
|
||||
"phase0__epoch_processing__effective_balance_updates_test.go",
|
||||
"phase0__epoch_processing__epoch_processing_test.go",
|
||||
"phase0__epoch_processing__eth1_data_reset_test.go",
|
||||
@@ -287,6 +288,7 @@ go_test(
|
||||
"//testing/spectest/shared/fulu/rewards:go_default_library",
|
||||
"//testing/spectest/shared/fulu/sanity:go_default_library",
|
||||
"//testing/spectest/shared/fulu/ssz_static:go_default_library",
|
||||
"//testing/spectest/shared/gloas/ssz_static:go_default_library",
|
||||
"//testing/spectest/shared/phase0/epoch_processing:go_default_library",
|
||||
"//testing/spectest/shared/phase0/finality:go_default_library",
|
||||
"//testing/spectest/shared/phase0/operations:go_default_library",
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package minimal
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/OffchainLabs/prysm/v6/testing/spectest/shared/gloas/ssz_static"
|
||||
)
|
||||
|
||||
func TestMinimal_Gloas_SSZStatic(t *testing.T) {
|
||||
ssz_static.RunSSZStaticTests(t, "minimal")
|
||||
}
|
||||
15
testing/spectest/shared/gloas/ssz_static/BUILD.bazel
Normal file
15
testing/spectest/shared/gloas/ssz_static/BUILD.bazel
Normal file
@@ -0,0 +1,15 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
testonly = True,
|
||||
srcs = ["ssz_static.go"],
|
||||
importpath = "github.com/OffchainLabs/prysm/v6/testing/spectest/shared/gloas/ssz_static",
|
||||
visibility = ["//testing/spectest:__subpackages__"],
|
||||
deps = [
|
||||
"//proto/engine/v1:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//testing/spectest/shared/common/ssz_static:go_default_library",
|
||||
"@com_github_prysmaticlabs_fastssz//:go_default_library",
|
||||
],
|
||||
)
|
||||
184
testing/spectest/shared/gloas/ssz_static/ssz_static.go
Normal file
184
testing/spectest/shared/gloas/ssz_static/ssz_static.go
Normal file
@@ -0,0 +1,184 @@
|
||||
package ssz_static
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
enginev1 "github.com/OffchainLabs/prysm/v6/proto/engine/v1"
|
||||
ethpb "github.com/OffchainLabs/prysm/v6/proto/prysm/v1alpha1"
|
||||
common "github.com/OffchainLabs/prysm/v6/testing/spectest/shared/common/ssz_static"
|
||||
fssz "github.com/prysmaticlabs/fastssz"
|
||||
)
|
||||
|
||||
// RunSSZStaticTests executes "ssz_static" tests.
|
||||
func RunSSZStaticTests(t *testing.T, config string) {
|
||||
common.RunSSZStaticTests(t, config, "gloas", unmarshalledSSZ, customHtr)
|
||||
}
|
||||
|
||||
func customHtr(t *testing.T, htrs []common.HTR, object interface{}) []common.HTR {
|
||||
// TODO: Add custom HTR for BeaconStateGloas when state-native support is implemented
|
||||
// For now, only use the default fastssz HTR methods
|
||||
return htrs
|
||||
}
|
||||
|
||||
// unmarshalledSSZ unmarshalls serialized input.
|
||||
func unmarshalledSSZ(t *testing.T, serializedBytes []byte, folderName string) (interface{}, error) {
|
||||
var obj interface{}
|
||||
|
||||
switch folderName {
|
||||
// Gloas specific types
|
||||
case "ExecutionPayloadBid":
|
||||
obj = ðpb.ExecutionPayloadBid{}
|
||||
case "SignedExecutionPayloadBid":
|
||||
obj = ðpb.SignedExecutionPayloadBid{}
|
||||
case "PayloadAttestationData":
|
||||
obj = ðpb.PayloadAttestationData{}
|
||||
case "PayloadAttestation":
|
||||
obj = ðpb.PayloadAttestation{}
|
||||
case "PayloadAttestationMessage":
|
||||
obj = ðpb.PayloadAttestationMessage{}
|
||||
case "BeaconBlock":
|
||||
obj = ðpb.BeaconBlockGloas{}
|
||||
case "BeaconBlockBody":
|
||||
obj = ðpb.BeaconBlockBodyGloas{}
|
||||
case "BeaconState":
|
||||
obj = ðpb.BeaconStateGloas{}
|
||||
case "BuilderPendingPayment":
|
||||
obj = ðpb.BuilderPendingPayment{}
|
||||
case "BuilderPendingWithdrawal":
|
||||
obj = ðpb.BuilderPendingWithdrawal{}
|
||||
case "ExecutionPayloadEnvelope":
|
||||
obj = ðpb.ExecutionPayloadEnvelope{}
|
||||
case "SignedExecutionPayloadEnvelope":
|
||||
obj = ðpb.SignedExecutionPayloadEnvelope{}
|
||||
case "ForkChoiceNode":
|
||||
t.Skip("Not a consensus type")
|
||||
case "IndexedPayloadAttestation":
|
||||
t.Skip("Not a consensus type")
|
||||
case "DataColumnSidecar":
|
||||
obj = ðpb.DataColumnSidecarGloas{}
|
||||
|
||||
// Standard types that also exist in gloas
|
||||
case "ExecutionPayload":
|
||||
obj = &enginev1.ExecutionPayloadDeneb{}
|
||||
case "ExecutionPayloadHeader":
|
||||
obj = &enginev1.ExecutionPayloadHeaderDeneb{}
|
||||
case "Attestation":
|
||||
obj = ðpb.AttestationElectra{}
|
||||
case "AttestationData":
|
||||
obj = ðpb.AttestationData{}
|
||||
case "AttesterSlashing":
|
||||
obj = ðpb.AttesterSlashingElectra{}
|
||||
case "AggregateAndProof":
|
||||
obj = ðpb.AggregateAttestationAndProofElectra{}
|
||||
case "BeaconBlockHeader":
|
||||
obj = ðpb.BeaconBlockHeader{}
|
||||
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")
|
||||
case "Fork":
|
||||
obj = ðpb.Fork{}
|
||||
case "ForkData":
|
||||
obj = ðpb.ForkData{}
|
||||
case "HistoricalBatch":
|
||||
obj = ðpb.HistoricalBatch{}
|
||||
case "IndexedAttestation":
|
||||
obj = ðpb.IndexedAttestationElectra{}
|
||||
case "PendingAttestation":
|
||||
obj = ðpb.PendingAttestation{}
|
||||
case "ProposerSlashing":
|
||||
obj = ðpb.ProposerSlashing{}
|
||||
case "SignedAggregateAndProof":
|
||||
obj = ðpb.SignedAggregateAttestationAndProofElectra{}
|
||||
case "SignedBeaconBlock":
|
||||
obj = ðpb.SignedBeaconBlockGloas{}
|
||||
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 "SingleAttestation":
|
||||
obj = ðpb.SingleAttestation{}
|
||||
case "SyncAggregate":
|
||||
obj = ðpb.SyncAggregate{}
|
||||
case "SyncAggregatorSelectionData":
|
||||
obj = ðpb.SyncAggregatorSelectionData{}
|
||||
case "SyncCommittee":
|
||||
obj = ðpb.SyncCommittee{}
|
||||
case "LightClientOptimisticUpdate":
|
||||
obj = ðpb.LightClientOptimisticUpdateDeneb{}
|
||||
case "LightClientFinalityUpdate":
|
||||
obj = ðpb.LightClientFinalityUpdateElectra{}
|
||||
case "LightClientBootstrap":
|
||||
obj = ðpb.LightClientBootstrapElectra{}
|
||||
case "LightClientUpdate":
|
||||
obj = ðpb.LightClientUpdateElectra{}
|
||||
case "LightClientHeader":
|
||||
obj = ðpb.LightClientHeaderDeneb{}
|
||||
case "BlobIdentifier":
|
||||
obj = ðpb.BlobIdentifier{}
|
||||
case "BlobSidecar":
|
||||
t.Skip("Unused type")
|
||||
case "PowBlock":
|
||||
obj = ðpb.PowBlock{}
|
||||
case "Withdrawal":
|
||||
obj = &enginev1.Withdrawal{}
|
||||
case "HistoricalSummary":
|
||||
obj = ðpb.HistoricalSummary{}
|
||||
case "BLSToExecutionChange":
|
||||
obj = ðpb.BLSToExecutionChange{}
|
||||
case "SignedBLSToExecutionChange":
|
||||
obj = ðpb.SignedBLSToExecutionChange{}
|
||||
case "PendingDeposit":
|
||||
obj = ðpb.PendingDeposit{}
|
||||
case "PendingPartialWithdrawal":
|
||||
obj = ðpb.PendingPartialWithdrawal{}
|
||||
case "PendingConsolidation":
|
||||
obj = ðpb.PendingConsolidation{}
|
||||
case "WithdrawalRequest":
|
||||
obj = &enginev1.WithdrawalRequest{}
|
||||
case "DepositRequest":
|
||||
obj = &enginev1.DepositRequest{}
|
||||
case "ConsolidationRequest":
|
||||
obj = &enginev1.ConsolidationRequest{}
|
||||
case "ExecutionRequests":
|
||||
obj = &enginev1.ExecutionRequests{}
|
||||
case "DataColumnsByRootIdentifier":
|
||||
obj = ðpb.DataColumnsByRootIdentifier{}
|
||||
case "MatrixEntry":
|
||||
t.Skip("Unused type")
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user