mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-10 03:31:20 +00:00
aed6e13498
* initial commit for cli integration of web3signer * resolving conflicts and execution * remove aggregation slot from proto * rem aggregation slot * define a sync message block root struct * fix sync message name * sync message block root struct * amend where sync committee block root is used * altered switch statement to return correct json request by type * fixing fork data import, types, and unit tests * reverting unwanted changes * reverting more unwanted changes * fixing deepsource issues * fixing formatting * more fixes for deepsource and code clean up * only want to fetch once for fetch validating public keys * adding more comments * new unit tests for requests and fixing a mapper issue * Update validator/client/validator.go Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update validator/accounts/wallet/wallet.go Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * adjusting comment * adjusting comment * fixing import organization * including more unit tests * adding new cli edit * adding in checks for wallet initialize * adding web3signer flags to main.go * some how resolved files did not save correctly * adding in check to make sure web flag only works with types imported and derived * Update validator/client/sync_committee.go Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update validator/client/aggregate.go Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update validator/accounts/wallet/wallet.go Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update cmd/validator/wallet/wallet.go Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update cmd/validator/wallet/wallet.go Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update cmd/validator/main.go Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update cmd/validator/flags/flags.go Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update cmd/validator/flags/flags.go Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update cmd/validator/wallet/wallet.go Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update cmd/validator/wallet/wallet.go Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * reverting changes that accidently got checked in * reverting * reverting * continuing to revert unintenteded changes * reverting * removing more unneeded changes * addressing review comment * initial refactor * adding in more clarifying comments * fixing mock * resolving desource issues * addressing gosec scan for helper go file * addressing gosec * trying to fix bazel build * removal of interface to fix build * fixing maligned struct * addressing deepsource * fixing deepsource * addressing efficiency of type checking * fixing bazel test failure * fixing go linter errors * gaz * web changes * add w3signer * new kind * proper use * align * adding prysm validator flags to help flags list * addressing root comment * ci lint * fixing standardapi tests * fixing accounts_test after removal of keymanager from rpc server * fixing more unit tests * Update cmd/validator/flags/flags.go Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update cmd/validator/flags/flags.go Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update validator/client/service.go Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update validator/client/service.go Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * addressing missed err checks * fixing mock tests * fixing gofmt * unskipping minimal e2e test and removing related TODOs * Update testing/endtoend/components/validator.go Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> * Update testing/endtoend/components/validator.go Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> * adding some error wrapers to clarify failure point * fixing bazel build with new error checks * taking preston's advice to make test fail faster to understand what's going on with the test * checking if genesis validators root is not zero hash * adding check for genesis validators root giving zero hash * fixing missing dependency * adding check for wallet * log all * fixing errors for http responses * switching marshal to pretty print * adding pretty sign request test * fixing base url setting * adding in check for web3signer and temporary wallet instead of having to open the wallet * refactoring web3signer to not require wallet * bazel build fix * fixing gazelle build * adding content type of request * fixing more bazel * removing unused code * removing unused comments * adding skip test back in * addressing a validation and error message * fix parse * body * fixing logic for datadir * improving error handling * show resp * fix * sign resp as str * point of pointer remove * sign resp * unmarshal sig resp * read body as str * adding more verbose logging * removing unused result * fixing unit test * reconfiguring files to properly nest code and mocks * fix build issue * using context when using client function calls * fixing based on suggestion * addressing comments * gaz * removing defined max timeout * reverting json print pretty * Update validator/accounts/wallet_edit.go Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> * removing unneeded code restrictions * should not introduce new code that may impact existing key manager types * adjusting comments * adding in json validation * running go mod tidy * some logging * more logs * fixing typo * remove logs * testing without byte trim * fixing order or properties * gaz * tidy * reverting some logs * removing the confusing comments * Update validator/client/aggregate.go Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update validator/client/aggregate.go Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * addressing pr comments * editing bytes test * Run gazelle update-repos * run gazelle * improving unit test coverage * fixing text * fixing a potential escaped error Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
249 lines
7.9 KiB
Go
249 lines
7.9 KiB
Go
package testutil
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"time"
|
|
|
|
types "github.com/prysmaticlabs/eth2-types"
|
|
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
|
prysmTime "github.com/prysmaticlabs/prysm/time"
|
|
"github.com/prysmaticlabs/prysm/validator/client/iface"
|
|
"github.com/prysmaticlabs/prysm/validator/keymanager"
|
|
)
|
|
|
|
var _ iface.Validator = (*FakeValidator)(nil)
|
|
|
|
// FakeValidator for mocking.
|
|
type FakeValidator struct {
|
|
DoneCalled bool
|
|
WaitForWalletInitializationCalled bool
|
|
SlasherReadyCalled bool
|
|
NextSlotCalled bool
|
|
UpdateDutiesCalled bool
|
|
UpdateProtectionsCalled bool
|
|
RoleAtCalled bool
|
|
AttestToBlockHeadCalled bool
|
|
ProposeBlockCalled bool
|
|
LogValidatorGainsAndLossesCalled bool
|
|
SaveProtectionsCalled bool
|
|
DeleteProtectionCalled bool
|
|
SlotDeadlineCalled bool
|
|
HandleKeyReloadCalled bool
|
|
WaitForChainStartCalled int
|
|
WaitForSyncCalled int
|
|
WaitForActivationCalled int
|
|
CanonicalHeadSlotCalled int
|
|
ReceiveBlocksCalled int
|
|
RetryTillSuccess int
|
|
ProposeBlockArg1 uint64
|
|
AttestToBlockHeadArg1 uint64
|
|
RoleAtArg1 uint64
|
|
UpdateDutiesArg1 uint64
|
|
NextSlotRet <-chan types.Slot
|
|
PublicKey string
|
|
UpdateDutiesRet error
|
|
RolesAtRet []iface.ValidatorRole
|
|
Balances map[[fieldparams.BLSPubkeyLength]byte]uint64
|
|
IndexToPubkeyMap map[uint64][fieldparams.BLSPubkeyLength]byte
|
|
PubkeyToIndexMap map[[fieldparams.BLSPubkeyLength]byte]uint64
|
|
PubkeysToStatusesMap map[[fieldparams.BLSPubkeyLength]byte]ethpb.ValidatorStatus
|
|
Km keymanager.IKeymanager
|
|
}
|
|
|
|
type ctxKey string
|
|
|
|
// AllValidatorsAreExitedCtxKey represents the metadata context key used for exits.
|
|
var AllValidatorsAreExitedCtxKey = ctxKey("exited")
|
|
|
|
// Done for mocking.
|
|
func (fv *FakeValidator) Done() {
|
|
fv.DoneCalled = true
|
|
}
|
|
|
|
// WaitForWalletInitialization for mocking.
|
|
func (fv *FakeValidator) WaitForKeymanagerInitialization(_ context.Context) error {
|
|
fv.WaitForWalletInitializationCalled = true
|
|
return nil
|
|
}
|
|
|
|
// WaitForChainStart for mocking.
|
|
func (fv *FakeValidator) WaitForChainStart(_ context.Context) error {
|
|
fv.WaitForChainStartCalled++
|
|
if fv.RetryTillSuccess >= fv.WaitForChainStartCalled {
|
|
return iface.ErrConnectionIssue
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// WaitForActivation for mocking.
|
|
func (fv *FakeValidator) WaitForActivation(_ context.Context, _ chan [][fieldparams.BLSPubkeyLength]byte) error {
|
|
fv.WaitForActivationCalled++
|
|
if fv.RetryTillSuccess >= fv.WaitForActivationCalled {
|
|
return iface.ErrConnectionIssue
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// WaitForSync for mocking.
|
|
func (fv *FakeValidator) WaitForSync(_ context.Context) error {
|
|
fv.WaitForSyncCalled++
|
|
if fv.RetryTillSuccess >= fv.WaitForSyncCalled {
|
|
return iface.ErrConnectionIssue
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// SlasherReady for mocking.
|
|
func (fv *FakeValidator) SlasherReady(_ context.Context) error {
|
|
fv.SlasherReadyCalled = true
|
|
return nil
|
|
}
|
|
|
|
// CanonicalHeadSlot for mocking.
|
|
func (fv *FakeValidator) CanonicalHeadSlot(_ context.Context) (types.Slot, error) {
|
|
fv.CanonicalHeadSlotCalled++
|
|
if fv.RetryTillSuccess > fv.CanonicalHeadSlotCalled {
|
|
return 0, iface.ErrConnectionIssue
|
|
}
|
|
return 0, nil
|
|
}
|
|
|
|
// SlotDeadline for mocking.
|
|
func (fv *FakeValidator) SlotDeadline(_ types.Slot) time.Time {
|
|
fv.SlotDeadlineCalled = true
|
|
return prysmTime.Now()
|
|
}
|
|
|
|
// NextSlot for mocking.
|
|
func (fv *FakeValidator) NextSlot() <-chan types.Slot {
|
|
fv.NextSlotCalled = true
|
|
return fv.NextSlotRet
|
|
}
|
|
|
|
// UpdateDuties for mocking.
|
|
func (fv *FakeValidator) UpdateDuties(_ context.Context, slot types.Slot) error {
|
|
fv.UpdateDutiesCalled = true
|
|
fv.UpdateDutiesArg1 = uint64(slot)
|
|
return fv.UpdateDutiesRet
|
|
}
|
|
|
|
// UpdateProtections for mocking.
|
|
func (fv *FakeValidator) UpdateProtections(_ context.Context, _ uint64) error {
|
|
fv.UpdateProtectionsCalled = true
|
|
return nil
|
|
}
|
|
|
|
// LogValidatorGainsAndLosses for mocking.
|
|
func (fv *FakeValidator) LogValidatorGainsAndLosses(_ context.Context, _ types.Slot) error {
|
|
fv.LogValidatorGainsAndLossesCalled = true
|
|
return nil
|
|
}
|
|
|
|
// ResetAttesterProtectionData for mocking.
|
|
func (fv *FakeValidator) ResetAttesterProtectionData() {
|
|
fv.DeleteProtectionCalled = true
|
|
}
|
|
|
|
// RolesAt for mocking.
|
|
func (fv *FakeValidator) RolesAt(_ context.Context, slot types.Slot) (map[[fieldparams.BLSPubkeyLength]byte][]iface.ValidatorRole, error) {
|
|
fv.RoleAtCalled = true
|
|
fv.RoleAtArg1 = uint64(slot)
|
|
vr := make(map[[fieldparams.BLSPubkeyLength]byte][]iface.ValidatorRole)
|
|
vr[[fieldparams.BLSPubkeyLength]byte{1}] = fv.RolesAtRet
|
|
return vr, nil
|
|
}
|
|
|
|
// SubmitAttestation for mocking.
|
|
func (fv *FakeValidator) SubmitAttestation(_ context.Context, slot types.Slot, _ [fieldparams.BLSPubkeyLength]byte) {
|
|
fv.AttestToBlockHeadCalled = true
|
|
fv.AttestToBlockHeadArg1 = uint64(slot)
|
|
}
|
|
|
|
// ProposeBlock for mocking.
|
|
func (fv *FakeValidator) ProposeBlock(_ context.Context, slot types.Slot, _ [fieldparams.BLSPubkeyLength]byte) {
|
|
fv.ProposeBlockCalled = true
|
|
fv.ProposeBlockArg1 = uint64(slot)
|
|
}
|
|
|
|
// SubmitAggregateAndProof for mocking.
|
|
func (_ *FakeValidator) SubmitAggregateAndProof(_ context.Context, _ types.Slot, _ [fieldparams.BLSPubkeyLength]byte) {
|
|
}
|
|
|
|
// SubmitSyncCommitteeMessage for mocking.
|
|
func (_ *FakeValidator) SubmitSyncCommitteeMessage(_ context.Context, _ types.Slot, _ [fieldparams.BLSPubkeyLength]byte) {
|
|
}
|
|
|
|
// LogAttestationsSubmitted for mocking.
|
|
func (_ *FakeValidator) LogAttestationsSubmitted() {}
|
|
|
|
// LogNextDutyTimeLeft for mocking.
|
|
func (_ *FakeValidator) LogNextDutyTimeLeft(_ types.Slot) error {
|
|
return nil
|
|
}
|
|
|
|
// UpdateDomainDataCaches for mocking.
|
|
func (_ *FakeValidator) UpdateDomainDataCaches(context.Context, types.Slot) {}
|
|
|
|
// BalancesByPubkeys for mocking.
|
|
func (fv *FakeValidator) BalancesByPubkeys(_ context.Context) map[[fieldparams.BLSPubkeyLength]byte]uint64 {
|
|
return fv.Balances
|
|
}
|
|
|
|
// IndicesToPubkeys for mocking.
|
|
func (fv *FakeValidator) IndicesToPubkeys(_ context.Context) map[uint64][fieldparams.BLSPubkeyLength]byte {
|
|
return fv.IndexToPubkeyMap
|
|
}
|
|
|
|
// PubkeysToIndices for mocking.
|
|
func (fv *FakeValidator) PubkeysToIndices(_ context.Context) map[[fieldparams.BLSPubkeyLength]byte]uint64 {
|
|
return fv.PubkeyToIndexMap
|
|
}
|
|
|
|
// PubkeysToStatuses for mocking.
|
|
func (fv *FakeValidator) PubkeysToStatuses(_ context.Context) map[[fieldparams.BLSPubkeyLength]byte]ethpb.ValidatorStatus {
|
|
return fv.PubkeysToStatusesMap
|
|
}
|
|
|
|
// AllValidatorsAreExited for mocking
|
|
func (_ *FakeValidator) AllValidatorsAreExited(ctx context.Context) (bool, error) {
|
|
if ctx.Value(AllValidatorsAreExitedCtxKey) == nil {
|
|
return false, nil
|
|
}
|
|
return ctx.Value(AllValidatorsAreExitedCtxKey).(bool), nil
|
|
}
|
|
|
|
// Keymanager for mocking
|
|
func (fv *FakeValidator) Keymanager() (keymanager.IKeymanager, error) {
|
|
return fv.Km, nil
|
|
}
|
|
|
|
// CheckDoppelGanger for mocking
|
|
func (_ *FakeValidator) CheckDoppelGanger(_ context.Context) error {
|
|
return nil
|
|
}
|
|
|
|
// ReceiveBlocks for mocking
|
|
func (fv *FakeValidator) ReceiveBlocks(_ context.Context, connectionErrorChannel chan<- error) {
|
|
fv.ReceiveBlocksCalled++
|
|
if fv.RetryTillSuccess > fv.ReceiveBlocksCalled {
|
|
connectionErrorChannel <- iface.ErrConnectionIssue
|
|
}
|
|
}
|
|
|
|
// HandleKeyReload for mocking
|
|
func (fv *FakeValidator) HandleKeyReload(_ context.Context, newKeys [][fieldparams.BLSPubkeyLength]byte) (anyActive bool, err error) {
|
|
fv.HandleKeyReloadCalled = true
|
|
for _, key := range newKeys {
|
|
if bytes.Equal(key[:], ActiveKey[:]) {
|
|
return true, nil
|
|
}
|
|
}
|
|
return false, nil
|
|
}
|
|
|
|
// SubmitSignedContributionAndProof for mocking
|
|
func (_ *FakeValidator) SubmitSignedContributionAndProof(_ context.Context, _ types.Slot, _ [fieldparams.BLSPubkeyLength]byte) {
|
|
}
|