Add spec tests for process_slashing and process_justification_finalization (#3803)

* Add precompute spec tests

* Gazelle
This commit is contained in:
terence tsao 2019-10-18 09:09:38 -07:00 committed by GitHub
parent a41ac6b498
commit a05dca18c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 0 deletions

View File

@ -26,6 +26,7 @@ go_test(
],
deps = [
"//beacon-chain/core/epoch:go_default_library",
"//beacon-chain/core/epoch/precompute:go_default_library",
"//beacon-chain/core/helpers:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//shared/params/spectest:go_default_library",
@ -55,6 +56,7 @@ go_test(
],
deps = [
"//beacon-chain/core/epoch:go_default_library",
"//beacon-chain/core/epoch/precompute:go_default_library",
"//beacon-chain/core/helpers:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//shared/params/spectest:go_default_library",

View File

@ -1,10 +1,12 @@
package spectest
import (
"context"
"path"
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch"
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch/precompute"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/params/spectest"
@ -22,6 +24,7 @@ func runJustificationAndFinalizationTests(t *testing.T, config string) {
t.Run(folder.Name(), func(t *testing.T) {
folderPath := path.Join(testsFolderPath, folder.Name())
testutil.RunEpochOperationTest(t, folderPath, processJustificationAndFinalizationWrapper)
testutil.RunEpochOperationTest(t, folderPath, processJustificationAndFinalizationPrecomputeWrapper)
})
}
}
@ -53,3 +56,19 @@ func processJustificationAndFinalizationWrapper(t *testing.T, state *pb.BeaconSt
return state, nil
}
func processJustificationAndFinalizationPrecomputeWrapper(t *testing.T, state *pb.BeaconState) (*pb.BeaconState, error) {
ctx := context.Background()
vp, bp := precompute.New(ctx, state)
_, bp, err := precompute.ProcessAttestations(ctx, state, vp, bp)
if err != nil {
t.Fatal(err)
}
state, err = precompute.ProcessJustificationAndFinalizationPreCompute(state, bp)
if err != nil {
t.Fatalf("could not process justification: %v", err)
}
return state, nil
}

View File

@ -1,10 +1,12 @@
package spectest
import (
"context"
"path"
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch"
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch/precompute"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/params/spectest"
"github.com/prysmaticlabs/prysm/shared/testutil"
@ -20,6 +22,7 @@ func runSlashingsTests(t *testing.T, config string) {
t.Run(folder.Name(), func(t *testing.T) {
folderPath := path.Join(testsFolderPath, folder.Name())
testutil.RunEpochOperationTest(t, folderPath, processSlashingsWrapper)
testutil.RunEpochOperationTest(t, folderPath, processSlashingsPrecomputeWrapper)
})
}
}
@ -31,3 +34,15 @@ func processSlashingsWrapper(t *testing.T, state *pb.BeaconState) (*pb.BeaconSta
}
return state, nil
}
func processSlashingsPrecomputeWrapper(t *testing.T, state *pb.BeaconState) (*pb.BeaconState, error) {
ctx := context.Background()
vp, bp := precompute.New(ctx, state)
_, bp, err := precompute.ProcessAttestations(ctx, state, vp, bp)
if err != nil {
t.Fatal(err)
}
state = precompute.ProcessSlashingsPrecompute(state, bp)
return state, nil
}