prysm-pulse/spectest/shared/phase0/epoch_processing/rewards_and_penalties.go

42 lines
1.4 KiB
Go
Raw Normal View History

package epoch_processing
2020-06-09 22:40:48 +00:00
import (
"context"
"path"
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch/precompute"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
"github.com/prysmaticlabs/prysm/spectest/utils"
2020-06-09 22:40:48 +00:00
)
// RunRewardsAndPenaltiesTests executes "epoch_processing/rewards_and_penalties" tests.
func RunRewardsAndPenaltiesTests(t *testing.T, config string) {
require.NoError(t, utils.SetConfig(t, config))
2020-06-09 22:40:48 +00:00
testPath := "epoch_processing/rewards_and_penalties/pyspec_tests"
testFolders, testsFolderPath := utils.TestFolders(t, config, "phase0", testPath)
2020-06-09 22:40:48 +00:00
for _, folder := range testFolders {
helpers.ClearCache()
t.Run(folder.Name(), func(t *testing.T) {
folderPath := path.Join(testsFolderPath, folder.Name())
RunEpochOperationTest(t, folderPath, processRewardsAndPenaltiesPrecomputeWrapper)
2020-06-09 22:40:48 +00:00
})
}
}
func processRewardsAndPenaltiesPrecomputeWrapper(t *testing.T, st iface.BeaconState) (iface.BeaconState, error) {
2020-06-09 22:40:48 +00:00
ctx := context.Background()
vp, bp, err := precompute.New(ctx, st)
require.NoError(t, err)
vp, bp, err = precompute.ProcessAttestations(ctx, st, vp, bp)
require.NoError(t, err)
2020-06-09 22:40:48 +00:00
st, err = precompute.ProcessRewardsAndPenaltiesPrecompute(st, bp, vp, precompute.AttestationsDelta, precompute.ProposersDelta)
require.NoError(t, err, "Could not process reward")
2020-06-09 22:40:48 +00:00
return st, nil
2020-06-09 22:40:48 +00:00
}