Template based protobuf parameters for ssz configurations (#3062)

* WIP on build time configuration changes

* add ssz_minimal tests

* split up spec tests into mainnet and minimal, skip any minimal test that are failing without --define ssz=minimal

* lint

* add commentary to ssz_proto_library
This commit is contained in:
Preston Van Loon 2019-07-24 22:03:05 -04:00 committed by GitHub
parent f58afa62af
commit 7d47be84ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
55 changed files with 1118 additions and 328 deletions

View File

@ -17,19 +17,22 @@ go_library(
],
)
go_test(
test_suite(
name = "go_default_test",
size = "medium",
srcs = [
"attestation_test.go",
"attester_slashing_test.go",
"block_header_test.go",
"block_processing_test.go",
"deposit_test.go",
"proposer_slashing_test.go",
"transfer_test.go",
"voluntary_exit_test.go",
tags = ["spectest"],
tests = [
":go_mainnet_test",
":go_minimal_test",
],
)
go_test(
name = "go_mainnet_test",
size = "medium",
srcs = glob(
["*_test.go"],
exclude = ["*_minimal_test.go"],
),
data = glob(["*.yaml"]) + [
"@eth2_spec_tests//:test_data",
],
@ -49,3 +52,29 @@ go_test(
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
],
)
go_test(
name = "go_minimal_test",
size = "small",
srcs = glob(
["*_test.go"],
exclude = ["*_mainnet_test.go"],
),
data = glob(["*.yaml"]) + [
"@eth2_spec_tests//:test_data",
],
embed = [":go_default_library"],
tags = ["spectest"],
deps = [
"//beacon-chain/core/blocks:go_default_library",
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/core/state:go_default_library",
"//beacon-chain/core/state/stateutils:go_default_library",
"//proto/eth/v1alpha1:go_default_library",
"//shared/params/spectest:go_default_library",
"//shared/testutil:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@in_gopkg_d4l3k_messagediff_v1//:go_default_library",
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
],
)

View File

@ -0,0 +1,9 @@
package spectest
import (
"testing"
)
func TestAttestationMainnet(t *testing.T) {
runAttestationTest(t, "attestation_mainnet.yaml")
}

View File

@ -0,0 +1,9 @@
package spectest
import (
"testing"
)
func TestAttestationMinimal(t *testing.T) {
runAttestationTest(t, "attestation_minimal.yaml")
}

View File

@ -76,11 +76,3 @@ func runAttestationTest(t *testing.T, filename string) {
})
}
}
func TestAttestationMinimal(t *testing.T) {
runAttestationTest(t, "attestation_minimal.yaml")
}
func TestAttestationMainnet(t *testing.T) {
runAttestationTest(t, "attestation_mainnet.yaml")
}

View File

@ -0,0 +1,15 @@
package spectest
import (
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
)
func TestAttesterSlashingMainnet(t *testing.T) {
filepath, err := bazel.Runfile(attesterSlashingPrefix + "attester_slashing_mainnet.yaml")
if err != nil {
t.Fatal(err)
}
runAttesterSlashingTest(t, filepath)
}

View File

@ -0,0 +1,15 @@
package spectest
import (
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
)
func TestAttesterSlashingMinimal(t *testing.T) {
filepath, err := bazel.Runfile(attesterSlashingPrefix + "attester_slashing_minimal.yaml")
if err != nil {
t.Fatal(err)
}
runAttesterSlashingTest(t, filepath)
}

View File

@ -4,7 +4,6 @@ import (
"io/ioutil"
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
"github.com/gogo/protobuf/proto"
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
@ -14,6 +13,8 @@ import (
"gopkg.in/d4l3k/messagediff.v1"
)
const attesterSlashingPrefix = "tests/operations/attester_slashing/"
func runAttesterSlashingTest(t *testing.T, filename string) {
file, err := ioutil.ReadFile(filename)
if err != nil {
@ -60,21 +61,3 @@ func runAttesterSlashingTest(t *testing.T, filename string) {
})
}
}
var attesterSlashingPrefix = "tests/operations/attester_slashing/"
func TestAttesterSlashingMinimal(t *testing.T) {
filepath, err := bazel.Runfile(attesterSlashingPrefix + "attester_slashing_minimal.yaml")
if err != nil {
t.Fatal(err)
}
runAttesterSlashingTest(t, filepath)
}
func TestAttesterSlashingMainnet(t *testing.T) {
filepath, err := bazel.Runfile(attesterSlashingPrefix + "attester_slashing_mainnet.yaml")
if err != nil {
t.Fatal(err)
}
runAttesterSlashingTest(t, filepath)
}

View File

@ -0,0 +1,15 @@
package spectest
import (
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
)
func TestBlockHeaderMainnet(t *testing.T) {
filepath, err := bazel.Runfile(blkHeaderPrefix + "block_header_mainnet.yaml")
if err != nil {
t.Fatal(err)
}
runBlockHeaderTest(t, filepath)
}

View File

@ -0,0 +1,15 @@
package spectest
import (
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
)
func TestBlockHeaderMinimal(t *testing.T) {
filepath, err := bazel.Runfile(blkHeaderPrefix + "block_header_minimal.yaml")
if err != nil {
t.Fatal(err)
}
runBlockHeaderTest(t, filepath)
}

View File

@ -4,7 +4,6 @@ import (
"io/ioutil"
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
"github.com/gogo/protobuf/proto"
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
@ -13,6 +12,8 @@ import (
"gopkg.in/d4l3k/messagediff.v1"
)
const blkHeaderPrefix = "tests/operations/block_header/"
// Block header test is actually a full block processing test. Not sure why it
// was named "block_header". The note in the test format readme says "Note that
// block_header is not strictly an operation (and is a full Block), but
@ -62,21 +63,3 @@ func runBlockHeaderTest(t *testing.T, filename string) {
})
}
}
var blkHeaderPrefix = "tests/operations/block_header/"
func TestBlockHeaderMinimal(t *testing.T) {
filepath, err := bazel.Runfile(blkHeaderPrefix + "block_header_minimal.yaml")
if err != nil {
t.Fatal(err)
}
runBlockHeaderTest(t, filepath)
}
func TestBlockHeaderMainnet(t *testing.T) {
filepath, err := bazel.Runfile(blkHeaderPrefix + "block_header_mainnet.yaml")
if err != nil {
t.Fatal(err)
}
runBlockHeaderTest(t, filepath)
}

View File

@ -0,0 +1,9 @@
package spectest
import (
"testing"
)
func TestBlockProcessingMainnetYaml(t *testing.T) {
runBlockProcessingTest(t, "sanity_blocks_mainnet.yaml")
}

View File

@ -0,0 +1,11 @@
package spectest
import (
"testing"
)
func TestBlockProcessingMinimalYaml(t *testing.T) {
t.Skip("This test suite requires --define ssz=minimal to be provided and there isn't a great way to do that without breaking //... See https://github.com/prysmaticlabs/prysm/issues/3066")
runBlockProcessingTest(t, "sanity_blocks_minimal.yaml")
}

View File

@ -15,16 +15,6 @@ import (
"gopkg.in/d4l3k/messagediff.v1"
)
func TestBlockProcessingMinimalYaml(t *testing.T) {
t.Skip("Test will fail with mainnet protos")
runBlockProcessingTest(t, "sanity_blocks_minimal.yaml")
}
func TestBlockProcessingMainnetYaml(t *testing.T) {
runBlockProcessingTest(t, "sanity_blocks_mainnet.yaml")
}
func runBlockProcessingTest(t *testing.T, filename string) {
filepath, err := bazel.Runfile("tests/sanity/blocks/" + filename)
if err != nil {

View File

@ -0,0 +1,15 @@
package spectest
import (
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
)
func TestDepositMainnetYaml(t *testing.T) {
filepath, err := bazel.Runfile(depositPrefix + "deposit_mainnet.yaml")
if err != nil {
t.Fatal(err)
}
runDepositTest(t, filepath)
}

View File

@ -0,0 +1,15 @@
package spectest
import (
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
)
func TestDepositMinimalYaml(t *testing.T) {
filepath, err := bazel.Runfile(depositPrefix + "deposit_minimal.yaml")
if err != nil {
t.Fatal(err)
}
runDepositTest(t, filepath)
}

View File

@ -5,7 +5,6 @@ import (
"reflect"
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state/stateutils"
@ -13,6 +12,8 @@ import (
"github.com/prysmaticlabs/prysm/shared/testutil"
)
const depositPrefix = "tests/operations/deposit/"
func runDepositTest(t *testing.T, filename string) {
file, err := ioutil.ReadFile(filename)
if err != nil {
@ -55,21 +56,3 @@ func runDepositTest(t *testing.T, filename string) {
})
}
}
var depositPrefix = "tests/operations/deposit/"
func TestDepositMinimalYaml(t *testing.T) {
filepath, err := bazel.Runfile(depositPrefix + "deposit_minimal.yaml")
if err != nil {
t.Fatal(err)
}
runDepositTest(t, filepath)
}
func TestDepositMainnetYaml(t *testing.T) {
filepath, err := bazel.Runfile(depositPrefix + "deposit_mainnet.yaml")
if err != nil {
t.Fatal(err)
}
runDepositTest(t, filepath)
}

View File

@ -0,0 +1,15 @@
package spectest
import (
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
)
func TestProposerSlashingMainnet(t *testing.T) {
filepath, err := bazel.Runfile(proposerSlashingPrefix + "proposer_slashing_mainnet.yaml")
if err != nil {
t.Fatal(err)
}
runProposerSlashingTest(t, filepath)
}

View File

@ -0,0 +1,15 @@
package spectest
import (
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
)
func TestProposerSlashingMinimal(t *testing.T) {
filepath, err := bazel.Runfile(proposerSlashingPrefix + "proposer_slashing_minimal.yaml")
if err != nil {
t.Fatal(err)
}
runProposerSlashingTest(t, filepath)
}

View File

@ -4,7 +4,6 @@ import (
"io/ioutil"
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
"github.com/gogo/protobuf/proto"
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
@ -14,6 +13,8 @@ import (
"gopkg.in/d4l3k/messagediff.v1"
)
const proposerSlashingPrefix = "tests/operations/proposer_slashing/"
func runProposerSlashingTest(t *testing.T, filename string) {
file, err := ioutil.ReadFile(filename)
if err != nil {
@ -60,21 +61,3 @@ func runProposerSlashingTest(t *testing.T, filename string) {
})
}
}
var proposerSlashingPrefix = "tests/operations/proposer_slashing/"
func TestProposerSlashingMinimal(t *testing.T) {
filepath, err := bazel.Runfile(proposerSlashingPrefix + "proposer_slashing_minimal.yaml")
if err != nil {
t.Fatal(err)
}
runProposerSlashingTest(t, filepath)
}
func TestProposerSlashingMainnet(t *testing.T) {
filepath, err := bazel.Runfile(proposerSlashingPrefix + "proposer_slashing_mainnet.yaml")
if err != nil {
t.Fatal(err)
}
runProposerSlashingTest(t, filepath)
}

View File

@ -0,0 +1,16 @@
package spectest
import (
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
)
func TestTransferMainnet(t *testing.T) {
t.Skip("Transfer tests are disabled. See https://github.com/ethereum/eth2.0-specs/pull/1238#issuecomment-507054595")
filepath, err := bazel.Runfile(transferPrefix + "transfer_mainnet.yaml")
if err != nil {
t.Fatal(err)
}
runTransferTest(t, filepath)
}

View File

@ -0,0 +1,16 @@
package spectest
import (
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
)
func TestTransferMinimal(t *testing.T) {
t.Skip("Transfer tests are disabled. See https://github.com/ethereum/eth2.0-specs/pull/1238#issuecomment-507054595")
filepath, err := bazel.Runfile(transferPrefix + "transfer_minimal.yaml")
if err != nil {
t.Fatal(err)
}
runTransferTest(t, filepath)
}

View File

@ -4,7 +4,6 @@ import (
"io/ioutil"
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
"github.com/gogo/protobuf/proto"
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
@ -14,6 +13,8 @@ import (
"gopkg.in/d4l3k/messagediff.v1"
)
const transferPrefix = "tests/operations/transfer/"
func runTransferTest(t *testing.T, filename string) {
file, err := ioutil.ReadFile(filename)
if err != nil {
@ -60,23 +61,3 @@ func runTransferTest(t *testing.T, filename string) {
})
}
}
var transferPrefix = "tests/operations/transfer/"
func TestTransferMinimal(t *testing.T) {
t.Skip("Transfer tests are disabled. See https://github.com/ethereum/eth2.0-specs/pull/1238#issuecomment-507054595")
filepath, err := bazel.Runfile(transferPrefix + "transfer_minimal.yaml")
if err != nil {
t.Fatal(err)
}
runTransferTest(t, filepath)
}
func TestTransferMainnet(t *testing.T) {
t.Skip("Transfer tests are disabled. See https://github.com/ethereum/eth2.0-specs/pull/1238#issuecomment-507054595")
filepath, err := bazel.Runfile(transferPrefix + "transfer_mainnet.yaml")
if err != nil {
t.Fatal(err)
}
runTransferTest(t, filepath)
}

View File

@ -0,0 +1,15 @@
package spectest
import (
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
)
func TestVoluntaryExitMainnet(t *testing.T) {
filepath, err := bazel.Runfile(exitPrefix + "voluntary_exit_mainnet.yaml")
if err != nil {
t.Fatal(err)
}
runVoluntaryExitTest(t, filepath)
}

View File

@ -0,0 +1,15 @@
package spectest
import (
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
)
func TestVoluntaryExitMinimal(t *testing.T) {
filepath, err := bazel.Runfile(exitPrefix + "voluntary_exit_mainnet.yaml")
if err != nil {
t.Fatal(err)
}
runVoluntaryExitTest(t, filepath)
}

View File

@ -4,7 +4,6 @@ import (
"io/ioutil"
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
"github.com/gogo/protobuf/proto"
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
@ -14,6 +13,8 @@ import (
"gopkg.in/d4l3k/messagediff.v1"
)
const exitPrefix = "tests/operations/voluntary_exit/"
func runVoluntaryExitTest(t *testing.T, filename string) {
file, err := ioutil.ReadFile(filename)
if err != nil {
@ -60,21 +61,3 @@ func runVoluntaryExitTest(t *testing.T, filename string) {
})
}
}
var exitPrefix = "tests/operations/voluntary_exit/"
func TestVoluntaryExitMinimal(t *testing.T) {
filepath, err := bazel.Runfile(exitPrefix + "voluntary_exit_mainnet.yaml")
if err != nil {
t.Fatal(err)
}
runVoluntaryExitTest(t, filepath)
}
func TestVoluntaryExitMainnet(t *testing.T) {
filepath, err := bazel.Runfile(exitPrefix + "voluntary_exit_mainnet.yaml")
if err != nil {
t.Fatal(err)
}
runVoluntaryExitTest(t, filepath)
}

View File

@ -8,16 +8,49 @@ go_library(
deps = ["//proto/beacon/p2p/v1:go_default_library"],
)
go_test(
test_suite(
name = "go_default_test",
size = "medium",
srcs = [
"crosslink_test.go",
"final_updates_test.go",
"justification_and_finalization_test.go",
"registry_test.go",
"slashings_test.go",
tags = ["spectest"],
tests = [
":go_mainnet_test",
":go_minimal_test",
],
)
go_test(
name = "go_mainnet_test",
size = "small",
srcs = glob(
["*_test.go"],
exclude = ["*_minimal_test.go"],
),
data = [
"@eth2_spec_tests//:test_data",
],
embed = [":go_default_library"],
shard_count = 4,
tags = [
"spectest",
],
deps = [
"//beacon-chain/core/epoch:go_default_library",
"//beacon-chain/core/helpers:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//shared/params/spectest:go_default_library",
"//shared/testutil:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@in_gopkg_d4l3k_messagediff_v1//:go_default_library",
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
],
)
go_test(
name = "go_minimal_test",
size = "small",
srcs = glob(
["*_test.go"],
exclude = ["*_mainnet_test.go"],
),
data = [
"@eth2_spec_tests//:test_data",
],

View File

@ -0,0 +1,17 @@
package spectest
import (
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
)
func TestCrosslinksProcessingMainnet(t *testing.T) {
helpers.ClearAllCaches()
filepath, err := bazel.Runfile(crosslinkPrefix + "crosslinks_mainnet.yaml")
if err != nil {
t.Fatal(err)
}
runCrosslinkProcessingTests(t, filepath)
}

View File

@ -0,0 +1,15 @@
package spectest
import (
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
)
func TestCrosslinksProcessingMinimal(t *testing.T) {
filepath, err := bazel.Runfile(crosslinkPrefix + "crosslinks_minimal.yaml")
if err != nil {
t.Fatal(err)
}
runCrosslinkProcessingTests(t, filepath)
}

View File

@ -5,13 +5,13 @@ import (
"reflect"
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/shared/params/spectest"
"github.com/prysmaticlabs/prysm/shared/testutil"
)
const crosslinkPrefix = "tests/epoch_processing/crosslinks/"
func runCrosslinkProcessingTests(t *testing.T, filename string) {
file, err := ioutil.ReadFile(filename)
if err != nil {
@ -45,22 +45,3 @@ func runCrosslinkProcessingTests(t *testing.T, filename string) {
})
}
}
const crosslinkPrefix = "tests/epoch_processing/crosslinks/"
func TestCrosslinksProcessingMinimal(t *testing.T) {
filepath, err := bazel.Runfile(crosslinkPrefix + "crosslinks_minimal.yaml")
if err != nil {
t.Fatal(err)
}
runCrosslinkProcessingTests(t, filepath)
}
func TestCrosslinksProcessingMainnet(t *testing.T) {
helpers.ClearAllCaches()
filepath, err := bazel.Runfile(crosslinkPrefix + "crosslinks_mainnet.yaml")
if err != nil {
t.Fatal(err)
}
runCrosslinkProcessingTests(t, filepath)
}

View File

@ -0,0 +1,15 @@
package spectest
import (
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
)
func TestFinalUpdatesMainnet(t *testing.T) {
filepath, err := bazel.Runfile(finalUpdatesPrefix + "final_updates_mainnet.yaml")
if err != nil {
t.Fatal(err)
}
runFinalUpdatesTests(t, filepath)
}

View File

@ -0,0 +1,15 @@
package spectest
import (
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
)
func TestFinalUpdatesMinimal(t *testing.T) {
filepath, err := bazel.Runfile(finalUpdatesPrefix + "final_updates_minimal.yaml")
if err != nil {
t.Fatal(err)
}
runFinalUpdatesTests(t, filepath)
}

View File

@ -5,7 +5,6 @@ import (
"reflect"
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
@ -14,6 +13,8 @@ import (
"gopkg.in/d4l3k/messagediff.v1"
)
const finalUpdatesPrefix = "tests/epoch_processing/final_updates/"
func runFinalUpdatesTests(t *testing.T, filename string) {
file, err := ioutil.ReadFile(filename)
if err != nil {
@ -51,21 +52,3 @@ func runFinalUpdatesTests(t *testing.T, filename string) {
})
}
}
const finalUpdatesPrefix = "tests/epoch_processing/final_updates/"
func TestFinalUpdatesMinimal(t *testing.T) {
filepath, err := bazel.Runfile(finalUpdatesPrefix + "final_updates_minimal.yaml")
if err != nil {
t.Fatal(err)
}
runFinalUpdatesTests(t, filepath)
}
func TestFinalUpdatesMainnet(t *testing.T) {
filepath, err := bazel.Runfile(finalUpdatesPrefix + "final_updates_mainnet.yaml")
if err != nil {
t.Fatal(err)
}
runFinalUpdatesTests(t, filepath)
}

View File

@ -0,0 +1,15 @@
package spectest
import (
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
)
func TestJustificationAndFinalizationMainnet(t *testing.T) {
filepath, err := bazel.Runfile(justificationAndFinalizationPrefix + "justification_and_finalization_mainnet.yaml")
if err != nil {
t.Fatal(err)
}
runJustificationAndFinalizationTests(t, filepath)
}

View File

@ -0,0 +1,16 @@
package spectest
import (
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
)
func TestJustificationAndFinalizationMinimal(t *testing.T) {
t.Skip("This test suite requires --define ssz=minimal to be provided and there isn't a great way to do that without breaking //... See https://github.com/prysmaticlabs/prysm/issues/3066")
filepath, err := bazel.Runfile(justificationAndFinalizationPrefix + "justification_and_finalization_minimal.yaml")
if err != nil {
t.Fatal(err)
}
runJustificationAndFinalizationTests(t, filepath)
}

View File

@ -6,7 +6,6 @@ import (
"reflect"
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
"github.com/gogo/protobuf/proto"
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
@ -16,6 +15,8 @@ import (
"gopkg.in/d4l3k/messagediff.v1"
)
const justificationAndFinalizationPrefix = "tests/epoch_processing/justification_and_finalization/"
// This is a subset of state.ProcessEpoch. The spec test defines input data for
// `justification_and_finalization` only.
func processJustificationAndFinalizationWrapper(state *pb.BeaconState) (*pb.BeaconState, error) {
@ -99,23 +100,3 @@ func runJustificationAndFinalizationTests(t *testing.T, filename string) {
})
}
}
const justificationAndFinalizationPrefix = "tests/epoch_processing/justification_and_finalization/"
func TestJustificationAndFinalizationMinimal(t *testing.T) {
// TODO(#2891): Verify with ETH2 spec test.
t.Skip("The input data fails preconditions for matching attestations in the state for the current epoch.")
filepath, err := bazel.Runfile(justificationAndFinalizationPrefix + "justification_and_finalization_minimal.yaml")
if err != nil {
t.Fatal(err)
}
runJustificationAndFinalizationTests(t, filepath)
}
func TestJustificationAndFinalizationMainnet(t *testing.T) {
filepath, err := bazel.Runfile(justificationAndFinalizationPrefix + "justification_and_finalization_mainnet.yaml")
if err != nil {
t.Fatal(err)
}
runJustificationAndFinalizationTests(t, filepath)
}

View File

@ -0,0 +1,15 @@
package spectest
import (
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
)
func TestRegistryProcessingMainnet(t *testing.T) {
filepath, err := bazel.Runfile(registryUpdatesPrefix + "registry_updates_mainnet.yaml")
if err != nil {
t.Fatal(err)
}
runRegisteryProcessingTests(t, filepath)
}

View File

@ -0,0 +1,15 @@
package spectest
import (
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
)
func TestRegistryProcessingMinimal(t *testing.T) {
filepath, err := bazel.Runfile(registryUpdatesPrefix + "registry_updates_minimal.yaml")
if err != nil {
t.Fatal(err)
}
runRegisteryProcessingTests(t, filepath)
}

View File

@ -5,12 +5,13 @@ import (
"reflect"
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch"
"github.com/prysmaticlabs/prysm/shared/params/spectest"
"github.com/prysmaticlabs/prysm/shared/testutil"
)
const registryUpdatesPrefix = "tests/epoch_processing/registry_updates/"
func runRegisteryProcessingTests(t *testing.T, filename string) {
file, err := ioutil.ReadFile(filename)
if err != nil {
@ -43,21 +44,3 @@ func runRegisteryProcessingTests(t *testing.T, filename string) {
})
}
}
const registryUpdatesPrefix = "tests/epoch_processing/registry_updates/"
func TestRegistryProcessingMinimal(t *testing.T) {
filepath, err := bazel.Runfile(registryUpdatesPrefix + "registry_updates_minimal.yaml")
if err != nil {
t.Fatal(err)
}
runRegisteryProcessingTests(t, filepath)
}
func TestRegistryProcessingMainnet(t *testing.T) {
filepath, err := bazel.Runfile(registryUpdatesPrefix + "registry_updates_mainnet.yaml")
if err != nil {
t.Fatal(err)
}
runRegisteryProcessingTests(t, filepath)
}

View File

@ -0,0 +1,15 @@
package spectest
import (
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
)
func TestSlashingsMainnet(t *testing.T) {
filepath, err := bazel.Runfile(slashingsPrefix + "slashings_mainnet.yaml")
if err != nil {
t.Fatal(err)
}
runSlashingsTests(t, filepath)
}

View File

@ -0,0 +1,15 @@
package spectest
import (
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
)
func TestSlashingsMinimal(t *testing.T) {
filepath, err := bazel.Runfile(slashingsPrefix + "slashings_minimal.yaml")
if err != nil {
t.Fatal(err)
}
runSlashingsTests(t, filepath)
}

View File

@ -5,13 +5,14 @@ import (
"reflect"
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/shared/params/spectest"
"github.com/prysmaticlabs/prysm/shared/testutil"
)
const slashingsPrefix = "tests/epoch_processing/slashings/"
func runSlashingsTests(t *testing.T, filename string) {
file, err := ioutil.ReadFile(filename)
if err != nil {
@ -45,21 +46,3 @@ func runSlashingsTests(t *testing.T, filename string) {
})
}
}
const slashingsPrefix = "tests/epoch_processing/slashings/"
func TestSlashingsMinimal(t *testing.T) {
filepath, err := bazel.Runfile(slashingsPrefix + "slashings_minimal.yaml")
if err != nil {
t.Fatal(err)
}
runSlashingsTests(t, filepath)
}
func TestSlashingsMainnet(t *testing.T) {
filepath, err := bazel.Runfile(slashingsPrefix + "slashings_mainnet.yaml")
if err != nil {
t.Fatal(err)
}
runSlashingsTests(t, filepath)
}

View File

@ -15,13 +15,49 @@ go_library(
],
)
go_test(
test_suite(
name = "go_default_test",
size = "large",
srcs = [
"genesis_test.go",
"slot_processing_test.go",
tags = ["spectest"],
tests = [
":go_mainnet_test",
":go_minimal_test",
],
)
go_test(
name = "go_mainnet_test",
size = "medium",
srcs = glob(
["*_test.go"],
exclude = ["*_minimal_test.go"],
),
data = [
"@eth2_spec_tests//:test_data",
],
embed = [":go_default_library"],
shard_count = 2,
tags = ["spectest"],
deps = [
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/core/state:go_default_library",
"//proto/eth/v1alpha1:go_default_library",
"//shared/params:go_default_library",
"//shared/params/spectest:go_default_library",
"//shared/testutil:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
"@in_gopkg_d4l3k_messagediff_v1//:go_default_library",
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
],
)
go_test(
name = "go_minimal_test",
size = "small",
srcs = glob(
["*_test.go"],
exclude = ["*_mainnet_test.go"],
),
data = [
"@eth2_spec_tests//:test_data",
],

View File

@ -16,7 +16,7 @@ import (
)
func TestGenesisInitializationMinimal(t *testing.T) {
t.Skip("Tests will fail with mainnet config - awaiting mainnet tests from the researchers")
t.Skip("This test suite requires --define ssz=minimal to be provided and there isn't a great way to do that without breaking //... See https://github.com/prysmaticlabs/prysm/issues/3066")
filepath, err := bazel.Runfile("tests/genesis/initialization/genesis_initialization_minimal.yaml")
if err != nil {
t.Fatal(err)
@ -68,44 +68,3 @@ func TestGenesisInitializationMinimal(t *testing.T) {
})
}
}
func TestGenesisValidityMinimal(t *testing.T) {
filepath, err := bazel.Runfile("tests/genesis/validity/genesis_validity_minimal.yaml")
if err != nil {
t.Fatal(err)
}
file, err := ioutil.ReadFile(filepath)
if err != nil {
t.Fatalf("Could not load file %v", err)
}
s := &GensisValidityTest{}
if err := testutil.UnmarshalYaml(file, s); err != nil {
t.Fatalf("Failed to Unmarshal: %v", err)
}
if err := spectest.SetConfig(s.Config); err != nil {
t.Fatal(err)
}
for _, tt := range s.TestCases {
t.Run(tt.Description, func(t *testing.T) {
helpers.ClearAllCaches()
genesisState := tt.Genesis
validatorCount, err := helpers.ActiveValidatorCount(genesisState, 0)
if err != nil {
t.Fatalf("Could not get active validator count: %v", err)
}
isValid := state.IsValidGenesisState(validatorCount, genesisState.GenesisTime)
if isValid != tt.IsValid {
t.Fatalf(
"Genesis state does not have expected validity. Expected to be valid: %d, %d. %t %t",
tt.Genesis.GenesisTime,
validatorCount,
isValid,
tt.IsValid,
)
}
})
}
}

View File

@ -0,0 +1,53 @@
package spectest
import (
"io/ioutil"
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
"github.com/prysmaticlabs/prysm/shared/params/spectest"
"github.com/prysmaticlabs/prysm/shared/testutil"
)
func TestGenesisValidityMinimal(t *testing.T) {
filepath, err := bazel.Runfile("tests/genesis/validity/genesis_validity_minimal.yaml")
if err != nil {
t.Fatal(err)
}
file, err := ioutil.ReadFile(filepath)
if err != nil {
t.Fatalf("Could not load file %v", err)
}
s := &GensisValidityTest{}
if err := testutil.UnmarshalYaml(file, s); err != nil {
t.Fatalf("Failed to Unmarshal: %v", err)
}
if err := spectest.SetConfig(s.Config); err != nil {
t.Fatal(err)
}
for _, tt := range s.TestCases {
t.Run(tt.Description, func(t *testing.T) {
helpers.ClearAllCaches()
genesisState := tt.Genesis
validatorCount, err := helpers.ActiveValidatorCount(genesisState, 0)
if err != nil {
t.Fatalf("Could not get active validator count: %v", err)
}
isValid := state.IsValidGenesisState(validatorCount, genesisState.GenesisTime)
if isValid != tt.IsValid {
t.Fatalf(
"Genesis state does not have expected validity. Expected to be valid: %d, %d. %t %t",
tt.Genesis.GenesisTime,
validatorCount,
isValid,
tt.IsValid,
)
}
})
}
}

View File

@ -0,0 +1,9 @@
package spectest
import (
"testing"
)
func TestSlotProcessingMainnet(t *testing.T) {
runSlotProcessingTests(t, "sanity_slots_mainnet.yaml")
}

View File

@ -0,0 +1,10 @@
package spectest
import (
"testing"
)
func TestSlotProcessingMinimal(t *testing.T) {
t.Skip("This test suite requires --define ssz=minimal to be provided and there isn't a great way to do that without breaking //... See https://github.com/prysmaticlabs/prysm/issues/3066")
runSlotProcessingTests(t, "sanity_slots_minimal.yaml")
}

View File

@ -13,8 +13,10 @@ import (
"gopkg.in/d4l3k/messagediff.v1"
)
func TestSlotProcessingMainnet(t *testing.T) {
filepath, err := bazel.Runfile("tests/sanity/slots/sanity_slots_mainnet.yaml")
const slotProcessingPrefix = "tests/sanity/slots/"
func runSlotProcessingTests(t *testing.T, filename string) {
filepath, err := bazel.Runfile(slotProcessingPrefix + filename)
if err != nil {
t.Fatal(err)
}

13
proto/BUILD.bazel Normal file
View File

@ -0,0 +1,13 @@
config_setting(
name = "ssz_mainnet",
define_values = {
"ssz": "mainnet",
},
)
config_setting(
name = "ssz_minimal",
define_values = {
"ssz": "minimal",
},
)

View File

@ -1,6 +1,7 @@
# gazelle:ignore
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
load("//proto:ssz_proto_library.bzl", "ssz_proto_files")
go_proto_library(
name = "v1_go_proto",
@ -21,12 +22,22 @@ go_library(
visibility = ["//visibility:public"],
)
proto_library(
name = "v1_proto",
ssz_proto_files(
name = "ssz_proto_files",
srcs = [
"messages.proto",
"types.proto",
],
config = select({
"//conditions:default": "mainnet",
"//proto:ssz_mainnet": "mainnet",
"//proto:ssz_minimal": "minimal",
}),
)
proto_library(
name = "v1_proto",
srcs = [":ssz_proto_files"],
visibility = ["//visibility:public"],
deps = [
"//proto/eth/v1alpha1:v1alpha1_proto",

View File

@ -14,13 +14,13 @@ message BeaconState {
// History [2001-3000]
ethereum.eth.v1alpha1.BeaconBlockHeader latest_block_header = 2001;
repeated bytes block_roots = 2002 [(gogoproto.moretags) = "ssz-size:\"8192,32\""];
repeated bytes state_roots = 2003 [(gogoproto.moretags) = "ssz-size:\"8192,32\""];
repeated bytes block_roots = 2002 [(gogoproto.moretags) = "ssz-size:\"block_roots.size\""];
repeated bytes state_roots = 2003 [(gogoproto.moretags) = "ssz-size:\"state_roots.size\""];
repeated bytes historical_roots = 2004 [(gogoproto.moretags) = "ssz-size:\"?,32\" ssz-max:\"16777216\""];
// Eth1 [3001-4000]
ethereum.eth.v1alpha1.Eth1Data eth1_data = 3001;
repeated ethereum.eth.v1alpha1.Eth1Data eth1_data_votes = 3002 [(gogoproto.moretags) = "ssz-max:\"1024\""];
repeated ethereum.eth.v1alpha1.Eth1Data eth1_data_votes = 3002 [(gogoproto.moretags) = "ssz-max:\"eth1_data_votes.size\""];
uint64 eth1_deposit_index = 3003;
// Registry [4001-5000]
@ -29,20 +29,20 @@ message BeaconState {
// Shuffling [5001-6000]
uint64 start_shard = 5001;
repeated bytes randao_mixes = 5002 [(gogoproto.moretags) = "ssz-size:\"65536,32\""];
repeated bytes active_index_roots = 5003 [(gogoproto.moretags) = "ssz-size:\"65536,32\""];
repeated bytes compact_committees_roots = 5004 [(gogoproto.moretags) = "ssz-size:\"65536,32\""];
repeated bytes randao_mixes = 5002 [(gogoproto.moretags) = "ssz-size:\"randao_mixes.size\""];
repeated bytes active_index_roots = 5003 [(gogoproto.moretags) = "ssz-size:\"active_index_roots.size\""];
repeated bytes compact_committees_roots = 5004 [(gogoproto.moretags) = "ssz-size:\"compact_committees_roots.size\""];
// Slashings [6001-7000]
repeated uint64 slashings = 6001 [(gogoproto.moretags) = "ssz-size:\"8192\""];
repeated uint64 slashings = 6001 [(gogoproto.moretags) = "ssz-size:\"slashings.size\""];
// Attestations [7001-8000]
repeated PendingAttestation previous_epoch_attestations = 7001 [(gogoproto.moretags) = "ssz-max:\"8192\""];
repeated PendingAttestation current_epoch_attestations = 7002 [(gogoproto.moretags) = "ssz-max:\"8192\""];
repeated PendingAttestation previous_epoch_attestations = 7001 [(gogoproto.moretags) = "ssz-max:\"previous_epoch_attestations.max\""];
repeated PendingAttestation current_epoch_attestations = 7002 [(gogoproto.moretags) = "ssz-max:\"current_epoch_attestations.max\""];
// Crosslinks [8001-9000]
repeated ethereum.eth.v1alpha1.Crosslink previous_crosslinks = 8001 [(gogoproto.moretags) = "ssz-size:\"1024\""];
repeated ethereum.eth.v1alpha1.Crosslink current_crosslinks = 8002 [(gogoproto.moretags) = "ssz-size:\"1024\""];
repeated ethereum.eth.v1alpha1.Crosslink previous_crosslinks = 8001 [(gogoproto.moretags) = "ssz-size:\"previous_crosslinks.size\""];
repeated ethereum.eth.v1alpha1.Crosslink current_crosslinks = 8002 [(gogoproto.moretags) = "ssz-size:\"current_crosslinks.size\""];
// Finality [9001-10000]
// Spec type [4]Bitvector which means this would be a fixed size of 4 bits.
@ -84,8 +84,8 @@ message AttestationDataAndCustodyBit {
}
message HistoricalBatch {
repeated bytes block_roots = 1 [(gogoproto.moretags) = "ssz-size:\"8192,32\""];
repeated bytes state_roots = 2 [(gogoproto.moretags) = "ssz-size:\"8192,32\""];
repeated bytes block_roots = 1 [(gogoproto.moretags) = "ssz-size:\"block_roots.size\""];
repeated bytes state_roots = 2 [(gogoproto.moretags) = "ssz-size:\"state_roots.size\""];
}
message CompactCommittee {

View File

@ -1,9 +1,10 @@
# gazelle:ignore
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
load("//proto:ssz_proto_library.bzl", "ssz_proto_files")
proto_library(
name = "v1alpha1_proto",
ssz_proto_files(
name = "ssz_proto_files",
srcs = [
"attestation.proto",
"beacon_block.proto",
@ -11,6 +12,16 @@ proto_library(
"node.proto",
"validator.proto",
],
config = select({
"//conditions:default": "mainnet",
"//proto:ssz_mainnet": "mainnet",
"//proto:ssz_minimal": "minimal",
}),
)
proto_library(
name = "v1alpha1_proto",
srcs = [":ssz_proto_files"],
visibility = ["//visibility:public"],
deps = [
"@com_google_protobuf//:empty_proto",
@ -31,9 +42,3 @@ go_proto_library(
"@go_googleapis//google/api:annotations_go_proto",
],
)
#go_library(
# name = "go_default_library",
# embed = [":v1alpha1_go_proto"],
# visibility = ["//visibility:public"],
#)

View File

@ -0,0 +1,69 @@
"""
SSZ proto templating rules.
These rules allow for variable substitution for hardcoded tag values like ssz-size and ssz-max.
"""
####### Configuration #######
mainnet = {
"block_roots.size": "8192,32",
"state_roots.size": "8192,32",
"eth1_data_votes.size": "1024",
"randao_mixes.size": "65536,32",
"active_index_roots.size": "65536,32",
"compact_committees_roots.size": "65536,32",
"previous_epoch_attestations.max": "8192",
"current_epoch_attestations.max": "8192",
"previous_crosslinks.size": "1024",
"current_crosslinks.size": "1024",
"slashings.size": "8192",
}
minimal = {
"block_roots.size": "64,32",
"state_roots.size": "64,32",
"eth1_data_votes.size": "16",
"randao_mixes.size": "64,32",
"active_index_roots.size": "64,32",
"compact_committees_roots.size": "64,32",
"previous_epoch_attestations.max": "1024",
"current_epoch_attestations.max": "1024",
"previous_crosslinks.size": "8",
"current_crosslinks.size": "8",
"slashings.size": "64",
}
###### Rules definitions #######
def _ssz_proto_files_impl(ctx):
"""
ssz_proto_files implementation performs expand_template based on the value of "config".
"""
outputs = []
if (ctx.attr.config.lower() == "mainnet"):
subs = mainnet
elif (ctx.attr.config.lower() == "minimal"):
subs = minimal
else:
fail("%s is an unknown configuration" % ctx.attr.config)
for src in ctx.attr.srcs:
output = ctx.actions.declare_file(src.files.to_list()[0].basename)
outputs.append(output)
ctx.actions.expand_template(
template = src.files.to_list()[0],
output = output,
substitutions = subs,
)
return [DefaultInfo(files = depset(outputs))]
ssz_proto_files = rule(
implementation = _ssz_proto_files_impl,
attrs = {
"srcs": attr.label_list(mandatory = True, allow_files = [".proto"]),
"config": attr.string(mandatory = True),
},
)

View File

@ -34,7 +34,6 @@ go_test(
name = "go_default_test",
size = "small",
srcs = [
"ssz_compatibility_test.go",
"ssz_regression_test.go",
"tags_test.go",
],
@ -54,3 +53,47 @@ go_test(
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
],
)
go_test(
name = "go_minimal_test",
size = "small",
srcs = [
"ssz_minimal_compatibility_test.go",
],
data = [
"@eth2_spec_tests//:test_data",
],
tags = ["spectest"],
deps = [
"//proto/beacon/p2p/v1:go_default_library",
"//proto/eth/v1alpha1:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/testutil:go_default_library",
"@com_github_ghodss_yaml//:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
"@com_github_prysmaticlabs_go_ssz//spectests:go_default_library",
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
],
)
go_test(
name = "go_mainnet_test",
size = "small",
srcs = [
"ssz_mainnet_compatibility_test.go",
],
data = [
"@eth2_spec_tests//:test_data",
],
tags = ["spectest"],
deps = [
"//proto/beacon/p2p/v1:go_default_library",
"//proto/eth/v1alpha1:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/testutil:go_default_library",
"@com_github_ghodss_yaml//:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
"@com_github_prysmaticlabs_go_ssz//spectests:go_default_library",
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
],
)

View File

@ -15,7 +15,7 @@ import (
"github.com/prysmaticlabs/prysm/shared/testutil"
)
func TestYamlStatic(t *testing.T) {
func TestYamlStatic_Mainnet(t *testing.T) {
topPath := "tests/ssz_static/core/"
yamlFileNames := []string{
"ssz_mainnet_random.yaml",
@ -35,11 +35,11 @@ func TestYamlStatic(t *testing.T) {
if err := yaml.Unmarshal(file, s); err != nil {
t.Fatalf("Failed to unmarshal: %v", err)
}
runTestCases(t, s)
runTestCasesMainnet(t, s)
}
}
func runTestCases(t *testing.T, s *sszspectest.SszMainnetTest) {
func runTestCasesMainnet(t *testing.T, s *sszspectest.SszMainnetTest) {
for _, testCase := range s.TestCases {
if !testutil.IsEmpty(testCase.Attestation.Value) {
p := &ethpb.Attestation{}

View File

@ -0,0 +1,356 @@
package testing
import (
"bytes"
"io/ioutil"
"path"
"testing"
"github.com/bazelbuild/rules_go/go/tools/bazel"
"github.com/ghodss/yaml"
"github.com/prysmaticlabs/go-ssz"
sszspectest "github.com/prysmaticlabs/go-ssz/spectests"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/testutil"
)
func TestYamlStatic_Minimal(t *testing.T) {
t.Skip("This test suite requires --define ssz=minimal to be provided and there isn't a great way to do that without breaking //...")
topPath := "tests/ssz_static/core/"
yamlFileNames := []string{
"ssz_minimal_random.yaml",
}
for _, f := range yamlFileNames {
fullPath := path.Join(topPath, f)
filepath, err := bazel.Runfile(fullPath)
if err != nil {
t.Fatal(err)
}
file, err := ioutil.ReadFile(filepath)
if err != nil {
t.Fatalf("Could not load file %v", err)
}
s := &sszspectest.SszMinimalTest{}
if err := yaml.Unmarshal(file, s); err != nil {
t.Fatalf("Failed to unmarshal: %v", err)
}
runTestCasesMinimal(t, s)
}
}
func runTestCasesMinimal(t *testing.T, s *sszspectest.SszMinimalTest) {
for _, testCase := range s.TestCases {
if !testutil.IsEmpty(testCase.Attestation.Value) {
p := &ethpb.Attestation{}
if err := testutil.ConvertToPb(testCase.Attestation.Value, p); err != nil {
t.Fatal(err)
}
root, err := ssz.HashTreeRoot(p)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(root[:], testCase.Attestation.Root) {
t.Errorf("Expected attestation root %#x, received %#x", testCase.Attestation.Root, root[:])
}
root, err = ssz.SigningRoot(p)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(root[:], testCase.Attestation.SigningRoot) {
t.Errorf("Expected attestation signing root data %#x, received %#x", testCase.AttestationData.Root, root[:])
}
}
if !testutil.IsEmpty(testCase.AttestationData.Value) {
p := &ethpb.AttestationData{}
if err := testutil.ConvertToPb(testCase.AttestationData.Value, p); err != nil {
t.Fatal(err)
}
root, err := ssz.HashTreeRoot(p)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(root[:], testCase.AttestationData.Root) {
t.Errorf("Expected attestation data %#x, received %#x", testCase.AttestationData.Root, root[:])
}
}
if !testutil.IsEmpty(testCase.AttestationDataAndCustodyBit.Value) {
p := &pb.AttestationDataAndCustodyBit{}
if err := testutil.ConvertToPb(testCase.AttestationDataAndCustodyBit.Value, p); err != nil {
t.Fatal(err)
}
root, err := ssz.HashTreeRoot(p)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(root[:], testCase.AttestationDataAndCustodyBit.Root) {
t.Errorf("Expected attestation data and custody bit %#x, received %#x", testCase.AttestationDataAndCustodyBit.Root, root[:])
}
}
if !testutil.IsEmpty(testCase.AttesterSlashing.Value) {
p := &ethpb.AttesterSlashing{}
if err := testutil.ConvertToPb(testCase.AttesterSlashing.Value, p); err != nil {
t.Fatal(err)
}
root, err := ssz.HashTreeRoot(p)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(root[:], testCase.AttesterSlashing.Root) {
t.Errorf("Expected attester slashing bit %#x, received %#x", testCase.AttesterSlashing.Root, root[:])
}
}
if !testutil.IsEmpty(testCase.BeaconBlock.Value) {
p := &ethpb.BeaconBlock{}
if err := testutil.ConvertToPb(testCase.BeaconBlock.Value, p); err != nil {
t.Fatal(err)
}
root, err := ssz.HashTreeRoot(p)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(root[:], testCase.BeaconBlock.Root) {
t.Errorf("Expected beacon block root %#x, received %#x", testCase.BeaconBlock.Root, root[:])
}
root, err = ssz.SigningRoot(p)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(root[:], testCase.BeaconBlock.SigningRoot) {
t.Errorf("Expected beacon block signing root %#x, received %#x", testCase.BeaconBlock.Root, root[:])
}
}
if !testutil.IsEmpty(testCase.BeaconBlockBody.Value) {
p := &ethpb.BeaconBlockBody{}
if err := testutil.ConvertToPb(testCase.BeaconBlockBody.Value, p); err != nil {
t.Fatal(err)
}
root, err := ssz.HashTreeRoot(p)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(root[:], testCase.BeaconBlockBody.Root) {
t.Errorf("Expected beacon block body %#x, received %#x", testCase.BeaconBlockBody.Root, root[:])
}
}
if !testutil.IsEmpty(testCase.BeaconBlockHeader.Value) {
p := &ethpb.BeaconBlockHeader{}
if err := testutil.ConvertToPb(testCase.BeaconBlockHeader.Value, p); err != nil {
t.Fatal(err)
}
root, err := ssz.HashTreeRoot(p)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(root[:], testCase.BeaconBlockHeader.Root) {
t.Errorf("Expected beacon block header root %#x, received %#x", testCase.BeaconBlockHeader.Root, root[:])
}
root, err = ssz.SigningRoot(p)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(root[:], testCase.BeaconBlockHeader.SigningRoot) {
t.Errorf("Expected beacon block header signing root %#x, received %#x", testCase.BeaconBlock.Root, root[:])
}
}
if !testutil.IsEmpty(testCase.BeaconState.Value) {
p := &pb.BeaconState{}
if err := testutil.ConvertToPb(testCase.BeaconState.Value, p); err != nil {
t.Fatal(err)
}
root, err := ssz.HashTreeRoot(p)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(root[:], testCase.BeaconState.Root) {
t.Errorf("Expected beacon state %#x, received %#x", testCase.BeaconState.Root, root[:])
}
}
if !testutil.IsEmpty(testCase.Crosslink.Value) {
c := &ethpb.Crosslink{}
if err := testutil.ConvertToPb(testCase.Crosslink.Value, c); err != nil {
t.Fatal(err)
}
root, err := ssz.HashTreeRoot(c)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(root[:], testCase.Crosslink.Root) {
t.Errorf("Expected crosslink %#x, received %#x", testCase.Crosslink.Root, root[:])
}
}
if !testutil.IsEmpty(testCase.Deposit.Value) {
p := &ethpb.Deposit{}
if err := testutil.ConvertToPb(testCase.Deposit.Value, p); err != nil {
t.Fatal(err)
}
root, err := ssz.HashTreeRoot(p)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(root[:], testCase.Deposit.Root) {
t.Errorf("Expected deposit root %#x, received %#x", testCase.Deposit.Root, root[:])
}
}
if !testutil.IsEmpty(testCase.DepositData.Value) {
p := &ethpb.Deposit_Data{}
if err := testutil.ConvertToPb(testCase.DepositData.Value, p); err != nil {
t.Fatal(err)
}
root, err := ssz.HashTreeRoot(p)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(root[:], testCase.DepositData.Root) {
t.Errorf("Expected deposit data root %#x, received %#x", testCase.DepositData.Root, root[:])
}
root, err = ssz.SigningRoot(p)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(root[:], testCase.DepositData.SigningRoot) {
t.Errorf("Expected deposit data signing root %#x, received %#x", testCase.BeaconBlock.Root, root[:])
}
}
if !testutil.IsEmpty(testCase.Eth1Data.Value) {
p := &ethpb.Eth1Data{}
if err := testutil.ConvertToPb(testCase.Eth1Data.Value, p); err != nil {
t.Fatal(err)
}
root, err := ssz.HashTreeRoot(p)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(root[:], testCase.Eth1Data.Root) {
t.Errorf("Expected pb data %#x, received %#x", testCase.Eth1Data.Root, root[:])
}
}
if !testutil.IsEmpty(testCase.Fork.Value) {
p := &pb.Fork{}
if err := testutil.ConvertToPb(testCase.Fork.Value, p); err != nil {
t.Fatal(err)
}
root, err := ssz.HashTreeRoot(p)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(root[:], testCase.Fork.Root) {
t.Errorf("Expected fork %#x, received %#x", testCase.Fork.Root, root[:])
}
}
if !testutil.IsEmpty(testCase.HistoricalBatch.Value) {
p := &pb.HistoricalBatch{}
if err := testutil.ConvertToPb(testCase.HistoricalBatch.Value, p); err != nil {
t.Fatal(err)
}
root, err := ssz.HashTreeRoot(p)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(root[:], testCase.HistoricalBatch.Root) {
t.Errorf("Expected historical batch %#x, received %#x", testCase.HistoricalBatch.Root, root[:])
}
}
if !testutil.IsEmpty(testCase.IndexedAttestation.Value) {
p := &ethpb.IndexedAttestation{}
if err := testutil.ConvertToPb(testCase.IndexedAttestation.Value, p); err != nil {
t.Fatal(err)
}
root, err := ssz.HashTreeRoot(p)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(root[:], testCase.IndexedAttestation.Root) {
t.Errorf("Expected indexed attestation root %#x, received %#x", testCase.IndexedAttestation.Root, root[:])
}
root, err = ssz.SigningRoot(p)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(root[:], testCase.IndexedAttestation.SigningRoot) {
t.Errorf("Expected indexed attestation signing root %#x, received %#x", testCase.BeaconBlock.Root, root[:])
}
}
if !testutil.IsEmpty(testCase.PendingAttestation.Value) {
p := &pb.PendingAttestation{}
if err := testutil.ConvertToPb(testCase.PendingAttestation.Value, p); err != nil {
t.Fatal(err)
}
root, err := ssz.HashTreeRoot(p)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(root[:], testCase.PendingAttestation.Root) {
t.Errorf("Expected pending attestation %#x, received %#x", testCase.PendingAttestation.Root, root[:])
}
}
if !testutil.IsEmpty(testCase.ProposerSlashing.Value) {
p := &ethpb.ProposerSlashing{}
if err := testutil.ConvertToPb(testCase.ProposerSlashing.Value, p); err != nil {
t.Fatal(err)
}
root, err := ssz.HashTreeRoot(p)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(root[:], testCase.ProposerSlashing.Root) {
t.Errorf("Expected proposer slashing %#x, received %#x", testCase.ProposerSlashing.Root, root[:])
}
}
if !testutil.IsEmpty(testCase.Transfer.Value) {
p := &ethpb.Transfer{}
if err := testutil.ConvertToPb(testCase.Transfer.Value, p); err != nil {
t.Fatal(err)
}
root, err := ssz.HashTreeRoot(p)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(root[:], testCase.Transfer.Root) {
t.Errorf("Expected transfer root %#x, received %#x", testCase.Transfer.Root, root[:])
}
root, err = ssz.SigningRoot(p)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(root[:], testCase.Transfer.SigningRoot) {
t.Errorf("Expected transfer signing root %#x, received %#x", testCase.BeaconBlock.Root, root[:])
}
}
if !testutil.IsEmpty(testCase.Validator.Value) {
p := &ethpb.Validator{}
if err := testutil.ConvertToPb(testCase.Validator.Value, p); err != nil {
t.Fatal(err)
}
root, err := ssz.HashTreeRoot(p)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(root[:], testCase.Validator.Root) {
t.Errorf("Expected validator %#x, received %#x", testCase.Validator.Root, root[:])
}
}
if !testutil.IsEmpty(testCase.VoluntaryExit.Value) {
p := &ethpb.VoluntaryExit{}
if err := testutil.ConvertToPb(testCase.VoluntaryExit.Value, p); err != nil {
t.Fatal(err)
}
root, err := ssz.HashTreeRoot(p)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(root[:], testCase.VoluntaryExit.Root) {
t.Errorf("Expected voluntary exit root %#x, received %#x", testCase.VoluntaryExit.Root, root[:])
}
root, err = ssz.SigningRoot(p)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(root[:], testCase.VoluntaryExit.SigningRoot) {
t.Errorf("Expected voluntary exit signing root %#x, received %#x", testCase.BeaconBlock.Root, root[:])
}
}
}
}