mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 12:27:18 +00:00
f0fcebccc4
* Get started on cleaning up slashing protection * Merge branch 'master' of github.com:prysmaticlabs/prysm into cleanup-protection * Move protection functions to own files * Lint * Merge branch 'master' of github.com:prysmaticlabs/prysm into cleanup-protection * Begin adding test for proposal protection * Merge branch 'master' of github.com:prysmaticlabs/prysm into cleanup-protection * Fix build * Fix tests * Fix tst * Fix tests * Fix proposal tests * Merge branch 'master' into cleanup-protection * Merge branch 'master' into cleanup-protection * Merge branch 'master' into cleanup-protection * Merge branch 'master' of github.com:prysmaticlabs/prysm into cleanup-protection * Reorder protections * Change lock * Fix test * Merge branch 'master' into cleanup-protection * Merge branch 'master' into cleanup-protection * Merge branch 'master' into cleanup-protection * Change log * Merge branch 'cleanup-protection' of github.com:prysmaticlabs/prysm into cleanup-protection * Merge branch 'master' into cleanup-protection
68 lines
2.0 KiB
Go
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{
|
|
ProtectAttester: false,
|
|
SlasherProtection: true,
|
|
}
|
|
reset := featureconfig.InitWithReset(config)
|
|
defer reset()
|
|
validator, _, finish := setup(t)
|
|
defer finish()
|
|
|
|
block := ðpb.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{
|
|
ProtectAttester: false,
|
|
SlasherProtection: true,
|
|
}
|
|
reset := featureconfig.InitWithReset(config)
|
|
defer reset()
|
|
validator, _, finish := setup(t)
|
|
defer finish()
|
|
|
|
block := ðpb.SignedBeaconBlock{
|
|
Block: ðpb.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)
|
|
}
|
|
}
|