prysm-pulse/testing/endtoend/evaluators/finality.go
kasey d58d3f2c57
E2E deposit testing overhaul (#11667)
* rewrite/refactor deposit testing code

keep track of sent deposits so that they can be compared in detail with
the validator set retreived from the API.

* fix bugs in evaluator and retry

* lint + deepsource appeasement

* typo s/Sprintf/Printf/

* gosec, more like nosec

* fix gosec number - 204->304

* type switch to get signed block from container

* improve comments

* centralizing constants and adding comments

* lock around Depositor to avoid future races

Co-authored-by: Kasey Kirkham <kasey@users.noreply.github.com>
2022-11-19 03:40:32 +00:00

62 lines
1.9 KiB
Go

package evaluators
import (
"context"
"fmt"
"github.com/pkg/errors"
ethtypes "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
eth "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v3/testing/endtoend/policies"
"github.com/prysmaticlabs/prysm/v3/testing/endtoend/types"
"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/emptypb"
)
// FinalizationOccurs is an evaluator to make sure finalization is performing as it should.
// Requires to be run after at least 4 epochs have passed.
var FinalizationOccurs = func(epoch ethtypes.Epoch) types.Evaluator {
return types.Evaluator{
Name: "finalizes_at_epoch_%d",
Policy: policies.AfterNthEpoch(epoch),
Evaluation: finalizationOccurs,
}
}
func finalizationOccurs(_ types.EvaluationContext, conns ...*grpc.ClientConn) error {
conn := conns[0]
client := eth.NewBeaconChainClient(conn)
chainHead, err := client.GetChainHead(context.Background(), &emptypb.Empty{})
if err != nil {
return errors.Wrap(err, "failed to get chain head")
}
currentEpoch := chainHead.HeadEpoch
finalizedEpoch := chainHead.FinalizedEpoch
expectedFinalizedEpoch := currentEpoch - 2
if expectedFinalizedEpoch != finalizedEpoch {
return fmt.Errorf(
"expected finalized epoch to be %d, received: %d",
expectedFinalizedEpoch,
finalizedEpoch,
)
}
previousJustifiedEpoch := chainHead.PreviousJustifiedEpoch
currentJustifiedEpoch := chainHead.JustifiedEpoch
if previousJustifiedEpoch+1 != currentJustifiedEpoch {
return fmt.Errorf(
"there should be no gaps between current and previous justified epochs, received current %d and previous %d",
currentJustifiedEpoch,
previousJustifiedEpoch,
)
}
if currentJustifiedEpoch+1 != currentEpoch {
return fmt.Errorf(
"there should be no gaps between current epoch and current justified epoch, received current %d and justified %d",
currentEpoch,
currentJustifiedEpoch,
)
}
return nil
}