prysm-pulse/testing/util/attestation_test.go

59 lines
1.9 KiB
Go
Raw Normal View History

package util
2021-01-07 21:00:21 +00:00
import (
"testing"
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
"github.com/prysmaticlabs/prysm/config/params"
v1 "github.com/prysmaticlabs/prysm/proto/eth/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/testing/require"
2021-01-07 21:00:21 +00:00
)
func TestHydrateAttestation(t *testing.T) {
a := HydrateAttestation(&ethpb.Attestation{})
2021-01-07 21:00:21 +00:00
_, err := a.HashTreeRoot()
require.NoError(t, err)
require.DeepEqual(t, a.Signature, make([]byte, fieldparams.BLSSignatureLength))
2021-01-07 21:00:21 +00:00
}
func TestHydrateAttestationData(t *testing.T) {
d := HydrateAttestationData(&ethpb.AttestationData{})
2021-01-07 21:00:21 +00:00
_, err := d.HashTreeRoot()
require.NoError(t, err)
require.DeepEqual(t, d.BeaconBlockRoot, make([]byte, fieldparams.RootLength))
require.DeepEqual(t, d.Target.Root, make([]byte, fieldparams.RootLength))
require.DeepEqual(t, d.Source.Root, make([]byte, fieldparams.RootLength))
2021-01-07 21:00:21 +00:00
}
func TestHydrateV1Attestation(t *testing.T) {
a := HydrateV1Attestation(&v1.Attestation{})
_, err := a.HashTreeRoot()
require.NoError(t, err)
require.DeepEqual(t, a.Signature, make([]byte, fieldparams.BLSSignatureLength))
}
func TestHydrateV1AttestationData(t *testing.T) {
d := HydrateV1AttestationData(&v1.AttestationData{})
_, err := d.HashTreeRoot()
require.NoError(t, err)
require.DeepEqual(t, d.BeaconBlockRoot, make([]byte, fieldparams.RootLength))
require.DeepEqual(t, d.Target.Root, make([]byte, fieldparams.RootLength))
require.DeepEqual(t, d.Source.Root, make([]byte, fieldparams.RootLength))
}
func TestHydrateIndexedAttestation(t *testing.T) {
a := &ethpb.IndexedAttestation{}
a = HydrateIndexedAttestation(a)
_, err := a.HashTreeRoot()
require.NoError(t, err)
_, err = a.Data.HashTreeRoot()
require.NoError(t, err)
}
func TestGenerateAttestations_EpochBoundary(t *testing.T) {
gs, pk := DeterministicGenesisState(t, 32)
_, err := GenerateAttestations(gs, pk, 1, params.BeaconConfig().SlotsPerEpoch, false)
require.NoError(t, err)
}