WIP write test

This commit is contained in:
thatkawaiiguy
2019-01-30 23:21:36 -05:00
parent d97e0d5732
commit f7e7ed715c
2 changed files with 74 additions and 31 deletions

View File

@@ -192,7 +192,7 @@ func TestProcessEth1Data_InactionSlot(t *testing.T) {
},
}
// Adding a new receipt root ['D'] which should be the new processed receipt root.
// Adding a new deposit root ['G'] which should be the new processed deposit root.
newState := ProcessEth1Data(state)
if !bytes.Equal(newState.LatestEth1Data.DepositRootHash32, []byte{'A'}) {
t.Errorf("Incorrect DepositRootHash32. Wanted: %v, got: %v",

View File

@@ -1,6 +1,7 @@
package state
import (
"bytes"
"fmt"
"strings"
"testing"
@@ -93,8 +94,8 @@ func TestProcessBlock_IncorrectAttesterSlashing(t *testing.T) {
latestMixes := make([][]byte, config.LatestRandaoMixesLength)
beaconState := &pb.BeaconState{
LatestRandaoMixesHash32S: latestMixes,
Slot: 5,
ValidatorRegistry: registry,
Slot: 5,
ValidatorRegistry: registry,
}
block := &pb.BeaconBlock{
Slot: 5,
@@ -158,8 +159,8 @@ func TestProcessBlock_IncorrectProcessBlockAttestations(t *testing.T) {
latestMixes := make([][]byte, config.LatestRandaoMixesLength)
beaconState := &pb.BeaconState{
LatestRandaoMixesHash32S: latestMixes,
Slot: 5,
ValidatorRegistry: registry,
Slot: 5,
ValidatorRegistry: registry,
}
block := &pb.BeaconBlock{
Slot: 5,
@@ -246,9 +247,9 @@ func TestProcessBlock_IncorrectProcessExits(t *testing.T) {
LatestRandaoMixesHash32S: latestMixes,
ValidatorRegistry: registry,
Slot: 64,
PreviousJustifiedSlot: 10,
LatestBlockRootHash32S: blockRoots,
LatestCrosslinks: stateLatestCrosslinks,
PreviousJustifiedSlot: 10,
LatestBlockRootHash32S: blockRoots,
LatestCrosslinks: stateLatestCrosslinks,
}
exits := make([]*pb.Exit, config.MaxExits+1)
block := &pb.BeaconBlock{
@@ -337,9 +338,9 @@ func TestProcessBlock_PassesProcessingConditions(t *testing.T) {
LatestRandaoMixesHash32S: latestMixes,
ValidatorRegistry: registry,
Slot: 64,
PreviousJustifiedSlot: 10,
LatestBlockRootHash32S: blockRoots,
LatestCrosslinks: stateLatestCrosslinks,
PreviousJustifiedSlot: 10,
LatestBlockRootHash32S: blockRoots,
LatestCrosslinks: stateLatestCrosslinks,
}
exits := []*pb.Exit{
{
@@ -497,8 +498,8 @@ func TestProcessEpoch_CantGetCurrentValidatorIndices(t *testing.T) {
for i := uint64(0); i < config.EpochLength*2; i++ {
attestations = append(attestations, &pb.PendingAttestationRecord{
Data: &pb.AttestationData{
Slot: 1,
Shard: 1,
Slot: 1,
Shard: 1,
JustifiedBlockRootHash32: make([]byte, 32),
},
ParticipationBitfield: []byte{0xff},
@@ -517,37 +518,79 @@ func TestProcessEpoch_CantGetCurrentValidatorIndices(t *testing.T) {
}
}
func TestProcessEpoch_CantGetPrevValidatorIndices(t *testing.T) {
latestBlockRoots := make([][]byte, config.LatestBlockRootsLength)
for i := 0; i < len(latestBlockRoots); i++ {
latestBlockRoots[i] = config.ZeroHash[:]
func TestProcessEpoch_ProcessesEth1Data(t *testing.T) {
validatorRegistry := validators.InitialValidatorRegistry()
validatorBalances := make([]uint64, len(validatorRegistry))
for i := 0; i < len(validatorBalances); i++ {
validatorBalances[i] = config.MaxDeposit
}
startingSlot := config.Eth1DataVotingPeriod - config.EpochLength
var attestations []*pb.PendingAttestationRecord
for i := uint64(0); i < config.EpochLength*2; i++ {
for i := uint64(startingSlot - config.EpochLength); i < config.Eth1DataVotingPeriod; i++ {
attestations = append(attestations, &pb.PendingAttestationRecord{
Data: &pb.AttestationData{
Slot: 1,
Slot: i,
Shard: 1,
JustifiedBlockRootHash32: make([]byte, 32),
JustifiedSlot: startingSlot,
JustifiedBlockRootHash32: []byte{0},
},
ParticipationBitfield: []byte{0xff},
SlotIncluded: i + 1,
})
}
state := &pb.BeaconState{
Slot: config.EpochLength * 2,
LatestAttestations: attestations,
LatestBlockRootHash32S: latestBlockRoots,
var blockRoots [][]byte
for i := uint64(startingSlot); i < config.Eth1DataVotingPeriod; i++ {
blockRoots = append(blockRoots, []byte{byte(i)})
}
want := fmt.Sprintf(
"input committee slot 1 out of bounds: %d <= slot < %d",
config.EpochLength,
config.EpochLength*3,
)
if _, err := ProcessEpoch(state); !strings.Contains(err.Error(), want) {
t.Errorf("Expected: %s, received: %v", want, err)
var randaoHashes [][]byte
for i := uint64(startingSlot); i < config.Eth1DataVotingPeriod; i++ {
randaoHashes = append(randaoHashes, []byte{byte(i)})
}
crosslinkRecord := []*pb.CrosslinkRecord{{}, {}}
requiredVoteCount := config.Eth1DataVotingPeriod
state := &pb.BeaconState{
Slot: config.Eth1DataVotingPeriod,
LatestAttestations: attestations,
ValidatorBalances: validatorBalances,
ValidatorRegistry: validatorRegistry,
LatestBlockRootHash32S: blockRoots,
LatestCrosslinks: crosslinkRecord,
LatestRandaoMixesHash32S: randaoHashes,
LatestEth1Data: &pb.Eth1Data{
DepositRootHash32: []byte{1},
BlockHash32: []byte{2},
},
Eth1DataVotes: []*pb.Eth1DataVote{
{
Eth1Data: &pb.Eth1Data{
DepositRootHash32: []byte{'A'},
BlockHash32: []byte{'B'},
},
VoteCount: requiredVoteCount,
},
{
Eth1Data: &pb.Eth1Data{
DepositRootHash32: []byte{'C'},
BlockHash32: []byte{'D'},
},
VoteCount: 0,
},
},
}
state, err := ProcessEpoch(state)
if err != nil {
t.Errorf("Expected epoch transition to pass processing conditions: %v", err)
}
if !bytes.Equal(state.LatestEth1Data.DepositRootHash32, []byte{'A'}) {
t.Errorf("Expected epoch transition to process Eth1 data: %v", err)
}
}