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

core: enable ssz encoding in protos #2286

Merged
merged 2 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion core/consensus/msg_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestHashProto(t *testing.T) {
require.NoError(t, err)

require.Equal(t,
"281aa1a75b2bd09f00f2d69bdf1256b83350dac475108cde608fc3f11428e54d",
"d8f9bc3de8b0cb0e3eb1f773c14a96d58f7acaf0f09192ce6562d84ea315e67b",
hex.EncodeToString(hash[:]),
)
}
Expand Down
12 changes: 6 additions & 6 deletions core/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import (
pbv1 "github.com/obolnetwork/charon/core/corepb/v1"
)

// sszMarshallingEnabled will be enabled in v0.17.
var sszMarshallingEnabled = false
// sszMarshallingEnabled is enabled from v0.17.
var sszMarshallingEnabled = true

// EnabledSSZMarshallingForT enables SSZ marshalling for the duration of the test.
func EnabledSSZMarshallingForT(t *testing.T) {
// DisableSSZMarshallingForT disables SSZ marshalling for the duration of the test.
func DisableSSZMarshallingForT(t *testing.T) {
t.Helper()
sszMarshallingEnabled = true
sszMarshallingEnabled = false
t.Cleanup(func() {
sszMarshallingEnabled = false
sszMarshallingEnabled = true
})
}

Expand Down
28 changes: 14 additions & 14 deletions core/ssz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ func TestMarshalUnsignedProto(t *testing.T) {

seed := time.Now().Unix()

for _, enabledSSZ := range []bool{true, false} {
for _, disableSSZ := range []bool{true, false} {
for i, test := range tests {
f := testutil.NewEth2Fuzzer(t, seed+int64(i)) // Use the same seed for ssz vs json for each type.

t.Run(fmt.Sprintf("%T_%v", test.unsignedPtr(), enabledSSZ), func(t *testing.T) {
if enabledSSZ {
core.EnabledSSZMarshallingForT(t)
t.Run(fmt.Sprintf("%T_%v", test.unsignedPtr(), disableSSZ), func(t *testing.T) {
if disableSSZ {
core.DisableSSZMarshallingForT(t)
}

unsignedPtr := test.unsignedPtr()
Expand All @@ -121,10 +121,10 @@ func TestMarshalUnsignedProto(t *testing.T) {

b, err := proto.Marshal(pb)
require.NoError(t, err)
if enabledSSZ {
sszSizes[fmt.Sprintf("%T", unsignedPtr)] = len(b)
} else {
if disableSSZ {
jsonSizes[fmt.Sprintf("%T", unsignedPtr)] = len(b)
} else {
sszSizes[fmt.Sprintf("%T", unsignedPtr)] = len(b)
}
})
}
Expand Down Expand Up @@ -170,13 +170,13 @@ func TestMarshalParSignedProto(t *testing.T) {

seed := time.Now().Unix()

for _, enabledSSZ := range []bool{true, false} {
for _, disabledSSZ := range []bool{true, false} {
for i, test := range tests {
f := testutil.NewEth2Fuzzer(t, seed+int64(i)) // Use the same seed for ssz vs json for each type.

t.Run(fmt.Sprintf("%T_%v", test.signedPtr(), enabledSSZ), func(t *testing.T) {
if enabledSSZ {
core.EnabledSSZMarshallingForT(t)
t.Run(fmt.Sprintf("%T_%v", test.signedPtr(), disabledSSZ), func(t *testing.T) {
if disabledSSZ {
core.DisableSSZMarshallingForT(t)
}

signedPtr := test.signedPtr()
Expand All @@ -202,10 +202,10 @@ func TestMarshalParSignedProto(t *testing.T) {

b, err := proto.Marshal(pb)
require.NoError(t, err)
if enabledSSZ {
sszSizes[fmt.Sprintf("%T", signedPtr)] = len(b)
} else {
if disabledSSZ {
jsonSizes[fmt.Sprintf("%T", signedPtr)] = len(b)
} else {
sszSizes[fmt.Sprintf("%T", signedPtr)] = len(b)
}
})
}
Expand Down