Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unskip minimal spec test for finalization #3920

Merged
merged 1 commit into from
Nov 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ import (
)

func TestJustificationAndFinalizationMinimal(t *testing.T) {
t.Skip("Fails for could not get target atts current epoch")
runJustificationAndFinalizationTests(t, "minimal")
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package spectest

import (
"bytes"
"context"
"fmt"
"path"
"testing"

Expand Down Expand Up @@ -32,19 +34,19 @@ func runJustificationAndFinalizationTests(t *testing.T, config string) {
// This is a subset of state.ProcessEpoch. The spec test defines input data for
// `justification_and_finalization` only.
func processJustificationAndFinalizationWrapper(t *testing.T, state *pb.BeaconState) (*pb.BeaconState, error) {
prevEpochAtts, err := epoch.MatchAttestations(state, helpers.PrevEpoch(state))
prevEpochAtts, err := targetAtts(state, helpers.PrevEpoch(state))
if err != nil {
t.Fatalf("could not get target atts prev epoch %d: %v", helpers.PrevEpoch(state), err)
}
currentEpochAtts, err := epoch.MatchAttestations(state, helpers.CurrentEpoch(state))
currentEpochAtts, err := targetAtts(state, helpers.CurrentEpoch(state))
if err != nil {
t.Fatalf("could not get target atts current epoch %d: %v", helpers.CurrentEpoch(state), err)
}
prevEpochAttestedBalance, err := epoch.AttestingBalance(state, prevEpochAtts.Target)
prevEpochAttestedBalance, err := epoch.AttestingBalance(state, prevEpochAtts)
if err != nil {
t.Fatalf("could not get attesting balance prev epoch: %v", err)
}
currentEpochAttestedBalance, err := epoch.AttestingBalance(state, currentEpochAtts.Target)
currentEpochAttestedBalance, err := epoch.AttestingBalance(state, currentEpochAtts)
if err != nil {
t.Fatalf("could not get attesting balance current epoch: %v", err)
}
Expand Down Expand Up @@ -72,3 +74,36 @@ func processJustificationAndFinalizationPrecomputeWrapper(t *testing.T, state *p

return state, nil
}

func targetAtts(state *pb.BeaconState, epoch uint64) ([]*pb.PendingAttestation, error) {
currentEpoch := helpers.CurrentEpoch(state)
previousEpoch := helpers.PrevEpoch(state)

// Input epoch for matching the source attestations has to be within range
// of current epoch & previous epoch.
if epoch != currentEpoch && epoch != previousEpoch {
return nil, fmt.Errorf("input epoch: %d != current epoch: %d or previous epoch: %d",
epoch, currentEpoch, previousEpoch)
}

// Decide if the source attestations are coming from current or previous epoch.
var srcAtts []*pb.PendingAttestation
if epoch == currentEpoch {
srcAtts = state.CurrentEpochAttestations
} else {
srcAtts = state.PreviousEpochAttestations
}
targetRoot, err := helpers.BlockRoot(state, epoch)
if err != nil {
return nil, err
}

tgtAtts := make([]*pb.PendingAttestation, 0, len(srcAtts))
for _, srcAtt := range srcAtts {
if bytes.Equal(srcAtt.Data.Target.Root, targetRoot) {
tgtAtts = append(tgtAtts, srcAtt)
}
}

return tgtAtts, nil
}