mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 21:38:05 -05:00
Update spec tests (#8792)
* update path to minimal tests * update specs testutils * fix attestation_test * attester_slashing_test * fix block_header_test * block_processing_minimal * core/blocks minimal spectests * epoch_processing minimal spectests * slot_processing minimal spectests * bls spectests * update mainnet tests * fix remaining tests * gazelle
This commit is contained in:
18
WORKSPACE
18
WORKSPACE
@@ -231,14 +231,14 @@ http_archive(
|
||||
filegroup(
|
||||
name = "test_data",
|
||||
srcs = glob([
|
||||
"**/*.ssz",
|
||||
"**/*.ssz_snappy",
|
||||
"**/*.yaml",
|
||||
]),
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
""",
|
||||
sha256 = "ef5396e4b13995da9776eeb5ae346a2de90970c28da3c4f0dcaa4ab9f0ad1f93",
|
||||
url = "https://github.com/ethereum/eth2.0-spec-tests/releases/download/v1.0.0/general.tar.gz",
|
||||
sha256 = "deacc076365c727d653ac064894ecf0d1b0a675d86704dc8de271259f6a7314b",
|
||||
url = "https://github.com/ethereum/eth2.0-spec-tests/releases/download/v1.1.0-alpha.3/general.tar.gz",
|
||||
)
|
||||
|
||||
http_archive(
|
||||
@@ -247,14 +247,14 @@ http_archive(
|
||||
filegroup(
|
||||
name = "test_data",
|
||||
srcs = glob([
|
||||
"**/*.ssz",
|
||||
"**/*.ssz_snappy",
|
||||
"**/*.yaml",
|
||||
]),
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
""",
|
||||
sha256 = "170551b441e7d54b73248372ad9ce8cb6c148810b5f1364637117a63f4f1c085",
|
||||
url = "https://github.com/ethereum/eth2.0-spec-tests/releases/download/v1.0.0/minimal.tar.gz",
|
||||
sha256 = "6e9886af3d2f024e563249d70388129e28e3e92f742f289238ed9b7ec7a7f930",
|
||||
url = "https://github.com/ethereum/eth2.0-spec-tests/releases/download/v1.1.0-alpha.3/minimal.tar.gz",
|
||||
)
|
||||
|
||||
http_archive(
|
||||
@@ -263,14 +263,14 @@ http_archive(
|
||||
filegroup(
|
||||
name = "test_data",
|
||||
srcs = glob([
|
||||
"**/*.ssz",
|
||||
"**/*.ssz_snappy",
|
||||
"**/*.yaml",
|
||||
]),
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
""",
|
||||
sha256 = "b541a9979b4703fa5ee5d2182b0b5313c38efc54ae7eaec2eef793230a52ec83",
|
||||
url = "https://github.com/ethereum/eth2.0-spec-tests/releases/download/v1.0.0/mainnet.tar.gz",
|
||||
sha256 = "a7b3d0ffc02a567250f424d69b2474fdc9477cd56eada60af7474560b46a8527",
|
||||
url = "https://github.com/ethereum/eth2.0-spec-tests/releases/download/v1.1.0-alpha.3/mainnet.tar.gz",
|
||||
)
|
||||
|
||||
http_archive(
|
||||
|
||||
@@ -45,6 +45,7 @@ go_test(
|
||||
"//shared/testutil:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"@com_github_gogo_protobuf//proto:go_default_library",
|
||||
"@com_github_golang_snappy//:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@in_gopkg_d4l3k_messagediff_v1//:go_default_library",
|
||||
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
|
||||
@@ -82,6 +83,7 @@ go_test(
|
||||
"//shared/testutil:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"@com_github_gogo_protobuf//proto:go_default_library",
|
||||
"@com_github_golang_snappy//:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@in_gopkg_d4l3k_messagediff_v1//:go_default_library",
|
||||
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/snappy"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
"github.com/prysmaticlabs/prysm/shared/params/spectest"
|
||||
@@ -14,14 +15,16 @@ import (
|
||||
func runAttestationTest(t *testing.T, config string) {
|
||||
require.NoError(t, spectest.SetConfig(t, config))
|
||||
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "operations/attestation/pyspec_tests")
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "phase0", "operations/attestation/pyspec_tests")
|
||||
for _, folder := range testFolders {
|
||||
t.Run(folder.Name(), func(t *testing.T) {
|
||||
folderPath := path.Join(testsFolderPath, folder.Name())
|
||||
attestationFile, err := testutil.BazelFileBytes(folderPath, "attestation.ssz")
|
||||
attestationFile, err := testutil.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.Attestation{}
|
||||
require.NoError(t, att.UnmarshalSSZ(attestationFile), "Failed to unmarshal")
|
||||
require.NoError(t, att.UnmarshalSSZ(attestationSSZ), "Failed to unmarshal")
|
||||
|
||||
body := ðpb.BeaconBlockBody{Attestations: []*ethpb.Attestation{att}}
|
||||
testutil.RunBlockOperationTest(t, folderPath, body, blocks.ProcessAttestations)
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/snappy"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
v "github.com/prysmaticlabs/prysm/beacon-chain/core/validators"
|
||||
@@ -17,14 +18,16 @@ import (
|
||||
func runAttesterSlashingTest(t *testing.T, config string) {
|
||||
require.NoError(t, spectest.SetConfig(t, config))
|
||||
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "operations/attester_slashing/pyspec_tests")
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "phase0", "operations/attester_slashing/pyspec_tests")
|
||||
for _, folder := range testFolders {
|
||||
t.Run(folder.Name(), func(t *testing.T) {
|
||||
folderPath := path.Join(testsFolderPath, folder.Name())
|
||||
attSlashingFile, err := testutil.BazelFileBytes(folderPath, "attester_slashing.ssz")
|
||||
attSlashingFile, err := testutil.BazelFileBytes(folderPath, "attester_slashing.ssz_snappy")
|
||||
require.NoError(t, err)
|
||||
attSlashingSSZ, err := snappy.Decode(nil /* dst */, attSlashingFile)
|
||||
require.NoError(t, err, "Failed to decompress")
|
||||
attSlashing := ðpb.AttesterSlashing{}
|
||||
require.NoError(t, attSlashing.UnmarshalSSZ(attSlashingFile), "Failed to unmarshal")
|
||||
require.NoError(t, attSlashing.UnmarshalSSZ(attSlashingSSZ), "Failed to unmarshal")
|
||||
|
||||
body := ðpb.BeaconBlockBody{AttesterSlashings: []*ethpb.AttesterSlashing{attSlashing}}
|
||||
testutil.RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s iface.BeaconState, b *ethpb.SignedBeaconBlock) (iface.BeaconState, error) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/bazelbuild/rules_go/go/tools/bazel"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/golang/snappy"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateV0"
|
||||
@@ -21,23 +22,27 @@ import (
|
||||
func runBlockHeaderTest(t *testing.T, config string) {
|
||||
require.NoError(t, spectest.SetConfig(t, config))
|
||||
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "operations/block_header/pyspec_tests")
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "phase0", "operations/block_header/pyspec_tests")
|
||||
for _, folder := range testFolders {
|
||||
t.Run(folder.Name(), func(t *testing.T) {
|
||||
blockFile, err := testutil.BazelFileBytes(testsFolderPath, folder.Name(), "block.ssz")
|
||||
blockFile, err := testutil.BazelFileBytes(testsFolderPath, folder.Name(), "block.ssz_snappy")
|
||||
require.NoError(t, err)
|
||||
blockSSZ, err := snappy.Decode(nil /* dst */, blockFile)
|
||||
require.NoError(t, err, "Failed to decompress")
|
||||
block := ðpb.BeaconBlock{}
|
||||
require.NoError(t, block.UnmarshalSSZ(blockFile), "Failed to unmarshal")
|
||||
require.NoError(t, block.UnmarshalSSZ(blockSSZ), "Failed to unmarshal")
|
||||
|
||||
preBeaconStateFile, err := testutil.BazelFileBytes(testsFolderPath, folder.Name(), "pre.ssz")
|
||||
preBeaconStateFile, err := testutil.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.BeaconState{}
|
||||
require.NoError(t, preBeaconStateBase.UnmarshalSSZ(preBeaconStateFile), "Failed to unmarshal")
|
||||
require.NoError(t, preBeaconStateBase.UnmarshalSSZ(preBeaconStateSSZ), "Failed to unmarshal")
|
||||
preBeaconState, err := stateV0.InitializeFromProto(preBeaconStateBase)
|
||||
require.NoError(t, err)
|
||||
|
||||
// If the post.ssz is not present, it means the test should fail on our end.
|
||||
postSSZFilepath, err := bazel.Runfile(path.Join(testsFolderPath, folder.Name(), "post.ssz"))
|
||||
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
|
||||
@@ -54,9 +59,11 @@ func runBlockHeaderTest(t *testing.T, config string) {
|
||||
|
||||
postBeaconStateFile, err := ioutil.ReadFile(postSSZFilepath)
|
||||
require.NoError(t, err)
|
||||
postBeaconStateSSZ, err := snappy.Decode(nil /* dst */, postBeaconStateFile)
|
||||
require.NoError(t, err, "Failed to decompress")
|
||||
|
||||
postBeaconState := &pb.BeaconState{}
|
||||
require.NoError(t, postBeaconState.UnmarshalSSZ(postBeaconStateFile), "Failed to unmarshal")
|
||||
require.NoError(t, postBeaconState.UnmarshalSSZ(postBeaconStateSSZ), "Failed to unmarshal")
|
||||
pbState, err := stateV0.ProtobufBeaconState(beaconState.CloneInnerState())
|
||||
require.NoError(t, err)
|
||||
if !proto.Equal(pbState, postBeaconState) {
|
||||
|
||||
@@ -4,6 +4,6 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBlockProcessingMainnetYaml(t *testing.T) {
|
||||
func TestBlockProcessingMainnet(t *testing.T) {
|
||||
runBlockProcessingTest(t, "mainnet")
|
||||
}
|
||||
|
||||
@@ -4,6 +4,6 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBlockProcessingMinimalYaml(t *testing.T) {
|
||||
func TestBlockProcessingMinimal(t *testing.T) {
|
||||
runBlockProcessingTest(t, "minimal")
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
"github.com/bazelbuild/rules_go/go/tools/bazel"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/golang/snappy"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
|
||||
@@ -31,14 +32,16 @@ func init() {
|
||||
func runBlockProcessingTest(t *testing.T, config string) {
|
||||
require.NoError(t, spectest.SetConfig(t, config))
|
||||
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "sanity/blocks/pyspec_tests")
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "phase0", "sanity/blocks/pyspec_tests")
|
||||
for _, folder := range testFolders {
|
||||
t.Run(folder.Name(), func(t *testing.T) {
|
||||
helpers.ClearCache()
|
||||
preBeaconStateFile, err := testutil.BazelFileBytes(testsFolderPath, folder.Name(), "pre.ssz")
|
||||
preBeaconStateFile, err := testutil.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")
|
||||
beaconStateBase := &pb.BeaconState{}
|
||||
require.NoError(t, beaconStateBase.UnmarshalSSZ(preBeaconStateFile), "Failed to unmarshal")
|
||||
require.NoError(t, beaconStateBase.UnmarshalSSZ(preBeaconStateSSZ), "Failed to unmarshal")
|
||||
beaconState, err := stateV0.InitializeFromProto(beaconStateBase)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -52,11 +55,13 @@ func runBlockProcessingTest(t *testing.T, config string) {
|
||||
var processedState iface.BeaconState
|
||||
var ok bool
|
||||
for i := 0; i < metaYaml.BlocksCount; i++ {
|
||||
filename := fmt.Sprintf("blocks_%d.ssz", i)
|
||||
filename := fmt.Sprintf("blocks_%d.ssz_snappy", i)
|
||||
blockFile, err := testutil.BazelFileBytes(testsFolderPath, folder.Name(), filename)
|
||||
require.NoError(t, err)
|
||||
blockSSZ, err := snappy.Decode(nil /* dst */, blockFile)
|
||||
require.NoError(t, err, "Failed to decompress")
|
||||
block := ðpb.SignedBeaconBlock{}
|
||||
require.NoError(t, block.UnmarshalSSZ(blockFile), "Failed to unmarshal")
|
||||
require.NoError(t, block.UnmarshalSSZ(blockSSZ), "Failed to unmarshal")
|
||||
processedState, transitionError = state.ExecuteStateTransition(context.Background(), beaconState, block)
|
||||
if transitionError != nil {
|
||||
break
|
||||
@@ -66,7 +71,7 @@ func runBlockProcessingTest(t *testing.T, config string) {
|
||||
}
|
||||
|
||||
// If the post.ssz is not present, it means the test should fail on our end.
|
||||
postSSZFilepath, readError := bazel.Runfile(path.Join(testsFolderPath, folder.Name(), "post.ssz"))
|
||||
postSSZFilepath, readError := bazel.Runfile(path.Join(testsFolderPath, folder.Name(), "post.ssz_snappy"))
|
||||
postSSZExists := true
|
||||
if readError != nil && strings.Contains(readError.Error(), "could not locate file") {
|
||||
postSSZExists = false
|
||||
@@ -81,9 +86,11 @@ func runBlockProcessingTest(t *testing.T, config string) {
|
||||
|
||||
postBeaconStateFile, err := ioutil.ReadFile(postSSZFilepath)
|
||||
require.NoError(t, err)
|
||||
postBeaconStateSSZ, err := snappy.Decode(nil /* dst */, postBeaconStateFile)
|
||||
require.NoError(t, err, "Failed to decompress")
|
||||
|
||||
postBeaconState := &pb.BeaconState{}
|
||||
require.NoError(t, postBeaconState.UnmarshalSSZ(postBeaconStateFile), "Failed to unmarshal")
|
||||
require.NoError(t, postBeaconState.UnmarshalSSZ(postBeaconStateSSZ), "Failed to unmarshal")
|
||||
pbState, err := stateV0.ProtobufBeaconState(beaconState.InnerStateUnsafe())
|
||||
require.NoError(t, err)
|
||||
if !proto.Equal(pbState, postBeaconState) {
|
||||
|
||||
@@ -4,6 +4,6 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDepositMainnetYaml(t *testing.T) {
|
||||
func TestDepositMainnet(t *testing.T) {
|
||||
runDepositTest(t, "mainnet")
|
||||
}
|
||||
|
||||
@@ -4,6 +4,6 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDepositMinimalYaml(t *testing.T) {
|
||||
func TestDepositMinimal(t *testing.T) {
|
||||
runDepositTest(t, "minimal")
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/snappy"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
|
||||
@@ -16,14 +17,16 @@ import (
|
||||
func runDepositTest(t *testing.T, config string) {
|
||||
require.NoError(t, spectest.SetConfig(t, config))
|
||||
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "operations/deposit/pyspec_tests")
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "phase0", "operations/deposit/pyspec_tests")
|
||||
for _, folder := range testFolders {
|
||||
t.Run(folder.Name(), func(t *testing.T) {
|
||||
folderPath := path.Join(testsFolderPath, folder.Name())
|
||||
depositFile, err := testutil.BazelFileBytes(folderPath, "deposit.ssz")
|
||||
depositFile, err := testutil.BazelFileBytes(folderPath, "deposit.ssz_snappy")
|
||||
require.NoError(t, err)
|
||||
depositSSZ, err := snappy.Decode(nil /* dst */, depositFile)
|
||||
require.NoError(t, err, "Failed to decompress")
|
||||
deposit := ðpb.Deposit{}
|
||||
require.NoError(t, deposit.UnmarshalSSZ(depositFile), "Failed to unmarshal")
|
||||
require.NoError(t, deposit.UnmarshalSSZ(depositSSZ), "Failed to unmarshal")
|
||||
|
||||
body := ðpb.BeaconBlockBody{Deposits: []*ethpb.Deposit{deposit}}
|
||||
processDepositsFunc := func(ctx context.Context, s iface.BeaconState, b *ethpb.SignedBeaconBlock) (iface.BeaconState, error) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/snappy"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
v "github.com/prysmaticlabs/prysm/beacon-chain/core/validators"
|
||||
@@ -17,14 +18,16 @@ import (
|
||||
func runProposerSlashingTest(t *testing.T, config string) {
|
||||
require.NoError(t, spectest.SetConfig(t, config))
|
||||
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "operations/proposer_slashing/pyspec_tests")
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "phase0", "operations/proposer_slashing/pyspec_tests")
|
||||
for _, folder := range testFolders {
|
||||
t.Run(folder.Name(), func(t *testing.T) {
|
||||
folderPath := path.Join(testsFolderPath, folder.Name())
|
||||
proposerSlashingFile, err := testutil.BazelFileBytes(folderPath, "proposer_slashing.ssz")
|
||||
proposerSlashingFile, err := testutil.BazelFileBytes(folderPath, "proposer_slashing.ssz_snappy")
|
||||
require.NoError(t, err)
|
||||
proposerSlashingSSZ, err := snappy.Decode(nil /* dst */, proposerSlashingFile)
|
||||
require.NoError(t, err, "Failed to decompress")
|
||||
proposerSlashing := ðpb.ProposerSlashing{}
|
||||
require.NoError(t, proposerSlashing.UnmarshalSSZ(proposerSlashingFile), "Failed to unmarshal")
|
||||
require.NoError(t, proposerSlashing.UnmarshalSSZ(proposerSlashingSSZ), "Failed to unmarshal")
|
||||
|
||||
body := ðpb.BeaconBlockBody{ProposerSlashings: []*ethpb.ProposerSlashing{proposerSlashing}}
|
||||
testutil.RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s iface.BeaconState, b *ethpb.SignedBeaconBlock) (iface.BeaconState, error) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/snappy"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
|
||||
@@ -16,14 +17,16 @@ import (
|
||||
func runVoluntaryExitTest(t *testing.T, config string) {
|
||||
require.NoError(t, spectest.SetConfig(t, config))
|
||||
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "operations/voluntary_exit/pyspec_tests")
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "phase0", "operations/voluntary_exit/pyspec_tests")
|
||||
for _, folder := range testFolders {
|
||||
t.Run(folder.Name(), func(t *testing.T) {
|
||||
folderPath := path.Join(testsFolderPath, folder.Name())
|
||||
exitFile, err := testutil.BazelFileBytes(folderPath, "voluntary_exit.ssz")
|
||||
exitFile, err := testutil.BazelFileBytes(folderPath, "voluntary_exit.ssz_snappy")
|
||||
require.NoError(t, err)
|
||||
exitSSZ, err := snappy.Decode(nil /* dst */, exitFile)
|
||||
require.NoError(t, err, "Failed to decompress")
|
||||
voluntaryExit := ðpb.SignedVoluntaryExit{}
|
||||
require.NoError(t, voluntaryExit.UnmarshalSSZ(exitFile), "Failed to unmarshal")
|
||||
require.NoError(t, voluntaryExit.UnmarshalSSZ(exitSSZ), "Failed to unmarshal")
|
||||
|
||||
body := ðpb.BeaconBlockBody{VoluntaryExits: []*ethpb.SignedVoluntaryExit{voluntaryExit}}
|
||||
testutil.RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s iface.BeaconState, b *ethpb.SignedBeaconBlock) (iface.BeaconState, error) {
|
||||
|
||||
@@ -37,6 +37,7 @@ go_test(
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"@com_github_ghodss_yaml//:go_default_library",
|
||||
"@com_github_gogo_protobuf//proto:go_default_library",
|
||||
"@com_github_golang_snappy//:go_default_library",
|
||||
"@in_gopkg_d4l3k_messagediff_v1//:go_default_library",
|
||||
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
|
||||
],
|
||||
@@ -70,6 +71,7 @@ go_test(
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"@com_github_ghodss_yaml//:go_default_library",
|
||||
"@com_github_gogo_protobuf//proto:go_default_library",
|
||||
"@com_github_golang_snappy//:go_default_library",
|
||||
"@in_gopkg_d4l3k_messagediff_v1//:go_default_library",
|
||||
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
|
||||
],
|
||||
|
||||
@@ -2,11 +2,12 @@ package spectest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"path"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/ghodss/yaml"
|
||||
"github.com/golang/snappy"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch/precompute"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateV0"
|
||||
@@ -21,13 +22,31 @@ type Delta struct {
|
||||
Penalties []uint64 `json:"penalties"`
|
||||
}
|
||||
|
||||
var deltaFiles = []string{"source_deltas.yaml", "target_deltas.yaml", "head_deltas.yaml", "inactivity_penalty_deltas.yaml", "inclusion_delay_deltas.yaml"}
|
||||
// unmarshalSSZ deserializes specs data into a simple aggregating container.
|
||||
func (d *Delta) unmarshalSSZ(buf []byte) error {
|
||||
offset1 := binary.LittleEndian.Uint32(buf[:4])
|
||||
offset2 := binary.LittleEndian.Uint32(buf[4:8])
|
||||
|
||||
for i := uint32(0); i < offset2-offset1; i += 8 {
|
||||
d.Rewards = append(d.Rewards, binary.LittleEndian.Uint64(buf[offset1+i:offset1+i+8]))
|
||||
d.Penalties = append(d.Penalties, binary.LittleEndian.Uint64(buf[offset2+i:offset2+i+8]))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var deltaFiles = []string{
|
||||
"source_deltas.ssz_snappy",
|
||||
"target_deltas.ssz_snappy",
|
||||
"head_deltas.ssz_snappy",
|
||||
"inactivity_penalty_deltas.ssz_snappy",
|
||||
"inclusion_delay_deltas.ssz_snappy",
|
||||
}
|
||||
|
||||
func runPrecomputeRewardsAndPenaltiesTests(t *testing.T, config string) {
|
||||
require.NoError(t, spectest.SetConfig(t, config))
|
||||
testPaths := []string{"rewards/basic/pyspec_tests", "rewards/leak/pyspec_tests", "rewards/random/pyspec_tests"}
|
||||
for _, testPath := range testPaths {
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, testPath)
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "phase0", testPath)
|
||||
for _, folder := range testFolders {
|
||||
helpers.ClearCache()
|
||||
t.Run(folder.Name(), func(t *testing.T) {
|
||||
@@ -40,10 +59,12 @@ func runPrecomputeRewardsAndPenaltiesTests(t *testing.T, config string) {
|
||||
|
||||
func runPrecomputeRewardsAndPenaltiesTest(t *testing.T, testFolderPath string) {
|
||||
ctx := context.Background()
|
||||
preBeaconStateFile, err := testutil.BazelFileBytes(path.Join(testFolderPath, "pre.ssz"))
|
||||
preBeaconStateFile, err := testutil.BazelFileBytes(path.Join(testFolderPath, "pre.ssz_snappy"))
|
||||
require.NoError(t, err)
|
||||
preBeaconStateSSZ, err := snappy.Decode(nil /* dst */, preBeaconStateFile)
|
||||
require.NoError(t, err, "Failed to decompress")
|
||||
preBeaconStateBase := &pb.BeaconState{}
|
||||
require.NoError(t, preBeaconStateBase.UnmarshalSSZ(preBeaconStateFile), "Failed to unmarshal")
|
||||
require.NoError(t, preBeaconStateBase.UnmarshalSSZ(preBeaconStateSSZ), "Failed to unmarshal")
|
||||
preBeaconState, err := stateV0.InitializeFromProto(preBeaconStateBase)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -69,11 +90,10 @@ func runPrecomputeRewardsAndPenaltiesTest(t *testing.T, testFolderPath string) {
|
||||
for _, dFile := range deltaFiles {
|
||||
sourceFile, err := testutil.BazelFileBytes(path.Join(testFolderPath, dFile))
|
||||
require.NoError(t, err)
|
||||
sourceSSZ, err := snappy.Decode(nil /* dst */, sourceFile)
|
||||
require.NoError(t, err, "Failed to decompress")
|
||||
d := &Delta{}
|
||||
err = yaml.Unmarshal(sourceFile, &d)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
require.NoError(t, d.unmarshalSSZ(sourceSSZ), "Failed to unmarshal")
|
||||
for i, reward := range d.Rewards {
|
||||
totalSpecTestRewards[i] += reward
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package spectest
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestEffectiveBalanceUpdatesMainnet(t *testing.T) {
|
||||
runEffectiveBalanceUpdatesTests(t, "mainnet")
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package spectest
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestEffectiveBalanceUpdatesMinimal(t *testing.T) {
|
||||
runEffectiveBalanceUpdatesTests(t, "minimal")
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package spectest
|
||||
|
||||
import (
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch"
|
||||
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
|
||||
"github.com/prysmaticlabs/prysm/shared/params/spectest"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
)
|
||||
|
||||
func runEffectiveBalanceUpdatesTests(t *testing.T, config string) {
|
||||
require.NoError(t, spectest.SetConfig(t, config))
|
||||
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "phase0", "epoch_processing/effective_balance_updates/pyspec_tests")
|
||||
for _, folder := range testFolders {
|
||||
t.Run(folder.Name(), func(t *testing.T) {
|
||||
folderPath := path.Join(testsFolderPath, folder.Name())
|
||||
testutil.RunEpochOperationTest(t, folderPath, processEffectiveBalanceUpdatesWrapper)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func processEffectiveBalanceUpdatesWrapper(t *testing.T, state iface.BeaconState) (iface.BeaconState, error) {
|
||||
state, err := epoch.ProcessEffectiveBalanceUpdates(state)
|
||||
require.NoError(t, err, "Could not process final updates")
|
||||
return state, nil
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package spectest
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestEth1DataResetMainnet(t *testing.T) {
|
||||
runEth1DataResetTests(t, "mainnet")
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package spectest
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestEth1DataResetMinimal(t *testing.T) {
|
||||
runEth1DataResetTests(t, "minimal")
|
||||
}
|
||||
@@ -11,20 +11,20 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
)
|
||||
|
||||
func runFinalUpdatesTests(t *testing.T, config string) {
|
||||
func runEth1DataResetTests(t *testing.T, config string) {
|
||||
require.NoError(t, spectest.SetConfig(t, config))
|
||||
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "epoch_processing/final_updates/pyspec_tests")
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "phase0", "epoch_processing/eth1_data_reset/pyspec_tests")
|
||||
for _, folder := range testFolders {
|
||||
t.Run(folder.Name(), func(t *testing.T) {
|
||||
folderPath := path.Join(testsFolderPath, folder.Name())
|
||||
testutil.RunEpochOperationTest(t, folderPath, processFinalUpdatesWrapper)
|
||||
testutil.RunEpochOperationTest(t, folderPath, processEth1DataResetWrapper)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func processFinalUpdatesWrapper(t *testing.T, state iface.BeaconState) (iface.BeaconState, error) {
|
||||
state, err := epoch.ProcessFinalUpdates(state)
|
||||
func processEth1DataResetWrapper(t *testing.T, state iface.BeaconState) (iface.BeaconState, error) {
|
||||
state, err := epoch.ProcessEth1DataReset(state)
|
||||
require.NoError(t, err, "Could not process final updates")
|
||||
return state, nil
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package spectest
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFinalUpdatesMainnet(t *testing.T) {
|
||||
runFinalUpdatesTests(t, "mainnet")
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package spectest
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFinalUpdatesMinimal(t *testing.T) {
|
||||
runFinalUpdatesTests(t, "minimal")
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package spectest
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestHistoricalRootsUpdateMainnet(t *testing.T) {
|
||||
runHistoricalRootsUpdateTests(t, "mainnet")
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package spectest
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestHistoricalRootsUpdateMinimal(t *testing.T) {
|
||||
runHistoricalRootsUpdateTests(t, "minimal")
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package spectest
|
||||
|
||||
import (
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch"
|
||||
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
|
||||
"github.com/prysmaticlabs/prysm/shared/params/spectest"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
)
|
||||
|
||||
func runHistoricalRootsUpdateTests(t *testing.T, config string) {
|
||||
require.NoError(t, spectest.SetConfig(t, config))
|
||||
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "phase0", "epoch_processing/historical_roots_update/pyspec_tests")
|
||||
for _, folder := range testFolders {
|
||||
t.Run(folder.Name(), func(t *testing.T) {
|
||||
folderPath := path.Join(testsFolderPath, folder.Name())
|
||||
testutil.RunEpochOperationTest(t, folderPath, processHistoricalRootsUpdateWrapper)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func processHistoricalRootsUpdateWrapper(t *testing.T, state iface.BeaconState) (iface.BeaconState, error) {
|
||||
state, err := epoch.ProcessHistoricalRootsUpdate(state)
|
||||
require.NoError(t, err, "Could not process final updates")
|
||||
return state, nil
|
||||
}
|
||||
@@ -16,7 +16,7 @@ func runJustificationAndFinalizationTests(t *testing.T, config string) {
|
||||
require.NoError(t, spectest.SetConfig(t, config))
|
||||
|
||||
testPath := "epoch_processing/justification_and_finalization/pyspec_tests"
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, testPath)
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "phase0", testPath)
|
||||
for _, folder := range testFolders {
|
||||
t.Run(folder.Name(), func(t *testing.T) {
|
||||
folderPath := path.Join(testsFolderPath, folder.Name())
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package spectest
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestParticipationRecordUpdatesMainnet(t *testing.T) {
|
||||
runParticipationRecordUpdatesTests(t, "mainnet")
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package spectest
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestParticipationRecordUpdatesMinimal(t *testing.T) {
|
||||
runParticipationRecordUpdatesTests(t, "minimal")
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package spectest
|
||||
|
||||
import (
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch"
|
||||
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
|
||||
"github.com/prysmaticlabs/prysm/shared/params/spectest"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
)
|
||||
|
||||
func runParticipationRecordUpdatesTests(t *testing.T, config string) {
|
||||
require.NoError(t, spectest.SetConfig(t, config))
|
||||
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "phase0", "epoch_processing/participation_record_updates/pyspec_tests")
|
||||
for _, folder := range testFolders {
|
||||
t.Run(folder.Name(), func(t *testing.T) {
|
||||
folderPath := path.Join(testsFolderPath, folder.Name())
|
||||
testutil.RunEpochOperationTest(t, folderPath, processParticipationRecordUpdatesWrapper)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func processParticipationRecordUpdatesWrapper(t *testing.T, state iface.BeaconState) (iface.BeaconState, error) {
|
||||
state, err := epoch.ProcessParticipationRecordUpdates(state)
|
||||
require.NoError(t, err, "Could not process final updates")
|
||||
return state, nil
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package spectest
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestRandaoMixesResetMainnet(t *testing.T) {
|
||||
runRandaoMixesResetTests(t, "mainnet")
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package spectest
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestRandaoMixesResetMinimal(t *testing.T) {
|
||||
runRandaoMixesResetTests(t, "minimal")
|
||||
}
|
||||
30
beacon-chain/core/epoch/spectest/randao_mixes_reset_test.go
Normal file
30
beacon-chain/core/epoch/spectest/randao_mixes_reset_test.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package spectest
|
||||
|
||||
import (
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch"
|
||||
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
|
||||
"github.com/prysmaticlabs/prysm/shared/params/spectest"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
)
|
||||
|
||||
func runRandaoMixesResetTests(t *testing.T, config string) {
|
||||
require.NoError(t, spectest.SetConfig(t, config))
|
||||
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "phase0", "epoch_processing/randao_mixes_reset/pyspec_tests")
|
||||
for _, folder := range testFolders {
|
||||
t.Run(folder.Name(), func(t *testing.T) {
|
||||
folderPath := path.Join(testsFolderPath, folder.Name())
|
||||
testutil.RunEpochOperationTest(t, folderPath, processRandaoMixesResetWrapper)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func processRandaoMixesResetWrapper(t *testing.T, state iface.BeaconState) (iface.BeaconState, error) {
|
||||
state, err := epoch.ProcessRandaoMixesReset(state)
|
||||
require.NoError(t, err, "Could not process final updates")
|
||||
return state, nil
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
func runRegistryUpdatesTests(t *testing.T, config string) {
|
||||
require.NoError(t, spectest.SetConfig(t, config))
|
||||
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "epoch_processing/registry_updates/pyspec_tests")
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "phase0", "epoch_processing/registry_updates/pyspec_tests")
|
||||
for _, folder := range testFolders {
|
||||
t.Run(folder.Name(), func(t *testing.T) {
|
||||
folderPath := path.Join(testsFolderPath, folder.Name())
|
||||
|
||||
@@ -17,7 +17,7 @@ func runRewardsAndPenaltiesTests(t *testing.T, config string) {
|
||||
require.NoError(t, spectest.SetConfig(t, config))
|
||||
|
||||
testPath := "epoch_processing/rewards_and_penalties/pyspec_tests"
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, testPath)
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "phase0", testPath)
|
||||
for _, folder := range testFolders {
|
||||
helpers.ClearCache()
|
||||
t.Run(folder.Name(), func(t *testing.T) {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package spectest
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSlashingsResetMainnet(t *testing.T) {
|
||||
runSlashingsResetTests(t, "mainnet")
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package spectest
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSlashingsResetMinimal(t *testing.T) {
|
||||
runSlashingsResetTests(t, "minimal")
|
||||
}
|
||||
30
beacon-chain/core/epoch/spectest/slashings_reset_test.go
Normal file
30
beacon-chain/core/epoch/spectest/slashings_reset_test.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package spectest
|
||||
|
||||
import (
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch"
|
||||
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
|
||||
"github.com/prysmaticlabs/prysm/shared/params/spectest"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
)
|
||||
|
||||
func runSlashingsResetTests(t *testing.T, config string) {
|
||||
require.NoError(t, spectest.SetConfig(t, config))
|
||||
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "phase0", "epoch_processing/slashings_reset/pyspec_tests")
|
||||
for _, folder := range testFolders {
|
||||
t.Run(folder.Name(), func(t *testing.T) {
|
||||
folderPath := path.Join(testsFolderPath, folder.Name())
|
||||
testutil.RunEpochOperationTest(t, folderPath, processSlashingsResetWrapper)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func processSlashingsResetWrapper(t *testing.T, state iface.BeaconState) (iface.BeaconState, error) {
|
||||
state, err := epoch.ProcessSlashingsReset(state)
|
||||
require.NoError(t, err, "Could not process final updates")
|
||||
return state, nil
|
||||
}
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
func runSlashingsTests(t *testing.T, config string) {
|
||||
require.NoError(t, spectest.SetConfig(t, config))
|
||||
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "epoch_processing/slashings/pyspec_tests")
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "phase0", "epoch_processing/slashings/pyspec_tests")
|
||||
for _, folder := range testFolders {
|
||||
t.Run(folder.Name(), func(t *testing.T) {
|
||||
folderPath := path.Join(testsFolderPath, folder.Name())
|
||||
|
||||
@@ -27,7 +27,7 @@ func TestShufflingMainnet(t *testing.T) {
|
||||
func runShuffleTests(t *testing.T, config string) {
|
||||
require.NoError(t, spectest.SetConfig(t, config))
|
||||
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "shuffling/core/shuffle")
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "phase0", "shuffling/core/shuffle")
|
||||
for _, folder := range testFolders {
|
||||
t.Run(folder.Name(), func(t *testing.T) {
|
||||
testCaseFile, err := testutil.BazelFileBytes(path.Join(testsFolderPath, folder.Name(), "mapping.yaml"))
|
||||
|
||||
@@ -33,6 +33,7 @@ go_test(
|
||||
"//shared/testutil:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"@com_github_gogo_protobuf//proto:go_default_library",
|
||||
"@com_github_golang_snappy//:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@com_github_urfave_cli_v2//:go_default_library",
|
||||
"@in_gopkg_d4l3k_messagediff_v1//:go_default_library",
|
||||
@@ -67,6 +68,7 @@ go_test(
|
||||
"//shared/testutil:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"@com_github_gogo_protobuf//proto:go_default_library",
|
||||
"@com_github_golang_snappy//:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@com_github_urfave_cli_v2//:go_default_library",
|
||||
"@in_gopkg_d4l3k_messagediff_v1//:go_default_library",
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/golang/snappy"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateV0"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
@@ -22,14 +23,16 @@ func init() {
|
||||
func runSlotProcessingTests(t *testing.T, config string) {
|
||||
require.NoError(t, spectest.SetConfig(t, config))
|
||||
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "sanity/slots/pyspec_tests")
|
||||
testFolders, testsFolderPath := testutil.TestFolders(t, config, "phase0", "sanity/slots/pyspec_tests")
|
||||
|
||||
for _, folder := range testFolders {
|
||||
t.Run(folder.Name(), func(t *testing.T) {
|
||||
preBeaconStateFile, err := testutil.BazelFileBytes(testsFolderPath, folder.Name(), "pre.ssz")
|
||||
preBeaconStateFile, err := testutil.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")
|
||||
base := &pb.BeaconState{}
|
||||
require.NoError(t, base.UnmarshalSSZ(preBeaconStateFile), "Failed to unmarshal")
|
||||
require.NoError(t, base.UnmarshalSSZ(preBeaconStateSSZ), "Failed to unmarshal")
|
||||
beaconState, err := stateV0.InitializeFromProto(base)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -39,10 +42,12 @@ func runSlotProcessingTests(t *testing.T, config string) {
|
||||
slotsCount, err := strconv.Atoi(fileStr[:len(fileStr)-5])
|
||||
require.NoError(t, err)
|
||||
|
||||
postBeaconStateFile, err := testutil.BazelFileBytes(testsFolderPath, folder.Name(), "post.ssz")
|
||||
postBeaconStateFile, err := testutil.BazelFileBytes(testsFolderPath, folder.Name(), "post.ssz_snappy")
|
||||
require.NoError(t, err)
|
||||
postBeaconStateSSZ, err := snappy.Decode(nil /* dst */, postBeaconStateFile)
|
||||
require.NoError(t, err, "Failed to decompress")
|
||||
postBeaconState := &pb.BeaconState{}
|
||||
require.NoError(t, postBeaconState.UnmarshalSSZ(postBeaconStateFile), "Failed to unmarshal")
|
||||
require.NoError(t, postBeaconState.UnmarshalSSZ(postBeaconStateSSZ), "Failed to unmarshal")
|
||||
postState, err := state.ProcessSlots(context.Background(), beaconState, beaconState.Slot().Add(uint64(slotsCount)))
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ go_test(
|
||||
"//shared/testutil:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"@com_github_golang_snappy//:go_default_library",
|
||||
"@com_github_ferranbt_fastssz//:go_default_library",
|
||||
"@com_github_ghodss_yaml//:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
@@ -88,6 +89,7 @@ go_test(
|
||||
"//shared/testutil:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"@com_github_golang_snappy//:go_default_library",
|
||||
"@com_github_ferranbt_fastssz//:go_default_library",
|
||||
"@com_github_ghodss_yaml//:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
@@ -117,6 +119,7 @@ go_test(
|
||||
"//shared/testutil:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"@com_github_golang_snappy//:go_default_library",
|
||||
"@com_github_ferranbt_fastssz//:go_default_library",
|
||||
"@com_github_ghodss_yaml//:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"testing"
|
||||
|
||||
fssz "github.com/ferranbt/fastssz"
|
||||
"github.com/golang/snappy"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateV0"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
@@ -25,16 +26,18 @@ type SSZRoots struct {
|
||||
func runSSZStaticTests(t *testing.T, config string) {
|
||||
require.NoError(t, spectest.SetConfig(t, config))
|
||||
|
||||
testFolders, _ := testutil.TestFolders(t, config, "ssz_static")
|
||||
testFolders, _ := testutil.TestFolders(t, config, "phase0", "ssz_static")
|
||||
for _, folder := range testFolders {
|
||||
innerPath := path.Join("ssz_static", folder.Name(), "ssz_random")
|
||||
innerTestFolders, innerTestsFolderPath := testutil.TestFolders(t, config, innerPath)
|
||||
innerTestFolders, innerTestsFolderPath := testutil.TestFolders(t, config, "phase0", innerPath)
|
||||
|
||||
for _, innerFolder := range innerTestFolders {
|
||||
t.Run(path.Join(folder.Name(), innerFolder.Name()), func(t *testing.T) {
|
||||
serializedBytes, err := testutil.BazelFileBytes(innerTestsFolderPath, innerFolder.Name(), "serialized.ssz")
|
||||
serializedBytes, err := testutil.BazelFileBytes(innerTestsFolderPath, innerFolder.Name(), "serialized.ssz_snappy")
|
||||
require.NoError(t, err)
|
||||
object, err := UnmarshalledSSZ(t, serializedBytes, folder.Name())
|
||||
serializedSSZ, err := snappy.Decode(nil /* dst */, serializedBytes)
|
||||
require.NoError(t, err, "Failed to decompress")
|
||||
object, err := UnmarshalledSSZ(t, serializedSSZ, folder.Name())
|
||||
require.NoError(t, err, "Could not unmarshall serialized SSZ")
|
||||
|
||||
rootsYamlFile, err := testutil.BazelFileBytes(innerTestsFolderPath, innerFolder.Name(), "roots.yaml")
|
||||
|
||||
@@ -18,7 +18,7 @@ func TestAggregateYaml(t *testing.T) {
|
||||
}
|
||||
|
||||
func testAggregateYaml(t *testing.T) {
|
||||
testFolders, testFolderPath := testutil.TestFolders(t, "general", "bls/aggregate/small")
|
||||
testFolders, testFolderPath := testutil.TestFolders(t, "general", "phase0", "bls/aggregate/small")
|
||||
|
||||
for _, folder := range testFolders {
|
||||
t.Run(folder.Name(), func(t *testing.T) {
|
||||
|
||||
@@ -19,7 +19,7 @@ func TestAggregateVerifyYaml(t *testing.T) {
|
||||
}
|
||||
|
||||
func testAggregateVerifyYaml(t *testing.T) {
|
||||
testFolders, testFolderPath := testutil.TestFolders(t, "general", "bls/aggregate_verify/small")
|
||||
testFolders, testFolderPath := testutil.TestFolders(t, "general", "phase0", "bls/aggregate_verify/small")
|
||||
|
||||
for i, folder := range testFolders {
|
||||
t.Run(folder.Name(), func(t *testing.T) {
|
||||
|
||||
@@ -19,7 +19,7 @@ func TestFastAggregateVerifyYaml(t *testing.T) {
|
||||
}
|
||||
|
||||
func testFastAggregateVerifyYaml(t *testing.T) {
|
||||
testFolders, testFolderPath := testutil.TestFolders(t, "general", "bls/fast_aggregate_verify/small")
|
||||
testFolders, testFolderPath := testutil.TestFolders(t, "general", "phase0", "bls/fast_aggregate_verify/small")
|
||||
|
||||
for i, folder := range testFolders {
|
||||
t.Run(folder.Name(), func(t *testing.T) {
|
||||
|
||||
@@ -21,7 +21,7 @@ func TestSignMessageYaml(t *testing.T) {
|
||||
}
|
||||
|
||||
func testSignMessageYaml(t *testing.T) {
|
||||
testFolders, testFolderPath := testutil.TestFolders(t, "general", "bls/sign/small")
|
||||
testFolders, testFolderPath := testutil.TestFolders(t, "general", "phase0", "bls/sign/small")
|
||||
|
||||
for i, folder := range testFolders {
|
||||
t.Run(folder.Name(), func(t *testing.T) {
|
||||
|
||||
@@ -18,7 +18,7 @@ func TestVerifyMessageYaml(t *testing.T) {
|
||||
}
|
||||
|
||||
func testVerifyMessageYaml(t *testing.T) {
|
||||
testFolders, testFolderPath := testutil.TestFolders(t, "general", "bls/verify/small")
|
||||
testFolders, testFolderPath := testutil.TestFolders(t, "general", "phase0", "bls/verify/small")
|
||||
|
||||
for i, folder := range testFolders {
|
||||
t.Run(folder.Name(), func(t *testing.T) {
|
||||
|
||||
@@ -32,6 +32,7 @@ go_library(
|
||||
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
|
||||
"@com_github_ghodss_yaml//:go_default_library",
|
||||
"@com_github_gogo_protobuf//proto:go_default_library",
|
||||
"@com_github_golang_snappy//:go_default_library",
|
||||
"@com_github_json_iterator_go//:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_prysmaticlabs_eth2_types//:go_default_library",
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/bazelbuild/rules_go/go/tools/bazel"
|
||||
"github.com/ghodss/yaml"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/golang/snappy"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
@@ -43,8 +44,8 @@ func UnmarshalYaml(y []byte, dest interface{}) error {
|
||||
|
||||
// TestFolders sets the proper config and returns the result of ReadDir
|
||||
// on the passed in eth2-spec-tests directory along with its path.
|
||||
func TestFolders(t testing.TB, config, folderPath string) ([]os.FileInfo, string) {
|
||||
testsFolderPath := path.Join("tests", config, "phase0", folderPath)
|
||||
func TestFolders(t testing.TB, config, forkOrPhase, folderPath string) ([]os.FileInfo, string) {
|
||||
testsFolderPath := path.Join("tests", config, forkOrPhase, folderPath)
|
||||
filepath, err := bazel.Runfile(testsFolderPath)
|
||||
require.NoError(t, err)
|
||||
testFolders, err := ioutil.ReadDir(filepath)
|
||||
@@ -87,17 +88,19 @@ func RunBlockOperationTest(
|
||||
body *ethpb.BeaconBlockBody,
|
||||
operationFn blockOperation,
|
||||
) {
|
||||
preBeaconStateFile, err := BazelFileBytes(path.Join(folderPath, "pre.ssz"))
|
||||
preBeaconStateFile, err := BazelFileBytes(path.Join(folderPath, "pre.ssz_snappy"))
|
||||
require.NoError(t, err)
|
||||
preBeaconStateSSZ, err := snappy.Decode(nil /* dst */, preBeaconStateFile)
|
||||
require.NoError(t, err, "Failed to decompress")
|
||||
preStateBase := &pb.BeaconState{}
|
||||
if err := preStateBase.UnmarshalSSZ(preBeaconStateFile); err != nil {
|
||||
if err := preStateBase.UnmarshalSSZ(preBeaconStateSSZ); err != nil {
|
||||
t.Fatalf("Failed to unmarshal: %v", err)
|
||||
}
|
||||
preState, err := stateV0.InitializeFromProto(preStateBase)
|
||||
require.NoError(t, err)
|
||||
|
||||
// If the post.ssz is not present, it means the test should fail on our end.
|
||||
postSSZFilepath, err := bazel.Runfile(path.Join(folderPath, "post.ssz"))
|
||||
postSSZFilepath, err := bazel.Runfile(path.Join(folderPath, "post.ssz_snappy"))
|
||||
postSSZExists := true
|
||||
if err != nil && strings.Contains(err.Error(), "could not locate file") {
|
||||
postSSZExists = false
|
||||
@@ -114,9 +117,11 @@ func RunBlockOperationTest(
|
||||
|
||||
postBeaconStateFile, err := ioutil.ReadFile(postSSZFilepath)
|
||||
require.NoError(t, err)
|
||||
postBeaconStateSSZ, err := snappy.Decode(nil /* dst */, postBeaconStateFile)
|
||||
require.NoError(t, err, "Failed to decompress")
|
||||
|
||||
postBeaconState := &pb.BeaconState{}
|
||||
if err := postBeaconState.UnmarshalSSZ(postBeaconStateFile); err != nil {
|
||||
if err := postBeaconState.UnmarshalSSZ(postBeaconStateSSZ); err != nil {
|
||||
t.Fatalf("Failed to unmarshal: %v", err)
|
||||
}
|
||||
pbState, err := stateV0.ProtobufBeaconState(beaconState.InnerStateUnsafe())
|
||||
@@ -144,17 +149,19 @@ func RunEpochOperationTest(
|
||||
testFolderPath string,
|
||||
operationFn epochOperation,
|
||||
) {
|
||||
preBeaconStateFile, err := BazelFileBytes(path.Join(testFolderPath, "pre.ssz"))
|
||||
preBeaconStateFile, err := BazelFileBytes(path.Join(testFolderPath, "pre.ssz_snappy"))
|
||||
require.NoError(t, err)
|
||||
preBeaconStateSSZ, err := snappy.Decode(nil /* dst */, preBeaconStateFile)
|
||||
require.NoError(t, err, "Failed to decompress")
|
||||
preBeaconStateBase := &pb.BeaconState{}
|
||||
if err := preBeaconStateBase.UnmarshalSSZ(preBeaconStateFile); err != nil {
|
||||
if err := preBeaconStateBase.UnmarshalSSZ(preBeaconStateSSZ); err != nil {
|
||||
t.Fatalf("Failed to unmarshal: %v", err)
|
||||
}
|
||||
preBeaconState, err := stateV0.InitializeFromProto(preBeaconStateBase)
|
||||
require.NoError(t, err)
|
||||
|
||||
// If the post.ssz is not present, it means the test should fail on our end.
|
||||
postSSZFilepath, err := bazel.Runfile(path.Join(testFolderPath, "post.ssz"))
|
||||
postSSZFilepath, err := bazel.Runfile(path.Join(testFolderPath, "post.ssz_snappy"))
|
||||
postSSZExists := true
|
||||
if err != nil && strings.Contains(err.Error(), "could not locate file") {
|
||||
postSSZExists = false
|
||||
@@ -168,8 +175,10 @@ func RunEpochOperationTest(
|
||||
|
||||
postBeaconStateFile, err := ioutil.ReadFile(postSSZFilepath)
|
||||
require.NoError(t, err)
|
||||
postBeaconStateSSZ, err := snappy.Decode(nil /* dst */, postBeaconStateFile)
|
||||
require.NoError(t, err, "Failed to decompress")
|
||||
postBeaconState := &pb.BeaconState{}
|
||||
if err := postBeaconState.UnmarshalSSZ(postBeaconStateFile); err != nil {
|
||||
if err := postBeaconState.UnmarshalSSZ(postBeaconStateSSZ); err != nil {
|
||||
t.Fatalf("Failed to unmarshal: %v", err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user