mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-08 02:31:19 +00:00
d077483577
* v3 import renamings * tidy * fmt * rev * Update beacon-chain/core/epoch/precompute/reward_penalty_test.go * Update beacon-chain/core/helpers/validators_test.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/iface/BUILD.bazel * Update beacon-chain/db/kv/kv.go * Update beacon-chain/db/kv/state.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/sync/initial-sync/service.go * fix deps * fix bad replacements * fix bad replacements * change back * gohashtree version * fix deps Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: Potuz <potuz@prysmaticlabs.com>
134 lines
3.5 KiB
Go
134 lines
3.5 KiB
Go
package equality_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/encoding/ssz/equality"
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
|
)
|
|
|
|
func TestDeepEqualBasicTypes(t *testing.T) {
|
|
assert.Equal(t, true, equality.DeepEqual(true, true))
|
|
assert.Equal(t, false, equality.DeepEqual(true, false))
|
|
|
|
assert.Equal(t, true, equality.DeepEqual(byte(222), byte(222)))
|
|
assert.Equal(t, false, equality.DeepEqual(byte(222), byte(111)))
|
|
|
|
assert.Equal(t, true, equality.DeepEqual(uint64(1234567890), uint64(1234567890)))
|
|
assert.Equal(t, false, equality.DeepEqual(uint64(1234567890), uint64(987653210)))
|
|
|
|
assert.Equal(t, true, equality.DeepEqual("hello", "hello"))
|
|
assert.Equal(t, false, equality.DeepEqual("hello", "world"))
|
|
|
|
assert.Equal(t, true, equality.DeepEqual([3]byte{1, 2, 3}, [3]byte{1, 2, 3}))
|
|
assert.Equal(t, false, equality.DeepEqual([3]byte{1, 2, 3}, [3]byte{1, 2, 4}))
|
|
|
|
var nilSlice1, nilSlice2 []byte
|
|
assert.Equal(t, true, equality.DeepEqual(nilSlice1, nilSlice2))
|
|
assert.Equal(t, true, equality.DeepEqual(nilSlice1, []byte{}))
|
|
assert.Equal(t, true, equality.DeepEqual([]byte{1, 2, 3}, []byte{1, 2, 3}))
|
|
assert.Equal(t, false, equality.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, equality.DeepEqual(store1, store2))
|
|
assert.Equal(t, false, equality.DeepEqual(store1, store3))
|
|
}
|
|
|
|
func TestDeepEqualStructs_Unexported(t *testing.T) {
|
|
type Store struct {
|
|
V1 uint64
|
|
V2 []byte
|
|
dontIgnoreMe string
|
|
}
|
|
store1 := Store{uint64(1234), nil, "hi there"}
|
|
store2 := Store{uint64(1234), []byte{}, "hi there"}
|
|
store3 := Store{uint64(4321), []byte{}, "wow"}
|
|
store4 := Store{uint64(4321), []byte{}, "bow wow"}
|
|
assert.Equal(t, true, equality.DeepEqual(store1, store2))
|
|
assert.Equal(t, false, equality.DeepEqual(store1, store3))
|
|
assert.Equal(t, false, equality.DeepEqual(store3, store4))
|
|
}
|
|
|
|
func TestDeepEqualProto(t *testing.T) {
|
|
var fork1, fork2 *ethpb.Fork
|
|
assert.Equal(t, true, equality.DeepEqual(fork1, fork2))
|
|
|
|
fork1 = ðpb.Fork{
|
|
PreviousVersion: []byte{123},
|
|
CurrentVersion: []byte{124},
|
|
Epoch: 1234567890,
|
|
}
|
|
fork2 = ðpb.Fork{
|
|
PreviousVersion: []byte{123},
|
|
CurrentVersion: []byte{125},
|
|
Epoch: 1234567890,
|
|
}
|
|
assert.Equal(t, true, equality.DeepEqual(fork1, fork1))
|
|
assert.Equal(t, false, equality.DeepEqual(fork1, fork2))
|
|
|
|
checkpoint1 := ðpb.Checkpoint{
|
|
Epoch: 1234567890,
|
|
Root: []byte{},
|
|
}
|
|
checkpoint2 := ðpb.Checkpoint{
|
|
Epoch: 1234567890,
|
|
Root: nil,
|
|
}
|
|
assert.Equal(t, true, equality.DeepEqual(checkpoint1, checkpoint2))
|
|
}
|
|
|
|
func Test_IsProto(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
item interface{}
|
|
want bool
|
|
}{
|
|
{
|
|
name: "uint64",
|
|
item: 0,
|
|
want: false,
|
|
},
|
|
{
|
|
name: "string",
|
|
item: "foobar cheese",
|
|
want: false,
|
|
},
|
|
{
|
|
name: "uint64 array",
|
|
item: []uint64{1, 2, 3, 4, 5, 6},
|
|
want: false,
|
|
},
|
|
{
|
|
name: "Attestation",
|
|
item: ðpb.Attestation{},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "Array of attestations",
|
|
item: []*ethpb.Attestation{},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "Map of attestations",
|
|
item: make(map[uint64]*ethpb.Attestation),
|
|
want: true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := equality.IsProto(tt.item); got != tt.want {
|
|
t.Errorf("isProtoSlice() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|