mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
64795bd231
* archive participation begin implementation * validator participation compute * comments * compute participation common func * full test for archiving data * gazelle * complete tests * gaz * remove double negative grammar in comment * use archive in rpc * uses the archive! * error if nothing found in archive * comment * use head fetcher and root * tests pass * archive active set changes appropriately * archive committees * archive info * done with committee info archiving * archived set changes stored * fix build * test for archive balances and active indices * further abstractions * only archive epoch end * tests all pass * tests pass now * archive done * test for activated validators * tests for exited * amend message * use different proto * finalization fetcher * gaz * use root * use ctx * use new ethapis * use proper hash * match apis compatibility * match apis * properly use participation * fix tests * use right commit
69 lines
2.4 KiB
Go
69 lines
2.4 KiB
Go
package epoch
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/go-bitfield"
|
|
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())
|
|
epoch := 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: epoch*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 := 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)
|
|
}
|
|
}
|