mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-12 04:30:04 +00:00
df33ce3309
* slasher beacon node changes * remaining beacon node items * moar changes * gaz * flag fix * rem slashable * builds * imports * fix up * pruning faster test * deepsource * fix wrong item * node node feature flags * broken test * preston review * more preston comments * comment Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
51 lines
1.9 KiB
Go
51 lines
1.9 KiB
Go
package slashingprotection
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/config/params"
|
|
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
|
eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/testing/assert"
|
|
mockSlasher "github.com/prysmaticlabs/prysm/validator/testing"
|
|
)
|
|
|
|
func TestService_VerifyAttestation(t *testing.T) {
|
|
s := &Service{slasherClient: mockSlasher.MockSlasher{SlashAttestation: true}}
|
|
att := ð.IndexedAttestation{
|
|
AttestingIndices: []uint64{1, 2},
|
|
Data: ð.AttestationData{
|
|
Slot: 5,
|
|
CommitteeIndex: 2,
|
|
BeaconBlockRoot: []byte("great block"),
|
|
Source: ð.Checkpoint{
|
|
Epoch: 4,
|
|
Root: []byte("good source"),
|
|
},
|
|
Target: ð.Checkpoint{
|
|
Epoch: 10,
|
|
Root: []byte("good target"),
|
|
},
|
|
},
|
|
}
|
|
assert.Equal(t, false, s.CheckAttestationSafety(context.Background(), att), "Expected verify attestation to fail verification")
|
|
s = &Service{slasherClient: mockSlasher.MockSlasher{SlashAttestation: false}}
|
|
assert.Equal(t, true, s.CheckAttestationSafety(context.Background(), att), "Expected verify attestation to pass verification")
|
|
}
|
|
|
|
func TestService_VerifyBlock(t *testing.T) {
|
|
s := &Service{slasherClient: mockSlasher.MockSlasher{SlashBlock: true}}
|
|
blk := ð.BeaconBlockHeader{
|
|
Slot: 0,
|
|
ProposerIndex: 0,
|
|
ParentRoot: bytesutil.PadTo([]byte("parent"), 32),
|
|
StateRoot: bytesutil.PadTo([]byte("state"), 32),
|
|
BodyRoot: bytesutil.PadTo([]byte("body"), 32),
|
|
}
|
|
sblk := ð.SignedBeaconBlockHeader{Header: blk, Signature: params.BeaconConfig().EmptySignature[:]}
|
|
assert.Equal(t, false, s.CheckBlockSafety(context.Background(), sblk), "Expected verify block to fail verification")
|
|
s = &Service{slasherClient: mockSlasher.MockSlasher{SlashBlock: false}}
|
|
assert.Equal(t, true, s.CheckBlockSafety(context.Background(), sblk), "Expected verify block to pass verification")
|
|
}
|