mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
test:beta.1 deneb tests (#12680)
This commit is contained in:
committed by
Preston Van Loon
parent
57b8da08d1
commit
708aee0fcb
@@ -9,6 +9,7 @@ go_test(
|
||||
"block_header_test.go",
|
||||
"bls_to_execution_change_test.go",
|
||||
"deposit_test.go",
|
||||
"execution_payload_test.go",
|
||||
"proposer_slashing_test.go",
|
||||
"sync_committee_test.go",
|
||||
"voluntary_exit_test.go",
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package operations
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/operations"
|
||||
)
|
||||
|
||||
func TestMainnet_Deneb_Operations_PayloadExecution(t *testing.T) {
|
||||
operations.RunExecutionPayloadTest(t, "mainnet")
|
||||
}
|
||||
13
testing/spectest/mainnet/deneb/random/BUILD.bazel
Normal file
13
testing/spectest/mainnet/deneb/random/BUILD.bazel
Normal file
@@ -0,0 +1,13 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_test")
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
size = "medium",
|
||||
timeout = "short",
|
||||
srcs = ["random_test.go"],
|
||||
data = glob(["*.yaml"]) + [
|
||||
"@consensus_spec_tests_mainnet//:test_data",
|
||||
],
|
||||
tags = ["spectest"],
|
||||
deps = ["//testing/spectest/shared/deneb/sanity:go_default_library"],
|
||||
)
|
||||
11
testing/spectest/mainnet/deneb/random/random_test.go
Normal file
11
testing/spectest/mainnet/deneb/random/random_test.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package random
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/sanity"
|
||||
)
|
||||
|
||||
func TestMainnet_Deneb_Random(t *testing.T) {
|
||||
sanity.RunBlockProcessingTest(t, "mainnet", "random/random/pyspec_tests")
|
||||
}
|
||||
13
testing/spectest/minimal/deneb/fork_transition/BUILD.bazel
Normal file
13
testing/spectest/minimal/deneb/fork_transition/BUILD.bazel
Normal file
@@ -0,0 +1,13 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_test")
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
timeout = "short",
|
||||
srcs = ["transition_test.go"],
|
||||
data = glob(["*.yaml"]) + [
|
||||
"@consensus_spec_tests_minimal//:test_data",
|
||||
],
|
||||
eth_network = "minimal",
|
||||
tags = ["spectest"],
|
||||
deps = ["//testing/spectest/shared/deneb/fork:go_default_library"],
|
||||
)
|
||||
@@ -0,0 +1,11 @@
|
||||
package fork_transition
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/fork"
|
||||
)
|
||||
|
||||
func TestMinimal_Deneb_Transition(t *testing.T) {
|
||||
fork.RunForkTransitionTest(t, "minimal")
|
||||
}
|
||||
@@ -9,6 +9,7 @@ go_test(
|
||||
"block_header_test.go",
|
||||
"bls_to_execution_change_test.go",
|
||||
"deposit_test.go",
|
||||
"execution_payload_test.go",
|
||||
"proposer_slashing_test.go",
|
||||
"sync_committee_test.go",
|
||||
"voluntary_exit_test.go",
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package operations
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/operations"
|
||||
)
|
||||
|
||||
func TestMinimal_Deneb_Operations_PayloadExecution(t *testing.T) {
|
||||
operations.RunExecutionPayloadTest(t, "minimal")
|
||||
}
|
||||
13
testing/spectest/minimal/deneb/random/BUILD.bazel
Normal file
13
testing/spectest/minimal/deneb/random/BUILD.bazel
Normal file
@@ -0,0 +1,13 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_test")
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
size = "small",
|
||||
srcs = ["random_test.go"],
|
||||
data = glob(["*.yaml"]) + [
|
||||
"@consensus_spec_tests_minimal//:test_data",
|
||||
],
|
||||
eth_network = "minimal",
|
||||
tags = ["spectest"],
|
||||
deps = ["//testing/spectest/shared/deneb/sanity:go_default_library"],
|
||||
)
|
||||
11
testing/spectest/minimal/deneb/random/random_test.go
Normal file
11
testing/spectest/minimal/deneb/random/random_test.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package random
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/sanity"
|
||||
)
|
||||
|
||||
func TestMinimal_Deneb_Random(t *testing.T) {
|
||||
sanity.RunBlockProcessingTest(t, "minimal", "random/random/pyspec_tests")
|
||||
}
|
||||
@@ -9,6 +9,7 @@ go_library(
|
||||
"block_header.go",
|
||||
"bls_to_execution_changes.go",
|
||||
"deposit.go",
|
||||
"execution_payload.go",
|
||||
"helpers.go",
|
||||
"proposer_slashing.go",
|
||||
"sync_committee.go",
|
||||
@@ -21,6 +22,7 @@ go_library(
|
||||
"//beacon-chain/core/altair:go_default_library",
|
||||
"//beacon-chain/core/blocks:go_default_library",
|
||||
"//beacon-chain/core/helpers:go_default_library",
|
||||
"//beacon-chain/core/transition:go_default_library",
|
||||
"//beacon-chain/core/validators:go_default_library",
|
||||
"//beacon-chain/state:go_default_library",
|
||||
"//beacon-chain/state/state-native:go_default_library",
|
||||
|
||||
104
testing/spectest/shared/deneb/operations/execution_payload.go
Normal file
104
testing/spectest/shared/deneb/operations/execution_payload.go
Normal file
@@ -0,0 +1,104 @@
|
||||
package operations
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/bazelbuild/rules_go/go/tools/bazel"
|
||||
"github.com/golang/snappy"
|
||||
"github.com/prysmaticlabs/prysm/v4/beacon-chain/core/blocks"
|
||||
"github.com/prysmaticlabs/prysm/v4/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/v4/beacon-chain/core/transition"
|
||||
state_native "github.com/prysmaticlabs/prysm/v4/beacon-chain/state/state-native"
|
||||
blocks2 "github.com/prysmaticlabs/prysm/v4/consensus-types/blocks"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v4/testing/require"
|
||||
"github.com/prysmaticlabs/prysm/v4/testing/spectest/utils"
|
||||
"github.com/prysmaticlabs/prysm/v4/testing/util"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
func RunExecutionPayloadTest(t *testing.T, config string) {
|
||||
require.NoError(t, utils.SetConfig(t, config))
|
||||
testFolders, testsFolderPath := utils.TestFolders(t, config, "deneb", "operations/execution_payload/pyspec_tests")
|
||||
if len(testFolders) == 0 {
|
||||
t.Fatalf("No test folders found for %s/%s/%s", config, "deneb", "operations/execution_payload/pyspec_tests")
|
||||
}
|
||||
for _, folder := range testFolders {
|
||||
t.Run(folder.Name(), func(t *testing.T) {
|
||||
helpers.ClearCache()
|
||||
|
||||
blockBodyFile, err := util.BazelFileBytes(testsFolderPath, folder.Name(), "body.ssz_snappy")
|
||||
require.NoError(t, err)
|
||||
blockSSZ, err := snappy.Decode(nil /* dst */, blockBodyFile)
|
||||
require.NoError(t, err, "Failed to decompress")
|
||||
body := ðpb.BeaconBlockBodyDeneb{}
|
||||
require.NoError(t, body.UnmarshalSSZ(blockSSZ), "Failed to unmarshal")
|
||||
b, err := blocks2.NewBeaconBlock(ðpb.BeaconBlockDeneb{Body: body})
|
||||
require.NoError(t, err)
|
||||
|
||||
preBeaconStateFile, err := util.BazelFileBytes(testsFolderPath, folder.Name(), "pre.ssz_snappy")
|
||||
require.NoError(t, err)
|
||||
preBeaconStateSSZ, err := snappy.Decode(nil /* dst */, preBeaconStateFile)
|
||||
require.NoError(t, err, "Failed to decompress")
|
||||
preBeaconStateBase := ðpb.BeaconStateDeneb{}
|
||||
require.NoError(t, preBeaconStateBase.UnmarshalSSZ(preBeaconStateSSZ), "Failed to unmarshal")
|
||||
preBeaconState, err := state_native.InitializeFromProtoDeneb(preBeaconStateBase)
|
||||
require.NoError(t, err)
|
||||
|
||||
postSSZFilepath, err := bazel.Runfile(path.Join(testsFolderPath, folder.Name(), "post.ssz_snappy"))
|
||||
postSSZExists := true
|
||||
if err != nil && strings.Contains(err.Error(), "could not locate file") {
|
||||
postSSZExists = false
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
payload, err := blocks2.WrappedExecutionPayloadDeneb(body.ExecutionPayload, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
file, err := util.BazelFileBytes(testsFolderPath, folder.Name(), "execution.yaml")
|
||||
require.NoError(t, err)
|
||||
config := &ExecutionConfig{}
|
||||
require.NoError(t, utils.UnmarshalYaml(file, config), "Failed to Unmarshal")
|
||||
|
||||
if postSSZExists {
|
||||
require.NoError(t, blocks.ValidatePayloadWhenMergeCompletes(preBeaconState, payload))
|
||||
require.NoError(t, blocks.ValidatePayload(preBeaconState, payload))
|
||||
require.NoError(t, transition.VerifyBlobCommitmentCount(b))
|
||||
require.NoError(t, preBeaconState.SetLatestExecutionPayloadHeader(payload))
|
||||
postBeaconStateFile, err := os.ReadFile(postSSZFilepath) // #nosec G304
|
||||
require.NoError(t, err)
|
||||
postBeaconStateSSZ, err := snappy.Decode(nil /* dst */, postBeaconStateFile)
|
||||
require.NoError(t, err, "Failed to decompress")
|
||||
|
||||
postBeaconState := ðpb.BeaconStateDeneb{}
|
||||
require.NoError(t, postBeaconState.UnmarshalSSZ(postBeaconStateSSZ), "Failed to unmarshal")
|
||||
pbState, err := state_native.ProtobufBeaconStateDeneb(preBeaconState.ToProto())
|
||||
require.NoError(t, err)
|
||||
t.Log(pbState)
|
||||
t.Log(postBeaconState)
|
||||
if !proto.Equal(pbState, postBeaconState) {
|
||||
t.Fatal("Post state does not match expected")
|
||||
}
|
||||
} else if config.Valid {
|
||||
err1 := blocks.ValidatePayloadWhenMergeCompletes(preBeaconState, payload)
|
||||
err2 := blocks.ValidatePayload(preBeaconState, payload)
|
||||
err3 := transition.VerifyBlobCommitmentCount(b)
|
||||
// Note: This doesn't test anything worthwhile. It essentially tests
|
||||
// that *any* error has occurred, not any specific error.
|
||||
if err1 == nil && err2 == nil && err3 == nil {
|
||||
t.Fatal("Did not fail when expected")
|
||||
}
|
||||
t.Logf("Expected failure; failure reason = %v", err)
|
||||
return
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
type ExecutionConfig struct {
|
||||
Valid bool `json:"execution_valid"`
|
||||
}
|
||||
Reference in New Issue
Block a user