mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
273871940c
* Moved a few packagesXXX to test_XXX * Gaz
70 lines
2.5 KiB
Go
70 lines
2.5 KiB
Go
package epoch_test
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/go-bitfield"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch"
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
)
|
|
|
|
func TestComputeValidatorParticipation(t *testing.T) {
|
|
params.OverrideBeaconConfig(params.MinimalSpecConfig())
|
|
e := uint64(1)
|
|
attestedBalance := uint64(1)
|
|
validatorCount := uint64(100)
|
|
|
|
validators := make([]*ethpb.Validator, validatorCount)
|
|
balances := make([]uint64, validatorCount)
|
|
for i := 0; i < len(validators); i++ {
|
|
validators[i] = ðpb.Validator{
|
|
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
|
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
|
|
}
|
|
balances[i] = params.BeaconConfig().MaxEffectiveBalance
|
|
}
|
|
|
|
atts := []*pb.PendingAttestation{{Data: ðpb.AttestationData{Crosslink: ðpb.Crosslink{Shard: 0}, Target: ðpb.Checkpoint{}}}}
|
|
var crosslinks []*ethpb.Crosslink
|
|
for i := uint64(0); i < params.BeaconConfig().ShardCount; i++ {
|
|
crosslinks = append(crosslinks, ðpb.Crosslink{
|
|
StartEpoch: 0,
|
|
DataRoot: []byte{'A'},
|
|
})
|
|
}
|
|
|
|
s := &pb.BeaconState{
|
|
Slot: e*params.BeaconConfig().SlotsPerEpoch + 1,
|
|
Validators: validators,
|
|
Balances: balances,
|
|
BlockRoots: make([][]byte, 128),
|
|
Slashings: []uint64{0, 1e9, 1e9},
|
|
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
|
ActiveIndexRoots: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
|
CompactCommitteesRoots: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
|
CurrentCrosslinks: crosslinks,
|
|
CurrentEpochAttestations: atts,
|
|
FinalizedCheckpoint: ðpb.Checkpoint{},
|
|
JustificationBits: bitfield.Bitvector4{0x00},
|
|
CurrentJustifiedCheckpoint: ðpb.Checkpoint{},
|
|
}
|
|
|
|
res, err := epoch.ComputeValidatorParticipation(s)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
wanted := ðpb.ValidatorParticipation{
|
|
VotedEther: attestedBalance,
|
|
EligibleEther: validatorCount * params.BeaconConfig().MaxEffectiveBalance,
|
|
GlobalParticipationRate: float32(attestedBalance) / float32(validatorCount*params.BeaconConfig().MaxEffectiveBalance),
|
|
}
|
|
|
|
if !reflect.DeepEqual(res, wanted) {
|
|
t.Errorf("Incorrect validator participation, wanted %v received %v", wanted, res)
|
|
}
|
|
}
|