From 8c8fe7ad7e8b16cc4478ccc522016ba2138db021 Mon Sep 17 00:00:00 2001 From: terence tsao Date: Fri, 9 Jun 2023 09:04:34 -0700 Subject: [PATCH 1/4] test(spec): add deneb spec tests --- WORKSPACE | 10 +- config/params/loader_test.go | 2 +- .../deneb/epoch_processing/BUILD.bazel | 25 ++++ .../effective_balance_updates_test.go | 11 ++ .../epoch_processing/eth1_data_reset_test.go | 11 ++ .../historical_summaries_update_test.go | 11 ++ .../inactivity_updates_test.go | 11 ++ .../justification_and_finalization_test.go | 11 ++ .../participation_flag_updates_test.go | 11 ++ .../randao_mixes_reset_test.go | 11 ++ .../epoch_processing/registry_updates_test.go | 11 ++ .../rewards_and_penalties_test.go | 11 ++ .../epoch_processing/slashings_reset_test.go | 11 ++ .../deneb/epoch_processing/slashings_test.go | 11 ++ .../mainnet/deneb/finality/BUILD.bazel | 14 ++ .../mainnet/deneb/finality/finality_test.go | 11 ++ .../mainnet/deneb/fork_helper/BUILD.bazel | 5 +- .../fork_helper/upgrade_to_capella_test.go | 11 ++ .../mainnet/deneb/fork_transition/BUILD.bazel | 12 ++ .../deneb/fork_transition/transition_test.go | 11 ++ .../mainnet/deneb/forkchoice/BUILD.bazel | 16 +++ .../deneb/forkchoice/forkchoice_test.go | 12 ++ .../mainnet/deneb/operations/BUILD.bazel | 21 +++ .../deneb/operations/attestation_test.go | 11 ++ .../operations/attester_slashing_test.go | 11 ++ .../deneb/operations/block_header_test.go | 11 ++ .../mainnet/deneb/operations/deposit_test.go | 11 ++ .../operations/proposer_slashing_test.go | 11 ++ .../deneb/operations/sync_committee_test.go | 11 ++ .../deneb/operations/voluntary_exit_test.go | 11 ++ .../mainnet/deneb/rewards/BUILD.bazel | 12 ++ .../mainnet/deneb/rewards/rewards_test.go | 11 ++ .../spectest/mainnet/deneb/sanity/BUILD.bazel | 16 +++ .../mainnet/deneb/sanity/blocks_test.go | 11 ++ .../mainnet/deneb/sanity/slots_test.go | 11 ++ .../deneb/epoch_processing/BUILD.bazel | 28 ++++ .../effective_balance_updates_test.go | 11 ++ .../epoch_processing/eth1_data_reset_test.go | 11 ++ .../historical_summaries_update_test.go | 11 ++ .../inactivity_updates_test.go | 11 ++ .../justification_and_finalization_test.go | 11 ++ .../participation_flag_updates_test.go | 11 ++ .../randao_mixes_reset_test.go | 11 ++ .../epoch_processing/registry_updates_test.go | 11 ++ .../rewards_and_penalties_test.go | 11 ++ .../epoch_processing/slashings_reset_test.go | 11 ++ .../deneb/epoch_processing/slashings_test.go | 11 ++ .../minimal/deneb/finality/BUILD.bazel | 17 +++ .../minimal/deneb/finality/finality_test.go | 11 ++ .../spectest/minimal/deneb/fork/BUILD.bazel | 5 +- .../deneb/fork/upgrade_to_capella_test.go | 11 ++ .../minimal/deneb/forkchoice/BUILD.bazel | 20 +++ .../deneb/forkchoice/forkchoice_test.go | 12 ++ .../minimal/deneb/operations/BUILD.bazel | 26 ++++ .../deneb/operations/attestation_test.go | 11 ++ .../operations/attester_slashing_test.go | 11 ++ .../deneb/operations/block_header_test.go | 11 ++ .../bls_to_execution_change_test.go | 11 ++ .../minimal/deneb/operations/deposit_test.go | 11 ++ .../operations/proposer_slashing_test.go | 11 ++ .../deneb/operations/sync_committee_test.go | 11 ++ .../deneb/operations/voluntary_exit_test.go | 11 ++ .../deneb/operations/withdrawals_test.go | 11 ++ .../minimal/deneb/rewards/BUILD.bazel | 16 +++ .../minimal/deneb/rewards/rewards_test.go | 11 ++ .../spectest/minimal/deneb/sanity/BUILD.bazel | 19 +++ .../minimal/deneb/sanity/blocks_test.go | 11 ++ .../minimal/deneb/sanity/slots_test.go | 11 ++ .../shared/common/forkchoice/runner.go | 29 ++++ .../shared/common/forkchoice/service.go | 14 +- .../shared/deneb/epoch_processing/BUILD.bazel | 38 ++++++ .../effective_balance_updates.go | 30 +++++ .../deneb/epoch_processing/eth1_data_reset.go | 30 +++++ .../shared/deneb/epoch_processing/helpers.go | 75 +++++++++++ .../historical_summaries_update.go | 30 +++++ .../epoch_processing/inactivity_updates.go | 41 ++++++ .../justification_and_finalization.go | 40 ++++++ .../participation_flag_updates.go | 30 +++++ .../epoch_processing/randao_mixes_reset.go | 30 +++++ .../epoch_processing/registry_updates.go | 32 +++++ .../epoch_processing/rewards_and_penalties.go | 41 ++++++ .../deneb/epoch_processing/slashings.go | 33 +++++ .../deneb/epoch_processing/slashings_reset.go | 30 +++++ .../shared/deneb/finality/BUILD.bazel | 22 +++ .../shared/deneb/finality/finality.go | 83 ++++++++++++ .../spectest/shared/deneb/fork/BUILD.bazel | 10 +- .../spectest/shared/deneb/fork/transition.go | 125 +++++++++++++++++ .../shared/deneb/fork/upgrade_to_capella.go | 63 +++++++++ .../shared/deneb/operations/BUILD.bazel | 39 ++++++ .../shared/deneb/operations/attestation.go | 56 ++++++++ .../deneb/operations/attester_slashing.go | 38 ++++++ .../shared/deneb/operations/block_header.go | 83 ++++++++++++ .../operations/bls_to_execution_changes.go | 62 +++++++++ .../shared/deneb/operations/deposit.go | 38 ++++++ .../shared/deneb/operations/helpers.go | 85 ++++++++++++ .../deneb/operations/proposer_slashing.go | 38 ++++++ .../shared/deneb/operations/sync_committee.go | 41 ++++++ .../shared/deneb/operations/voluntary_exit.go | 37 +++++ .../shared/deneb/operations/withdrawals.go | 49 +++++++ .../spectest/shared/deneb/rewards/BUILD.bazel | 19 +++ .../shared/deneb/rewards/rewards_penalties.go | 126 ++++++++++++++++++ .../spectest/shared/deneb/sanity/BUILD.bazel | 27 ++++ .../shared/deneb/sanity/block_processing.go | 110 +++++++++++++++ .../deneb/sanity/block_processing.yaml.go | 6 + .../shared/deneb/sanity/slot_processing.go | 61 +++++++++ .../shared/deneb/ssz_static/ssz_static.go | 19 ++- 106 files changed, 2568 insertions(+), 19 deletions(-) create mode 100644 testing/spectest/mainnet/deneb/epoch_processing/BUILD.bazel create mode 100644 testing/spectest/mainnet/deneb/epoch_processing/effective_balance_updates_test.go create mode 100644 testing/spectest/mainnet/deneb/epoch_processing/eth1_data_reset_test.go create mode 100644 testing/spectest/mainnet/deneb/epoch_processing/historical_summaries_update_test.go create mode 100644 testing/spectest/mainnet/deneb/epoch_processing/inactivity_updates_test.go create mode 100644 testing/spectest/mainnet/deneb/epoch_processing/justification_and_finalization_test.go create mode 100644 testing/spectest/mainnet/deneb/epoch_processing/participation_flag_updates_test.go create mode 100644 testing/spectest/mainnet/deneb/epoch_processing/randao_mixes_reset_test.go create mode 100644 testing/spectest/mainnet/deneb/epoch_processing/registry_updates_test.go create mode 100644 testing/spectest/mainnet/deneb/epoch_processing/rewards_and_penalties_test.go create mode 100644 testing/spectest/mainnet/deneb/epoch_processing/slashings_reset_test.go create mode 100644 testing/spectest/mainnet/deneb/epoch_processing/slashings_test.go create mode 100644 testing/spectest/mainnet/deneb/finality/BUILD.bazel create mode 100644 testing/spectest/mainnet/deneb/finality/finality_test.go create mode 100644 testing/spectest/mainnet/deneb/fork_helper/upgrade_to_capella_test.go create mode 100644 testing/spectest/mainnet/deneb/fork_transition/BUILD.bazel create mode 100644 testing/spectest/mainnet/deneb/fork_transition/transition_test.go create mode 100644 testing/spectest/mainnet/deneb/forkchoice/BUILD.bazel create mode 100644 testing/spectest/mainnet/deneb/forkchoice/forkchoice_test.go create mode 100644 testing/spectest/mainnet/deneb/operations/BUILD.bazel create mode 100644 testing/spectest/mainnet/deneb/operations/attestation_test.go create mode 100644 testing/spectest/mainnet/deneb/operations/attester_slashing_test.go create mode 100644 testing/spectest/mainnet/deneb/operations/block_header_test.go create mode 100644 testing/spectest/mainnet/deneb/operations/deposit_test.go create mode 100644 testing/spectest/mainnet/deneb/operations/proposer_slashing_test.go create mode 100644 testing/spectest/mainnet/deneb/operations/sync_committee_test.go create mode 100644 testing/spectest/mainnet/deneb/operations/voluntary_exit_test.go create mode 100644 testing/spectest/mainnet/deneb/rewards/BUILD.bazel create mode 100644 testing/spectest/mainnet/deneb/rewards/rewards_test.go create mode 100644 testing/spectest/mainnet/deneb/sanity/BUILD.bazel create mode 100644 testing/spectest/mainnet/deneb/sanity/blocks_test.go create mode 100644 testing/spectest/mainnet/deneb/sanity/slots_test.go create mode 100644 testing/spectest/minimal/deneb/epoch_processing/BUILD.bazel create mode 100644 testing/spectest/minimal/deneb/epoch_processing/effective_balance_updates_test.go create mode 100644 testing/spectest/minimal/deneb/epoch_processing/eth1_data_reset_test.go create mode 100644 testing/spectest/minimal/deneb/epoch_processing/historical_summaries_update_test.go create mode 100644 testing/spectest/minimal/deneb/epoch_processing/inactivity_updates_test.go create mode 100644 testing/spectest/minimal/deneb/epoch_processing/justification_and_finalization_test.go create mode 100644 testing/spectest/minimal/deneb/epoch_processing/participation_flag_updates_test.go create mode 100644 testing/spectest/minimal/deneb/epoch_processing/randao_mixes_reset_test.go create mode 100644 testing/spectest/minimal/deneb/epoch_processing/registry_updates_test.go create mode 100644 testing/spectest/minimal/deneb/epoch_processing/rewards_and_penalties_test.go create mode 100644 testing/spectest/minimal/deneb/epoch_processing/slashings_reset_test.go create mode 100644 testing/spectest/minimal/deneb/epoch_processing/slashings_test.go create mode 100644 testing/spectest/minimal/deneb/finality/BUILD.bazel create mode 100644 testing/spectest/minimal/deneb/finality/finality_test.go create mode 100644 testing/spectest/minimal/deneb/fork/upgrade_to_capella_test.go create mode 100644 testing/spectest/minimal/deneb/forkchoice/BUILD.bazel create mode 100644 testing/spectest/minimal/deneb/forkchoice/forkchoice_test.go create mode 100644 testing/spectest/minimal/deneb/operations/BUILD.bazel create mode 100644 testing/spectest/minimal/deneb/operations/attestation_test.go create mode 100644 testing/spectest/minimal/deneb/operations/attester_slashing_test.go create mode 100644 testing/spectest/minimal/deneb/operations/block_header_test.go create mode 100644 testing/spectest/minimal/deneb/operations/bls_to_execution_change_test.go create mode 100644 testing/spectest/minimal/deneb/operations/deposit_test.go create mode 100644 testing/spectest/minimal/deneb/operations/proposer_slashing_test.go create mode 100644 testing/spectest/minimal/deneb/operations/sync_committee_test.go create mode 100644 testing/spectest/minimal/deneb/operations/voluntary_exit_test.go create mode 100644 testing/spectest/minimal/deneb/operations/withdrawals_test.go create mode 100644 testing/spectest/minimal/deneb/rewards/BUILD.bazel create mode 100644 testing/spectest/minimal/deneb/rewards/rewards_test.go create mode 100644 testing/spectest/minimal/deneb/sanity/BUILD.bazel create mode 100644 testing/spectest/minimal/deneb/sanity/blocks_test.go create mode 100644 testing/spectest/minimal/deneb/sanity/slots_test.go create mode 100644 testing/spectest/shared/deneb/epoch_processing/BUILD.bazel create mode 100644 testing/spectest/shared/deneb/epoch_processing/effective_balance_updates.go create mode 100644 testing/spectest/shared/deneb/epoch_processing/eth1_data_reset.go create mode 100644 testing/spectest/shared/deneb/epoch_processing/helpers.go create mode 100644 testing/spectest/shared/deneb/epoch_processing/historical_summaries_update.go create mode 100644 testing/spectest/shared/deneb/epoch_processing/inactivity_updates.go create mode 100644 testing/spectest/shared/deneb/epoch_processing/justification_and_finalization.go create mode 100644 testing/spectest/shared/deneb/epoch_processing/participation_flag_updates.go create mode 100644 testing/spectest/shared/deneb/epoch_processing/randao_mixes_reset.go create mode 100644 testing/spectest/shared/deneb/epoch_processing/registry_updates.go create mode 100644 testing/spectest/shared/deneb/epoch_processing/rewards_and_penalties.go create mode 100644 testing/spectest/shared/deneb/epoch_processing/slashings.go create mode 100644 testing/spectest/shared/deneb/epoch_processing/slashings_reset.go create mode 100644 testing/spectest/shared/deneb/finality/BUILD.bazel create mode 100644 testing/spectest/shared/deneb/finality/finality.go create mode 100644 testing/spectest/shared/deneb/fork/transition.go create mode 100644 testing/spectest/shared/deneb/fork/upgrade_to_capella.go create mode 100644 testing/spectest/shared/deneb/operations/BUILD.bazel create mode 100644 testing/spectest/shared/deneb/operations/attestation.go create mode 100644 testing/spectest/shared/deneb/operations/attester_slashing.go create mode 100644 testing/spectest/shared/deneb/operations/block_header.go create mode 100644 testing/spectest/shared/deneb/operations/bls_to_execution_changes.go create mode 100644 testing/spectest/shared/deneb/operations/deposit.go create mode 100644 testing/spectest/shared/deneb/operations/helpers.go create mode 100644 testing/spectest/shared/deneb/operations/proposer_slashing.go create mode 100644 testing/spectest/shared/deneb/operations/sync_committee.go create mode 100644 testing/spectest/shared/deneb/operations/voluntary_exit.go create mode 100644 testing/spectest/shared/deneb/operations/withdrawals.go create mode 100644 testing/spectest/shared/deneb/rewards/BUILD.bazel create mode 100644 testing/spectest/shared/deneb/rewards/rewards_penalties.go create mode 100644 testing/spectest/shared/deneb/sanity/BUILD.bazel create mode 100644 testing/spectest/shared/deneb/sanity/block_processing.go create mode 100644 testing/spectest/shared/deneb/sanity/block_processing.yaml.go create mode 100644 testing/spectest/shared/deneb/sanity/slot_processing.go diff --git a/WORKSPACE b/WORKSPACE index a5c599340041..2f0e47b783e3 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -213,7 +213,7 @@ filegroup( url = "https://github.com/ethereum/EIPs/archive/5480440fe51742ed23342b68cf106cefd427e39d.tar.gz", ) -consensus_spec_version = "v1.4.0-alpha.2" +consensus_spec_version = "v1.4.0-beta.0" bls_test_version = "v0.1.1" @@ -229,7 +229,7 @@ filegroup( visibility = ["//visibility:public"], ) """, - sha256 = "bfba887cbe043907adf884cf6d18f2e8a31e34e9245397b84af1f54ed22b706a", + sha256 = "b225137494dfe4ce833abf78690b908828c63399e8f34bef5f2e258fadbf363a", url = "https://github.com/ethereum/consensus-spec-tests/releases/download/%s/general.tar.gz" % consensus_spec_version, ) @@ -245,7 +245,7 @@ filegroup( visibility = ["//visibility:public"], ) """, - sha256 = "9ff77bef0ca1e39bcee2769075c89f0f91fb8f89ad38a1b3e0c31cf6732650ad", + sha256 = "4ad95a45a635f9c2071d9a75d6e37ac15c8a6bb35e0a31ac1f1c9f3ecd34e706", url = "https://github.com/ethereum/consensus-spec-tests/releases/download/%s/minimal.tar.gz" % consensus_spec_version, ) @@ -261,7 +261,7 @@ filegroup( visibility = ["//visibility:public"], ) """, - sha256 = "fbcc3c9898110c675e5de9c27cb667ad7cadf930db7ebb5c6bba15d7be95bf8a", + sha256 = "5eeb9b7b0c882fe11ea14444cec44e9e77655f384d80b6743b1f0f82ec9a6599", url = "https://github.com/ethereum/consensus-spec-tests/releases/download/%s/mainnet.tar.gz" % consensus_spec_version, ) @@ -276,7 +276,7 @@ filegroup( visibility = ["//visibility:public"], ) """, - sha256 = "9fff1bcdd0e5857797197800db091c3675b2c11b54f704fe4de1ba683bed7ba5", + sha256 = "939c1a79a0990831d91792de622ce2a410cfc77bce8c845b5ad18e05fed64bff", strip_prefix = "consensus-specs-" + consensus_spec_version[1:], url = "https://github.com/ethereum/consensus-specs/archive/refs/tags/%s.tar.gz" % consensus_spec_version, ) diff --git a/config/params/loader_test.go b/config/params/loader_test.go index 327e424a8171..fbe894b50c73 100644 --- a/config/params/loader_test.go +++ b/config/params/loader_test.go @@ -23,7 +23,7 @@ import ( var placeholderFields = []string{"UPDATE_TIMEOUT", "ATTESTATION_SUBNET_EXTRA_BITS", "RESP_TIMEOUT", "MAX_REQUEST_BLOCKS", "EPOCHS_PER_SUBNET_SUBSCRIPTION", "EIP6110_FORK_EPOCH", "MESSAGE_DOMAIN_INVALID_SNAPPY", "MIN_EPOCHS_FOR_BLOCK_REQUESTS", "MAXIMUM_GOSSIP_CLOCK_DISPARITY", "MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS", "MESSAGE_DOMAIN_VALID_SNAPPY", "GOSSIP_MAX_SIZE", "SUBNETS_PER_NODE", "ATTESTATION_SUBNET_COUNT", "MAX_REQUEST_BLOCKS_DENEB", "MAX_REQUEST_BLOB_SIDECARS", - "MAX_CHUNK_SIZE", "ATTESTATION_PROPAGATION_SLOT_RANGE", "ATTESTATION_SUBNET_PREFIX_BITS", "EIP6110_FORK_VERSION", "TTFB_TIMEOUT"} + "MAX_CHUNK_SIZE", "ATTESTATION_PROPAGATION_SLOT_RANGE", "ATTESTATION_SUBNET_PREFIX_BITS", "EIP6110_FORK_VERSION", "TTFB_TIMEOUT", "WHISK_FORK_VERSION", "WHISK_FORK_EPOCH", "WHISK_FORK_EPOCH", "BLOB_SIDECAR_SUBNET_COUNT"} func assertEqualConfigs(t *testing.T, name string, fields []string, expected, actual *params.BeaconChainConfig) { // Misc params. diff --git a/testing/spectest/mainnet/deneb/epoch_processing/BUILD.bazel b/testing/spectest/mainnet/deneb/epoch_processing/BUILD.bazel new file mode 100644 index 000000000000..4e09c8fdc9f8 --- /dev/null +++ b/testing/spectest/mainnet/deneb/epoch_processing/BUILD.bazel @@ -0,0 +1,25 @@ +load("@prysm//tools/go:def.bzl", "go_test") + +go_test( + name = "go_default_test", + size = "small", + srcs = [ + "effective_balance_updates_test.go", + "eth1_data_reset_test.go", + "historical_summaries_update_test.go", + "inactivity_updates_test.go", + "justification_and_finalization_test.go", + "participation_flag_updates_test.go", + "randao_mixes_reset_test.go", + "registry_updates_test.go", + "rewards_and_penalties_test.go", + "slashings_reset_test.go", + "slashings_test.go", + ], + data = glob(["*.yaml"]) + [ + "@consensus_spec_tests_mainnet//:test_data", + ], + shard_count = 4, + tags = ["spectest"], + deps = ["//testing/spectest/shared/deneb/epoch_processing:go_default_library"], +) diff --git a/testing/spectest/mainnet/deneb/epoch_processing/effective_balance_updates_test.go b/testing/spectest/mainnet/deneb/epoch_processing/effective_balance_updates_test.go new file mode 100644 index 000000000000..9f9b44357394 --- /dev/null +++ b/testing/spectest/mainnet/deneb/epoch_processing/effective_balance_updates_test.go @@ -0,0 +1,11 @@ +package epoch_processing + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/epoch_processing" +) + +func TestMainnet_Deneb_EpochProcessing_EffectiveBalanceUpdates(t *testing.T) { + epoch_processing.RunEffectiveBalanceUpdatesTests(t, "mainnet") +} diff --git a/testing/spectest/mainnet/deneb/epoch_processing/eth1_data_reset_test.go b/testing/spectest/mainnet/deneb/epoch_processing/eth1_data_reset_test.go new file mode 100644 index 000000000000..1144ff84b919 --- /dev/null +++ b/testing/spectest/mainnet/deneb/epoch_processing/eth1_data_reset_test.go @@ -0,0 +1,11 @@ +package epoch_processing + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/epoch_processing" +) + +func TestMainnet_Deneb_EpochProcessing_Eth1DataReset(t *testing.T) { + epoch_processing.RunEth1DataResetTests(t, "mainnet") +} diff --git a/testing/spectest/mainnet/deneb/epoch_processing/historical_summaries_update_test.go b/testing/spectest/mainnet/deneb/epoch_processing/historical_summaries_update_test.go new file mode 100644 index 000000000000..743c1bdc3974 --- /dev/null +++ b/testing/spectest/mainnet/deneb/epoch_processing/historical_summaries_update_test.go @@ -0,0 +1,11 @@ +package epoch_processing + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/epoch_processing" +) + +func TestMainnet_Deneb_EpochProcessing_HistoricalSummariesUpdate(t *testing.T) { + epoch_processing.RunHistoricalSummariesUpdateTests(t, "mainnet") +} diff --git a/testing/spectest/mainnet/deneb/epoch_processing/inactivity_updates_test.go b/testing/spectest/mainnet/deneb/epoch_processing/inactivity_updates_test.go new file mode 100644 index 000000000000..848ff3fb8b69 --- /dev/null +++ b/testing/spectest/mainnet/deneb/epoch_processing/inactivity_updates_test.go @@ -0,0 +1,11 @@ +package epoch_processing + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/epoch_processing" +) + +func TestMainnet_Deneb_EpochProcessing_InactivityUpdates(t *testing.T) { + epoch_processing.RunInactivityUpdatesTest(t, "mainnet") +} diff --git a/testing/spectest/mainnet/deneb/epoch_processing/justification_and_finalization_test.go b/testing/spectest/mainnet/deneb/epoch_processing/justification_and_finalization_test.go new file mode 100644 index 000000000000..0f8a53789507 --- /dev/null +++ b/testing/spectest/mainnet/deneb/epoch_processing/justification_and_finalization_test.go @@ -0,0 +1,11 @@ +package epoch_processing + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/epoch_processing" +) + +func TestMainnet_Deneb_EpochProcessing_JustificationAndFinalization(t *testing.T) { + epoch_processing.RunJustificationAndFinalizationTests(t, "mainnet") +} diff --git a/testing/spectest/mainnet/deneb/epoch_processing/participation_flag_updates_test.go b/testing/spectest/mainnet/deneb/epoch_processing/participation_flag_updates_test.go new file mode 100644 index 000000000000..337117848dd1 --- /dev/null +++ b/testing/spectest/mainnet/deneb/epoch_processing/participation_flag_updates_test.go @@ -0,0 +1,11 @@ +package epoch_processing + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/epoch_processing" +) + +func TestMainnet_Deneb_EpochProcessing_ParticipationFlag(t *testing.T) { + epoch_processing.RunParticipationFlagUpdatesTests(t, "mainnet") +} diff --git a/testing/spectest/mainnet/deneb/epoch_processing/randao_mixes_reset_test.go b/testing/spectest/mainnet/deneb/epoch_processing/randao_mixes_reset_test.go new file mode 100644 index 000000000000..9f6618836ff8 --- /dev/null +++ b/testing/spectest/mainnet/deneb/epoch_processing/randao_mixes_reset_test.go @@ -0,0 +1,11 @@ +package epoch_processing + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/epoch_processing" +) + +func TestMainnet_Deneb_EpochProcessing_RandaoMixesReset(t *testing.T) { + epoch_processing.RunRandaoMixesResetTests(t, "mainnet") +} diff --git a/testing/spectest/mainnet/deneb/epoch_processing/registry_updates_test.go b/testing/spectest/mainnet/deneb/epoch_processing/registry_updates_test.go new file mode 100644 index 000000000000..9d4f59562c4d --- /dev/null +++ b/testing/spectest/mainnet/deneb/epoch_processing/registry_updates_test.go @@ -0,0 +1,11 @@ +package epoch_processing + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/epoch_processing" +) + +func TestMainnet_Deneb_EpochProcessing_ResetRegistryUpdates(t *testing.T) { + epoch_processing.RunRegistryUpdatesTests(t, "mainnet") +} diff --git a/testing/spectest/mainnet/deneb/epoch_processing/rewards_and_penalties_test.go b/testing/spectest/mainnet/deneb/epoch_processing/rewards_and_penalties_test.go new file mode 100644 index 000000000000..0a57f6172f82 --- /dev/null +++ b/testing/spectest/mainnet/deneb/epoch_processing/rewards_and_penalties_test.go @@ -0,0 +1,11 @@ +package epoch_processing + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/epoch_processing" +) + +func TestMainnet_Deneb_EpochProcessing_RewardsAndPenalties(t *testing.T) { + epoch_processing.RunRewardsAndPenaltiesTests(t, "mainnet") +} diff --git a/testing/spectest/mainnet/deneb/epoch_processing/slashings_reset_test.go b/testing/spectest/mainnet/deneb/epoch_processing/slashings_reset_test.go new file mode 100644 index 000000000000..7b8eb0db4af8 --- /dev/null +++ b/testing/spectest/mainnet/deneb/epoch_processing/slashings_reset_test.go @@ -0,0 +1,11 @@ +package epoch_processing + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/epoch_processing" +) + +func TestMainnet_Deneb_EpochProcessing_SlashingsReset(t *testing.T) { + epoch_processing.RunSlashingsResetTests(t, "mainnet") +} diff --git a/testing/spectest/mainnet/deneb/epoch_processing/slashings_test.go b/testing/spectest/mainnet/deneb/epoch_processing/slashings_test.go new file mode 100644 index 000000000000..ce7d05123273 --- /dev/null +++ b/testing/spectest/mainnet/deneb/epoch_processing/slashings_test.go @@ -0,0 +1,11 @@ +package epoch_processing + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/epoch_processing" +) + +func TestMainnet_Deneb_EpochProcessing_Slashings(t *testing.T) { + epoch_processing.RunSlashingsTests(t, "mainnet") +} diff --git a/testing/spectest/mainnet/deneb/finality/BUILD.bazel b/testing/spectest/mainnet/deneb/finality/BUILD.bazel new file mode 100644 index 000000000000..266a9c898b44 --- /dev/null +++ b/testing/spectest/mainnet/deneb/finality/BUILD.bazel @@ -0,0 +1,14 @@ +load("@prysm//tools/go:def.bzl", "go_test") + +go_test( + name = "go_default_test", + size = "medium", + timeout = "short", + srcs = ["finality_test.go"], + data = glob(["*.yaml"]) + [ + "@consensus_spec_tests_mainnet//:test_data", + ], + shard_count = 4, + tags = ["spectest"], + deps = ["//testing/spectest/shared/deneb/finality:go_default_library"], +) diff --git a/testing/spectest/mainnet/deneb/finality/finality_test.go b/testing/spectest/mainnet/deneb/finality/finality_test.go new file mode 100644 index 000000000000..b95929f3ec07 --- /dev/null +++ b/testing/spectest/mainnet/deneb/finality/finality_test.go @@ -0,0 +1,11 @@ +package finality + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/finality" +) + +func TestMainnet_Deneb_Finality(t *testing.T) { + finality.RunFinalityTest(t, "mainnet") +} diff --git a/testing/spectest/mainnet/deneb/fork_helper/BUILD.bazel b/testing/spectest/mainnet/deneb/fork_helper/BUILD.bazel index f370420a4d28..4b6f515979b4 100644 --- a/testing/spectest/mainnet/deneb/fork_helper/BUILD.bazel +++ b/testing/spectest/mainnet/deneb/fork_helper/BUILD.bazel @@ -3,7 +3,10 @@ load("@prysm//tools/go:def.bzl", "go_test") go_test( name = "go_default_test", size = "small", - srcs = ["upgrade_to_deneb_test.go"], + srcs = [ + "upgrade_to_capella_test.go", + "upgrade_to_deneb_test.go", + ], data = glob(["*.yaml"]) + [ "@consensus_spec_tests_mainnet//:test_data", ], diff --git a/testing/spectest/mainnet/deneb/fork_helper/upgrade_to_capella_test.go b/testing/spectest/mainnet/deneb/fork_helper/upgrade_to_capella_test.go new file mode 100644 index 000000000000..d80f62d39fcc --- /dev/null +++ b/testing/spectest/mainnet/deneb/fork_helper/upgrade_to_capella_test.go @@ -0,0 +1,11 @@ +package fork_helper + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/fork" +) + +func TestMainnet_Deneb_UpgradeToCapella(t *testing.T) { + fork.RunUpgradeToDeneb4(t, "mainnet") +} diff --git a/testing/spectest/mainnet/deneb/fork_transition/BUILD.bazel b/testing/spectest/mainnet/deneb/fork_transition/BUILD.bazel new file mode 100644 index 000000000000..76e831a68a4f --- /dev/null +++ b/testing/spectest/mainnet/deneb/fork_transition/BUILD.bazel @@ -0,0 +1,12 @@ +load("@prysm//tools/go:def.bzl", "go_test") + +go_test( + name = "go_default_test", + size = "small", + srcs = ["transition_test.go"], + data = glob(["*.yaml"]) + [ + "@consensus_spec_tests_mainnet//:test_data", + ], + tags = ["spectest"], + deps = ["//testing/spectest/shared/deneb/fork:go_default_library"], +) diff --git a/testing/spectest/mainnet/deneb/fork_transition/transition_test.go b/testing/spectest/mainnet/deneb/fork_transition/transition_test.go new file mode 100644 index 000000000000..27a046806870 --- /dev/null +++ b/testing/spectest/mainnet/deneb/fork_transition/transition_test.go @@ -0,0 +1,11 @@ +package fork_transition + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/fork" +) + +func TestMainnet_Deneb_Transition(t *testing.T) { + fork.RunForkTransitionTest(t, "mainnet") +} diff --git a/testing/spectest/mainnet/deneb/forkchoice/BUILD.bazel b/testing/spectest/mainnet/deneb/forkchoice/BUILD.bazel new file mode 100644 index 000000000000..1c2f4d9d33f4 --- /dev/null +++ b/testing/spectest/mainnet/deneb/forkchoice/BUILD.bazel @@ -0,0 +1,16 @@ +load("@prysm//tools/go:def.bzl", "go_test") + +go_test( + name = "go_default_test", + size = "enormous", + timeout = "short", + srcs = ["forkchoice_test.go"], + data = glob(["*.yaml"]) + [ + "@consensus_spec_tests_mainnet//:test_data", + ], + tags = ["spectest"], + deps = [ + "//runtime/version:go_default_library", + "//testing/spectest/shared/common/forkchoice:go_default_library", + ], +) diff --git a/testing/spectest/mainnet/deneb/forkchoice/forkchoice_test.go b/testing/spectest/mainnet/deneb/forkchoice/forkchoice_test.go new file mode 100644 index 000000000000..86383a4281f1 --- /dev/null +++ b/testing/spectest/mainnet/deneb/forkchoice/forkchoice_test.go @@ -0,0 +1,12 @@ +package forkchoice + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/runtime/version" + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/common/forkchoice" +) + +func TestMainnet_Deneb_Forkchoice(t *testing.T) { + forkchoice.Run(t, "mainnet", version.Deneb) +} diff --git a/testing/spectest/mainnet/deneb/operations/BUILD.bazel b/testing/spectest/mainnet/deneb/operations/BUILD.bazel new file mode 100644 index 000000000000..64cd0ffbba03 --- /dev/null +++ b/testing/spectest/mainnet/deneb/operations/BUILD.bazel @@ -0,0 +1,21 @@ +load("@prysm//tools/go:def.bzl", "go_test") + +go_test( + name = "go_default_test", + size = "small", + srcs = [ + "attestation_test.go", + "attester_slashing_test.go", + "block_header_test.go", + "deposit_test.go", + "proposer_slashing_test.go", + "sync_committee_test.go", + "voluntary_exit_test.go", + ], + data = glob(["*.yaml"]) + [ + "@consensus_spec_tests_mainnet//:test_data", + ], + shard_count = 4, + tags = ["spectest"], + deps = ["//testing/spectest/shared/deneb/operations:go_default_library"], +) diff --git a/testing/spectest/mainnet/deneb/operations/attestation_test.go b/testing/spectest/mainnet/deneb/operations/attestation_test.go new file mode 100644 index 000000000000..82b284e4102b --- /dev/null +++ b/testing/spectest/mainnet/deneb/operations/attestation_test.go @@ -0,0 +1,11 @@ +package operations + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/operations" +) + +func TestMainnet_Deneb_Operations_Attestation(t *testing.T) { + operations.RunAttestationTest(t, "mainnet") +} diff --git a/testing/spectest/mainnet/deneb/operations/attester_slashing_test.go b/testing/spectest/mainnet/deneb/operations/attester_slashing_test.go new file mode 100644 index 000000000000..605e1e184857 --- /dev/null +++ b/testing/spectest/mainnet/deneb/operations/attester_slashing_test.go @@ -0,0 +1,11 @@ +package operations + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/operations" +) + +func TestMainnet_Deneb_Operations_AttesterSlashing(t *testing.T) { + operations.RunAttesterSlashingTest(t, "mainnet") +} diff --git a/testing/spectest/mainnet/deneb/operations/block_header_test.go b/testing/spectest/mainnet/deneb/operations/block_header_test.go new file mode 100644 index 000000000000..8040153ec0d5 --- /dev/null +++ b/testing/spectest/mainnet/deneb/operations/block_header_test.go @@ -0,0 +1,11 @@ +package operations + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/operations" +) + +func TestMainnet_Deneb_Operations_BlockHeader(t *testing.T) { + operations.RunBlockHeaderTest(t, "mainnet") +} diff --git a/testing/spectest/mainnet/deneb/operations/deposit_test.go b/testing/spectest/mainnet/deneb/operations/deposit_test.go new file mode 100644 index 000000000000..68d2258d914e --- /dev/null +++ b/testing/spectest/mainnet/deneb/operations/deposit_test.go @@ -0,0 +1,11 @@ +package operations + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/operations" +) + +func TestMainnet_Deneb_Operations_Deposit(t *testing.T) { + operations.RunDepositTest(t, "mainnet") +} diff --git a/testing/spectest/mainnet/deneb/operations/proposer_slashing_test.go b/testing/spectest/mainnet/deneb/operations/proposer_slashing_test.go new file mode 100644 index 000000000000..5dfdb9ef0d9f --- /dev/null +++ b/testing/spectest/mainnet/deneb/operations/proposer_slashing_test.go @@ -0,0 +1,11 @@ +package operations + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/operations" +) + +func TestMainnet_Deneb_Operations_ProposerSlashing(t *testing.T) { + operations.RunProposerSlashingTest(t, "mainnet") +} diff --git a/testing/spectest/mainnet/deneb/operations/sync_committee_test.go b/testing/spectest/mainnet/deneb/operations/sync_committee_test.go new file mode 100644 index 000000000000..b9f8bf2a6b44 --- /dev/null +++ b/testing/spectest/mainnet/deneb/operations/sync_committee_test.go @@ -0,0 +1,11 @@ +package operations + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/operations" +) + +func TestMainnet_Deneb_Operations_SyncCommittee(t *testing.T) { + operations.RunSyncCommitteeTest(t, "mainnet") +} diff --git a/testing/spectest/mainnet/deneb/operations/voluntary_exit_test.go b/testing/spectest/mainnet/deneb/operations/voluntary_exit_test.go new file mode 100644 index 000000000000..660f635d05ef --- /dev/null +++ b/testing/spectest/mainnet/deneb/operations/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_VoluntaryExit(t *testing.T) { + operations.RunVoluntaryExitTest(t, "mainnet") +} diff --git a/testing/spectest/mainnet/deneb/rewards/BUILD.bazel b/testing/spectest/mainnet/deneb/rewards/BUILD.bazel new file mode 100644 index 000000000000..57975aeb9496 --- /dev/null +++ b/testing/spectest/mainnet/deneb/rewards/BUILD.bazel @@ -0,0 +1,12 @@ +load("@prysm//tools/go:def.bzl", "go_test") + +go_test( + name = "go_default_test", + size = "small", + srcs = ["rewards_test.go"], + data = glob(["*.yaml"]) + [ + "@consensus_spec_tests_mainnet//:test_data", + ], + tags = ["spectest"], + deps = ["//testing/spectest/shared/deneb/rewards:go_default_library"], +) diff --git a/testing/spectest/mainnet/deneb/rewards/rewards_test.go b/testing/spectest/mainnet/deneb/rewards/rewards_test.go new file mode 100644 index 000000000000..4d1a94dedfbf --- /dev/null +++ b/testing/spectest/mainnet/deneb/rewards/rewards_test.go @@ -0,0 +1,11 @@ +package rewards + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/rewards" +) + +func TestMainnet_Deneb_Rewards(t *testing.T) { + rewards.RunPrecomputeRewardsAndPenaltiesTests(t, "mainnet") +} diff --git a/testing/spectest/mainnet/deneb/sanity/BUILD.bazel b/testing/spectest/mainnet/deneb/sanity/BUILD.bazel new file mode 100644 index 000000000000..e9f552cdb17e --- /dev/null +++ b/testing/spectest/mainnet/deneb/sanity/BUILD.bazel @@ -0,0 +1,16 @@ +load("@prysm//tools/go:def.bzl", "go_test") + +go_test( + name = "go_default_test", + size = "medium", + timeout = "short", + srcs = [ + "blocks_test.go", + "slots_test.go", + ], + data = glob(["*.yaml"]) + [ + "@consensus_spec_tests_mainnet//:test_data", + ], + tags = ["spectest"], + deps = ["//testing/spectest/shared/deneb/sanity:go_default_library"], +) diff --git a/testing/spectest/mainnet/deneb/sanity/blocks_test.go b/testing/spectest/mainnet/deneb/sanity/blocks_test.go new file mode 100644 index 000000000000..879970a6ca89 --- /dev/null +++ b/testing/spectest/mainnet/deneb/sanity/blocks_test.go @@ -0,0 +1,11 @@ +package sanity + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/sanity" +) + +func TestMainnet_Deneb_Sanity_Blocks(t *testing.T) { + sanity.RunBlockProcessingTest(t, "mainnet", "sanity/blocks/pyspec_tests") +} diff --git a/testing/spectest/mainnet/deneb/sanity/slots_test.go b/testing/spectest/mainnet/deneb/sanity/slots_test.go new file mode 100644 index 000000000000..2173aebacd15 --- /dev/null +++ b/testing/spectest/mainnet/deneb/sanity/slots_test.go @@ -0,0 +1,11 @@ +package sanity + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/sanity" +) + +func TestMainnet_Deneb_Sanity_Slots(t *testing.T) { + sanity.RunSlotProcessingTests(t, "mainnet") +} diff --git a/testing/spectest/minimal/deneb/epoch_processing/BUILD.bazel b/testing/spectest/minimal/deneb/epoch_processing/BUILD.bazel new file mode 100644 index 000000000000..5538aef08b42 --- /dev/null +++ b/testing/spectest/minimal/deneb/epoch_processing/BUILD.bazel @@ -0,0 +1,28 @@ +load("@prysm//tools/go:def.bzl", "go_test") + +go_test( + name = "go_default_test", + size = "small", + srcs = [ + "effective_balance_updates_test.go", + "eth1_data_reset_test.go", + "historical_summaries_update_test.go", + "inactivity_updates_test.go", + "justification_and_finalization_test.go", + "participation_flag_updates_test.go", + "randao_mixes_reset_test.go", + "registry_updates_test.go", + "rewards_and_penalties_test.go", + "slashings_reset_test.go", + "slashings_test.go", + ], + data = glob(["*.yaml"]) + [ + "@consensus_spec_tests_minimal//:test_data", + ], + eth_network = "minimal", + tags = [ + "minimal", + "spectest", + ], + deps = ["//testing/spectest/shared/deneb/epoch_processing:go_default_library"], +) diff --git a/testing/spectest/minimal/deneb/epoch_processing/effective_balance_updates_test.go b/testing/spectest/minimal/deneb/epoch_processing/effective_balance_updates_test.go new file mode 100644 index 000000000000..184d43c4e989 --- /dev/null +++ b/testing/spectest/minimal/deneb/epoch_processing/effective_balance_updates_test.go @@ -0,0 +1,11 @@ +package epoch_processing + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/epoch_processing" +) + +func TestMinimal_Deneb_EpochProcessing_EffectiveBalanceUpdates(t *testing.T) { + epoch_processing.RunEffectiveBalanceUpdatesTests(t, "minimal") +} diff --git a/testing/spectest/minimal/deneb/epoch_processing/eth1_data_reset_test.go b/testing/spectest/minimal/deneb/epoch_processing/eth1_data_reset_test.go new file mode 100644 index 000000000000..b59d4b250f4f --- /dev/null +++ b/testing/spectest/minimal/deneb/epoch_processing/eth1_data_reset_test.go @@ -0,0 +1,11 @@ +package epoch_processing + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/epoch_processing" +) + +func TestMinimal_Deneb_EpochProcessing_Eth1DataReset(t *testing.T) { + epoch_processing.RunEth1DataResetTests(t, "minimal") +} diff --git a/testing/spectest/minimal/deneb/epoch_processing/historical_summaries_update_test.go b/testing/spectest/minimal/deneb/epoch_processing/historical_summaries_update_test.go new file mode 100644 index 000000000000..8ec4cd66a1bd --- /dev/null +++ b/testing/spectest/minimal/deneb/epoch_processing/historical_summaries_update_test.go @@ -0,0 +1,11 @@ +package epoch_processing + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/epoch_processing" +) + +func TestMinimal_Deneb_EpochProcessing_HistoricalSummariesUpdate(t *testing.T) { + epoch_processing.RunHistoricalSummariesUpdateTests(t, "minimal") +} diff --git a/testing/spectest/minimal/deneb/epoch_processing/inactivity_updates_test.go b/testing/spectest/minimal/deneb/epoch_processing/inactivity_updates_test.go new file mode 100644 index 000000000000..1fae2bee6e95 --- /dev/null +++ b/testing/spectest/minimal/deneb/epoch_processing/inactivity_updates_test.go @@ -0,0 +1,11 @@ +package epoch_processing + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/epoch_processing" +) + +func TestMinimal_Deneb_EpochProcessing_InactivityUpdates(t *testing.T) { + epoch_processing.RunInactivityUpdatesTest(t, "minimal") +} diff --git a/testing/spectest/minimal/deneb/epoch_processing/justification_and_finalization_test.go b/testing/spectest/minimal/deneb/epoch_processing/justification_and_finalization_test.go new file mode 100644 index 000000000000..70da63464970 --- /dev/null +++ b/testing/spectest/minimal/deneb/epoch_processing/justification_and_finalization_test.go @@ -0,0 +1,11 @@ +package epoch_processing + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/epoch_processing" +) + +func TestMinimal_Deneb_EpochProcessing_JustificationAndFinalization(t *testing.T) { + epoch_processing.RunJustificationAndFinalizationTests(t, "minimal") +} diff --git a/testing/spectest/minimal/deneb/epoch_processing/participation_flag_updates_test.go b/testing/spectest/minimal/deneb/epoch_processing/participation_flag_updates_test.go new file mode 100644 index 000000000000..f0ff5e77ec14 --- /dev/null +++ b/testing/spectest/minimal/deneb/epoch_processing/participation_flag_updates_test.go @@ -0,0 +1,11 @@ +package epoch_processing + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/epoch_processing" +) + +func TestMinimal_Deneb_EpochProcessing_ParticipationFlag(t *testing.T) { + epoch_processing.RunParticipationFlagUpdatesTests(t, "minimal") +} diff --git a/testing/spectest/minimal/deneb/epoch_processing/randao_mixes_reset_test.go b/testing/spectest/minimal/deneb/epoch_processing/randao_mixes_reset_test.go new file mode 100644 index 000000000000..063a2980cb32 --- /dev/null +++ b/testing/spectest/minimal/deneb/epoch_processing/randao_mixes_reset_test.go @@ -0,0 +1,11 @@ +package epoch_processing + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/epoch_processing" +) + +func TestMinimal_Deneb_EpochProcessing_RandaoMixesReset(t *testing.T) { + epoch_processing.RunRandaoMixesResetTests(t, "minimal") +} diff --git a/testing/spectest/minimal/deneb/epoch_processing/registry_updates_test.go b/testing/spectest/minimal/deneb/epoch_processing/registry_updates_test.go new file mode 100644 index 000000000000..cdc58989b57a --- /dev/null +++ b/testing/spectest/minimal/deneb/epoch_processing/registry_updates_test.go @@ -0,0 +1,11 @@ +package epoch_processing + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/epoch_processing" +) + +func TestMinimal_Deneb_EpochProcessing_ResetRegistryUpdates(t *testing.T) { + epoch_processing.RunRegistryUpdatesTests(t, "minimal") +} diff --git a/testing/spectest/minimal/deneb/epoch_processing/rewards_and_penalties_test.go b/testing/spectest/minimal/deneb/epoch_processing/rewards_and_penalties_test.go new file mode 100644 index 000000000000..ddf555548c5f --- /dev/null +++ b/testing/spectest/minimal/deneb/epoch_processing/rewards_and_penalties_test.go @@ -0,0 +1,11 @@ +package epoch_processing + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/epoch_processing" +) + +func TestMinimal_Deneb_EpochProcessing_RewardsAndPenalties(t *testing.T) { + epoch_processing.RunRewardsAndPenaltiesTests(t, "minimal") +} diff --git a/testing/spectest/minimal/deneb/epoch_processing/slashings_reset_test.go b/testing/spectest/minimal/deneb/epoch_processing/slashings_reset_test.go new file mode 100644 index 000000000000..4745db7fc830 --- /dev/null +++ b/testing/spectest/minimal/deneb/epoch_processing/slashings_reset_test.go @@ -0,0 +1,11 @@ +package epoch_processing + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/epoch_processing" +) + +func TestMinimal_Deneb_EpochProcessing_SlashingsReset(t *testing.T) { + epoch_processing.RunSlashingsResetTests(t, "minimal") +} diff --git a/testing/spectest/minimal/deneb/epoch_processing/slashings_test.go b/testing/spectest/minimal/deneb/epoch_processing/slashings_test.go new file mode 100644 index 000000000000..1bfed6465d8d --- /dev/null +++ b/testing/spectest/minimal/deneb/epoch_processing/slashings_test.go @@ -0,0 +1,11 @@ +package epoch_processing + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/epoch_processing" +) + +func TestMinimal_Deneb_EpochProcessing_Slashings(t *testing.T) { + epoch_processing.RunSlashingsTests(t, "minimal") +} diff --git a/testing/spectest/minimal/deneb/finality/BUILD.bazel b/testing/spectest/minimal/deneb/finality/BUILD.bazel new file mode 100644 index 000000000000..6f8ee09fc6fa --- /dev/null +++ b/testing/spectest/minimal/deneb/finality/BUILD.bazel @@ -0,0 +1,17 @@ +load("@prysm//tools/go:def.bzl", "go_test") + +go_test( + name = "go_default_test", + size = "small", + srcs = ["finality_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/finality:go_default_library"], +) diff --git a/testing/spectest/minimal/deneb/finality/finality_test.go b/testing/spectest/minimal/deneb/finality/finality_test.go new file mode 100644 index 000000000000..3234cac55695 --- /dev/null +++ b/testing/spectest/minimal/deneb/finality/finality_test.go @@ -0,0 +1,11 @@ +package finality + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/finality" +) + +func TestMinimal_Deneb_Finality(t *testing.T) { + finality.RunFinalityTest(t, "minimal") +} diff --git a/testing/spectest/minimal/deneb/fork/BUILD.bazel b/testing/spectest/minimal/deneb/fork/BUILD.bazel index 4c72a8287759..34def2a647a3 100644 --- a/testing/spectest/minimal/deneb/fork/BUILD.bazel +++ b/testing/spectest/minimal/deneb/fork/BUILD.bazel @@ -3,7 +3,10 @@ load("@prysm//tools/go:def.bzl", "go_test") go_test( name = "go_default_test", size = "small", - srcs = ["upgrade_to_deneb_test.go"], + srcs = [ + "upgrade_to_capella_test.go", + "upgrade_to_deneb_test.go", + ], data = glob(["*.yaml"]) + [ "@consensus_spec_tests_minimal//:test_data", ], diff --git a/testing/spectest/minimal/deneb/fork/upgrade_to_capella_test.go b/testing/spectest/minimal/deneb/fork/upgrade_to_capella_test.go new file mode 100644 index 000000000000..8a0d781c8974 --- /dev/null +++ b/testing/spectest/minimal/deneb/fork/upgrade_to_capella_test.go @@ -0,0 +1,11 @@ +package fork + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/fork" +) + +func TestMinimal_Deneb_UpgradeToDeneb(t *testing.T) { + fork.RunUpgradeToDeneb4(t, "minimal") +} diff --git a/testing/spectest/minimal/deneb/forkchoice/BUILD.bazel b/testing/spectest/minimal/deneb/forkchoice/BUILD.bazel new file mode 100644 index 000000000000..9bb5b8073fed --- /dev/null +++ b/testing/spectest/minimal/deneb/forkchoice/BUILD.bazel @@ -0,0 +1,20 @@ +load("@prysm//tools/go:def.bzl", "go_test") + +go_test( + name = "go_default_test", + size = "enormous", + timeout = "short", + srcs = ["forkchoice_test.go"], + data = glob(["*.yaml"]) + [ + "@consensus_spec_tests_minimal//:test_data", + ], + eth_network = "minimal", + tags = [ + "minimal", + "spectest", + ], + deps = [ + "//runtime/version:go_default_library", + "//testing/spectest/shared/common/forkchoice:go_default_library", + ], +) diff --git a/testing/spectest/minimal/deneb/forkchoice/forkchoice_test.go b/testing/spectest/minimal/deneb/forkchoice/forkchoice_test.go new file mode 100644 index 000000000000..e58e7e1eca82 --- /dev/null +++ b/testing/spectest/minimal/deneb/forkchoice/forkchoice_test.go @@ -0,0 +1,12 @@ +package forkchoice + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/runtime/version" + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/common/forkchoice" +) + +func TestMinimal_Deneb_Forkchoice(t *testing.T) { + forkchoice.Run(t, "minimal", version.Deneb) +} diff --git a/testing/spectest/minimal/deneb/operations/BUILD.bazel b/testing/spectest/minimal/deneb/operations/BUILD.bazel new file mode 100644 index 000000000000..efca2f458999 --- /dev/null +++ b/testing/spectest/minimal/deneb/operations/BUILD.bazel @@ -0,0 +1,26 @@ +load("@prysm//tools/go:def.bzl", "go_test") + +go_test( + name = "go_default_test", + size = "small", + srcs = [ + "attestation_test.go", + "attester_slashing_test.go", + "block_header_test.go", + "bls_to_execution_change_test.go", + "deposit_test.go", + "proposer_slashing_test.go", + "sync_committee_test.go", + "voluntary_exit_test.go", + "withdrawals_test.go", + ], + data = glob(["*.yaml"]) + [ + "@consensus_spec_tests_minimal//:test_data", + ], + eth_network = "minimal", + tags = [ + "minimal", + "spectest", + ], + deps = ["//testing/spectest/shared/deneb/operations:go_default_library"], +) diff --git a/testing/spectest/minimal/deneb/operations/attestation_test.go b/testing/spectest/minimal/deneb/operations/attestation_test.go new file mode 100644 index 000000000000..0e205c1f3f82 --- /dev/null +++ b/testing/spectest/minimal/deneb/operations/attestation_test.go @@ -0,0 +1,11 @@ +package operations + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/operations" +) + +func TestMinimal_Deneb_Operations_Attestation(t *testing.T) { + operations.RunAttestationTest(t, "minimal") +} diff --git a/testing/spectest/minimal/deneb/operations/attester_slashing_test.go b/testing/spectest/minimal/deneb/operations/attester_slashing_test.go new file mode 100644 index 000000000000..a68fe12ca495 --- /dev/null +++ b/testing/spectest/minimal/deneb/operations/attester_slashing_test.go @@ -0,0 +1,11 @@ +package operations + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/operations" +) + +func TestMinimal_Deneb_Operations_AttesterSlashing(t *testing.T) { + operations.RunAttesterSlashingTest(t, "minimal") +} diff --git a/testing/spectest/minimal/deneb/operations/block_header_test.go b/testing/spectest/minimal/deneb/operations/block_header_test.go new file mode 100644 index 000000000000..d307d052fd03 --- /dev/null +++ b/testing/spectest/minimal/deneb/operations/block_header_test.go @@ -0,0 +1,11 @@ +package operations + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/operations" +) + +func TestMinimal_Deneb_Operations_BlockHeader(t *testing.T) { + operations.RunBlockHeaderTest(t, "minimal") +} diff --git a/testing/spectest/minimal/deneb/operations/bls_to_execution_change_test.go b/testing/spectest/minimal/deneb/operations/bls_to_execution_change_test.go new file mode 100644 index 000000000000..f43eb1520267 --- /dev/null +++ b/testing/spectest/minimal/deneb/operations/bls_to_execution_change_test.go @@ -0,0 +1,11 @@ +package operations + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/operations" +) + +func TestMinimal_Deneb_Operations_BLSToExecutionChange(t *testing.T) { + operations.RunBLSToExecutionChangeTest(t, "minimal") +} diff --git a/testing/spectest/minimal/deneb/operations/deposit_test.go b/testing/spectest/minimal/deneb/operations/deposit_test.go new file mode 100644 index 000000000000..f4d821bf55fb --- /dev/null +++ b/testing/spectest/minimal/deneb/operations/deposit_test.go @@ -0,0 +1,11 @@ +package operations + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/operations" +) + +func TestMinimal_Deneb_Operations_Deposit(t *testing.T) { + operations.RunDepositTest(t, "minimal") +} diff --git a/testing/spectest/minimal/deneb/operations/proposer_slashing_test.go b/testing/spectest/minimal/deneb/operations/proposer_slashing_test.go new file mode 100644 index 000000000000..1b8246ed1b6d --- /dev/null +++ b/testing/spectest/minimal/deneb/operations/proposer_slashing_test.go @@ -0,0 +1,11 @@ +package operations + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/operations" +) + +func TestMinimal_Deneb_Operations_ProposerSlashing(t *testing.T) { + operations.RunProposerSlashingTest(t, "minimal") +} diff --git a/testing/spectest/minimal/deneb/operations/sync_committee_test.go b/testing/spectest/minimal/deneb/operations/sync_committee_test.go new file mode 100644 index 000000000000..22cb83fedebd --- /dev/null +++ b/testing/spectest/minimal/deneb/operations/sync_committee_test.go @@ -0,0 +1,11 @@ +package operations + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/operations" +) + +func TestMinimal_Deneb_Operations_SyncCommittee(t *testing.T) { + operations.RunProposerSlashingTest(t, "minimal") +} diff --git a/testing/spectest/minimal/deneb/operations/voluntary_exit_test.go b/testing/spectest/minimal/deneb/operations/voluntary_exit_test.go new file mode 100644 index 000000000000..9d43275b1cef --- /dev/null +++ b/testing/spectest/minimal/deneb/operations/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_VoluntaryExit(t *testing.T) { + operations.RunVoluntaryExitTest(t, "minimal") +} diff --git a/testing/spectest/minimal/deneb/operations/withdrawals_test.go b/testing/spectest/minimal/deneb/operations/withdrawals_test.go new file mode 100644 index 000000000000..16f41da5c071 --- /dev/null +++ b/testing/spectest/minimal/deneb/operations/withdrawals_test.go @@ -0,0 +1,11 @@ +package operations + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/operations" +) + +func TestMinimal_Deneb_Operations_Withdrawals(t *testing.T) { + operations.RunWithdrawalsTest(t, "minimal") +} diff --git a/testing/spectest/minimal/deneb/rewards/BUILD.bazel b/testing/spectest/minimal/deneb/rewards/BUILD.bazel new file mode 100644 index 000000000000..3028db0cb695 --- /dev/null +++ b/testing/spectest/minimal/deneb/rewards/BUILD.bazel @@ -0,0 +1,16 @@ +load("@prysm//tools/go:def.bzl", "go_test") + +go_test( + name = "go_default_test", + size = "small", + srcs = ["rewards_test.go"], + data = glob(["*.yaml"]) + [ + "@consensus_spec_tests_minimal//:test_data", + ], + eth_network = "minimal", + tags = [ + "minimal", + "spectest", + ], + deps = ["//testing/spectest/shared/deneb/rewards:go_default_library"], +) diff --git a/testing/spectest/minimal/deneb/rewards/rewards_test.go b/testing/spectest/minimal/deneb/rewards/rewards_test.go new file mode 100644 index 000000000000..d6549a411f6a --- /dev/null +++ b/testing/spectest/minimal/deneb/rewards/rewards_test.go @@ -0,0 +1,11 @@ +package rewards + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/rewards" +) + +func TestMinimal_Deneb_Rewards(t *testing.T) { + rewards.RunPrecomputeRewardsAndPenaltiesTests(t, "minimal") +} diff --git a/testing/spectest/minimal/deneb/sanity/BUILD.bazel b/testing/spectest/minimal/deneb/sanity/BUILD.bazel new file mode 100644 index 000000000000..e3cbcd4146ab --- /dev/null +++ b/testing/spectest/minimal/deneb/sanity/BUILD.bazel @@ -0,0 +1,19 @@ +load("@prysm//tools/go:def.bzl", "go_test") + +go_test( + name = "go_default_test", + size = "small", + srcs = [ + "blocks_test.go", + "slots_test.go", + ], + data = glob(["*.yaml"]) + [ + "@consensus_spec_tests_minimal//:test_data", + ], + eth_network = "minimal", + tags = [ + "minimal", + "spectest", + ], + deps = ["//testing/spectest/shared/deneb/sanity:go_default_library"], +) diff --git a/testing/spectest/minimal/deneb/sanity/blocks_test.go b/testing/spectest/minimal/deneb/sanity/blocks_test.go new file mode 100644 index 000000000000..e3b95eb340e1 --- /dev/null +++ b/testing/spectest/minimal/deneb/sanity/blocks_test.go @@ -0,0 +1,11 @@ +package sanity + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/sanity" +) + +func TestMinimal_Deneb_Sanity_Blocks(t *testing.T) { + sanity.RunBlockProcessingTest(t, "minimal", "sanity/blocks/pyspec_tests") +} diff --git a/testing/spectest/minimal/deneb/sanity/slots_test.go b/testing/spectest/minimal/deneb/sanity/slots_test.go new file mode 100644 index 000000000000..b4020cef9f69 --- /dev/null +++ b/testing/spectest/minimal/deneb/sanity/slots_test.go @@ -0,0 +1,11 @@ +package sanity + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/sanity" +) + +func TestMinimal_Deneb_Sanity_Slots(t *testing.T) { + sanity.RunSlotProcessingTests(t, "minimal") +} diff --git a/testing/spectest/shared/common/forkchoice/runner.go b/testing/spectest/shared/common/forkchoice/runner.go index b0f2396458df..0a21493867ff 100644 --- a/testing/spectest/shared/common/forkchoice/runner.go +++ b/testing/spectest/shared/common/forkchoice/runner.go @@ -77,6 +77,9 @@ func runTest(t *testing.T, config string, fork int, basePath string) { case version.Capella: beaconState = unmarshalCapellaState(t, preBeaconStateSSZ) beaconBlock = unmarshalCapellaBlock(t, blockSSZ) + case version.Deneb: + beaconState = unmarshalDenebState(t, preBeaconStateSSZ) + beaconBlock = unmarshalDenebBlock(t, blockSSZ) default: t.Fatalf("unknown fork version: %v", fork) } @@ -102,6 +105,8 @@ func runTest(t *testing.T, config string, fork int, basePath string) { beaconBlock = unmarshalSignedBellatrixBlock(t, blockSSZ) case version.Capella: beaconBlock = unmarshalSignedCapellaBlock(t, blockSSZ) + case version.Deneb: + beaconBlock = unmarshalSignedDenebBlock(t, blockSSZ) default: t.Fatalf("unknown fork version: %v", fork) } @@ -243,3 +248,27 @@ func unmarshalSignedCapellaBlock(t *testing.T, raw []byte) interfaces.ReadOnlySi require.NoError(t, err) return blk } + +func unmarshalDenebState(t *testing.T, raw []byte) state.BeaconState { + base := ðpb.BeaconStateDeneb{} + require.NoError(t, base.UnmarshalSSZ(raw)) + st, err := state_native.InitializeFromProtoDeneb(base) + require.NoError(t, err) + return st +} + +func unmarshalDenebBlock(t *testing.T, raw []byte) interfaces.SignedBeaconBlock { + base := ðpb.BeaconBlockDeneb{} + require.NoError(t, base.UnmarshalSSZ(raw)) + blk, err := blocks.NewSignedBeaconBlock(ðpb.SignedBeaconBlockDeneb{Block: base, Signature: make([]byte, fieldparams.BLSSignatureLength)}) + require.NoError(t, err) + return blk +} + +func unmarshalSignedDenebBlock(t *testing.T, raw []byte) interfaces.SignedBeaconBlock { + base := ðpb.SignedBeaconBlockDeneb{} + require.NoError(t, base.UnmarshalSSZ(raw)) + blk, err := blocks.NewSignedBeaconBlock(base) + require.NoError(t, err) + return blk +} diff --git a/testing/spectest/shared/common/forkchoice/service.go b/testing/spectest/shared/common/forkchoice/service.go index b3f4c8b5d297..bf2d61e8696a 100644 --- a/testing/spectest/shared/common/forkchoice/service.go +++ b/testing/spectest/shared/common/forkchoice/service.go @@ -2,6 +2,7 @@ package forkchoice import ( "context" + "math/big" "testing" "github.com/ethereum/go-ethereum/common" @@ -83,15 +84,22 @@ type engineMock struct { func (m *engineMock) GetPayload(context.Context, [8]byte, primitives.Slot) (interfaces.ExecutionData, *pb.BlobsBundle, bool, error) { return nil, nil, false, nil } - +func (m *engineMock) GetPayloadV2(context.Context, [8]byte) (*pb.ExecutionPayloadCapella, error) { + return nil, nil +} func (m *engineMock) ForkchoiceUpdated(context.Context, *pb.ForkchoiceState, payloadattribute.Attributer) (*pb.PayloadIDBytes, []byte, error) { return nil, m.latestValidHash, m.payloadStatus } + func (m *engineMock) NewPayload(context.Context, interfaces.ExecutionData, [][32]byte) ([]byte, error) { return m.latestValidHash, m.payloadStatus } -func (m *engineMock) LatestExecutionBlock() (*pb.ExecutionBlock, error) { +func (m *engineMock) ForkchoiceUpdatedV2(context.Context, *pb.ForkchoiceState, payloadattribute.Attributer) (*pb.PayloadIDBytes, []byte, error) { + return nil, m.latestValidHash, m.payloadStatus +} + +func (m *engineMock) LatestExecutionBlock(context.Context) (*pb.ExecutionBlock, error) { return nil, nil } @@ -105,7 +113,7 @@ func (m *engineMock) ExecutionBlockByHash(_ context.Context, hash common.Hash, _ return nil, nil } - td := bytesutil.LittleEndianBytesToBigInt(b.TotalDifficulty) + td := new(big.Int).SetBytes(bytesutil.ReverseByteOrder(b.TotalDifficulty)) tdHex := hexutil.EncodeBig(td) return &pb.ExecutionBlock{ Header: gethtypes.Header{ diff --git a/testing/spectest/shared/deneb/epoch_processing/BUILD.bazel b/testing/spectest/shared/deneb/epoch_processing/BUILD.bazel new file mode 100644 index 000000000000..0e3c558ba1f3 --- /dev/null +++ b/testing/spectest/shared/deneb/epoch_processing/BUILD.bazel @@ -0,0 +1,38 @@ +load("@prysm//tools/go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + testonly = True, + srcs = [ + "effective_balance_updates.go", + "eth1_data_reset.go", + "helpers.go", + "historical_summaries_update.go", + "inactivity_updates.go", + "justification_and_finalization.go", + "participation_flag_updates.go", + "randao_mixes_reset.go", + "registry_updates.go", + "rewards_and_penalties.go", + "slashings.go", + "slashings_reset.go", + ], + importpath = "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/epoch_processing", + visibility = ["//testing/spectest:__subpackages__"], + deps = [ + "//beacon-chain/core/altair:go_default_library", + "//beacon-chain/core/epoch:go_default_library", + "//beacon-chain/core/epoch/precompute:go_default_library", + "//beacon-chain/core/helpers:go_default_library", + "//beacon-chain/state:go_default_library", + "//beacon-chain/state/state-native:go_default_library", + "//config/params: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", + "@io_bazel_rules_go//go/tools/bazel:go_default_library", + "@org_golang_google_protobuf//proto:go_default_library", + ], +) diff --git a/testing/spectest/shared/deneb/epoch_processing/effective_balance_updates.go b/testing/spectest/shared/deneb/epoch_processing/effective_balance_updates.go new file mode 100644 index 000000000000..e0aaecf41259 --- /dev/null +++ b/testing/spectest/shared/deneb/epoch_processing/effective_balance_updates.go @@ -0,0 +1,30 @@ +package epoch_processing + +import ( + "path" + "testing" + + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/epoch" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/state" + "github.com/prysmaticlabs/prysm/v4/testing/require" + "github.com/prysmaticlabs/prysm/v4/testing/spectest/utils" +) + +// RunEffectiveBalanceUpdatesTests executes "epoch_processing/effective_balance_updates" tests. +func RunEffectiveBalanceUpdatesTests(t *testing.T, config string) { + require.NoError(t, utils.SetConfig(t, config)) + + testFolders, testsFolderPath := utils.TestFolders(t, config, "deneb", "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()) + RunEpochOperationTest(t, folderPath, processEffectiveBalanceUpdatesWrapper) + }) + } +} + +func processEffectiveBalanceUpdatesWrapper(t *testing.T, st state.BeaconState) (state.BeaconState, error) { + st, err := epoch.ProcessEffectiveBalanceUpdates(st) + require.NoError(t, err, "Could not process final updates") + return st, nil +} diff --git a/testing/spectest/shared/deneb/epoch_processing/eth1_data_reset.go b/testing/spectest/shared/deneb/epoch_processing/eth1_data_reset.go new file mode 100644 index 000000000000..131472c6b9cb --- /dev/null +++ b/testing/spectest/shared/deneb/epoch_processing/eth1_data_reset.go @@ -0,0 +1,30 @@ +package epoch_processing + +import ( + "path" + "testing" + + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/epoch" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/state" + "github.com/prysmaticlabs/prysm/v4/testing/require" + "github.com/prysmaticlabs/prysm/v4/testing/spectest/utils" +) + +// RunEth1DataResetTests executes "epoch_processing/eth1_data_reset" tests. +func RunEth1DataResetTests(t *testing.T, config string) { + require.NoError(t, utils.SetConfig(t, config)) + + testFolders, testsFolderPath := utils.TestFolders(t, config, "deneb", "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()) + RunEpochOperationTest(t, folderPath, processEth1DataResetWrapper) + }) + } +} + +func processEth1DataResetWrapper(t *testing.T, st state.BeaconState) (state.BeaconState, error) { + st, err := epoch.ProcessEth1DataReset(st) + require.NoError(t, err, "Could not process final updates") + return st, nil +} diff --git a/testing/spectest/shared/deneb/epoch_processing/helpers.go b/testing/spectest/shared/deneb/epoch_processing/helpers.go new file mode 100644 index 000000000000..7382f95bfe6c --- /dev/null +++ b/testing/spectest/shared/deneb/epoch_processing/helpers.go @@ -0,0 +1,75 @@ +package epoch_processing + +import ( + "os" + "path" + "strings" + "testing" + + "github.com/bazelbuild/rules_go/go/tools/bazel" + "github.com/golang/snappy" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/state" + 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/util" + "google.golang.org/protobuf/proto" +) + +type epochOperation func(*testing.T, state.BeaconState) (state.BeaconState, error) + +// RunEpochOperationTest takes in the prestate and processes it through the +// passed in epoch operation function and checks the post state with the expected post state. +func RunEpochOperationTest( + t *testing.T, + testFolderPath string, + operationFn epochOperation, +) { + preBeaconStateFile, err := util.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.BeaconStateDeneb{} + if err := preBeaconStateBase.UnmarshalSSZ(preBeaconStateSSZ); err != nil { + t.Fatalf("Failed to unmarshal: %v", err) + } + preBeaconState, err := state_native.InitializeFromProtoDeneb(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_snappy")) + postSSZExists := true + if err != nil && strings.Contains(err.Error(), "could not locate file") { + postSSZExists = false + } else if err != nil { + t.Fatal(err) + } + + beaconState, err := operationFn(t, preBeaconState) + if postSSZExists { + require.NoError(t, err) + + 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{} + if err := postBeaconState.UnmarshalSSZ(postBeaconStateSSZ); err != nil { + t.Fatalf("Failed to unmarshal: %v", err) + } + + pbState, err := state_native.ProtobufBeaconStateDeneb(beaconState.ToProtoUnsafe()) + require.NoError(t, err) + if !proto.Equal(pbState, postBeaconState) { + t.Fatal("Post state does not match expected") + } + } else { + // Note: This doesn't test anything worthwhile. It essentially tests + // that *any* error has occurred, not any specific error. + if err == nil { + t.Fatal("Did not fail when expected") + } + t.Logf("Expected failure; failure reason = %v", err) + return + } +} diff --git a/testing/spectest/shared/deneb/epoch_processing/historical_summaries_update.go b/testing/spectest/shared/deneb/epoch_processing/historical_summaries_update.go new file mode 100644 index 000000000000..9dcbadbe16fd --- /dev/null +++ b/testing/spectest/shared/deneb/epoch_processing/historical_summaries_update.go @@ -0,0 +1,30 @@ +package epoch_processing + +import ( + "path" + "testing" + + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/epoch" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/state" + "github.com/prysmaticlabs/prysm/v4/testing/require" + "github.com/prysmaticlabs/prysm/v4/testing/spectest/utils" +) + +// RunHistoricalSummariesUpdateTests executes "epoch_processing/historical_Summaries_update" tests. +func RunHistoricalSummariesUpdateTests(t *testing.T, config string) { + require.NoError(t, utils.SetConfig(t, config)) + + testFolders, testsFolderPath := utils.TestFolders(t, config, "deneb", "epoch_processing/historical_summaries_update/pyspec_tests") + for _, folder := range testFolders { + t.Run(folder.Name(), func(t *testing.T) { + folderPath := path.Join(testsFolderPath, folder.Name()) + RunEpochOperationTest(t, folderPath, processHistoricalSummariesUpdateWrapper) + }) + } +} + +func processHistoricalSummariesUpdateWrapper(t *testing.T, st state.BeaconState) (state.BeaconState, error) { + st, err := epoch.ProcessHistoricalDataUpdate(st) + require.NoError(t, err, "Could not process final updates") + return st, nil +} diff --git a/testing/spectest/shared/deneb/epoch_processing/inactivity_updates.go b/testing/spectest/shared/deneb/epoch_processing/inactivity_updates.go new file mode 100644 index 000000000000..49d003cec42e --- /dev/null +++ b/testing/spectest/shared/deneb/epoch_processing/inactivity_updates.go @@ -0,0 +1,41 @@ +package epoch_processing + +import ( + "context" + "path" + "testing" + + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/altair" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/state" + "github.com/prysmaticlabs/prysm/v4/testing/require" + "github.com/prysmaticlabs/prysm/v4/testing/spectest/utils" +) + +// RunInactivityUpdatesTest executes "epoch_processing/inactivity_updates" tests. +func RunInactivityUpdatesTest(t *testing.T, config string) { + require.NoError(t, utils.SetConfig(t, config)) + + testPath := "epoch_processing/inactivity_updates/pyspec_tests" + testFolders, testsFolderPath := utils.TestFolders(t, config, "deneb", testPath) + for _, folder := range testFolders { + helpers.ClearCache() + t.Run(folder.Name(), func(t *testing.T) { + folderPath := path.Join(testsFolderPath, folder.Name()) + RunEpochOperationTest(t, folderPath, processInactivityUpdates) + }) + } +} + +func processInactivityUpdates(t *testing.T, st state.BeaconState) (state.BeaconState, error) { + ctx := context.Background() + vp, bp, err := altair.InitializePrecomputeValidators(ctx, st) + require.NoError(t, err) + vp, _, err = altair.ProcessEpochParticipation(ctx, st, bp, vp) + require.NoError(t, err) + + st, _, err = altair.ProcessInactivityScores(ctx, st, vp) + require.NoError(t, err, "Could not process reward") + + return st, nil +} diff --git a/testing/spectest/shared/deneb/epoch_processing/justification_and_finalization.go b/testing/spectest/shared/deneb/epoch_processing/justification_and_finalization.go new file mode 100644 index 000000000000..f18b6d5382aa --- /dev/null +++ b/testing/spectest/shared/deneb/epoch_processing/justification_and_finalization.go @@ -0,0 +1,40 @@ +package epoch_processing + +import ( + "context" + "path" + "testing" + + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/altair" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/epoch/precompute" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/state" + "github.com/prysmaticlabs/prysm/v4/testing/require" + "github.com/prysmaticlabs/prysm/v4/testing/spectest/utils" +) + +// RunJustificationAndFinalizationTests executes "epoch_processing/justification_and_finalization" tests. +func RunJustificationAndFinalizationTests(t *testing.T, config string) { + require.NoError(t, utils.SetConfig(t, config)) + + testPath := "epoch_processing/justification_and_finalization/pyspec_tests" + testFolders, testsFolderPath := utils.TestFolders(t, config, "deneb", testPath) + for _, folder := range testFolders { + t.Run(folder.Name(), func(t *testing.T) { + folderPath := path.Join(testsFolderPath, folder.Name()) + RunEpochOperationTest(t, folderPath, processJustificationAndFinalizationPrecomputeWrapper) + }) + } +} + +func processJustificationAndFinalizationPrecomputeWrapper(t *testing.T, st state.BeaconState) (state.BeaconState, error) { + ctx := context.Background() + vp, bp, err := altair.InitializePrecomputeValidators(ctx, st) + require.NoError(t, err) + _, bp, err = altair.ProcessEpochParticipation(ctx, st, bp, vp) + require.NoError(t, err) + + st, err = precompute.ProcessJustificationAndFinalizationPreCompute(st, bp) + require.NoError(t, err, "Could not process justification") + + return st, nil +} diff --git a/testing/spectest/shared/deneb/epoch_processing/participation_flag_updates.go b/testing/spectest/shared/deneb/epoch_processing/participation_flag_updates.go new file mode 100644 index 000000000000..62878abc51c9 --- /dev/null +++ b/testing/spectest/shared/deneb/epoch_processing/participation_flag_updates.go @@ -0,0 +1,30 @@ +package epoch_processing + +import ( + "path" + "testing" + + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/altair" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/state" + "github.com/prysmaticlabs/prysm/v4/testing/require" + "github.com/prysmaticlabs/prysm/v4/testing/spectest/utils" +) + +// RunParticipationFlagUpdatesTests executes "epoch_processing/participation_flag_updates" tests. +func RunParticipationFlagUpdatesTests(t *testing.T, config string) { + require.NoError(t, utils.SetConfig(t, config)) + + testFolders, testsFolderPath := utils.TestFolders(t, config, "deneb", "epoch_processing/participation_flag_updates/pyspec_tests") + for _, folder := range testFolders { + t.Run(folder.Name(), func(t *testing.T) { + folderPath := path.Join(testsFolderPath, folder.Name()) + RunEpochOperationTest(t, folderPath, processParticipationFlagUpdatesWrapper) + }) + } +} + +func processParticipationFlagUpdatesWrapper(t *testing.T, st state.BeaconState) (state.BeaconState, error) { + st, err := altair.ProcessParticipationFlagUpdates(st) + require.NoError(t, err, "Could not process participation flag update") + return st, nil +} diff --git a/testing/spectest/shared/deneb/epoch_processing/randao_mixes_reset.go b/testing/spectest/shared/deneb/epoch_processing/randao_mixes_reset.go new file mode 100644 index 000000000000..c9a78ee7ae72 --- /dev/null +++ b/testing/spectest/shared/deneb/epoch_processing/randao_mixes_reset.go @@ -0,0 +1,30 @@ +package epoch_processing + +import ( + "path" + "testing" + + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/epoch" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/state" + "github.com/prysmaticlabs/prysm/v4/testing/require" + "github.com/prysmaticlabs/prysm/v4/testing/spectest/utils" +) + +// RunRandaoMixesResetTests executes "epoch_processing/randao_mixes_reset" tests. +func RunRandaoMixesResetTests(t *testing.T, config string) { + require.NoError(t, utils.SetConfig(t, config)) + + testFolders, testsFolderPath := utils.TestFolders(t, config, "deneb", "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()) + RunEpochOperationTest(t, folderPath, processRandaoMixesResetWrapper) + }) + } +} + +func processRandaoMixesResetWrapper(t *testing.T, st state.BeaconState) (state.BeaconState, error) { + st, err := epoch.ProcessRandaoMixesReset(st) + require.NoError(t, err, "Could not process final updates") + return st, nil +} diff --git a/testing/spectest/shared/deneb/epoch_processing/registry_updates.go b/testing/spectest/shared/deneb/epoch_processing/registry_updates.go new file mode 100644 index 000000000000..75d0838f7600 --- /dev/null +++ b/testing/spectest/shared/deneb/epoch_processing/registry_updates.go @@ -0,0 +1,32 @@ +package epoch_processing + +import ( + "context" + "path" + "testing" + + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/epoch" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/state" + "github.com/prysmaticlabs/prysm/v4/testing/require" + "github.com/prysmaticlabs/prysm/v4/testing/spectest/utils" +) + +// RunRegistryUpdatesTests executes "epoch_processing/registry_updates" tests. +func RunRegistryUpdatesTests(t *testing.T, config string) { + require.NoError(t, utils.SetConfig(t, config)) + + testFolders, testsFolderPath := utils.TestFolders(t, config, "deneb", "epoch_processing/registry_updates/pyspec_tests") + for _, folder := range testFolders { + t.Run(folder.Name(), func(t *testing.T) { + // Important to clear cache for every test or else the old value of active validator count gets reused. + helpers.ClearCache() + folderPath := path.Join(testsFolderPath, folder.Name()) + RunEpochOperationTest(t, folderPath, processRegistryUpdatesWrapper) + }) + } +} + +func processRegistryUpdatesWrapper(_ *testing.T, state state.BeaconState) (state.BeaconState, error) { + return epoch.ProcessRegistryUpdates(context.Background(), state) +} diff --git a/testing/spectest/shared/deneb/epoch_processing/rewards_and_penalties.go b/testing/spectest/shared/deneb/epoch_processing/rewards_and_penalties.go new file mode 100644 index 000000000000..6db4e8bec69d --- /dev/null +++ b/testing/spectest/shared/deneb/epoch_processing/rewards_and_penalties.go @@ -0,0 +1,41 @@ +package epoch_processing + +import ( + "context" + "path" + "testing" + + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/altair" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/state" + "github.com/prysmaticlabs/prysm/v4/testing/require" + "github.com/prysmaticlabs/prysm/v4/testing/spectest/utils" +) + +// RunRewardsAndPenaltiesTests executes "epoch_processing/rewards_and_penalties" tests. +func RunRewardsAndPenaltiesTests(t *testing.T, config string) { + require.NoError(t, utils.SetConfig(t, config)) + + testPath := "epoch_processing/rewards_and_penalties/pyspec_tests" + testFolders, testsFolderPath := utils.TestFolders(t, config, "deneb", testPath) + for _, folder := range testFolders { + helpers.ClearCache() + t.Run(folder.Name(), func(t *testing.T) { + folderPath := path.Join(testsFolderPath, folder.Name()) + RunEpochOperationTest(t, folderPath, processRewardsAndPenaltiesPrecomputeWrapper) + }) + } +} + +func processRewardsAndPenaltiesPrecomputeWrapper(t *testing.T, st state.BeaconState) (state.BeaconState, error) { + ctx := context.Background() + vp, bp, err := altair.InitializePrecomputeValidators(ctx, st) + require.NoError(t, err) + vp, bp, err = altair.ProcessEpochParticipation(ctx, st, bp, vp) + require.NoError(t, err) + + st, err = altair.ProcessRewardsAndPenaltiesPrecompute(st, bp, vp) + require.NoError(t, err, "Could not process reward") + + return st, nil +} diff --git a/testing/spectest/shared/deneb/epoch_processing/slashings.go b/testing/spectest/shared/deneb/epoch_processing/slashings.go new file mode 100644 index 000000000000..ff21ac0a7d40 --- /dev/null +++ b/testing/spectest/shared/deneb/epoch_processing/slashings.go @@ -0,0 +1,33 @@ +package epoch_processing + +import ( + "path" + "testing" + + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/epoch" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/state" + "github.com/prysmaticlabs/prysm/v4/config/params" + "github.com/prysmaticlabs/prysm/v4/testing/require" + "github.com/prysmaticlabs/prysm/v4/testing/spectest/utils" +) + +// RunSlashingsTests executes "epoch_processing/slashings" tests. +func RunSlashingsTests(t *testing.T, config string) { + require.NoError(t, utils.SetConfig(t, config)) + + testFolders, testsFolderPath := utils.TestFolders(t, config, "deneb", "epoch_processing/slashings/pyspec_tests") + for _, folder := range testFolders { + t.Run(folder.Name(), func(t *testing.T) { + folderPath := path.Join(testsFolderPath, folder.Name()) + helpers.ClearCache() + RunEpochOperationTest(t, folderPath, processSlashingsWrapper) + }) + } +} + +func processSlashingsWrapper(t *testing.T, st state.BeaconState) (state.BeaconState, error) { + st, err := epoch.ProcessSlashings(st, params.BeaconConfig().ProportionalSlashingMultiplierBellatrix) + require.NoError(t, err, "Could not process slashings") + return st, nil +} diff --git a/testing/spectest/shared/deneb/epoch_processing/slashings_reset.go b/testing/spectest/shared/deneb/epoch_processing/slashings_reset.go new file mode 100644 index 000000000000..73d822883a26 --- /dev/null +++ b/testing/spectest/shared/deneb/epoch_processing/slashings_reset.go @@ -0,0 +1,30 @@ +package epoch_processing + +import ( + "path" + "testing" + + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/epoch" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/state" + "github.com/prysmaticlabs/prysm/v4/testing/require" + "github.com/prysmaticlabs/prysm/v4/testing/spectest/utils" +) + +// RunSlashingsResetTests executes "epoch_processing/slashings_reset" tests. +func RunSlashingsResetTests(t *testing.T, config string) { + require.NoError(t, utils.SetConfig(t, config)) + + testFolders, testsFolderPath := utils.TestFolders(t, config, "deneb", "epoch_processing/slashings_reset/pyspec_tests") + for _, folder := range testFolders { + t.Run(folder.Name(), func(t *testing.T) { + folderPath := path.Join(testsFolderPath, folder.Name()) + RunEpochOperationTest(t, folderPath, processSlashingsResetWrapper) + }) + } +} + +func processSlashingsResetWrapper(t *testing.T, st state.BeaconState) (state.BeaconState, error) { + st, err := epoch.ProcessSlashingsReset(st) + require.NoError(t, err, "Could not process final updates") + return st, nil +} diff --git a/testing/spectest/shared/deneb/finality/BUILD.bazel b/testing/spectest/shared/deneb/finality/BUILD.bazel new file mode 100644 index 000000000000..7181022607b8 --- /dev/null +++ b/testing/spectest/shared/deneb/finality/BUILD.bazel @@ -0,0 +1,22 @@ +load("@prysm//tools/go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + testonly = True, + srcs = ["finality.go"], + importpath = "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/finality", + visibility = ["//visibility:public"], + deps = [ + "//beacon-chain/core/helpers:go_default_library", + "//beacon-chain/core/transition:go_default_library", + "//beacon-chain/state:go_default_library", + "//beacon-chain/state/state-native:go_default_library", + "//consensus-types/blocks: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", + ], +) diff --git a/testing/spectest/shared/deneb/finality/finality.go b/testing/spectest/shared/deneb/finality/finality.go new file mode 100644 index 000000000000..f8fc856c91aa --- /dev/null +++ b/testing/spectest/shared/deneb/finality/finality.go @@ -0,0 +1,83 @@ +package finality + +import ( + "context" + "fmt" + "testing" + + "github.com/golang/snappy" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/transition" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/state" + state_native "github.com/prysmaticlabs/prysm/v4/beacon-chain/state/state-native" + "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 init() { + transition.SkipSlotCache.Disable() +} + +type Config struct { + BlocksCount int `json:"blocks_count"` +} + +// RunFinalityTest executes finality spec tests. +func RunFinalityTest(t *testing.T, config string) { + require.NoError(t, utils.SetConfig(t, config)) + + testFolders, testsFolderPath := utils.TestFolders(t, config, "deneb", "finality/finality/pyspec_tests") + for _, folder := range testFolders { + t.Run(folder.Name(), func(t *testing.T) { + helpers.ClearCache() + 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") + beaconStateBase := ðpb.BeaconStateDeneb{} + require.NoError(t, beaconStateBase.UnmarshalSSZ(preBeaconStateSSZ), "Failed to unmarshal") + beaconState, err := state_native.InitializeFromProtoDeneb(beaconStateBase) + require.NoError(t, err) + + file, err := util.BazelFileBytes(testsFolderPath, folder.Name(), "meta.yaml") + require.NoError(t, err) + + metaYaml := &Config{} + require.NoError(t, utils.UnmarshalYaml(file, metaYaml), "Failed to Unmarshal") + + var processedState state.BeaconState + var ok bool + for i := 0; i < metaYaml.BlocksCount; i++ { + filename := fmt.Sprintf("blocks_%d.ssz_snappy", i) + blockFile, err := util.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.SignedBeaconBlockDeneb{} + require.NoError(t, block.UnmarshalSSZ(blockSSZ), "Failed to unmarshal") + wsb, err := blocks.NewSignedBeaconBlock(block) + require.NoError(t, err) + processedState, err = transition.ExecuteStateTransition(context.Background(), beaconState, wsb) + require.NoError(t, err) + beaconState, ok = processedState.(*state_native.BeaconState) + require.Equal(t, true, ok) + } + + postBeaconStateFile, err := util.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.BeaconStateDeneb{} + require.NoError(t, postBeaconState.UnmarshalSSZ(postBeaconStateSSZ), "Failed to unmarshal") + pbState, err := state_native.ProtobufBeaconStateDeneb(beaconState.ToProtoUnsafe()) + require.NoError(t, err) + if !proto.Equal(pbState, postBeaconState) { + t.Fatal("Post state does not match expected") + } + }) + } +} diff --git a/testing/spectest/shared/deneb/fork/BUILD.bazel b/testing/spectest/shared/deneb/fork/BUILD.bazel index e8449f7aa7f1..71a0b1b21425 100644 --- a/testing/spectest/shared/deneb/fork/BUILD.bazel +++ b/testing/spectest/shared/deneb/fork/BUILD.bazel @@ -3,13 +3,21 @@ load("@prysm//tools/go:def.bzl", "go_library") go_library( name = "go_default_library", testonly = True, - srcs = ["upgrade_to_deneb.go"], + srcs = [ + "transition.go", + "upgrade_to_capella.go", + "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/core/transition:go_default_library", "//beacon-chain/state/state-native:go_default_library", + "//config/params:go_default_library", + "//consensus-types/blocks:go_default_library", + "//consensus-types/primitives:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//testing/require:go_default_library", "//testing/spectest/utils:go_default_library", diff --git a/testing/spectest/shared/deneb/fork/transition.go b/testing/spectest/shared/deneb/fork/transition.go new file mode 100644 index 000000000000..aebedd5a6b04 --- /dev/null +++ b/testing/spectest/shared/deneb/fork/transition.go @@ -0,0 +1,125 @@ +package fork + +import ( + "context" + "fmt" + "testing" + + "github.com/golang/snappy" + "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" + "github.com/prysmaticlabs/prysm/v4/config/params" + "github.com/prysmaticlabs/prysm/v4/consensus-types/blocks" + types "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives" + 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" +) + +type ForkConfig struct { + PostFork string `json:"post_fork"` + ForkEpoch int `json:"fork_epoch"` + ForkBlock *int `json:"fork_block"` + BlocksCount int `json:"blocks_count"` +} + +// RunForkTransitionTest is a helper function that runs deneb's transition core tests. +func RunForkTransitionTest(t *testing.T, config string) { + params.SetupTestConfigCleanup(t) + require.NoError(t, utils.SetConfig(t, config)) + + testFolders, testsFolderPath := utils.TestFolders(t, config, "deneb", "transition/core/pyspec_tests") + for _, folder := range testFolders { + t.Run(folder.Name(), func(t *testing.T) { + helpers.ClearCache() + file, err := util.BazelFileBytes(testsFolderPath, folder.Name(), "meta.yaml") + require.NoError(t, err) + config := &ForkConfig{} + require.NoError(t, utils.UnmarshalYaml(file, config), "Failed to Unmarshal") + + preforkBlocks := make([]*ethpb.SignedBeaconBlockCapella, 0) + postforkBlocks := make([]*ethpb.SignedBeaconBlockDeneb, 0) + // Fork happens without any pre-fork blocks. + if config.ForkBlock == nil { + for i := 0; i < config.BlocksCount; i++ { + fileName := fmt.Sprint("blocks_", i, ".ssz_snappy") + blockFile, err := util.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.SignedBeaconBlockDeneb{} + require.NoError(t, block.UnmarshalSSZ(blockSSZ), "Failed to unmarshal") + postforkBlocks = append(postforkBlocks, block) + } + // Fork happens with pre-fork blocks. + } else { + for i := 0; i <= *config.ForkBlock; i++ { + fileName := fmt.Sprint("blocks_", i, ".ssz_snappy") + blockFile, err := util.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.SignedBeaconBlockCapella{} + require.NoError(t, block.UnmarshalSSZ(blockSSZ), "Failed to unmarshal") + preforkBlocks = append(preforkBlocks, block) + } + for i := *config.ForkBlock + 1; i < config.BlocksCount; i++ { + fileName := fmt.Sprint("blocks_", i, ".ssz_snappy") + blockFile, err := util.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.SignedBeaconBlockDeneb{} + require.NoError(t, block.UnmarshalSSZ(blockSSZ), "Failed to unmarshal") + postforkBlocks = append(postforkBlocks, block) + } + } + + 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") + beaconStateBase := ðpb.BeaconStateCapella{} + require.NoError(t, beaconStateBase.UnmarshalSSZ(preBeaconStateSSZ), "Failed to unmarshal") + beaconState, err := state_native.InitializeFromProtoCapella(beaconStateBase) + require.NoError(t, err) + + bc := params.BeaconConfig().Copy() + bc.DenebForkEpoch = types.Epoch(config.ForkEpoch) + params.OverrideBeaconConfig(bc) + + ctx := context.Background() + var ok bool + for _, b := range preforkBlocks { + wsb, err := blocks.NewSignedBeaconBlock(b) + require.NoError(t, err) + st, err := transition.ExecuteStateTransition(ctx, beaconState, wsb) + require.NoError(t, err) + beaconState, ok = st.(*state_native.BeaconState) + require.Equal(t, true, ok) + } + + for _, b := range postforkBlocks { + wsb, err := blocks.NewSignedBeaconBlock(b) + require.NoError(t, err) + st, err := transition.ExecuteStateTransition(ctx, beaconState, wsb) + require.NoError(t, err) + beaconState, ok = st.(*state_native.BeaconState) + require.Equal(t, true, ok) + } + + postBeaconStateFile, err := util.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.BeaconStateDeneb{} + require.NoError(t, postBeaconState.UnmarshalSSZ(postBeaconStateSSZ), "Failed to unmarshal") + + pbState, err := state_native.ProtobufBeaconStateDeneb(beaconState.ToProto()) + require.NoError(t, err) + require.DeepEqual(t, postBeaconState, pbState, "Did not get expected post state") + }) + } +} diff --git a/testing/spectest/shared/deneb/fork/upgrade_to_capella.go b/testing/spectest/shared/deneb/fork/upgrade_to_capella.go new file mode 100644 index 000000000000..5b109d950a0a --- /dev/null +++ b/testing/spectest/shared/deneb/fork/upgrade_to_capella.go @@ -0,0 +1,63 @@ +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" +) + +// RunUpgradeToDeneb4 is a helper function that runs Deneb4's fork spec tests. +// It unmarshals a pre- and post-state to check `UpgradeToDeneb4` comply with spec implementation. +func RunUpgradeToDeneb4(t *testing.T, config string) { + 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) { + if folder.Name() != "fork_next_epoch_with_block" { + t.Skip("Skipping non-upgrade_to_Deneb4 test") + } + 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") + } + }) + } +} diff --git a/testing/spectest/shared/deneb/operations/BUILD.bazel b/testing/spectest/shared/deneb/operations/BUILD.bazel new file mode 100644 index 000000000000..3474c7032840 --- /dev/null +++ b/testing/spectest/shared/deneb/operations/BUILD.bazel @@ -0,0 +1,39 @@ +load("@prysm//tools/go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + testonly = True, + srcs = [ + "attestation.go", + "attester_slashing.go", + "block_header.go", + "bls_to_execution_changes.go", + "deposit.go", + "helpers.go", + "proposer_slashing.go", + "sync_committee.go", + "voluntary_exit.go", + "withdrawals.go", + ], + importpath = "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/operations", + visibility = ["//testing/spectest:__subpackages__"], + deps = [ + "//beacon-chain/core/altair:go_default_library", + "//beacon-chain/core/blocks:go_default_library", + "//beacon-chain/core/helpers:go_default_library", + "//beacon-chain/core/validators:go_default_library", + "//beacon-chain/state:go_default_library", + "//beacon-chain/state/state-native:go_default_library", + "//consensus-types/blocks:go_default_library", + "//consensus-types/interfaces:go_default_library", + "//proto/engine/v1: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", + "@com_github_pkg_errors//:go_default_library", + "@io_bazel_rules_go//go/tools/bazel:go_default_library", + "@org_golang_google_protobuf//proto:go_default_library", + ], +) diff --git a/testing/spectest/shared/deneb/operations/attestation.go b/testing/spectest/shared/deneb/operations/attestation.go new file mode 100644 index 000000000000..d3952cc168ec --- /dev/null +++ b/testing/spectest/shared/deneb/operations/attestation.go @@ -0,0 +1,56 @@ +package operations + +import ( + "context" + "errors" + "path" + "testing" + + "github.com/golang/snappy" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/altair" + b "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/blocks" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/state" + "github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces" + 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" +) + +func RunAttestationTest(t *testing.T, config string) { + require.NoError(t, utils.SetConfig(t, config)) + testFolders, testsFolderPath := utils.TestFolders(t, config, "deneb", "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.Attestation{} + require.NoError(t, att.UnmarshalSSZ(attestationSSZ), "Failed to unmarshal") + + body := ðpb.BeaconBlockBodyDeneb{Attestations: []*ethpb.Attestation{att}} + processAtt := func(ctx context.Context, st state.BeaconState, blk interfaces.SignedBeaconBlock) (state.BeaconState, error) { + st, err = altair.ProcessAttestationsNoVerifySignature(ctx, st, blk) + 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) + }) + } +} diff --git a/testing/spectest/shared/deneb/operations/attester_slashing.go b/testing/spectest/shared/deneb/operations/attester_slashing.go new file mode 100644 index 000000000000..4b2eadd066c3 --- /dev/null +++ b/testing/spectest/shared/deneb/operations/attester_slashing.go @@ -0,0 +1,38 @@ +package operations + +import ( + "context" + "path" + "testing" + + "github.com/golang/snappy" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/blocks" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/validators" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/state" + "github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces" + 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" +) + +func RunAttesterSlashingTest(t *testing.T, config string) { + require.NoError(t, utils.SetConfig(t, config)) + testFolders, testsFolderPath := utils.TestFolders(t, config, "deneb", "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 := util.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(attSlashingSSZ), "Failed to unmarshal") + + body := ðpb.BeaconBlockBodyDeneb{AttesterSlashings: []*ethpb.AttesterSlashing{attSlashing}} + RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) { + return blocks.ProcessAttesterSlashings(ctx, s, b.Block().Body().AttesterSlashings(), validators.SlashValidator) + }) + }) + } +} diff --git a/testing/spectest/shared/deneb/operations/block_header.go b/testing/spectest/shared/deneb/operations/block_header.go new file mode 100644 index 000000000000..c54b755e41e0 --- /dev/null +++ b/testing/spectest/shared/deneb/operations/block_header.go @@ -0,0 +1,83 @@ +package operations + +import ( + "context" + "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" + 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" +) + +func RunBlockHeaderTest(t *testing.T, config string) { + require.NoError(t, utils.SetConfig(t, config)) + testFolders, testsFolderPath := utils.TestFolders(t, config, "deneb", "operations/block_header/pyspec_tests") + for _, folder := range testFolders { + t.Run(folder.Name(), func(t *testing.T) { + helpers.ClearCache() + blockFile, err := util.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.BeaconBlockDeneb{} + require.NoError(t, block.UnmarshalSSZ(blockSSZ), "Failed to unmarshal") + + 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) + + // 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_snappy")) + postSSZExists := true + if err != nil && strings.Contains(err.Error(), "could not locate file") { + postSSZExists = false + } else { + require.NoError(t, err) + } + + // Spectest blocks are not signed, so we'll call NoVerify to skip sig verification. + bodyRoot, err := block.Body.HashTreeRoot() + require.NoError(t, err) + beaconState, err := blocks.ProcessBlockHeaderNoVerify(context.Background(), preBeaconState, block.Slot, block.ProposerIndex, block.ParentRoot, bodyRoot[:]) + if postSSZExists { + require.NoError(t, err) + + 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(beaconState.ToProto()) + require.NoError(t, err) + if !proto.Equal(pbState, postBeaconState) { + t.Fatal("Post state does not match expected") + } + } else { + // Note: This doesn't test anything worthwhile. It essentially tests + // that *any* error has occurred, not any specific error. + if err == nil { + t.Fatal("Did not fail when expected") + } + t.Logf("Expected failure; failure reason = %v", err) + return + } + }) + } +} diff --git a/testing/spectest/shared/deneb/operations/bls_to_execution_changes.go b/testing/spectest/shared/deneb/operations/bls_to_execution_changes.go new file mode 100644 index 000000000000..7515b4b3c06c --- /dev/null +++ b/testing/spectest/shared/deneb/operations/bls_to_execution_changes.go @@ -0,0 +1,62 @@ +package operations + +import ( + "context" + "path" + "testing" + + "github.com/golang/snappy" + "github.com/pkg/errors" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/blocks" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/state" + "github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces" + 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" +) + +func RunBLSToExecutionChangeTest(t *testing.T, config string) { + require.NoError(t, utils.SetConfig(t, config)) + testFolders, testsFolderPath := utils.TestFolders(t, config, "deneb", "operations/bls_to_execution_change/pyspec_tests") + if len(testFolders) == 0 { + t.Fatalf("No test folders found for %s/%s/%s", config, "deneb", "operations/bls_to_execution_change/pyspec_tests") + } + for _, folder := range testFolders { + t.Run(folder.Name(), func(t *testing.T) { + folderPath := path.Join(testsFolderPath, folder.Name()) + changeFile, err := util.BazelFileBytes(folderPath, "address_change.ssz_snappy") + require.NoError(t, err) + changeSSZ, err := snappy.Decode(nil /* dst */, changeFile) + require.NoError(t, err, "Failed to decompress") + change := ðpb.SignedBLSToExecutionChange{} + require.NoError(t, change.UnmarshalSSZ(changeSSZ), "Failed to unmarshal") + + body := ðpb.BeaconBlockBodyDeneb{ + BlsToExecutionChanges: []*ethpb.SignedBLSToExecutionChange{change}, + } + RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) { + st, err := blocks.ProcessBLSToExecutionChanges(s, b) + if err != nil { + return nil, err + } + changes, err := b.Block().Body().BLSToExecutionChanges() + if err != nil { + return nil, err + } + cSet, err := blocks.BLSChangesSignatureBatch(st, changes) + if err != nil { + return nil, err + } + ok, err := cSet.Verify() + if err != nil { + return nil, err + } + if !ok { + return nil, errors.New("signature did not verify") + } + return st, nil + }) + }) + } +} diff --git a/testing/spectest/shared/deneb/operations/deposit.go b/testing/spectest/shared/deneb/operations/deposit.go new file mode 100644 index 000000000000..59a3982781ac --- /dev/null +++ b/testing/spectest/shared/deneb/operations/deposit.go @@ -0,0 +1,38 @@ +package operations + +import ( + "context" + "path" + "testing" + + "github.com/golang/snappy" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/altair" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/state" + "github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces" + 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" +) + +func RunDepositTest(t *testing.T, config string) { + require.NoError(t, utils.SetConfig(t, config)) + testFolders, testsFolderPath := utils.TestFolders(t, config, "deneb", "operations/deposit/pyspec_tests") + for _, folder := range testFolders { + t.Run(folder.Name(), func(t *testing.T) { + folderPath := path.Join(testsFolderPath, folder.Name()) + depositFile, err := util.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(depositSSZ), "Failed to unmarshal") + + body := ðpb.BeaconBlockBodyDeneb{Deposits: []*ethpb.Deposit{deposit}} + processDepositsFunc := func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) { + return altair.ProcessDeposits(ctx, s, b.Block().Body().Deposits()) + } + RunBlockOperationTest(t, folderPath, body, processDepositsFunc) + }) + } +} diff --git a/testing/spectest/shared/deneb/operations/helpers.go b/testing/spectest/shared/deneb/operations/helpers.go new file mode 100644 index 000000000000..483b9470d963 --- /dev/null +++ b/testing/spectest/shared/deneb/operations/helpers.go @@ -0,0 +1,85 @@ +package operations + +import ( + "context" + "os" + "path" + "strings" + "testing" + + "github.com/bazelbuild/rules_go/go/tools/bazel" + "github.com/golang/snappy" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/state" + state_native "github.com/prysmaticlabs/prysm/v4/beacon-chain/state/state-native" + "github.com/prysmaticlabs/prysm/v4/consensus-types/blocks" + "github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces" + ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1" + "github.com/prysmaticlabs/prysm/v4/testing/require" + "github.com/prysmaticlabs/prysm/v4/testing/util" + "google.golang.org/protobuf/proto" +) + +type blockOperation func(context.Context, state.BeaconState, interfaces.SignedBeaconBlock) (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. +func RunBlockOperationTest( + t *testing.T, + folderPath string, + body *ethpb.BeaconBlockBodyDeneb, + operationFn blockOperation, +) { + preBeaconStateFile, err := util.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.BeaconStateDeneb{} + if err := preStateBase.UnmarshalSSZ(preBeaconStateSSZ); err != nil { + t.Fatalf("Failed to unmarshal: %v", err) + } + preState, err := state_native.InitializeFromProtoDeneb(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_snappy")) + postSSZExists := true + if err != nil && strings.Contains(err.Error(), "could not locate file") { + postSSZExists = false + } else if err != nil { + t.Fatal(err) + } + + helpers.ClearCache() + b := util.NewBeaconBlockDeneb() + b.Block.Body = body + wsb, err := blocks.NewSignedBeaconBlock(b) + require.NoError(t, err) + beaconState, err := operationFn(context.Background(), preState, wsb) + if postSSZExists { + require.NoError(t, err) + + 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{} + if err := postBeaconState.UnmarshalSSZ(postBeaconStateSSZ); err != nil { + t.Fatalf("Failed to unmarshal: %v", err) + } + pbState, err := state_native.ProtobufBeaconStateDeneb(beaconState.ToProtoUnsafe()) + require.NoError(t, err) + if !proto.Equal(pbState, postBeaconState) { + t.Error("Post state does not match expected") + } + } else { + // Note: This doesn't test anything worthwhile. It essentially tests + // that *any* error has occurred, not any specific error. + if err == nil { + t.Fatal("Did not fail when expected") + } + t.Logf("Expected failure; failure reason = %v", err) + return + } +} diff --git a/testing/spectest/shared/deneb/operations/proposer_slashing.go b/testing/spectest/shared/deneb/operations/proposer_slashing.go new file mode 100644 index 000000000000..f9a87c73c725 --- /dev/null +++ b/testing/spectest/shared/deneb/operations/proposer_slashing.go @@ -0,0 +1,38 @@ +package operations + +import ( + "context" + "path" + "testing" + + "github.com/golang/snappy" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/blocks" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/validators" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/state" + "github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces" + 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" +) + +func RunProposerSlashingTest(t *testing.T, config string) { + require.NoError(t, utils.SetConfig(t, config)) + testFolders, testsFolderPath := utils.TestFolders(t, config, "deneb", "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 := util.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(proposerSlashingSSZ), "Failed to unmarshal") + + body := ðpb.BeaconBlockBodyDeneb{ProposerSlashings: []*ethpb.ProposerSlashing{proposerSlashing}} + RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) { + return blocks.ProcessProposerSlashings(ctx, s, b.Block().Body().ProposerSlashings(), validators.SlashValidator) + }) + }) + } +} diff --git a/testing/spectest/shared/deneb/operations/sync_committee.go b/testing/spectest/shared/deneb/operations/sync_committee.go new file mode 100644 index 000000000000..b8756ccb8323 --- /dev/null +++ b/testing/spectest/shared/deneb/operations/sync_committee.go @@ -0,0 +1,41 @@ +package operations + +import ( + "context" + "path" + "testing" + + "github.com/golang/snappy" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/altair" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/state" + "github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces" + 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" +) + +func RunSyncCommitteeTest(t *testing.T, config string) { + require.NoError(t, utils.SetConfig(t, config)) + testFolders, testsFolderPath := utils.TestFolders(t, config, "deneb", "operations/sync_aggregate/pyspec_tests") + for _, folder := range testFolders { + t.Run(folder.Name(), func(t *testing.T) { + folderPath := path.Join(testsFolderPath, folder.Name()) + syncCommitteeFile, err := util.BazelFileBytes(folderPath, "sync_aggregate.ssz_snappy") + require.NoError(t, err) + syncCommitteeSSZ, err := snappy.Decode(nil /* dst */, syncCommitteeFile) + require.NoError(t, err, "Failed to decompress") + sc := ðpb.SyncAggregate{} + require.NoError(t, sc.UnmarshalSSZ(syncCommitteeSSZ), "Failed to unmarshal") + + body := ðpb.BeaconBlockBodyDeneb{SyncAggregate: sc} + RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) { + st, _, err := altair.ProcessSyncAggregate(context.Background(), s, body.SyncAggregate) + if err != nil { + return nil, err + } + return st, nil + }) + }) + } +} diff --git a/testing/spectest/shared/deneb/operations/voluntary_exit.go b/testing/spectest/shared/deneb/operations/voluntary_exit.go new file mode 100644 index 000000000000..2d74cbf5c628 --- /dev/null +++ b/testing/spectest/shared/deneb/operations/voluntary_exit.go @@ -0,0 +1,37 @@ +package operations + +import ( + "context" + "path" + "testing" + + "github.com/golang/snappy" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/blocks" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/state" + "github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces" + 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" +) + +func RunVoluntaryExitTest(t *testing.T, config string) { + require.NoError(t, utils.SetConfig(t, config)) + testFolders, testsFolderPath := utils.TestFolders(t, config, "deneb", "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 := util.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(exitSSZ), "Failed to unmarshal") + + body := ðpb.BeaconBlockBodyDeneb{VoluntaryExits: []*ethpb.SignedVoluntaryExit{voluntaryExit}} + RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) { + return blocks.ProcessVoluntaryExits(ctx, s, b.Block().Body().VoluntaryExits()) + }) + }) + } +} diff --git a/testing/spectest/shared/deneb/operations/withdrawals.go b/testing/spectest/shared/deneb/operations/withdrawals.go new file mode 100644 index 000000000000..b06407d57697 --- /dev/null +++ b/testing/spectest/shared/deneb/operations/withdrawals.go @@ -0,0 +1,49 @@ +package operations + +import ( + "context" + "path" + "testing" + + "github.com/golang/snappy" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/blocks" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/state" + consensusblocks "github.com/prysmaticlabs/prysm/v4/consensus-types/blocks" + "github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces" + enginev1 "github.com/prysmaticlabs/prysm/v4/proto/engine/v1" + 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" +) + +func RunWithdrawalsTest(t *testing.T, config string) { + require.NoError(t, utils.SetConfig(t, config)) + testFolders, testsFolderPath := utils.TestFolders(t, config, "deneb", "operations/withdrawals/pyspec_tests") + for _, folder := range testFolders { + t.Run(folder.Name(), func(t *testing.T) { + folderPath := path.Join(testsFolderPath, folder.Name()) + payloadFile, err := util.BazelFileBytes(folderPath, "execution_payload.ssz_snappy") + require.NoError(t, err) + payloadSSZ, err := snappy.Decode(nil /* dst */, payloadFile) + require.NoError(t, err, "Failed to decompress") + payload := &enginev1.ExecutionPayloadDeneb{} + require.NoError(t, payload.UnmarshalSSZ(payloadSSZ), "Failed to unmarshal") + + body := ðpb.BeaconBlockBodyDeneb{ExecutionPayload: payload} + RunBlockOperationTest(t, folderPath, body, func(_ context.Context, s state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) { + payload, err := b.Block().Body().Execution() + if err != nil { + return nil, err + } + withdrawals, err := payload.Withdrawals() + if err != nil { + return nil, err + } + p, err := consensusblocks.WrappedExecutionPayloadCapella(&enginev1.ExecutionPayloadCapella{Withdrawals: withdrawals}, 0) + require.NoError(t, err) + return blocks.ProcessWithdrawals(s, p) + }) + }) + } +} diff --git a/testing/spectest/shared/deneb/rewards/BUILD.bazel b/testing/spectest/shared/deneb/rewards/BUILD.bazel new file mode 100644 index 000000000000..678aeb982a75 --- /dev/null +++ b/testing/spectest/shared/deneb/rewards/BUILD.bazel @@ -0,0 +1,19 @@ +load("@prysm//tools/go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + testonly = True, + srcs = ["rewards_penalties.go"], + importpath = "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/rewards", + visibility = ["//testing/spectest:__subpackages__"], + deps = [ + "//beacon-chain/core/altair: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", + ], +) diff --git a/testing/spectest/shared/deneb/rewards/rewards_penalties.go b/testing/spectest/shared/deneb/rewards/rewards_penalties.go new file mode 100644 index 000000000000..18f4a85b3883 --- /dev/null +++ b/testing/spectest/shared/deneb/rewards/rewards_penalties.go @@ -0,0 +1,126 @@ +package rewards + +import ( + "context" + "encoding/binary" + "fmt" + "path" + "reflect" + "strings" + "testing" + + "github.com/golang/snappy" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/altair" + "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" +) + +// Delta contains list of rewards and penalties. +type Delta struct { + Rewards []uint64 `json:"rewards"` + Penalties []uint64 `json:"penalties"` +} + +// 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 +} + +// RunPrecomputeRewardsAndPenaltiesTests executes "rewards/{basic, leak, random}" tests. +func RunPrecomputeRewardsAndPenaltiesTests(t *testing.T, config string) { + require.NoError(t, utils.SetConfig(t, config)) + + _, testsFolderPath := utils.TestFolders(t, config, "deneb", "rewards") + testTypes, err := util.BazelListDirectories(testsFolderPath) + require.NoError(t, err) + + for _, testType := range testTypes { + testFolders, testsFolderPath := utils.TestFolders(t, config, "deneb", fmt.Sprintf("rewards/%s/pyspec_tests", testType)) + for _, folder := range testFolders { + helpers.ClearCache() + t.Run(fmt.Sprintf("%v/%v", testType, folder.Name()), func(t *testing.T) { + folderPath := path.Join(testsFolderPath, folder.Name()) + runPrecomputeRewardsAndPenaltiesTest(t, folderPath) + }) + } + } +} + +func runPrecomputeRewardsAndPenaltiesTest(t *testing.T, testFolderPath string) { + ctx := context.Background() + preBeaconStateFile, err := util.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.BeaconStateDeneb{} + require.NoError(t, preBeaconStateBase.UnmarshalSSZ(preBeaconStateSSZ), "Failed to unmarshal") + preBeaconState, err := state_native.InitializeFromProtoDeneb(preBeaconStateBase) + require.NoError(t, err) + + vp, bp, err := altair.InitializePrecomputeValidators(ctx, preBeaconState) + require.NoError(t, err) + vp, bp, err = altair.ProcessEpochParticipation(ctx, preBeaconState, bp, vp) + require.NoError(t, err) + deltas, err := altair.AttestationsDelta(preBeaconState, bp, vp) + require.NoError(t, err) + + rewards := make([]uint64, len(deltas)) + penalties := make([]uint64, len(deltas)) + for i, d := range deltas { + rewards[i] = d.HeadReward + d.SourceReward + d.TargetReward + penalties[i] = d.SourcePenalty + d.TargetPenalty + } + + totalSpecTestRewards := make([]uint64, len(rewards)) + totalSpecTestPenalties := make([]uint64, len(penalties)) + + // Fetch delta files. i.e. source_deltas.ssz_snappy, etc. + testfiles, err := util.BazelListFiles(path.Join(testFolderPath)) + require.NoError(t, err) + deltaFiles := make([]string, 0, len(testfiles)) + for _, tf := range testfiles { + if strings.Contains(tf, "deltas") { + deltaFiles = append(deltaFiles, tf) + } + } + if len(deltaFiles) == 0 { + t.Fatal("No delta files") + } + + for _, dFile := range deltaFiles { + sourceFile, err := util.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{} + require.NoError(t, d.unmarshalSSZ(sourceSSZ), "Failed to unmarshal") + for i, reward := range d.Rewards { + totalSpecTestRewards[i] += reward + } + for i, penalty := range d.Penalties { + totalSpecTestPenalties[i] += penalty + } + } + + if !reflect.DeepEqual(rewards, totalSpecTestRewards) { + t.Error("Rewards don't match") + t.Log(rewards) + t.Log(totalSpecTestRewards) + } + if !reflect.DeepEqual(penalties, totalSpecTestPenalties) { + t.Error("Penalties don't match") + t.Log(penalties) + t.Log(totalSpecTestPenalties) + } +} diff --git a/testing/spectest/shared/deneb/sanity/BUILD.bazel b/testing/spectest/shared/deneb/sanity/BUILD.bazel new file mode 100644 index 000000000000..69b2065de19e --- /dev/null +++ b/testing/spectest/shared/deneb/sanity/BUILD.bazel @@ -0,0 +1,27 @@ +load("@prysm//tools/go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + testonly = True, + srcs = [ + "block_processing.go", + "block_processing.yaml.go", + "slot_processing.go", + ], + importpath = "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/sanity", + visibility = ["//testing/spectest:__subpackages__"], + deps = [ + "//beacon-chain/core/helpers:go_default_library", + "//beacon-chain/core/transition:go_default_library", + "//beacon-chain/state:go_default_library", + "//beacon-chain/state/state-native:go_default_library", + "//consensus-types/blocks: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", + "@io_bazel_rules_go//go/tools/bazel:go_default_library", + "@org_golang_google_protobuf//proto:go_default_library", + ], +) diff --git a/testing/spectest/shared/deneb/sanity/block_processing.go b/testing/spectest/shared/deneb/sanity/block_processing.go new file mode 100644 index 000000000000..74a5934e0282 --- /dev/null +++ b/testing/spectest/shared/deneb/sanity/block_processing.go @@ -0,0 +1,110 @@ +package sanity + +import ( + "context" + "fmt" + "os" + "path" + "strings" + "testing" + + "github.com/bazelbuild/rules_go/go/tools/bazel" + "github.com/golang/snappy" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/transition" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/state" + state_native "github.com/prysmaticlabs/prysm/v4/beacon-chain/state/state-native" + "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 init() { + transition.SkipSlotCache.Disable() +} + +// RunBlockProcessingTest executes "sanity/blocks" tests. +func RunBlockProcessingTest(t *testing.T, config, folderPath string) { + require.NoError(t, utils.SetConfig(t, config)) + + testFolders, testsFolderPath := utils.TestFolders(t, config, "deneb", folderPath) + for _, folder := range testFolders { + t.Run(folder.Name(), func(t *testing.T) { + helpers.ClearCache() + 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") + beaconStateBase := ðpb.BeaconStateDeneb{} + require.NoError(t, beaconStateBase.UnmarshalSSZ(preBeaconStateSSZ), "Failed to unmarshal") + beaconState, err := state_native.InitializeFromProtoDeneb(beaconStateBase) + require.NoError(t, err) + + file, err := util.BazelFileBytes(testsFolderPath, folder.Name(), "meta.yaml") + require.NoError(t, err) + + metaYaml := &SanityConfig{} + require.NoError(t, utils.UnmarshalYaml(file, metaYaml), "Failed to Unmarshal") + + var transitionError error + var processedState state.BeaconState + var ok bool + for i := 0; i < metaYaml.BlocksCount; i++ { + filename := fmt.Sprintf("blocks_%d.ssz_snappy", i) + blockFile, err := util.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.SignedBeaconBlockDeneb{} + require.NoError(t, block.UnmarshalSSZ(blockSSZ), "Failed to unmarshal") + wsb, err := blocks.NewSignedBeaconBlock(block) + require.NoError(t, err) + processedState, transitionError = transition.ExecuteStateTransition(context.Background(), beaconState, wsb) + if transitionError != nil { + break + } + beaconState, ok = processedState.(*state_native.BeaconState) + require.Equal(t, true, ok) + } + + // 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_snappy")) + postSSZExists := true + if readError != nil && strings.Contains(readError.Error(), "could not locate file") { + postSSZExists = false + } else if readError != nil { + t.Fatal(readError) + } + + if postSSZExists { + if transitionError != nil { + t.Errorf("Unexpected error: %v", transitionError) + } + + 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(beaconState.ToProtoUnsafe()) + require.NoError(t, err) + if !proto.Equal(pbState, postBeaconState) { + t.Fatal("Post state does not match expected") + } + } else { + // Note: This doesn't test anything worthwhile. It essentially tests + // that *any* error has occurred, not any specific error. + if transitionError == nil { + t.Fatal("Did not fail when expected") + } + t.Logf("Expected failure; failure reason = %v", transitionError) + return + } + }) + } +} diff --git a/testing/spectest/shared/deneb/sanity/block_processing.yaml.go b/testing/spectest/shared/deneb/sanity/block_processing.yaml.go new file mode 100644 index 000000000000..3aae0d2baa8e --- /dev/null +++ b/testing/spectest/shared/deneb/sanity/block_processing.yaml.go @@ -0,0 +1,6 @@ +package sanity + +// SanityConfig -- +type SanityConfig struct { + BlocksCount int `json:"blocks_count"` +} diff --git a/testing/spectest/shared/deneb/sanity/slot_processing.go b/testing/spectest/shared/deneb/sanity/slot_processing.go new file mode 100644 index 000000000000..60e80474c12f --- /dev/null +++ b/testing/spectest/shared/deneb/sanity/slot_processing.go @@ -0,0 +1,61 @@ +package sanity + +import ( + "context" + "strconv" + "testing" + + "github.com/golang/snappy" + "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/transition" + 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" +) + +func init() { + transition.SkipSlotCache.Disable() +} + +// RunSlotProcessingTests executes "sanity/slots" tests. +func RunSlotProcessingTests(t *testing.T, config string) { + require.NoError(t, utils.SetConfig(t, config)) + + testFolders, testsFolderPath := utils.TestFolders(t, config, "deneb", "sanity/slots/pyspec_tests") + + for _, folder := range testFolders { + t.Run(folder.Name(), func(t *testing.T) { + 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") + base := ðpb.BeaconStateDeneb{} + require.NoError(t, base.UnmarshalSSZ(preBeaconStateSSZ), "Failed to unmarshal") + beaconState, err := state_native.InitializeFromProtoDeneb(base) + require.NoError(t, err) + + file, err := util.BazelFileBytes(testsFolderPath, folder.Name(), "slots.yaml") + require.NoError(t, err) + fileStr := string(file) + slotsCount, err := strconv.ParseUint(fileStr[:len(fileStr)-5], 10, 64) + require.NoError(t, err) + + postBeaconStateFile, err := util.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.BeaconStateDeneb{} + require.NoError(t, postBeaconState.UnmarshalSSZ(postBeaconStateSSZ), "Failed to unmarshal") + postState, err := transition.ProcessSlots(context.Background(), beaconState, beaconState.Slot().Add(slotsCount)) + require.NoError(t, err) + + pbState, err := state_native.ProtobufBeaconStateDeneb(postState.ToProto()) + require.NoError(t, err) + if !proto.Equal(pbState, postBeaconState) { + t.Fatal("Did not receive expected post state") + } + }) + } +} diff --git a/testing/spectest/shared/deneb/ssz_static/ssz_static.go b/testing/spectest/shared/deneb/ssz_static/ssz_static.go index 86eaafcd4f6b..5165a43b3e7f 100644 --- a/testing/spectest/shared/deneb/ssz_static/ssz_static.go +++ b/testing/spectest/shared/deneb/ssz_static/ssz_static.go @@ -19,14 +19,16 @@ func RunSSZStaticTests(t *testing.T, config string) { } func customHtr(t *testing.T, htrs []common.HTR, object interface{}) []common.HTR { - switch object.(type) { - case *ethpb.BeaconStateDeneb: - htrs = append(htrs, func(s interface{}) ([32]byte, error) { - beaconState, err := state_native.InitializeFromProtoDeneb(s.(*ethpb.BeaconStateDeneb)) - require.NoError(t, err) - return beaconState.HashTreeRoot(context.Background()) - }) + _, ok := object.(*ethpb.BeaconStateDeneb) + if !ok { + return htrs } + + htrs = append(htrs, func(s interface{}) ([32]byte, error) { + beaconState, err := state_native.InitializeFromProtoDeneb(s.(*ethpb.BeaconStateDeneb)) + require.NoError(t, err) + return beaconState.HashTreeRoot(context.Background()) + }) return htrs } @@ -47,12 +49,14 @@ func unmarshalledSSZ(t *testing.T, serializedBytes []byte, folderName string) (i case "AggregateAndProof": obj = ðpb.AggregateAttestationAndProof{} case "BeaconBlock": + t.Skip("Skipping BeaconBlock test") obj = ðpb.BeaconBlockDeneb{} case "BeaconBlockBody": obj = ðpb.BeaconBlockBodyDeneb{} case "BeaconBlockHeader": obj = ðpb.BeaconBlockHeader{} case "BeaconState": + t.Skip("Skipping BeaconState test") obj = ðpb.BeaconStateDeneb{} case "Checkpoint": obj = ðpb.Checkpoint{} @@ -82,6 +86,7 @@ func unmarshalledSSZ(t *testing.T, serializedBytes []byte, folderName string) (i case "SignedAggregateAndProof": obj = ðpb.SignedAggregateAttestationAndProof{} case "SignedBeaconBlock": + t.Skip("Skipping SignedBeaconBlock test") obj = ðpb.SignedBeaconBlockDeneb{} case "SignedBeaconBlockHeader": obj = ðpb.SignedBeaconBlockHeader{} From 6f32e9ba24238f10d9168d921e825fc9f9a77f6d Mon Sep 17 00:00:00 2001 From: terence tsao Date: Mon, 24 Jul 2023 06:17:26 -0700 Subject: [PATCH 2/4] fix: bad capella names --- .../mainnet/deneb/fork_helper/BUILD.bazel | 5 +- .../fork_helper/upgrade_to_capella_test.go | 11 ---- .../spectest/minimal/deneb/fork/BUILD.bazel | 5 +- .../deneb/fork/upgrade_to_capella_test.go | 11 ---- .../spectest/shared/deneb/fork/BUILD.bazel | 1 - .../shared/deneb/fork/upgrade_to_capella.go | 63 ------------------- 6 files changed, 2 insertions(+), 94 deletions(-) delete mode 100644 testing/spectest/mainnet/deneb/fork_helper/upgrade_to_capella_test.go delete mode 100644 testing/spectest/minimal/deneb/fork/upgrade_to_capella_test.go delete mode 100644 testing/spectest/shared/deneb/fork/upgrade_to_capella.go diff --git a/testing/spectest/mainnet/deneb/fork_helper/BUILD.bazel b/testing/spectest/mainnet/deneb/fork_helper/BUILD.bazel index 4b6f515979b4..f370420a4d28 100644 --- a/testing/spectest/mainnet/deneb/fork_helper/BUILD.bazel +++ b/testing/spectest/mainnet/deneb/fork_helper/BUILD.bazel @@ -3,10 +3,7 @@ load("@prysm//tools/go:def.bzl", "go_test") go_test( name = "go_default_test", size = "small", - srcs = [ - "upgrade_to_capella_test.go", - "upgrade_to_deneb_test.go", - ], + srcs = ["upgrade_to_deneb_test.go"], data = glob(["*.yaml"]) + [ "@consensus_spec_tests_mainnet//:test_data", ], diff --git a/testing/spectest/mainnet/deneb/fork_helper/upgrade_to_capella_test.go b/testing/spectest/mainnet/deneb/fork_helper/upgrade_to_capella_test.go deleted file mode 100644 index d80f62d39fcc..000000000000 --- a/testing/spectest/mainnet/deneb/fork_helper/upgrade_to_capella_test.go +++ /dev/null @@ -1,11 +0,0 @@ -package fork_helper - -import ( - "testing" - - "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/fork" -) - -func TestMainnet_Deneb_UpgradeToCapella(t *testing.T) { - fork.RunUpgradeToDeneb4(t, "mainnet") -} diff --git a/testing/spectest/minimal/deneb/fork/BUILD.bazel b/testing/spectest/minimal/deneb/fork/BUILD.bazel index 34def2a647a3..4c72a8287759 100644 --- a/testing/spectest/minimal/deneb/fork/BUILD.bazel +++ b/testing/spectest/minimal/deneb/fork/BUILD.bazel @@ -3,10 +3,7 @@ load("@prysm//tools/go:def.bzl", "go_test") go_test( name = "go_default_test", size = "small", - srcs = [ - "upgrade_to_capella_test.go", - "upgrade_to_deneb_test.go", - ], + srcs = ["upgrade_to_deneb_test.go"], data = glob(["*.yaml"]) + [ "@consensus_spec_tests_minimal//:test_data", ], diff --git a/testing/spectest/minimal/deneb/fork/upgrade_to_capella_test.go b/testing/spectest/minimal/deneb/fork/upgrade_to_capella_test.go deleted file mode 100644 index 8a0d781c8974..000000000000 --- a/testing/spectest/minimal/deneb/fork/upgrade_to_capella_test.go +++ /dev/null @@ -1,11 +0,0 @@ -package fork - -import ( - "testing" - - "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/fork" -) - -func TestMinimal_Deneb_UpgradeToDeneb(t *testing.T) { - fork.RunUpgradeToDeneb4(t, "minimal") -} diff --git a/testing/spectest/shared/deneb/fork/BUILD.bazel b/testing/spectest/shared/deneb/fork/BUILD.bazel index 71a0b1b21425..1d95c555bc15 100644 --- a/testing/spectest/shared/deneb/fork/BUILD.bazel +++ b/testing/spectest/shared/deneb/fork/BUILD.bazel @@ -5,7 +5,6 @@ go_library( testonly = True, srcs = [ "transition.go", - "upgrade_to_capella.go", "upgrade_to_deneb.go", ], importpath = "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/fork", diff --git a/testing/spectest/shared/deneb/fork/upgrade_to_capella.go b/testing/spectest/shared/deneb/fork/upgrade_to_capella.go deleted file mode 100644 index 5b109d950a0a..000000000000 --- a/testing/spectest/shared/deneb/fork/upgrade_to_capella.go +++ /dev/null @@ -1,63 +0,0 @@ -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" -) - -// RunUpgradeToDeneb4 is a helper function that runs Deneb4's fork spec tests. -// It unmarshals a pre- and post-state to check `UpgradeToDeneb4` comply with spec implementation. -func RunUpgradeToDeneb4(t *testing.T, config string) { - 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) { - if folder.Name() != "fork_next_epoch_with_block" { - t.Skip("Skipping non-upgrade_to_Deneb4 test") - } - 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") - } - }) - } -} From 4d626dc45a0621d1ae1bfd5ac4c4d33b71cf71ac Mon Sep 17 00:00:00 2001 From: terence tsao Date: Mon, 24 Jul 2023 07:04:47 -0700 Subject: [PATCH 3/4] fix: add mainnet withdrawals and bls spec tests --- testing/spectest/mainnet/deneb/operations/BUILD.bazel | 2 ++ .../deneb/operations/bls_to_execution_change_test.go | 11 +++++++++++ .../mainnet/deneb/operations/withdrawals_test.go | 11 +++++++++++ 3 files changed, 24 insertions(+) create mode 100644 testing/spectest/mainnet/deneb/operations/bls_to_execution_change_test.go create mode 100644 testing/spectest/mainnet/deneb/operations/withdrawals_test.go diff --git a/testing/spectest/mainnet/deneb/operations/BUILD.bazel b/testing/spectest/mainnet/deneb/operations/BUILD.bazel index 64cd0ffbba03..aae67fa87994 100644 --- a/testing/spectest/mainnet/deneb/operations/BUILD.bazel +++ b/testing/spectest/mainnet/deneb/operations/BUILD.bazel @@ -7,10 +7,12 @@ go_test( "attestation_test.go", "attester_slashing_test.go", "block_header_test.go", + "bls_to_execution_change_test.go", "deposit_test.go", "proposer_slashing_test.go", "sync_committee_test.go", "voluntary_exit_test.go", + "withdrawals_test.go", ], data = glob(["*.yaml"]) + [ "@consensus_spec_tests_mainnet//:test_data", diff --git a/testing/spectest/mainnet/deneb/operations/bls_to_execution_change_test.go b/testing/spectest/mainnet/deneb/operations/bls_to_execution_change_test.go new file mode 100644 index 000000000000..898c91182994 --- /dev/null +++ b/testing/spectest/mainnet/deneb/operations/bls_to_execution_change_test.go @@ -0,0 +1,11 @@ +package operations + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/operations" +) + +func TestMainnet_Deneb_Operations_BLSToExecutionChange(t *testing.T) { + operations.RunBLSToExecutionChangeTest(t, "mainnet") +} diff --git a/testing/spectest/mainnet/deneb/operations/withdrawals_test.go b/testing/spectest/mainnet/deneb/operations/withdrawals_test.go new file mode 100644 index 000000000000..0df254a6f0b9 --- /dev/null +++ b/testing/spectest/mainnet/deneb/operations/withdrawals_test.go @@ -0,0 +1,11 @@ +package operations + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v4/testing/spectest/shared/deneb/operations" +) + +func TestMainnet_Deneb_Operations_Withdrawals(t *testing.T) { + operations.RunWithdrawalsTest(t, "mainnet") +} From 9f2d53754588ce54b10e297e8c765246964e069c Mon Sep 17 00:00:00 2001 From: terence tsao Date: Tue, 25 Jul 2023 13:26:19 -0700 Subject: [PATCH 4/4] James feedback --- testing/spectest/shared/deneb/operations/withdrawals.go | 2 +- testing/spectest/shared/deneb/ssz_static/ssz_static.go | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/testing/spectest/shared/deneb/operations/withdrawals.go b/testing/spectest/shared/deneb/operations/withdrawals.go index b06407d57697..3b45d3d74280 100644 --- a/testing/spectest/shared/deneb/operations/withdrawals.go +++ b/testing/spectest/shared/deneb/operations/withdrawals.go @@ -40,7 +40,7 @@ func RunWithdrawalsTest(t *testing.T, config string) { if err != nil { return nil, err } - p, err := consensusblocks.WrappedExecutionPayloadCapella(&enginev1.ExecutionPayloadCapella{Withdrawals: withdrawals}, 0) + p, err := consensusblocks.WrappedExecutionPayloadDeneb(&enginev1.ExecutionPayloadDeneb{Withdrawals: withdrawals}, 0) require.NoError(t, err) return blocks.ProcessWithdrawals(s, p) }) diff --git a/testing/spectest/shared/deneb/ssz_static/ssz_static.go b/testing/spectest/shared/deneb/ssz_static/ssz_static.go index 5165a43b3e7f..a4d4154c523c 100644 --- a/testing/spectest/shared/deneb/ssz_static/ssz_static.go +++ b/testing/spectest/shared/deneb/ssz_static/ssz_static.go @@ -49,14 +49,12 @@ func unmarshalledSSZ(t *testing.T, serializedBytes []byte, folderName string) (i case "AggregateAndProof": obj = ðpb.AggregateAttestationAndProof{} case "BeaconBlock": - t.Skip("Skipping BeaconBlock test") obj = ðpb.BeaconBlockDeneb{} case "BeaconBlockBody": obj = ðpb.BeaconBlockBodyDeneb{} case "BeaconBlockHeader": obj = ðpb.BeaconBlockHeader{} case "BeaconState": - t.Skip("Skipping BeaconState test") obj = ðpb.BeaconStateDeneb{} case "Checkpoint": obj = ðpb.Checkpoint{} @@ -86,7 +84,6 @@ func unmarshalledSSZ(t *testing.T, serializedBytes []byte, folderName string) (i case "SignedAggregateAndProof": obj = ðpb.SignedAggregateAttestationAndProof{} case "SignedBeaconBlock": - t.Skip("Skipping SignedBeaconBlock test") obj = ðpb.SignedBeaconBlockDeneb{} case "SignedBeaconBlockHeader": obj = ðpb.SignedBeaconBlockHeader{}