github.com/prysmaticlabs/prysm@v1.4.4/spectest/shared/phase0/epoch_processing/slashings.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" 9 "github.com/prysmaticlabs/prysm/beacon-chain/core/epoch/precompute" 10 iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface" 11 "github.com/prysmaticlabs/prysm/shared/testutil/require" 12 "github.com/prysmaticlabs/prysm/spectest/utils" 13 ) 14 15 // RunSlashingsTests executes "epoch_processing/slashings" tests. 16 func RunSlashingsTests(t *testing.T, config string) { 17 require.NoError(t, utils.SetConfig(t, config)) 18 19 testFolders, testsFolderPath := utils.TestFolders(t, config, "phase0", "epoch_processing/slashings/pyspec_tests") 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, processSlashingsWrapper) 24 RunEpochOperationTest(t, folderPath, processSlashingsPrecomputeWrapper) 25 }) 26 } 27 } 28 29 func processSlashingsWrapper(t *testing.T, state iface.BeaconState) (iface.BeaconState, error) { 30 state, err := epoch.ProcessSlashings(state) 31 require.NoError(t, err, "Could not process slashings") 32 return state, nil 33 } 34 35 func processSlashingsPrecomputeWrapper(t *testing.T, state iface.BeaconState) (iface.BeaconState, error) { 36 ctx := context.Background() 37 vp, bp, err := precompute.New(ctx, state) 38 require.NoError(t, err) 39 _, bp, err = precompute.ProcessAttestations(ctx, state, vp, bp) 40 require.NoError(t, err) 41 42 return state, precompute.ProcessSlashingsPrecompute(state, bp) 43 }