github.com/prysmaticlabs/prysm@v1.4.4/spectest/shared/phase0/epoch_processing/justification_and_finalization.go (about)

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