Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SSZ Compatibility Test #2924

Merged
merged 23 commits into from
Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
aab1716
figuring out how to seqeeze in multiple fields in a tag for pb
terencechain Jul 5, 2019
44b3e7d
Added max tags and regenerated pb.go
terencechain Jul 5, 2019
94cc34e
updated to new standard
terencechain Jul 5, 2019
2b82863
Merge branch 'spec-v0.6' of github.com:prysmaticlabs/prysm into updat…
prestonvanloon Jul 6, 2019
bd8425b
New bitfield types in proto (#2915)
prestonvanloon Jul 6, 2019
7212322
use proper override for gogo-protobuf
prestonvanloon Jul 7, 2019
6a925f2
fix a few tags
prestonvanloon Jul 7, 2019
c9973c5
forgot to include custody bits and Slashable not used
terencechain Jul 7, 2019
ab25218
Update yaml struct to use pb
terencechain Jul 8, 2019
1ad731c
Update workspace to use latest ssz
terencechain Jul 8, 2019
2014f50
All tests fail
terencechain Jul 8, 2019
c96839c
Merge branch 'update-max-size-tag' into fix-ssz-compat-tests
terencechain Jul 8, 2019
f48d9e9
Merge branch 'spec-v0.6' of https://github.com/prysmaticlabs/prysm in…
terencechain Jul 8, 2019
97c79ab
Use the latest go-ssz commit
terencechain Jul 8, 2019
bbe004a
All pass except for state (too long to taste)
terencechain Jul 8, 2019
77dc2f4
Merge branch 'spec-v0.6' of https://github.com/prysmaticlabs/prysm in…
terencechain Jul 8, 2019
eba2533
Update test.proto
terencechain Jul 8, 2019
091b80c
Added rest of the tests
terencechain Jul 9, 2019
192dda2
Merge branch 'fix-ssz-compat-tests' of https://github.com/prysmaticla…
terencechain Jul 9, 2019
9c8ef7f
state still fails, need investigation for justification_bits
terencechain Jul 9, 2019
148bc8d
use 1 justification bits
terencechain Jul 9, 2019
76eb83b
fix tag test, apply @rauljordan's suggestion
prestonvanloon Jul 9, 2019
234aefb
add IsEmpty and use ssz struct
prestonvanloon Jul 9, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions proto/beacon/p2p/v1/messages.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

295 changes: 147 additions & 148 deletions proto/beacon/p2p/v1/types.pb.go

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions proto/beacon/p2p/v1/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ message BeaconState {
repeated bytes compact_committees_roots = 5004 [(gogoproto.moretags) = "ssz-size:\"65536,32\""];

// Slashings [6001-7000]
repeated uint64 slashings = 6001 [(gogoproto.moretags) = "ssz:\"size=8192\""];
repeated uint64 slashings = 6001 [(gogoproto.moretags) = "ssz-size:\"8192\""];

// Attestations [7001-8000]
repeated PendingAttestation previous_epoch_attestations = 7001 [(gogoproto.moretags) = "ssz-max:\"8192\""];
Expand All @@ -45,7 +45,7 @@ message BeaconState {

// Finality [9001-10000]
// Spec type [4]Bitvector which means this would be a fixed size of 4 bits.
bytes justification_bits = 9001 [(gogoproto.casttype) = "github.com/prysmaticlabs/go-bitfield.Bitvector4"];
bytes justification_bits = 9001 [(gogoproto.moretags) = "ssz-size:\"1\"", (gogoproto.casttype) = "github.com/prysmaticlabs/go-bitfield.Bitvector4"];
Checkpoint previous_justified_checkpoint = 9002;
Checkpoint current_justified_checkpoint = 9003;
Checkpoint finalized_checkpoint = 9004;
Expand Down Expand Up @@ -296,5 +296,5 @@ message CompactCommittee {
// The list of the validator public keys in the committee.
repeated bytes pubkeys = 1 [(gogoproto.moretags) = "ssz-size:\"?,48\" ssz-max:\"4096\""];
// The list of the validator indices in the committee.
repeated uint64 compact_validators = 2 [(gogoproto.moretags) = "ssz-size:\"4096\""];
repeated uint64 compact_validators = 2 [(gogoproto.moretags) = "ssz-max:\"4096\""];
}
274 changes: 145 additions & 129 deletions proto/beacon/rpc/v1/services.pb.go

Large diffs are not rendered by default.

230 changes: 115 additions & 115 deletions proto/beacon/rpc/v1_gateway/services.pb.go

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions proto/sharding/p2p/v1/messages.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions proto/testing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ go_proto_library(
go_library(
name = "go_default_library",
testonly = True,
srcs = ["ssz_minimal.yaml.go"],
srcs = ["ssz_protobuf.yaml.go"],
embed = [":ethereum_testing_go_proto"],
importpath = "github.com/prysmaticlabs/prysm/proto/testing",
visibility = ["//visibility:public"],
Expand All @@ -42,10 +42,10 @@ go_test(
tags = ["spectest"],
deps = [
"//proto/beacon/p2p/v1:go_default_library",
"//shared/params/spectest: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",
],
)
90 changes: 43 additions & 47 deletions proto/testing/ssz_compatibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,44 @@ package testing
import (
"bytes"
"io/ioutil"
"reflect"
"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"
"github.com/prysmaticlabs/prysm/shared/params/spectest"
"github.com/prysmaticlabs/prysm/shared/testutil"
)

func TestMainnetRandomYaml(t *testing.T) {
filepath, err := bazel.Runfile("/eth2_spec_tests/tests/ssz_static/core/ssz_mainnet_random.yaml")
if err != nil {
t.Fatal(err)
}
file, err := ioutil.ReadFile(filepath)
if err != nil {
t.Fatalf("Could not load file %v", err)
}

s := &SszMinimalTest{}
if err := yaml.Unmarshal(file, s); err != nil {
t.Fatalf("Failed to unmarshal: %v", err)
func TestYamlStatic(t *testing.T) {
topPath := "/eth2_spec_tests/tests/ssz_static/core/"
yamlFileNames := []string{
"ssz_mainnet_random.yaml",
}

if err := spectest.SetConfig(s.Config); err != nil {
t.Fatal(err)
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.SszMainnetTest{}
if err := yaml.Unmarshal(file, s); err != nil {
t.Fatalf("Failed to unmarshal: %v", err)
}
runTestCases(t, s)
}
}

func runTestCases(t *testing.T, s *sszspectest.SszMainnetTest) {
for _, testCase := range s.TestCases {
if !isEmpty(testCase.Attestation.Value) {
if !testutil.IsEmpty(testCase.Attestation.Value) {
p := &pb.Attestation{}
if err := testutil.ConvertToPb(testCase.Attestation.Value, p); err != nil {
t.Fatal(err)
Expand All @@ -47,7 +53,7 @@ func TestMainnetRandomYaml(t *testing.T) {
t.Errorf("Expected attestation %#x, received %#x", testCase.Attestation.Root, root[:])
}
}
if !isEmpty(testCase.AttestationData.Value) {
if !testutil.IsEmpty(testCase.AttestationData.Value) {
p := &pb.AttestationData{}
if err := testutil.ConvertToPb(testCase.AttestationData.Value, p); err != nil {
t.Fatal(err)
Expand All @@ -60,7 +66,7 @@ func TestMainnetRandomYaml(t *testing.T) {
t.Errorf("Expected attestation data %#x, received %#x", testCase.AttestationData.Root, root[:])
}
}
if !isEmpty(testCase.AttestationDataAndCustodyBit.Value) {
if !testutil.IsEmpty(testCase.AttestationDataAndCustodyBit.Value) {
p := &pb.AttestationDataAndCustodyBit{}
if err := testutil.ConvertToPb(testCase.AttestationDataAndCustodyBit.Value, p); err != nil {
t.Fatal(err)
Expand All @@ -73,7 +79,7 @@ func TestMainnetRandomYaml(t *testing.T) {
t.Errorf("Expected attestation data and custody bit %#x, received %#x", testCase.AttestationDataAndCustodyBit.Root, root[:])
}
}
if !isEmpty(testCase.AttesterSlashing.Value) {
if !testutil.IsEmpty(testCase.AttesterSlashing.Value) {
p := &pb.AttesterSlashing{}
if err := testutil.ConvertToPb(testCase.AttesterSlashing.Value, p); err != nil {
t.Fatal(err)
Expand All @@ -86,7 +92,7 @@ func TestMainnetRandomYaml(t *testing.T) {
t.Errorf("Expected attester slashing bit %#x, received %#x", testCase.AttesterSlashing.Root, root[:])
}
}
if !isEmpty(testCase.BeaconBlock.Value) {
if !testutil.IsEmpty(testCase.BeaconBlock.Value) {
p := &pb.BeaconBlock{}
if err := testutil.ConvertToPb(testCase.BeaconBlock.Value, p); err != nil {
t.Fatal(err)
Expand All @@ -99,7 +105,7 @@ func TestMainnetRandomYaml(t *testing.T) {
t.Errorf("Expected beacon block %#x, received %#x", testCase.BeaconBlock.Root, root[:])
}
}
if !isEmpty(testCase.BeaconBlockBody.Value) {
if !testutil.IsEmpty(testCase.BeaconBlockBody.Value) {
p := &pb.BeaconBlockBody{}
if err := testutil.ConvertToPb(testCase.BeaconBlockBody.Value, p); err != nil {
t.Fatal(err)
Expand All @@ -112,7 +118,7 @@ func TestMainnetRandomYaml(t *testing.T) {
t.Errorf("Expected beacon block body %#x, received %#x", testCase.BeaconBlockBody.Root, root[:])
}
}
if !isEmpty(testCase.BeaconBlockHeader.Value) {
if !testutil.IsEmpty(testCase.BeaconBlockHeader.Value) {
p := &pb.BeaconBlockHeader{}
if err := testutil.ConvertToPb(testCase.BeaconBlockHeader.Value, p); err != nil {
t.Fatal(err)
Expand All @@ -125,7 +131,7 @@ func TestMainnetRandomYaml(t *testing.T) {
t.Errorf("Expected beacon block header %#x, received %#x", testCase.BeaconBlockHeader.Root, root[:])
}
}
if !isEmpty(testCase.BeaconState.Value) {
if !testutil.IsEmpty(testCase.BeaconState.Value) {
p := &pb.BeaconState{}
if err := testutil.ConvertToPb(testCase.BeaconState.Value, p); err != nil {
t.Fatal(err)
Expand All @@ -138,7 +144,7 @@ func TestMainnetRandomYaml(t *testing.T) {
t.Errorf("Expected beacon state %#x, received %#x", testCase.BeaconState.Root, root[:])
}
}
if !isEmpty(testCase.Crosslink.Value) {
if !testutil.IsEmpty(testCase.Crosslink.Value) {
c := &pb.Crosslink{}
if err := testutil.ConvertToPb(testCase.Crosslink.Value, c); err != nil {
t.Fatal(err)
Expand All @@ -151,7 +157,7 @@ func TestMainnetRandomYaml(t *testing.T) {
t.Errorf("Expected crosslink %#x, received %#x", testCase.Crosslink.Root, root[:])
}
}
if !isEmpty(testCase.Deposit.Value) {
if !testutil.IsEmpty(testCase.Deposit.Value) {
p := &pb.Deposit{}
if err := testutil.ConvertToPb(testCase.Deposit.Value, p); err != nil {
t.Fatal(err)
Expand All @@ -164,7 +170,7 @@ func TestMainnetRandomYaml(t *testing.T) {
t.Errorf("Expected deposit root %#x, received %#x", testCase.Deposit.Root, root[:])
}
}
if !isEmpty(testCase.DepositData.Value) {
if !testutil.IsEmpty(testCase.DepositData.Value) {
p := &pb.DepositData{}
if err := testutil.ConvertToPb(testCase.DepositData.Value, p); err != nil {
t.Fatal(err)
Expand All @@ -177,7 +183,7 @@ func TestMainnetRandomYaml(t *testing.T) {
t.Errorf("Expected deposit data %#x, received %#x", testCase.DepositData.Root, root[:])
}
}
if !isEmpty(testCase.Eth1Data.Value) {
if !testutil.IsEmpty(testCase.Eth1Data.Value) {
p := &pb.Eth1Data{}
if err := testutil.ConvertToPb(testCase.Eth1Data.Value, p); err != nil {
t.Fatal(err)
Expand All @@ -190,7 +196,7 @@ func TestMainnetRandomYaml(t *testing.T) {
t.Errorf("Expected eth1 data %#x, received %#x", testCase.Eth1Data.Root, root[:])
}
}
if !isEmpty(testCase.Fork.Value) {
if !testutil.IsEmpty(testCase.Fork.Value) {
p := &pb.Fork{}
if err := testutil.ConvertToPb(testCase.Fork.Value, p); err != nil {
t.Fatal(err)
Expand All @@ -203,7 +209,7 @@ func TestMainnetRandomYaml(t *testing.T) {
t.Errorf("Expected fork %#x, received %#x", testCase.Fork.Root, root[:])
}
}
if !isEmpty(testCase.HistoricalBatch.Value) {
if !testutil.IsEmpty(testCase.HistoricalBatch.Value) {
p := &pb.HistoricalBatch{}
if err := testutil.ConvertToPb(testCase.HistoricalBatch.Value, p); err != nil {
t.Fatal(err)
Expand All @@ -216,7 +222,7 @@ func TestMainnetRandomYaml(t *testing.T) {
t.Errorf("Expected historical batch %#x, received %#x", testCase.HistoricalBatch.Root, root[:])
}
}
if !isEmpty(testCase.IndexedAttestation.Value) {
if !testutil.IsEmpty(testCase.IndexedAttestation.Value) {
p := &pb.IndexedAttestation{}
if err := testutil.ConvertToPb(testCase.IndexedAttestation.Value, p); err != nil {
t.Fatal(err)
Expand All @@ -229,7 +235,7 @@ func TestMainnetRandomYaml(t *testing.T) {
t.Errorf("Expected indexed attestation %#x, received %#x", testCase.IndexedAttestation.Root, root[:])
}
}
if !isEmpty(testCase.PendingAttestation.Value) {
if !testutil.IsEmpty(testCase.PendingAttestation.Value) {
p := &pb.PendingAttestation{}
if err := testutil.ConvertToPb(testCase.PendingAttestation.Value, p); err != nil {
t.Fatal(err)
Expand All @@ -242,7 +248,7 @@ func TestMainnetRandomYaml(t *testing.T) {
t.Errorf("Expected pending attestation %#x, received %#x", testCase.PendingAttestation.Root, root[:])
}
}
if !isEmpty(testCase.ProposerSlashing.Value) {
if !testutil.IsEmpty(testCase.ProposerSlashing.Value) {
p := &pb.ProposerSlashing{}
if err := testutil.ConvertToPb(testCase.ProposerSlashing.Value, p); err != nil {
t.Fatal(err)
Expand All @@ -255,7 +261,7 @@ func TestMainnetRandomYaml(t *testing.T) {
t.Errorf("Expected proposer slashing %#x, received %#x", testCase.ProposerSlashing.Root, root[:])
}
}
if !isEmpty(testCase.Transfer.Value) {
if !testutil.IsEmpty(testCase.Transfer.Value) {
p := &pb.Transfer{}
if err := testutil.ConvertToPb(testCase.Transfer.Value, p); err != nil {
t.Fatal(err)
Expand All @@ -268,7 +274,7 @@ func TestMainnetRandomYaml(t *testing.T) {
t.Errorf("Expected trasnfer %#x, received %#x", testCase.Transfer.Root, root[:])
}
}
if !isEmpty(testCase.Validator.Value) {
if !testutil.IsEmpty(testCase.Validator.Value) {
p := &pb.Validator{}
if err := testutil.ConvertToPb(testCase.Validator.Value, p); err != nil {
t.Fatal(err)
Expand All @@ -281,7 +287,7 @@ func TestMainnetRandomYaml(t *testing.T) {
t.Errorf("Expected trasnfer %#x, received %#x", testCase.Validator.Root, root[:])
}
}
if !isEmpty(testCase.VoluntaryExit.Value) {
if !testutil.IsEmpty(testCase.VoluntaryExit.Value) {
p := &pb.VoluntaryExit{}
if err := testutil.ConvertToPb(testCase.VoluntaryExit.Value, p); err != nil {
t.Fatal(err)
Expand All @@ -296,13 +302,3 @@ func TestMainnetRandomYaml(t *testing.T) {
}
}
}

func isEmpty(item interface{}) bool {
val := reflect.ValueOf(item)
for i := 0; i < val.NumField(); i++ {
if !reflect.DeepEqual(val.Field(i).Interface(), reflect.Zero(val.Field(i).Type()).Interface()) {
return false
}
}
return true
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions proto/testing/tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ func sszTagSizes(i interface{}, fName string) ([]int, error) {
if !exists {
return nil, errors.New("wanted field does not exist")
}
tag, exists := field.Tag.Lookup("ssz")
tag, exists := field.Tag.Lookup("ssz-size")
if !exists {
return nil, errors.New("wanted field does not contain ssz tag")
return nil, errors.New("wanted field does not contain ssz-size tag")
}
start := strings.IndexRune(tag, '=')
items := strings.Split(tag[start+1:], ",")
Expand Down
1 change: 1 addition & 0 deletions shared/testutil/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ go_library(
srcs = [
"checkbit.go",
"helpers.go",
"is_empty.go",
"json_to_pb_converter.go",
"log.go",
"tempdir.go",
Expand Down
14 changes: 14 additions & 0 deletions shared/testutil/is_empty.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package testutil

import "reflect"

// IsEmpty returns true if the struct is empty.
func IsEmpty(item interface{}) bool {
val := reflect.ValueOf(item)
for i := 0; i < val.NumField(); i++ {
if !reflect.DeepEqual(val.Field(i).Interface(), reflect.Zero(val.Field(i).Type()).Interface()) {
return false
}
}
return true
}