EIP 7549 spectests (#14027)

* EIP 7549 spectests

* merge fix
This commit is contained in:
Radosław Kapka
2024-06-10 18:33:43 +02:00
committed by GitHub
parent 8413660d5f
commit b7866be3a9
17 changed files with 101 additions and 9 deletions

View File

@@ -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",

View File

@@ -0,0 +1,7 @@
package electra
import "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/altair"
var (
ProcessAttestationsNoVerifySignature = altair.ProcessAttestationsNoVerifySignature
)

View File

@@ -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",

View File

@@ -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")
}

View File

@@ -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",

View File

@@ -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")
}

View File

@@ -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",

View 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 := &ethpb.AttestationElectra{}
require.NoError(t, att.UnmarshalSSZ(attestationSSZ), "Failed to unmarshal")
body := &ethpb.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)
})
}
}

View File

@@ -30,7 +30,7 @@ func RunAttesterSlashingTest(t *testing.T, config string) {
require.NoError(t, attSlashing.UnmarshalSSZ(attSlashingSSZ), "Failed to unmarshal")
body := &ethpb.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)
})
})

View File

@@ -35,7 +35,7 @@ func RunBLSToExecutionChangeTest(t *testing.T, config string) {
body := &ethpb.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

View File

@@ -30,7 +30,7 @@ func RunConsolidationTest(t *testing.T, config string) {
require.NoError(t, consolidation.UnmarshalSSZ(consolidationSSZ), "Failed to unmarshal")
body := &ethpb.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")

View File

@@ -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()

View File

@@ -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.

View File

@@ -30,7 +30,7 @@ func RunProposerSlashingTest(t *testing.T, config string) {
require.NoError(t, proposerSlashing.UnmarshalSSZ(proposerSlashingSSZ), "Failed to unmarshal")
body := &ethpb.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)
})
})

View File

@@ -29,7 +29,7 @@ func RunSyncCommitteeTest(t *testing.T, config string) {
require.NoError(t, sc.UnmarshalSSZ(syncCommitteeSSZ), "Failed to unmarshal")
body := &ethpb.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

View File

@@ -29,7 +29,7 @@ func RunVoluntaryExitTest(t *testing.T, config string) {
require.NoError(t, voluntaryExit.UnmarshalSSZ(exitSSZ), "Failed to unmarshal")
body := &ethpb.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())
})
})

View File

@@ -31,7 +31,7 @@ func RunWithdrawalsTest(t *testing.T, config string) {
require.NoError(t, payload.UnmarshalSSZ(payloadSSZ), "failed to unmarshal")
body := &ethpb.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