2022-06-24 02:41:16 +00:00
|
|
|
package testing
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-02-10 19:36:19 +00:00
|
|
|
"math/big"
|
2022-06-24 02:41:16 +00:00
|
|
|
|
2023-01-26 13:07:44 +00:00
|
|
|
"github.com/pkg/errors"
|
2023-03-17 18:52:56 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v4/api/client/builder"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/config/params"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/consensus-types/blocks"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
|
|
|
|
v1 "github.com/prysmaticlabs/prysm/v4/proto/engine/v1"
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/time/slots"
|
2022-06-24 02:41:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// MockBuilderService to mock builder.
|
|
|
|
type MockBuilderService struct {
|
|
|
|
HasConfigured bool
|
|
|
|
Payload *v1.ExecutionPayload
|
2023-02-01 16:24:51 +00:00
|
|
|
PayloadCapella *v1.ExecutionPayloadCapella
|
2022-06-24 02:41:16 +00:00
|
|
|
ErrSubmitBlindedBlock error
|
|
|
|
Bid *ethpb.SignedBuilderBid
|
2023-02-10 16:20:38 +00:00
|
|
|
BidCapella *ethpb.SignedBuilderBidCapella
|
2022-06-24 02:41:16 +00:00
|
|
|
ErrGetHeader error
|
|
|
|
ErrRegisterValidator error
|
|
|
|
}
|
|
|
|
|
|
|
|
// Configured for mocking.
|
|
|
|
func (s *MockBuilderService) Configured() bool {
|
|
|
|
return s.HasConfigured
|
|
|
|
}
|
|
|
|
|
|
|
|
// SubmitBlindedBlock for mocking.
|
2023-02-09 09:23:32 +00:00
|
|
|
func (s *MockBuilderService) SubmitBlindedBlock(_ context.Context, _ interfaces.ReadOnlySignedBeaconBlock) (interfaces.ExecutionData, error) {
|
2023-02-01 16:24:51 +00:00
|
|
|
if s.Payload != nil {
|
|
|
|
w, err := blocks.WrappedExecutionPayload(s.Payload)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not wrap payload")
|
|
|
|
}
|
|
|
|
return w, s.ErrSubmitBlindedBlock
|
|
|
|
}
|
2023-02-10 19:36:19 +00:00
|
|
|
w, err := blocks.WrappedExecutionPayloadCapella(s.PayloadCapella, big.NewInt(0))
|
2023-01-26 13:07:44 +00:00
|
|
|
if err != nil {
|
2023-02-01 16:24:51 +00:00
|
|
|
return nil, errors.Wrap(err, "could not wrap capella payload")
|
2023-01-26 13:07:44 +00:00
|
|
|
}
|
|
|
|
return w, s.ErrSubmitBlindedBlock
|
2022-06-24 02:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetHeader for mocking.
|
2023-02-10 19:36:19 +00:00
|
|
|
func (s *MockBuilderService) GetHeader(ctx context.Context, slot primitives.Slot, hr [32]byte, pb [48]byte) (builder.SignedBid, error) {
|
|
|
|
if slots.ToEpoch(slot) >= params.BeaconConfig().CapellaForkEpoch {
|
|
|
|
return builder.WrappedSignedBuilderBidCapella(s.BidCapella)
|
2023-02-10 16:20:38 +00:00
|
|
|
}
|
2023-02-10 19:36:19 +00:00
|
|
|
w, err := builder.WrappedSignedBuilderBid(s.Bid)
|
2023-01-26 13:07:44 +00:00
|
|
|
if err != nil {
|
2023-02-10 16:20:38 +00:00
|
|
|
return nil, errors.Wrap(err, "could not wrap capella bid")
|
2023-01-26 13:07:44 +00:00
|
|
|
}
|
|
|
|
return w, s.ErrGetHeader
|
2022-06-24 02:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterValidator for mocking.
|
|
|
|
func (s *MockBuilderService) RegisterValidator(context.Context, []*ethpb.SignedValidatorRegistrationV1) error {
|
|
|
|
return s.ErrRegisterValidator
|
|
|
|
}
|