prysm-pulse/validator/testing/mock_slasher.go
Raul Jordan d077483577
Add V3 Suffix to All Prysm Packages (#11083)
* v3 import renamings

* tidy

* fmt

* rev

* Update beacon-chain/core/epoch/precompute/reward_penalty_test.go

* Update beacon-chain/core/helpers/validators_test.go

* Update beacon-chain/db/alias.go

* Update beacon-chain/db/alias.go

* Update beacon-chain/db/alias.go

* Update beacon-chain/db/iface/BUILD.bazel

* Update beacon-chain/db/kv/kv.go

* Update beacon-chain/db/kv/state.go

* Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go

* Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go

* Update beacon-chain/sync/initial-sync/service.go

* fix deps

* fix bad replacements

* fix bad replacements

* change back

* gohashtree version

* fix deps

Co-authored-by: Nishant Das <nishdas93@gmail.com>
Co-authored-by: Potuz <potuz@prysmaticlabs.com>
2022-08-16 12:20:13 +00:00

69 lines
2.1 KiB
Go

package testing
import (
"context"
"errors"
eth "github.com/prysmaticlabs/prysm/v3/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(_ context.Context, _ *eth.HighestAttestationRequest, _ ...grpc.CallOption) (*eth.HighestAttestationResponse, error) {
return &eth.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 &eth.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 &eth.ProposerSlashingResponse{
ProposerSlashings: slashings,
}, nil
}
return nil, nil
}