mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-26 05:17:22 +00:00
1022d9dba8
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
70 lines
1.6 KiB
Go
70 lines
1.6 KiB
Go
package stateutil
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/go-ssz"
|
|
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
|
)
|
|
|
|
func TestAttestationDataRoot_EqualGeneric(t *testing.T) {
|
|
attData := ðpb.AttestationData{
|
|
Slot: 39,
|
|
CommitteeIndex: 2,
|
|
BeaconBlockRoot: bytesutil.PadTo([]byte("block root"), 32),
|
|
Source: ðpb.Checkpoint{
|
|
Root: bytesutil.PadTo([]byte("source root"), 32),
|
|
Epoch: 0,
|
|
},
|
|
Target: ðpb.Checkpoint{
|
|
Root: bytesutil.PadTo([]byte("target root"), 32),
|
|
Epoch: 9,
|
|
},
|
|
}
|
|
genericHtr, err := ssz.HashTreeRoot(attData)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
dataHtr, err := AttestationDataRoot(attData)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !bytes.Equal(genericHtr[:], dataHtr[:]) {
|
|
t.Fatalf("Expected %#x, received %#x", genericHtr, dataHtr)
|
|
}
|
|
}
|
|
|
|
func BenchmarkAttestationDataRoot(b *testing.B) {
|
|
attData := ðpb.AttestationData{
|
|
Slot: 39,
|
|
CommitteeIndex: 2,
|
|
BeaconBlockRoot: bytesutil.PadTo([]byte("block root"), 32),
|
|
Source: ðpb.Checkpoint{
|
|
Root: bytesutil.PadTo([]byte("source root"), 32),
|
|
Epoch: 0,
|
|
},
|
|
Target: ðpb.Checkpoint{
|
|
Root: bytesutil.PadTo([]byte("target root"), 32),
|
|
Epoch: 9,
|
|
},
|
|
}
|
|
b.Run("generic", func(b *testing.B) {
|
|
for i := 0; i < b.N; i++ {
|
|
_, err := ssz.HashTreeRoot(attData)
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
}
|
|
})
|
|
b.Run("stateutil", func(b *testing.B) {
|
|
for i := 0; i < b.N; i++ {
|
|
_, err := AttestationDataRoot(attData)
|
|
if err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
}
|
|
})
|
|
}
|