mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
Add unit test to ActiveValidatorIndices (#4263)
* Add regression test to ActiveValidatorIndices * fix test, more comments * imports
This commit is contained in:
parent
0cb59bb018
commit
e72ff1bb4f
@ -1,6 +1,7 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
@ -248,3 +249,159 @@ func TestDomain_OK(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test basic functionality of ActiveValidatorIndices without caching. This test will need to be
|
||||
// rewritten when releasing some cache flag.
|
||||
func TestActiveValidatorIndices(t *testing.T) {
|
||||
farFutureEpoch := params.BeaconConfig().FarFutureEpoch
|
||||
type args struct {
|
||||
state *pb.BeaconState
|
||||
epoch uint64
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []uint64
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "all_active_epoch_10",
|
||||
args: args{
|
||||
state: &pb.BeaconState{
|
||||
Validators: []*ethpb.Validator{
|
||||
ðpb.Validator{
|
||||
ActivationEpoch: 0,
|
||||
ExitEpoch: farFutureEpoch,
|
||||
},
|
||||
ðpb.Validator{
|
||||
ActivationEpoch: 0,
|
||||
ExitEpoch: farFutureEpoch,
|
||||
},
|
||||
ðpb.Validator{
|
||||
ActivationEpoch: 0,
|
||||
ExitEpoch: farFutureEpoch,
|
||||
},
|
||||
},
|
||||
},
|
||||
epoch: 10,
|
||||
},
|
||||
want: []uint64{0, 1, 2},
|
||||
},
|
||||
{
|
||||
name: "some_active_epoch_10",
|
||||
args: args{
|
||||
state: &pb.BeaconState{
|
||||
Validators: []*ethpb.Validator{
|
||||
ðpb.Validator{
|
||||
ActivationEpoch: 0,
|
||||
ExitEpoch: farFutureEpoch,
|
||||
},
|
||||
ðpb.Validator{
|
||||
ActivationEpoch: 0,
|
||||
ExitEpoch: farFutureEpoch,
|
||||
},
|
||||
ðpb.Validator{
|
||||
ActivationEpoch: 0,
|
||||
ExitEpoch: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
epoch: 10,
|
||||
},
|
||||
want: []uint64{0, 1},
|
||||
},
|
||||
{
|
||||
name: "some_active_with_recent_new_epoch_10",
|
||||
args: args{
|
||||
state: &pb.BeaconState{
|
||||
Validators: []*ethpb.Validator{
|
||||
ðpb.Validator{
|
||||
ActivationEpoch: 0,
|
||||
ExitEpoch: farFutureEpoch,
|
||||
},
|
||||
ðpb.Validator{
|
||||
ActivationEpoch: 0,
|
||||
ExitEpoch: farFutureEpoch,
|
||||
},
|
||||
ðpb.Validator{
|
||||
ActivationEpoch: 0,
|
||||
ExitEpoch: 1,
|
||||
},
|
||||
ðpb.Validator{
|
||||
ActivationEpoch: 0,
|
||||
ExitEpoch: farFutureEpoch,
|
||||
},
|
||||
},
|
||||
},
|
||||
epoch: 10,
|
||||
},
|
||||
want: []uint64{0, 1, 3},
|
||||
},
|
||||
{
|
||||
name: "some_active_with_recent_new_epoch_10",
|
||||
args: args{
|
||||
state: &pb.BeaconState{
|
||||
Validators: []*ethpb.Validator{
|
||||
ðpb.Validator{
|
||||
ActivationEpoch: 0,
|
||||
ExitEpoch: farFutureEpoch,
|
||||
},
|
||||
ðpb.Validator{
|
||||
ActivationEpoch: 0,
|
||||
ExitEpoch: farFutureEpoch,
|
||||
},
|
||||
ðpb.Validator{
|
||||
ActivationEpoch: 0,
|
||||
ExitEpoch: 1,
|
||||
},
|
||||
ðpb.Validator{
|
||||
ActivationEpoch: 0,
|
||||
ExitEpoch: farFutureEpoch,
|
||||
},
|
||||
},
|
||||
},
|
||||
epoch: 10,
|
||||
},
|
||||
want: []uint64{0, 1, 3},
|
||||
},
|
||||
{
|
||||
name: "some_active_with_recent_new_epoch_10",
|
||||
args: args{
|
||||
state: &pb.BeaconState{
|
||||
Validators: []*ethpb.Validator{
|
||||
ðpb.Validator{
|
||||
ActivationEpoch: 0,
|
||||
ExitEpoch: farFutureEpoch,
|
||||
},
|
||||
ðpb.Validator{
|
||||
ActivationEpoch: 0,
|
||||
ExitEpoch: 1,
|
||||
},
|
||||
ðpb.Validator{
|
||||
ActivationEpoch: 0,
|
||||
ExitEpoch: farFutureEpoch,
|
||||
},
|
||||
ðpb.Validator{
|
||||
ActivationEpoch: 0,
|
||||
ExitEpoch: farFutureEpoch,
|
||||
},
|
||||
},
|
||||
},
|
||||
epoch: 10,
|
||||
},
|
||||
want: []uint64{0, 2, 3},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := ActiveValidatorIndices(tt.args.state, tt.args.epoch)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("ActiveValidatorIndices() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("ActiveValidatorIndices() got = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user