prysm-pulse/beacon-chain/state/stateutil/attestations_test.go
Preston Van Loon b7175b3482
Update fastssz: Attempt 2 (#7115)
* Revert "Revert "Update fastssz" (#7100)"

This reverts commit b954db9704.
* Preston's patch
* Merge branch 'master' of github.com:prysmaticlabs/prysm into revert-7100-revert-6760-update-fssz
* Update fssz, add regression test case
* more HTR with fssz
* fix some tests
* only one test left
* Make it so that HTR will work
* gofmt, imports
* gofmt, imports
* fix
* Merge branch 'master' of github.com:prysmaticlabs/prysm into revert-7100-revert-6760-update-fssz
* fix
* Merge branch 'master' into revert-7100-revert-6760-update-fssz
* Merge refs/heads/master into revert-7100-revert-6760-update-fssz
* gaz
* Merge branch 'revert-7100-revert-6760-update-fssz' of github.com:prysmaticlabs/prysm into revert-7100-revert-6760-update-fssz
* Merge refs/heads/master into revert-7100-revert-6760-update-fssz
* fix test
* Merge branch 'revert-7100-revert-6760-update-fssz' of github.com:prysmaticlabs/prysm into revert-7100-revert-6760-update-fssz
* Merge refs/heads/master into revert-7100-revert-6760-update-fssz
2020-08-27 18:13:32 +00:00

63 lines
1.5 KiB
Go

package stateutil
import (
"bytes"
"testing"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
)
func TestAttestationDataRoot_EqualGeneric(t *testing.T) {
attData := &ethpb.AttestationData{
Slot: 39,
CommitteeIndex: 2,
BeaconBlockRoot: bytesutil.PadTo([]byte("block root"), 32),
Source: &ethpb.Checkpoint{
Root: bytesutil.PadTo([]byte("source root"), 32),
Epoch: 0,
},
Target: &ethpb.Checkpoint{
Root: bytesutil.PadTo([]byte("target root"), 32),
Epoch: 9,
},
}
genericHtr, err := attData.HashTreeRoot()
require.NoError(t, err)
dataHtr, err := AttestationDataRoot(attData)
require.NoError(t, err)
if !bytes.Equal(genericHtr[:], dataHtr[:]) {
t.Fatalf("Expected %#x, received %#x", genericHtr, dataHtr)
}
}
func BenchmarkAttestationDataRoot(b *testing.B) {
attData := &ethpb.AttestationData{
Slot: 39,
CommitteeIndex: 2,
BeaconBlockRoot: bytesutil.PadTo([]byte("block root"), 32),
Source: &ethpb.Checkpoint{
Root: bytesutil.PadTo([]byte("source root"), 32),
Epoch: 0,
},
Target: &ethpb.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 := attData.HashTreeRoot()
require.NoError(b, err)
}
})
b.Run("stateutil", func(b *testing.B) {
for i := 0; i < b.N; i++ {
_, err := AttestationDataRoot(attData)
require.NoError(b, err)
}
})
}