2021-09-29 18:17:37 +00:00
|
|
|
package slasher
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2022-01-26 14:48:20 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/slasher/mock"
|
2021-09-29 18:17:37 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
|
|
|
"github.com/prysmaticlabs/prysm/testing/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestServer_IsSlashableAttestation_SlashingFound(t *testing.T) {
|
2022-01-26 14:48:20 +00:00
|
|
|
mockSlasher := &mock.MockSlashingChecker{
|
2021-09-29 18:17:37 +00:00
|
|
|
AttesterSlashingFound: true,
|
|
|
|
}
|
|
|
|
s := Server{SlashingChecker: mockSlasher}
|
|
|
|
ctx := context.Background()
|
|
|
|
slashing, err := s.IsSlashableAttestation(ctx, ðpb.IndexedAttestation{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, true, len(slashing.AttesterSlashings) > 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestServer_IsSlashableAttestation_SlashingNotFound(t *testing.T) {
|
2022-01-26 14:48:20 +00:00
|
|
|
mockSlasher := &mock.MockSlashingChecker{
|
2021-09-29 18:17:37 +00:00
|
|
|
AttesterSlashingFound: false,
|
|
|
|
}
|
|
|
|
s := Server{SlashingChecker: mockSlasher}
|
|
|
|
ctx := context.Background()
|
|
|
|
slashing, err := s.IsSlashableAttestation(ctx, ðpb.IndexedAttestation{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, true, len(slashing.AttesterSlashings) == 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestServer_IsSlashableBlock_SlashingFound(t *testing.T) {
|
2022-01-26 14:48:20 +00:00
|
|
|
mockSlasher := &mock.MockSlashingChecker{
|
2021-09-29 18:17:37 +00:00
|
|
|
ProposerSlashingFound: true,
|
|
|
|
}
|
|
|
|
s := Server{SlashingChecker: mockSlasher}
|
|
|
|
ctx := context.Background()
|
|
|
|
slashing, err := s.IsSlashableBlock(ctx, ðpb.SignedBeaconBlockHeader{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, true, len(slashing.ProposerSlashings) > 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestServer_IsSlashableBlock_SlashingNotFound(t *testing.T) {
|
2022-01-26 14:48:20 +00:00
|
|
|
mockSlasher := &mock.MockSlashingChecker{
|
2021-09-29 18:17:37 +00:00
|
|
|
ProposerSlashingFound: false,
|
|
|
|
}
|
|
|
|
s := Server{SlashingChecker: mockSlasher}
|
|
|
|
ctx := context.Background()
|
|
|
|
slashing, err := s.IsSlashableBlock(ctx, ðpb.SignedBeaconBlockHeader{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, true, len(slashing.ProposerSlashings) == 0)
|
|
|
|
}
|