mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-26 13:18:57 +00:00
7cc32c4dda
* remove unused code * remove defer use in loop * Remove unused methods and constants * gofmt and gaz * nilness check * remove unused args * Add TODO for refactoring subscribeWithBase to remove unused arg. It seems too involved to include in this sweeping PR. https://github.com/prysmaticlabs/prysm/issues/7437 * replace empty slice declaration * Remove unnecessary type conversions * remove redundant type declaration * rename receivers to be consistent * Remove bootnode query tool. It is now obsolete by discv5 * Remove relay node. It is no longer used or supported * Revert "Remove relay node. It is no longer used or supported" This reverts commit 4bd7717334dad85ef4766ed9bc4da711fb5fa810. * Delete unused test directory * Delete unsupported gcp startup script * Delete old k8s script * build fixes * fix build * go mod tidy * revert slasher/db/kv/block_header.go * fix build * remove redundant nil check * combine func args Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: Victor Farazdagi <simple.square@gmail.com>
82 lines
2.6 KiB
Go
Generated
82 lines
2.6 KiB
Go
Generated
package testing
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/golang/protobuf/proto"
|
|
eth "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
slashpb "github.com/prysmaticlabs/prysm/proto/slashing"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
// MockSlasher mocks the slasher rpc server.
|
|
type MockSlasher struct {
|
|
SlashAttestation bool
|
|
SlashBlock bool
|
|
IsSlashableAttestationCalled bool
|
|
IsSlashableAttestationNoUpdateCalled bool
|
|
IsSlashableBlockCalled bool
|
|
IsSlashableBlockNoUpdateCalled bool
|
|
}
|
|
|
|
// IsSlashableAttestation returns slashbale attestation if slash attestation is set to true.
|
|
func (ms MockSlasher) IsSlashableAttestation(_ context.Context, in *eth.IndexedAttestation, _ ...grpc.CallOption) (*slashpb.AttesterSlashingResponse, error) {
|
|
ms.IsSlashableAttestationCalled = true
|
|
if ms.SlashAttestation {
|
|
|
|
slashingAtt, ok := proto.Clone(in).(*eth.IndexedAttestation)
|
|
if !ok {
|
|
return nil, errors.New("object is not of type *eth.IndexedAttestation")
|
|
}
|
|
slashingAtt.Data.BeaconBlockRoot = []byte("slashing")
|
|
slashings := []*eth.AttesterSlashing{{
|
|
Attestation_1: in,
|
|
Attestation_2: slashingAtt,
|
|
},
|
|
}
|
|
return &slashpb.AttesterSlashingResponse{
|
|
AttesterSlashing: slashings,
|
|
}, nil
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
// IsSlashableAttestationNoUpdate returns slashbale if slash attestation is set to true.
|
|
func (ms MockSlasher) IsSlashableAttestationNoUpdate(_ context.Context, _ *eth.IndexedAttestation, _ ...grpc.CallOption) (*slashpb.Slashable, error) {
|
|
ms.IsSlashableAttestationNoUpdateCalled = true
|
|
return &slashpb.Slashable{
|
|
Slashable: ms.SlashAttestation,
|
|
}, nil
|
|
|
|
}
|
|
|
|
// IsSlashableBlock returns proposer slashing if slash block is set to true.
|
|
func (ms MockSlasher) IsSlashableBlock(_ context.Context, in *eth.SignedBeaconBlockHeader, _ ...grpc.CallOption) (*slashpb.ProposerSlashingResponse, error) {
|
|
ms.IsSlashableBlockCalled = true
|
|
if ms.SlashBlock {
|
|
slashingBlk, ok := proto.Clone(in).(*eth.SignedBeaconBlockHeader)
|
|
if !ok {
|
|
return nil, errors.New("object is not of type *eth.SignedBeaconBlockHeader")
|
|
}
|
|
slashingBlk.Header.BodyRoot = []byte("slashing")
|
|
slashings := []*eth.ProposerSlashing{{
|
|
Header_1: in,
|
|
Header_2: slashingBlk,
|
|
},
|
|
}
|
|
return &slashpb.ProposerSlashingResponse{
|
|
ProposerSlashing: slashings,
|
|
}, nil
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
// IsSlashableBlockNoUpdate returns slashbale if slash block is set to true.
|
|
func (ms MockSlasher) IsSlashableBlockNoUpdate(_ context.Context, _ *eth.BeaconBlockHeader, _ ...grpc.CallOption) (*slashpb.Slashable, error) {
|
|
ms.IsSlashableBlockNoUpdateCalled = true
|
|
return &slashpb.Slashable{
|
|
Slashable: ms.SlashBlock,
|
|
}, nil
|
|
}
|