2020-10-20 19:14:24 +00:00
|
|
|
package blockchain
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2021-07-21 21:34:07 +00:00
|
|
|
eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
2021-09-23 18:53:46 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/testing/require"
|
|
|
|
"github.com/prysmaticlabs/prysm/testing/util"
|
2020-10-20 19:14:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestReportEpochMetrics_BadHeadState(t *testing.T) {
|
2021-09-23 18:53:46 +00:00
|
|
|
s, err := util.NewBeaconState()
|
2021-02-08 20:00:09 +00:00
|
|
|
require.NoError(t, err)
|
2021-09-23 18:53:46 +00:00
|
|
|
h, err := util.NewBeaconState()
|
2021-02-08 20:00:09 +00:00
|
|
|
require.NoError(t, err)
|
2020-10-20 19:14:24 +00:00
|
|
|
require.NoError(t, h.SetValidators(nil))
|
2021-02-08 20:00:09 +00:00
|
|
|
err = reportEpochMetrics(context.Background(), s, h)
|
2020-10-20 19:14:24 +00:00
|
|
|
require.ErrorContains(t, "failed to initialize precompute: nil validators in state", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestReportEpochMetrics_BadAttestation(t *testing.T) {
|
2021-09-23 18:53:46 +00:00
|
|
|
s, err := util.NewBeaconState()
|
2021-02-08 20:00:09 +00:00
|
|
|
require.NoError(t, err)
|
2021-09-23 18:53:46 +00:00
|
|
|
h, err := util.NewBeaconState()
|
2021-02-08 20:00:09 +00:00
|
|
|
require.NoError(t, err)
|
2021-07-29 21:45:17 +00:00
|
|
|
require.NoError(t, h.AppendCurrentEpochAttestations(ð.PendingAttestation{InclusionDelay: 0}))
|
2021-02-08 20:00:09 +00:00
|
|
|
err = reportEpochMetrics(context.Background(), s, h)
|
2020-10-20 19:14:24 +00:00
|
|
|
require.ErrorContains(t, "attestation with inclusion delay of 0", err)
|
|
|
|
}
|
2021-01-27 02:27:34 +00:00
|
|
|
|
|
|
|
func TestReportEpochMetrics_SlashedValidatorOutOfBound(t *testing.T) {
|
2021-09-23 18:53:46 +00:00
|
|
|
h, _ := util.DeterministicGenesisState(t, 1)
|
2021-01-27 02:27:34 +00:00
|
|
|
v, err := h.ValidatorAtIndex(0)
|
|
|
|
require.NoError(t, err)
|
|
|
|
v.Slashed = true
|
|
|
|
require.NoError(t, h.UpdateValidatorAtIndex(0, v))
|
2021-09-23 18:53:46 +00:00
|
|
|
require.NoError(t, h.AppendCurrentEpochAttestations(ð.PendingAttestation{InclusionDelay: 1, Data: util.HydrateAttestationData(ð.AttestationData{})}))
|
2021-01-27 02:27:34 +00:00
|
|
|
err = reportEpochMetrics(context.Background(), h, h)
|
|
|
|
require.ErrorContains(t, "slot 0 out of bounds", err)
|
|
|
|
}
|