mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 03:30:35 +00:00
5a66807989
* First take at updating everything to v5 * Patch gRPC gateway to use prysm v5 Fix patch * Update go ssz --------- Co-authored-by: Preston Van Loon <pvanloon@offchainlabs.com>
65 lines
2.1 KiB
Go
65 lines
2.1 KiB
Go
package simulator
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/config/params"
|
|
"github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/slashings"
|
|
"github.com/prysmaticlabs/prysm/v5/testing/require"
|
|
)
|
|
|
|
func TestGenerateAttestationsForSlot_Slashing(t *testing.T) {
|
|
ctx := context.Background()
|
|
simParams := &Parameters{
|
|
SecondsPerSlot: params.BeaconConfig().SecondsPerSlot,
|
|
SlotsPerEpoch: params.BeaconConfig().SlotsPerEpoch,
|
|
AggregationPercent: 1,
|
|
NumValidators: 64,
|
|
AttesterSlashingProbab: 1,
|
|
}
|
|
srv := setupService(t, simParams)
|
|
|
|
epoch3Atts, _, err := srv.generateAttestationsForSlot(ctx, params.BeaconConfig().SlotsPerEpoch*3)
|
|
require.NoError(t, err)
|
|
epoch4Atts, _, err := srv.generateAttestationsForSlot(ctx, params.BeaconConfig().SlotsPerEpoch*4)
|
|
require.NoError(t, err)
|
|
for i := 0; i < len(epoch3Atts); i += 2 {
|
|
goodAtt := epoch3Atts[i]
|
|
surroundAtt := epoch4Atts[i+1]
|
|
require.Equal(t, true, slashings.IsSurround(surroundAtt, goodAtt))
|
|
}
|
|
}
|
|
|
|
func TestGenerateAttestationsForSlot_CorrectIndices(t *testing.T) {
|
|
ctx := context.Background()
|
|
simParams := &Parameters{
|
|
SecondsPerSlot: params.BeaconConfig().SecondsPerSlot,
|
|
SlotsPerEpoch: params.BeaconConfig().SlotsPerEpoch,
|
|
AggregationPercent: 1,
|
|
NumValidators: 16384,
|
|
AttesterSlashingProbab: 0,
|
|
}
|
|
srv := setupService(t, simParams)
|
|
slot0Atts, _, err := srv.generateAttestationsForSlot(ctx, 0)
|
|
require.NoError(t, err)
|
|
slot1Atts, _, err := srv.generateAttestationsForSlot(ctx, 1)
|
|
require.NoError(t, err)
|
|
slot2Atts, _, err := srv.generateAttestationsForSlot(ctx, 2)
|
|
require.NoError(t, err)
|
|
var validatorIndices []uint64
|
|
for _, att := range append(slot0Atts, slot1Atts...) {
|
|
validatorIndices = append(validatorIndices, att.AttestingIndices...)
|
|
}
|
|
for _, att := range slot2Atts {
|
|
validatorIndices = append(validatorIndices, att.AttestingIndices...)
|
|
}
|
|
|
|
// Making sure indices are one after the other for attestations.
|
|
var validatorIndex uint64
|
|
for _, ii := range validatorIndices {
|
|
require.Equal(t, validatorIndex, ii)
|
|
validatorIndex++
|
|
}
|
|
}
|