mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 04:47:18 +00:00
d077483577
* v3 import renamings * tidy * fmt * rev * Update beacon-chain/core/epoch/precompute/reward_penalty_test.go * Update beacon-chain/core/helpers/validators_test.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/iface/BUILD.bazel * Update beacon-chain/db/kv/kv.go * Update beacon-chain/db/kv/state.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/sync/initial-sync/service.go * fix deps * fix bad replacements * fix bad replacements * change back * gohashtree version * fix deps Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: Potuz <potuz@prysmaticlabs.com>
65 lines
2.1 KiB
Go
65 lines
2.1 KiB
Go
package simulator
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/config/params"
|
|
"github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1/slashings"
|
|
"github.com/prysmaticlabs/prysm/v3/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++
|
|
}
|
|
}
|