Bellatrix spec tests (#10014)

* Add merge spectests

* fix build

* gazelle

* operation

* all tests should pass

* go fmt

* fix test

* fix dependency

* rm unused constants

* rename to bellatrix

* Gaz

* Rm unused files

* Use Bellatrix for test names

* Add more spec tests

* Gaz and fix test

* sync with dev

* Preston's feedback

* Go fmt

* sync with dev

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
terence tsao
2022-01-10 10:27:08 -08:00
committed by GitHub
parent b1c2454658
commit 84335b0084
101 changed files with 2621 additions and 1 deletions

View File

@@ -4,7 +4,11 @@ go_library(
name = "go_default_library",
srcs = ["upgrade.go"],
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/core/execution",
visibility = ["//beacon-chain:__subpackages__"],
visibility = [
"//beacon-chain:__subpackages__",
"//testing/spectest:__subpackages__",
"//validator/client:__pkg__",
],
deps = [
"//beacon-chain/core/time:go_default_library",
"//beacon-chain/state:go_default_library",

View File

@@ -33,6 +33,7 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/state/v3",
visibility = [
"//beacon-chain:__subpackages__",
"//testing/spectest:__subpackages__",
"//testing/util:__pkg__",
],
deps = [

View File

@@ -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_roots_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/bellatrix/epoch_processing:go_default_library"],
)

View File

@@ -0,0 +1,11 @@
package epoch_processing
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/epoch_processing"
)
func TestMainnet_Bellatrix_EpochProcessing_EffectiveBalanceUpdates(t *testing.T) {
epoch_processing.RunEffectiveBalanceUpdatesTests(t, "mainnet")
}

View File

@@ -0,0 +1,11 @@
package epoch_processing
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/epoch_processing"
)
func TestMainnet_Bellatrix_EpochProcessing_Eth1DataReset(t *testing.T) {
epoch_processing.RunEth1DataResetTests(t, "mainnet")
}

View File

@@ -0,0 +1,11 @@
package epoch_processing
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/epoch_processing"
)
func TestMainnet_Bellatrix_EpochProcessing_HistoricalRootsUpdate(t *testing.T) {
epoch_processing.RunHistoricalRootsUpdateTests(t, "mainnet")
}

View File

@@ -0,0 +1,11 @@
package epoch_processing
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/epoch_processing"
)
func TestMainnet_Bellatrix_EpochProcessing_InactivityUpdates(t *testing.T) {
epoch_processing.RunInactivityUpdatesTest(t, "mainnet")
}

View File

@@ -0,0 +1,11 @@
package epoch_processing
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/epoch_processing"
)
func TestMainnet_Bellatrix_EpochProcessing_JustificationAndFinalization(t *testing.T) {
epoch_processing.RunJustificationAndFinalizationTests(t, "mainnet")
}

View File

@@ -0,0 +1,11 @@
package epoch_processing
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/epoch_processing"
)
func TestMainnet_Bellatrix_EpochProcessing_ParticipationFlag(t *testing.T) {
epoch_processing.RunParticipationFlagUpdatesTests(t, "mainnet")
}

View File

@@ -0,0 +1,11 @@
package epoch_processing
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/epoch_processing"
)
func TestMainnet_Bellatrix_EpochProcessing_RandaoMixesReset(t *testing.T) {
epoch_processing.RunRandaoMixesResetTests(t, "mainnet")
}

View File

@@ -0,0 +1,11 @@
package epoch_processing
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/epoch_processing"
)
func TestMainnet_Bellatrix_EpochProcessing_ResetRegistryUpdates(t *testing.T) {
epoch_processing.RunRegistryUpdatesTests(t, "mainnet")
}

View File

@@ -0,0 +1,11 @@
package epoch_processing
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/epoch_processing"
)
func TestMainnet_Bellatrix_EpochProcessing_RewardsAndPenalties(t *testing.T) {
epoch_processing.RunRewardsAndPenaltiesTests(t, "mainnet")
}

View File

@@ -0,0 +1,11 @@
package epoch_processing
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/epoch_processing"
)
func TestMainnet_Bellatrix_EpochProcessing_SlashingsReset(t *testing.T) {
epoch_processing.RunSlashingsResetTests(t, "mainnet")
}

View File

@@ -0,0 +1,11 @@
package epoch_processing
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/epoch_processing"
)
func TestMainnet_Bellatrix_EpochProcessing_Slashings(t *testing.T) {
epoch_processing.RunSlashingsTests(t, "mainnet")
}

View File

@@ -0,0 +1,13 @@
load("@prysm//tools/go:def.bzl", "go_test")
go_test(
name = "go_default_test",
size = "medium",
srcs = ["finality_test.go"],
data = glob(["*.yaml"]) + [
"@consensus_spec_tests_mainnet//:test_data",
],
shard_count = 4,
tags = ["spectest"],
deps = ["//testing/spectest/shared/bellatrix/finality:go_default_library"],
)

View File

@@ -0,0 +1,11 @@
package finality
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/finality"
)
func TestMainnet_Bellatrix_Finality(t *testing.T) {
finality.RunFinalityTest(t, "mainnet")
}

View File

@@ -0,0 +1,13 @@
load("@prysm//tools/go:def.bzl", "go_test")
go_test(
name = "go_default_test",
size = "small",
srcs = ["upgrade_to_altair_test.go"],
data = glob(["*.yaml"]) + [
"@consensus_spec_tests_mainnet//:test_data",
],
shard_count = 4,
tags = ["spectest"],
deps = ["//testing/spectest/shared/bellatrix/fork:go_default_library"],
)

View File

@@ -0,0 +1,11 @@
package fork_helper
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/fork"
)
func TestMainnet_Bellatrix_UpgradeToBellatrix(t *testing.T) {
fork.RunUpgradeToBellatrix(t, "mainnet")
}

View File

@@ -0,0 +1,11 @@
load("@prysm//tools/go:def.bzl", "go_test")
go_test(
name = "go_default_test",
srcs = ["transition_test.go"],
data = glob(["*.yaml"]) + [
"@consensus_spec_tests_mainnet//:test_data",
],
tags = ["spectest"],
deps = ["//testing/spectest/shared/bellatrix/fork:go_default_library"],
)

View File

@@ -0,0 +1,11 @@
package fork_transition
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/fork"
)
func TestMainnet_Bellatrix_Transition(t *testing.T) {
fork.RunForkTransitionTest(t, "mainnet")
}

View File

@@ -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/bellatrix/operations:go_default_library"],
)

View File

@@ -0,0 +1,11 @@
package operations
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/operations"
)
func TestMainnet_Bellatrix_Operations_Attestation(t *testing.T) {
operations.RunAttestationTest(t, "mainnet")
}

View File

@@ -0,0 +1,11 @@
package operations
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/operations"
)
func TestMainnet_Bellatrix_Operations_AttesterSlashing(t *testing.T) {
operations.RunAttesterSlashingTest(t, "mainnet")
}

View File

@@ -0,0 +1,11 @@
package operations
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/operations"
)
func TestMainnet_Bellatrix_Operations_BlockHeader(t *testing.T) {
operations.RunBlockHeaderTest(t, "mainnet")
}

View File

@@ -0,0 +1,11 @@
package operations
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/operations"
)
func TestMainnet_Bellatrix_Operations_Deposit(t *testing.T) {
operations.RunDepositTest(t, "mainnet")
}

View File

@@ -0,0 +1,11 @@
package operations
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/operations"
)
func TestMainnet_Bellatrix_Operations_ProposerSlashing(t *testing.T) {
operations.RunProposerSlashingTest(t, "mainnet")
}

View File

@@ -0,0 +1,11 @@
package operations
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/operations"
)
func TestMainnet_Bellatrix_Operations_SyncCommittee(t *testing.T) {
operations.RunSyncCommitteeTest(t, "mainnet")
}

View File

@@ -0,0 +1,11 @@
package operations
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/operations"
)
func TestMainnet_Bellatrix_Operations_VoluntaryExit(t *testing.T) {
operations.RunVoluntaryExitTest(t, "mainnet")
}

View File

@@ -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/bellatrix/rewards:go_default_library"],
)

View File

@@ -0,0 +1,11 @@
package rewards
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/rewards"
)
func TestMainnet_Bellatrix_Rewards(t *testing.T) {
rewards.RunPrecomputeRewardsAndPenaltiesTests(t, "mainnet")
}

View File

@@ -0,0 +1,15 @@
load("@prysm//tools/go:def.bzl", "go_test")
go_test(
name = "go_default_test",
size = "medium",
srcs = [
"blocks_test.go",
"slots_test.go",
],
data = glob(["*.yaml"]) + [
"@consensus_spec_tests_mainnet//:test_data",
],
tags = ["spectest"],
deps = ["//testing/spectest/shared/bellatrix/sanity:go_default_library"],
)

View File

@@ -0,0 +1,11 @@
package sanity
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/sanity"
)
func TestMainnet_Bellatrix_Sanity_Blocks(t *testing.T) {
sanity.RunBlockProcessingTest(t, "mainnet", "sanity/blocks/pyspec_tests")
}

View File

@@ -0,0 +1,11 @@
package sanity
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/sanity"
)
func TestMainnet_Bellatrix_Sanity_Slots(t *testing.T) {
sanity.RunSlotProcessingTests(t, "mainnet")
}

View File

@@ -0,0 +1,12 @@
load("@prysm//tools/go:def.bzl", "go_test")
go_test(
name = "go_default_test",
size = "small",
srcs = ["ssz_static_test.go"],
data = glob(["*.yaml"]) + [
"@consensus_spec_tests_mainnet//:test_data",
],
tags = ["spectest"],
deps = ["//testing/spectest/shared/bellatrix/ssz_static:go_default_library"],
)

View File

@@ -0,0 +1,11 @@
package ssz_static
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/ssz_static"
)
func TestMainnet_Bellatrix_SSZStatic(t *testing.T) {
ssz_static.RunSSZStaticTests(t, "mainnet")
}

View File

@@ -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_roots_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/bellatrix/epoch_processing:go_default_library"],
)

View File

@@ -0,0 +1,11 @@
package epoch_processing
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/epoch_processing"
)
func TestMinimal_Bellatrix_EpochProcessing_EffectiveBalanceUpdates(t *testing.T) {
epoch_processing.RunEffectiveBalanceUpdatesTests(t, "minimal")
}

View File

@@ -0,0 +1,11 @@
package epoch_processing
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/epoch_processing"
)
func TestMinimal_Bellatrix_EpochProcessing_Eth1DataReset(t *testing.T) {
epoch_processing.RunEth1DataResetTests(t, "minimal")
}

View File

@@ -0,0 +1,11 @@
package epoch_processing
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/epoch_processing"
)
func TestMinimal_Bellatrix_EpochProcessing_HistoricalRootsUpdate(t *testing.T) {
epoch_processing.RunHistoricalRootsUpdateTests(t, "minimal")
}

View File

@@ -0,0 +1,11 @@
package epoch_processing
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/epoch_processing"
)
func TestMinimal_Bellatrix_EpochProcessing_InactivityUpdates(t *testing.T) {
epoch_processing.RunInactivityUpdatesTest(t, "minimal")
}

View File

@@ -0,0 +1,11 @@
package epoch_processing
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/epoch_processing"
)
func TestMinimal_Bellatrix_EpochProcessing_JustificationAndFinalization(t *testing.T) {
epoch_processing.RunJustificationAndFinalizationTests(t, "minimal")
}

View File

@@ -0,0 +1,11 @@
package epoch_processing
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/epoch_processing"
)
func TestMinimal_Bellatrix_EpochProcessing_ParticipationFlag(t *testing.T) {
epoch_processing.RunParticipationFlagUpdatesTests(t, "minimal")
}

View File

@@ -0,0 +1,11 @@
package epoch_processing
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/epoch_processing"
)
func TestMinimal_Bellatrix_EpochProcessing_RandaoMixesReset(t *testing.T) {
epoch_processing.RunRandaoMixesResetTests(t, "minimal")
}

View File

@@ -0,0 +1,11 @@
package epoch_processing
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/epoch_processing"
)
func TestMinimal_Bellatrix_EpochProcessing_ResetRegistryUpdates(t *testing.T) {
epoch_processing.RunRegistryUpdatesTests(t, "minimal")
}

View File

@@ -0,0 +1,11 @@
package epoch_processing
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/epoch_processing"
)
func TestMinimal_Bellatrix_EpochProcessing_RewardsAndPenalties(t *testing.T) {
epoch_processing.RunRewardsAndPenaltiesTests(t, "minimal")
}

View File

@@ -0,0 +1,11 @@
package epoch_processing
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/epoch_processing"
)
func TestMinimal_Bellatrix_EpochProcessing_SlashingsReset(t *testing.T) {
epoch_processing.RunSlashingsResetTests(t, "minimal")
}

View File

@@ -0,0 +1,11 @@
package epoch_processing
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/epoch_processing"
)
func TestMinimal_Bellatrix_EpochProcessing_Slashings(t *testing.T) {
epoch_processing.RunSlashingsTests(t, "minimal")
}

View File

@@ -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/bellatrix/finality:go_default_library"],
)

View File

@@ -0,0 +1,11 @@
package finality
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/finality"
)
func TestMinimal_Bellatrix_Finality(t *testing.T) {
finality.RunFinalityTest(t, "minimal")
}

View File

@@ -0,0 +1,17 @@
load("@prysm//tools/go:def.bzl", "go_test")
go_test(
name = "go_default_test",
size = "small",
srcs = ["upgrade_to_altair_test.go"],
data = glob(["*.yaml"]) + [
"@consensus_spec_tests_minimal//:test_data",
],
eth_network = "minimal",
shard_count = 4,
tags = [
"minimal",
"spectest",
],
deps = ["//testing/spectest/shared/bellatrix/fork:go_default_library"],
)

View File

@@ -0,0 +1,11 @@
package fork
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/fork"
)
func TestMinimal_Bellatrix_UpgradeToMerge(t *testing.T) {
fork.RunUpgradeToBellatrix(t, "minimal")
}

View File

@@ -0,0 +1,24 @@
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_minimal//:test_data",
],
eth_network = "minimal",
tags = [
"minimal",
"spectest",
],
deps = ["//testing/spectest/shared/bellatrix/operations:go_default_library"],
)

View File

@@ -0,0 +1,11 @@
package operations
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/operations"
)
func TestMinimal_Bellatrix_Operations_Attestation(t *testing.T) {
operations.RunAttestationTest(t, "minimal")
}

View File

@@ -0,0 +1,11 @@
package operations
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/operations"
)
func TestMinimal_Bellatrix_Operations_AttesterSlashing(t *testing.T) {
operations.RunAttesterSlashingTest(t, "minimal")
}

View File

@@ -0,0 +1,11 @@
package operations
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/operations"
)
func TestMinimal_Bellatrix_Operations_BlockHeader(t *testing.T) {
operations.RunBlockHeaderTest(t, "minimal")
}

View File

@@ -0,0 +1,11 @@
package operations
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/operations"
)
func TestMinimal_Bellatrix_Operations_Deposit(t *testing.T) {
operations.RunDepositTest(t, "minimal")
}

View File

@@ -0,0 +1,11 @@
package operations
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/operations"
)
func TestMinimal_Bellatrix_Operations_ProposerSlashing(t *testing.T) {
operations.RunProposerSlashingTest(t, "minimal")
}

View File

@@ -0,0 +1,11 @@
package operations
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/operations"
)
func TestMinimal_Bellatrix_Operations_SyncCommittee(t *testing.T) {
operations.RunProposerSlashingTest(t, "minimal")
}

View File

@@ -0,0 +1,11 @@
package operations
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/operations"
)
func TestMinimal_Bellatrix_Operations_VoluntaryExit(t *testing.T) {
operations.RunVoluntaryExitTest(t, "minimal")
}

View File

@@ -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/bellatrix/rewards:go_default_library"],
)

View File

@@ -0,0 +1,11 @@
package rewards
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/rewards"
)
func TestMinimal_Bellatrix_Rewards(t *testing.T) {
rewards.RunPrecomputeRewardsAndPenaltiesTests(t, "minimal")
}

View File

@@ -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/bellatrix/sanity:go_default_library"],
)

View File

@@ -0,0 +1,11 @@
package sanity
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/sanity"
)
func TestMinimal_Bellatrix_Sanity_Blocks(t *testing.T) {
sanity.RunBlockProcessingTest(t, "minimal", "sanity/blocks/pyspec_tests")
}

View File

@@ -0,0 +1,11 @@
package sanity
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/sanity"
)
func TestMinimal_Bellatrix_Sanity_Slots(t *testing.T) {
sanity.RunSlotProcessingTests(t, "minimal")
}

View File

@@ -0,0 +1,16 @@
load("@prysm//tools/go:def.bzl", "go_test")
go_test(
name = "go_default_test",
size = "small",
srcs = ["ssz_static_test.go"],
data = glob(["*.yaml"]) + [
"@consensus_spec_tests_minimal//:test_data",
],
eth_network = "minimal",
tags = [
"minimal",
"spectest",
],
deps = ["//testing/spectest/shared/bellatrix/ssz_static:go_default_library"],
)

View File

@@ -0,0 +1,11 @@
package ssz_static
import (
"testing"
"github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/ssz_static"
)
func TestMinimal_Bellatrix_SSZStatic(t *testing.T) {
ssz_static.RunSSZStaticTests(t, "minimal")
}

View File

@@ -0,0 +1,39 @@
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_roots_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/testing/spectest/shared/bellatrix/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/v3: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",
"@in_gopkg_d4l3k_messagediff_v1//:go_default_library",
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
"@org_golang_google_protobuf//proto:go_default_library",
],
)

View File

@@ -0,0 +1,30 @@
package epoch_processing
import (
"path"
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/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, "bellatrix", "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, state state.BeaconState) (state.BeaconState, error) {
state, err := epoch.ProcessEffectiveBalanceUpdates(state)
require.NoError(t, err, "Could not process final updates")
return state, nil
}

View File

@@ -0,0 +1,30 @@
package epoch_processing
import (
"path"
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/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, "bellatrix", "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, state state.BeaconState) (state.BeaconState, error) {
state, err := epoch.ProcessEth1DataReset(state)
require.NoError(t, err, "Could not process final updates")
return state, nil
}

View File

@@ -0,0 +1,78 @@
package epoch_processing
import (
"io/ioutil"
"path"
"strings"
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
"github.com/golang/snappy"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
v3 "github.com/prysmaticlabs/prysm/beacon-chain/state/v3"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/testing/util"
"google.golang.org/protobuf/proto"
"gopkg.in/d4l3k/messagediff.v1"
)
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 := &ethpb.BeaconStateBellatrix{}
if err := preBeaconStateBase.UnmarshalSSZ(preBeaconStateSSZ); err != nil {
t.Fatalf("Failed to unmarshal: %v", err)
}
preBeaconState, err := v3.InitializeFromProto(preBeaconStateBase)
require.NoError(t, err)
// If the post.ssz is not present, it means the test should fail on our end.
postSSZFilepath, err := bazel.Runfile(path.Join(testFolderPath, "post.ssz_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 := ioutil.ReadFile(postSSZFilepath) // #nosec G304
require.NoError(t, err)
postBeaconStateSSZ, err := snappy.Decode(nil /* dst */, postBeaconStateFile)
require.NoError(t, err, "Failed to decompress")
postBeaconState := &ethpb.BeaconStateBellatrix{}
if err := postBeaconState.UnmarshalSSZ(postBeaconStateSSZ); err != nil {
t.Fatalf("Failed to unmarshal: %v", err)
}
pbState, err := v3.ProtobufBeaconState(beaconState.InnerStateUnsafe())
require.NoError(t, err)
if !proto.Equal(pbState, postBeaconState) {
diff, _ := messagediff.PrettyDiff(beaconState.InnerStateUnsafe(), postBeaconState)
t.Log(diff)
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
}
}

View File

@@ -0,0 +1,30 @@
package epoch_processing
import (
"path"
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/testing/spectest/utils"
)
// RunHistoricalRootsUpdateTests executes "epoch_processing/historical_roots_update" tests.
func RunHistoricalRootsUpdateTests(t *testing.T, config string) {
require.NoError(t, utils.SetConfig(t, config))
testFolders, testsFolderPath := utils.TestFolders(t, config, "bellatrix", "epoch_processing/historical_roots_update/pyspec_tests")
for _, folder := range testFolders {
t.Run(folder.Name(), func(t *testing.T) {
folderPath := path.Join(testsFolderPath, folder.Name())
RunEpochOperationTest(t, folderPath, processHistoricalRootsUpdateWrapper)
})
}
}
func processHistoricalRootsUpdateWrapper(t *testing.T, state state.BeaconState) (state.BeaconState, error) {
state, err := epoch.ProcessHistoricalRootsUpdate(state)
require.NoError(t, err, "Could not process final updates")
return state, nil
}

View File

@@ -0,0 +1,41 @@
package epoch_processing
import (
"context"
"path"
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/core/altair"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/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, "bellatrix", 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
}

View File

@@ -0,0 +1,40 @@
package epoch_processing
import (
"context"
"path"
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/core/altair"
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch/precompute"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/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, "bellatrix", 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
}

View File

@@ -0,0 +1,30 @@
package epoch_processing
import (
"path"
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/core/altair"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/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, "bellatrix", "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, state state.BeaconState) (state.BeaconState, error) {
state, err := altair.ProcessParticipationFlagUpdates(state)
require.NoError(t, err, "Could not process participation flag update")
return state, nil
}

View File

@@ -0,0 +1,30 @@
package epoch_processing
import (
"path"
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/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, "bellatrix", "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, state state.BeaconState) (state.BeaconState, error) {
state, err := epoch.ProcessRandaoMixesReset(state)
require.NoError(t, err, "Could not process final updates")
return state, nil
}

View File

@@ -0,0 +1,34 @@
package epoch_processing
import (
"context"
"path"
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/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, "bellatrix", "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(t *testing.T, state state.BeaconState) (state.BeaconState, error) {
state, err := epoch.ProcessRegistryUpdates(context.Background(), state)
require.NoError(t, err, "Could not process registry updates")
return state, nil
}

View File

@@ -0,0 +1,41 @@
package epoch_processing
import (
"context"
"path"
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/core/altair"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/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, "bellatrix", 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
}

View File

@@ -0,0 +1,33 @@
package epoch_processing
import (
"path"
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/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, "bellatrix", "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, state state.BeaconState) (state.BeaconState, error) {
state, err := epoch.ProcessSlashings(state, params.BeaconConfig().ProportionalSlashingMultiplierMerge)
require.NoError(t, err, "Could not process slashings")
return state, nil
}

View File

@@ -0,0 +1,30 @@
package epoch_processing
import (
"path"
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/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, "bellatrix", "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, state state.BeaconState) (state.BeaconState, error) {
state, err := epoch.ProcessSlashingsReset(state)
require.NoError(t, err, "Could not process final updates")
return state, nil
}

View File

@@ -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/testing/spectest/shared/bellatrix/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/v3:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v1alpha1/wrapper: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",
],
)

View File

@@ -0,0 +1,83 @@
package finality
import (
"context"
"fmt"
"testing"
"github.com/golang/snappy"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/transition"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
v3 "github.com/prysmaticlabs/prysm/beacon-chain/state/v3"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/testing/spectest/utils"
"github.com/prysmaticlabs/prysm/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, "bellatrix", "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 := &ethpb.BeaconStateBellatrix{}
require.NoError(t, beaconStateBase.UnmarshalSSZ(preBeaconStateSSZ), "Failed to unmarshal")
beaconState, err := v3.InitializeFromProto(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 := &ethpb.SignedBeaconBlockMerge{}
require.NoError(t, block.UnmarshalSSZ(blockSSZ), "Failed to unmarshal")
wsb, err := wrapper.WrappedMergeSignedBeaconBlock(block)
require.NoError(t, err)
processedState, err = transition.ExecuteStateTransition(context.Background(), beaconState, wsb)
require.NoError(t, err)
beaconState, ok = processedState.(*v3.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 := &ethpb.BeaconStateBellatrix{}
require.NoError(t, postBeaconState.UnmarshalSSZ(postBeaconStateSSZ), "Failed to unmarshal")
pbState, err := v3.ProtobufBeaconState(beaconState.InnerStateUnsafe())
require.NoError(t, err)
if !proto.Equal(pbState, postBeaconState) {
t.Fatal("Post state does not match expected")
}
})
}
}

View File

@@ -0,0 +1,29 @@
load("@prysm//tools/go:def.bzl", "go_library")
go_library(
name = "go_default_library",
testonly = True,
srcs = [
"transition.go",
"upgrade_to_altair.go",
],
importpath = "github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/fork",
visibility = ["//visibility:public"],
deps = [
"//beacon-chain/core/execution:go_default_library",
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/core/transition:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/v2:go_default_library",
"//beacon-chain/state/v3:go_default_library",
"//config/params:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v1alpha1/wrapper: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_prysmaticlabs_eth2_types//:go_default_library",
"@org_golang_google_protobuf//proto:go_default_library",
],
)

View File

@@ -0,0 +1,126 @@
package fork
import (
"context"
"fmt"
"testing"
"github.com/golang/snappy"
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/transition"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
v2 "github.com/prysmaticlabs/prysm/beacon-chain/state/v2"
v3 "github.com/prysmaticlabs/prysm/beacon-chain/state/v3"
"github.com/prysmaticlabs/prysm/config/params"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/testing/spectest/utils"
"github.com/prysmaticlabs/prysm/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 bellatrix's transition core tests.
func RunForkTransitionTest(t *testing.T, config string) {
require.NoError(t, utils.SetConfig(t, config))
testFolders, testsFolderPath := utils.TestFolders(t, config, "bellatrix", "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.SignedBeaconBlockAltair, 0)
postforkBlocks := make([]*ethpb.SignedBeaconBlockMerge, 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 := &ethpb.SignedBeaconBlockMerge{}
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 := &ethpb.SignedBeaconBlockAltair{}
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 := &ethpb.SignedBeaconBlockMerge{}
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 := &ethpb.BeaconStateAltair{}
require.NoError(t, beaconStateBase.UnmarshalSSZ(preBeaconStateSSZ), "Failed to unmarshal")
beaconState, err := v2.InitializeFromProto(beaconStateBase)
require.NoError(t, err)
bc := params.BeaconConfig()
bc.BellatrixForkEpoch = types.Epoch(config.ForkEpoch)
params.OverrideBeaconConfig(bc)
ctx := context.Background()
var ok bool
for _, b := range preforkBlocks {
wsb, err := wrapper.WrappedAltairSignedBeaconBlock(b)
require.NoError(t, err)
st, err := transition.ExecuteStateTransition(ctx, beaconState, wsb)
require.NoError(t, err)
beaconState, ok = st.(*v2.BeaconState)
require.Equal(t, true, ok)
}
postState := state.BeaconState(beaconState)
for _, b := range postforkBlocks {
wsb, err := wrapper.WrappedMergeSignedBeaconBlock(b)
require.NoError(t, err)
st, err := transition.ExecuteStateTransition(ctx, postState, wsb)
require.NoError(t, err)
postState, ok = st.(*v3.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 := &ethpb.BeaconStateBellatrix{}
require.NoError(t, postBeaconState.UnmarshalSSZ(postBeaconStateSSZ), "Failed to unmarshal")
pbState, err := v3.ProtobufBeaconState(postState.CloneInnerState())
require.NoError(t, err)
require.DeepSSZEqual(t, pbState, postBeaconState)
})
}
}

View File

@@ -0,0 +1,60 @@
package fork
import (
"context"
"path"
"testing"
"github.com/golang/snappy"
"github.com/prysmaticlabs/prysm/beacon-chain/core/execution"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
v2 "github.com/prysmaticlabs/prysm/beacon-chain/state/v2"
v3 "github.com/prysmaticlabs/prysm/beacon-chain/state/v3"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/testing/spectest/utils"
"github.com/prysmaticlabs/prysm/testing/util"
"google.golang.org/protobuf/proto"
)
// RunUpgradeToBellatrix is a helper function that runs bellatrix's fork spec tests.
// It unmarshals a pre- and post-state to check `UpgradeToMerge` comply with spec implementation.
func RunUpgradeToBellatrix(t *testing.T, config string) {
require.NoError(t, utils.SetConfig(t, config))
testFolders, testsFolderPath := utils.TestFolders(t, config, "bellatrix", "fork/fork/pyspec_tests")
for _, folder := range testFolders {
t.Run(folder.Name(), func(t *testing.T) {
helpers.ClearCache()
folderPath := path.Join(testsFolderPath, folder.Name())
preStateFile, err := util.BazelFileBytes(path.Join(folderPath, "pre.ssz_snappy"))
require.NoError(t, err)
preStateSSZ, err := snappy.Decode(nil /* dst */, preStateFile)
require.NoError(t, err, "Failed to decompress")
preStateBase := &ethpb.BeaconStateAltair{}
if err := preStateBase.UnmarshalSSZ(preStateSSZ); err != nil {
t.Fatalf("Failed to unmarshal: %v", err)
}
preState, err := v2.InitializeFromProto(preStateBase)
require.NoError(t, err)
postState, err := execution.UpgradeToMerge(context.Background(), preState)
require.NoError(t, err)
postStateFromFunction, err := v3.ProtobufBeaconState(postState.InnerStateUnsafe())
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 := &ethpb.BeaconStateBellatrix{}
if err := postStateFromFile.UnmarshalSSZ(postStateSSZ); err != nil {
t.Fatalf("Failed to unmarshal: %v", err)
}
if !proto.Equal(postStateFromFile, postStateFromFunction) {
t.Fatal("Post state does not match expected")
}
})
}
}

View File

@@ -0,0 +1,36 @@
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",
"deposit.go",
"helpers.go",
"proposer_slashing.go",
"sync_committee.go",
"voluntary_exit.go",
],
importpath = "github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/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/v3:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v1alpha1/block:go_default_library",
"//proto/prysm/v1alpha1/wrapper: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",
"@in_gopkg_d4l3k_messagediff_v1//:go_default_library",
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
"@org_golang_google_protobuf//proto:go_default_library",
],
)

View File

@@ -0,0 +1,56 @@
package operations
import (
"context"
"errors"
"path"
"testing"
"github.com/golang/snappy"
"github.com/prysmaticlabs/prysm/beacon-chain/core/altair"
b "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/testing/spectest/utils"
"github.com/prysmaticlabs/prysm/testing/util"
)
func RunAttestationTest(t *testing.T, config string) {
require.NoError(t, utils.SetConfig(t, config))
testFolders, testsFolderPath := utils.TestFolders(t, config, "bellatrix", "operations/attestation/pyspec_tests")
for _, folder := range testFolders {
t.Run(folder.Name(), func(t *testing.T) {
folderPath := path.Join(testsFolderPath, folder.Name())
attestationFile, err := util.BazelFileBytes(folderPath, "attestation.ssz_snappy")
require.NoError(t, err)
attestationSSZ, err := snappy.Decode(nil /* dst */, attestationFile)
require.NoError(t, err, "Failed to decompress")
att := &ethpb.Attestation{}
require.NoError(t, att.UnmarshalSSZ(attestationSSZ), "Failed to unmarshal")
body := &ethpb.BeaconBlockBodyMerge{Attestations: []*ethpb.Attestation{att}}
processAtt := func(ctx context.Context, st state.BeaconState, blk block.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)
})
}
}

View File

@@ -0,0 +1,38 @@
package operations
import (
"context"
"path"
"testing"
"github.com/golang/snappy"
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/validators"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/testing/spectest/utils"
"github.com/prysmaticlabs/prysm/testing/util"
)
func RunAttesterSlashingTest(t *testing.T, config string) {
require.NoError(t, utils.SetConfig(t, config))
testFolders, testsFolderPath := utils.TestFolders(t, config, "bellatrix", "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 := &ethpb.AttesterSlashing{}
require.NoError(t, attSlashing.UnmarshalSSZ(attSlashingSSZ), "Failed to unmarshal")
body := &ethpb.BeaconBlockBodyMerge{AttesterSlashings: []*ethpb.AttesterSlashing{attSlashing}}
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b block.SignedBeaconBlock) (state.BeaconState, error) {
return blocks.ProcessAttesterSlashings(ctx, s, b.Block().Body().AttesterSlashings(), validators.SlashValidator)
})
})
}
}

View File

@@ -0,0 +1,84 @@
package operations
import (
"context"
"io/ioutil"
"path"
"strings"
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
"github.com/golang/snappy"
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
v3 "github.com/prysmaticlabs/prysm/beacon-chain/state/v3"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/testing/spectest/utils"
"github.com/prysmaticlabs/prysm/testing/util"
"google.golang.org/protobuf/proto"
"gopkg.in/d4l3k/messagediff.v1"
)
func RunBlockHeaderTest(t *testing.T, config string) {
require.NoError(t, utils.SetConfig(t, config))
testFolders, testsFolderPath := utils.TestFolders(t, config, "bellatrix", "operations/block_header/pyspec_tests")
for _, folder := range testFolders {
t.Run(folder.Name(), func(t *testing.T) {
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 := &ethpb.BeaconBlockMerge{}
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 := &ethpb.BeaconStateBellatrix{}
require.NoError(t, preBeaconStateBase.UnmarshalSSZ(preBeaconStateSSZ), "Failed to unmarshal")
preBeaconState, err := v3.InitializeFromProto(preBeaconStateBase)
require.NoError(t, err)
// If the post.ssz is not present, it means the test should fail on our end.
postSSZFilepath, err := bazel.Runfile(path.Join(testsFolderPath, folder.Name(), "post.ssz_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 := ioutil.ReadFile(postSSZFilepath) // #nosec G304
require.NoError(t, err)
postBeaconStateSSZ, err := snappy.Decode(nil /* dst */, postBeaconStateFile)
require.NoError(t, err, "Failed to decompress")
postBeaconState := &ethpb.BeaconStateBellatrix{}
require.NoError(t, postBeaconState.UnmarshalSSZ(postBeaconStateSSZ), "Failed to unmarshal")
pbState, err := v3.ProtobufBeaconState(beaconState.CloneInnerState())
require.NoError(t, err)
if !proto.Equal(pbState, postBeaconState) {
diff, _ := messagediff.PrettyDiff(beaconState.CloneInnerState(), postBeaconState)
t.Log(diff)
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
}
})
}
}

View File

@@ -0,0 +1,38 @@
package operations
import (
"context"
"path"
"testing"
"github.com/golang/snappy"
"github.com/prysmaticlabs/prysm/beacon-chain/core/altair"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/testing/spectest/utils"
"github.com/prysmaticlabs/prysm/testing/util"
)
func RunDepositTest(t *testing.T, config string) {
require.NoError(t, utils.SetConfig(t, config))
testFolders, testsFolderPath := utils.TestFolders(t, config, "bellatrix", "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 := &ethpb.Deposit{}
require.NoError(t, deposit.UnmarshalSSZ(depositSSZ), "Failed to unmarshal")
body := &ethpb.BeaconBlockBodyMerge{Deposits: []*ethpb.Deposit{deposit}}
processDepositsFunc := func(ctx context.Context, s state.BeaconState, b block.SignedBeaconBlock) (state.BeaconState, error) {
return altair.ProcessDeposits(ctx, s, b.Block().Body().Deposits())
}
RunBlockOperationTest(t, folderPath, body, processDepositsFunc)
})
}
}

View File

@@ -0,0 +1,88 @@
package operations
import (
"context"
"io/ioutil"
"path"
"strings"
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
"github.com/golang/snappy"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
v3 "github.com/prysmaticlabs/prysm/beacon-chain/state/v3"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block"
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/testing/util"
"google.golang.org/protobuf/proto"
"gopkg.in/d4l3k/messagediff.v1"
)
type blockOperation func(context.Context, state.BeaconState, block.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.BeaconBlockBodyMerge,
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 := &ethpb.BeaconStateBellatrix{}
if err := preStateBase.UnmarshalSSZ(preBeaconStateSSZ); err != nil {
t.Fatalf("Failed to unmarshal: %v", err)
}
preState, err := v3.InitializeFromProto(preStateBase)
require.NoError(t, err)
// If the post.ssz is not present, it means the test should fail on our end.
postSSZFilepath, err := bazel.Runfile(path.Join(folderPath, "post.ssz_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.NewBeaconBlockMerge()
b.Block.Body = body
wsb, err := wrapper.WrappedMergeSignedBeaconBlock(b)
require.NoError(t, err)
beaconState, err := operationFn(context.Background(), preState, wsb)
if postSSZExists {
require.NoError(t, err)
postBeaconStateFile, err := ioutil.ReadFile(postSSZFilepath) // #nosec G304
require.NoError(t, err)
postBeaconStateSSZ, err := snappy.Decode(nil /* dst */, postBeaconStateFile)
require.NoError(t, err, "Failed to decompress")
postBeaconState := &ethpb.BeaconStateBellatrix{}
if err := postBeaconState.UnmarshalSSZ(postBeaconStateSSZ); err != nil {
t.Fatalf("Failed to unmarshal: %v", err)
}
pbState, err := v3.ProtobufBeaconState(beaconState.InnerStateUnsafe())
require.NoError(t, err)
if !proto.Equal(pbState, postBeaconState) {
diff, _ := messagediff.PrettyDiff(beaconState.InnerStateUnsafe(), postBeaconState)
t.Log(diff)
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
}
}

View File

@@ -0,0 +1,38 @@
package operations
import (
"context"
"path"
"testing"
"github.com/golang/snappy"
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/validators"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/testing/spectest/utils"
"github.com/prysmaticlabs/prysm/testing/util"
)
func RunProposerSlashingTest(t *testing.T, config string) {
require.NoError(t, utils.SetConfig(t, config))
testFolders, testsFolderPath := utils.TestFolders(t, config, "bellatrix", "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 := &ethpb.ProposerSlashing{}
require.NoError(t, proposerSlashing.UnmarshalSSZ(proposerSlashingSSZ), "Failed to unmarshal")
body := &ethpb.BeaconBlockBodyMerge{ProposerSlashings: []*ethpb.ProposerSlashing{proposerSlashing}}
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b block.SignedBeaconBlock) (state.BeaconState, error) {
return blocks.ProcessProposerSlashings(ctx, s, b.Block().Body().ProposerSlashings(), validators.SlashValidator)
})
})
}
}

View File

@@ -0,0 +1,37 @@
package operations
import (
"context"
"path"
"testing"
"github.com/golang/snappy"
"github.com/prysmaticlabs/prysm/beacon-chain/core/altair"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/testing/spectest/utils"
"github.com/prysmaticlabs/prysm/testing/util"
)
func RunSyncCommitteeTest(t *testing.T, config string) {
require.NoError(t, utils.SetConfig(t, config))
testFolders, testsFolderPath := utils.TestFolders(t, config, "bellatrix", "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 := &ethpb.SyncAggregate{}
require.NoError(t, sc.UnmarshalSSZ(syncCommitteeSSZ), "Failed to unmarshal")
body := &ethpb.BeaconBlockBodyMerge{SyncAggregate: sc}
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b block.SignedBeaconBlock) (state.BeaconState, error) {
return altair.ProcessSyncAggregate(context.Background(), s, body.SyncAggregate)
})
})
}
}

View File

@@ -0,0 +1,37 @@
package operations
import (
"context"
"path"
"testing"
"github.com/golang/snappy"
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/testing/spectest/utils"
"github.com/prysmaticlabs/prysm/testing/util"
)
func RunVoluntaryExitTest(t *testing.T, config string) {
require.NoError(t, utils.SetConfig(t, config))
testFolders, testsFolderPath := utils.TestFolders(t, config, "bellatrix", "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 := &ethpb.SignedVoluntaryExit{}
require.NoError(t, voluntaryExit.UnmarshalSSZ(exitSSZ), "Failed to unmarshal")
body := &ethpb.BeaconBlockBodyMerge{VoluntaryExits: []*ethpb.SignedVoluntaryExit{voluntaryExit}}
RunBlockOperationTest(t, folderPath, body, func(ctx context.Context, s state.BeaconState, b block.SignedBeaconBlock) (state.BeaconState, error) {
return blocks.ProcessVoluntaryExits(ctx, s, b.Block().Body().VoluntaryExits())
})
})
}
}

View File

@@ -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/testing/spectest/shared/bellatrix/rewards",
visibility = ["//testing/spectest:__subpackages__"],
deps = [
"//beacon-chain/core/altair:go_default_library",
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/state/v3: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",
],
)

View File

@@ -0,0 +1,119 @@
package rewards
import (
"context"
"encoding/binary"
"fmt"
"path"
"reflect"
"strings"
"testing"
"github.com/golang/snappy"
"github.com/prysmaticlabs/prysm/beacon-chain/core/altair"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
v3 "github.com/prysmaticlabs/prysm/beacon-chain/state/v3"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/testing/spectest/utils"
"github.com/prysmaticlabs/prysm/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, "bellatrix", "rewards")
testTypes, err := util.BazelListDirectories(testsFolderPath)
require.NoError(t, err)
for _, testType := range testTypes {
testFolders, testsFolderPath := utils.TestFolders(t, config, "bellatrix", 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 := &ethpb.BeaconStateBellatrix{}
require.NoError(t, preBeaconStateBase.UnmarshalSSZ(preBeaconStateSSZ), "Failed to unmarshal")
preBeaconState, err := v3.InitializeFromProto(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)
rewards, penalties, err := altair.AttestationsDelta(preBeaconState, bp, vp)
require.NoError(t, err)
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)
}
}

View File

@@ -0,0 +1,29 @@
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/testing/spectest/shared/bellatrix/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/v3:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v1alpha1/wrapper:go_default_library",
"//testing/require:go_default_library",
"//testing/spectest/utils:go_default_library",
"//testing/util:go_default_library",
"@com_github_d4l3k_messagediff//:go_default_library",
"@com_github_golang_snappy//:go_default_library",
"@in_gopkg_d4l3k_messagediff_v1//:go_default_library",
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
"@org_golang_google_protobuf//proto:go_default_library",
],
)

View File

@@ -0,0 +1,113 @@
package sanity
import (
"context"
"fmt"
"io/ioutil"
"path"
"strings"
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
"github.com/d4l3k/messagediff"
"github.com/golang/snappy"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/transition"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
v3 "github.com/prysmaticlabs/prysm/beacon-chain/state/v3"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/testing/spectest/utils"
"github.com/prysmaticlabs/prysm/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, "bellatrix", 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 := &ethpb.BeaconStateBellatrix{}
require.NoError(t, beaconStateBase.UnmarshalSSZ(preBeaconStateSSZ), "Failed to unmarshal")
beaconState, err := v3.InitializeFromProto(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 := &ethpb.SignedBeaconBlockMerge{}
require.NoError(t, block.UnmarshalSSZ(blockSSZ), "Failed to unmarshal")
wsb, err := wrapper.WrappedMergeSignedBeaconBlock(block)
require.NoError(t, err)
processedState, transitionError = transition.ExecuteStateTransition(context.Background(), beaconState, wsb)
if transitionError != nil {
break
}
beaconState, ok = processedState.(*v3.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 := ioutil.ReadFile(postSSZFilepath) // #nosec G304
require.NoError(t, err)
postBeaconStateSSZ, err := snappy.Decode(nil /* dst */, postBeaconStateFile)
require.NoError(t, err, "Failed to decompress")
postBeaconState := &ethpb.BeaconStateBellatrix{}
require.NoError(t, postBeaconState.UnmarshalSSZ(postBeaconStateSSZ), "Failed to unmarshal")
pbState, err := v3.ProtobufBeaconState(beaconState.InnerStateUnsafe())
require.NoError(t, err)
if !proto.Equal(pbState, postBeaconState) {
diff, _ := messagediff.PrettyDiff(beaconState.InnerStateUnsafe(), postBeaconState)
t.Log(diff)
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
}
})
}
}

View File

@@ -0,0 +1,6 @@
package sanity
// SanityConfig --
type SanityConfig struct {
BlocksCount int `json:"blocks_count"`
}

View File

@@ -0,0 +1,63 @@
package sanity
import (
"context"
"strconv"
"testing"
"github.com/golang/snappy"
"github.com/prysmaticlabs/prysm/beacon-chain/core/transition"
v3 "github.com/prysmaticlabs/prysm/beacon-chain/state/v3"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/testing/require"
"github.com/prysmaticlabs/prysm/testing/spectest/utils"
"github.com/prysmaticlabs/prysm/testing/util"
"google.golang.org/protobuf/proto"
"gopkg.in/d4l3k/messagediff.v1"
)
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, "bellatrix", "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 := &ethpb.BeaconStateBellatrix{}
require.NoError(t, base.UnmarshalSSZ(preBeaconStateSSZ), "Failed to unmarshal")
beaconState, err := v3.InitializeFromProto(base)
require.NoError(t, err)
file, err := util.BazelFileBytes(testsFolderPath, folder.Name(), "slots.yaml")
require.NoError(t, err)
fileStr := string(file)
slotsCount, err := strconv.Atoi(fileStr[:len(fileStr)-5])
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 := &ethpb.BeaconStateBellatrix{}
require.NoError(t, postBeaconState.UnmarshalSSZ(postBeaconStateSSZ), "Failed to unmarshal")
postState, err := transition.ProcessSlots(context.Background(), beaconState, beaconState.Slot().Add(uint64(slotsCount)))
require.NoError(t, err)
pbState, err := v3.ProtobufBeaconState(postState.CloneInnerState())
require.NoError(t, err)
if !proto.Equal(pbState, postBeaconState) {
diff, _ := messagediff.PrettyDiff(beaconState, postBeaconState)
t.Fatalf("Post state does not match expected. Diff between states %s", diff)
}
})
}
}

View File

@@ -0,0 +1,18 @@
load("@prysm//tools/go:def.bzl", "go_library")
go_library(
name = "go_default_library",
testonly = True,
srcs = ["ssz_static.go"],
importpath = "github.com/prysmaticlabs/prysm/testing/spectest/shared/bellatrix/ssz_static",
visibility = ["//testing/spectest:__subpackages__"],
deps = [
"//beacon-chain/state/v3: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_ferranbt_fastssz//:go_default_library",
"@com_github_golang_snappy//:go_default_library",
],
)

Some files were not shown because too many files have changed in this diff Show More