prysm-pulse/beacon-chain/rpc/prysm/v1alpha1/slasher/attestations_test.go
Preston Van Loon 943dec525c
Refactor mock test helpers (#10133)
* Delete deploy contract tool. Move mock to its own package as testonly with some helper functions

* gofmt contracts/deposit/mock/mock.go

* move stategen mock.go to its on testonly pkg

* move password_reader_mock.go to mock testonly package

* move mock keymanager to its own testonly package

* move attestations mock

* move voluntaryexits mock

* Move slashings mock to mock pkg

* move the slasher mock

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2022-01-26 14:48:20 +00:00

64 lines
1.9 KiB
Go

package slasher
import (
"context"
"testing"
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/beacon-chain/slasher/mock"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/testing/require"
)
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,
},
}
mockSlasher := &mock.MockSlashingChecker{
HighestAtts: highestAtts,
}
s := Server{SlashingChecker: mockSlasher}
ctx := context.Background()
t.Run("single index found", func(t *testing.T) {
resp, err := s.HighestAttestations(ctx, &ethpb.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, &ethpb.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, &ethpb.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, &ethpb.HighestAttestationRequest{
ValidatorIndices: []uint64{0, 3},
})
require.NoError(t, err)
require.Equal(t, 1, len(resp.Attestations))
require.DeepEqual(t, highestAtts[0], resp.Attestations[0])
})
}