mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-23 20:07:17 +00:00
5569a68452
* Value assigned to a variable is never read before being overwritten * The result of append is not used anywhere * Suspicious assignment of range-loop vars detected * Unused method receiver detected * Revert "Auxiliary commit to revert individual files from 54edcb445484a2e5d79612e19af8e949b8861253" This reverts commit bbd1e1beabf7b0c5cfc4f514dcc820062ad6c063. * Method modifies receiver * Fix test * Duplicate imports detected * Incorrectly formatted error string * Types of function parameters can be combined * One more "Unused method receiver detected" * Unused parameter detected in function
69 lines
2.1 KiB
Go
69 lines
2.1 KiB
Go
package testing
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
// MockSlasher mocks the slasher rpc server.
|
|
type MockSlasher struct {
|
|
SlashAttestation bool
|
|
SlashBlock bool
|
|
IsSlashableAttestationCalled bool
|
|
IsSlashableBlockCalled bool
|
|
}
|
|
|
|
// HighestAttestations will return an empty array of attestations.
|
|
func (MockSlasher) HighestAttestations(ctx context.Context, req *eth.HighestAttestationRequest, _ ...grpc.CallOption) (*eth.HighestAttestationResponse, error) {
|
|
return ð.HighestAttestationResponse{
|
|
Attestations: nil,
|
|
}, nil
|
|
}
|
|
|
|
// IsSlashableAttestation returns slashbale attestation if slash attestation is set to true.
|
|
func (ms MockSlasher) IsSlashableAttestation(_ context.Context, in *eth.IndexedAttestation, _ ...grpc.CallOption) (*eth.AttesterSlashingResponse, error) {
|
|
ms.IsSlashableAttestationCalled = true // skipcq: RVV-B0006
|
|
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 ð.AttesterSlashingResponse{
|
|
AttesterSlashings: slashings,
|
|
}, nil
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
// IsSlashableBlock returns proposer slashing if slash block is set to true.
|
|
func (ms MockSlasher) IsSlashableBlock(_ context.Context, in *eth.SignedBeaconBlockHeader, _ ...grpc.CallOption) (*eth.ProposerSlashingResponse, error) {
|
|
ms.IsSlashableBlockCalled = true // skipcq: RVV-B0006
|
|
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 ð.ProposerSlashingResponse{
|
|
ProposerSlashings: slashings,
|
|
}, nil
|
|
}
|
|
return nil, nil
|
|
}
|