mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 23:18:15 -05:00
Copied over ssz.DeepEqual as sszutil.DeepEqual from go-ssz (#8258)
* Copied over ssz.DeepEqual as sszutil.DeepEqual from go-ssz * Added test cases for DeepEqual * Remove commented code
This commit is contained in:
@@ -74,6 +74,7 @@ go_test(
|
||||
"//shared/bytesutil:go_default_library",
|
||||
"//shared/hashutil:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/sszutil:go_default_library",
|
||||
"//shared/testutil:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
@@ -82,7 +83,6 @@ go_test(
|
||||
"@com_github_google_gofuzz//:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -6,10 +6,10 @@ import (
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
|
||||
beaconstate "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/sszutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
)
|
||||
@@ -34,7 +34,7 @@ func TestSkipSlotCache_OK(t *testing.T) {
|
||||
bState, err = state.ExecuteStateTransition(context.Background(), bState, blk)
|
||||
require.NoError(t, err, "Could not process state transition")
|
||||
|
||||
if !ssz.DeepEqual(originalState.CloneInnerState(), bState.CloneInnerState()) {
|
||||
if !sszutil.DeepEqual(originalState.CloneInnerState(), bState.CloneInnerState()) {
|
||||
t.Fatal("Skipped slots cache leads to different states")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,13 +61,13 @@ go_test(
|
||||
"//shared/bytesutil:go_default_library",
|
||||
"//shared/interop:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/sszutil:go_default_library",
|
||||
"//shared/testutil:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"@com_github_gogo_protobuf//proto:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -8,12 +8,12 @@ import (
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/interop"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/sszutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -225,7 +225,7 @@ func TestForkManualCopy_OK(t *testing.T) {
|
||||
require.NoError(t, a.SetFork(wantedFork))
|
||||
|
||||
newState := a.CloneInnerState()
|
||||
if !ssz.DeepEqual(newState.Fork, wantedFork) {
|
||||
if !sszutil.DeepEqual(newState.Fork, wantedFork) {
|
||||
t.Errorf("Wanted %v but got %v", wantedFork, newState.Fork)
|
||||
}
|
||||
|
||||
|
||||
@@ -78,6 +78,7 @@ go_library(
|
||||
"//shared/runutil:go_default_library",
|
||||
"//shared/sliceutil:go_default_library",
|
||||
"//shared/slotutil:go_default_library",
|
||||
"//shared/sszutil:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//shared/traceutil:go_default_library",
|
||||
"@com_github_gogo_protobuf//proto:go_default_library",
|
||||
@@ -94,7 +95,6 @@ go_library(
|
||||
"@com_github_prometheus_client_golang//prometheus:go_default_library",
|
||||
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@com_github_trailofbits_go_mutexasserts//:go_default_library",
|
||||
"@io_opencensus_go//trace:go_default_library",
|
||||
@@ -160,6 +160,7 @@ go_test(
|
||||
"//shared/bytesutil:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/rand:go_default_library",
|
||||
"//shared/sszutil:go_default_library",
|
||||
"//shared/testutil:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/types"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
@@ -17,6 +16,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/rand"
|
||||
"github.com/prysmaticlabs/prysm/shared/runutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/slotutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/sszutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/traceutil"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/trailofbits/go-mutexasserts"
|
||||
@@ -302,7 +302,7 @@ func (s *Service) deleteBlockFromPendingQueue(slot uint64, b *ethpb.SignedBeacon
|
||||
|
||||
newBlks := make([]*ethpb.SignedBeaconBlock, 0, len(blks))
|
||||
for _, blk := range blks {
|
||||
if ssz.DeepEqual(blk, b) {
|
||||
if sszutil.DeepEqual(blk, b) {
|
||||
continue
|
||||
}
|
||||
newBlks = append(newBlks, blk)
|
||||
|
||||
@@ -10,11 +10,11 @@ import (
|
||||
|
||||
"github.com/libp2p/go-libp2p-core/network"
|
||||
"github.com/libp2p/go-libp2p-core/protocol"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
db "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
|
||||
p2ptest "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/sszutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
@@ -108,7 +108,7 @@ func TestMetadataRPCHandler_SendsMetadata(t *testing.T) {
|
||||
metadata, err := r.sendMetaDataRequest(context.Background(), p2.BHost.ID())
|
||||
assert.NoError(t, err)
|
||||
|
||||
if !ssz.DeepEqual(metadata, p2.LocalMetadata) {
|
||||
if !sszutil.DeepEqual(metadata, p2.LocalMetadata) {
|
||||
t.Fatalf("Metadata unequal, received %v but wanted %v", metadata, p2.LocalMetadata)
|
||||
}
|
||||
|
||||
|
||||
@@ -36,11 +36,11 @@ go_test(
|
||||
"//shared/bls:go_default_library",
|
||||
"//shared/featureconfig:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/sszutil:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -8,12 +8,12 @@ import (
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/shared/aggregation"
|
||||
aggtesting "github.com/prysmaticlabs/prysm/shared/aggregation/testing"
|
||||
"github.com/prysmaticlabs/prysm/shared/bls"
|
||||
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/sszutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -54,7 +54,7 @@ func TestAggregateAttestations_AggregatePair(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
got, err := AggregatePair(tt.a1, tt.a2)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, true, ssz.DeepEqual(got, tt.want))
|
||||
require.Equal(t, true, sszutil.DeepEqual(got, tt.want))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
21
shared/sszutil/BUILD.bazel
Normal file
21
shared/sszutil/BUILD.bazel
Normal file
@@ -0,0 +1,21 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_test")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["deep_equal.go"],
|
||||
importpath = "github.com/prysmaticlabs/prysm/shared/sszutil",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
size = "small",
|
||||
srcs = ["deep_equal_test.go"],
|
||||
deps = [
|
||||
":go_default_library",
|
||||
"//proto/beacon/p2p/v1:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
],
|
||||
)
|
||||
191
shared/sszutil/deep_equal.go
Normal file
191
shared/sszutil/deep_equal.go
Normal file
@@ -0,0 +1,191 @@
|
||||
package sszutil
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// During deepValueEqual, must keep track of checks that are
|
||||
// in progress. The comparison algorithm assumes that all
|
||||
// checks in progress are true when it reencounters them.
|
||||
// Visited comparisons are stored in a map indexed by visit.
|
||||
type visit struct {
|
||||
a1 unsafe.Pointer
|
||||
a2 unsafe.Pointer
|
||||
typ reflect.Type
|
||||
}
|
||||
|
||||
// Copyright 2009 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
//
|
||||
// This file extends Go's reflect.DeepEqual function into a sszutil.DeepEqual
|
||||
// function that is compliant with the supported types of ssz and its
|
||||
// intricacies when determining equality of empty values.
|
||||
//
|
||||
// Tests for deep equality using reflected types. The map argument tracks
|
||||
// comparisons that have already been seen, which allows short circuiting on
|
||||
// recursive types.
|
||||
func deepValueEqual(v1, v2 reflect.Value, visited map[visit]bool, depth int) bool {
|
||||
if !v1.IsValid() || !v2.IsValid() {
|
||||
return v1.IsValid() == v2.IsValid()
|
||||
}
|
||||
if v1.Type() != v2.Type() {
|
||||
return false
|
||||
}
|
||||
|
||||
// We want to avoid putting more in the visited map than we need to.
|
||||
// For any possible reference cycle that might be encountered,
|
||||
// hard(t) needs to return true for at least one of the types in the cycle.
|
||||
hard := func(k reflect.Kind) bool {
|
||||
switch k {
|
||||
case reflect.Slice, reflect.Ptr, reflect.Interface:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
if v1.CanAddr() && v2.CanAddr() && hard(v1.Kind()) {
|
||||
addr1 := unsafe.Pointer(v1.UnsafeAddr())
|
||||
addr2 := unsafe.Pointer(v2.UnsafeAddr())
|
||||
if uintptr(addr1) > uintptr(addr2) {
|
||||
// Canonicalize order to reduce number of entries in visited.
|
||||
// Assumes non-moving garbage collector.
|
||||
addr1, addr2 = addr2, addr1
|
||||
}
|
||||
|
||||
// Short circuit if references are already seen.
|
||||
typ := v1.Type()
|
||||
v := visit{addr1, addr2, typ}
|
||||
if visited[v] {
|
||||
return true
|
||||
}
|
||||
|
||||
// Remember for later.
|
||||
visited[v] = true
|
||||
}
|
||||
|
||||
switch v1.Kind() {
|
||||
case reflect.String:
|
||||
return v1.String() == v2.String()
|
||||
case reflect.Array:
|
||||
for i := 0; i < v1.Len(); i++ {
|
||||
if !deepValueEqual(v1.Index(i), v2.Index(i), visited, depth+1) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
case reflect.Slice:
|
||||
if v1.IsNil() && v2.Len() == 0 {
|
||||
return true
|
||||
}
|
||||
if v1.Len() == 0 && v2.IsNil() {
|
||||
return true
|
||||
}
|
||||
if v1.IsNil() && v2.IsNil() {
|
||||
return true
|
||||
}
|
||||
if v1.Len() != v2.Len() {
|
||||
return false
|
||||
}
|
||||
if v1.Pointer() == v2.Pointer() {
|
||||
return true
|
||||
}
|
||||
for i := 0; i < v1.Len(); i++ {
|
||||
if !deepValueEqual(v1.Index(i), v2.Index(i), visited, depth+1) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
case reflect.Interface:
|
||||
if v1.IsNil() || v2.IsNil() {
|
||||
return v1.IsNil() == v2.IsNil()
|
||||
}
|
||||
return deepValueEqual(v1.Elem(), v2.Elem(), visited, depth+1)
|
||||
case reflect.Ptr:
|
||||
if v1.Pointer() == v2.Pointer() {
|
||||
return true
|
||||
}
|
||||
return deepValueEqual(v1.Elem(), v2.Elem(), visited, depth+1)
|
||||
case reflect.Struct:
|
||||
for i, n := 0, v1.NumField(); i < n; i++ {
|
||||
if !deepValueEqual(v1.Field(i), v2.Field(i), visited, depth+1) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
case reflect.Uint64:
|
||||
return v1.Interface().(uint64) == v2.Interface().(uint64)
|
||||
case reflect.Uint32:
|
||||
return v1.Interface().(uint32) == v2.Interface().(uint32)
|
||||
case reflect.Int32:
|
||||
return v1.Interface().(int32) == v2.Interface().(int32)
|
||||
case reflect.Uint16:
|
||||
return v1.Interface().(uint16) == v2.Interface().(uint16)
|
||||
case reflect.Uint8:
|
||||
return v1.Interface().(uint8) == v2.Interface().(uint8)
|
||||
case reflect.Bool:
|
||||
return v1.Interface().(bool) == v2.Interface().(bool)
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// DeepEqual reports whether two SSZ-able values x and y are ``deeply equal,'' defined as follows:
|
||||
// Two values of identical type are deeply equal if one of the following cases applies:
|
||||
//
|
||||
// Values of distinct types are never deeply equal.
|
||||
//
|
||||
// Array values are deeply equal when their corresponding elements are deeply equal.
|
||||
//
|
||||
// Struct values are deeply equal if their corresponding fields,
|
||||
// both exported and unexported, are deeply equal.
|
||||
//
|
||||
// Interface values are deeply equal if they hold deeply equal concrete values.
|
||||
//
|
||||
// Pointer values are deeply equal if they are equal using Go's == operator
|
||||
// or if they point to deeply equal values.
|
||||
//
|
||||
// Slice values are deeply equal when all of the following are true:
|
||||
// they are both nil, one is nil and the other is empty or vice-versa,
|
||||
// they have the same length, and either they point to the same initial entry of the same array
|
||||
// (that is, &x[0] == &y[0]) or their corresponding elements (up to length) are deeply equal.
|
||||
//
|
||||
// Other values - numbers, bools, strings, and channels - are deeply equal
|
||||
// if they are equal using Go's == operator.
|
||||
//
|
||||
// In general DeepEqual is a recursive relaxation of Go's == operator.
|
||||
// However, this idea is impossible to implement without some inconsistency.
|
||||
// Specifically, it is possible for a value to be unequal to itself,
|
||||
// either because it is of func type (uncomparable in general)
|
||||
// or because it is a floating-point NaN value (not equal to itself in floating-point comparison),
|
||||
// or because it is an array, struct, or interface containing
|
||||
// such a value.
|
||||
//
|
||||
// On the other hand, pointer values are always equal to themselves,
|
||||
// even if they point at or contain such problematic values,
|
||||
// because they compare equal using Go's == operator, and that
|
||||
// is a sufficient condition to be deeply equal, regardless of content.
|
||||
// DeepEqual has been defined so that the same short-cut applies
|
||||
// to slices and maps: if x and y are the same slice or the same map,
|
||||
// they are deeply equal regardless of content.
|
||||
//
|
||||
// As DeepEqual traverses the data values it may find a cycle. The
|
||||
// second and subsequent times that DeepEqual compares two pointer
|
||||
// values that have been compared before, it treats the values as
|
||||
// equal rather than examining the values to which they point.
|
||||
// This ensures that DeepEqual terminates.
|
||||
//
|
||||
// Credits go to the Go team as this is an extension of the official Go source code's
|
||||
// reflect.DeepEqual function to handle special SSZ edge cases.
|
||||
func DeepEqual(x, y interface{}) bool {
|
||||
if x == nil || y == nil {
|
||||
return x == y
|
||||
}
|
||||
v1 := reflect.ValueOf(x)
|
||||
v2 := reflect.ValueOf(y)
|
||||
if v1.Type() != v2.Type() {
|
||||
return false
|
||||
}
|
||||
return deepValueEqual(v1, v2, make(map[visit]bool), 0)
|
||||
}
|
||||
73
shared/sszutil/deep_equal_test.go
Normal file
73
shared/sszutil/deep_equal_test.go
Normal file
@@ -0,0 +1,73 @@
|
||||
package sszutil_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/sszutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
)
|
||||
|
||||
func TestDeepEqualBasicTypes(t *testing.T) {
|
||||
assert.Equal(t, true, sszutil.DeepEqual(true, true))
|
||||
assert.Equal(t, false, sszutil.DeepEqual(true, false))
|
||||
|
||||
assert.Equal(t, true, sszutil.DeepEqual(byte(222), byte(222)))
|
||||
assert.Equal(t, false, sszutil.DeepEqual(byte(222), byte(111)))
|
||||
|
||||
assert.Equal(t, true, sszutil.DeepEqual(uint64(1234567890), uint64(1234567890)))
|
||||
assert.Equal(t, false, sszutil.DeepEqual(uint64(1234567890), uint64(987653210)))
|
||||
|
||||
assert.Equal(t, true, sszutil.DeepEqual("hello", "hello"))
|
||||
assert.Equal(t, false, sszutil.DeepEqual("hello", "world"))
|
||||
|
||||
assert.Equal(t, true, sszutil.DeepEqual([3]byte{1, 2, 3}, [3]byte{1, 2, 3}))
|
||||
assert.Equal(t, false, sszutil.DeepEqual([3]byte{1, 2, 3}, [3]byte{1, 2, 4}))
|
||||
|
||||
var nilSlice1, nilSlice2 []byte
|
||||
assert.Equal(t, true, sszutil.DeepEqual(nilSlice1, nilSlice2))
|
||||
assert.Equal(t, true, sszutil.DeepEqual(nilSlice1, []byte{}))
|
||||
assert.Equal(t, true, sszutil.DeepEqual([]byte{1, 2, 3}, []byte{1, 2, 3}))
|
||||
assert.Equal(t, false, sszutil.DeepEqual([]byte{1, 2, 3}, []byte{1, 2, 4}))
|
||||
}
|
||||
|
||||
func TestDeepEqualStructs(t *testing.T) {
|
||||
type Store struct {
|
||||
V1 uint64
|
||||
V2 []byte
|
||||
}
|
||||
store1 := Store{uint64(1234), nil}
|
||||
store2 := Store{uint64(1234), []byte{}}
|
||||
store3 := Store{uint64(4321), []byte{}}
|
||||
assert.Equal(t, true, sszutil.DeepEqual(store1, store2))
|
||||
assert.Equal(t, false, sszutil.DeepEqual(store1, store3))
|
||||
}
|
||||
|
||||
func TestDeepEqualProto(t *testing.T) {
|
||||
var fork1, fork2 pb.Fork
|
||||
assert.Equal(t, true, sszutil.DeepEqual(fork1, fork2))
|
||||
|
||||
fork1 = pb.Fork{
|
||||
PreviousVersion: []byte{123},
|
||||
CurrentVersion: []byte{124},
|
||||
Epoch: uint64(1234567890),
|
||||
}
|
||||
fork2 = pb.Fork{
|
||||
PreviousVersion: []byte{123},
|
||||
CurrentVersion: []byte{125},
|
||||
Epoch: uint64(1234567890),
|
||||
}
|
||||
assert.Equal(t, true, sszutil.DeepEqual(fork1, fork1))
|
||||
assert.Equal(t, false, sszutil.DeepEqual(fork1, fork2))
|
||||
|
||||
checkpoint1 := ethpb.Checkpoint{
|
||||
Epoch: uint64(1234567890),
|
||||
Root: []byte{},
|
||||
}
|
||||
checkpoint2 := ethpb.Checkpoint{
|
||||
Epoch: uint64(1234567890),
|
||||
Root: nil,
|
||||
}
|
||||
assert.Equal(t, true, sszutil.DeepEqual(checkpoint1, checkpoint2))
|
||||
}
|
||||
@@ -13,6 +13,7 @@ go_library(
|
||||
"//beacon-chain/core/state:go_default_library",
|
||||
"//beacon-chain/state:go_default_library",
|
||||
"//proto/beacon/p2p/v1:go_default_library",
|
||||
"//shared/sszutil:go_default_library",
|
||||
"//shared/version:go_default_library",
|
||||
"@com_github_kr_pretty//:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
|
||||
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/sszutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/version"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli/v2"
|
||||
@@ -188,7 +189,7 @@ func main() {
|
||||
if err := dataFetcher(expectedPostStatePath, expectedState); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if !ssz.DeepEqual(expectedState, postState.InnerStateUnsafe()) {
|
||||
if !sszutil.DeepEqual(expectedState, postState.InnerStateUnsafe()) {
|
||||
diff, _ := messagediff.PrettyDiff(expectedState, postState.InnerStateUnsafe())
|
||||
log.Errorf("Derived state differs from provided post state: %s", diff)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user