mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Add Deneb upgrade function (#12433)
This commit is contained in:
committed by
Preston Van Loon
parent
c03571138c
commit
e0c69396ed
13
testing/spectest/mainnet/deneb/fork_helper/BUILD.bazel
Normal file
13
testing/spectest/mainnet/deneb/fork_helper/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 = ["upgrade_to_deneb_test.go"],
|
||||
data = glob(["*.yaml"]) + [
|
||||
"@consensus_spec_tests_mainnet//:test_data",
|
||||
],
|
||||
shard_count = 4,
|
||||
tags = ["spectest"],
|
||||
deps = ["//testing/spectest/shared/deneb/fork:go_default_library"],
|
||||
)
|
||||
@@ -0,0 +1,11 @@
|
||||
package fork_helper
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/fork"
|
||||
)
|
||||
|
||||
func TestMainnet_UpgradeToDeneb(t *testing.T) {
|
||||
fork.RunUpgradeToDeneb(t, "mainnet")
|
||||
}
|
||||
17
testing/spectest/minimal/deneb/fork/BUILD.bazel
Normal file
17
testing/spectest/minimal/deneb/fork/BUILD.bazel
Normal file
@@ -0,0 +1,17 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_test")
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
size = "small",
|
||||
srcs = ["upgrade_to_deneb_test.go"],
|
||||
data = glob(["*.yaml"]) + [
|
||||
"@consensus_spec_tests_minimal//:test_data",
|
||||
],
|
||||
eth_network = "minimal",
|
||||
shard_count = 4,
|
||||
tags = [
|
||||
"minimal",
|
||||
"spectest",
|
||||
],
|
||||
deps = ["//testing/spectest/shared/deneb/fork:go_default_library"],
|
||||
)
|
||||
11
testing/spectest/minimal/deneb/fork/upgrade_to_deneb_test.go
Normal file
11
testing/spectest/minimal/deneb/fork/upgrade_to_deneb_test.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package fork
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/fork"
|
||||
)
|
||||
|
||||
func TestMinimal_UpgradeToDeneb(t *testing.T) {
|
||||
fork.RunUpgradeToDeneb(t, "minimal")
|
||||
}
|
||||
20
testing/spectest/shared/deneb/fork/BUILD.bazel
Normal file
20
testing/spectest/shared/deneb/fork/BUILD.bazel
Normal file
@@ -0,0 +1,20 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
testonly = True,
|
||||
srcs = ["upgrade_to_deneb.go"],
|
||||
importpath = "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/fork",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//beacon-chain/core/deneb:go_default_library",
|
||||
"//beacon-chain/core/helpers:go_default_library",
|
||||
"//beacon-chain/state/state-native:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//testing/require:go_default_library",
|
||||
"//testing/spectest/utils:go_default_library",
|
||||
"//testing/util:go_default_library",
|
||||
"@com_github_golang_snappy//:go_default_library",
|
||||
"@org_golang_google_protobuf//proto:go_default_library",
|
||||
],
|
||||
)
|
||||
61
testing/spectest/shared/deneb/fork/upgrade_to_deneb.go
Normal file
61
testing/spectest/shared/deneb/fork/upgrade_to_deneb.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package fork
|
||||
|
||||
import (
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/snappy"
|
||||
"github.com/prysmaticlabs/prysm/v4/beacon-chain/core/deneb"
|
||||
"github.com/prysmaticlabs/prysm/v4/beacon-chain/core/helpers"
|
||||
state_native "github.com/prysmaticlabs/prysm/v4/beacon-chain/state/state-native"
|
||||
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"
|
||||
)
|
||||
|
||||
// RunUpgradeToDeneb is a helper function that runs Deneb's fork spec tests.
|
||||
// It unmarshals a pre- and post-state to check `UpgradeToDeneb` comply with spec implementation.
|
||||
func RunUpgradeToDeneb(t *testing.T, config string) {
|
||||
t.Skip("skipping tests at commit with incompatible ssz schema")
|
||||
require.NoError(t, utils.SetConfig(t, config))
|
||||
|
||||
testFolders, testsFolderPath := utils.TestFolders(t, config, "deneb", "fork/fork/pyspec_tests")
|
||||
for _, folder := range testFolders {
|
||||
t.Run(folder.Name(), func(t *testing.T) {
|
||||
helpers.ClearCache()
|
||||
folderPath := path.Join(testsFolderPath, folder.Name())
|
||||
|
||||
preStateFile, err := util.BazelFileBytes(path.Join(folderPath, "pre.ssz_snappy"))
|
||||
require.NoError(t, err)
|
||||
preStateSSZ, err := snappy.Decode(nil /* dst */, preStateFile)
|
||||
require.NoError(t, err, "Failed to decompress")
|
||||
preStateBase := ðpb.BeaconStateCapella{}
|
||||
if err := preStateBase.UnmarshalSSZ(preStateSSZ); err != nil {
|
||||
t.Fatalf("Failed to unmarshal: %v", err)
|
||||
}
|
||||
preState, err := state_native.InitializeFromProtoCapella(preStateBase)
|
||||
require.NoError(t, err)
|
||||
postState, err := deneb.UpgradeToDeneb(preState)
|
||||
require.NoError(t, err)
|
||||
postStateFromFunction, err := state_native.ProtobufBeaconStateDeneb(postState.ToProtoUnsafe())
|
||||
require.NoError(t, err)
|
||||
|
||||
postStateFile, err := util.BazelFileBytes(path.Join(folderPath, "post.ssz_snappy"))
|
||||
require.NoError(t, err)
|
||||
postStateSSZ, err := snappy.Decode(nil /* dst */, postStateFile)
|
||||
require.NoError(t, err, "Failed to decompress")
|
||||
postStateFromFile := ðpb.BeaconStateDeneb{}
|
||||
if err := postStateFromFile.UnmarshalSSZ(postStateSSZ); err != nil {
|
||||
t.Fatalf("Failed to unmarshal: %v", err)
|
||||
}
|
||||
|
||||
if !proto.Equal(postStateFromFile, postStateFromFunction) {
|
||||
t.Log(postStateFromFile.LatestExecutionPayloadHeader)
|
||||
t.Log(postStateFromFunction.LatestExecutionPayloadHeader)
|
||||
t.Fatal("Post state does not match expected")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user