-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Block Processing Sanity Spec Tests (#2817)
* update PrevEpoch * add new changes * shift to blocks package * add more changes * new changes * updated pb with size tags * add new changes * fix errors * uncomment code * more changes * add new changes * rename and lint * gaz * more changes * proccess slot SigningRoot instead of HashTreeRoot * ensure yaml generated structs work * block sanity all passing * minimal and mainnet all pass * remove commented code * fix one test * fix all tests * fix again * no state comparison * matching spec * change target viz * comments gazelle * clear caches before test cases * latest attempts * clean up test format * remove debugging log, remove yaml * unskip attestation * remove skip, check post state, diff state diffs * handle err * add bug fixes * fixed one more bug * fixed churn limit bug * change hashProto to HashTreeRoot * all tests pass :) * fix all tests * gaz * add regression tests * fix test bug
- Loading branch information
Nishant Das
authored
Jun 29, 2019
1 parent
816d14f
commit c5a4778
Showing
24 changed files
with
365 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = [ | ||
"blocks_mainnet.yaml.go", | ||
"blocks_minimal.yaml.go", | ||
], | ||
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks/spectest", | ||
visibility = ["//beacon-chain:__subpackages__"], | ||
deps = ["//proto/beacon/p2p/v1:go_default_library"], | ||
) | ||
|
||
go_test( | ||
name = "go_default_test", | ||
srcs = ["block_processing_test.go"], | ||
data = [ | ||
"@eth2_spec_tests//:test_data", | ||
], | ||
embed = [":go_default_library"], | ||
tags = ["spectest"], | ||
deps = [ | ||
"//beacon-chain/core/blocks:go_default_library", | ||
"//beacon-chain/core/helpers:go_default_library", | ||
"//beacon-chain/core/state:go_default_library", | ||
"//shared/params/spectest:go_default_library", | ||
"@com_github_ghodss_yaml//:go_default_library", | ||
"@com_github_golang_protobuf//proto:go_default_library", | ||
"@in_gopkg_d4l3k_messagediff_v1//:go_default_library", | ||
"@io_bazel_rules_go//go/tools/bazel:go_default_library", | ||
], | ||
) |
66 changes: 66 additions & 0 deletions
66
beacon-chain/core/blocks/spectest/block_processing_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package spectest | ||
|
||
import ( | ||
"context" | ||
"io/ioutil" | ||
"testing" | ||
|
||
"github.com/bazelbuild/rules_go/go/tools/bazel" | ||
"github.com/ghodss/yaml" | ||
"github.com/golang/protobuf/proto" | ||
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" | ||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" | ||
"github.com/prysmaticlabs/prysm/beacon-chain/core/state" | ||
"github.com/prysmaticlabs/prysm/shared/params/spectest" | ||
"gopkg.in/d4l3k/messagediff.v1" | ||
) | ||
|
||
func TestBlockProcessingMinimalYaml(t *testing.T) { | ||
runBlockProcessingTest(t, "sanity_blocks_minimal.yaml") | ||
} | ||
|
||
func TestBlockProcessingMainnetYaml(t *testing.T) { | ||
runBlockProcessingTest(t, "sanity_blocks_mainnet.yaml") | ||
} | ||
|
||
func runBlockProcessingTest(t *testing.T, filename string) { | ||
filepath, err := bazel.Runfile("/eth2_spec_tests/tests/sanity/blocks/" + filename) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
file, err := ioutil.ReadFile(filepath) | ||
if err != nil { | ||
t.Fatalf("Could not load file %v", err) | ||
} | ||
|
||
s := &BlocksMainnet{} | ||
if err := yaml.Unmarshal(file, s); err != nil { | ||
t.Fatalf("Failed to Unmarshal: %v", err) | ||
} | ||
|
||
if err := spectest.SetConfig(s.Config); err != nil { | ||
t.Fatalf("Could not set config: %v", err) | ||
} | ||
|
||
for _, tt := range s.TestCases { | ||
t.Run(tt.Description, func(t *testing.T) { | ||
ctx := context.Background() | ||
helpers.ClearAllCaches() | ||
blocks.ClearEth1DataVoteCache() | ||
|
||
stateConfig := state.DefaultConfig() | ||
s := tt.Pre // Pre-state | ||
for _, b := range tt.Blocks { | ||
if tt.Pre, err = state.ExecuteStateTransition(ctx, tt.Pre, b, stateConfig); err != nil { | ||
t.Fatalf("Transition failed with block at slot %d: %v", b.Slot, err) | ||
} | ||
} | ||
|
||
if !proto.Equal(s, tt.Post) { | ||
diff, _ := messagediff.PrettyDiff(s, tt.Post) | ||
t.Log(diff) | ||
t.Fatal("Post state does not match expected") | ||
} | ||
}) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.