mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-26 05:17:22 +00:00
QSP-39 AreEth1DataEqual Should Return True If Both Nil (#6372)
* resolve small core issue * add tests Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
parent
ac69dbc2f8
commit
6b27452947
@ -112,7 +112,11 @@ func ProcessEth1DataInBlock(beaconState *stateTrie.BeaconState, block *ethpb.Bea
|
|||||||
return beaconState, nil
|
return beaconState, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func areEth1DataEqual(a, b *ethpb.Eth1Data) bool {
|
// AreEth1DataEqual checks equality between two eth1 data objects.
|
||||||
|
func AreEth1DataEqual(a, b *ethpb.Eth1Data) bool {
|
||||||
|
if a == nil && b == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
if a == nil || b == nil {
|
if a == nil || b == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -130,7 +134,7 @@ func Eth1DataHasEnoughSupport(beaconState *stateTrie.BeaconState, data *ethpb.Et
|
|||||||
data = stateTrie.CopyETH1Data(data)
|
data = stateTrie.CopyETH1Data(data)
|
||||||
|
|
||||||
for _, vote := range beaconState.Eth1DataVotes() {
|
for _, vote := range beaconState.Eth1DataVotes() {
|
||||||
if areEth1DataEqual(vote, data) {
|
if AreEth1DataEqual(vote, data) {
|
||||||
voteCount++
|
voteCount++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,8 +90,8 @@ func TestFuzzareEth1DataEqual_10000(t *testing.T) {
|
|||||||
for i := 0; i < 10000; i++ {
|
for i := 0; i < 10000; i++ {
|
||||||
fuzzer.Fuzz(eth1data)
|
fuzzer.Fuzz(eth1data)
|
||||||
fuzzer.Fuzz(eth1data2)
|
fuzzer.Fuzz(eth1data2)
|
||||||
areEth1DataEqual(eth1data, eth1data2)
|
AreEth1DataEqual(eth1data, eth1data2)
|
||||||
areEth1DataEqual(eth1data, eth1data)
|
AreEth1DataEqual(eth1data, eth1data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2224,3 +2224,75 @@ func TestVerifyAttestations_HandlesPlannedFork(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAreEth1DataEqual(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
a *ethpb.Eth1Data
|
||||||
|
b *ethpb.Eth1Data
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
want bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "true when both are nil",
|
||||||
|
args: args{
|
||||||
|
a: nil,
|
||||||
|
b: nil,
|
||||||
|
},
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "false when only one is nil",
|
||||||
|
args: args{
|
||||||
|
a: nil,
|
||||||
|
b: ðpb.Eth1Data{
|
||||||
|
DepositRoot: make([]byte, 32),
|
||||||
|
DepositCount: 0,
|
||||||
|
BlockHash: make([]byte, 32),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "true when real equality",
|
||||||
|
args: args{
|
||||||
|
a: ðpb.Eth1Data{
|
||||||
|
DepositRoot: make([]byte, 32),
|
||||||
|
DepositCount: 0,
|
||||||
|
BlockHash: make([]byte, 32),
|
||||||
|
},
|
||||||
|
b: ðpb.Eth1Data{
|
||||||
|
DepositRoot: make([]byte, 32),
|
||||||
|
DepositCount: 0,
|
||||||
|
BlockHash: make([]byte, 32),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "false is field value differs",
|
||||||
|
args: args{
|
||||||
|
a: ðpb.Eth1Data{
|
||||||
|
DepositRoot: make([]byte, 32),
|
||||||
|
DepositCount: 0,
|
||||||
|
BlockHash: make([]byte, 32),
|
||||||
|
},
|
||||||
|
b: ðpb.Eth1Data{
|
||||||
|
DepositRoot: make([]byte, 32),
|
||||||
|
DepositCount: 64,
|
||||||
|
BlockHash: make([]byte, 32),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := blocks.AreEth1DataEqual(tt.args.a, tt.args.b); got != tt.want {
|
||||||
|
t.Errorf("AreEth1DataEqual() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user