/
justification_and_finalization.go
42 lines (35 loc) · 1.47 KB
/
justification_and_finalization.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package epoch_processing
import (
"context"
"path"
"testing"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/epoch/precompute"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v3/testing/require"
"github.com/prysmaticlabs/prysm/v3/testing/spectest/utils"
)
// RunJustificationAndFinalizationTests executes "epoch_processing/justification_and_finalization" tests.
func RunJustificationAndFinalizationTests(t *testing.T, config string) {
require.NoError(t, utils.SetConfig(t, config))
testPath := "epoch_processing/justification_and_finalization/pyspec_tests"
testFolders, testsFolderPath := utils.TestFolders(t, config, "phase0", testPath)
if len(testFolders) == 0 {
t.Fatalf("No test folders found for %s/%s/%s", config, "phase0", testPath)
}
for _, folder := range testFolders {
t.Run(folder.Name(), func(t *testing.T) {
folderPath := path.Join(testsFolderPath, folder.Name())
RunEpochOperationTest(t, folderPath, processJustificationAndFinalizationPrecomputeWrapper)
})
}
}
func processJustificationAndFinalizationPrecomputeWrapper(t *testing.T, st state.BeaconState) (state.BeaconState, error) {
ctx := context.Background()
vp, bp, err := precompute.New(ctx, st)
require.NoError(t, err)
_, bp, err = precompute.ProcessAttestations(ctx, st, vp, bp)
require.NoError(t, err)
st, err = precompute.ProcessJustificationAndFinalizationPreCompute(st, bp)
require.NoError(t, err, "Could not process justification")
return st, nil
}