prysm-pulse/beacon-chain/core/state/transition_test.go

55 lines
1.5 KiB
Go
Raw Normal View History

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) {
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
}
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")
}
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},
},
},
}
beaconState.ShardAndCommitteesAtSlots = shardCommitteeForSlots
2018-11-24 18:57:07 +00:00
crosslinks := []*pb.CrosslinkRecord{
{Slot: 1},
{Slot: 1},
{Slot: 1},
}
beaconState.LatestCrosslinks = crosslinks
2018-11-24 18:57:07 +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},
}
beaconState.LatestCrosslinks = crosslinks
2018-11-24 18:57:07 +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
}
}