mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 21:07:18 +00:00
acf201428e
* Use new proposal protection format * Update comments * Split and merge with new db * fix tests * fix test * optimize domain * fix validation * fix validation * check import error * fix e2e * fix old propose tests add ign block test * constant secret key * static test for signing * test domain * fix testsplit * gaz * gaz * tidy * raul feedback * fix tests * tidy * added info log for the migration * gaz * Update validator/client/propose_protect.go Co-authored-by: Nishant Das <nishdas93@gmail.com> * nishant feedback * import fix * fix * remove propose protection flag * fix block sign test Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
84 lines
2.9 KiB
Go
84 lines
2.9 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
mockSlasher "github.com/prysmaticlabs/prysm/validator/testing"
|
|
)
|
|
|
|
func TestPreBlockSignLocalValidation(t *testing.T) {
|
|
ctx := context.Background()
|
|
config := &featureconfig.Flags{
|
|
SlasherProtection: false,
|
|
}
|
|
reset := featureconfig.InitWithReset(config)
|
|
defer reset()
|
|
validator, _, validatorKey, finish := setup(t)
|
|
defer finish()
|
|
|
|
block := ðpb.BeaconBlock{
|
|
Slot: 10,
|
|
ProposerIndex: 0,
|
|
}
|
|
err := validator.db.SaveProposalHistoryForSlot(ctx, validatorKey.PublicKey().Marshal(), 10, []byte{1})
|
|
require.NoError(t, err)
|
|
pubKey := [48]byte{}
|
|
copy(pubKey[:], validatorKey.PublicKey().Marshal())
|
|
err = validator.preBlockSignValidations(context.Background(), pubKey, block)
|
|
require.ErrorContains(t, failedPreBlockSignLocalErr, err)
|
|
block.Slot = 9
|
|
err = validator.preBlockSignValidations(context.Background(), pubKey, block)
|
|
require.NoError(t, err, "Expected allowed attestation not to throw error")
|
|
}
|
|
|
|
func TestPreBlockSignValidation(t *testing.T) {
|
|
config := &featureconfig.Flags{
|
|
SlasherProtection: true,
|
|
}
|
|
reset := featureconfig.InitWithReset(config)
|
|
defer reset()
|
|
validator, _, validatorKey, finish := setup(t)
|
|
defer finish()
|
|
pubKey := [48]byte{}
|
|
copy(pubKey[:], validatorKey.PublicKey().Marshal())
|
|
|
|
block := ðpb.BeaconBlock{
|
|
Slot: 10,
|
|
ProposerIndex: 0,
|
|
}
|
|
mockProtector := &mockSlasher.MockProtector{AllowBlock: false}
|
|
validator.protector = mockProtector
|
|
err := validator.preBlockSignValidations(context.Background(), pubKey, block)
|
|
require.ErrorContains(t, failedPreBlockSignExternalErr, err)
|
|
mockProtector.AllowBlock = true
|
|
err = validator.preBlockSignValidations(context.Background(), pubKey, block)
|
|
require.NoError(t, err, "Expected allowed attestation not to throw error")
|
|
}
|
|
|
|
func TestPostBlockSignUpdate(t *testing.T) {
|
|
config := &featureconfig.Flags{
|
|
SlasherProtection: true,
|
|
}
|
|
reset := featureconfig.InitWithReset(config)
|
|
defer reset()
|
|
validator, _, validatorKey, finish := setup(t)
|
|
defer finish()
|
|
pubKey := [48]byte{}
|
|
copy(pubKey[:], validatorKey.PublicKey().Marshal())
|
|
emptyBlock := testutil.NewBeaconBlock()
|
|
emptyBlock.Block.Slot = 10
|
|
emptyBlock.Block.ProposerIndex = 0
|
|
mockProtector := &mockSlasher.MockProtector{AllowBlock: false}
|
|
validator.protector = mockProtector
|
|
err := validator.postBlockSignUpdate(context.Background(), pubKey, emptyBlock, nil)
|
|
require.ErrorContains(t, failedPostBlockSignErr, err, "Expected error when post signature update is detected as slashable")
|
|
mockProtector.AllowBlock = true
|
|
err = validator.postBlockSignUpdate(context.Background(), pubKey, emptyBlock, ðpb.DomainResponse{SignatureDomain: make([]byte, 32)})
|
|
require.NoError(t, err, "Expected allowed attestation not to throw error")
|
|
}
|