2021-04-22 14:53:30 +00:00
|
|
|
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"
|
2021-03-08 22:37:33 +00:00
|
|
|
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
|
2020-08-10 10:34:33 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
2021-04-22 14:53:30 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/spectest/utils"
|
2020-06-09 22:40:48 +00:00
|
|
|
)
|
|
|
|
|
2021-04-23 12:06:05 +00:00
|
|
|
// RunRewardsAndPenaltiesTests executes "epoch_processing/rewards_and_penalties" tests.
|
2021-04-22 14:53:30 +00:00
|
|
|
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"
|
2021-04-22 16:34:00 +00:00
|
|
|
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())
|
2021-04-22 16:34:00 +00:00
|
|
|
RunEpochOperationTest(t, folderPath, processRewardsAndPenaltiesPrecomputeWrapper)
|
2020-06-09 22:40:48 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-08 22:37:33 +00:00
|
|
|
func processRewardsAndPenaltiesPrecomputeWrapper(t *testing.T, st iface.BeaconState) (iface.BeaconState, error) {
|
2020-06-09 22:40:48 +00:00
|
|
|
ctx := context.Background()
|
2021-01-04 20:07:12 +00:00
|
|
|
vp, bp, err := precompute.New(ctx, st)
|
2020-08-10 10:34:33 +00:00
|
|
|
require.NoError(t, err)
|
2021-01-04 20:07:12 +00:00
|
|
|
vp, bp, err = precompute.ProcessAttestations(ctx, st, vp, bp)
|
2020-08-10 10:34:33 +00:00
|
|
|
require.NoError(t, err)
|
2020-06-09 22:40:48 +00:00
|
|
|
|
2021-04-13 04:55:45 +00:00
|
|
|
st, err = precompute.ProcessRewardsAndPenaltiesPrecompute(st, bp, vp, precompute.AttestationsDelta, precompute.ProposersDelta)
|
2020-08-10 10:34:33 +00:00
|
|
|
require.NoError(t, err, "Could not process reward")
|
2020-06-09 22:40:48 +00:00
|
|
|
|
2021-01-04 20:07:12 +00:00
|
|
|
return st, nil
|
2020-06-09 22:40:48 +00:00
|
|
|
}
|