prysm-pulse/validator/client/propose_protect_test.go
Ivan Martinez 359b9bef49
Merge separated local slashing protection flags (#6487)
* Merge split-up local protection flags

* Fix deprecated flags

* Fix text
2020-07-03 21:01:54 -05:00

68 lines
2.0 KiB
Go

package client
import (
"context"
"strings"
"testing"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
mockSlasher "github.com/prysmaticlabs/prysm/validator/testing"
)
func TestPreBlockSignValidation(t *testing.T) {
config := &featureconfig.Flags{
LocalProtection: false,
SlasherProtection: true,
}
reset := featureconfig.InitWithReset(config)
defer reset()
validator, _, finish := setup(t)
defer finish()
block := &ethpb.BeaconBlock{
Slot: 10,
ProposerIndex: 0,
}
mockProtector := &mockSlasher.MockProtector{AllowBlock: false}
validator.protector = mockProtector
err := validator.preBlockSignValidations(context.Background(), validatorPubKey, block)
if err == nil || !strings.Contains(err.Error(), failedPreBlockSignExternalErr) {
t.Fatal(err)
}
mockProtector.AllowBlock = true
err = validator.preBlockSignValidations(context.Background(), validatorPubKey, block)
if err != nil {
t.Fatalf("Expected allowed attestation not to throw error. got: %v", err)
}
}
func TestPostBlockSignUpdate(t *testing.T) {
config := &featureconfig.Flags{
LocalProtection: false,
SlasherProtection: true,
}
reset := featureconfig.InitWithReset(config)
defer reset()
validator, _, finish := setup(t)
defer finish()
block := &ethpb.SignedBeaconBlock{
Block: &ethpb.BeaconBlock{
Slot: 10,
ProposerIndex: 0,
},
}
mockProtector := &mockSlasher.MockProtector{AllowBlock: false}
validator.protector = mockProtector
err := validator.postBlockSignUpdate(context.Background(), validatorPubKey, block)
if err == nil || !strings.Contains(err.Error(), failedPostBlockSignErr) {
t.Fatalf("Expected error to be thrown when post signature update is detected as slashable. got: %v", err)
}
mockProtector.AllowBlock = true
err = validator.postBlockSignUpdate(context.Background(), validatorPubKey, block)
if err != nil {
t.Fatalf("Expected allowed attestation not to throw error. got: %v", err)
}
}