mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 12:27:18 +00:00
a840fa563d
* remove accounts-v1 * get all tests to not panic * all client tests passing * fix node test * eliminate old flags * tidy up
64 lines
2.0 KiB
Go
64 lines
2.0 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/require"
|
|
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, _, 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{
|
|
LocalProtection: false,
|
|
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.SignedBeaconBlock{
|
|
Block: ðpb.BeaconBlock{
|
|
Slot: 10,
|
|
ProposerIndex: 0,
|
|
},
|
|
}
|
|
mockProtector := &mockSlasher.MockProtector{AllowBlock: false}
|
|
validator.protector = mockProtector
|
|
err := validator.postBlockSignUpdate(context.Background(), pubKey, block)
|
|
require.ErrorContains(t, failedPostBlockSignErr, err, "Expected error when post signature update is detected as slashable")
|
|
mockProtector.AllowBlock = true
|
|
err = validator.postBlockSignUpdate(context.Background(), pubKey, block)
|
|
require.NoError(t, err, "Expected allowed attestation not to throw error")
|
|
}
|