2018-11-24 18:57:07 +00:00
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestIsNewValidatorSetTransition(t *testing.T) {
|
2018-12-23 22:51:04 +00:00
|
|
|
beaconState, err := NewGenesisBeaconState(nil)
|
2018-11-24 18:57:07 +00:00
|
|
|
if err != nil {
|
2018-12-01 22:09:12 +00:00
|
|
|
t.Fatalf("Failed to initialize state: %v", err)
|
2018-11-24 18:57:07 +00:00
|
|
|
}
|
2018-12-23 22:51:04 +00:00
|
|
|
beaconState.ValidatorRegistryLastChangeSlot = 1
|
|
|
|
if IsValidatorSetChange(beaconState, 0) {
|
2018-11-24 18:57:07 +00:00
|
|
|
t.Errorf("Is new validator set change should be false, last changed slot greater than finalized slot")
|
|
|
|
}
|
2018-12-23 22:51:04 +00:00
|
|
|
beaconState.FinalizedSlot = 2
|
|
|
|
if IsValidatorSetChange(beaconState, 2) {
|
2018-11-24 18:57:07 +00:00
|
|
|
t.Errorf("Is new validator set change should be false, MinValidatorSetChangeInterval has not reached")
|
|
|
|
}
|
|
|
|
shardCommitteeForSlots := []*pb.ShardAndCommitteeArray{{
|
|
|
|
ArrayShardAndCommittee: []*pb.ShardAndCommittee{
|
|
|
|
{Shard: 0},
|
|
|
|
{Shard: 1},
|
|
|
|
{Shard: 2},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2018-12-23 22:51:04 +00:00
|
|
|
beaconState.ShardAndCommitteesAtSlots = shardCommitteeForSlots
|
2018-11-24 18:57:07 +00:00
|
|
|
|
|
|
|
crosslinks := []*pb.CrosslinkRecord{
|
|
|
|
{Slot: 1},
|
|
|
|
{Slot: 1},
|
|
|
|
{Slot: 1},
|
|
|
|
}
|
2018-12-23 22:51:04 +00:00
|
|
|
beaconState.LatestCrosslinks = crosslinks
|
2018-11-24 18:57:07 +00:00
|
|
|
|
2018-12-23 22:51:04 +00:00
|
|
|
if IsValidatorSetChange(beaconState, params.BeaconConfig().MinValidatorSetChangeInterval+1) {
|
2018-11-24 18:57:07 +00:00
|
|
|
t.Errorf("Is new validator set change should be false, crosslink slot record is higher than current slot")
|
|
|
|
}
|
|
|
|
|
|
|
|
crosslinks = []*pb.CrosslinkRecord{
|
|
|
|
{Slot: 2},
|
|
|
|
{Slot: 2},
|
|
|
|
{Slot: 2},
|
|
|
|
}
|
2018-12-23 22:51:04 +00:00
|
|
|
beaconState.LatestCrosslinks = crosslinks
|
2018-11-24 18:57:07 +00:00
|
|
|
|
2018-12-23 22:51:04 +00:00
|
|
|
if !IsValidatorSetChange(beaconState, params.BeaconConfig().MinValidatorSetChangeInterval+1) {
|
|
|
|
t.Errorf("New validator set change failed should have been true")
|
2018-11-24 18:57:07 +00:00
|
|
|
}
|
|
|
|
}
|