mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 07:58:22 -05:00
@@ -3,6 +3,7 @@ load("@prysm//tools/go:def.bzl", "go_library", "go_test")
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"attestation.go",
|
||||
"churn.go",
|
||||
"consolidations.go",
|
||||
"deposits.go",
|
||||
|
||||
7
beacon-chain/core/electra/attestation.go
Normal file
7
beacon-chain/core/electra/attestation.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package electra
|
||||
|
||||
import "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/altair"
|
||||
|
||||
var (
|
||||
ProcessAttestationsNoVerifySignature = altair.ProcessAttestationsNoVerifySignature
|
||||
)
|
||||
@@ -3,6 +3,7 @@ load("@prysm//tools/go:def.bzl", "go_test")
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = [
|
||||
"attestation_test.go",
|
||||
"attester_slashing_test.go",
|
||||
"block_header_test.go",
|
||||
"bls_to_execution_change_test.go",
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package operations
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v5/testing/spectest/shared/electra/operations"
|
||||
)
|
||||
|
||||
func TestMainnet_Electra_Operations_Attestation(t *testing.T) {
|
||||
operations.RunAttestationTest(t, "mainnet")
|
||||
}
|
||||
@@ -3,6 +3,7 @@ load("@prysm//tools/go:def.bzl", "go_test")
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = [
|
||||
"attestation_test.go",
|
||||
"attester_slashing_test.go",
|
||||
"block_header_test.go",
|
||||
"bls_to_execution_change_test.go",
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package operations
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v5/testing/spectest/shared/electra/operations"
|
||||
)
|
||||
|
||||
func TestMinimal_Electra_Operations_Attestation(t *testing.T) {
|
||||
operations.RunAttestationTest(t, "minimal")
|
||||
}
|
||||
@@ -4,6 +4,7 @@ go_library(
|
||||
name = "go_default_library",
|
||||
testonly = True,
|
||||
srcs = [
|
||||
"attestation.go",
|
||||
"attester_slashing.go",
|
||||
"block_header.go",
|
||||
"bls_to_execution_changes.go",
|
||||
|
||||
59
testing/spectest/shared/electra/operations/attestation.go
Normal file
59
testing/spectest/shared/electra/operations/attestation.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package operations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/snappy"
|
||||
"github.com/pkg/errors"
|
||||
b "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/blocks"
|
||||
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/electra"
|
||||
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state"
|
||||
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v5/testing/require"
|
||||
"github.com/prysmaticlabs/prysm/v5/testing/spectest/utils"
|
||||
"github.com/prysmaticlabs/prysm/v5/testing/util"
|
||||
)
|
||||
|
||||
func RunAttestationTest(t *testing.T, config string) {
|
||||
require.NoError(t, utils.SetConfig(t, config))
|
||||
testFolders, testsFolderPath := utils.TestFolders(t, config, "electra", "operations/attestation/pyspec_tests")
|
||||
if len(testFolders) == 0 {
|
||||
t.Fatalf("No test folders found for %s/%s/%s", config, "electra", "operations/attestation/pyspec_tests")
|
||||
}
|
||||
for _, folder := range testFolders {
|
||||
t.Run(folder.Name(), func(t *testing.T) {
|
||||
folderPath := path.Join(testsFolderPath, folder.Name())
|
||||
attestationFile, err := util.BazelFileBytes(folderPath, "attestation.ssz_snappy")
|
||||
require.NoError(t, err)
|
||||
attestationSSZ, err := snappy.Decode(nil /* dst */, attestationFile)
|
||||
require.NoError(t, err, "Failed to decompress")
|
||||
att := ðpb.AttestationElectra{}
|
||||
require.NoError(t, att.UnmarshalSSZ(attestationSSZ), "Failed to unmarshal")
|
||||
|
||||
body := ðpb.BeaconBlockBodyElectra{Attestations: []*ethpb.AttestationElectra{att}}
|
||||
processAtt := func(ctx context.Context, st state.BeaconState, blk interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, error) {
|
||||
st, err = electra.ProcessAttestationsNoVerifySignature(ctx, st, blk.Block())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
aSet, err := b.AttestationSignatureBatch(ctx, st, blk.Block().Body().Attestations())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
verified, err := aSet.Verify()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !verified {
|
||||
return nil, errors.New("could not batch verify attestation signature")
|
||||
}
|
||||
return st, nil
|
||||
}
|
||||
|
||||
RunBlockOperationTest(t, folderPath, body, processAtt)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ func RunAttesterSlashingTest(t *testing.T, config string) {
|
||||
require.NoError(t, attSlashing.UnmarshalSSZ(attSlashingSSZ), "Failed to unmarshal")
|
||||
|
||||
body := ðpb.BeaconBlockBodyElectra{AttesterSlashings: []*ethpb.AttesterSlashingElectra{attSlashing}}
|
||||
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) {
|
||||
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, error) {
|
||||
return blocks.ProcessAttesterSlashings(ctx, s, b.Block().Body().AttesterSlashings(), validators.SlashValidator)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -35,7 +35,7 @@ func RunBLSToExecutionChangeTest(t *testing.T, config string) {
|
||||
body := ðpb.BeaconBlockBodyElectra{
|
||||
BlsToExecutionChanges: []*ethpb.SignedBLSToExecutionChange{change},
|
||||
}
|
||||
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) {
|
||||
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, error) {
|
||||
st, err := blocks.ProcessBLSToExecutionChanges(s, b.Block())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -30,7 +30,7 @@ func RunConsolidationTest(t *testing.T, config string) {
|
||||
require.NoError(t, consolidation.UnmarshalSSZ(consolidationSSZ), "Failed to unmarshal")
|
||||
|
||||
body := ðpb.BeaconBlockBodyElectra{Consolidations: []*ethpb.SignedConsolidation{consolidation}}
|
||||
processConsolidationFunc := func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) {
|
||||
processConsolidationFunc := func(ctx context.Context, s state.BeaconState, b interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, error) {
|
||||
body, ok := b.Block().Body().(interfaces.ROBlockBodyElectra)
|
||||
if !ok {
|
||||
t.Error("block body is not electra")
|
||||
|
||||
@@ -36,7 +36,7 @@ func RunExecutionLayerWithdrawalRequestTest(t *testing.T, config string) {
|
||||
withdrawalRequest,
|
||||
},
|
||||
}}
|
||||
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) {
|
||||
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, error) {
|
||||
bod, ok := b.Block().Body().(interfaces.ROBlockBodyElectra)
|
||||
require.Equal(t, true, ok)
|
||||
e, err := bod.Execution()
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
"google.golang.org/protobuf/testing/protocmp"
|
||||
)
|
||||
|
||||
type blockOperation func(context.Context, state.BeaconState, interfaces.SignedBeaconBlock) (state.BeaconState, error)
|
||||
type blockOperation func(context.Context, state.BeaconState, interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, error)
|
||||
|
||||
// RunBlockOperationTest takes in the prestate and the beacon block body, processes it through the
|
||||
// passed in block operation function and checks the post state with the expected post state.
|
||||
|
||||
@@ -30,7 +30,7 @@ func RunProposerSlashingTest(t *testing.T, config string) {
|
||||
require.NoError(t, proposerSlashing.UnmarshalSSZ(proposerSlashingSSZ), "Failed to unmarshal")
|
||||
|
||||
body := ðpb.BeaconBlockBodyElectra{ProposerSlashings: []*ethpb.ProposerSlashing{proposerSlashing}}
|
||||
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) {
|
||||
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, error) {
|
||||
return blocks.ProcessProposerSlashings(ctx, s, b.Block().Body().ProposerSlashings(), validators.SlashValidator)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -29,7 +29,7 @@ func RunSyncCommitteeTest(t *testing.T, config string) {
|
||||
require.NoError(t, sc.UnmarshalSSZ(syncCommitteeSSZ), "Failed to unmarshal")
|
||||
|
||||
body := ðpb.BeaconBlockBodyElectra{SyncAggregate: sc}
|
||||
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) {
|
||||
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, error) {
|
||||
st, _, err := electra.ProcessSyncAggregate(context.Background(), s, body.SyncAggregate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -29,7 +29,7 @@ func RunVoluntaryExitTest(t *testing.T, config string) {
|
||||
require.NoError(t, voluntaryExit.UnmarshalSSZ(exitSSZ), "Failed to unmarshal")
|
||||
|
||||
body := ðpb.BeaconBlockBodyElectra{VoluntaryExits: []*ethpb.SignedVoluntaryExit{voluntaryExit}}
|
||||
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) {
|
||||
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, error) {
|
||||
return blocks.ProcessVoluntaryExits(ctx, s, b.Block().Body().VoluntaryExits())
|
||||
})
|
||||
})
|
||||
|
||||
@@ -31,7 +31,7 @@ func RunWithdrawalsTest(t *testing.T, config string) {
|
||||
require.NoError(t, payload.UnmarshalSSZ(payloadSSZ), "failed to unmarshal")
|
||||
|
||||
body := ðpb.BeaconBlockBodyElectra{ExecutionPayload: payload}
|
||||
RunBlockOperationTest(t, folderPath, body, func(_ context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) {
|
||||
RunBlockOperationTest(t, folderPath, body, func(_ context.Context, s state.BeaconState, b interfaces.ReadOnlySignedBeaconBlock) (state.BeaconState, error) {
|
||||
payload, err := b.Block().Body().Execution()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user