2021-09-30 02:33:28 +00:00
|
|
|
package slasher
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2022-08-16 12:20:13 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/slasher/mock"
|
|
|
|
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
2021-09-30 02:33:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestServer_HighestAttestations(t *testing.T) {
|
|
|
|
highestAtts := map[types.ValidatorIndex]*ethpb.HighestAttestation{
|
|
|
|
0: {
|
|
|
|
ValidatorIndex: 0,
|
|
|
|
HighestSourceEpoch: 1,
|
|
|
|
HighestTargetEpoch: 2,
|
|
|
|
},
|
|
|
|
1: {
|
|
|
|
ValidatorIndex: 1,
|
|
|
|
HighestSourceEpoch: 2,
|
|
|
|
HighestTargetEpoch: 3,
|
|
|
|
},
|
|
|
|
}
|
2022-01-26 14:48:20 +00:00
|
|
|
mockSlasher := &mock.MockSlashingChecker{
|
2021-09-30 02:33:28 +00:00
|
|
|
HighestAtts: highestAtts,
|
|
|
|
}
|
|
|
|
s := Server{SlashingChecker: mockSlasher}
|
|
|
|
ctx := context.Background()
|
|
|
|
t.Run("single index found", func(t *testing.T) {
|
|
|
|
resp, err := s.HighestAttestations(ctx, ðpb.HighestAttestationRequest{
|
|
|
|
ValidatorIndices: []uint64{0},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 1, len(resp.Attestations))
|
|
|
|
require.DeepEqual(t, highestAtts[0], resp.Attestations[0])
|
|
|
|
})
|
|
|
|
t.Run("single index not found", func(t *testing.T) {
|
|
|
|
resp, err := s.HighestAttestations(ctx, ðpb.HighestAttestationRequest{
|
|
|
|
ValidatorIndices: []uint64{3},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 0, len(resp.Attestations))
|
|
|
|
})
|
|
|
|
t.Run("multiple indices all found", func(t *testing.T) {
|
|
|
|
resp, err := s.HighestAttestations(ctx, ðpb.HighestAttestationRequest{
|
|
|
|
ValidatorIndices: []uint64{0, 1},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 2, len(resp.Attestations))
|
|
|
|
require.DeepEqual(t, highestAtts[0], resp.Attestations[0])
|
|
|
|
require.DeepEqual(t, highestAtts[1], resp.Attestations[1])
|
|
|
|
})
|
|
|
|
t.Run("multiple indices some not found", func(t *testing.T) {
|
|
|
|
resp, err := s.HighestAttestations(ctx, ðpb.HighestAttestationRequest{
|
|
|
|
ValidatorIndices: []uint64{0, 3},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 1, len(resp.Attestations))
|
|
|
|
require.DeepEqual(t, highestAtts[0], resp.Attestations[0])
|
|
|
|
})
|
|
|
|
}
|