mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 21:38:05 -05:00
proper error checking and type assertions (#5424)
* proper error checking and type assertions
This commit is contained in:
@@ -15,10 +15,9 @@ func TestHeadSlot_DataRace(t *testing.T) {
|
||||
beaconDB: db,
|
||||
}
|
||||
go func() {
|
||||
s.saveHead(
|
||||
context.Background(),
|
||||
[32]byte{},
|
||||
)
|
||||
if err := s.saveHead(context.Background(), [32]byte{}, ); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}()
|
||||
s.HeadSlot()
|
||||
}
|
||||
@@ -31,10 +30,9 @@ func TestHeadRoot_DataRace(t *testing.T) {
|
||||
head: &head{root: [32]byte{'A'}},
|
||||
}
|
||||
go func() {
|
||||
s.saveHead(
|
||||
context.Background(),
|
||||
[32]byte{},
|
||||
)
|
||||
if err := s.saveHead(context.Background(), [32]byte{}, ); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}()
|
||||
if _, err := s.HeadRoot(context.Background()); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -49,12 +47,13 @@ func TestHeadBlock_DataRace(t *testing.T) {
|
||||
head: &head{block: ðpb.SignedBeaconBlock{}},
|
||||
}
|
||||
go func() {
|
||||
s.saveHead(
|
||||
context.Background(),
|
||||
[32]byte{},
|
||||
)
|
||||
if err := s.saveHead(context.Background(), [32]byte{}, ); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}()
|
||||
s.HeadBlock(context.Background())
|
||||
if _, err := s.HeadBlock(context.Background()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHeadState_DataRace(t *testing.T) {
|
||||
@@ -64,10 +63,11 @@ func TestHeadState_DataRace(t *testing.T) {
|
||||
beaconDB: db,
|
||||
}
|
||||
go func() {
|
||||
s.saveHead(
|
||||
context.Background(),
|
||||
[32]byte{},
|
||||
)
|
||||
if err := s.saveHead(context.Background(), [32]byte{}, ); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}()
|
||||
s.HeadState(context.Background())
|
||||
if _, err := s.HeadState(context.Background()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +128,10 @@ func TestPrevJustifiedCheckpt_GenesisRootOk(t *testing.T) {
|
||||
|
||||
func TestHeadSlot_CanRetrieve(t *testing.T) {
|
||||
c := &Service{}
|
||||
s, _ := state.InitializeFromProto(&pb.BeaconState{})
|
||||
s, err := state.InitializeFromProto(&pb.BeaconState{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
c.head = &head{slot: 100, state: s}
|
||||
if c.HeadSlot() != 100 {
|
||||
t.Errorf("Wanted head slot: %d, got: %d", 100, c.HeadSlot())
|
||||
@@ -145,7 +148,10 @@ func TestHeadRoot_CanRetrieve(t *testing.T) {
|
||||
|
||||
func TestHeadBlock_CanRetrieve(t *testing.T) {
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 1}}
|
||||
s, _ := state.InitializeFromProto(&pb.BeaconState{})
|
||||
s, err := state.InitializeFromProto(&pb.BeaconState{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
c := &Service{}
|
||||
c.head = &head{block: b, state: s}
|
||||
|
||||
|
||||
@@ -44,10 +44,20 @@ func TestSaveHead_Different(t *testing.T) {
|
||||
|
||||
newHeadBlock := ðpb.BeaconBlock{Slot: 1}
|
||||
newHeadSignedBlock := ðpb.SignedBeaconBlock{Block: newHeadBlock}
|
||||
service.beaconDB.SaveBlock(context.Background(), newHeadSignedBlock)
|
||||
newRoot, _ := ssz.HashTreeRoot(newHeadBlock)
|
||||
headState, _ := state.InitializeFromProto(&pb.BeaconState{Slot: 1})
|
||||
service.beaconDB.SaveState(context.Background(), headState, newRoot)
|
||||
if err := service.beaconDB.SaveBlock(context.Background(), newHeadSignedBlock); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
newRoot, err := ssz.HashTreeRoot(newHeadBlock)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
headState, err := state.InitializeFromProto(&pb.BeaconState{Slot: 1})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveState(context.Background(), headState, newRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.saveHead(context.Background(), newRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -30,10 +30,15 @@ func TestFilterBoundaryCandidates_FilterCorrect(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
st, _ := stateTrie.InitializeFromProtoUnsafe(&pb.BeaconState{})
|
||||
st, err := stateTrie.InitializeFromProtoUnsafe(&pb.BeaconState{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for i := uint64(0); i < 500; i++ {
|
||||
st.SetSlot(i)
|
||||
if err := st.SetSlot(i); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
root := [32]byte{}
|
||||
copy(root[:], bytesutil.Bytes32(i))
|
||||
service.initSyncState[root] = st.Copy()
|
||||
@@ -43,14 +48,18 @@ func TestFilterBoundaryCandidates_FilterCorrect(t *testing.T) {
|
||||
}
|
||||
lastIndex := len(service.boundaryRoots) - 1
|
||||
for i := uint64(500); i < 2000; i++ {
|
||||
st.SetSlot(i)
|
||||
if err := st.SetSlot(i); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
root := [32]byte{}
|
||||
copy(root[:], bytesutil.Bytes32(i))
|
||||
service.initSyncState[root] = st.Copy()
|
||||
}
|
||||
// Set current state.
|
||||
latestSlot := helpers.RoundUpToNearestEpoch(2000)
|
||||
st.SetSlot(latestSlot)
|
||||
if err := st.SetSlot(latestSlot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
lastRoot := [32]byte{}
|
||||
copy(lastRoot[:], bytesutil.Bytes32(latestSlot))
|
||||
|
||||
@@ -85,10 +94,15 @@ func TestFilterBoundaryCandidates_HandleSkippedSlots(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
st, _ := stateTrie.InitializeFromProtoUnsafe(&pb.BeaconState{})
|
||||
st, err := stateTrie.InitializeFromProtoUnsafe(&pb.BeaconState{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for i := uint64(0); i < 500; i++ {
|
||||
st.SetSlot(i)
|
||||
if err := st.SetSlot(i); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
root := [32]byte{}
|
||||
copy(root[:], bytesutil.Bytes32(i))
|
||||
service.initSyncState[root] = st.Copy()
|
||||
@@ -98,7 +112,9 @@ func TestFilterBoundaryCandidates_HandleSkippedSlots(t *testing.T) {
|
||||
}
|
||||
lastIndex := len(service.boundaryRoots) - 1
|
||||
for i := uint64(500); i < 2000; i++ {
|
||||
st.SetSlot(i)
|
||||
if err := st.SetSlot(i); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
root := [32]byte{}
|
||||
copy(root[:], bytesutil.Bytes32(i))
|
||||
// save only for offsetted slots
|
||||
@@ -108,7 +124,9 @@ func TestFilterBoundaryCandidates_HandleSkippedSlots(t *testing.T) {
|
||||
}
|
||||
// Set current state.
|
||||
latestSlot := helpers.RoundUpToNearestEpoch(2000)
|
||||
st.SetSlot(latestSlot)
|
||||
if err := st.SetSlot(latestSlot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
lastRoot := [32]byte{}
|
||||
copy(lastRoot[:], bytesutil.Bytes32(latestSlot))
|
||||
|
||||
@@ -150,10 +168,15 @@ func TestPruneOldStates_AlreadyFinalized(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
st, _ := stateTrie.InitializeFromProtoUnsafe(&pb.BeaconState{})
|
||||
st, err := stateTrie.InitializeFromProtoUnsafe(&pb.BeaconState{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for i := uint64(100); i < 200; i++ {
|
||||
st.SetSlot(i)
|
||||
if err := st.SetSlot(i); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
root := [32]byte{}
|
||||
copy(root[:], bytesutil.Bytes32(i))
|
||||
service.initSyncState[root] = st.Copy()
|
||||
@@ -184,10 +207,15 @@ func TestPruneNonBoundary_CanPrune(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
st, _ := stateTrie.InitializeFromProtoUnsafe(&pb.BeaconState{})
|
||||
st, err := stateTrie.InitializeFromProtoUnsafe(&pb.BeaconState{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for i := uint64(0); i < 2000; i++ {
|
||||
st.SetSlot(i)
|
||||
if err := st.SetSlot(i); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
root := [32]byte{}
|
||||
copy(root[:], bytesutil.Bytes32(i))
|
||||
service.initSyncState[root] = st.Copy()
|
||||
@@ -223,19 +251,28 @@ func TestGenerateState_CorrectlyGenerated(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
beaconState.SetLatestBlockHeader(ðpb.BeaconBlockHeader{
|
||||
err = beaconState.SetLatestBlockHeader(ðpb.BeaconBlockHeader{
|
||||
Slot: genesisBlock.Block.Slot,
|
||||
ParentRoot: genesisBlock.Block.ParentRoot,
|
||||
StateRoot: params.BeaconConfig().ZeroHash[:],
|
||||
BodyRoot: bodyRoot[:],
|
||||
})
|
||||
beaconState.SetSlashings(make([]uint64, params.BeaconConfig().EpochsPerSlashingsVector))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := beaconState.SetSlashings(make([]uint64, params.BeaconConfig().EpochsPerSlashingsVector)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cp := beaconState.CurrentJustifiedCheckpoint()
|
||||
mockRoot := [32]byte{}
|
||||
copy(mockRoot[:], "hello-world")
|
||||
cp.Root = mockRoot[:]
|
||||
beaconState.SetCurrentJustifiedCheckpoint(cp)
|
||||
beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{})
|
||||
if err := beaconState.SetCurrentJustifiedCheckpoint(cp); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = db.SaveBlock(context.Background(), genesisBlock)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -40,13 +40,19 @@ func TestStore_OnAttestation(t *testing.T) {
|
||||
if err := db.SaveBlock(ctx, BlkWithOutState); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
BlkWithOutStateRoot, _ := ssz.HashTreeRoot(BlkWithOutState.Block)
|
||||
BlkWithOutStateRoot, err := ssz.HashTreeRoot(BlkWithOutState.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
BlkWithStateBadAtt := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 1}}
|
||||
if err := db.SaveBlock(ctx, BlkWithStateBadAtt); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
BlkWithStateBadAttRoot, _ := ssz.HashTreeRoot(BlkWithStateBadAtt.Block)
|
||||
BlkWithStateBadAttRoot, err := ssz.HashTreeRoot(BlkWithStateBadAtt.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
s, err := beaconstate.InitializeFromProto(&pb.BeaconState{})
|
||||
if err := s.SetSlot(100 * params.BeaconConfig().SlotsPerEpoch); err != nil {
|
||||
@@ -60,8 +66,11 @@ func TestStore_OnAttestation(t *testing.T) {
|
||||
if err := db.SaveBlock(ctx, BlkWithValidState); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
BlkWithValidStateRoot, _ := ssz.HashTreeRoot(BlkWithValidState.Block)
|
||||
s, _ = stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
BlkWithValidStateRoot, err := ssz.HashTreeRoot(BlkWithValidState.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s, err = stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
Fork: &pb.Fork{
|
||||
Epoch: 0,
|
||||
CurrentVersion: params.BeaconConfig().GenesisForkVersion,
|
||||
@@ -69,6 +78,9 @@ func TestStore_OnAttestation(t *testing.T) {
|
||||
},
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveState(ctx, s, BlkWithValidStateRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -137,7 +149,7 @@ func TestStore_SaveCheckpointState(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
s, _ := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
s, err := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
Fork: &pb.Fork{
|
||||
Epoch: 0,
|
||||
CurrentVersion: params.BeaconConfig().GenesisForkVersion,
|
||||
@@ -153,6 +165,9 @@ func TestStore_SaveCheckpointState(t *testing.T) {
|
||||
Validators: []*ethpb.Validator{{PublicKey: bytesutil.PadTo([]byte("foo"), 48)}},
|
||||
Balances: []uint64{0},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r := [32]byte{'g'}
|
||||
if err := service.beaconDB.SaveState(ctx, s, r); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -163,7 +178,9 @@ func TestStore_SaveCheckpointState(t *testing.T) {
|
||||
service.prevFinalizedCheckpt = ðpb.Checkpoint{Root: r[:]}
|
||||
|
||||
cp1 := ðpb.Checkpoint{Epoch: 1, Root: bytesutil.PadTo([]byte{'A'}, 32)}
|
||||
service.beaconDB.SaveState(ctx, s, bytesutil.ToBytes32([]byte{'A'}))
|
||||
if err := service.beaconDB.SaveState(ctx, s, bytesutil.ToBytes32([]byte{'A'})); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s1, err := service.getAttPreState(ctx, cp1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -173,7 +190,9 @@ func TestStore_SaveCheckpointState(t *testing.T) {
|
||||
}
|
||||
|
||||
cp2 := ðpb.Checkpoint{Epoch: 2, Root: bytesutil.PadTo([]byte{'B'}, 32)}
|
||||
service.beaconDB.SaveState(ctx, s, bytesutil.ToBytes32([]byte{'B'}))
|
||||
if err := service.beaconDB.SaveState(ctx, s, bytesutil.ToBytes32([]byte{'B'})); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s2, err := service.getAttPreState(ctx, cp2)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -206,13 +225,17 @@ func TestStore_SaveCheckpointState(t *testing.T) {
|
||||
t.Errorf("Wanted state slot: %d, got: %d", 2*params.BeaconConfig().SlotsPerEpoch, s2.Slot())
|
||||
}
|
||||
|
||||
s.SetSlot(params.BeaconConfig().SlotsPerEpoch + 1)
|
||||
if err := s.SetSlot(params.BeaconConfig().SlotsPerEpoch + 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
service.justifiedCheckpt = ðpb.Checkpoint{Root: r[:]}
|
||||
service.bestJustifiedCheckpt = ðpb.Checkpoint{Root: r[:]}
|
||||
service.finalizedCheckpt = ðpb.Checkpoint{Root: r[:]}
|
||||
service.prevFinalizedCheckpt = ðpb.Checkpoint{Root: r[:]}
|
||||
cp3 := ðpb.Checkpoint{Epoch: 1, Root: bytesutil.PadTo([]byte{'C'}, 32)}
|
||||
service.beaconDB.SaveState(ctx, s, bytesutil.ToBytes32([]byte{'C'}))
|
||||
if err := service.beaconDB.SaveState(ctx, s, bytesutil.ToBytes32([]byte{'C'})); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s3, err := service.getAttPreState(ctx, cp3)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -235,9 +258,13 @@ func TestStore_UpdateCheckpointState(t *testing.T) {
|
||||
|
||||
epoch := uint64(1)
|
||||
baseState, _ := testutil.DeterministicGenesisState(t, 1)
|
||||
baseState.SetSlot(epoch * params.BeaconConfig().SlotsPerEpoch)
|
||||
if err := baseState.SetSlot(epoch * params.BeaconConfig().SlotsPerEpoch); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
checkpoint := ðpb.Checkpoint{Epoch: epoch}
|
||||
service.beaconDB.SaveState(ctx, baseState, bytesutil.ToBytes32(checkpoint.Root))
|
||||
if err := service.beaconDB.SaveState(ctx, baseState, bytesutil.ToBytes32(checkpoint.Root)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
returned, err := service.getAttPreState(ctx, checkpoint)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -256,7 +283,9 @@ func TestStore_UpdateCheckpointState(t *testing.T) {
|
||||
|
||||
epoch = uint64(2)
|
||||
newCheckpoint := ðpb.Checkpoint{Epoch: epoch}
|
||||
service.beaconDB.SaveState(ctx, baseState, bytesutil.ToBytes32(newCheckpoint.Root))
|
||||
if err := service.beaconDB.SaveState(ctx, baseState, bytesutil.ToBytes32(newCheckpoint.Root)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
returned, err = service.getAttPreState(ctx, newCheckpoint)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -368,11 +397,17 @@ func TestVerifyBeaconBlock_futureBlock(t *testing.T) {
|
||||
}
|
||||
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 2}}
|
||||
service.beaconDB.SaveBlock(ctx, b)
|
||||
r, _ := ssz.HashTreeRoot(b.Block)
|
||||
if err := service.beaconDB.SaveBlock(ctx, b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r, err := ssz.HashTreeRoot(b.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
d := ðpb.AttestationData{Slot: 1, BeaconBlockRoot: r[:]}
|
||||
|
||||
if err := service.verifyBeaconBlock(ctx, d); !strings.Contains(err.Error(), "could not process attestation for future block") {
|
||||
err = service.verifyBeaconBlock(ctx, d)
|
||||
if err == nil || !strings.Contains(err.Error(), "could not process attestation for future block") {
|
||||
t.Error("Did not receive the wanted error")
|
||||
}
|
||||
}
|
||||
@@ -389,8 +424,13 @@ func TestVerifyBeaconBlock_OK(t *testing.T) {
|
||||
}
|
||||
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 2}}
|
||||
service.beaconDB.SaveBlock(ctx, b)
|
||||
r, _ := ssz.HashTreeRoot(b.Block)
|
||||
if err := service.beaconDB.SaveBlock(ctx, b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r, err := ssz.HashTreeRoot(b.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
d := ðpb.AttestationData{Slot: 2, BeaconBlockRoot: r[:]}
|
||||
|
||||
if err := service.verifyBeaconBlock(ctx, d); err != nil {
|
||||
|
||||
@@ -110,7 +110,7 @@ func TestStore_OnBlock(t *testing.T) {
|
||||
service.finalizedCheckpt.Root = roots[0]
|
||||
|
||||
_, err := service.onBlock(ctx, ðpb.SignedBeaconBlock{Block: tt.blk})
|
||||
if !strings.Contains(err.Error(), tt.wantErrString) {
|
||||
if err == nil || !strings.Contains(err.Error(), tt.wantErrString) {
|
||||
t.Errorf("Store.OnBlock() error = %v, wantErr = %v", err, tt.wantErrString)
|
||||
}
|
||||
})
|
||||
@@ -144,7 +144,10 @@ func TestRemoveStateSinceLastFinalized(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s, _ := stateTrie.InitializeFromProto(&pb.BeaconState{Slot: uint64(i)})
|
||||
s, err := stateTrie.InitializeFromProto(&pb.BeaconState{Slot: uint64(i)})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveState(ctx, s, r); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -217,9 +220,15 @@ func TestRemoveStateSinceLastFinalized_EmptyStartSlot(t *testing.T) {
|
||||
}
|
||||
|
||||
lastJustifiedBlk := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{ParentRoot: []byte{'G'}}}
|
||||
lastJustifiedRoot, _ := ssz.HashTreeRoot(lastJustifiedBlk.Block)
|
||||
lastJustifiedRoot, err := ssz.HashTreeRoot(lastJustifiedBlk.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
newJustifiedBlk := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 1, ParentRoot: lastJustifiedRoot[:]}}
|
||||
newJustifiedRoot, _ := ssz.HashTreeRoot(newJustifiedBlk.Block)
|
||||
newJustifiedRoot, err := ssz.HashTreeRoot(newJustifiedBlk.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveBlock(ctx, newJustifiedBlk); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -252,9 +261,15 @@ func TestShouldUpdateJustified_ReturnFalse(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
lastJustifiedBlk := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{ParentRoot: []byte{'G'}}}
|
||||
lastJustifiedRoot, _ := ssz.HashTreeRoot(lastJustifiedBlk.Block)
|
||||
lastJustifiedRoot, err := ssz.HashTreeRoot(lastJustifiedBlk.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
newJustifiedBlk := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{ParentRoot: lastJustifiedRoot[:]}}
|
||||
newJustifiedRoot, _ := ssz.HashTreeRoot(newJustifiedBlk.Block)
|
||||
newJustifiedRoot, err := ssz.HashTreeRoot(newJustifiedBlk.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveBlock(ctx, newJustifiedBlk); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -286,7 +301,10 @@ func TestCachedPreState_CanGetFromCache(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
s, _ := stateTrie.InitializeFromProto(&pb.BeaconState{Slot: 1})
|
||||
s, err := stateTrie.InitializeFromProto(&pb.BeaconState{Slot: 1})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r := [32]byte{'A'}
|
||||
b := ðpb.BeaconBlock{Slot: 1, ParentRoot: r[:]}
|
||||
service.initSyncState[r] = s
|
||||
@@ -317,12 +335,17 @@ func TestCachedPreState_CanGetFromDB(t *testing.T) {
|
||||
service.finalizedCheckpt = ðpb.Checkpoint{Root: r[:]}
|
||||
_, err = service.verifyBlkPreState(ctx, b)
|
||||
wanted := "pre state of slot 1 does not exist"
|
||||
if err.Error() != wanted {
|
||||
if err == nil || err.Error() != wanted {
|
||||
t.Error("Did not get wanted error")
|
||||
}
|
||||
|
||||
s, _ := stateTrie.InitializeFromProto(&pb.BeaconState{Slot: 1})
|
||||
service.beaconDB.SaveState(ctx, s, r)
|
||||
s, err := stateTrie.InitializeFromProto(&pb.BeaconState{Slot: 1})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveState(ctx, s, r); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
received, err := service.verifyBlkPreState(ctx, b)
|
||||
if err != nil {
|
||||
@@ -346,16 +369,28 @@ func TestSaveInitState_CanSaveDelete(t *testing.T) {
|
||||
|
||||
for i := uint64(0); i < 64; i++ {
|
||||
b := ðpb.BeaconBlock{Slot: i}
|
||||
s, _ := stateTrie.InitializeFromProto(&pb.BeaconState{Slot: i})
|
||||
r, _ := ssz.HashTreeRoot(b)
|
||||
s, err := stateTrie.InitializeFromProto(&pb.BeaconState{Slot: i})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r, err := ssz.HashTreeRoot(b)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
service.initSyncState[r] = s
|
||||
}
|
||||
|
||||
// Set finalized root as slot 32
|
||||
finalizedRoot, _ := ssz.HashTreeRoot(ðpb.BeaconBlock{Slot: 32})
|
||||
finalizedRoot, err := ssz.HashTreeRoot(ðpb.BeaconBlock{Slot: 32})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
s, _ := stateTrie.InitializeFromProto(&pb.BeaconState{FinalizedCheckpoint: ðpb.Checkpoint{
|
||||
s, err := stateTrie.InitializeFromProto(&pb.BeaconState{FinalizedCheckpoint: ðpb.Checkpoint{
|
||||
Epoch: 1, Root: finalizedRoot[:]}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.saveInitState(ctx, s); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -401,7 +436,10 @@ func TestUpdateJustified_CouldUpdateBest(t *testing.T) {
|
||||
}
|
||||
|
||||
// Could update
|
||||
s, _ := stateTrie.InitializeFromProto(&pb.BeaconState{CurrentJustifiedCheckpoint: ðpb.Checkpoint{Epoch: 1, Root: r[:]}})
|
||||
s, err := stateTrie.InitializeFromProto(&pb.BeaconState{CurrentJustifiedCheckpoint: ðpb.Checkpoint{Epoch: 1, Root: r[:]}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.updateJustified(context.Background(), s); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -433,10 +471,19 @@ func TestFilterBlockRoots_CanFilter(t *testing.T) {
|
||||
}
|
||||
|
||||
fBlock := ðpb.BeaconBlock{}
|
||||
fRoot, _ := ssz.HashTreeRoot(fBlock)
|
||||
fRoot, err := ssz.HashTreeRoot(fBlock)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
hBlock := ðpb.BeaconBlock{Slot: 1}
|
||||
headRoot, _ := ssz.HashTreeRoot(hBlock)
|
||||
st, _ := stateTrie.InitializeFromProtoUnsafe(&pb.BeaconState{})
|
||||
headRoot, err := ssz.HashTreeRoot(hBlock)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
st, err := stateTrie.InitializeFromProtoUnsafe(&pb.BeaconState{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveBlock(ctx, ðpb.SignedBeaconBlock{Block: fBlock}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -479,10 +526,15 @@ func TestPersistCache_CanSave(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
st, _ := stateTrie.InitializeFromProtoUnsafe(&pb.BeaconState{})
|
||||
st, err := stateTrie.InitializeFromProtoUnsafe(&pb.BeaconState{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for i := uint64(0); i < initialSyncCacheSize; i++ {
|
||||
st.SetSlot(i)
|
||||
if err := st.SetSlot(i); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
root := [32]byte{}
|
||||
copy(root[:], bytesutil.Bytes32(i))
|
||||
service.initSyncState[root] = st.Copy()
|
||||
@@ -531,7 +583,10 @@ func TestFillForkChoiceMissingBlocks_CanSave(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
st, _ := stateTrie.InitializeFromProtoUnsafe(&pb.BeaconState{})
|
||||
st, err := stateTrie.InitializeFromProtoUnsafe(&pb.BeaconState{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveState(ctx, st.Copy(), validGenesisRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -585,7 +640,10 @@ func TestFillForkChoiceMissingBlocks_FilterFinalized(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
st, _ := stateTrie.InitializeFromProtoUnsafe(&pb.BeaconState{})
|
||||
st, err := stateTrie.InitializeFromProtoUnsafe(&pb.BeaconState{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveState(ctx, st.Copy(), validGenesisRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -595,12 +653,18 @@ func TestFillForkChoiceMissingBlocks_FilterFinalized(t *testing.T) {
|
||||
if err := service.beaconDB.SaveBlock(ctx, b63); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r63, _ := ssz.HashTreeRoot(b63.Block)
|
||||
r63, err := ssz.HashTreeRoot(b63.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b64 := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 64, ParentRoot: r63[:]}}
|
||||
if err := service.beaconDB.SaveBlock(ctx, b64); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r64, _ := ssz.HashTreeRoot(b64.Block)
|
||||
r64, err := ssz.HashTreeRoot(b64.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b65 := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 65, ParentRoot: r64[:]}}
|
||||
if err := service.beaconDB.SaveBlock(ctx, b65); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -629,21 +693,45 @@ func TestFillForkChoiceMissingBlocks_FilterFinalized(t *testing.T) {
|
||||
// (B1, and B3 are all from the same slots)
|
||||
func blockTree1(db db.Database, genesisRoot []byte) ([][]byte, error) {
|
||||
b0 := ðpb.BeaconBlock{Slot: 0, ParentRoot: genesisRoot}
|
||||
r0, _ := ssz.HashTreeRoot(b0)
|
||||
r0, err := ssz.HashTreeRoot(b0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b1 := ðpb.BeaconBlock{Slot: 1, ParentRoot: r0[:]}
|
||||
r1, _ := ssz.HashTreeRoot(b1)
|
||||
r1, err := ssz.HashTreeRoot(b1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b3 := ðpb.BeaconBlock{Slot: 3, ParentRoot: r0[:]}
|
||||
r3, _ := ssz.HashTreeRoot(b3)
|
||||
r3, err := ssz.HashTreeRoot(b3)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b4 := ðpb.BeaconBlock{Slot: 4, ParentRoot: r3[:]}
|
||||
r4, _ := ssz.HashTreeRoot(b4)
|
||||
r4, err := ssz.HashTreeRoot(b4)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b5 := ðpb.BeaconBlock{Slot: 5, ParentRoot: r4[:]}
|
||||
r5, _ := ssz.HashTreeRoot(b5)
|
||||
r5, err := ssz.HashTreeRoot(b5)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b6 := ðpb.BeaconBlock{Slot: 6, ParentRoot: r4[:]}
|
||||
r6, _ := ssz.HashTreeRoot(b6)
|
||||
r6, err := ssz.HashTreeRoot(b6)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b7 := ðpb.BeaconBlock{Slot: 7, ParentRoot: r5[:]}
|
||||
r7, _ := ssz.HashTreeRoot(b7)
|
||||
r7, err := ssz.HashTreeRoot(b7)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b8 := ðpb.BeaconBlock{Slot: 8, ParentRoot: r6[:]}
|
||||
r8, _ := ssz.HashTreeRoot(b8)
|
||||
r8, err := ssz.HashTreeRoot(b8)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
st, err := stateTrie.InitializeFromProtoUnsafe(&pb.BeaconState{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -21,13 +21,11 @@ func TestChainService_SaveHead_DataRace(t *testing.T) {
|
||||
beaconDB: db,
|
||||
}
|
||||
go func() {
|
||||
s.saveHead(
|
||||
context.Background(),
|
||||
[32]byte{},
|
||||
)
|
||||
if err := s.saveHead(context.Background(), [32]byte{}, ); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}()
|
||||
s.saveHead(
|
||||
context.Background(),
|
||||
[32]byte{},
|
||||
)
|
||||
if err := s.saveHead(context.Background(), [32]byte{}, ); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,7 +272,10 @@ func TestChainService_InitializeBeaconChain(t *testing.T) {
|
||||
|
||||
// Set up 10 deposits pre chain start for validators to register
|
||||
count := uint64(10)
|
||||
deposits, _, _ := testutil.DeterministicDepositsAndKeys(count)
|
||||
deposits, _, err := testutil.DeterministicDepositsAndKeys(count)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
trie, _, err := testutil.DepositTrieFromDeposits(deposits)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -282,10 +285,13 @@ func TestChainService_InitializeBeaconChain(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
genState.SetEth1Data(ðpb.Eth1Data{
|
||||
err = genState.SetEth1Data(ðpb.Eth1Data{
|
||||
DepositRoot: hashTreeRoot[:],
|
||||
DepositCount: uint64(len(deposits)),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
genState, err = b.ProcessDeposits(ctx, genState, ðpb.BeaconBlockBody{Deposits: deposits})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -334,7 +340,10 @@ func TestChainService_InitializeChainInfo(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
headRoot, _ := ssz.HashTreeRoot(headBlock.Block)
|
||||
headRoot, err := ssz.HashTreeRoot(headBlock.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.SaveState(ctx, headState, headRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -391,10 +400,15 @@ func TestChainService_SaveHeadNoDB(t *testing.T) {
|
||||
beaconDB: db,
|
||||
}
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 1}}
|
||||
r, _ := ssz.HashTreeRoot(b)
|
||||
r, err := ssz.HashTreeRoot(b)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
state := &pb.BeaconState{}
|
||||
newState, err := beaconstate.InitializeFromProto(state)
|
||||
s.beaconDB.SaveState(ctx, newState, r)
|
||||
if err := s.beaconDB.SaveState(ctx, newState, r); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.saveHeadNoDB(ctx, b, r); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -467,9 +481,15 @@ func TestHasBlock_ForkChoiceAndDB(t *testing.T) {
|
||||
beaconDB: db,
|
||||
}
|
||||
block := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{}}}
|
||||
r, _ := ssz.HashTreeRoot(block.Block)
|
||||
r, err := ssz.HashTreeRoot(block.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
bs := &pb.BeaconState{FinalizedCheckpoint: ðpb.Checkpoint{}, CurrentJustifiedCheckpoint: ðpb.Checkpoint{}}
|
||||
state, _ := beaconstate.InitializeFromProto(bs)
|
||||
state, err := beaconstate.InitializeFromProto(bs)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.insertBlockToForkChoiceStore(ctx, block.Block, r, state); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -494,7 +514,10 @@ func BenchmarkHasBlockDB(b *testing.B) {
|
||||
if err := s.beaconDB.SaveBlock(ctx, block); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
r, _ := ssz.HashTreeRoot(block.Block)
|
||||
r, err := ssz.HashTreeRoot(block.Block)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
@@ -514,9 +537,15 @@ func BenchmarkHasBlockForkChoiceStore(b *testing.B) {
|
||||
beaconDB: db,
|
||||
}
|
||||
block := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{}}}
|
||||
r, _ := ssz.HashTreeRoot(block.Block)
|
||||
r, err := ssz.HashTreeRoot(block.Block)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
bs := &pb.BeaconState{FinalizedCheckpoint: ðpb.Checkpoint{}, CurrentJustifiedCheckpoint: ðpb.Checkpoint{}}
|
||||
state, _ := beaconstate.InitializeFromProto(bs)
|
||||
state, err := beaconstate.InitializeFromProto(bs)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
if err := s.insertBlockToForkChoiceStore(ctx, block.Block, r, state); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
7
beacon-chain/cache/committee_test.go
vendored
7
beacon-chain/cache/committee_test.go
vendored
@@ -177,14 +177,17 @@ func TestCommitteeCache_CanRotate(t *testing.T) {
|
||||
func TestCommitteeCacheOutOfRange(t *testing.T) {
|
||||
cache := NewCommitteesCache()
|
||||
seed := bytesutil.ToBytes32([]byte("foo"))
|
||||
cache.CommitteeCache.Add(&Committees{
|
||||
err := cache.CommitteeCache.Add(&Committees{
|
||||
CommitteeCount: 1,
|
||||
Seed: seed,
|
||||
ShuffledIndices: []uint64{0},
|
||||
SortedIndices: []uint64{},
|
||||
ProposerIndices: []uint64{},
|
||||
})
|
||||
_, err := cache.Committee(0, seed, math.MaxUint64) // Overflow!
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = cache.Committee(0, seed, math.MaxUint64) // Overflow!
|
||||
if err == nil {
|
||||
t.Fatal("Did not fail as expected")
|
||||
}
|
||||
|
||||
7
beacon-chain/cache/eth1_data_test.go
vendored
7
beacon-chain/cache/eth1_data_test.go
vendored
@@ -74,8 +74,11 @@ func TestEth1DataVoteCache_CanIncrement(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, _ = cache.IncrementEth1DataVote(eInfo.Eth1DataHash)
|
||||
count, _ := cache.IncrementEth1DataVote(eInfo.Eth1DataHash)
|
||||
_, err = cache.IncrementEth1DataVote(eInfo.Eth1DataHash)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
count, err := cache.IncrementEth1DataVote(eInfo.Eth1DataHash)
|
||||
|
||||
if count != 58 {
|
||||
t.Errorf(
|
||||
|
||||
@@ -25,8 +25,13 @@ func TestFuzzProcessAttestationNoVerify_10000(t *testing.T) {
|
||||
for i := 0; i < 10000; i++ {
|
||||
fuzzer.Fuzz(state)
|
||||
fuzzer.Fuzz(att)
|
||||
s, _ := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
_, _ = ProcessAttestationNoVerify(ctx, s, att)
|
||||
s, err := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
if _, err = ProcessAttestationNoVerify(ctx, s, att); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,8 +44,13 @@ func TestFuzzProcessBlockHeader_10000(t *testing.T) {
|
||||
fuzzer.Fuzz(state)
|
||||
fuzzer.Fuzz(block)
|
||||
|
||||
s, _ := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
_, _ = ProcessBlockHeader(s, block)
|
||||
s, err := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
if _, err = ProcessBlockHeader(s, block); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,8 +73,12 @@ func TestFuzzverifySigningRoot_10000(t *testing.T) {
|
||||
fuzzer.Fuzz(&s)
|
||||
fuzzer.Fuzz(&d)
|
||||
domain := bytesutil.FromBytes4(domain[:])
|
||||
verifySigningRoot(state, pubkey[:], sig[:], domain)
|
||||
verifySigningRoot(state, p, s, d)
|
||||
if err := verifySigningRoot(state, pubkey[:], sig[:], domain); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
if err := verifySigningRoot(state, p, s, d); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -87,8 +101,12 @@ func TestFuzzverifyDepositDataSigningRoot_10000(t *testing.T) {
|
||||
fuzzer.Fuzz(&s)
|
||||
fuzzer.Fuzz(&d)
|
||||
domain := bytesutil.FromBytes4(domain[:])
|
||||
verifySignature(ba, pubkey[:], sig[:], domain)
|
||||
verifySignature(ba, p, s, d)
|
||||
if err := verifySignature(ba, pubkey[:], sig[:], domain); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
if err := verifySignature(ba, p, s, d); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,10 +144,15 @@ func TestFuzzEth1DataHasEnoughSupport_10000(t *testing.T) {
|
||||
for i := 0; i < 100000; i++ {
|
||||
fuzzer.Fuzz(eth1data)
|
||||
fuzzer.Fuzz(&stateVotes)
|
||||
s, _ := beaconstate.InitializeFromProto(ðereum_beacon_p2p_v1.BeaconState{
|
||||
s, err := beaconstate.InitializeFromProto(ðereum_beacon_p2p_v1.BeaconState{
|
||||
Eth1DataVotes: stateVotes,
|
||||
})
|
||||
Eth1DataHasEnoughSupport(s, eth1data)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
if _, err := Eth1DataHasEnoughSupport(s, eth1data); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -142,8 +165,13 @@ func TestFuzzProcessBlockHeaderNoVerify_10000(t *testing.T) {
|
||||
for i := 0; i < 10000; i++ {
|
||||
fuzzer.Fuzz(state)
|
||||
fuzzer.Fuzz(block)
|
||||
s, _ := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
_, _ = ProcessBlockHeaderNoVerify(s, block)
|
||||
s, err := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
if _, err = ProcessBlockHeaderNoVerify(s, block); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,7 +183,10 @@ func TestFuzzProcessRandao_10000(t *testing.T) {
|
||||
for i := 0; i < 10000; i++ {
|
||||
fuzzer.Fuzz(state)
|
||||
fuzzer.Fuzz(blockBody)
|
||||
s, _ := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
s, err := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
r, err := ProcessRandao(s, blockBody)
|
||||
if err != nil && r != nil {
|
||||
t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, blockBody)
|
||||
@@ -171,7 +202,10 @@ func TestFuzzProcessRandaoNoVerify_10000(t *testing.T) {
|
||||
for i := 0; i < 10000; i++ {
|
||||
fuzzer.Fuzz(state)
|
||||
fuzzer.Fuzz(blockBody)
|
||||
s, _ := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
s, err := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
r, err := ProcessRandaoNoVerify(s, blockBody)
|
||||
if err != nil && r != nil {
|
||||
t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, blockBody)
|
||||
@@ -187,7 +221,10 @@ func TestFuzzProcessProposerSlashings_10000(t *testing.T) {
|
||||
for i := 0; i < 10000; i++ {
|
||||
fuzzer.Fuzz(state)
|
||||
fuzzer.Fuzz(blockBody)
|
||||
s, _ := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
s, err := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
r, err := ProcessProposerSlashings(ctx, s, blockBody)
|
||||
if err != nil && r != nil {
|
||||
t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, blockBody)
|
||||
@@ -202,8 +239,13 @@ func TestFuzzVerifyProposerSlashing_10000(t *testing.T) {
|
||||
for i := 0; i < 10000; i++ {
|
||||
fuzzer.Fuzz(state)
|
||||
fuzzer.Fuzz(proposerSlashing)
|
||||
s, _ := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
VerifyProposerSlashing(s, proposerSlashing)
|
||||
s, err := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
if err := VerifyProposerSlashing(s, proposerSlashing); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,7 +257,10 @@ func TestFuzzProcessAttesterSlashings_10000(t *testing.T) {
|
||||
for i := 0; i < 10000; i++ {
|
||||
fuzzer.Fuzz(state)
|
||||
fuzzer.Fuzz(blockBody)
|
||||
s, _ := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
s, err := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
r, err := ProcessAttesterSlashings(ctx, s, blockBody)
|
||||
if err != nil && r != nil {
|
||||
t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, blockBody)
|
||||
@@ -231,8 +276,13 @@ func TestFuzzVerifyAttesterSlashing_10000(t *testing.T) {
|
||||
for i := 0; i < 10000; i++ {
|
||||
fuzzer.Fuzz(state)
|
||||
fuzzer.Fuzz(attesterSlashing)
|
||||
s, _ := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
VerifyAttesterSlashing(ctx, s, attesterSlashing)
|
||||
s, err := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
if err := VerifyAttesterSlashing(ctx, s, attesterSlashing); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,7 +316,10 @@ func TestFuzzProcessAttestations_10000(t *testing.T) {
|
||||
for i := 0; i < 10000; i++ {
|
||||
fuzzer.Fuzz(state)
|
||||
fuzzer.Fuzz(blockBody)
|
||||
s, _ := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
s, err := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
r, err := ProcessAttestations(ctx, s, blockBody)
|
||||
if err != nil && r != nil {
|
||||
t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, blockBody)
|
||||
@@ -282,7 +335,10 @@ func TestFuzzProcessAttestationsNoVerify_10000(t *testing.T) {
|
||||
for i := 0; i < 10000; i++ {
|
||||
fuzzer.Fuzz(state)
|
||||
fuzzer.Fuzz(blockBody)
|
||||
s, _ := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
s, err := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
r, err := ProcessAttestationsNoVerify(ctx, s, blockBody)
|
||||
if err != nil && r != nil {
|
||||
t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, blockBody)
|
||||
@@ -298,7 +354,10 @@ func TestFuzzProcessAttestation_10000(t *testing.T) {
|
||||
for i := 0; i < 10000; i++ {
|
||||
fuzzer.Fuzz(state)
|
||||
fuzzer.Fuzz(attestation)
|
||||
s, _ := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
s, err := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
r, err := ProcessAttestation(ctx, s, attestation)
|
||||
if err != nil && r != nil {
|
||||
t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, attestation)
|
||||
@@ -314,8 +373,13 @@ func TestFuzzVerifyIndexedAttestationn_10000(t *testing.T) {
|
||||
for i := 0; i < 10000; i++ {
|
||||
fuzzer.Fuzz(state)
|
||||
fuzzer.Fuzz(idxAttestation)
|
||||
s, _ := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
VerifyIndexedAttestation(ctx, s, idxAttestation)
|
||||
s, err := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
if err := VerifyIndexedAttestation(ctx, s, idxAttestation); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,8 +391,13 @@ func TestFuzzVerifyAttestation_10000(t *testing.T) {
|
||||
for i := 0; i < 10000; i++ {
|
||||
fuzzer.Fuzz(state)
|
||||
fuzzer.Fuzz(attestation)
|
||||
s, _ := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
VerifyAttestation(ctx, s, attestation)
|
||||
s, err := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
if err := VerifyAttestation(ctx, s, attestation); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,7 +409,10 @@ func TestFuzzProcessDeposits_10000(t *testing.T) {
|
||||
for i := 0; i < 10000; i++ {
|
||||
fuzzer.Fuzz(state)
|
||||
fuzzer.Fuzz(blockBody)
|
||||
s, _ := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
s, err := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
r, err := ProcessDeposits(ctx, s, blockBody)
|
||||
if err != nil && r != nil {
|
||||
t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, blockBody)
|
||||
@@ -357,7 +429,10 @@ func TestFuzzProcessPreGenesisDeposit_10000(t *testing.T) {
|
||||
for i := 0; i < 10000; i++ {
|
||||
fuzzer.Fuzz(state)
|
||||
fuzzer.Fuzz(deposit)
|
||||
s, _ := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
s, err := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
r, err := ProcessPreGenesisDeposit(ctx, s, deposit)
|
||||
if err != nil && r != nil {
|
||||
t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, deposit)
|
||||
@@ -373,7 +448,10 @@ func TestFuzzProcessDeposit_10000(t *testing.T) {
|
||||
for i := 0; i < 10000; i++ {
|
||||
fuzzer.Fuzz(state)
|
||||
fuzzer.Fuzz(deposit)
|
||||
s, _ := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
s, err := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
r, err := ProcessDeposit(s, deposit)
|
||||
if err != nil && r != nil {
|
||||
t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, deposit)
|
||||
@@ -388,8 +466,13 @@ func TestFuzzverifyDeposit_10000(t *testing.T) {
|
||||
for i := 0; i < 10000; i++ {
|
||||
fuzzer.Fuzz(state)
|
||||
fuzzer.Fuzz(deposit)
|
||||
s, _ := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
verifyDeposit(s, deposit)
|
||||
s, err := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
if err := verifyDeposit(s, deposit); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -401,7 +484,10 @@ func TestFuzzProcessVoluntaryExits_10000(t *testing.T) {
|
||||
for i := 0; i < 10000; i++ {
|
||||
fuzzer.Fuzz(state)
|
||||
fuzzer.Fuzz(blockBody)
|
||||
s, _ := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
s, err := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
r, err := ProcessVoluntaryExits(ctx, s, blockBody)
|
||||
if err != nil && r != nil {
|
||||
t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, blockBody)
|
||||
@@ -416,7 +502,10 @@ func TestFuzzProcessVoluntaryExitsNoVerify_10000(t *testing.T) {
|
||||
for i := 0; i < 10000; i++ {
|
||||
fuzzer.Fuzz(state)
|
||||
fuzzer.Fuzz(blockBody)
|
||||
s, _ := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
s, err := beaconstate.InitializeFromProtoUnsafe(state)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
r, err := ProcessVoluntaryExitsNoVerify(s, blockBody)
|
||||
if err != nil && r != nil {
|
||||
t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, blockBody)
|
||||
@@ -436,6 +525,8 @@ func TestFuzzVerifyExit_10000(t *testing.T) {
|
||||
fuzzer.Fuzz(val)
|
||||
fuzzer.Fuzz(fork)
|
||||
fuzzer.Fuzz(&slot)
|
||||
VerifyExit(val, slot, fork, ve)
|
||||
if err := VerifyExit(val, slot, fork, ve); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,9 @@ func init() {
|
||||
|
||||
func TestProcessBlockHeader_WrongProposerSig(t *testing.T) {
|
||||
beaconState, privKeys := testutil.DeterministicGenesisState(t, 100)
|
||||
beaconState.SetLatestBlockHeader(ðpb.BeaconBlockHeader{Slot: 9})
|
||||
if err := beaconState.SetLatestBlockHeader(ðpb.BeaconBlockHeader{Slot: 9}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
lbhsr, err := ssz.HashTreeRoot(beaconState.LatestBlockHeader())
|
||||
if err != nil {
|
||||
@@ -67,7 +69,7 @@ func TestProcessBlockHeader_WrongProposerSig(t *testing.T) {
|
||||
|
||||
_, err = blocks.ProcessBlockHeader(beaconState, block)
|
||||
want := "signature did not verify"
|
||||
if !strings.Contains(err.Error(), want) {
|
||||
if err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected %v, received %v", want, err)
|
||||
}
|
||||
|
||||
@@ -82,7 +84,7 @@ func TestProcessBlockHeader_DifferentSlots(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
state, _ := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
state, err := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: validators,
|
||||
Slot: 0,
|
||||
LatestBlockHeader: ðpb.BeaconBlockHeader{Slot: 9},
|
||||
@@ -92,6 +94,9 @@ func TestProcessBlockHeader_DifferentSlots(t *testing.T) {
|
||||
},
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
lbhsr, err := ssz.HashTreeRoot(state.LatestBlockHeader())
|
||||
if err != nil {
|
||||
@@ -118,7 +123,7 @@ func TestProcessBlockHeader_DifferentSlots(t *testing.T) {
|
||||
|
||||
_, err = blocks.ProcessBlockHeader(state, block)
|
||||
want := "is different then block slot"
|
||||
if !strings.Contains(err.Error(), want) {
|
||||
if err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected %v, received %v", want, err)
|
||||
}
|
||||
}
|
||||
@@ -132,7 +137,7 @@ func TestProcessBlockHeader_PreviousBlockRootNotSignedRoot(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
state, _ := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
state, err := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: validators,
|
||||
Slot: 0,
|
||||
LatestBlockHeader: ðpb.BeaconBlockHeader{Slot: 9},
|
||||
@@ -142,6 +147,9 @@ func TestProcessBlockHeader_PreviousBlockRootNotSignedRoot(t *testing.T) {
|
||||
},
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
currentEpoch := helpers.CurrentEpoch(state)
|
||||
dt, err := helpers.Domain(state.Fork(), currentEpoch, params.BeaconConfig().DomainBeaconProposer)
|
||||
@@ -164,7 +172,7 @@ func TestProcessBlockHeader_PreviousBlockRootNotSignedRoot(t *testing.T) {
|
||||
|
||||
_, err = blocks.ProcessBlockHeader(state, block)
|
||||
want := "does not match"
|
||||
if !strings.Contains(err.Error(), want) {
|
||||
if err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected %v, received %v", want, err)
|
||||
}
|
||||
}
|
||||
@@ -178,7 +186,7 @@ func TestProcessBlockHeader_SlashedProposer(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
state, _ := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
state, err := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: validators,
|
||||
Slot: 0,
|
||||
LatestBlockHeader: ðpb.BeaconBlockHeader{Slot: 9},
|
||||
@@ -188,6 +196,9 @@ func TestProcessBlockHeader_SlashedProposer(t *testing.T) {
|
||||
},
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
parentRoot, err := ssz.HashTreeRoot(state.LatestBlockHeader())
|
||||
if err != nil {
|
||||
@@ -214,7 +225,7 @@ func TestProcessBlockHeader_SlashedProposer(t *testing.T) {
|
||||
|
||||
_, err = blocks.ProcessBlockHeader(state, block)
|
||||
want := "was previously slashed"
|
||||
if !strings.Contains(err.Error(), want) {
|
||||
if err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected %v, received %v", want, err)
|
||||
}
|
||||
}
|
||||
@@ -228,7 +239,7 @@ func TestProcessBlockHeader_OK(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
state, _ := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
state, err := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: validators,
|
||||
Slot: 0,
|
||||
LatestBlockHeader: ðpb.BeaconBlockHeader{Slot: 9},
|
||||
@@ -238,6 +249,9 @@ func TestProcessBlockHeader_OK(t *testing.T) {
|
||||
},
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
latestBlockSignedRoot, err := ssz.HashTreeRoot(state.LatestBlockHeader())
|
||||
if err != nil {
|
||||
@@ -323,7 +337,7 @@ func TestProcessRandao_IncorrectProposerFailsVerification(t *testing.T) {
|
||||
if _, err := blocks.ProcessRandao(
|
||||
beaconState,
|
||||
block.Body,
|
||||
); !strings.Contains(err.Error(), want) {
|
||||
); err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected %v, received %v", want, err)
|
||||
}
|
||||
}
|
||||
@@ -362,9 +376,12 @@ func TestProcessRandao_SignatureVerifiesAndUpdatesLatestStateMixes(t *testing.T)
|
||||
}
|
||||
|
||||
func TestProcessEth1Data_SetsCorrectly(t *testing.T) {
|
||||
beaconState, _ := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
beaconState, err := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
Eth1DataVotes: []*ethpb.Eth1Data{},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
block := ðpb.BeaconBlock{
|
||||
Body: ðpb.BeaconBlockBody{
|
||||
@@ -374,7 +391,6 @@ func TestProcessEth1Data_SetsCorrectly(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
var err error
|
||||
for i := uint64(0); i < params.BeaconConfig().SlotsPerEth1VotingPeriod; i++ {
|
||||
beaconState, err = blocks.ProcessEth1DataInBlock(beaconState, block)
|
||||
if err != nil {
|
||||
@@ -412,7 +428,9 @@ func TestProcessProposerSlashings_UnmatchedHeaderSlots(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
beaconState.SetSlot(currentSlot)
|
||||
if err := beaconState.SetSlot(currentSlot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
block := ðpb.BeaconBlock{
|
||||
Body: ðpb.BeaconBlockBody{
|
||||
@@ -420,7 +438,8 @@ func TestProcessProposerSlashings_UnmatchedHeaderSlots(t *testing.T) {
|
||||
},
|
||||
}
|
||||
want := "mismatched header slots"
|
||||
if _, err := blocks.ProcessProposerSlashings(context.Background(), beaconState, block.Body); !strings.Contains(err.Error(), want) {
|
||||
_, err := blocks.ProcessProposerSlashings(context.Background(), beaconState, block.Body)
|
||||
if err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected %s, received %v", want, err)
|
||||
}
|
||||
}
|
||||
@@ -444,14 +463,17 @@ func TestProcessProposerSlashings_SameHeaders(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
beaconState.SetSlot(currentSlot)
|
||||
if err := beaconState.SetSlot(currentSlot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
block := ðpb.BeaconBlock{
|
||||
Body: ðpb.BeaconBlockBody{
|
||||
ProposerSlashings: slashings,
|
||||
},
|
||||
}
|
||||
want := "expected slashing headers to differ"
|
||||
if _, err := blocks.ProcessProposerSlashings(context.Background(), beaconState, block.Body); !strings.Contains(err.Error(), want) {
|
||||
_, err := blocks.ProcessProposerSlashings(context.Background(), beaconState, block.Body)
|
||||
if err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected %s, received %v", want, err)
|
||||
}
|
||||
}
|
||||
@@ -484,10 +506,13 @@ func TestProcessProposerSlashings_ValidatorNotSlashable(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
beaconState, _ := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
beaconState, err := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: registry,
|
||||
Slot: currentSlot,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
block := ðpb.BeaconBlock{
|
||||
Body: ðpb.BeaconBlockBody{
|
||||
ProposerSlashings: slashings,
|
||||
@@ -498,7 +523,8 @@ func TestProcessProposerSlashings_ValidatorNotSlashable(t *testing.T) {
|
||||
beaconState.Validators()[0].PublicKey,
|
||||
)
|
||||
|
||||
if _, err := blocks.ProcessProposerSlashings(context.Background(), beaconState, block.Body); !strings.Contains(err.Error(), want) {
|
||||
_, err = blocks.ProcessProposerSlashings(context.Background(), beaconState, block.Body)
|
||||
if err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected %s, received %v", want, err)
|
||||
}
|
||||
}
|
||||
@@ -603,10 +629,13 @@ func TestProcessAttesterSlashings_DataNotSlashable(t *testing.T) {
|
||||
registry := []*ethpb.Validator{}
|
||||
currentSlot := uint64(0)
|
||||
|
||||
beaconState, _ := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
beaconState, err := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: registry,
|
||||
Slot: currentSlot,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
block := ðpb.BeaconBlock{
|
||||
Body: ðpb.BeaconBlockBody{
|
||||
AttesterSlashings: slashings,
|
||||
@@ -614,7 +643,8 @@ func TestProcessAttesterSlashings_DataNotSlashable(t *testing.T) {
|
||||
}
|
||||
want := fmt.Sprint("attestations are not slashable")
|
||||
|
||||
if _, err := blocks.ProcessAttesterSlashings(context.Background(), beaconState, block.Body); !strings.Contains(err.Error(), want) {
|
||||
_, err = blocks.ProcessAttesterSlashings(context.Background(), beaconState, block.Body)
|
||||
if err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected %s, received %v", want, err)
|
||||
}
|
||||
}
|
||||
@@ -623,10 +653,13 @@ func TestProcessAttesterSlashings_IndexedAttestationFailedToVerify(t *testing.T)
|
||||
registry := []*ethpb.Validator{}
|
||||
currentSlot := uint64(0)
|
||||
|
||||
beaconState, _ := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
beaconState, err := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: registry,
|
||||
Slot: currentSlot,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
slashings := []*ethpb.AttesterSlashing{
|
||||
{
|
||||
@@ -654,7 +687,8 @@ func TestProcessAttesterSlashings_IndexedAttestationFailedToVerify(t *testing.T)
|
||||
}
|
||||
|
||||
want := fmt.Sprint("validator indices count exceeds MAX_VALIDATORS_PER_COMMITTEE")
|
||||
if _, err := blocks.ProcessAttesterSlashings(context.Background(), beaconState, block.Body); !strings.Contains(err.Error(), want) {
|
||||
_, err = blocks.ProcessAttesterSlashings(context.Background(), beaconState, block.Body)
|
||||
if err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected %s, received %v", want, err)
|
||||
}
|
||||
}
|
||||
@@ -709,7 +743,9 @@ func TestProcessAttesterSlashings_AppliesCorrectStatus(t *testing.T) {
|
||||
}
|
||||
|
||||
currentSlot := 2 * params.BeaconConfig().SlotsPerEpoch
|
||||
beaconState.SetSlot(currentSlot)
|
||||
if err := beaconState.SetSlot(currentSlot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
block := ðpb.BeaconBlock{
|
||||
Body: ðpb.BeaconBlockBody{
|
||||
@@ -759,7 +795,8 @@ func TestProcessAttestations_InclusionDelayFailure(t *testing.T) {
|
||||
params.BeaconConfig().MinAttestationInclusionDelay,
|
||||
beaconState.Slot(),
|
||||
)
|
||||
if _, err := blocks.ProcessAttestations(context.Background(), beaconState, block.Body); !strings.Contains(err.Error(), want) {
|
||||
_, err := blocks.ProcessAttestations(context.Background(), beaconState, block.Body)
|
||||
if err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected %s, received %v", want, err)
|
||||
}
|
||||
}
|
||||
@@ -776,11 +813,18 @@ func TestProcessAttestations_NeitherCurrentNorPrevEpoch(t *testing.T) {
|
||||
},
|
||||
}
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 100)
|
||||
beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().SlotsPerEpoch*4 + params.BeaconConfig().MinAttestationInclusionDelay)
|
||||
err := beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().SlotsPerEpoch*4 + params.BeaconConfig().MinAttestationInclusionDelay)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
pfc := beaconState.PreviousJustifiedCheckpoint()
|
||||
pfc.Root = []byte("hello-world")
|
||||
beaconState.SetPreviousJustifiedCheckpoint(pfc)
|
||||
beaconState.SetPreviousEpochAttestations([]*pb.PendingAttestation{})
|
||||
if err := beaconState.SetPreviousJustifiedCheckpoint(pfc); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := beaconState.SetPreviousEpochAttestations([]*pb.PendingAttestation{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
want := fmt.Sprintf(
|
||||
"expected target epoch (%d) to be the previous epoch (%d) or the current epoch (%d)",
|
||||
@@ -788,7 +832,8 @@ func TestProcessAttestations_NeitherCurrentNorPrevEpoch(t *testing.T) {
|
||||
helpers.PrevEpoch(beaconState),
|
||||
helpers.CurrentEpoch(beaconState),
|
||||
)
|
||||
if _, err := blocks.ProcessAttestations(context.Background(), beaconState, block.Body); !strings.Contains(err.Error(), want) {
|
||||
_, err = blocks.ProcessAttestations(context.Background(), beaconState, block.Body)
|
||||
if err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected %s, received %v", want, err)
|
||||
}
|
||||
}
|
||||
@@ -810,18 +855,25 @@ func TestProcessAttestations_CurrentEpochFFGDataMismatches(t *testing.T) {
|
||||
},
|
||||
}
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 100)
|
||||
beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().MinAttestationInclusionDelay)
|
||||
if err := beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().MinAttestationInclusionDelay); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cfc := beaconState.CurrentJustifiedCheckpoint()
|
||||
cfc.Root = []byte("hello-world")
|
||||
beaconState.SetCurrentJustifiedCheckpoint(cfc)
|
||||
beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{})
|
||||
if err := beaconState.SetCurrentJustifiedCheckpoint(cfc); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
want := fmt.Sprintf(
|
||||
"expected source epoch %d, received %d",
|
||||
helpers.CurrentEpoch(beaconState),
|
||||
attestations[0].Data.Source.Epoch,
|
||||
)
|
||||
if _, err := blocks.ProcessAttestations(context.Background(), beaconState, block.Body); !strings.Contains(err.Error(), want) {
|
||||
_, err := blocks.ProcessAttestations(context.Background(), beaconState, block.Body)
|
||||
if err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected %s, received %v", want, err)
|
||||
}
|
||||
|
||||
@@ -833,7 +885,8 @@ func TestProcessAttestations_CurrentEpochFFGDataMismatches(t *testing.T) {
|
||||
beaconState.CurrentJustifiedCheckpoint().Root,
|
||||
attestations[0].Data.Source.Root,
|
||||
)
|
||||
if _, err := blocks.ProcessAttestations(context.Background(), beaconState, block.Body); !strings.Contains(err.Error(), want) {
|
||||
_, err = blocks.ProcessAttestations(context.Background(), beaconState, block.Body)
|
||||
if err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected %s, received %v", want, err)
|
||||
}
|
||||
}
|
||||
@@ -859,18 +912,26 @@ func TestProcessAttestations_PrevEpochFFGDataMismatches(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().SlotsPerEpoch + params.BeaconConfig().MinAttestationInclusionDelay)
|
||||
err := beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().SlotsPerEpoch + params.BeaconConfig().MinAttestationInclusionDelay)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
pfc := beaconState.PreviousJustifiedCheckpoint()
|
||||
pfc.Root = []byte("hello-world")
|
||||
beaconState.SetPreviousJustifiedCheckpoint(pfc)
|
||||
beaconState.SetPreviousEpochAttestations([]*pb.PendingAttestation{})
|
||||
if err := beaconState.SetPreviousJustifiedCheckpoint(pfc); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := beaconState.SetPreviousEpochAttestations([]*pb.PendingAttestation{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
want := fmt.Sprintf(
|
||||
"expected source epoch %d, received %d",
|
||||
helpers.PrevEpoch(beaconState),
|
||||
attestations[0].Data.Source.Epoch,
|
||||
)
|
||||
if _, err := blocks.ProcessAttestations(context.Background(), beaconState, block.Body); !strings.Contains(err.Error(), want) {
|
||||
_, err = blocks.ProcessAttestations(context.Background(), beaconState, block.Body)
|
||||
if err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected %s, received %v", want, err)
|
||||
}
|
||||
|
||||
@@ -883,7 +944,8 @@ func TestProcessAttestations_PrevEpochFFGDataMismatches(t *testing.T) {
|
||||
beaconState.CurrentJustifiedCheckpoint().Root,
|
||||
attestations[0].Data.Source.Root,
|
||||
)
|
||||
if _, err := blocks.ProcessAttestations(context.Background(), beaconState, block.Body); !strings.Contains(err.Error(), want) {
|
||||
_, err = blocks.ProcessAttestations(context.Background(), beaconState, block.Body)
|
||||
if err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected %s, received %v", want, err)
|
||||
}
|
||||
}
|
||||
@@ -905,16 +967,23 @@ func TestProcessAttestations_InvalidAggregationBitsLength(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().MinAttestationInclusionDelay)
|
||||
err := beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().MinAttestationInclusionDelay)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cfc := beaconState.CurrentJustifiedCheckpoint()
|
||||
cfc.Root = []byte("hello-world")
|
||||
beaconState.SetCurrentJustifiedCheckpoint(cfc)
|
||||
beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{})
|
||||
if err := beaconState.SetCurrentJustifiedCheckpoint(cfc); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
expected := "failed to verify aggregation bitfield: wanted participants bitfield length 3, got: 4"
|
||||
_, err := blocks.ProcessAttestations(context.Background(), beaconState, block.Body)
|
||||
if !strings.Contains(err.Error(), expected) {
|
||||
_, err = blocks.ProcessAttestations(context.Background(), beaconState, block.Body)
|
||||
if err == nil || !strings.Contains(err.Error(), expected) {
|
||||
t.Errorf("Did not receive wanted error")
|
||||
}
|
||||
}
|
||||
@@ -936,8 +1005,12 @@ func TestProcessAttestations_OK(t *testing.T) {
|
||||
|
||||
cfc := beaconState.CurrentJustifiedCheckpoint()
|
||||
cfc.Root = mockRoot[:]
|
||||
beaconState.SetCurrentJustifiedCheckpoint(cfc)
|
||||
beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{})
|
||||
if err := beaconState.SetCurrentJustifiedCheckpoint(cfc); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
committee, err := helpers.BeaconCommitteeFromState(beaconState, att.Data.Slot, att.Data.CommitteeIndex)
|
||||
if err != nil {
|
||||
@@ -968,7 +1041,10 @@ func TestProcessAttestations_OK(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().MinAttestationInclusionDelay)
|
||||
err = beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().MinAttestationInclusionDelay)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if _, err := blocks.ProcessAttestations(context.Background(), beaconState, block.Body); err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
@@ -997,8 +1073,12 @@ func TestProcessAggregatedAttestation_OverlappingBits(t *testing.T) {
|
||||
|
||||
cfc := beaconState.CurrentJustifiedCheckpoint()
|
||||
cfc.Root = []byte("hello-world")
|
||||
beaconState.SetCurrentJustifiedCheckpoint(cfc)
|
||||
beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{})
|
||||
if err := beaconState.SetCurrentJustifiedCheckpoint(cfc); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
committee, err := helpers.BeaconCommitteeFromState(beaconState, att1.Data.Slot, att1.Data.CommitteeIndex)
|
||||
if err != nil {
|
||||
@@ -1075,8 +1155,12 @@ func TestProcessAggregatedAttestation_NoOverlappingBits(t *testing.T) {
|
||||
|
||||
cfc := beaconState.CurrentJustifiedCheckpoint()
|
||||
cfc.Root = mockRoot[:]
|
||||
beaconState.SetCurrentJustifiedCheckpoint(cfc)
|
||||
beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{})
|
||||
if err := beaconState.SetCurrentJustifiedCheckpoint(cfc); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
committee, err := helpers.BeaconCommitteeFromState(beaconState, att1.Data.Slot, att1.Data.CommitteeIndex)
|
||||
if err != nil {
|
||||
@@ -1134,7 +1218,10 @@ func TestProcessAggregatedAttestation_NoOverlappingBits(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().MinAttestationInclusionDelay)
|
||||
err = beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().MinAttestationInclusionDelay)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if _, err := blocks.ProcessAttestations(context.Background(), beaconState, block.Body); err != nil {
|
||||
t.Error(err)
|
||||
@@ -1151,7 +1238,8 @@ func TestProcessAttestationsNoVerify_IncorrectSlotTargetEpoch(t *testing.T) {
|
||||
},
|
||||
}
|
||||
wanted := fmt.Sprintf("data slot is not in the same epoch as target %d != %d", helpers.SlotToEpoch(att.Data.Slot), att.Data.Target.Epoch)
|
||||
if _, err := blocks.ProcessAttestationNoVerify(context.TODO(), beaconState, att); err.Error() != wanted {
|
||||
_, err := blocks.ProcessAttestationNoVerify(context.TODO(), beaconState, att)
|
||||
if err == nil || err.Error() != wanted {
|
||||
t.Error("Did not get wanted error")
|
||||
}
|
||||
}
|
||||
@@ -1176,11 +1264,18 @@ func TestProcessAttestationsNoVerify_OK(t *testing.T) {
|
||||
zeroSig := [96]byte{}
|
||||
att.Signature = zeroSig[:]
|
||||
|
||||
beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().MinAttestationInclusionDelay)
|
||||
err := beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().MinAttestationInclusionDelay)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ckp := beaconState.CurrentJustifiedCheckpoint()
|
||||
copy(ckp.Root, "hello-world")
|
||||
beaconState.SetCurrentJustifiedCheckpoint(ckp)
|
||||
beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{})
|
||||
if err := beaconState.SetCurrentJustifiedCheckpoint(ckp); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if _, err := blocks.ProcessAttestationNoVerify(context.TODO(), beaconState, att); err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
@@ -1196,11 +1291,14 @@ func TestConvertToIndexed_OK(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
state, _ := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
state, err := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
Slot: 5,
|
||||
Validators: validators,
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tests := []struct {
|
||||
aggregationBitfield bitfield.Bitlist
|
||||
wantedAttestingIndices []uint64
|
||||
@@ -1252,7 +1350,10 @@ func TestConvertToIndexed_OK(t *testing.T) {
|
||||
func TestVerifyIndexedAttestation_OK(t *testing.T) {
|
||||
numOfValidators := 4 * params.BeaconConfig().SlotsPerEpoch
|
||||
validators := make([]*ethpb.Validator, numOfValidators)
|
||||
_, keys, _ := testutil.DeterministicDepositsAndKeys(numOfValidators)
|
||||
_, keys, err := testutil.DeterministicDepositsAndKeys(numOfValidators)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for i := 0; i < len(validators); i++ {
|
||||
validators[i] = ðpb.Validator{
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
@@ -1260,7 +1361,7 @@ func TestVerifyIndexedAttestation_OK(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
state, _ := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
state, err := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
Slot: 5,
|
||||
Validators: validators,
|
||||
Fork: &pb.Fork{
|
||||
@@ -1270,6 +1371,9 @@ func TestVerifyIndexedAttestation_OK(t *testing.T) {
|
||||
},
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tests := []struct {
|
||||
attestation *ethpb.IndexedAttestation
|
||||
}{
|
||||
@@ -1349,7 +1453,8 @@ func TestValidateIndexedAttestation_AboveMaxLength(t *testing.T) {
|
||||
}
|
||||
|
||||
want := "validator indices count exceeds MAX_VALIDATORS_PER_COMMITTEE"
|
||||
if err := blocks.VerifyIndexedAttestation(context.Background(), &stateTrie.BeaconState{}, indexedAtt1); !strings.Contains(err.Error(), want) {
|
||||
err := blocks.VerifyIndexedAttestation(context.Background(), &stateTrie.BeaconState{}, indexedAtt1)
|
||||
if err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected verification to fail return false, received: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -1357,7 +1462,10 @@ func TestValidateIndexedAttestation_AboveMaxLength(t *testing.T) {
|
||||
func TestProcessDeposits_SameValidatorMultipleDepositsSameBlock(t *testing.T) {
|
||||
// Same validator created 3 valid deposits within the same block
|
||||
testutil.ResetCache()
|
||||
dep, _, _ := testutil.DeterministicDepositsAndKeysSameValidator(3)
|
||||
dep, _, err := testutil.DeterministicDepositsAndKeysSameValidator(3)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
eth1Data, err := testutil.DeterministicEth1Data(len(dep))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -1375,7 +1483,7 @@ func TestProcessDeposits_SameValidatorMultipleDepositsSameBlock(t *testing.T) {
|
||||
},
|
||||
}
|
||||
balances := []uint64{0}
|
||||
beaconState, _ := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
beaconState, err := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: registry,
|
||||
Balances: balances,
|
||||
Eth1Data: eth1Data,
|
||||
@@ -1384,6 +1492,9 @@ func TestProcessDeposits_SameValidatorMultipleDepositsSameBlock(t *testing.T) {
|
||||
CurrentVersion: params.BeaconConfig().GenesisForkVersion,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
newState, err := blocks.ProcessDeposits(context.Background(), beaconState, block.Body)
|
||||
if err != nil {
|
||||
t.Fatalf("Expected block deposits to process correctly, received: %v", err)
|
||||
@@ -1422,20 +1533,27 @@ func TestProcessDeposits_MerkleBranchFailsVerification(t *testing.T) {
|
||||
Deposits: []*ethpb.Deposit{deposit},
|
||||
},
|
||||
}
|
||||
beaconState, _ := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
beaconState, err := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
DepositRoot: []byte{0},
|
||||
BlockHash: []byte{1},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := "deposit root did not verify"
|
||||
if _, err := blocks.ProcessDeposits(context.Background(), beaconState, block.Body); !strings.Contains(err.Error(), want) {
|
||||
_, err = blocks.ProcessDeposits(context.Background(), beaconState, block.Body)
|
||||
if err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected error: %s, received %v", want, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcessDeposits_AddsNewValidatorDeposit(t *testing.T) {
|
||||
dep, _, _ := testutil.DeterministicDepositsAndKeys(1)
|
||||
dep, _, err := testutil.DeterministicDepositsAndKeys(1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
eth1Data, err := testutil.DeterministicEth1Data(len(dep))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -1453,7 +1571,7 @@ func TestProcessDeposits_AddsNewValidatorDeposit(t *testing.T) {
|
||||
},
|
||||
}
|
||||
balances := []uint64{0}
|
||||
beaconState, _ := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
beaconState, err := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: registry,
|
||||
Balances: balances,
|
||||
Eth1Data: eth1Data,
|
||||
@@ -1462,6 +1580,9 @@ func TestProcessDeposits_AddsNewValidatorDeposit(t *testing.T) {
|
||||
CurrentVersion: params.BeaconConfig().GenesisForkVersion,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
newState, err := blocks.ProcessDeposits(context.Background(), beaconState, block.Body)
|
||||
if err != nil {
|
||||
t.Fatalf("Expected block deposits to process correctly, received: %v", err)
|
||||
@@ -1521,7 +1642,7 @@ func TestProcessDeposits_RepeatedDeposit_IncreasesValidatorBalance(t *testing.T)
|
||||
}
|
||||
balances := []uint64{0, 50}
|
||||
root := depositTrie.Root()
|
||||
beaconState, _ := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
beaconState, err := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: registry,
|
||||
Balances: balances,
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
@@ -1529,6 +1650,9 @@ func TestProcessDeposits_RepeatedDeposit_IncreasesValidatorBalance(t *testing.T)
|
||||
BlockHash: root[:],
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
newState, err := blocks.ProcessDeposits(context.Background(), beaconState, block.Body)
|
||||
if err != nil {
|
||||
t.Fatalf("Process deposit failed: %v", err)
|
||||
@@ -1540,7 +1664,10 @@ func TestProcessDeposits_RepeatedDeposit_IncreasesValidatorBalance(t *testing.T)
|
||||
|
||||
func TestProcessDeposit_AddsNewValidatorDeposit(t *testing.T) {
|
||||
//Similar to TestProcessDeposits_AddsNewValidatorDeposit except that this test directly calls ProcessDeposit
|
||||
dep, _, _ := testutil.DeterministicDepositsAndKeys(1)
|
||||
dep, _, err := testutil.DeterministicDepositsAndKeys(1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
eth1Data, err := testutil.DeterministicEth1Data(len(dep))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -1553,7 +1680,7 @@ func TestProcessDeposit_AddsNewValidatorDeposit(t *testing.T) {
|
||||
},
|
||||
}
|
||||
balances := []uint64{0}
|
||||
beaconState, _ := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
beaconState, err := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: registry,
|
||||
Balances: balances,
|
||||
Eth1Data: eth1Data,
|
||||
@@ -1562,6 +1689,9 @@ func TestProcessDeposit_AddsNewValidatorDeposit(t *testing.T) {
|
||||
CurrentVersion: params.BeaconConfig().GenesisForkVersion,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
newState, err := blocks.ProcessDeposit(
|
||||
beaconState,
|
||||
dep[0],
|
||||
@@ -1586,7 +1716,10 @@ func TestProcessDeposit_AddsNewValidatorDeposit(t *testing.T) {
|
||||
|
||||
func TestProcessDeposit_SkipsInvalidDeposit(t *testing.T) {
|
||||
// Same test settings as in TestProcessDeposit_AddsNewValidatorDeposit, except that we use an invalid signature
|
||||
dep, _, _ := testutil.DeterministicDepositsAndKeys(1)
|
||||
dep, _, err := testutil.DeterministicDepositsAndKeys(1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dep[0].Data.Signature = make([]byte, 96)
|
||||
trie, _, err := testutil.DepositTrieFromDeposits(dep)
|
||||
if err != nil {
|
||||
@@ -1604,7 +1737,7 @@ func TestProcessDeposit_SkipsInvalidDeposit(t *testing.T) {
|
||||
},
|
||||
}
|
||||
balances := []uint64{0}
|
||||
beaconState, _ := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
beaconState, err := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: registry,
|
||||
Balances: balances,
|
||||
Eth1Data: eth1Data,
|
||||
@@ -1613,6 +1746,9 @@ func TestProcessDeposit_SkipsInvalidDeposit(t *testing.T) {
|
||||
CurrentVersion: params.BeaconConfig().GenesisForkVersion,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
newState, err := blocks.ProcessDeposit(
|
||||
beaconState,
|
||||
dep[0],
|
||||
@@ -1651,9 +1787,12 @@ func TestProcessVoluntaryExits_ValidatorNotActive(t *testing.T) {
|
||||
ExitEpoch: 0,
|
||||
},
|
||||
}
|
||||
state, _ := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
state, err := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: registry,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
block := ðpb.BeaconBlock{
|
||||
Body: ðpb.BeaconBlockBody{
|
||||
VoluntaryExits: exits,
|
||||
@@ -1662,7 +1801,8 @@ func TestProcessVoluntaryExits_ValidatorNotActive(t *testing.T) {
|
||||
|
||||
want := "non-active validator cannot exit"
|
||||
|
||||
if _, err := blocks.ProcessVoluntaryExits(context.Background(), state, block.Body); !strings.Contains(err.Error(), want) {
|
||||
_, err = blocks.ProcessVoluntaryExits(context.Background(), state, block.Body)
|
||||
if err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected %s, received %v", want, err)
|
||||
}
|
||||
}
|
||||
@@ -1680,10 +1820,13 @@ func TestProcessVoluntaryExits_InvalidExitEpoch(t *testing.T) {
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
},
|
||||
}
|
||||
state, _ := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
state, err := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: registry,
|
||||
Slot: 0,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
block := ðpb.BeaconBlock{
|
||||
Body: ðpb.BeaconBlockBody{
|
||||
VoluntaryExits: exits,
|
||||
@@ -1692,7 +1835,8 @@ func TestProcessVoluntaryExits_InvalidExitEpoch(t *testing.T) {
|
||||
|
||||
want := "expected current epoch >= exit epoch"
|
||||
|
||||
if _, err := blocks.ProcessVoluntaryExits(context.Background(), state, block.Body); !strings.Contains(err.Error(), want) {
|
||||
_, err = blocks.ProcessVoluntaryExits(context.Background(), state, block.Body)
|
||||
if err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected %s, received %v", want, err)
|
||||
}
|
||||
}
|
||||
@@ -1711,10 +1855,13 @@ func TestProcessVoluntaryExits_NotActiveLongEnoughToExit(t *testing.T) {
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
},
|
||||
}
|
||||
state, _ := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
state, err := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: registry,
|
||||
Slot: 10,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
block := ðpb.BeaconBlock{
|
||||
Body: ðpb.BeaconBlockBody{
|
||||
VoluntaryExits: exits,
|
||||
@@ -1722,7 +1869,8 @@ func TestProcessVoluntaryExits_NotActiveLongEnoughToExit(t *testing.T) {
|
||||
}
|
||||
|
||||
want := "validator has not been active long enough to exit"
|
||||
if _, err := blocks.ProcessVoluntaryExits(context.Background(), state, block.Body); !strings.Contains(err.Error(), want) {
|
||||
_, err = blocks.ProcessVoluntaryExits(context.Background(), state, block.Body)
|
||||
if err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected %s, received %v", want, err)
|
||||
}
|
||||
}
|
||||
@@ -1742,7 +1890,7 @@ func TestProcessVoluntaryExits_AppliesCorrectStatus(t *testing.T) {
|
||||
ActivationEpoch: 0,
|
||||
},
|
||||
}
|
||||
state, _ := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
state, err := stateTrie.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: registry,
|
||||
Fork: &pb.Fork{
|
||||
CurrentVersion: params.BeaconConfig().GenesisForkVersion,
|
||||
@@ -1750,7 +1898,13 @@ func TestProcessVoluntaryExits_AppliesCorrectStatus(t *testing.T) {
|
||||
},
|
||||
Slot: params.BeaconConfig().SlotsPerEpoch * 5,
|
||||
})
|
||||
state.SetSlot(state.Slot() + (params.BeaconConfig().PersistentCommitteePeriod * params.BeaconConfig().SlotsPerEpoch))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = state.SetSlot(state.Slot() + (params.BeaconConfig().PersistentCommitteePeriod * params.BeaconConfig().SlotsPerEpoch))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
priv := bls.RandKey()
|
||||
val, err := state.ValidatorAtIndex(0)
|
||||
@@ -1758,7 +1912,9 @@ func TestProcessVoluntaryExits_AppliesCorrectStatus(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
val.PublicKey = priv.PublicKey().Marshal()[:]
|
||||
state.UpdateValidatorAtIndex(0, val)
|
||||
if err := state.UpdateValidatorAtIndex(0, val); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
signingRoot, err := ssz.HashTreeRoot(exits[0].Exit)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -93,9 +93,12 @@ func TestEth1DataHasEnoughSupport(t *testing.T) {
|
||||
c.SlotsPerEth1VotingPeriod = tt.votingPeriodLength
|
||||
params.OverrideBeaconConfig(c)
|
||||
|
||||
s, _ := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
s, err := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
Eth1DataVotes: tt.stateVotes,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
result, err := blocks.Eth1DataHasEnoughSupport(s, tt.data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -18,6 +18,9 @@ func TestFuzzFinalUpdates_10000(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, _ = ProcessFinalUpdates(s)
|
||||
_, err = ProcessFinalUpdates(s)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,9 @@ func TestUnslashedAttestingIndices_CanSortAndFilter(t *testing.T) {
|
||||
slashedValidator := indices[0]
|
||||
validators = state.Validators()
|
||||
validators[slashedValidator].Slashed = true
|
||||
state.SetValidators(validators)
|
||||
if err = state.SetValidators(validators); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
indices, err = unslashedAttestingIndices(state, atts)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -311,16 +313,24 @@ func TestProcessFinalUpdates_CanProcess(t *testing.T) {
|
||||
s := buildState(params.BeaconConfig().SlotsPerHistoricalRoot-1, params.BeaconConfig().SlotsPerEpoch)
|
||||
ce := helpers.CurrentEpoch(s)
|
||||
ne := ce + 1
|
||||
s.SetEth1DataVotes([]*ethpb.Eth1Data{})
|
||||
if err := s.SetEth1DataVotes([]*ethpb.Eth1Data{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
balances := s.Balances()
|
||||
balances[0] = 29 * 1e9
|
||||
s.SetBalances(balances)
|
||||
if err := s.SetBalances(balances); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
slashings := s.Slashings()
|
||||
slashings[ce] = 0
|
||||
s.SetSlashings(slashings)
|
||||
if err := s.SetSlashings(slashings); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mixes := s.RandaoMixes()
|
||||
mixes[ce] = []byte{'A'}
|
||||
s.SetRandaoMixes(mixes)
|
||||
if err := s.SetRandaoMixes(mixes); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
newS, err := ProcessFinalUpdates(s)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -339,7 +349,7 @@ func TestProcessFinalUpdates_CanProcess(t *testing.T) {
|
||||
}
|
||||
|
||||
// Verify randao is correctly updated in the right position.
|
||||
if mix, _ := newS.RandaoMixAtIndex(ne); bytes.Equal(mix, params.BeaconConfig().ZeroHash[:]) {
|
||||
if mix, err := newS.RandaoMixAtIndex(ne); err != nil || bytes.Equal(mix, params.BeaconConfig().ZeroHash[:]) {
|
||||
t.Error("latest RANDAO still zero hashes")
|
||||
}
|
||||
|
||||
|
||||
@@ -74,13 +74,17 @@ func TestUpdateBalance(t *testing.T) {
|
||||
|
||||
func TestSameHead(t *testing.T) {
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 100)
|
||||
beaconState.SetSlot(1)
|
||||
if err := beaconState.SetSlot(1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
att := ðpb.Attestation{Data: ðpb.AttestationData{
|
||||
Target: ðpb.Checkpoint{Epoch: 0}}}
|
||||
r := [32]byte{'A'}
|
||||
br := beaconState.BlockRoots()
|
||||
br[0] = r[:]
|
||||
beaconState.SetBlockRoots(br)
|
||||
if err := beaconState.SetBlockRoots(br); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
att.Data.BeaconBlockRoot = r[:]
|
||||
same, err := precompute.SameHead(beaconState, &pb.PendingAttestation{Data: att.Data})
|
||||
if err != nil {
|
||||
@@ -102,13 +106,17 @@ func TestSameHead(t *testing.T) {
|
||||
|
||||
func TestSameTarget(t *testing.T) {
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 100)
|
||||
beaconState.SetSlot(1)
|
||||
if err := beaconState.SetSlot(1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
att := ðpb.Attestation{Data: ðpb.AttestationData{
|
||||
Target: ðpb.Checkpoint{Epoch: 0}}}
|
||||
r := [32]byte{'A'}
|
||||
br := beaconState.BlockRoots()
|
||||
br[0] = r[:]
|
||||
beaconState.SetBlockRoots(br)
|
||||
if err := beaconState.SetBlockRoots(br); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
att.Data.Target.Root = r[:]
|
||||
same, err := precompute.SameTarget(beaconState, &pb.PendingAttestation{Data: att.Data}, 0)
|
||||
if err != nil {
|
||||
@@ -130,13 +138,17 @@ func TestSameTarget(t *testing.T) {
|
||||
|
||||
func TestAttestedPrevEpoch(t *testing.T) {
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 100)
|
||||
beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch)
|
||||
if err := beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
att := ðpb.Attestation{Data: ðpb.AttestationData{
|
||||
Target: ðpb.Checkpoint{Epoch: 0}}}
|
||||
r := [32]byte{'A'}
|
||||
br := beaconState.BlockRoots()
|
||||
br[0] = r[:]
|
||||
beaconState.SetBlockRoots(br)
|
||||
if err := beaconState.SetBlockRoots(br); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
att.Data.Target.Root = r[:]
|
||||
att.Data.BeaconBlockRoot = r[:]
|
||||
votedEpoch, votedTarget, votedHead, err := precompute.AttestedPrevEpoch(beaconState, &pb.PendingAttestation{Data: att.Data})
|
||||
@@ -156,14 +168,18 @@ func TestAttestedPrevEpoch(t *testing.T) {
|
||||
|
||||
func TestAttestedCurrentEpoch(t *testing.T) {
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 100)
|
||||
beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch + 1)
|
||||
if err := beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch + 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
att := ðpb.Attestation{Data: ðpb.AttestationData{
|
||||
Target: ðpb.Checkpoint{Epoch: 1}}}
|
||||
r := [32]byte{'A'}
|
||||
|
||||
br := beaconState.BlockRoots()
|
||||
br[params.BeaconConfig().SlotsPerEpoch] = r[:]
|
||||
beaconState.SetBlockRoots(br)
|
||||
if err := beaconState.SetBlockRoots(br); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
att.Data.Target.Root = r[:]
|
||||
att.Data.BeaconBlockRoot = r[:]
|
||||
votedEpoch, votedTarget, err := precompute.AttestedCurrentEpoch(beaconState, &pb.PendingAttestation{Data: att.Data})
|
||||
@@ -184,7 +200,9 @@ func TestProcessAttestations(t *testing.T) {
|
||||
|
||||
validators := uint64(64)
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, validators)
|
||||
beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch)
|
||||
if err := beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
bf := []byte{0xff}
|
||||
att1 := ðpb.Attestation{Data: ðpb.AttestationData{
|
||||
@@ -199,18 +217,26 @@ func TestProcessAttestations(t *testing.T) {
|
||||
br := beaconState.BlockRoots()
|
||||
newRt := [32]byte{'B'}
|
||||
br[0] = newRt[:]
|
||||
beaconState.SetBlockRoots(br)
|
||||
if err := beaconState.SetBlockRoots(br); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
att2.Data.Target.Root = rt[:]
|
||||
att2.Data.BeaconBlockRoot = newRt[:]
|
||||
beaconState.SetPreviousEpochAttestations([]*pb.PendingAttestation{{Data: att1.Data, AggregationBits: bf}})
|
||||
beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{{Data: att2.Data, AggregationBits: bf}})
|
||||
err := beaconState.SetPreviousEpochAttestations([]*pb.PendingAttestation{{Data: att1.Data, AggregationBits: bf}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{{Data: att2.Data, AggregationBits: bf}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
vp := make([]*precompute.Validator, validators)
|
||||
for i := 0; i < len(vp); i++ {
|
||||
vp[i] = &precompute.Validator{CurrentEpochEffectiveBalance: 100}
|
||||
}
|
||||
bp := &precompute.Balance{}
|
||||
vp, bp, err := precompute.ProcessAttestations(context.Background(), beaconState, vp, bp)
|
||||
vp, bp, err = precompute.ProcessAttestations(context.Background(), beaconState, vp, bp)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -31,7 +31,10 @@ func TestNew(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
e := params.BeaconConfig().FarFutureEpoch
|
||||
v, b, _ := precompute.New(context.Background(), s)
|
||||
v, b, err := precompute.New(context.Background(), s)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(v[0], &precompute.Validator{IsSlashed: true, CurrentEpochEffectiveBalance: 100,
|
||||
InclusionDistance: e, InclusionSlot: e}) {
|
||||
t.Error("Incorrect validator 0 status")
|
||||
|
||||
@@ -35,7 +35,10 @@ func TestProcessRewardsAndPenaltiesPrecompute(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
vp, bp, _ := New(context.Background(), state)
|
||||
vp, bp, err := New(context.Background(), state)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
vp, bp, err = ProcessAttestations(context.Background(), state, vp, bp)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -88,7 +91,10 @@ func TestAttestationDeltaPrecompute(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
vp, bp, _ := New(context.Background(), state)
|
||||
vp, bp, err := New(context.Background(), state)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
vp, bp, err = ProcessAttestations(context.Background(), state, vp, bp)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -173,7 +179,10 @@ func TestAttestationDeltas_ZeroEpoch(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
vp, bp, _ := New(context.Background(), state)
|
||||
vp, bp, err := New(context.Background(), state)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
vp, bp, err = ProcessAttestations(context.Background(), state, vp, bp)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -28,8 +28,11 @@ func runJustificationAndFinalizationTests(t *testing.T, config string) {
|
||||
|
||||
func processJustificationAndFinalizationPrecomputeWrapper(t *testing.T, state *state.BeaconState) (*state.BeaconState, error) {
|
||||
ctx := context.Background()
|
||||
vp, bp, _ := precompute.New(ctx, state)
|
||||
_, bp, err := precompute.ProcessAttestations(ctx, state, vp, bp)
|
||||
vp, bp, err := precompute.New(ctx, state)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, bp, err = precompute.ProcessAttestations(ctx, state, vp, bp)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -37,8 +37,11 @@ func processSlashingsWrapper(t *testing.T, state *beaconstate.BeaconState) (*bea
|
||||
|
||||
func processSlashingsPrecomputeWrapper(t *testing.T, state *beaconstate.BeaconState) (*beaconstate.BeaconState, error) {
|
||||
ctx := context.Background()
|
||||
vp, bp, _ := precompute.New(ctx, state)
|
||||
_, bp, err := precompute.ProcessAttestations(ctx, state, vp, bp)
|
||||
vp, bp, err := precompute.New(ctx, state)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, bp, err = precompute.ProcessAttestations(ctx, state, vp, bp)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -240,7 +240,7 @@ func TestAggregateAttestations(t *testing.T) {
|
||||
func TestSlotSignature_Verify(t *testing.T) {
|
||||
priv := bls.RandKey()
|
||||
pub := priv.PublicKey()
|
||||
state, _ := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
state, err := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
Fork: &pb.Fork{
|
||||
CurrentVersion: params.BeaconConfig().GenesisForkVersion,
|
||||
PreviousVersion: params.BeaconConfig().GenesisForkVersion,
|
||||
@@ -248,6 +248,9 @@ func TestSlotSignature_Verify(t *testing.T) {
|
||||
},
|
||||
Slot: 100,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
slot := uint64(101)
|
||||
|
||||
sig, err := helpers.SlotSignature(state, slot, priv)
|
||||
@@ -259,7 +262,10 @@ func TestSlotSignature_Verify(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
msg, _ := ssz.HashTreeRoot(slot)
|
||||
msg, err := ssz.HashTreeRoot(slot)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !sig.Verify(msg[:], pub, domain) {
|
||||
t.Error("Could not verify slot signature")
|
||||
}
|
||||
|
||||
@@ -58,7 +58,10 @@ func TestBlockRootAtSlot_CorrectBlockRoot(t *testing.T) {
|
||||
for i, tt := range tests {
|
||||
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
|
||||
s.Slot = tt.stateSlot
|
||||
state, _ := beaconstate.InitializeFromProto(s)
|
||||
state, err := beaconstate.InitializeFromProto(s)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
wantedSlot := tt.slot
|
||||
result, err := helpers.BlockRootAtSlot(state, wantedSlot)
|
||||
if err != nil {
|
||||
@@ -111,8 +114,11 @@ func TestBlockRootAtSlot_OutOfBounds(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
state.Slot = tt.stateSlot
|
||||
s, _ := beaconstate.InitializeFromProto(state)
|
||||
_, err := helpers.BlockRootAtSlot(s, tt.slot)
|
||||
s, err := beaconstate.InitializeFromProto(state)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = helpers.BlockRootAtSlot(s, tt.slot)
|
||||
if err == nil {
|
||||
t.Errorf("Expected error %s, got nil", tt.expectedErr)
|
||||
}
|
||||
|
||||
@@ -96,11 +96,14 @@ func TestAttestationParticipants_NoCommitteeCache(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
state, _ := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
state, err := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
Slot: params.BeaconConfig().SlotsPerEpoch,
|
||||
Validators: validators,
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
attestationData := ðpb.AttestationData{}
|
||||
|
||||
@@ -157,10 +160,13 @@ func TestAttestationParticipants_EmptyBitfield(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
state, _ := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
state, err := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: validators,
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
attestationData := ðpb.AttestationData{Target: ðpb.Checkpoint{}}
|
||||
|
||||
committee, err := BeaconCommitteeFromState(state, attestationData.Slot, attestationData.CommitteeIndex)
|
||||
@@ -168,10 +174,6 @@ func TestAttestationParticipants_EmptyBitfield(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
indices := attestationutil.AttestingIndices(bitfield.NewBitlist(128), committee)
|
||||
if err != nil {
|
||||
t.Fatalf("attesting indices failed: %v", err)
|
||||
}
|
||||
|
||||
if len(indices) != 0 {
|
||||
t.Errorf("Attesting indices are non-zero despite an empty bitfield being provided; Size %d", len(indices))
|
||||
}
|
||||
@@ -200,11 +202,14 @@ func TestCommitteeAssignment_CanRetrieve(t *testing.T) {
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
}
|
||||
}
|
||||
state, _ := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
state, err := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: validators,
|
||||
Slot: params.BeaconConfig().SlotsPerEpoch,
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
index uint64
|
||||
@@ -276,14 +281,17 @@ func TestCommitteeAssignment_CantFindValidator(t *testing.T) {
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
}
|
||||
}
|
||||
state, _ := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
state, err := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: validators,
|
||||
Slot: params.BeaconConfig().SlotsPerEpoch,
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
index := uint64(10000)
|
||||
_, _, _, _, err := CommitteeAssignment(state, 1, index)
|
||||
_, _, _, _, err = CommitteeAssignment(state, 1, index)
|
||||
if err != nil && !strings.Contains(err.Error(), "not found in assignments") {
|
||||
t.Errorf("Wanted 'not found in assignments', received %v", err)
|
||||
}
|
||||
@@ -300,14 +308,20 @@ func TestCommitteeAssignments_AgreesWithSpecDefinitionMethod(t *testing.T) {
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
}
|
||||
}
|
||||
state, _ := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
state, err := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: validators,
|
||||
Slot: params.BeaconConfig().SlotsPerEpoch,
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Test for 2 epochs.
|
||||
for epoch := uint64(0); epoch < 2; epoch++ {
|
||||
state, _ := beaconstate.InitializeFromProto(state.CloneInnerState())
|
||||
state, err := beaconstate.InitializeFromProto(state.CloneInnerState())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assignments, proposers, err := CommitteeAssignments(state, epoch)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -348,11 +362,14 @@ func TestCommitteeAssignments_CanRetrieve(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
state, _ := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
state, err := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: validators,
|
||||
Slot: 2 * params.BeaconConfig().SlotsPerEpoch, // epoch 2
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
index uint64
|
||||
@@ -429,10 +446,13 @@ func TestVerifyAttestationBitfieldLengths_OK(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
state, _ := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
state, err := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: validators,
|
||||
RandaoMixes: activeRoots,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
attestation *ethpb.Attestation
|
||||
@@ -506,7 +526,9 @@ func TestVerifyAttestationBitfieldLengths_OK(t *testing.T) {
|
||||
|
||||
for i, tt := range tests {
|
||||
ClearCache()
|
||||
state.SetSlot(tt.stateSlot)
|
||||
if err := state.SetSlot(tt.stateSlot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err := VerifyAttestationBitfieldLengths(state, tt.attestation)
|
||||
if tt.verificationFailure {
|
||||
if err == nil {
|
||||
@@ -655,10 +677,13 @@ func BenchmarkComputeCommittee3000000_WithPreCache(b *testing.B) {
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
}
|
||||
}
|
||||
state, _ := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
state, err := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: validators,
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
epoch := CurrentEpoch(state)
|
||||
indices, err := ActiveValidatorIndices(state, epoch)
|
||||
@@ -692,10 +717,13 @@ func BenchmarkComputeCommittee128000_WithOutPreCache(b *testing.B) {
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
}
|
||||
}
|
||||
state, _ := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
state, err := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: validators,
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
epoch := CurrentEpoch(state)
|
||||
indices, err := ActiveValidatorIndices(state, epoch)
|
||||
@@ -730,10 +758,13 @@ func BenchmarkComputeCommittee1000000_WithOutCache(b *testing.B) {
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
}
|
||||
}
|
||||
state, _ := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
state, err := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: validators,
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
epoch := CurrentEpoch(state)
|
||||
indices, err := ActiveValidatorIndices(state, epoch)
|
||||
@@ -768,10 +799,13 @@ func BenchmarkComputeCommittee4000000_WithOutCache(b *testing.B) {
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
}
|
||||
}
|
||||
state, _ := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
state, err := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: validators,
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
epoch := CurrentEpoch(state)
|
||||
indices, err := ActiveValidatorIndices(state, epoch)
|
||||
@@ -812,11 +846,14 @@ func TestBeaconCommitteeFromState_UpdateCacheForPreviousEpoch(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
state, _ := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
state, err := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
Slot: params.BeaconConfig().SlotsPerEpoch,
|
||||
Validators: validators,
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if _, err := BeaconCommitteeFromState(state, 1 /* previous epoch */, 0); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -844,10 +881,13 @@ func TestPrecomputeProposerIndices_Ok(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
state, _ := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
state, err := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: validators,
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
indices, err := ActiveValidatorIndices(state, 0)
|
||||
if err != nil {
|
||||
|
||||
@@ -18,7 +18,10 @@ func TestRandaoMix_OK(t *testing.T) {
|
||||
binary.LittleEndian.PutUint64(intInBytes, uint64(i))
|
||||
randaoMixes[i] = intInBytes
|
||||
}
|
||||
state, _ := beaconstate.InitializeFromProto(&pb.BeaconState{RandaoMixes: randaoMixes})
|
||||
state, err := beaconstate.InitializeFromProto(&pb.BeaconState{RandaoMixes: randaoMixes})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tests := []struct {
|
||||
epoch uint64
|
||||
randaoMix []byte
|
||||
@@ -37,7 +40,9 @@ func TestRandaoMix_OK(t *testing.T) {
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
state.SetSlot((test.epoch + 1) * params.BeaconConfig().SlotsPerEpoch)
|
||||
if err := state.SetSlot((test.epoch + 1) * params.BeaconConfig().SlotsPerEpoch); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mix, err := RandaoMix(state, test.epoch)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -56,7 +61,10 @@ func TestRandaoMix_CopyOK(t *testing.T) {
|
||||
binary.LittleEndian.PutUint64(intInBytes, uint64(i))
|
||||
randaoMixes[i] = intInBytes
|
||||
}
|
||||
state, _ := beaconstate.InitializeFromProto(&pb.BeaconState{RandaoMixes: randaoMixes})
|
||||
state, err := beaconstate.InitializeFromProto(&pb.BeaconState{RandaoMixes: randaoMixes})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tests := []struct {
|
||||
epoch uint64
|
||||
randaoMix []byte
|
||||
@@ -75,7 +83,9 @@ func TestRandaoMix_CopyOK(t *testing.T) {
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
state.SetSlot((test.epoch + 1) * params.BeaconConfig().SlotsPerEpoch)
|
||||
if err := state.SetSlot((test.epoch + 1) * params.BeaconConfig().SlotsPerEpoch); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mix, err := RandaoMix(state, test.epoch)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -101,9 +111,13 @@ func TestGenerateSeed_OK(t *testing.T) {
|
||||
randaoMixes[i] = intInBytes
|
||||
}
|
||||
slot := 10 * params.BeaconConfig().MinSeedLookahead * params.BeaconConfig().SlotsPerEpoch
|
||||
state, _ := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
state, err := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
RandaoMixes: randaoMixes,
|
||||
Slot: slot})
|
||||
Slot: slot,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
got, err := Seed(state, 10, params.BeaconConfig().DomainBeaconAttester)
|
||||
if err != nil {
|
||||
|
||||
@@ -10,10 +10,13 @@ import (
|
||||
)
|
||||
|
||||
func TestTotalBalance_OK(t *testing.T) {
|
||||
state, _ := beaconstate.InitializeFromProto(&pb.BeaconState{Validators: []*ethpb.Validator{
|
||||
state, err := beaconstate.InitializeFromProto(&pb.BeaconState{Validators: []*ethpb.Validator{
|
||||
{EffectiveBalance: 27 * 1e9}, {EffectiveBalance: 28 * 1e9},
|
||||
{EffectiveBalance: 32 * 1e9}, {EffectiveBalance: 40 * 1e9},
|
||||
}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
balance := TotalBalance(state, []uint64{0, 1, 2, 3})
|
||||
wanted := state.Validators()[0].EffectiveBalance + state.Validators()[1].EffectiveBalance +
|
||||
@@ -25,7 +28,10 @@ func TestTotalBalance_OK(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTotalBalance_ReturnsOne(t *testing.T) {
|
||||
state, _ := beaconstate.InitializeFromProto(&pb.BeaconState{Validators: []*ethpb.Validator{}})
|
||||
state, err := beaconstate.InitializeFromProto(&pb.BeaconState{Validators: []*ethpb.Validator{}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
balance := TotalBalance(state, []uint64{})
|
||||
wanted := uint64(1)
|
||||
@@ -36,7 +42,7 @@ func TestTotalBalance_ReturnsOne(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTotalActiveBalance_OK(t *testing.T) {
|
||||
state, _ := beaconstate.InitializeFromProto(&pb.BeaconState{Validators: []*ethpb.Validator{
|
||||
state, err := beaconstate.InitializeFromProto(&pb.BeaconState{Validators: []*ethpb.Validator{
|
||||
{
|
||||
EffectiveBalance: 32 * 1e9,
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
@@ -54,6 +60,9 @@ func TestTotalActiveBalance_OK(t *testing.T) {
|
||||
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
},
|
||||
}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
balance, err := TotalActiveBalance(state)
|
||||
if err != nil {
|
||||
@@ -79,7 +88,10 @@ func TestGetBalance_OK(t *testing.T) {
|
||||
{i: 2, b: []uint64{0, 0, 0}},
|
||||
}
|
||||
for _, test := range tests {
|
||||
state, _ := beaconstate.InitializeFromProto(&pb.BeaconState{Balances: test.b})
|
||||
state, err := beaconstate.InitializeFromProto(&pb.BeaconState{Balances: test.b})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if state.Balances()[test.i] != test.b[test.i] {
|
||||
t.Errorf("Incorrect Validator balance. Wanted: %d, got: %d", test.b[test.i], state.Balances()[test.i])
|
||||
}
|
||||
@@ -98,11 +110,14 @@ func TestIncreaseBalance_OK(t *testing.T) {
|
||||
{i: 2, b: []uint64{27 * 1e9, 28 * 1e9, 32 * 1e9}, nb: 33 * 1e9, eb: 65 * 1e9},
|
||||
}
|
||||
for _, test := range tests {
|
||||
state, _ := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
state, err := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: []*ethpb.Validator{
|
||||
{EffectiveBalance: 4}, {EffectiveBalance: 4}, {EffectiveBalance: 4}},
|
||||
Balances: test.b,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := IncreaseBalance(state, test.i, test.nb); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -125,11 +140,14 @@ func TestDecreaseBalance_OK(t *testing.T) {
|
||||
{i: 3, b: []uint64{27 * 1e9, 28 * 1e9, 1, 28 * 1e9}, nb: 28 * 1e9, eb: 0},
|
||||
}
|
||||
for _, test := range tests {
|
||||
state, _ := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
state, err := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: []*ethpb.Validator{
|
||||
{EffectiveBalance: 4}, {EffectiveBalance: 4}, {EffectiveBalance: 4}, {EffectiveBalance: 3}},
|
||||
Balances: test.b,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := DecreaseBalance(state, test.i, test.nb); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -101,7 +101,9 @@ func BenchmarkShuffledIndex(b *testing.B) {
|
||||
for _, listSize := range listSizes {
|
||||
b.Run(fmt.Sprintf("ShuffledIndex_%d", listSize), func(ib *testing.B) {
|
||||
for i := uint64(0); i < uint64(ib.N); i++ {
|
||||
ShuffledIndex(i%listSize, listSize, seed)
|
||||
if _, err := ShuffledIndex(i%listSize, listSize, seed); err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -115,7 +117,9 @@ func BenchmarkIndexComparison(b *testing.B) {
|
||||
for i := 0; i < ib.N; i++ {
|
||||
// Simulate a list-shuffle by running shuffle-index listSize times.
|
||||
for j := uint64(0); j < listSize; j++ {
|
||||
ShuffledIndex(j, listSize, seed)
|
||||
if _, err := ShuffledIndex(j, listSize, seed); err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -132,7 +136,9 @@ func BenchmarkShuffleList(b *testing.B) {
|
||||
}
|
||||
b.Run(fmt.Sprintf("ShuffleList_%d", listSize), func(ib *testing.B) {
|
||||
for i := 0; i < ib.N; i++ {
|
||||
ShuffleList(testIndices, seed)
|
||||
if _, err := ShuffleList(testIndices, seed); err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -38,7 +38,10 @@ func TestCurrentEpoch_OK(t *testing.T) {
|
||||
{slot: 200, epoch: 6},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
state, _ := beaconstate.InitializeFromProto(&pb.BeaconState{Slot: tt.slot})
|
||||
state, err := beaconstate.InitializeFromProto(&pb.BeaconState{Slot: tt.slot})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if tt.epoch != CurrentEpoch(state) {
|
||||
t.Errorf("CurrentEpoch(%d) = %d, wanted: %d", state.Slot(), CurrentEpoch(state), tt.epoch)
|
||||
}
|
||||
@@ -55,7 +58,10 @@ func TestPrevEpoch_OK(t *testing.T) {
|
||||
{slot: 2 * params.BeaconConfig().SlotsPerEpoch, epoch: 1},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
state, _ := beaconstate.InitializeFromProto(&pb.BeaconState{Slot: tt.slot})
|
||||
state, err := beaconstate.InitializeFromProto(&pb.BeaconState{Slot: tt.slot})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if tt.epoch != PrevEpoch(state) {
|
||||
t.Errorf("PrevEpoch(%d) = %d, wanted: %d", state.Slot(), PrevEpoch(state), tt.epoch)
|
||||
}
|
||||
@@ -74,7 +80,10 @@ func TestNextEpoch_OK(t *testing.T) {
|
||||
{slot: 200, epoch: 200/params.BeaconConfig().SlotsPerEpoch + 1},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
state, _ := beaconstate.InitializeFromProto(&pb.BeaconState{Slot: tt.slot})
|
||||
state, err := beaconstate.InitializeFromProto(&pb.BeaconState{Slot: tt.slot})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if tt.epoch != NextEpoch(state) {
|
||||
t.Errorf("NextEpoch(%d) = %d, wanted: %d", state.Slot(), NextEpoch(state), tt.epoch)
|
||||
}
|
||||
|
||||
@@ -128,11 +128,14 @@ func TestBeaconProposerIndex_OK(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
state, _ := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
state, err := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
Validators: validators,
|
||||
Slot: 0,
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
slot uint64
|
||||
@@ -162,7 +165,9 @@ func TestBeaconProposerIndex_OK(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
ClearCache()
|
||||
state.SetSlot(tt.slot)
|
||||
if err := state.SetSlot(tt.slot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
result, err := BeaconProposerIndex(state)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to get shard and committees at slot: %v", err)
|
||||
@@ -205,11 +210,14 @@ func TestChurnLimit_OK(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
beaconState, _ := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
beaconState, err := beaconstate.InitializeFromProto(&pb.BeaconState{
|
||||
Slot: 1,
|
||||
Validators: validators,
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
validatorCount, err := ActiveValidatorCount(beaconState, CurrentEpoch(beaconState))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -404,7 +412,10 @@ func TestActiveValidatorIndices(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
s, _ := beaconstate.InitializeFromProto(tt.args.state)
|
||||
s, err := beaconstate.InitializeFromProto(tt.args.state)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, err := ActiveValidatorIndices(s, tt.args.epoch)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("ActiveValidatorIndices() error = %v, wantErr %v", err, tt.wantErr)
|
||||
@@ -588,7 +599,10 @@ func TestIsIsEligibleForActivation(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
s, _ := beaconstate.InitializeFromProto(tt.state)
|
||||
s, err := beaconstate.InitializeFromProto(tt.state)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := IsEligibleForActivation(s, tt.validator); got != tt.want {
|
||||
t.Errorf("IsEligibleForActivation() = %v, want %v", got, tt.want)
|
||||
}
|
||||
|
||||
@@ -69,11 +69,15 @@ func BenchmarkExecuteStateTransition_WithCache(b *testing.B) {
|
||||
// We have to reset slot back to last epoch to hydrate cache. Since
|
||||
// some attestations in block are from previous epoch
|
||||
currentSlot := beaconState.Slot()
|
||||
beaconState.SetSlot(beaconState.Slot() - params.BeaconConfig().SlotsPerEpoch)
|
||||
if err := beaconState.SetSlot(beaconState.Slot() - params.BeaconConfig().SlotsPerEpoch); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
if err := helpers.UpdateCommitteeCache(beaconState, helpers.CurrentEpoch(beaconState)); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
beaconState.SetSlot(currentSlot)
|
||||
if err := beaconState.SetSlot(currentSlot); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
// Run the state transition once to populate the cache.
|
||||
if _, err := state.ExecuteStateTransition(context.Background(), beaconState, block); err != nil {
|
||||
b.Fatalf("failed to process block, benchmarks will fail: %v", err)
|
||||
@@ -98,11 +102,15 @@ func BenchmarkProcessEpoch_2FullEpochs(b *testing.B) {
|
||||
// We have to reset slot back to last epoch to hydrate cache. Since
|
||||
// some attestations in block are from previous epoch
|
||||
currentSlot := beaconState.Slot()
|
||||
beaconState.SetSlot(beaconState.Slot() - params.BeaconConfig().SlotsPerEpoch)
|
||||
if err := beaconState.SetSlot(beaconState.Slot() - params.BeaconConfig().SlotsPerEpoch); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
if err := helpers.UpdateCommitteeCache(beaconState, helpers.CurrentEpoch(beaconState)); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
beaconState.SetSlot(currentSlot)
|
||||
if err := beaconState.SetSlot(currentSlot); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
|
||||
@@ -15,7 +15,10 @@ func TestSkipSlotCache_OK(t *testing.T) {
|
||||
state.SkipSlotCache.Enable()
|
||||
defer state.SkipSlotCache.Disable()
|
||||
bState, privs := testutil.DeterministicGenesisState(t, params.MinimalSpecConfig().MinGenesisActiveValidatorCount)
|
||||
originalState, _ := beaconstate.InitializeFromProto(bState.CloneInnerState())
|
||||
originalState, err := beaconstate.InitializeFromProto(bState.CloneInnerState())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
blkCfg := testutil.DefaultBlockGenConfig()
|
||||
blkCfg.NumAttestations = 1
|
||||
|
||||
@@ -42,7 +42,10 @@ func TestGenesisBeaconState_OK(t *testing.T) {
|
||||
}
|
||||
|
||||
genesisTime := uint64(99999)
|
||||
deposits, _, _ := testutil.DeterministicDepositsAndKeys(uint64(depositsForChainStart))
|
||||
deposits, _, err := testutil.DeterministicDepositsAndKeys(uint64(depositsForChainStart))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
eth1Data, err := testutil.DeterministicEth1Data(len(deposits))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -68,10 +71,18 @@ func TestGenesisBeaconState_OK(t *testing.T) {
|
||||
if len(newState.Validators()) != depositsForChainStart {
|
||||
t.Error("Validators was not correctly initialized")
|
||||
}
|
||||
if v, _ := newState.ValidatorAtIndex(0); v.ActivationEpoch != 0 {
|
||||
v, err := newState.ValidatorAtIndex(0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if v.ActivationEpoch != 0 {
|
||||
t.Error("Validators was not correctly initialized")
|
||||
}
|
||||
if v, _ := newState.ValidatorAtIndex(0); v.ActivationEligibilityEpoch != 0 {
|
||||
v, err = newState.ValidatorAtIndex(0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if v.ActivationEligibilityEpoch != 0 {
|
||||
t.Error("Validators was not correctly initialized")
|
||||
}
|
||||
if len(newState.Balances()) != depositsForChainStart {
|
||||
@@ -82,7 +93,11 @@ func TestGenesisBeaconState_OK(t *testing.T) {
|
||||
if len(newState.RandaoMixes()) != latestRandaoMixesLength {
|
||||
t.Error("Length of RandaoMixes was not correctly initialized")
|
||||
}
|
||||
if mix, _ := newState.RandaoMixAtIndex(0); !bytes.Equal(mix, eth1Data.BlockHash) {
|
||||
mix, err := newState.RandaoMixAtIndex(0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !bytes.Equal(mix, eth1Data.BlockHash) {
|
||||
t.Error("RandaoMixes was not correctly initialized")
|
||||
}
|
||||
|
||||
@@ -130,7 +145,10 @@ func TestGenesisBeaconState_OK(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGenesisState_HashEquality(t *testing.T) {
|
||||
deposits, _, _ := testutil.DeterministicDepositsAndKeys(100)
|
||||
deposits, _, err := testutil.DeterministicDepositsAndKeys(100)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
state1, err := state.GenesisBeaconState(deposits, 0, ðpb.Eth1Data{BlockHash: make([]byte, 32)})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -179,7 +179,9 @@ func TestFuzzverifyOperationLengths_10000(t *testing.T) {
|
||||
for i := 0; i < 10000; i++ {
|
||||
fuzzer.Fuzz(state)
|
||||
fuzzer.Fuzz(bb)
|
||||
verifyOperationLengths(state, bb)
|
||||
if err := verifyOperationLengths(state, bb); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,8 @@ func TestExecuteStateTransition_IncorrectSlot(t *testing.T) {
|
||||
},
|
||||
}
|
||||
want := "expected state.slot"
|
||||
if _, err := state.ExecuteStateTransition(context.Background(), beaconState, block); !strings.Contains(err.Error(), want) {
|
||||
_, err = state.ExecuteStateTransition(context.Background(), beaconState, block)
|
||||
if err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected %s, received %v", want, err)
|
||||
}
|
||||
}
|
||||
@@ -55,12 +56,20 @@ func TestExecuteStateTransition_FullProcess(t *testing.T) {
|
||||
DepositCount: 100,
|
||||
DepositRoot: []byte{2},
|
||||
}
|
||||
beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch - 1)
|
||||
if err := beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch - 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
e := beaconState.Eth1Data()
|
||||
e.DepositCount = 100
|
||||
beaconState.SetEth1Data(e)
|
||||
beaconState.SetLatestBlockHeader(ðpb.BeaconBlockHeader{Slot: beaconState.Slot()})
|
||||
beaconState.SetEth1DataVotes([]*ethpb.Eth1Data{eth1Data})
|
||||
if err := beaconState.SetEth1Data(e); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := beaconState.SetLatestBlockHeader(ðpb.BeaconBlockHeader{Slot: beaconState.Slot()}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := beaconState.SetEth1DataVotes([]*ethpb.Eth1Data{eth1Data}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
oldMix, err := beaconState.RandaoMixAtIndex(1)
|
||||
if err != nil {
|
||||
@@ -71,13 +80,17 @@ func TestExecuteStateTransition_FullProcess(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
beaconState.SetSlot(beaconState.Slot() + 1)
|
||||
if err := beaconState.SetSlot(beaconState.Slot() + 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
epoch := helpers.CurrentEpoch(beaconState)
|
||||
randaoReveal, err := testutil.RandaoReveal(beaconState, epoch, privKeys)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
beaconState.SetSlot(beaconState.Slot() - 1)
|
||||
if err := beaconState.SetSlot(beaconState.Slot() - 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
block := ðpb.SignedBeaconBlock{
|
||||
Block: ðpb.BeaconBlock{
|
||||
Slot: beaconState.Slot() + 1,
|
||||
@@ -111,7 +124,11 @@ func TestExecuteStateTransition_FullProcess(t *testing.T) {
|
||||
t.Errorf("Unexpected Slot number, expected: 64, received: %d", beaconState.Slot())
|
||||
}
|
||||
|
||||
if mix, _ := beaconState.RandaoMixAtIndex(1); bytes.Equal(mix, oldMix) {
|
||||
mix, err := beaconState.RandaoMixAtIndex(1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if bytes.Equal(mix, oldMix) {
|
||||
t.Errorf("Did not expect new and old randao mix to equal, %#x == %#x", mix, oldMix)
|
||||
}
|
||||
}
|
||||
@@ -133,12 +150,16 @@ func TestProcessBlock_IncorrectProposerSlashing(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
beaconState.SetSlot(beaconState.Slot() + 1)
|
||||
if err := beaconState.SetSlot(beaconState.Slot() + 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
proposerIdx, err := helpers.BeaconProposerIndex(beaconState)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
beaconState.SetSlot(beaconState.Slot() - 1)
|
||||
if err := beaconState.SetSlot(beaconState.Slot() - 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
domain, err := helpers.Domain(beaconState.Fork(), helpers.CurrentEpoch(beaconState), params.BeaconConfig().DomainBeaconProposer)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -151,7 +172,8 @@ func TestProcessBlock_IncorrectProposerSlashing(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := "could not process block proposer slashing"
|
||||
if _, err := state.ProcessBlock(context.Background(), beaconState, block); !strings.Contains(err.Error(), want) {
|
||||
_, err = state.ProcessBlock(context.Background(), beaconState, block)
|
||||
if err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected %s, received %v", want, err)
|
||||
}
|
||||
}
|
||||
@@ -176,12 +198,16 @@ func TestProcessBlock_IncorrectProcessBlockAttestations(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
beaconState.SetSlot(beaconState.Slot() + 1)
|
||||
if err := beaconState.SetSlot(beaconState.Slot() + 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
proposerIdx, err := helpers.BeaconProposerIndex(beaconState)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
beaconState.SetSlot(beaconState.Slot() - 1)
|
||||
if err := beaconState.SetSlot(beaconState.Slot() - 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
domain, err := helpers.Domain(beaconState.Fork(), helpers.CurrentEpoch(beaconState), params.BeaconConfig().DomainBeaconProposer)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -195,7 +221,8 @@ func TestProcessBlock_IncorrectProcessBlockAttestations(t *testing.T) {
|
||||
}
|
||||
|
||||
want := "could not process block attestations"
|
||||
if _, err := state.ProcessBlock(context.Background(), beaconState, block); !strings.Contains(err.Error(), want) {
|
||||
_, err = state.ProcessBlock(context.Background(), beaconState, block)
|
||||
if err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected %s, received %v", want, err)
|
||||
}
|
||||
}
|
||||
@@ -242,7 +269,9 @@ func TestProcessBlock_IncorrectProcessExits(t *testing.T) {
|
||||
for i := uint64(0); i < params.BeaconConfig().SlotsPerHistoricalRoot; i++ {
|
||||
blockRoots = append(blockRoots, []byte{byte(i)})
|
||||
}
|
||||
beaconState.SetBlockRoots(blockRoots)
|
||||
if err := beaconState.SetBlockRoots(blockRoots); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
blockAtt := ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Source: ðpb.Checkpoint{Epoch: 0},
|
||||
@@ -260,11 +289,14 @@ func TestProcessBlock_IncorrectProcessExits(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
beaconState.SetLatestBlockHeader(ðpb.BeaconBlockHeader{
|
||||
err = beaconState.SetLatestBlockHeader(ðpb.BeaconBlockHeader{
|
||||
Slot: genesisBlock.Block.Slot,
|
||||
ParentRoot: genesisBlock.Block.ParentRoot,
|
||||
BodyRoot: bodyRoot[:],
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
parentRoot, err := ssz.HashTreeRoot(beaconState.LatestBlockHeader())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -286,11 +318,18 @@ func TestProcessBlock_IncorrectProcessExits(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().MinAttestationInclusionDelay)
|
||||
err = beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().MinAttestationInclusionDelay)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cp := beaconState.CurrentJustifiedCheckpoint()
|
||||
cp.Root = []byte("hello-world")
|
||||
beaconState.SetCurrentJustifiedCheckpoint(cp)
|
||||
beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{})
|
||||
if err := beaconState.SetCurrentJustifiedCheckpoint(cp); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := state.ProcessBlock(context.Background(), beaconState, block); err == nil {
|
||||
t.Error("Expected err, received nil")
|
||||
}
|
||||
@@ -303,23 +342,36 @@ func TestProcessBlock_PassesProcessingConditions(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
beaconState.SetLatestBlockHeader(ðpb.BeaconBlockHeader{
|
||||
err = beaconState.SetLatestBlockHeader(ðpb.BeaconBlockHeader{
|
||||
Slot: genesisBlock.Block.Slot,
|
||||
ParentRoot: genesisBlock.Block.ParentRoot,
|
||||
StateRoot: params.BeaconConfig().ZeroHash[:],
|
||||
BodyRoot: bodyRoot[:],
|
||||
})
|
||||
beaconState.SetSlashings(make([]uint64, params.BeaconConfig().EpochsPerSlashingsVector))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = beaconState.SetSlashings(make([]uint64, params.BeaconConfig().EpochsPerSlashingsVector))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cp := beaconState.CurrentJustifiedCheckpoint()
|
||||
mockRoot := [32]byte{}
|
||||
copy(mockRoot[:], "hello-world")
|
||||
cp.Root = mockRoot[:]
|
||||
beaconState.SetCurrentJustifiedCheckpoint(cp)
|
||||
beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{})
|
||||
if err := beaconState.SetCurrentJustifiedCheckpoint(cp); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
proposerSlashIdx := uint64(3)
|
||||
slotsPerEpoch := params.BeaconConfig().SlotsPerEpoch
|
||||
beaconState.SetSlot((params.BeaconConfig().PersistentCommitteePeriod * slotsPerEpoch) + params.BeaconConfig().MinAttestationInclusionDelay)
|
||||
err = beaconState.SetSlot((params.BeaconConfig().PersistentCommitteePeriod * slotsPerEpoch) + params.BeaconConfig().MinAttestationInclusionDelay)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
currentEpoch := helpers.CurrentEpoch(beaconState)
|
||||
domain, err := helpers.Domain(
|
||||
@@ -364,7 +416,9 @@ func TestProcessBlock_PassesProcessingConditions(t *testing.T) {
|
||||
}
|
||||
validators := beaconState.Validators()
|
||||
validators[proposerSlashIdx].PublicKey = privKeys[proposerSlashIdx].PublicKey().Marshal()[:]
|
||||
beaconState.SetValidators(validators)
|
||||
if err := beaconState.SetValidators(validators); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
mockRoot2 := [32]byte{'A'}
|
||||
att1 := ðpb.IndexedAttestation{
|
||||
@@ -413,7 +467,9 @@ func TestProcessBlock_PassesProcessingConditions(t *testing.T) {
|
||||
for i := uint64(0); i < params.BeaconConfig().SlotsPerHistoricalRoot; i++ {
|
||||
blockRoots = append(blockRoots, []byte{byte(i)})
|
||||
}
|
||||
beaconState.SetBlockRoots(blockRoots)
|
||||
if err := beaconState.SetBlockRoots(blockRoots); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
aggBits := bitfield.NewBitlist(1)
|
||||
aggBits.SetBitAt(0, true)
|
||||
@@ -501,15 +557,25 @@ func TestProcessBlock_PassesProcessingConditions(t *testing.T) {
|
||||
t.Fatalf("Expected block to pass processing conditions: %v", err)
|
||||
}
|
||||
|
||||
if v, _ := beaconState.ValidatorAtIndex(proposerSlashings[0].ProposerIndex); !v.Slashed {
|
||||
v, err := beaconState.ValidatorAtIndex(proposerSlashings[0].ProposerIndex)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !v.Slashed {
|
||||
t.Errorf("Expected validator at index %d to be slashed, received false", proposerSlashings[0].ProposerIndex)
|
||||
}
|
||||
|
||||
if v, _ := beaconState.ValidatorAtIndex(1); !v.Slashed {
|
||||
v, err = beaconState.ValidatorAtIndex(1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !v.Slashed {
|
||||
t.Error("Expected validator at index 1 to be slashed, received false")
|
||||
}
|
||||
|
||||
v, _ := beaconState.ValidatorAtIndex(exit.Exit.ValidatorIndex)
|
||||
v, err = beaconState.ValidatorAtIndex(exit.Exit.ValidatorIndex)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
received := v.ExitEpoch
|
||||
wanted := params.BeaconConfig().FarFutureEpoch
|
||||
if received == wanted {
|
||||
@@ -669,7 +735,9 @@ func BenchmarkProcessBlk_65536Validators_FullBlock(b *testing.B) {
|
||||
buf = append(buf, hashed[:]...)
|
||||
v[3].WithdrawalCredentials = buf
|
||||
|
||||
s.SetValidators(v)
|
||||
if err := s.SetValidators(v); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
attestations := make([]*ethpb.Attestation, 128)
|
||||
for i := 0; i < len(attestations); i++ {
|
||||
@@ -714,10 +782,14 @@ func BenchmarkProcessBlk_65536Validators_FullBlock(b *testing.B) {
|
||||
v := s.Validators()
|
||||
v[1].Slashed = false
|
||||
v[2].Slashed = false
|
||||
s.SetValidators(v)
|
||||
b := s.Balances()
|
||||
b[3] += 2 * params.BeaconConfig().MinDepositAmount
|
||||
s.SetBalances(b)
|
||||
if err := s.SetValidators(v); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
balances := s.Balances()
|
||||
balances[3] += 2 * params.BeaconConfig().MinDepositAmount
|
||||
if err := s.SetBalances(balances); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -727,7 +799,9 @@ func TestProcessBlk_AttsBasedOnValidatorCount(t *testing.T) {
|
||||
// Default at 256 validators, can raise this number with faster BLS.
|
||||
validatorCount := uint64(256)
|
||||
s, privKeys := testutil.DeterministicGenesisState(t, validatorCount)
|
||||
s.SetSlot(params.BeaconConfig().SlotsPerEpoch)
|
||||
if err := s.SetSlot(params.BeaconConfig().SlotsPerEpoch); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
bitCount := validatorCount / params.BeaconConfig().SlotsPerEpoch
|
||||
aggBits := bitfield.NewBitlist(bitCount)
|
||||
@@ -769,8 +843,14 @@ func TestProcessBlk_AttsBasedOnValidatorCount(t *testing.T) {
|
||||
atts[i] = att
|
||||
}
|
||||
|
||||
epochSignature, _ := testutil.RandaoReveal(s, helpers.CurrentEpoch(s), privKeys)
|
||||
parentRoot, _ := ssz.HashTreeRoot(s.LatestBlockHeader())
|
||||
epochSignature, err := testutil.RandaoReveal(s, helpers.CurrentEpoch(s), privKeys)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
parentRoot, err := ssz.HashTreeRoot(s.LatestBlockHeader())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
blk := ðpb.SignedBeaconBlock{
|
||||
Block: ðpb.BeaconBlock{
|
||||
Slot: s.Slot(),
|
||||
@@ -852,7 +932,7 @@ func TestProcessOperations_OverMaxProposerSlashings(t *testing.T) {
|
||||
context.Background(),
|
||||
&beaconstate.BeaconState{},
|
||||
block.Body,
|
||||
); !strings.Contains(err.Error(), want) {
|
||||
); err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected %s, received %v", want, err)
|
||||
}
|
||||
}
|
||||
@@ -871,7 +951,7 @@ func TestProcessOperations_OverMaxAttesterSlashings(t *testing.T) {
|
||||
context.Background(),
|
||||
&beaconstate.BeaconState{},
|
||||
block.Body,
|
||||
); !strings.Contains(err.Error(), want) {
|
||||
); err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected %s, received %v", want, err)
|
||||
}
|
||||
}
|
||||
@@ -889,7 +969,7 @@ func TestProcessOperations_OverMaxAttestations(t *testing.T) {
|
||||
context.Background(),
|
||||
&beaconstate.BeaconState{},
|
||||
block.Body,
|
||||
); !strings.Contains(err.Error(), want) {
|
||||
); err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected %s, received %v", want, err)
|
||||
}
|
||||
}
|
||||
@@ -908,7 +988,7 @@ func TestProcessOperation_OverMaxVoluntaryExits(t *testing.T) {
|
||||
context.Background(),
|
||||
&beaconstate.BeaconState{},
|
||||
block.Body,
|
||||
); !strings.Contains(err.Error(), want) {
|
||||
); err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected %s, received %v", want, err)
|
||||
}
|
||||
}
|
||||
@@ -934,7 +1014,7 @@ func TestProcessOperations_IncorrectDeposits(t *testing.T) {
|
||||
context.Background(),
|
||||
s,
|
||||
block.Body,
|
||||
); !strings.Contains(err.Error(), want) {
|
||||
); err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Expected %s, received %v", want, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,7 +300,10 @@ func TestStore_DuplicatedAttestations_FiltersCorrectly(t *testing.T) {
|
||||
t.Errorf("Expected %d attestations, received %d", 1, len(retrievedAtts))
|
||||
}
|
||||
|
||||
att1 := proto.Clone(att).(*ethpb.Attestation)
|
||||
att1, ok := proto.Clone(att).(*ethpb.Attestation)
|
||||
if !ok {
|
||||
t.Error("Entity is not of type *ethpb.Attestation")
|
||||
}
|
||||
att1.Data.Source.Epoch = 6
|
||||
atts = []*ethpb.Attestation{att, att, att, att1, att1, att1}
|
||||
if err := db.SaveAttestations(ctx, atts); err != nil {
|
||||
|
||||
@@ -468,11 +468,17 @@ func TestStore_SaveBlock_CanGetHighestAt(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
block1 := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 1}}
|
||||
db.SaveBlock(ctx, block1)
|
||||
if err := db.SaveBlock(ctx, block1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
block2 := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 10}}
|
||||
db.SaveBlock(ctx, block2)
|
||||
if err := db.SaveBlock(ctx, block2); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
block3 := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 100}}
|
||||
db.SaveBlock(ctx, block3)
|
||||
if err := db.SaveBlock(ctx, block3); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
highestAt, err := db.HighestSlotBlocksBelow(ctx, 2)
|
||||
if err != nil {
|
||||
@@ -496,8 +502,13 @@ func TestStore_SaveBlock_CanGetHighestAt(t *testing.T) {
|
||||
t.Errorf("Wanted %v, received %v", block3, highestAt)
|
||||
}
|
||||
|
||||
r3, _ := ssz.HashTreeRoot(block3.Block)
|
||||
db.DeleteBlock(ctx, r3)
|
||||
r3, err := ssz.HashTreeRoot(block3.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.DeleteBlock(ctx, r3); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
highestAt, err = db.HighestSlotBlocksBelow(ctx, 101)
|
||||
if err != nil {
|
||||
@@ -514,11 +525,20 @@ func TestStore_GenesisBlock_CanGetHighestAt(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
genesisBlock := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
genesisRoot, _ := ssz.HashTreeRoot(genesisBlock.Block)
|
||||
db.SaveGenesisBlockRoot(ctx, genesisRoot)
|
||||
db.SaveBlock(ctx, genesisBlock)
|
||||
genesisRoot, err := ssz.HashTreeRoot(genesisBlock.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.SaveGenesisBlockRoot(ctx, genesisRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.SaveBlock(ctx, genesisBlock); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
block1 := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 1}}
|
||||
db.SaveBlock(ctx, block1)
|
||||
if err := db.SaveBlock(ctx, block1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
highestAt, err := db.HighestSlotBlocksBelow(ctx, 2)
|
||||
if err != nil {
|
||||
@@ -621,7 +641,10 @@ func TestStore_DeleteBlock_CanGetHighest(t *testing.T) {
|
||||
}
|
||||
|
||||
b51 := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 51}}
|
||||
r51, _ := ssz.HashTreeRoot(b51.Block)
|
||||
r51, err := ssz.HashTreeRoot(b51.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.SaveBlock(ctx, b51); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -651,6 +674,7 @@ func TestStore_DeleteBlocks_CanGetHighest(t *testing.T) {
|
||||
defer teardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
var err error
|
||||
b := make([]*ethpb.SignedBeaconBlock, 100)
|
||||
r := make([][32]byte, 100)
|
||||
for i := 0; i < 100; i++ {
|
||||
@@ -660,7 +684,10 @@ func TestStore_DeleteBlocks_CanGetHighest(t *testing.T) {
|
||||
Slot: uint64(i),
|
||||
},
|
||||
}
|
||||
r[i], _ = ssz.HashTreeRoot(b[i].Block)
|
||||
r[i], err = ssz.HashTreeRoot(b[i].Block)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := db.SaveBlocks(ctx, b); err != nil {
|
||||
|
||||
@@ -294,7 +294,10 @@ func TestStore_SaveDeleteState_CanGetHighest(t *testing.T) {
|
||||
|
||||
s0 := &pb.BeaconState{Slot: 1}
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 1}}
|
||||
r, _ := ssz.HashTreeRoot(b.Block)
|
||||
r, err := ssz.HashTreeRoot(b.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.SaveBlock(context.Background(), b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -308,7 +311,10 @@ func TestStore_SaveDeleteState_CanGetHighest(t *testing.T) {
|
||||
|
||||
s1 := &pb.BeaconState{Slot: 999}
|
||||
b = ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 999}}
|
||||
r1, _ := ssz.HashTreeRoot(b.Block)
|
||||
r1, err := ssz.HashTreeRoot(b.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.SaveBlock(context.Background(), b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -330,7 +336,10 @@ func TestStore_SaveDeleteState_CanGetHighest(t *testing.T) {
|
||||
|
||||
s2 := &pb.BeaconState{Slot: 1000}
|
||||
b = ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 1000}}
|
||||
r2, _ := ssz.HashTreeRoot(b.Block)
|
||||
r2, err := ssz.HashTreeRoot(b.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.SaveBlock(context.Background(), b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -350,7 +359,9 @@ func TestStore_SaveDeleteState_CanGetHighest(t *testing.T) {
|
||||
t.Errorf("Did not retrieve saved state: %v != %v", highest, s2)
|
||||
}
|
||||
|
||||
db.DeleteState(context.Background(), r2)
|
||||
if err := db.DeleteState(context.Background(), r2); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
highest, err = db.HighestSlotStates(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -359,7 +370,9 @@ func TestStore_SaveDeleteState_CanGetHighest(t *testing.T) {
|
||||
t.Errorf("Did not retrieve saved state: %v != %v", highest, s1)
|
||||
}
|
||||
|
||||
db.DeleteState(context.Background(), r1)
|
||||
if err := db.DeleteState(context.Background(), r1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
highest, err = db.HighestSlotStates(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -375,7 +388,10 @@ func TestStore_SaveDeleteState_CanGetHighestBelow(t *testing.T) {
|
||||
|
||||
s0 := &pb.BeaconState{Slot: 1}
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 1}}
|
||||
r, _ := ssz.HashTreeRoot(b.Block)
|
||||
r, err := ssz.HashTreeRoot(b.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.SaveBlock(context.Background(), b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -389,7 +405,10 @@ func TestStore_SaveDeleteState_CanGetHighestBelow(t *testing.T) {
|
||||
|
||||
s1 := &pb.BeaconState{Slot: 100}
|
||||
b = ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 100}}
|
||||
r1, _ := ssz.HashTreeRoot(b.Block)
|
||||
r1, err := ssz.HashTreeRoot(b.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.SaveBlock(context.Background(), b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -411,7 +430,10 @@ func TestStore_SaveDeleteState_CanGetHighestBelow(t *testing.T) {
|
||||
|
||||
s2 := &pb.BeaconState{Slot: 1000}
|
||||
b = ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 1000}}
|
||||
r2, _ := ssz.HashTreeRoot(b.Block)
|
||||
r2, err := ssz.HashTreeRoot(b.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.SaveBlock(context.Background(), b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -458,12 +480,19 @@ func TestStore_GenesisState_CanGetHighestBelow(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
genesisRoot := [32]byte{'a'}
|
||||
db.SaveGenesisBlockRoot(context.Background(), genesisRoot)
|
||||
db.SaveState(context.Background(), genesisState, genesisRoot)
|
||||
if err := db.SaveGenesisBlockRoot(context.Background(), genesisRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.SaveState(context.Background(), genesisState, genesisRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
s0 := &pb.BeaconState{Slot: 1}
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 1}}
|
||||
r, _ := ssz.HashTreeRoot(b.Block)
|
||||
r, err := ssz.HashTreeRoot(b.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.SaveBlock(context.Background(), b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,9 @@ func TestNodeClose_OK(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
|
||||
tmp := fmt.Sprintf("%s/datadirtest2", testutil.TempDir())
|
||||
os.RemoveAll(tmp)
|
||||
if err := os.RemoveAll(tmp); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
@@ -42,5 +44,7 @@ func TestNodeClose_OK(t *testing.T) {
|
||||
|
||||
testutil.AssertLogsContain(t, hook, "Stopping beacon node")
|
||||
|
||||
os.RemoveAll(tmp)
|
||||
if err := os.RemoveAll(tmp); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,9 +90,15 @@ func TestAggregateAttestations_MultipleAttestationsDifferentRoots(t *testing.T)
|
||||
Source: ðpb.Checkpoint{Root: mockRoot[:]},
|
||||
Target: ðpb.Checkpoint{Root: mockRoot[:]},
|
||||
}
|
||||
d1 := proto.Clone(d).(*ethpb.AttestationData)
|
||||
d1, ok := proto.Clone(d).(*ethpb.AttestationData)
|
||||
if !ok {
|
||||
t.Fatal("Entity is not of type *ethpb.AttestationData")
|
||||
}
|
||||
d1.Slot = 1
|
||||
d2 := proto.Clone(d).(*ethpb.AttestationData)
|
||||
d2, ok := proto.Clone(d).(*ethpb.AttestationData)
|
||||
if !ok {
|
||||
t.Fatal("Entity is not of type *ethpb.AttestationData")
|
||||
}
|
||||
d2.Slot = 2
|
||||
|
||||
sk := bls.RandKey()
|
||||
@@ -118,8 +124,14 @@ func TestAggregateAttestations_MultipleAttestationsDifferentRoots(t *testing.T)
|
||||
sort.Slice(received, func(i, j int) bool {
|
||||
return received[i].Data.Slot < received[j].Data.Slot
|
||||
})
|
||||
att1, _ := helpers.AggregateAttestations([]*ethpb.Attestation{atts[0], atts[1]})
|
||||
att2, _ := helpers.AggregateAttestations([]*ethpb.Attestation{atts[2], atts[3]})
|
||||
att1, err := helpers.AggregateAttestations([]*ethpb.Attestation{atts[0], atts[1]})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
att2, err := helpers.AggregateAttestations([]*ethpb.Attestation{atts[2], atts[3]})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
wanted := append(att1, att2...)
|
||||
if !reflect.DeepEqual(wanted, received) {
|
||||
t.Error("Did not aggregate attestations")
|
||||
|
||||
@@ -13,7 +13,11 @@ func BenchmarkAttCaches(b *testing.B) {
|
||||
att := ðpb.Attestation{}
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
ac.SaveUnaggregatedAttestation(att)
|
||||
ac.DeleteAggregatedAttestation(att)
|
||||
if err := ac.SaveUnaggregatedAttestation(att); err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
if err := ac.DeleteAggregatedAttestation(att); err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,9 +233,15 @@ func TestAggregateAndSaveForkChoiceAtts_Multiple(t *testing.T) {
|
||||
Source: ðpb.Checkpoint{Root: mockRoot[:]},
|
||||
Target: ðpb.Checkpoint{Root: mockRoot[:]},
|
||||
}
|
||||
d1 := proto.Clone(d).(*ethpb.AttestationData)
|
||||
d1, ok := proto.Clone(d).(*ethpb.AttestationData)
|
||||
if !ok {
|
||||
t.Fatal("Entity is not of type *ethpb.AttestationData")
|
||||
}
|
||||
d1.Slot = 1
|
||||
d2 := proto.Clone(d).(*ethpb.AttestationData)
|
||||
d2, ok := proto.Clone(d).(*ethpb.AttestationData)
|
||||
if !ok {
|
||||
t.Fatal("Entity is not of type *ethpb.AttestationData")
|
||||
}
|
||||
d2.Slot = 2
|
||||
|
||||
atts1 := []*ethpb.Attestation{
|
||||
|
||||
@@ -61,11 +61,20 @@ func TestPool_InsertAttesterSlashing(t *testing.T) {
|
||||
}
|
||||
|
||||
// We mark the following validators with some preconditions.
|
||||
exitedVal, _ := beaconState.ValidatorAtIndex(uint64(2))
|
||||
exitedVal, err := beaconState.ValidatorAtIndex(uint64(2))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
exitedVal.ExitEpoch = 0
|
||||
futureExitedVal, _ := beaconState.ValidatorAtIndex(uint64(4))
|
||||
futureExitedVal, err := beaconState.ValidatorAtIndex(uint64(4))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
futureExitedVal.ExitEpoch = 17
|
||||
slashedVal, _ := beaconState.ValidatorAtIndex(uint64(5))
|
||||
slashedVal, err := beaconState.ValidatorAtIndex(uint64(5))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
slashedVal.Slashed = true
|
||||
if err := beaconState.UpdateValidatorAtIndex(uint64(2), exitedVal); err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -45,11 +45,20 @@ func TestPool_InsertProposerSlashing(t *testing.T) {
|
||||
}
|
||||
|
||||
// We mark the following validators with some preconditions.
|
||||
exitedVal, _ := beaconState.ValidatorAtIndex(uint64(2))
|
||||
exitedVal, err := beaconState.ValidatorAtIndex(uint64(2))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
exitedVal.ExitEpoch = 0
|
||||
futureExitedVal, _ := beaconState.ValidatorAtIndex(uint64(4))
|
||||
futureExitedVal, err := beaconState.ValidatorAtIndex(uint64(4))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
futureExitedVal.ExitEpoch = 17
|
||||
slashedVal, _ := beaconState.ValidatorAtIndex(uint64(5))
|
||||
slashedVal, err := beaconState.ValidatorAtIndex(uint64(5))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
slashedVal.Slashed = true
|
||||
if err := beaconState.UpdateValidatorAtIndex(uint64(2), exitedVal); err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -576,7 +576,10 @@ func TestPeerProtectionIdempotent(t *testing.T) {
|
||||
cm := NewConnManager(10, 20, 0)
|
||||
SilencePeriod = 10 * time.Second
|
||||
|
||||
id, _ := tu.RandPeerID()
|
||||
id, err := tu.RandPeerID()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
cm.Protect(id, "global")
|
||||
cm.Protect(id, "global")
|
||||
cm.Protect(id, "global")
|
||||
|
||||
@@ -155,7 +155,11 @@ func TestStartDiscV5_DiscoverPeersWithSubnets(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s.Start()
|
||||
defer s.Stop()
|
||||
defer func() {
|
||||
if err := s.Stop(); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Wait for the nodes to have their local routing tables to be populated with the other nodes
|
||||
time.Sleep(discoveryWaitTime)
|
||||
@@ -232,7 +236,9 @@ func TestStaticPeering_PeersAreAdded(t *testing.T) {
|
||||
|
||||
defer func() {
|
||||
for _, h := range hosts {
|
||||
_ = h.Close()
|
||||
if err := h.Close(); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -247,7 +253,11 @@ func TestStaticPeering_PeersAreAdded(t *testing.T) {
|
||||
|
||||
s.Start()
|
||||
s.dv5Listener = &mockListener{}
|
||||
defer s.Stop()
|
||||
defer func() {
|
||||
if err := s.Stop(); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
peers := s.host.Network().Peers()
|
||||
|
||||
@@ -17,7 +17,11 @@ func TestPrivateKeyLoading(t *testing.T) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer os.Remove(file.Name())
|
||||
defer func() {
|
||||
if err := os.Remove(file.Name()); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}()
|
||||
key, _, err := crypto.GenerateSecp256k1Key(rand.Reader)
|
||||
if err != nil {
|
||||
t.Fatalf("Could not generate key: %v", err)
|
||||
@@ -46,7 +50,7 @@ func TestPrivateKeyLoading(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
newRaw, _ := newPkey.Raw()
|
||||
newRaw, err := newPkey.Raw()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -192,7 +192,10 @@ func TestPeerBadResponses(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
{
|
||||
bytes, _ := id.MarshalBinary()
|
||||
bytes, err := id.MarshalBinary()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fmt.Printf("%x\n", bytes)
|
||||
}
|
||||
|
||||
@@ -322,15 +325,24 @@ func TestDecay(t *testing.T) {
|
||||
p.Decay()
|
||||
|
||||
// Ensure the new values are as expected
|
||||
badResponses1, _ := p.BadResponses(pid1)
|
||||
badResponses1, err := p.BadResponses(pid1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if badResponses1 != 0 {
|
||||
t.Errorf("Unexpected bad responses for peer 0: expected 0, received %v", badResponses1)
|
||||
}
|
||||
badResponses2, _ := p.BadResponses(pid2)
|
||||
badResponses2, err := p.BadResponses(pid2)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if badResponses2 != 0 {
|
||||
t.Errorf("Unexpected bad responses for peer 0: expected 0, received %v", badResponses2)
|
||||
}
|
||||
badResponses3, _ := p.BadResponses(pid3)
|
||||
badResponses3, err := p.BadResponses(pid3)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if badResponses3 != 1 {
|
||||
t.Errorf("Unexpected bad responses for peer 0: expected 0, received %v", badResponses3)
|
||||
}
|
||||
@@ -500,7 +512,9 @@ func addPeer(t *testing.T, p *peers.Status, state peers.PeerConnectionState) pee
|
||||
// Set up some peers with different states
|
||||
mhBytes := []byte{0x11, 0x04}
|
||||
idBytes := make([]byte, 4)
|
||||
rand.Read(idBytes)
|
||||
if _, err := rand.Read(idBytes); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mhBytes = append(mhBytes, idBytes...)
|
||||
id, err := peer.IDFromBytes(mhBytes)
|
||||
if err != nil {
|
||||
|
||||
@@ -82,10 +82,15 @@ func createHost(t *testing.T, port int) (host.Host, *ecdsa.PrivateKey, net.IP) {
|
||||
}
|
||||
|
||||
func TestService_Stop_SetsStartedToFalse(t *testing.T) {
|
||||
s, _ := NewService(&Config{})
|
||||
s, err := NewService(&Config{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s.started = true
|
||||
s.dv5Listener = &mockListener{}
|
||||
_ = s.Stop()
|
||||
if err := s.Stop(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if s.started != false {
|
||||
t.Error("Expected Service.started to be false, got true")
|
||||
@@ -93,8 +98,13 @@ func TestService_Stop_SetsStartedToFalse(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestService_Stop_DontPanicIfDv5ListenerIsNotInited(t *testing.T) {
|
||||
s, _ := NewService(&Config{})
|
||||
_ = s.Stop()
|
||||
s, err := NewService(&Config{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.Stop(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestService_Start_OnlyStartsOnce(t *testing.T) {
|
||||
@@ -105,9 +115,16 @@ func TestService_Start_OnlyStartsOnce(t *testing.T) {
|
||||
UDPPort: 2000,
|
||||
Encoding: "ssz",
|
||||
}
|
||||
s, _ := NewService(cfg)
|
||||
s, err := NewService(cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s.dv5Listener = &mockListener{}
|
||||
defer s.Stop()
|
||||
defer func() {
|
||||
if err := s.Stop(); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}()
|
||||
s.Start()
|
||||
if s.started != true {
|
||||
t.Error("Expected service to be started")
|
||||
@@ -161,7 +178,9 @@ func TestListenForNewNodes(t *testing.T) {
|
||||
// close peers upon exit of test
|
||||
defer func() {
|
||||
for _, h := range hosts {
|
||||
_ = h.Close()
|
||||
if err := h.Close(); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -174,7 +193,11 @@ func TestListenForNewNodes(t *testing.T) {
|
||||
}
|
||||
|
||||
s.Start()
|
||||
defer s.Stop()
|
||||
defer func() {
|
||||
if err := s.Stop(); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}()
|
||||
|
||||
time.Sleep(4 * time.Second)
|
||||
peers := s.host.Network().Peers()
|
||||
@@ -190,14 +213,22 @@ func TestListenForNewNodes(t *testing.T) {
|
||||
|
||||
func TestPeer_Disconnect(t *testing.T) {
|
||||
h1, _, _ := createHost(t, 5000)
|
||||
defer h1.Close()
|
||||
defer func() {
|
||||
if err := h1.Close(); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}()
|
||||
|
||||
s := &Service{
|
||||
host: h1,
|
||||
}
|
||||
|
||||
h2, _, ipaddr := createHost(t, 5001)
|
||||
defer h2.Close()
|
||||
defer func() {
|
||||
if err := h2.Close(); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}()
|
||||
|
||||
h2Addr, err := multiaddr.NewMultiaddr(fmt.Sprintf("/ip4/%s/tcp/%d/p2p/%s", ipaddr, 5001, h2.ID()))
|
||||
if err != nil {
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
ma "github.com/multiformats/go-multiaddr"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// MockPeersProvider implements PeersProvider for testing.
|
||||
@@ -23,13 +24,25 @@ func (m *MockPeersProvider) Peers() *peers.Status {
|
||||
if m.peers == nil {
|
||||
m.peers = peers.NewStatus(5 /* maxBadResponses */)
|
||||
// Pretend we are connected to two peers
|
||||
id0, _ := peer.IDB58Decode("16Uiu2HAkyWZ4Ni1TpvDS8dPxsozmHY85KaiFjodQuV6Tz5tkHVeR")
|
||||
ma0, _ := ma.NewMultiaddr("/ip4/213.202.254.180/tcp/13000")
|
||||
id0, err := peer.IDB58Decode("16Uiu2HAkyWZ4Ni1TpvDS8dPxsozmHY85KaiFjodQuV6Tz5tkHVeR")
|
||||
if err != nil {
|
||||
log.WithError(err).Debug("Cannot decode")
|
||||
}
|
||||
ma0, err := ma.NewMultiaddr("/ip4/213.202.254.180/tcp/13000")
|
||||
if err != nil {
|
||||
log.WithError(err).Debug("Cannot create address")
|
||||
}
|
||||
m.peers.Add(id0, ma0, network.DirInbound, []uint64{})
|
||||
m.peers.SetConnectionState(id0, peers.PeerConnected)
|
||||
m.peers.SetChainState(id0, &pb.Status{FinalizedEpoch: uint64(10)})
|
||||
id1, _ := peer.IDB58Decode("16Uiu2HAm4HgJ9N1o222xK61o7LSgToYWoAy1wNTJRkh9gLZapVAy")
|
||||
ma1, _ := ma.NewMultiaddr("/ip4/52.23.23.253/tcp/30000/ipfs/QmfAgkmjiZNZhr2wFN9TwaRgHouMTBT6HELyzE5A3BT2wK/p2p-circuit")
|
||||
id1, err := peer.IDB58Decode("16Uiu2HAm4HgJ9N1o222xK61o7LSgToYWoAy1wNTJRkh9gLZapVAy")
|
||||
if err != nil {
|
||||
log.WithError(err).Debug("Cannot decode")
|
||||
}
|
||||
ma1, err := ma.NewMultiaddr("/ip4/52.23.23.253/tcp/30000/ipfs/QmfAgkmjiZNZhr2wFN9TwaRgHouMTBT6HELyzE5A3BT2wK/p2p-circuit")
|
||||
if err != nil {
|
||||
log.WithError(err).Debug("Cannot create address")
|
||||
}
|
||||
m.peers.Add(id1, ma1, network.DirOutbound, []uint64{})
|
||||
m.peers.SetConnectionState(id1, peers.PeerConnected)
|
||||
m.peers.SetChainState(id1, &pb.Status{FinalizedEpoch: uint64(11)})
|
||||
|
||||
@@ -83,7 +83,11 @@ func (p *TestP2P) ReceiveRPC(topic string, msg proto.Message) {
|
||||
if err != nil {
|
||||
p.t.Fatalf("Failed to open stream %v", err)
|
||||
}
|
||||
defer s.Close()
|
||||
defer func() {
|
||||
if err := s.Close(); err != nil {
|
||||
p.t.Log(err)
|
||||
}
|
||||
}()
|
||||
|
||||
n, err := p.Encoding().EncodeWithLength(s, msg)
|
||||
if err != nil {
|
||||
@@ -184,7 +188,9 @@ func (p *TestP2P) AddDisconnectionHandler(f func(ctx context.Context, id peer.ID
|
||||
// Must be handled in a goroutine as this callback cannot be blocking.
|
||||
go func() {
|
||||
p.peers.SetConnectionState(conn.RemotePeer(), peers.PeerDisconnecting)
|
||||
f(context.Background(), conn.RemotePeer())
|
||||
if err := f(context.Background(), conn.RemotePeer()); err != nil {
|
||||
logrus.WithError(err).Debug("Unable to invoke callback")
|
||||
}
|
||||
p.peers.SetConnectionState(conn.RemotePeer(), peers.PeerDisconnected)
|
||||
}()
|
||||
},
|
||||
|
||||
@@ -30,7 +30,10 @@ func TestProcessDeposit_OK(t *testing.T) {
|
||||
}
|
||||
web3Service = setDefaultMocks(web3Service)
|
||||
|
||||
deposits, _, _ := testutil.DeterministicDepositsAndKeys(1)
|
||||
deposits, _, err := testutil.DeterministicDepositsAndKeys(1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
eth1Data, err := testutil.DeterministicEth1Data(len(deposits))
|
||||
if err != nil {
|
||||
@@ -62,7 +65,10 @@ func TestProcessDeposit_InvalidMerkleBranch(t *testing.T) {
|
||||
}
|
||||
web3Service = setDefaultMocks(web3Service)
|
||||
|
||||
deposits, _, _ := testutil.DeterministicDepositsAndKeys(1)
|
||||
deposits, _, err := testutil.DeterministicDepositsAndKeys(1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
eth1Data, err := testutil.DeterministicEth1Data(len(deposits))
|
||||
if err != nil {
|
||||
@@ -97,7 +103,10 @@ func TestProcessDeposit_InvalidPublicKey(t *testing.T) {
|
||||
}
|
||||
web3Service = setDefaultMocks(web3Service)
|
||||
|
||||
deposits, _, _ := testutil.DeterministicDepositsAndKeys(1)
|
||||
deposits, _, err := testutil.DeterministicDepositsAndKeys(1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
deposits[0].Data.PublicKey = []byte("junk")
|
||||
|
||||
leaf, err := ssz.HashTreeRoot(deposits[0].Data)
|
||||
@@ -120,7 +129,9 @@ func TestProcessDeposit_InvalidPublicKey(t *testing.T) {
|
||||
DepositRoot: root[:],
|
||||
}
|
||||
|
||||
web3Service.processDeposit(eth1Data, deposits[0])
|
||||
if err := web3Service.processDeposit(eth1Data, deposits[0]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
testutil.AssertLogsContain(t, hook, pubKeyErr)
|
||||
}
|
||||
@@ -138,7 +149,10 @@ func TestProcessDeposit_InvalidSignature(t *testing.T) {
|
||||
}
|
||||
web3Service = setDefaultMocks(web3Service)
|
||||
|
||||
deposits, _, _ := testutil.DeterministicDepositsAndKeys(1)
|
||||
deposits, _, err := testutil.DeterministicDepositsAndKeys(1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var fakeSig [96]byte
|
||||
copy(fakeSig[:], []byte{'F', 'A', 'K', 'E'})
|
||||
deposits[0].Data.Signature = fakeSig[:]
|
||||
@@ -160,7 +174,9 @@ func TestProcessDeposit_InvalidSignature(t *testing.T) {
|
||||
DepositRoot: root[:],
|
||||
}
|
||||
|
||||
web3Service.processDeposit(eth1Data, deposits[0])
|
||||
if err := web3Service.processDeposit(eth1Data, deposits[0]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
testutil.AssertLogsContain(t, hook, pubKeyErr)
|
||||
}
|
||||
@@ -179,7 +195,10 @@ func TestProcessDeposit_UnableToVerify(t *testing.T) {
|
||||
web3Service = setDefaultMocks(web3Service)
|
||||
testutil.ResetCache()
|
||||
|
||||
deposits, keys, _ := testutil.DeterministicDepositsAndKeys(1)
|
||||
deposits, keys, err := testutil.DeterministicDepositsAndKeys(1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
domain := bls.ComputeDomain(params.BeaconConfig().DomainDeposit)
|
||||
|
||||
@@ -200,7 +219,9 @@ func TestProcessDeposit_UnableToVerify(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
deposits[0].Proof = proof
|
||||
web3Service.processDeposit(eth1Data, deposits[0])
|
||||
if err := web3Service.processDeposit(eth1Data, deposits[0]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := "signature did not verify"
|
||||
|
||||
testutil.AssertLogsContain(t, hook, want)
|
||||
@@ -296,7 +317,10 @@ func TestProcessDeposit_AllDepositedSuccessfully(t *testing.T) {
|
||||
web3Service = setDefaultMocks(web3Service)
|
||||
testutil.ResetCache()
|
||||
|
||||
deposits, keys, _ := testutil.DeterministicDepositsAndKeys(10)
|
||||
deposits, keys, err := testutil.DeterministicDepositsAndKeys(10)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
eth1Data, err := testutil.DeterministicEth1Data(len(deposits))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -61,7 +61,10 @@ func TestProcessDepositLog_OK(t *testing.T) {
|
||||
}
|
||||
|
||||
testAcc.Backend.Commit()
|
||||
deposits, _, _ := testutil.DeterministicDepositsAndKeys(1)
|
||||
deposits, _, err := testutil.DeterministicDepositsAndKeys(1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, depositRoots, err := testutil.DeterministicDepositTrie(len(deposits))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -90,7 +93,9 @@ func TestProcessDepositLog_OK(t *testing.T) {
|
||||
t.Fatal("no logs")
|
||||
}
|
||||
|
||||
web3Service.ProcessLog(context.Background(), logs[0])
|
||||
if err := web3Service.ProcessLog(context.Background(), logs[0]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
testutil.AssertLogsDoNotContain(t, hook, "Could not unpack log")
|
||||
testutil.AssertLogsDoNotContain(t, hook, "Could not save in trie")
|
||||
@@ -130,7 +135,10 @@ func TestProcessDepositLog_InsertsPendingDeposit(t *testing.T) {
|
||||
|
||||
testAcc.Backend.Commit()
|
||||
|
||||
deposits, _, _ := testutil.DeterministicDepositsAndKeys(1)
|
||||
deposits, _, err := testutil.DeterministicDepositsAndKeys(1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, depositRoots, err := testutil.DeterministicDepositTrie(len(deposits))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -163,8 +171,12 @@ func TestProcessDepositLog_InsertsPendingDeposit(t *testing.T) {
|
||||
|
||||
web3Service.chainStartData.Chainstarted = true
|
||||
|
||||
web3Service.ProcessDepositLog(context.Background(), logs[0])
|
||||
web3Service.ProcessDepositLog(context.Background(), logs[1])
|
||||
if err := web3Service.ProcessDepositLog(context.Background(), logs[0]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := web3Service.ProcessDepositLog(context.Background(), logs[1]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
pendingDeposits := web3Service.depositCache.PendingDeposits(context.Background(), nil /*blockNum*/)
|
||||
if len(pendingDeposits) != 2 {
|
||||
t.Errorf("Unexpected number of deposits. Wanted 2 deposit, got %+v", pendingDeposits)
|
||||
@@ -199,7 +211,10 @@ func TestUnpackDepositLogData_OK(t *testing.T) {
|
||||
t.Fatalf("Could not init from contract: %v", err)
|
||||
}
|
||||
|
||||
deposits, _, _ := testutil.DeterministicDepositsAndKeys(1)
|
||||
deposits, _, err := testutil.DeterministicDepositsAndKeys(1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, depositRoots, err := testutil.DeterministicDepositTrie(len(deposits))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -275,9 +290,14 @@ func TestProcessETH2GenesisLog_8DuplicatePubkeys(t *testing.T) {
|
||||
params.OverrideBeaconConfig(bConfig)
|
||||
|
||||
testAcc.Backend.Commit()
|
||||
testAcc.Backend.AdjustTime(time.Duration(int64(time.Now().Nanosecond())))
|
||||
if err := testAcc.Backend.AdjustTime(time.Duration(int64(time.Now().Nanosecond()))); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
deposits, _, _ := testutil.DeterministicDepositsAndKeys(1)
|
||||
deposits, _, err := testutil.DeterministicDepositsAndKeys(1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, depositRoots, err := testutil.DeterministicDepositTrie(len(deposits))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -311,7 +331,9 @@ func TestProcessETH2GenesisLog_8DuplicatePubkeys(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, log := range logs {
|
||||
web3Service.ProcessLog(context.Background(), log)
|
||||
if err := web3Service.ProcessLog(context.Background(), log); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
if web3Service.chainStartData.Chainstarted {
|
||||
@@ -353,9 +375,14 @@ func TestProcessETH2GenesisLog(t *testing.T) {
|
||||
params.OverrideBeaconConfig(bConfig)
|
||||
|
||||
testAcc.Backend.Commit()
|
||||
testAcc.Backend.AdjustTime(time.Duration(int64(time.Now().Nanosecond())))
|
||||
if err := testAcc.Backend.AdjustTime(time.Duration(int64(time.Now().Nanosecond()))); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
deposits, _, _ := testutil.DeterministicDepositsAndKeys(uint64(depositsReqForChainStart))
|
||||
deposits, _, err := testutil.DeterministicDepositsAndKeys(uint64(depositsReqForChainStart))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, roots, err := testutil.DeterministicDepositTrie(len(deposits))
|
||||
if err != nil {
|
||||
@@ -401,7 +428,9 @@ func TestProcessETH2GenesisLog(t *testing.T) {
|
||||
defer stateSub.Unsubscribe()
|
||||
|
||||
for _, log := range logs {
|
||||
web3Service.ProcessLog(context.Background(), log)
|
||||
if err := web3Service.ProcessLog(context.Background(), log); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
err = web3Service.ProcessETH1Block(context.Background(), big.NewInt(int64(logs[len(logs)-1].BlockNumber)))
|
||||
@@ -468,11 +497,16 @@ func TestProcessETH2GenesisLog_CorrectNumOfDeposits(t *testing.T) {
|
||||
flags.Get().DeploymentBlock = 0
|
||||
|
||||
testAcc.Backend.Commit()
|
||||
testAcc.Backend.AdjustTime(time.Duration(int64(time.Now().Nanosecond())))
|
||||
if err := testAcc.Backend.AdjustTime(time.Duration(int64(time.Now().Nanosecond()))); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
totalNumOfDeposits := depositsReqForChainStart + 30
|
||||
|
||||
deposits, _, _ := testutil.DeterministicDepositsAndKeys(uint64(totalNumOfDeposits))
|
||||
deposits, _, err := testutil.DeterministicDepositsAndKeys(uint64(totalNumOfDeposits))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, depositRoots, err := testutil.DeterministicDepositTrie(len(deposits))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -563,9 +597,14 @@ func TestWeb3ServiceProcessDepositLog_RequestMissedDeposits(t *testing.T) {
|
||||
params.OverrideBeaconConfig(bConfig)
|
||||
|
||||
testAcc.Backend.Commit()
|
||||
testAcc.Backend.AdjustTime(time.Duration(int64(time.Now().Nanosecond())))
|
||||
if err := testAcc.Backend.AdjustTime(time.Duration(int64(time.Now().Nanosecond()))); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
depositsWanted := 10
|
||||
deposits, _, _ := testutil.DeterministicDepositsAndKeys(uint64(depositsWanted))
|
||||
deposits, _, err := testutil.DeterministicDepositsAndKeys(uint64(depositsWanted))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, depositRoots, err := testutil.DeterministicDepositTrie(len(deposits))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -657,9 +696,14 @@ func TestConsistentGenesisState(t *testing.T) {
|
||||
web3Service := newPowchainService(t, testAcc, beaconDB)
|
||||
|
||||
testAcc.Backend.Commit()
|
||||
testAcc.Backend.AdjustTime(time.Duration(int64(time.Now().Nanosecond())))
|
||||
if err := testAcc.Backend.AdjustTime(time.Duration(int64(time.Now().Nanosecond()))); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
deposits, _, _ := testutil.DeterministicDepositsAndKeys(uint64(depositsReqForChainStart))
|
||||
deposits, _, err := testutil.DeterministicDepositsAndKeys(uint64(depositsReqForChainStart))
|
||||
if err != nil {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
_, roots, err := testutil.DeterministicDepositTrie(len(deposits))
|
||||
if err != nil {
|
||||
|
||||
@@ -413,14 +413,29 @@ func TestServer_GetChainHead(t *testing.T) {
|
||||
defer dbTest.TeardownDB(t, db)
|
||||
|
||||
finalizedBlock := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 1, ParentRoot: []byte{'A'}}}
|
||||
db.SaveBlock(context.Background(), finalizedBlock)
|
||||
fRoot, _ := ssz.HashTreeRoot(finalizedBlock.Block)
|
||||
if err := db.SaveBlock(context.Background(), finalizedBlock); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fRoot, err := ssz.HashTreeRoot(finalizedBlock.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
justifiedBlock := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 2, ParentRoot: []byte{'B'}}}
|
||||
db.SaveBlock(context.Background(), justifiedBlock)
|
||||
jRoot, _ := ssz.HashTreeRoot(justifiedBlock.Block)
|
||||
if err := db.SaveBlock(context.Background(), justifiedBlock); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
jRoot, err := ssz.HashTreeRoot(justifiedBlock.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
prevJustifiedBlock := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 3, ParentRoot: []byte{'C'}}}
|
||||
db.SaveBlock(context.Background(), prevJustifiedBlock)
|
||||
pjRoot, _ := ssz.HashTreeRoot(prevJustifiedBlock.Block)
|
||||
if err := db.SaveBlock(context.Background(), prevJustifiedBlock); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
pjRoot, err := ssz.HashTreeRoot(prevJustifiedBlock.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
s, err := stateTrie.InitializeFromProto(&pbp2p.BeaconState{
|
||||
Slot: 1,
|
||||
@@ -517,14 +532,29 @@ func TestServer_StreamChainHead_OnHeadUpdated(t *testing.T) {
|
||||
defer dbTest.TeardownDB(t, db)
|
||||
|
||||
finalizedBlock := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 1, ParentRoot: []byte{'A'}}}
|
||||
db.SaveBlock(context.Background(), finalizedBlock)
|
||||
fRoot, _ := ssz.HashTreeRoot(finalizedBlock.Block)
|
||||
if err := db.SaveBlock(context.Background(), finalizedBlock); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fRoot, err := ssz.HashTreeRoot(finalizedBlock.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
justifiedBlock := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 2, ParentRoot: []byte{'B'}}}
|
||||
db.SaveBlock(context.Background(), justifiedBlock)
|
||||
jRoot, _ := ssz.HashTreeRoot(justifiedBlock.Block)
|
||||
if err := db.SaveBlock(context.Background(), justifiedBlock); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
jRoot, err := ssz.HashTreeRoot(justifiedBlock.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
prevJustifiedBlock := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 3, ParentRoot: []byte{'C'}}}
|
||||
db.SaveBlock(context.Background(), prevJustifiedBlock)
|
||||
pjRoot, _ := ssz.HashTreeRoot(prevJustifiedBlock.Block)
|
||||
if err := db.SaveBlock(context.Background(), prevJustifiedBlock); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
pjRoot, err := ssz.HashTreeRoot(prevJustifiedBlock.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
s, err := stateTrie.InitializeFromProto(&pbp2p.BeaconState{
|
||||
Slot: 1,
|
||||
@@ -537,7 +567,10 @@ func TestServer_StreamChainHead_OnHeadUpdated(t *testing.T) {
|
||||
}
|
||||
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: s.PreviousJustifiedCheckpoint().Epoch*params.BeaconConfig().SlotsPerEpoch + 1}}
|
||||
hRoot, _ := ssz.HashTreeRoot(b.Block)
|
||||
hRoot, err := ssz.HashTreeRoot(b.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
chainService := &mock.ChainService{}
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -86,8 +86,12 @@ func TestServer_ListBeaconCommittees_PreviousEpoch(t *testing.T) {
|
||||
for i := 0; i < len(mixes); i++ {
|
||||
mixes[i] = make([]byte, 32)
|
||||
}
|
||||
headState.SetRandaoMixes(mixes)
|
||||
headState.SetSlot(params.BeaconConfig().SlotsPerEpoch * 2)
|
||||
if err := headState.SetRandaoMixes(mixes); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := headState.SetSlot(params.BeaconConfig().SlotsPerEpoch * 2); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
m := &mock.ChainService{
|
||||
State: headState,
|
||||
|
||||
@@ -69,7 +69,9 @@ func TestInfostream_HandleSetValidatorKeys(t *testing.T) {
|
||||
pubKeys: make([][]byte, 0),
|
||||
}
|
||||
for _, test := range tests {
|
||||
is.handleSetValidatorKeys(test.reqPubKeys)
|
||||
if err := is.handleSetValidatorKeys(test.reqPubKeys); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
if len(is.pubKeys) != len(test.reqPubKeys) {
|
||||
t.Errorf("Incorrect number of keys: expected %v, received %v", len(test.reqPubKeys), len(is.pubKeys))
|
||||
}
|
||||
@@ -112,8 +114,12 @@ func TestInfostream_HandleAddValidatorKeys(t *testing.T) {
|
||||
pubKeys: make([][]byte, 0),
|
||||
}
|
||||
for _, test := range tests {
|
||||
is.handleSetValidatorKeys(test.initialPubKeys)
|
||||
is.handleAddValidatorKeys(test.reqPubKeys)
|
||||
if err := is.handleSetValidatorKeys(test.initialPubKeys); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
if err := is.handleAddValidatorKeys(test.reqPubKeys); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
if len(is.pubKeys) != test.finalLen {
|
||||
t.Errorf("Incorrect number of keys: expected %v, received %v", len(is.pubKeys), test.finalLen)
|
||||
}
|
||||
@@ -156,7 +162,9 @@ func TestInfostream_HandleRemoveValidatorKeys(t *testing.T) {
|
||||
pubKeys: make([][]byte, 0),
|
||||
}
|
||||
for _, test := range tests {
|
||||
is.handleSetValidatorKeys(test.initialPubKeys)
|
||||
if err := is.handleSetValidatorKeys(test.initialPubKeys); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
is.handleRemoveValidatorKeys(test.reqPubKeys)
|
||||
if len(is.pubKeys) != test.finalLen {
|
||||
t.Errorf("Incorrect number of keys: expected %v, received %v", len(is.pubKeys), test.finalLen)
|
||||
|
||||
@@ -1437,12 +1437,15 @@ func TestServer_GetValidatorQueue_ExitedValidatorLeavesQueue(t *testing.T) {
|
||||
PublicKey: []byte("2"),
|
||||
},
|
||||
}
|
||||
headState, _ := stateTrie.InitializeFromProto(&pbp2p.BeaconState{
|
||||
headState, err := stateTrie.InitializeFromProto(&pbp2p.BeaconState{
|
||||
Validators: validators,
|
||||
FinalizedCheckpoint: ðpb.Checkpoint{
|
||||
Epoch: 0,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
bs := &Server{
|
||||
HeadFetcher: &mock.ChainService{
|
||||
State: headState,
|
||||
|
||||
@@ -43,8 +43,9 @@ func TestLifecycle_OK(t *testing.T) {
|
||||
|
||||
testutil.AssertLogsContain(t, hook, "listening on port")
|
||||
|
||||
rpcService.Stop()
|
||||
|
||||
if err := rpcService.Stop(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatus_CredentialError(t *testing.T) {
|
||||
@@ -75,5 +76,7 @@ func TestRPC_InsecureEndpoint(t *testing.T) {
|
||||
testutil.AssertLogsContain(t, hook, fmt.Sprint("listening on port"))
|
||||
testutil.AssertLogsContain(t, hook, "You are using an insecure gRPC connection")
|
||||
|
||||
rpcService.Stop()
|
||||
if err := rpcService.Stop(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,9 +53,12 @@ func TestSubmitAggregateAndProof_CantFindValidatorIndex(t *testing.T) {
|
||||
defer dbutil.TeardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
s, _ := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
s, err := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
server := &Server{
|
||||
HeadFetcher: &mock.ChainService{State: s},
|
||||
@@ -77,13 +80,16 @@ func TestSubmitAggregateAndProof_IsAggregator(t *testing.T) {
|
||||
defer dbutil.TeardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
s, _ := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
s, err := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
Validators: []*ethpb.Validator{
|
||||
ðpb.Validator{PublicKey: pubKey(0)},
|
||||
ðpb.Validator{PublicKey: pubKey(1)},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
server := &Server{
|
||||
HeadFetcher: &mock.ChainService{State: s},
|
||||
@@ -127,7 +133,10 @@ func TestSubmitAggregateAndProof_AggregateOk(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().MinAttestationInclusionDelay)
|
||||
err = beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().MinAttestationInclusionDelay)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
aggregatorServer := &Server{
|
||||
HeadFetcher: &mock.ChainService{State: beaconState},
|
||||
@@ -183,7 +192,10 @@ func TestSubmitAggregateAndProof_AggregateNotOk(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().MinAttestationInclusionDelay)
|
||||
err = beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().MinAttestationInclusionDelay)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
aggregatorServer := &Server{
|
||||
HeadFetcher: &mock.ChainService{State: beaconState},
|
||||
@@ -227,7 +239,10 @@ func generateAtt(state *beaconstate.BeaconState, index uint64, privKeys []*bls.S
|
||||
},
|
||||
AggregationBits: aggBits,
|
||||
}
|
||||
committee, _ := helpers.BeaconCommitteeFromState(state, att.Data.Slot, att.Data.CommitteeIndex)
|
||||
committee, err := helpers.BeaconCommitteeFromState(state, att.Data.Slot, att.Data.CommitteeIndex)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
attestingIndices := attestationutil.AttestingIndices(att.AggregationBits, committee)
|
||||
domain, err := helpers.Domain(state.Fork(), 0, params.BeaconConfig().DomainBeaconAttester)
|
||||
if err != nil {
|
||||
@@ -239,7 +254,10 @@ func generateAtt(state *beaconstate.BeaconState, index uint64, privKeys []*bls.S
|
||||
att.Signature = zeroSig[:]
|
||||
|
||||
for i, indice := range attestingIndices {
|
||||
hashTreeRoot, _ := ssz.HashTreeRoot(att.Data)
|
||||
hashTreeRoot, err := ssz.HashTreeRoot(att.Data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sig := privKeys[indice].Sign(hashTreeRoot[:], domain)
|
||||
sigs[i] = sig
|
||||
}
|
||||
|
||||
@@ -104,7 +104,10 @@ func TestGetDuties_OK(t *testing.T) {
|
||||
|
||||
genesis := blk.NewGenesisBlock([]byte{})
|
||||
depChainStart := params.BeaconConfig().MinGenesisActiveValidatorCount
|
||||
deposits, _, _ := testutil.DeterministicDepositsAndKeys(depChainStart)
|
||||
deposits, _, err := testutil.DeterministicDepositsAndKeys(depChainStart)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
eth1Data, err := testutil.DeterministicEth1Data(len(deposits))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -187,7 +190,10 @@ func TestGetDuties_CurrentEpoch_ShouldNotFail(t *testing.T) {
|
||||
|
||||
genesis := blk.NewGenesisBlock([]byte{})
|
||||
depChainStart := params.BeaconConfig().MinGenesisActiveValidatorCount
|
||||
deposits, _, _ := testutil.DeterministicDepositsAndKeys(depChainStart)
|
||||
deposits, _, err := testutil.DeterministicDepositsAndKeys(depChainStart)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
eth1Data, err := testutil.DeterministicEth1Data(len(deposits))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -196,7 +202,10 @@ func TestGetDuties_CurrentEpoch_ShouldNotFail(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Could not setup genesis state: %v", err)
|
||||
}
|
||||
bState.SetSlot(5) // Set state to non-epoch start slot.
|
||||
// Set state to non-epoch start slot.
|
||||
if err := bState.SetSlot(5); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
genesisRoot, err := ssz.HashTreeRoot(genesis.Block)
|
||||
if err != nil {
|
||||
@@ -236,7 +245,10 @@ func TestGetDuties_MultipleKeys_OK(t *testing.T) {
|
||||
|
||||
genesis := blk.NewGenesisBlock([]byte{})
|
||||
depChainStart := uint64(64)
|
||||
deposits, _, _ := testutil.DeterministicDepositsAndKeys(depChainStart)
|
||||
deposits, _, err := testutil.DeterministicDepositsAndKeys(depChainStart)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
eth1Data, err := testutil.DeterministicEth1Data(len(deposits))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -303,7 +315,10 @@ func BenchmarkCommitteeAssignment(b *testing.B) {
|
||||
|
||||
genesis := blk.NewGenesisBlock([]byte{})
|
||||
depChainStart := uint64(8192 * 2)
|
||||
deposits, _, _ := testutil.DeterministicDepositsAndKeys(depChainStart)
|
||||
deposits, _, err := testutil.DeterministicDepositsAndKeys(depChainStart)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
eth1Data, err := testutil.DeterministicEth1Data(len(deposits))
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
|
||||
@@ -65,11 +65,14 @@ func TestProposeAttestation_OK(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
state, _ := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
state, err := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
Slot: params.BeaconConfig().SlotsPerEpoch + 1,
|
||||
Validators: validators,
|
||||
RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := db.SaveState(ctx, state, root); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -156,7 +159,10 @@ func TestGetAttestationData_OK(t *testing.T) {
|
||||
beaconState.BlockRoots[1] = blockRoot[:]
|
||||
beaconState.BlockRoots[1*params.BeaconConfig().SlotsPerEpoch] = targetRoot[:]
|
||||
beaconState.BlockRoots[2*params.BeaconConfig().SlotsPerEpoch] = justifiedRoot[:]
|
||||
s, _ := beaconstate.InitializeFromProto(beaconState)
|
||||
s, err := beaconstate.InitializeFromProto(beaconState)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
chainService := &mock.ChainService{
|
||||
Genesis: time.Now(),
|
||||
}
|
||||
@@ -270,7 +276,10 @@ func TestAttestationDataAtSlot_HandlesFarAwayJustifiedEpoch(t *testing.T) {
|
||||
beaconState.BlockRoots[1] = blockRoot[:]
|
||||
beaconState.BlockRoots[1*params.BeaconConfig().SlotsPerEpoch] = epochBoundaryRoot[:]
|
||||
beaconState.BlockRoots[2*params.BeaconConfig().SlotsPerEpoch] = justifiedBlockRoot[:]
|
||||
s, _ := beaconstate.InitializeFromProto(beaconState)
|
||||
s, err := beaconstate.InitializeFromProto(beaconState)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
chainService := &mock.ChainService{
|
||||
Genesis: time.Now(),
|
||||
}
|
||||
@@ -323,7 +332,10 @@ func TestAttestationDataAtSlot_HandlesFarAwayJustifiedEpoch(t *testing.T) {
|
||||
|
||||
func TestAttestationDataSlot_handlesInProgressRequest(t *testing.T) {
|
||||
s := &pbp2p.BeaconState{Slot: 100}
|
||||
state, _ := beaconstate.InitializeFromProto(s)
|
||||
state, err := beaconstate.InitializeFromProto(s)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ctx := context.Background()
|
||||
chainService := &mock.ChainService{
|
||||
Genesis: time.Now(),
|
||||
@@ -411,7 +423,10 @@ func TestWaitForSlotOneThird_HeadIsHereNoWait(t *testing.T) {
|
||||
genesisTime := currentTime - (numOfSlots * params.BeaconConfig().SecondsPerSlot)
|
||||
|
||||
s := &pbp2p.BeaconState{Slot: 2}
|
||||
state, _ := beaconstate.InitializeFromProto(s)
|
||||
state, err := beaconstate.InitializeFromProto(s)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
server := &Server{
|
||||
AttestationCache: cache.NewAttestationCache(),
|
||||
HeadFetcher: &mock.ChainService{State: state},
|
||||
@@ -498,10 +513,16 @@ func TestServer_GetAttestationData_HeadStateSlotGreaterThanRequestSlot(t *testin
|
||||
beaconState.BlockRoots[1] = blockRoot[:]
|
||||
beaconState.BlockRoots[1*params.BeaconConfig().SlotsPerEpoch] = targetRoot[:]
|
||||
beaconState.BlockRoots[2*params.BeaconConfig().SlotsPerEpoch] = justifiedRoot[:]
|
||||
s, _ := beaconstate.InitializeFromProto(beaconState)
|
||||
s, err := beaconstate.InitializeFromProto(beaconState)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
beaconState2 := s.CloneInnerState()
|
||||
beaconState2.Slot--
|
||||
s2, _ := beaconstate.InitializeFromProto(beaconState2)
|
||||
s2, err := beaconstate.InitializeFromProto(beaconState2)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.SaveState(ctx, s2, blockRoot2); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -593,7 +614,10 @@ func TestGetAttestationData_SucceedsInFirstEpoch(t *testing.T) {
|
||||
beaconState.BlockRoots[1] = blockRoot[:]
|
||||
beaconState.BlockRoots[1*params.BeaconConfig().SlotsPerEpoch] = targetRoot[:]
|
||||
beaconState.BlockRoots[2*params.BeaconConfig().SlotsPerEpoch] = justifiedRoot[:]
|
||||
s, _ := beaconstate.InitializeFromProto(beaconState)
|
||||
s, err := beaconstate.InitializeFromProto(beaconState)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
chainService := &mock.ChainService{
|
||||
Genesis: time.Now(),
|
||||
}
|
||||
|
||||
@@ -24,7 +24,10 @@ func TestSub(t *testing.T) {
|
||||
db := dbutil.SetupDB(t)
|
||||
defer dbutil.TeardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
deposits, _, _ := testutil.DeterministicDepositsAndKeys(params.BeaconConfig().MinGenesisActiveValidatorCount)
|
||||
deposits, _, err := testutil.DeterministicDepositsAndKeys(params.BeaconConfig().MinGenesisActiveValidatorCount)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
beaconState, err := state.GenesisBeaconState(deposits, 0, ðpb.Eth1Data{BlockHash: make([]byte, 32)})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -80,7 +83,10 @@ func TestSub(t *testing.T) {
|
||||
case event := <-opChannel:
|
||||
if event.Type == opfeed.ExitReceived {
|
||||
notificationFound = true
|
||||
data := event.Data.(*opfeed.ExitReceivedData)
|
||||
data, ok := event.Data.(*opfeed.ExitReceivedData)
|
||||
if !ok {
|
||||
t.Error("Entity is not of type *opfeed.ExitReceivedData")
|
||||
}
|
||||
if epoch != data.Exit.Exit.Epoch {
|
||||
t.Errorf("Unexpected state feed epoch: expected %v, found %v", epoch, data.Exit.Exit.Epoch)
|
||||
}
|
||||
|
||||
@@ -359,7 +359,9 @@ func TestComputeStateRoot_OK(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
beaconState.SetSlot(beaconState.Slot() + 1)
|
||||
if err := beaconState.SetSlot(beaconState.Slot() + 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
randaoReveal, err := testutil.RandaoReveal(beaconState, 0, privKeys)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
@@ -368,7 +370,9 @@ func TestComputeStateRoot_OK(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
beaconState.SetSlot(beaconState.Slot() - 1)
|
||||
if err := beaconState.SetSlot(beaconState.Slot() - 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
req.Block.Body.RandaoReveal = randaoReveal[:]
|
||||
signingRoot, err := ssz.HashTreeRoot(req.Block)
|
||||
if err != nil {
|
||||
@@ -416,7 +420,7 @@ func TestPendingDeposits_Eth1DataVoteOK(t *testing.T) {
|
||||
|
||||
blockHash = make([]byte, 32)
|
||||
copy(blockHash, "0x0")
|
||||
beaconState, _ := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
beaconState, err := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
DepositRoot: make([]byte, 32),
|
||||
BlockHash: blockHash,
|
||||
@@ -425,6 +429,9 @@ func TestPendingDeposits_Eth1DataVoteOK(t *testing.T) {
|
||||
Eth1DepositIndex: 2,
|
||||
Eth1DataVotes: votes,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
blk := ðpb.BeaconBlock{
|
||||
Body: ðpb.BeaconBlockBody{Eth1Data: ðpb.Eth1Data{}},
|
||||
@@ -498,12 +505,15 @@ func TestPendingDeposits_OutsideEth1FollowWindow(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
beaconState, _ := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
beaconState, err := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
BlockHash: []byte("0x0"),
|
||||
},
|
||||
Eth1DepositIndex: 2,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var mockSig [96]byte
|
||||
var mockCreds [32]byte
|
||||
@@ -638,7 +648,7 @@ func TestPendingDeposits_FollowsCorrectEth1Block(t *testing.T) {
|
||||
votes = append(votes, vote)
|
||||
}
|
||||
|
||||
beaconState, _ := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
beaconState, err := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
BlockHash: []byte("0x0"),
|
||||
DepositCount: 5,
|
||||
@@ -646,6 +656,9 @@ func TestPendingDeposits_FollowsCorrectEth1Block(t *testing.T) {
|
||||
Eth1DepositIndex: 1,
|
||||
Eth1DataVotes: votes,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
blk := ðpb.BeaconBlock{
|
||||
Slot: beaconState.Slot(),
|
||||
}
|
||||
@@ -767,13 +780,16 @@ func TestPendingDeposits_CantReturnBelowStateEth1DepositIndex(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
beaconState, _ := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
beaconState, err := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
BlockHash: []byte("0x0"),
|
||||
DepositCount: 100,
|
||||
},
|
||||
Eth1DepositIndex: 10,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
blk := ðpb.BeaconBlock{
|
||||
Slot: beaconState.Slot(),
|
||||
}
|
||||
@@ -874,13 +890,16 @@ func TestPendingDeposits_CantReturnMoreThanMax(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
beaconState, _ := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
beaconState, err := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
BlockHash: []byte("0x0"),
|
||||
DepositCount: 100,
|
||||
},
|
||||
Eth1DepositIndex: 2,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
blk := ðpb.BeaconBlock{
|
||||
Slot: beaconState.Slot(),
|
||||
}
|
||||
@@ -978,13 +997,16 @@ func TestPendingDeposits_CantReturnMoreDepositCount(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
beaconState, _ := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
beaconState, err := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
BlockHash: []byte("0x0"),
|
||||
DepositCount: 5,
|
||||
},
|
||||
Eth1DepositIndex: 2,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
blk := ðpb.BeaconBlock{
|
||||
Slot: beaconState.Slot(),
|
||||
}
|
||||
@@ -1072,12 +1094,15 @@ func TestPendingDeposits_CantReturnMoreDepositCount(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEth1Data_EmptyVotesFetchBlockHashFailure(t *testing.T) {
|
||||
beaconState, _ := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
beaconState, err := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
BlockHash: []byte{'a'},
|
||||
},
|
||||
Eth1DataVotes: []*ethpb.Eth1Data{},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p := &mockPOW.FaultyMockPOWChain{
|
||||
HashesByHeight: make(map[int][]byte),
|
||||
}
|
||||
@@ -1320,7 +1345,10 @@ func TestFilterAttestation_OK(t *testing.T) {
|
||||
atts[i].Signature = zeroSig[:]
|
||||
|
||||
for i, indice := range attestingIndices {
|
||||
hashTreeRoot, _ := ssz.HashTreeRoot(atts[i].Data)
|
||||
hashTreeRoot, err := ssz.HashTreeRoot(atts[i].Data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sig := privKeys[indice].Sign(hashTreeRoot[:], domain)
|
||||
sigs[i] = sig
|
||||
}
|
||||
@@ -1341,12 +1369,15 @@ func Benchmark_Eth1Data(b *testing.B) {
|
||||
|
||||
hashesByHeight := make(map[int][]byte)
|
||||
|
||||
beaconState, _ := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
beaconState, err := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
Eth1DataVotes: []*ethpb.Eth1Data{},
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
BlockHash: []byte("stub"),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
var mockSig [96]byte
|
||||
var mockCreds [32]byte
|
||||
deposits := []*dbpb.DepositContainer{
|
||||
@@ -1380,10 +1411,13 @@ func Benchmark_Eth1Data(b *testing.B) {
|
||||
for i := 0; i < numOfVotes; i++ {
|
||||
blockhash := []byte{'b', 'l', 'o', 'c', 'k', byte(i)}
|
||||
deposit := []byte{'d', 'e', 'p', 'o', 's', 'i', 't', byte(i)}
|
||||
beaconState.SetEth1DataVotes(append(beaconState.Eth1DataVotes(), ðpb.Eth1Data{
|
||||
err := beaconState.SetEth1DataVotes(append(beaconState.Eth1DataVotes(), ðpb.Eth1Data{
|
||||
BlockHash: blockhash,
|
||||
DepositRoot: deposit,
|
||||
}))
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
hashesByHeight[i] = blockhash
|
||||
}
|
||||
hashesByHeight[numOfVotes+1] = []byte("stub")
|
||||
@@ -1431,12 +1465,15 @@ func TestDeposits_ReturnsEmptyList_IfLatestEth1DataEqGenesisEth1Block(t *testing
|
||||
GenesisEth1Block: height,
|
||||
}
|
||||
|
||||
beaconState, _ := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
beaconState, err := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
BlockHash: []byte("0x0"),
|
||||
},
|
||||
Eth1DepositIndex: 2,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
blk := ðpb.BeaconBlock{
|
||||
Slot: beaconState.Slot(),
|
||||
}
|
||||
|
||||
@@ -39,16 +39,22 @@ func TestValidatorIndex_OK(t *testing.T) {
|
||||
db := dbutil.SetupDB(t)
|
||||
defer dbutil.TeardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
st, _ := stateTrie.InitializeFromProtoUnsafe(&pbp2p.BeaconState{})
|
||||
st, err := stateTrie.InitializeFromProtoUnsafe(&pbp2p.BeaconState{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.SaveState(ctx, st.Copy(), [32]byte{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
pubKey := pubKey(1)
|
||||
|
||||
st.SetValidators([]*ethpb.Validator{
|
||||
err = st.SetValidators([]*ethpb.Validator{
|
||||
ðpb.Validator{PublicKey: pubKey},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Server := &Server{
|
||||
BeaconDB: db,
|
||||
@@ -68,10 +74,13 @@ func TestWaitForActivation_ContextClosed(t *testing.T) {
|
||||
defer dbutil.TeardownDB(t, db)
|
||||
ctx := context.Background()
|
||||
|
||||
beaconState, _ := stateTrie.InitializeFromProto(&pbp2p.BeaconState{
|
||||
beaconState, err := stateTrie.InitializeFromProto(&pbp2p.BeaconState{
|
||||
Slot: 0,
|
||||
Validators: []*ethpb.Validator{},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
block := blk.NewGenesisBlock([]byte{})
|
||||
if err := db.SaveBlock(ctx, block); err != nil {
|
||||
t.Fatalf("Could not save genesis block: %v", err)
|
||||
|
||||
@@ -88,7 +88,7 @@ func TestValidatorStatus_Pending(t *testing.T) {
|
||||
t.Fatalf("Could not get signing root %v", err)
|
||||
}
|
||||
// Pending active because activation epoch is still defaulted at far future slot.
|
||||
state, _ := stateTrie.InitializeFromProto(&pbp2p.BeaconState{
|
||||
state, err := stateTrie.InitializeFromProto(&pbp2p.BeaconState{
|
||||
Validators: []*ethpb.Validator{
|
||||
{
|
||||
ActivationEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||
@@ -99,6 +99,9 @@ func TestValidatorStatus_Pending(t *testing.T) {
|
||||
},
|
||||
Slot: 5000,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.SaveState(ctx, state, genesisRoot); err != nil {
|
||||
t.Fatalf("could not save state: %v", err)
|
||||
}
|
||||
@@ -403,13 +406,16 @@ func TestValidatorStatus_Exited(t *testing.T) {
|
||||
if err := db.SaveHeadBlockRoot(ctx, genesisRoot); err != nil {
|
||||
t.Fatalf("Could not save genesis state: %v", err)
|
||||
}
|
||||
state, _ := stateTrie.InitializeFromProto(&pbp2p.BeaconState{
|
||||
state, err := stateTrie.InitializeFromProto(&pbp2p.BeaconState{
|
||||
Slot: slot,
|
||||
Validators: []*ethpb.Validator{{
|
||||
PublicKey: pubKey,
|
||||
WithdrawableEpoch: epoch + 1},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
depData := ðpb.Deposit_Data{
|
||||
PublicKey: pubKey,
|
||||
Signature: []byte("hi"),
|
||||
|
||||
@@ -54,5 +54,6 @@ go_test(
|
||||
"@com_github_gogo_protobuf//proto:go_default_library",
|
||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -52,8 +52,12 @@ func TestFieldTrie_RecomputeTrie(t *testing.T) {
|
||||
val2.ExitEpoch = 40
|
||||
|
||||
changedVals := []*ethpb.Validator{val1, val2}
|
||||
newState.UpdateValidatorAtIndex(changedIdx[0], changedVals[0])
|
||||
newState.UpdateValidatorAtIndex(changedIdx[1], changedVals[1])
|
||||
if err := newState.UpdateValidatorAtIndex(changedIdx[0], changedVals[0]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := newState.UpdateValidatorAtIndex(changedIdx[1], changedVals[1]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
expectedRoot, err := stateutil.ValidatorRegistryRoot(newState.Validators())
|
||||
if err != nil {
|
||||
@@ -81,8 +85,12 @@ func TestFieldTrie_CopyTrieImmutable(t *testing.T) {
|
||||
changedIdx := []uint64{2, 29}
|
||||
|
||||
changedVals := [][32]byte{{'A', 'B'}, {'C', 'D'}}
|
||||
newState.UpdateRandaoMixesAtIndex(changedVals[0][:], changedIdx[0])
|
||||
newState.UpdateRandaoMixesAtIndex(changedVals[1][:], changedIdx[1])
|
||||
if err := newState.UpdateRandaoMixesAtIndex(changedVals[0][:], changedIdx[0]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := newState.UpdateRandaoMixesAtIndex(changedVals[1][:], changedIdx[1]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
root, err := trie.RecomputeTrie(changedIdx, newState.RandaoMixes())
|
||||
if err != nil {
|
||||
|
||||
@@ -8,12 +8,17 @@ import (
|
||||
)
|
||||
|
||||
func TestBeaconState_SlotDataRace(t *testing.T) {
|
||||
headState, _ := InitializeFromProto(&pb.BeaconState{Slot: 1})
|
||||
headState, err := InitializeFromProto(&pb.BeaconState{Slot: 1})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(2)
|
||||
go func() {
|
||||
headState.SetSlot(uint64(0))
|
||||
if err := headState.SetSlot(uint64(0)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
go func() {
|
||||
|
||||
@@ -10,7 +10,10 @@ import (
|
||||
func TestStateReferenceSharing_Finalizer(t *testing.T) {
|
||||
// This test showcases the logic on a the RandaoMixes field with the GC finalizer.
|
||||
|
||||
a, _ := InitializeFromProtoUnsafe(&p2ppb.BeaconState{RandaoMixes: [][]byte{[]byte("foo")}})
|
||||
a, err := InitializeFromProtoUnsafe(&p2ppb.BeaconState{RandaoMixes: [][]byte{[]byte("foo")}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if a.sharedFieldReferences[randaoMixes].refs != 1 {
|
||||
t.Error("Expected a single reference for Randao mixes")
|
||||
}
|
||||
@@ -33,7 +36,9 @@ func TestStateReferenceSharing_Finalizer(t *testing.T) {
|
||||
if b.sharedFieldReferences[randaoMixes].refs != 2 {
|
||||
t.Error("Expected 2 shared references to randao mixes")
|
||||
}
|
||||
b.UpdateRandaoMixesAtIndex([]byte("bar"), 0)
|
||||
if err := b.UpdateRandaoMixesAtIndex([]byte("bar"), 0); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if b.sharedFieldReferences[randaoMixes].refs != 1 || a.sharedFieldReferences[randaoMixes].refs != 1 {
|
||||
t.Error("Expected 1 shared reference to randao mix for both a and b")
|
||||
}
|
||||
|
||||
@@ -21,7 +21,9 @@ func TestSaveColdState_NonArchivedPoint(t *testing.T) {
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
service.slotsPerArchivedPoint = 2
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
beaconState.SetSlot(1)
|
||||
if err := beaconState.SetSlot(1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := service.saveColdState(ctx, [32]byte{}, beaconState); err != errSlotNonArchivedPoint {
|
||||
t.Error("Did not get wanted error")
|
||||
@@ -36,7 +38,9 @@ func TestSaveColdState_CanSave(t *testing.T) {
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
service.slotsPerArchivedPoint = 1
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
beaconState.SetSlot(1)
|
||||
if err := beaconState.SetSlot(1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
r := [32]byte{'a'}
|
||||
if err := service.saveColdState(ctx, r, beaconState); err != nil {
|
||||
@@ -73,8 +77,13 @@ func TestLoadColdStateByRoot_CanGet(t *testing.T) {
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
blk := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
blkRoot, _ := ssz.HashTreeRoot(blk.Block)
|
||||
service.beaconDB.SaveGenesisBlockRoot(ctx, blkRoot)
|
||||
blkRoot, err := ssz.HashTreeRoot(blk.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveGenesisBlockRoot(ctx, blkRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveState(ctx, beaconState, blkRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -104,8 +113,13 @@ func TestLoadColdStateBySlot_CanGet(t *testing.T) {
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
blk := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
blkRoot, _ := ssz.HashTreeRoot(blk.Block)
|
||||
service.beaconDB.SaveGenesisBlockRoot(ctx, blkRoot)
|
||||
blkRoot, err := ssz.HashTreeRoot(blk.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveGenesisBlockRoot(ctx, blkRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveState(ctx, beaconState, blkRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -27,11 +27,18 @@ func TestStateByRoot_ColdState(t *testing.T) {
|
||||
if err := db.SaveBlock(ctx, b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
bRoot, _ := ssz.HashTreeRoot(b.Block)
|
||||
bRoot, err := ssz.HashTreeRoot(b.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
beaconState.SetSlot(1)
|
||||
service.beaconDB.SaveState(ctx, beaconState, bRoot)
|
||||
if err := beaconState.SetSlot(1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveState(ctx, beaconState, bRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r := [32]byte{'a'}
|
||||
if err := service.beaconDB.SaveStateSummary(ctx, &pb.StateSummary{
|
||||
Root: r[:],
|
||||
@@ -58,8 +65,13 @@ func TestStateByRoot_HotStateDB(t *testing.T) {
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
blk := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
blkRoot, _ := ssz.HashTreeRoot(blk.Block)
|
||||
service.beaconDB.SaveGenesisBlockRoot(ctx, blkRoot)
|
||||
blkRoot, err := ssz.HashTreeRoot(blk.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveGenesisBlockRoot(ctx, blkRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveState(ctx, beaconState, blkRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -116,16 +128,23 @@ func TestStateBySlot_ColdState(t *testing.T) {
|
||||
service.splitInfo.slot = service.slotsPerArchivedPoint + 1
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
beaconState.SetSlot(1)
|
||||
if err := beaconState.SetSlot(1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 1}}
|
||||
if err := db.SaveBlock(ctx, b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
bRoot, _ := ssz.HashTreeRoot(b.Block)
|
||||
bRoot, err := ssz.HashTreeRoot(b.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.SaveState(ctx, beaconState, bRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
db.SaveGenesisBlockRoot(ctx, bRoot)
|
||||
if err := db.SaveGenesisBlockRoot(ctx, bRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
r := [32]byte{}
|
||||
if err := service.beaconDB.SaveArchivedPointRoot(ctx, r, 0); err != nil {
|
||||
@@ -163,11 +182,16 @@ func TestStateBySlot_HotStateDB(t *testing.T) {
|
||||
if err := db.SaveBlock(ctx, b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
bRoot, _ := ssz.HashTreeRoot(b.Block)
|
||||
bRoot, err := ssz.HashTreeRoot(b.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.SaveState(ctx, beaconState, bRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
db.SaveGenesisBlockRoot(ctx, bRoot)
|
||||
if err := db.SaveGenesisBlockRoot(ctx, bRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
slot := uint64(10)
|
||||
loadedState, err := service.StateBySlot(ctx, slot)
|
||||
|
||||
@@ -25,7 +25,9 @@ func TestSaveHotState_AlreadyHas(t *testing.T) {
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch)
|
||||
if err := beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r := [32]byte{'A'}
|
||||
|
||||
// Pre cache the hot state.
|
||||
@@ -52,7 +54,9 @@ func TestSaveHotState_CanSaveOnEpochBoundary(t *testing.T) {
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch)
|
||||
if err := beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r := [32]byte{'A'}
|
||||
|
||||
if err := service.saveHotState(ctx, r, beaconState); err != nil {
|
||||
@@ -77,13 +81,18 @@ func TestSaveHotState_NoSaveNotEpochBoundary(t *testing.T) {
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch - 1)
|
||||
if err := beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch - 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r := [32]byte{'A'}
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
if err := db.SaveBlock(ctx, b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
gRoot, _ := ssz.HashTreeRoot(b.Block)
|
||||
gRoot, err := ssz.HashTreeRoot(b.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.SaveGenesisBlockRoot(ctx, gRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -131,8 +140,13 @@ func TestLoadHoteStateByRoot_FromDBCanProcess(t *testing.T) {
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
blk := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
blkRoot, _ := ssz.HashTreeRoot(blk.Block)
|
||||
service.beaconDB.SaveGenesisBlockRoot(ctx, blkRoot)
|
||||
blkRoot, err := ssz.HashTreeRoot(blk.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveGenesisBlockRoot(ctx, blkRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveState(ctx, beaconState, blkRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -164,8 +178,13 @@ func TestLoadHoteStateByRoot_FromDBBoundaryCase(t *testing.T) {
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
blk := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
blkRoot, _ := ssz.HashTreeRoot(blk.Block)
|
||||
service.beaconDB.SaveGenesisBlockRoot(ctx, blkRoot)
|
||||
blkRoot, err := ssz.HashTreeRoot(blk.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveGenesisBlockRoot(ctx, blkRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveState(ctx, beaconState, blkRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -199,7 +218,10 @@ func TestLoadHoteStateBySlot_CanAdvanceSlotUsingDB(t *testing.T) {
|
||||
if err := service.beaconDB.SaveBlock(ctx, b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
gRoot, _ := ssz.HashTreeRoot(b.Block)
|
||||
gRoot, err := ssz.HashTreeRoot(b.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveGenesisBlockRoot(ctx, gRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -54,14 +54,19 @@ func TestMigrateToCold_MigrationCompletes(t *testing.T) {
|
||||
service.slotsPerArchivedPoint = 2
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch)
|
||||
if err := beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b := ðpb.SignedBeaconBlock{
|
||||
Block: ðpb.BeaconBlock{Slot: 2},
|
||||
}
|
||||
if err := service.beaconDB.SaveBlock(ctx, b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
bRoot, _ := ssz.HashTreeRoot(b.Block)
|
||||
bRoot, err := ssz.HashTreeRoot(b.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveStateSummary(ctx, &pb.StateSummary{Root: bRoot[:], Slot: 2}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -70,14 +75,19 @@ func TestMigrateToCold_MigrationCompletes(t *testing.T) {
|
||||
}
|
||||
|
||||
newBeaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
newBeaconState.SetSlot(3)
|
||||
if err := newBeaconState.SetSlot(3); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b = ðpb.SignedBeaconBlock{
|
||||
Block: ðpb.BeaconBlock{Slot: 3},
|
||||
}
|
||||
if err := service.beaconDB.SaveBlock(ctx, b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
bRoot, _ = ssz.HashTreeRoot(b.Block)
|
||||
bRoot, err = ssz.HashTreeRoot(b.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveStateSummary(ctx, &pb.StateSummary{Root: bRoot[:], Slot: 3}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -96,19 +96,28 @@ func TestReplayBlocks_AllSkipSlots(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
beaconState.SetLatestBlockHeader(ðpb.BeaconBlockHeader{
|
||||
err = beaconState.SetLatestBlockHeader(ðpb.BeaconBlockHeader{
|
||||
Slot: genesisBlock.Block.Slot,
|
||||
ParentRoot: genesisBlock.Block.ParentRoot,
|
||||
StateRoot: params.BeaconConfig().ZeroHash[:],
|
||||
BodyRoot: bodyRoot[:],
|
||||
})
|
||||
beaconState.SetSlashings(make([]uint64, params.BeaconConfig().EpochsPerSlashingsVector))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := beaconState.SetSlashings(make([]uint64, params.BeaconConfig().EpochsPerSlashingsVector)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cp := beaconState.CurrentJustifiedCheckpoint()
|
||||
mockRoot := [32]byte{}
|
||||
copy(mockRoot[:], "hello-world")
|
||||
cp.Root = mockRoot[:]
|
||||
beaconState.SetCurrentJustifiedCheckpoint(cp)
|
||||
beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{})
|
||||
if err := beaconState.SetCurrentJustifiedCheckpoint(cp); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
targetSlot := params.BeaconConfig().SlotsPerEpoch - 1
|
||||
@@ -132,19 +141,28 @@ func TestReplayBlocks_SameSlot(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
beaconState.SetLatestBlockHeader(ðpb.BeaconBlockHeader{
|
||||
err = beaconState.SetLatestBlockHeader(ðpb.BeaconBlockHeader{
|
||||
Slot: genesisBlock.Block.Slot,
|
||||
ParentRoot: genesisBlock.Block.ParentRoot,
|
||||
StateRoot: params.BeaconConfig().ZeroHash[:],
|
||||
BodyRoot: bodyRoot[:],
|
||||
})
|
||||
beaconState.SetSlashings(make([]uint64, params.BeaconConfig().EpochsPerSlashingsVector))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := beaconState.SetSlashings(make([]uint64, params.BeaconConfig().EpochsPerSlashingsVector)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cp := beaconState.CurrentJustifiedCheckpoint()
|
||||
mockRoot := [32]byte{}
|
||||
copy(mockRoot[:], "hello-world")
|
||||
cp.Root = mockRoot[:]
|
||||
beaconState.SetCurrentJustifiedCheckpoint(cp)
|
||||
beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{})
|
||||
if err := beaconState.SetCurrentJustifiedCheckpoint(cp); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
targetSlot := beaconState.Slot()
|
||||
@@ -413,7 +431,10 @@ func TestLastSavedBlock_CanGet(t *testing.T) {
|
||||
if savedSlot != s.splitInfo.slot+20 {
|
||||
t.Error("Did not save correct slot")
|
||||
}
|
||||
wantedRoot, _ := ssz.HashTreeRoot(b3.Block)
|
||||
wantedRoot, err := ssz.HashTreeRoot(b3.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if savedRoot != wantedRoot {
|
||||
t.Error("Did not save correct root")
|
||||
}
|
||||
@@ -484,7 +505,10 @@ func TestLastSavedState_CanGet(t *testing.T) {
|
||||
if err := s.beaconDB.SaveBlock(ctx, b2); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b2Root, _ := ssz.HashTreeRoot(b2.Block)
|
||||
b2Root, err := ssz.HashTreeRoot(b2.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
st, err := stateTrie.InitializeFromProtoUnsafe(&pb.BeaconState{Slot: s.splitInfo.slot + 10})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -532,23 +556,50 @@ func TestLastSavedState_NoSavedBlockState(t *testing.T) {
|
||||
// \- B7
|
||||
func tree1(db db.Database, genesisRoot []byte) ([][32]byte, []*ethpb.BeaconBlock, error) {
|
||||
b0 := ðpb.BeaconBlock{Slot: 0, ParentRoot: genesisRoot}
|
||||
r0, _ := ssz.HashTreeRoot(b0)
|
||||
r0, err := ssz.HashTreeRoot(b0)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b1 := ðpb.BeaconBlock{Slot: 1, ParentRoot: r0[:]}
|
||||
r1, _ := ssz.HashTreeRoot(b1)
|
||||
r1, err := ssz.HashTreeRoot(b1)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b2 := ðpb.BeaconBlock{Slot: 2, ParentRoot: r1[:]}
|
||||
r2, _ := ssz.HashTreeRoot(b2)
|
||||
r2, err := ssz.HashTreeRoot(b2)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b3 := ðpb.BeaconBlock{Slot: 3, ParentRoot: r1[:]}
|
||||
r3, _ := ssz.HashTreeRoot(b3)
|
||||
r3, err := ssz.HashTreeRoot(b3)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b4 := ðpb.BeaconBlock{Slot: 4, ParentRoot: r2[:]}
|
||||
r4, _ := ssz.HashTreeRoot(b4)
|
||||
r4, err := ssz.HashTreeRoot(b4)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b5 := ðpb.BeaconBlock{Slot: 5, ParentRoot: r3[:]}
|
||||
r5, _ := ssz.HashTreeRoot(b5)
|
||||
r5, err := ssz.HashTreeRoot(b5)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b6 := ðpb.BeaconBlock{Slot: 6, ParentRoot: r4[:]}
|
||||
r6, _ := ssz.HashTreeRoot(b6)
|
||||
r6, err := ssz.HashTreeRoot(b6)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b7 := ðpb.BeaconBlock{Slot: 7, ParentRoot: r6[:]}
|
||||
r7, _ := ssz.HashTreeRoot(b7)
|
||||
r7, err := ssz.HashTreeRoot(b7)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b8 := ðpb.BeaconBlock{Slot: 8, ParentRoot: r6[:]}
|
||||
r8, _ := ssz.HashTreeRoot(b8)
|
||||
r8, err := ssz.HashTreeRoot(b8)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
st, err := stateTrie.InitializeFromProtoUnsafe(&pb.BeaconState{})
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -572,19 +623,40 @@ func tree1(db db.Database, genesisRoot []byte) ([][32]byte, []*ethpb.BeaconBlock
|
||||
// \- B2 -- B3
|
||||
func tree2(db db.Database, genesisRoot []byte) ([][32]byte, []*ethpb.BeaconBlock, error) {
|
||||
b0 := ðpb.BeaconBlock{Slot: 0, ParentRoot: genesisRoot}
|
||||
r0, _ := ssz.HashTreeRoot(b0)
|
||||
r0, err := ssz.HashTreeRoot(b0)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b1 := ðpb.BeaconBlock{Slot: 1, ParentRoot: r0[:]}
|
||||
r1, _ := ssz.HashTreeRoot(b1)
|
||||
r1, err := ssz.HashTreeRoot(b1)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b21 := ðpb.BeaconBlock{Slot: 2, ParentRoot: r1[:], StateRoot: []byte{'A'}}
|
||||
r21, _ := ssz.HashTreeRoot(b21)
|
||||
r21, err := ssz.HashTreeRoot(b21)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b22 := ðpb.BeaconBlock{Slot: 2, ParentRoot: r1[:], StateRoot: []byte{'B'}}
|
||||
r22, _ := ssz.HashTreeRoot(b22)
|
||||
r22, err := ssz.HashTreeRoot(b22)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b23 := ðpb.BeaconBlock{Slot: 2, ParentRoot: r1[:], StateRoot: []byte{'C'}}
|
||||
r23, _ := ssz.HashTreeRoot(b23)
|
||||
r23, err := ssz.HashTreeRoot(b23)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b24 := ðpb.BeaconBlock{Slot: 2, ParentRoot: r1[:], StateRoot: []byte{'D'}}
|
||||
r24, _ := ssz.HashTreeRoot(b24)
|
||||
r24, err := ssz.HashTreeRoot(b24)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b3 := ðpb.BeaconBlock{Slot: 3, ParentRoot: r24[:]}
|
||||
r3, _ := ssz.HashTreeRoot(b3)
|
||||
r3, err := ssz.HashTreeRoot(b3)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
st, err := stateTrie.InitializeFromProtoUnsafe(&pb.BeaconState{})
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -609,17 +681,35 @@ func tree2(db db.Database, genesisRoot []byte) ([][32]byte, []*ethpb.BeaconBlock
|
||||
// \- B2
|
||||
func tree3(db db.Database, genesisRoot []byte) ([][32]byte, []*ethpb.BeaconBlock, error) {
|
||||
b0 := ðpb.BeaconBlock{Slot: 0, ParentRoot: genesisRoot}
|
||||
r0, _ := ssz.HashTreeRoot(b0)
|
||||
r0, err := ssz.HashTreeRoot(b0)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b1 := ðpb.BeaconBlock{Slot: 1, ParentRoot: r0[:]}
|
||||
r1, _ := ssz.HashTreeRoot(b1)
|
||||
r1, err := ssz.HashTreeRoot(b1)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b21 := ðpb.BeaconBlock{Slot: 2, ParentRoot: r1[:], StateRoot: []byte{'A'}}
|
||||
r21, _ := ssz.HashTreeRoot(b21)
|
||||
r21, err := ssz.HashTreeRoot(b21)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b22 := ðpb.BeaconBlock{Slot: 2, ParentRoot: r1[:], StateRoot: []byte{'B'}}
|
||||
r22, _ := ssz.HashTreeRoot(b22)
|
||||
r22, err := ssz.HashTreeRoot(b22)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b23 := ðpb.BeaconBlock{Slot: 2, ParentRoot: r1[:], StateRoot: []byte{'C'}}
|
||||
r23, _ := ssz.HashTreeRoot(b23)
|
||||
r23, err := ssz.HashTreeRoot(b23)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b24 := ðpb.BeaconBlock{Slot: 2, ParentRoot: r1[:], StateRoot: []byte{'D'}}
|
||||
r24, _ := ssz.HashTreeRoot(b24)
|
||||
r24, err := ssz.HashTreeRoot(b24)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
st, err := stateTrie.InitializeFromProtoUnsafe(&pb.BeaconState{})
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -645,15 +735,30 @@ func tree3(db db.Database, genesisRoot []byte) ([][32]byte, []*ethpb.BeaconBlock
|
||||
// \- B2
|
||||
func tree4(db db.Database, genesisRoot []byte) ([][32]byte, []*ethpb.BeaconBlock, error) {
|
||||
b0 := ðpb.BeaconBlock{Slot: 0, ParentRoot: genesisRoot}
|
||||
r0, _ := ssz.HashTreeRoot(b0)
|
||||
r0, err := ssz.HashTreeRoot(b0)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b21 := ðpb.BeaconBlock{Slot: 2, ParentRoot: r0[:], StateRoot: []byte{'A'}}
|
||||
r21, _ := ssz.HashTreeRoot(b21)
|
||||
r21, err := ssz.HashTreeRoot(b21)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b22 := ðpb.BeaconBlock{Slot: 2, ParentRoot: r0[:], StateRoot: []byte{'B'}}
|
||||
r22, _ := ssz.HashTreeRoot(b22)
|
||||
r22, err := ssz.HashTreeRoot(b22)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b23 := ðpb.BeaconBlock{Slot: 2, ParentRoot: r0[:], StateRoot: []byte{'C'}}
|
||||
r23, _ := ssz.HashTreeRoot(b23)
|
||||
r23, err := ssz.HashTreeRoot(b23)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
b24 := ðpb.BeaconBlock{Slot: 2, ParentRoot: r0[:], StateRoot: []byte{'D'}}
|
||||
r24, _ := ssz.HashTreeRoot(b24)
|
||||
r24, err := ssz.HashTreeRoot(b24)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
st, err := stateTrie.InitializeFromProtoUnsafe(&pb.BeaconState{})
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
||||
@@ -19,10 +19,18 @@ func TestResume(t *testing.T) {
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
root := [32]byte{'A'}
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch)
|
||||
service.beaconDB.SaveState(ctx, beaconState, root)
|
||||
service.beaconDB.SaveArchivedPointRoot(ctx, root, 1)
|
||||
service.beaconDB.SaveLastArchivedIndex(ctx, 1)
|
||||
if err := beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveState(ctx, beaconState, root); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveArchivedPointRoot(ctx, root, 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := service.beaconDB.SaveLastArchivedIndex(ctx, 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
resumeState, err := service.Resume(ctx)
|
||||
if err != nil {
|
||||
|
||||
@@ -24,7 +24,9 @@ func TestSaveState_ColdStateCanBeSaved(t *testing.T) {
|
||||
|
||||
// This goes to cold section.
|
||||
slot := uint64(1)
|
||||
beaconState.SetSlot(slot)
|
||||
if err := beaconState.SetSlot(slot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
service.splitInfo.slot = slot + 1
|
||||
|
||||
r := [32]byte{'a'}
|
||||
@@ -53,7 +55,9 @@ func TestSaveState_HotStateCanBeSaved(t *testing.T) {
|
||||
service.slotsPerArchivedPoint = 1
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
// This goes to hot section, verify it can save on epoch boundary.
|
||||
beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch)
|
||||
if err := beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
r := [32]byte{'a'}
|
||||
if err := service.SaveState(ctx, r, beaconState); err != nil {
|
||||
@@ -79,7 +83,9 @@ func TestSaveState_HotStateCached(t *testing.T) {
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
service.slotsPerArchivedPoint = 1
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch)
|
||||
if err := beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Cache the state prior.
|
||||
r := [32]byte{'a'}
|
||||
|
||||
@@ -42,7 +42,9 @@ func fuzzStateRootCache(t *testing.T, seed int64, iterations uint64) {
|
||||
for i := start; i < start+length; i++ {
|
||||
func() {
|
||||
defer func() {
|
||||
recover() // Ignore fuzzing panics for out of range values
|
||||
if r := recover(); r != nil {
|
||||
// Ignore fuzzing panics for out of range values
|
||||
}
|
||||
}()
|
||||
fuzzer.Fuzz(state)
|
||||
}()
|
||||
|
||||
@@ -68,8 +68,12 @@ func TestRecomputeFromLayer_FixedSizedArray(t *testing.T) {
|
||||
|
||||
changedIdx := []uint64{24, 41}
|
||||
changedRoots := [][32]byte{{'A', 'B', 'C'}, {'D', 'E', 'F'}}
|
||||
newState.UpdateBlockRootAtIndex(changedIdx[0], changedRoots[0])
|
||||
newState.UpdateBlockRootAtIndex(changedIdx[1], changedRoots[1])
|
||||
if err := newState.UpdateBlockRootAtIndex(changedIdx[0], changedRoots[0]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := newState.UpdateBlockRootAtIndex(changedIdx[1], changedRoots[1]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
expectedRoot, err := stateutil.RootsArrayHashTreeRoot(newState.BlockRoots(), params.BeaconConfig().SlotsPerHistoricalRoot, "BlockRoots")
|
||||
if err != nil {
|
||||
@@ -114,8 +118,12 @@ func TestRecomputeFromLayer_VariableSizedArray(t *testing.T) {
|
||||
val2.ExitEpoch = 40
|
||||
|
||||
changedVals := []*ethpb.Validator{val1, val2}
|
||||
newState.UpdateValidatorAtIndex(changedIdx[0], changedVals[0])
|
||||
newState.UpdateValidatorAtIndex(changedIdx[1], changedVals[1])
|
||||
if err := newState.UpdateValidatorAtIndex(changedIdx[0], changedVals[0]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := newState.UpdateValidatorAtIndex(changedIdx[1], changedVals[1]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
expectedRoot, err := stateutil.ValidatorRegistryRoot(newState.Validators())
|
||||
if err != nil {
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/interop"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func TestBeaconState_ProtoBeaconStateCompatibility(t *testing.T) {
|
||||
@@ -25,7 +26,10 @@ func TestBeaconState_ProtoBeaconStateCompatibility(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cloned := proto.Clone(genesis).(*pb.BeaconState)
|
||||
cloned, ok := proto.Clone(genesis).(*pb.BeaconState)
|
||||
if !ok {
|
||||
t.Error("Object is not of type *pb.BeaconState")
|
||||
}
|
||||
custom := customState.CloneInnerState()
|
||||
if !proto.Equal(cloned, custom) {
|
||||
t.Fatal("Cloned states did not match")
|
||||
@@ -140,7 +144,10 @@ func BenchmarkStateClone_Proto(b *testing.B) {
|
||||
genesis := setupGenesisState(b, 64)
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = proto.Clone(genesis).(*pb.BeaconState)
|
||||
_, ok := proto.Clone(genesis).(*pb.BeaconState)
|
||||
if !ok {
|
||||
b.Error("Entity is not of type *pb.BeaconState")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,9 +166,13 @@ func BenchmarkStateClone_Manual(b *testing.B) {
|
||||
}
|
||||
|
||||
func cloneValidatorsWithProto(vals []*ethpb.Validator) []*ethpb.Validator {
|
||||
var ok bool
|
||||
res := make([]*ethpb.Validator, len(vals))
|
||||
for i := 0; i < len(res); i++ {
|
||||
res[i] = proto.Clone(vals[i]).(*ethpb.Validator)
|
||||
res[i], ok = proto.Clone(vals[i]).(*ethpb.Validator)
|
||||
if !ok {
|
||||
log.Debug("Entity is not of type *ethpb.Validator")
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
@@ -197,7 +208,9 @@ func TestBeaconState_ImmutabilityWithSharedResources(t *testing.T) {
|
||||
if !reflect.DeepEqual(a.RandaoMixes(), b.RandaoMixes()) {
|
||||
t.Fatal("Test precondition failed, fields are not equal")
|
||||
}
|
||||
a.UpdateRandaoMixesAtIndex([]byte("foo"), 1)
|
||||
if err := a.UpdateRandaoMixesAtIndex([]byte("foo"), 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if reflect.DeepEqual(a.RandaoMixes(), b.RandaoMixes()) {
|
||||
t.Error("Expect a.RandaoMixes() to be different from b.RandaoMixes()")
|
||||
}
|
||||
@@ -206,7 +219,9 @@ func TestBeaconState_ImmutabilityWithSharedResources(t *testing.T) {
|
||||
if !reflect.DeepEqual(a.Validators(), b.Validators()) {
|
||||
t.Fatal("Test precondition failed, fields are not equal")
|
||||
}
|
||||
a.UpdateValidatorAtIndex(1, ðpb.Validator{Slashed: true})
|
||||
if err := a.UpdateValidatorAtIndex(1, ðpb.Validator{Slashed: true}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if reflect.DeepEqual(a.Validators(), b.Validators()) {
|
||||
t.Error("Expect a.Validators() to be different from b.Validators()")
|
||||
}
|
||||
@@ -215,7 +230,9 @@ func TestBeaconState_ImmutabilityWithSharedResources(t *testing.T) {
|
||||
if !reflect.DeepEqual(a.StateRoots(), b.StateRoots()) {
|
||||
t.Fatal("Test precondition failed, fields are not equal")
|
||||
}
|
||||
a.UpdateStateRootAtIndex(1, bytesutil.ToBytes32([]byte("foo")))
|
||||
if err := a.UpdateStateRootAtIndex(1, bytesutil.ToBytes32([]byte("foo"))); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if reflect.DeepEqual(a.StateRoots(), b.StateRoots()) {
|
||||
t.Fatal("Expected a.StateRoots() to be different from b.StateRoots()")
|
||||
}
|
||||
@@ -224,7 +241,9 @@ func TestBeaconState_ImmutabilityWithSharedResources(t *testing.T) {
|
||||
if !reflect.DeepEqual(a.BlockRoots(), b.BlockRoots()) {
|
||||
t.Fatal("Test precondition failed, fields are not equal")
|
||||
}
|
||||
a.UpdateBlockRootAtIndex(1, bytesutil.ToBytes32([]byte("foo")))
|
||||
if err := a.UpdateBlockRootAtIndex(1, bytesutil.ToBytes32([]byte("foo"))); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if reflect.DeepEqual(a.BlockRoots(), b.BlockRoots()) {
|
||||
t.Fatal("Expected a.BlockRoots() to be different from b.BlockRoots()")
|
||||
}
|
||||
@@ -242,7 +261,9 @@ func TestForkManualCopy_OK(t *testing.T) {
|
||||
CurrentVersion: []byte{'d', 'e', 'f'},
|
||||
Epoch: 0,
|
||||
}
|
||||
a.SetFork(wantedFork)
|
||||
if err := a.SetFork(wantedFork); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
newState := a.CloneInnerState()
|
||||
if !ssz.DeepEqual(newState.Fork, wantedFork) {
|
||||
|
||||
@@ -259,13 +259,20 @@ func TestRoundRobinSync(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
gRoot, _ := ssz.HashTreeRoot(gBlock.Block)
|
||||
beaconDB.SaveGenesisBlockRoot(context.Background(), gRoot)
|
||||
gRoot, err := ssz.HashTreeRoot(gBlock.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := beaconDB.SaveGenesisBlockRoot(context.Background(), gRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
st, err := stateTrie.InitializeFromProto(&p2ppb.BeaconState{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
beaconDB.SaveState(context.Background(), st, gRoot)
|
||||
if err := beaconDB.SaveState(context.Background(), st, gRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
mc := &mock.ChainService{
|
||||
State: st,
|
||||
@@ -315,7 +322,11 @@ func connectPeers(t *testing.T, host *p2pt.TestP2P, data []*peerData, peerStatus
|
||||
var datum = d
|
||||
|
||||
peer.SetStreamHandler(topic, func(stream network.Stream) {
|
||||
defer stream.Close()
|
||||
defer func() {
|
||||
if err := stream.Close(); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}()
|
||||
|
||||
req := &p2ppb.BeaconBlocksByRangeRequest{}
|
||||
if err := peer.Encoding().DecodeWithLength(stream, req); err != nil {
|
||||
@@ -358,7 +369,10 @@ func connectPeers(t *testing.T, host *p2pt.TestP2P, data []*peerData, peerStatus
|
||||
blk.Block.ParentRoot = newRoot[:]
|
||||
}
|
||||
ret = append(ret, blk)
|
||||
currRoot, _ := ssz.HashTreeRoot(blk.Block)
|
||||
currRoot, err := ssz.HashTreeRoot(blk.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
logrus.Infof("block with slot %d , signing root %#x and parent root %#x", slot, currRoot, parentRoot)
|
||||
}
|
||||
|
||||
|
||||
@@ -330,7 +330,11 @@ func connectPeers(t *testing.T, host *p2pt.TestP2P, data []*peerData, peerStatus
|
||||
var datum = d
|
||||
|
||||
peer.SetStreamHandler(topic, func(stream network.Stream) {
|
||||
defer stream.Close()
|
||||
defer func() {
|
||||
if err := stream.Close(); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}()
|
||||
|
||||
req := &p2ppb.BeaconBlocksByRangeRequest{}
|
||||
if err := peer.Encoding().DecodeWithLength(stream, req); err != nil {
|
||||
@@ -373,7 +377,10 @@ func connectPeers(t *testing.T, host *p2pt.TestP2P, data []*peerData, peerStatus
|
||||
blk.Block.ParentRoot = newRoot[:]
|
||||
}
|
||||
ret = append(ret, blk)
|
||||
currRoot, _ := ssz.HashTreeRoot(blk.Block)
|
||||
currRoot, err := ssz.HashTreeRoot(blk.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
logrus.Infof("block with slot %d , signing root %#x and parent root %#x", slot, currRoot, parentRoot)
|
||||
}
|
||||
|
||||
|
||||
@@ -82,10 +82,20 @@ func TestProcessPendingAtts_HasBlockSaveUnAggregatedAtt(t *testing.T) {
|
||||
Target: ðpb.Checkpoint{}}}}
|
||||
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
r32, _ := ssz.HashTreeRoot(b.Block)
|
||||
s, _ := beaconstate.InitializeFromProto(&pb.BeaconState{})
|
||||
r.db.SaveBlock(context.Background(), b)
|
||||
r.db.SaveState(context.Background(), s, r32)
|
||||
r32, err := ssz.HashTreeRoot(b.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s, err := beaconstate.InitializeFromProto(&pb.BeaconState{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := r.db.SaveBlock(context.Background(), b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := r.db.SaveState(context.Background(), s, r32); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
r.blkRootToPendingAtts[r32] = []*ethpb.AggregateAttestationAndProof{a}
|
||||
if err := r.processPendingAtts(context.Background()); err != nil {
|
||||
@@ -114,8 +124,13 @@ func TestProcessPendingAtts_HasBlockSaveAggregatedAtt(t *testing.T) {
|
||||
beaconState, privKeys := testutil.DeterministicGenesisState(t, validators)
|
||||
|
||||
sb := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
db.SaveBlock(context.Background(), sb)
|
||||
root, _ := ssz.HashTreeRoot(sb.Block)
|
||||
if err := db.SaveBlock(context.Background(), sb); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
root, err := ssz.HashTreeRoot(sb.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
aggBits := bitfield.NewBitlist(3)
|
||||
aggBits.SetBitAt(0, true)
|
||||
@@ -182,10 +197,20 @@ func TestProcessPendingAtts_HasBlockSaveAggregatedAtt(t *testing.T) {
|
||||
}
|
||||
|
||||
sb = ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
r32, _ := ssz.HashTreeRoot(sb.Block)
|
||||
r.db.SaveBlock(context.Background(), sb)
|
||||
s, _ := beaconstate.InitializeFromProto(&pb.BeaconState{})
|
||||
r.db.SaveState(context.Background(), s, r32)
|
||||
r32, err := ssz.HashTreeRoot(sb.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := r.db.SaveBlock(context.Background(), sb); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s, err := beaconstate.InitializeFromProto(&pb.BeaconState{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := r.db.SaveState(context.Background(), s, r32); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
r.blkRootToPendingAtts[r32] = []*ethpb.AggregateAttestationAndProof{aggregateAndProof}
|
||||
if err := r.processPendingAtts(context.Background()); err != nil {
|
||||
|
||||
@@ -46,16 +46,25 @@ func TestRegularSyncBeaconBlockSubscriber_ProcessPendingBlocks1(t *testing.T) {
|
||||
if err := r.db.SaveBlock(context.Background(), b0); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b0Root, _ := ssz.HashTreeRoot(b0.Block)
|
||||
b0Root, err := ssz.HashTreeRoot(b0.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b3 := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 3, ParentRoot: b0Root[:]}}
|
||||
if err := r.db.SaveBlock(context.Background(), b3); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Incomplete block link
|
||||
b1 := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 1, ParentRoot: b0Root[:]}}
|
||||
b1Root, _ := ssz.HashTreeRoot(b1.Block)
|
||||
b1Root, err := ssz.HashTreeRoot(b1.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b2 := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 2, ParentRoot: b1Root[:]}}
|
||||
b2Root, _ := ssz.HashTreeRoot(b1.Block)
|
||||
b2Root, err := ssz.HashTreeRoot(b1.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Add b2 to the cache
|
||||
r.slotToPendingBlocks[b2.Block.Slot] = b2
|
||||
@@ -137,22 +146,40 @@ func TestRegularSyncBeaconBlockSubscriber_ProcessPendingBlocks2(t *testing.T) {
|
||||
if err := r.db.SaveBlock(context.Background(), b0); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b0Root, _ := ssz.HashTreeRoot(b0.Block)
|
||||
b0Root, err := ssz.HashTreeRoot(b0.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b1 := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 1, ParentRoot: b0Root[:]}}
|
||||
if err := r.db.SaveBlock(context.Background(), b1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b1Root, _ := ssz.HashTreeRoot(b1.Block)
|
||||
b1Root, err := ssz.HashTreeRoot(b1.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Incomplete block links
|
||||
b2 := ðpb.BeaconBlock{Slot: 2, ParentRoot: b1Root[:]}
|
||||
b2Root, _ := ssz.HashTreeRoot(b2)
|
||||
b2Root, err := ssz.HashTreeRoot(b2)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b5 := ðpb.BeaconBlock{Slot: 5, ParentRoot: b2Root[:]}
|
||||
b5Root, _ := ssz.HashTreeRoot(b5)
|
||||
b5Root, err := ssz.HashTreeRoot(b5)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b3 := ðpb.BeaconBlock{Slot: 3, ParentRoot: b0Root[:]}
|
||||
b3Root, _ := ssz.HashTreeRoot(b3)
|
||||
b3Root, err := ssz.HashTreeRoot(b3)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b4 := ðpb.BeaconBlock{Slot: 4, ParentRoot: b3Root[:]}
|
||||
b4Root, _ := ssz.HashTreeRoot(b4)
|
||||
b4Root, err := ssz.HashTreeRoot(b4)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
r.slotToPendingBlocks[b4.Slot] = ðpb.SignedBeaconBlock{Block: b4}
|
||||
r.seenPendingBlocks[b4Root] = true
|
||||
@@ -232,22 +259,40 @@ func TestRegularSyncBeaconBlockSubscriber_PruneOldPendingBlocks(t *testing.T) {
|
||||
if err := r.db.SaveBlock(context.Background(), b0); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b0Root, _ := ssz.HashTreeRoot(b0.Block)
|
||||
b0Root, err := ssz.HashTreeRoot(b0.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b1 := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Slot: 1, ParentRoot: b0Root[:]}}
|
||||
if err := r.db.SaveBlock(context.Background(), b1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b1Root, _ := ssz.HashTreeRoot(b1.Block)
|
||||
b1Root, err := ssz.HashTreeRoot(b1.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Incomplete block links
|
||||
b2 := ðpb.BeaconBlock{Slot: 2, ParentRoot: b1Root[:]}
|
||||
b2Root, _ := ssz.HashTreeRoot(b2)
|
||||
b2Root, err := ssz.HashTreeRoot(b2)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b5 := ðpb.BeaconBlock{Slot: 5, ParentRoot: b2Root[:]}
|
||||
b5Root, _ := ssz.HashTreeRoot(b5)
|
||||
b5Root, err := ssz.HashTreeRoot(b5)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b3 := ðpb.BeaconBlock{Slot: 3, ParentRoot: b0Root[:]}
|
||||
b3Root, _ := ssz.HashTreeRoot(b3)
|
||||
b3Root, err := ssz.HashTreeRoot(b3)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b4 := ðpb.BeaconBlock{Slot: 4, ParentRoot: b3Root[:]}
|
||||
b4Root, _ := ssz.HashTreeRoot(b4)
|
||||
b4Root, err := ssz.HashTreeRoot(b4)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
r.slotToPendingBlocks[b2.Slot] = ðpb.SignedBeaconBlock{Block: b2}
|
||||
r.seenPendingBlocks[b2Root] = true
|
||||
|
||||
@@ -204,7 +204,9 @@ func TestHandshakeHandlers_Roundtrip(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
log.WithField("status", out).Warn("sending status")
|
||||
stream.Close()
|
||||
if err := stream.Close(); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
})
|
||||
|
||||
numInactive1 := len(p1.Peers().Inactive())
|
||||
|
||||
@@ -54,7 +54,10 @@ func TestRegisterRPC_ReceivesValidMessage(t *testing.T) {
|
||||
wg.Add(1)
|
||||
topic := "/testing/foobar/1"
|
||||
handler := func(ctx context.Context, msg interface{}, stream libp2pcore.Stream) error {
|
||||
m := msg.(*pb.TestSimpleMessage)
|
||||
m, ok := msg.(*pb.TestSimpleMessage)
|
||||
if !ok {
|
||||
t.Error("Object is not of type *pb.TestSimpleMessage")
|
||||
}
|
||||
if !bytes.Equal(m.Foo, []byte("foo")) {
|
||||
t.Errorf("Unexpected incoming message: %+v", m)
|
||||
}
|
||||
|
||||
@@ -39,7 +39,10 @@ func TestRegularSyncBeaconBlockSubscriber_FilterByFinalizedEpoch(t *testing.T) {
|
||||
if err := db.SaveBlock(context.Background(), parent); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
parentRoot, _ := ssz.HashTreeRoot(parent.Block)
|
||||
parentRoot, err := ssz.HashTreeRoot(parent.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
chain := &mock.ChainService{State: s}
|
||||
r := &Service{
|
||||
db: db,
|
||||
|
||||
@@ -42,8 +42,13 @@ func TestService_committeeIndexBeaconAttestationSubscriber_ValidMessage(t *testi
|
||||
if err := db.SaveBlock(ctx, blk); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
savedState, _ := beaconstate.InitializeFromProto(&pb.BeaconState{})
|
||||
db.SaveState(context.Background(), savedState, root)
|
||||
savedState, err := beaconstate.InitializeFromProto(&pb.BeaconState{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.SaveState(context.Background(), savedState, root); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
r := &Service{
|
||||
attPool: attestations.NewPool(),
|
||||
|
||||
@@ -36,7 +36,10 @@ func TestSubscribe_ReceivesValidMessage(t *testing.T) {
|
||||
wg.Add(1)
|
||||
|
||||
r.subscribe(topic, r.noopValidator, func(_ context.Context, msg proto.Message) error {
|
||||
m := msg.(*pb.SignedVoluntaryExit)
|
||||
m, ok := msg.(*pb.SignedVoluntaryExit)
|
||||
if !ok {
|
||||
t.Error("Object is not of type *pb.SignedVoluntaryExit")
|
||||
}
|
||||
if m.Exit == nil || m.Exit.Epoch != 55 {
|
||||
t.Errorf("Unexpected incoming message: %+v", m)
|
||||
}
|
||||
@@ -71,7 +74,9 @@ func TestSubscribe_ReceivesAttesterSlashing(t *testing.T) {
|
||||
wg.Add(1)
|
||||
params.OverrideBeaconConfig(params.MinimalSpecConfig())
|
||||
r.subscribe(topic, r.noopValidator, func(ctx context.Context, msg proto.Message) error {
|
||||
r.attesterSlashingSubscriber(ctx, msg)
|
||||
if err := r.attesterSlashingSubscriber(ctx, msg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
wg.Done()
|
||||
return nil
|
||||
})
|
||||
@@ -86,7 +91,10 @@ func TestSubscribe_ReceivesAttesterSlashing(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Error generating attester slashing")
|
||||
}
|
||||
r.db.SaveState(ctx, beaconState, bytesutil.ToBytes32(attesterSlashing.Attestation_1.Data.BeaconBlockRoot))
|
||||
err = r.db.SaveState(ctx, beaconState, bytesutil.ToBytes32(attesterSlashing.Attestation_1.Data.BeaconBlockRoot))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p2p.ReceivePubSub(topic, attesterSlashing)
|
||||
|
||||
if testutil.WaitTimeout(&wg, time.Second) {
|
||||
@@ -117,7 +125,9 @@ func TestSubscribe_ReceivesProposerSlashing(t *testing.T) {
|
||||
wg.Add(1)
|
||||
params.OverrideBeaconConfig(params.MinimalSpecConfig())
|
||||
r.subscribe(topic, r.noopValidator, func(ctx context.Context, msg proto.Message) error {
|
||||
r.proposerSlashingSubscriber(ctx, msg)
|
||||
if err := r.proposerSlashingSubscriber(ctx, msg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
wg.Done()
|
||||
return nil
|
||||
})
|
||||
@@ -133,7 +143,9 @@ func TestSubscribe_ReceivesProposerSlashing(t *testing.T) {
|
||||
t.Fatalf("Error generating proposer slashing")
|
||||
}
|
||||
root, err := ssz.HashTreeRoot(proposerSlashing.Header_1.Header)
|
||||
r.db.SaveState(ctx, beaconState, root)
|
||||
if err := r.db.SaveState(ctx, beaconState, root); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p2p.ReceivePubSub(topic, proposerSlashing)
|
||||
|
||||
if testutil.WaitTimeout(&wg, time.Second) {
|
||||
|
||||
@@ -171,10 +171,20 @@ func TestValidateAggregateAndProof_NotWithinSlotRange(t *testing.T) {
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, validators)
|
||||
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
db.SaveBlock(context.Background(), b)
|
||||
root, _ := ssz.HashTreeRoot(b.Block)
|
||||
s, _ := beaconstate.InitializeFromProto(&pb.BeaconState{})
|
||||
db.SaveState(context.Background(), s, root)
|
||||
if err := db.SaveBlock(context.Background(), b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
root, err := ssz.HashTreeRoot(b.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s, err := beaconstate.InitializeFromProto(&pb.BeaconState{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.SaveState(context.Background(), s, root); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
aggBits := bitfield.NewBitlist(3)
|
||||
aggBits.SetBitAt(0, true)
|
||||
@@ -252,8 +262,13 @@ func TestValidateAggregateAndProof_ExistedInPool(t *testing.T) {
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, validators)
|
||||
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
db.SaveBlock(context.Background(), b)
|
||||
root, _ := ssz.HashTreeRoot(b.Block)
|
||||
if err := db.SaveBlock(context.Background(), b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
root, err := ssz.HashTreeRoot(b.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
aggBits := bitfield.NewBitlist(3)
|
||||
aggBits.SetBitAt(0, true)
|
||||
@@ -316,10 +331,20 @@ func TestValidateAggregateAndProof_CanValidate(t *testing.T) {
|
||||
beaconState, privKeys := testutil.DeterministicGenesisState(t, validators)
|
||||
|
||||
b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{}}
|
||||
db.SaveBlock(context.Background(), b)
|
||||
root, _ := ssz.HashTreeRoot(b.Block)
|
||||
s, _ := beaconstate.InitializeFromProto(&pb.BeaconState{})
|
||||
db.SaveState(context.Background(), s, root)
|
||||
if err := db.SaveBlock(context.Background(), b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
root, err := ssz.HashTreeRoot(b.Block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s, err := beaconstate.InitializeFromProto(&pb.BeaconState{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.SaveState(context.Background(), s, root); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
aggBits := bitfield.NewBitlist(3)
|
||||
aggBits.SetBitAt(0, true)
|
||||
|
||||
@@ -54,8 +54,13 @@ func TestService_validateCommitteeIndexBeaconAttestation(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
savedState, _ := beaconstate.InitializeFromProto(&pb.BeaconState{})
|
||||
db.SaveState(context.Background(), savedState, validBlockRoot)
|
||||
savedState, err := beaconstate.InitializeFromProto(&pb.BeaconState{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.SaveState(context.Background(), savedState, validBlockRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
@@ -62,7 +62,11 @@ func runEndToEndTest(t *testing.T, config *types.E2EConfig) {
|
||||
t.Fatalf("Failed to dial: %v", err)
|
||||
}
|
||||
conns[i] = conn
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
if err := conn.Close(); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
nodeClient := eth.NewNodeClient(conns[0])
|
||||
genesis, err := nodeClient.GetGenesis(context.Background(), &ptypes.Empty{})
|
||||
|
||||
@@ -80,8 +80,6 @@
|
||||
"exclude_files": {
|
||||
"external/.*": "Third party code",
|
||||
"rules_go_work-.*": "Third party code",
|
||||
".*/.*_test\\.go": "TODO(5404): In a follow up PR",
|
||||
"beacon-chain/p2p/testing/.*\\.go": "TODO(5404): In a follow up PR",
|
||||
"shared/mock/.*\\.go": "Mocks are OK",
|
||||
".*/.*mock\\.go": "Mocks are OK",
|
||||
".*/testmain\\.go": "Test runner generated code"
|
||||
|
||||
@@ -10,7 +10,9 @@ import (
|
||||
)
|
||||
|
||||
func BenchmarkPairing(b *testing.B) {
|
||||
bls2.Init(bls2.BLS12_381)
|
||||
if err := bls2.Init(bls2.BLS12_381); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
newGt := &bls2.GT{}
|
||||
newG1 := &bls2.G1{}
|
||||
newG2 := &bls2.G2{}
|
||||
|
||||
@@ -284,7 +284,10 @@ func TestPublicKey_Copy(t *testing.T) {
|
||||
pubkeyA := bls.RandKey().PublicKey()
|
||||
pubkeyBytes := pubkeyA.Marshal()
|
||||
|
||||
pubkeyB, _ := pubkeyA.Copy()
|
||||
pubkeyB, err := pubkeyA.Copy()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
pubkeyB.Aggregate(bls.RandKey().PublicKey())
|
||||
|
||||
if !bytes.Equal(pubkeyA.Marshal(), pubkeyBytes) {
|
||||
@@ -296,5 +299,7 @@ func TestSerialize(t *testing.T) {
|
||||
rk := bls.RandKey()
|
||||
b := rk.Marshal()
|
||||
|
||||
bls.SecretKeyFromBytes(b)
|
||||
if _, err := bls.SecretKeyFromBytes(b); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,10 @@ import (
|
||||
)
|
||||
|
||||
func TestPathExpansion(t *testing.T) {
|
||||
user, _ := user.Current()
|
||||
user, err := user.Current()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
tests := map[string]string{
|
||||
"/home/someuser/tmp": "/home/someuser/tmp",
|
||||
"~/tmp": user.HomeDir + "/tmp",
|
||||
@@ -31,7 +34,10 @@ func TestPathExpansion(t *testing.T) {
|
||||
"$DDDXXX/a/b": "/tmp/a/b",
|
||||
"/a/b/": "/a/b",
|
||||
}
|
||||
os.Setenv("DDDXXX", "/tmp")
|
||||
err = os.Setenv("DDDXXX", "/tmp")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
for test, expected := range tests {
|
||||
got := expandPath(test)
|
||||
if got != expected {
|
||||
|
||||
@@ -54,7 +54,10 @@ func TestHashKeccak256(t *testing.T) {
|
||||
}
|
||||
|
||||
// Same hashing test from go-ethereum for keccak256
|
||||
hashOfabc, _ := hex.DecodeString("4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45")
|
||||
hashOfabc, err := hex.DecodeString("4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
hash = hashutil.HashKeccak256([]byte("abc"))
|
||||
|
||||
h := bytesutil.ToBytes32(hashOfabc)
|
||||
@@ -96,7 +99,9 @@ func TestHashProtoFuzz(t *testing.T) {
|
||||
for i := 0; i < 1000; i++ {
|
||||
msg := &pb.AddressBook{}
|
||||
f.Fuzz(msg)
|
||||
_, _ = hashutil.HashProto(msg)
|
||||
if _, err := hashutil.HashProto(msg); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,6 +119,8 @@ func BenchmarkHashProto(b *testing.B) {
|
||||
}
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
hashutil.HashProto(att)
|
||||
if _, err := hashutil.HashProto(att); err != nil {
|
||||
b.Log(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,4 +15,5 @@ go_test(
|
||||
"scatter_test.go",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
deps = ["@com_github_sirupsen_logrus//:go_default_library"],
|
||||
)
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/shared/mputil"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var input [][]byte
|
||||
@@ -21,7 +22,10 @@ func init() {
|
||||
input = make([][]byte, benchmarkElements)
|
||||
for i := 0; i < benchmarkElements; i++ {
|
||||
input[i] = make([]byte, benchmarkElementSize)
|
||||
rand.Read(input[i])
|
||||
_, err := rand.Read(input[i])
|
||||
if err != nil {
|
||||
log.WithError(err).Debug("Cannot read from rand")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,9 +51,12 @@ func BenchmarkHash(b *testing.B) {
|
||||
func BenchmarkHashMP(b *testing.B) {
|
||||
output := make([][]byte, len(input))
|
||||
for i := 0; i < b.N; i++ {
|
||||
workerResults, _ := mputil.Scatter(len(input), func(offset int, entries int, _ *sync.RWMutex) (interface{}, error) {
|
||||
workerResults, err := mputil.Scatter(len(input), func(offset int, entries int, _ *sync.RWMutex) (interface{}, error) {
|
||||
return hash(input[offset : offset+entries]), nil
|
||||
})
|
||||
if err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
for _, result := range workerResults {
|
||||
copy(output[result.Offset:], result.Extent.([][]byte))
|
||||
}
|
||||
|
||||
@@ -7,12 +7,18 @@ import (
|
||||
)
|
||||
|
||||
func TestConfig(t *testing.T) {
|
||||
SetConfig("minimal")
|
||||
err := SetConfig("minimal")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if params.BeaconConfig().SlotsPerEpoch != 8 {
|
||||
t.Errorf("Expected minimal config to be set, but got %d slots per epoch", params.BeaconConfig().SlotsPerEpoch)
|
||||
}
|
||||
|
||||
SetConfig("mainnet")
|
||||
err = SetConfig("mainnet")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if params.BeaconConfig().SlotsPerEpoch != 32 {
|
||||
t.Errorf("Expected mainnet config to be set, but got %d slots per epoch", params.BeaconConfig().SlotsPerEpoch)
|
||||
}
|
||||
|
||||
@@ -26,7 +26,12 @@ func TestLogrusCollector(t *testing.T) {
|
||||
hook := prometheus.NewLogrusCollector()
|
||||
log.AddHook(hook)
|
||||
go service.Start()
|
||||
defer service.Stop()
|
||||
defer func() {
|
||||
err := service.Stop()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
@@ -26,7 +26,10 @@ func TestLifecycle(t *testing.T) {
|
||||
t.Error("Unexpected content length 0")
|
||||
}
|
||||
|
||||
prometheusService.Stop()
|
||||
err = prometheusService.Stop()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
// Give service time to stop.
|
||||
time.Sleep(time.Second)
|
||||
|
||||
|
||||
@@ -156,7 +156,9 @@ func TestGenerateFullBlock_ValidDeposits(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
beaconState.SetEth1Data(eth1Data)
|
||||
if err := beaconState.SetEth1Data(eth1Data); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
conf := &BlockGenConfig{
|
||||
NumDeposits: 1,
|
||||
}
|
||||
@@ -187,7 +189,10 @@ func TestGenerateFullBlock_ValidDeposits(t *testing.T) {
|
||||
func TestGenerateFullBlock_ValidVoluntaryExits(t *testing.T) {
|
||||
beaconState, privs := DeterministicGenesisState(t, 256)
|
||||
// Moving the state 2048 epochs forward due to PERSISTENT_COMMITTEE_PERIOD.
|
||||
beaconState.SetSlot(3 + params.BeaconConfig().PersistentCommitteePeriod*params.BeaconConfig().SlotsPerEpoch)
|
||||
err := beaconState.SetSlot(3 + params.BeaconConfig().PersistentCommitteePeriod*params.BeaconConfig().SlotsPerEpoch)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
conf := &BlockGenConfig{
|
||||
NumVoluntaryExits: 1,
|
||||
}
|
||||
@@ -202,7 +207,11 @@ func TestGenerateFullBlock_ValidVoluntaryExits(t *testing.T) {
|
||||
|
||||
exitedIndex := block.Block.Body.VoluntaryExits[0].Exit.ValidatorIndex
|
||||
|
||||
if val, _ := beaconState.ValidatorAtIndexReadOnly(exitedIndex); val.ExitEpoch() == params.BeaconConfig().FarFutureEpoch {
|
||||
val, err := beaconState.ValidatorAtIndexReadOnly(exitedIndex)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if val.ExitEpoch() == params.BeaconConfig().FarFutureEpoch {
|
||||
t.Fatal("expected exiting validator index to be marked as exiting")
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user