-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add finality, sync tests and enable several sanity cases. (#487)
- Loading branch information
Showing
4 changed files
with
168 additions
and
106 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
defmodule FinalityTestRunner do | ||
@moduledoc """ | ||
Runner for finality test cases. See: https://github.com/ethereum/consensus-specs/tree/dev/tests/formats/finality | ||
""" | ||
|
||
use ExUnit.CaseTemplate | ||
use TestRunner | ||
|
||
@disabled_cases [ | ||
# "finality_no_updates_at_genesis", | ||
# "finality_rule_1", | ||
# "finality_rule_2", | ||
# "finality_rule_3", | ||
# "finality_rule_4" | ||
] | ||
|
||
@impl TestRunner | ||
def skip?(%SpecTestCase{fork: "capella", case: testcase}) do | ||
Enum.member?(@disabled_cases, testcase) | ||
end | ||
|
||
@impl TestRunner | ||
def run_test_case(testcase) do | ||
Helpers.ProcessBlocks.process_blocks(testcase) | ||
end | ||
end |
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,57 @@ | ||
defmodule Helpers.ProcessBlocks do | ||
@moduledoc """ | ||
Helper module for processing blocks. | ||
""" | ||
|
||
use ExUnit.CaseTemplate | ||
|
||
alias LambdaEthereumConsensus.StateTransition | ||
alias LambdaEthereumConsensus.Utils.Diff | ||
|
||
def process_blocks(%SpecTestCase{} = testcase) do | ||
case_dir = SpecTestCase.dir(testcase) | ||
|
||
pre = | ||
SpecTestUtils.read_ssz_from_file!( | ||
case_dir <> "/pre.ssz_snappy", | ||
SszTypes.BeaconState | ||
) | ||
|
||
post = | ||
SpecTestUtils.read_ssz_from_optional_file!( | ||
case_dir <> "/post.ssz_snappy", | ||
SszTypes.BeaconState | ||
) | ||
|
||
meta = | ||
YamlElixir.read_from_file!(case_dir <> "/meta.yaml") |> SpecTestUtils.sanitize_yaml() | ||
|
||
%{blocks_count: blocks_count} = meta | ||
|
||
blocks = | ||
0..(blocks_count - 1)//1 | ||
|> Enum.map(fn index -> | ||
SpecTestUtils.read_ssz_from_file!( | ||
case_dir <> "/blocks_#{index}.ssz_snappy", | ||
SszTypes.SignedBeaconBlock | ||
) | ||
end) | ||
|
||
result = | ||
blocks | ||
|> Enum.reduce_while({:ok, pre}, fn block, {:ok, state} -> | ||
case StateTransition.state_transition(state, block, true) do | ||
{:ok, post_state} -> {:cont, {:ok, post_state}} | ||
{:error, error} -> {:halt, {:error, error}} | ||
end | ||
end) | ||
|
||
case result do | ||
{:ok, state} -> | ||
assert Diff.diff(state, post) == :unchanged | ||
|
||
{:error, error} -> | ||
assert post == nil, "Process block failed, error: #{error}" | ||
end | ||
end | ||
end |
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,22 @@ | ||
defmodule SyncTestRunner do | ||
@moduledoc """ | ||
Runner for Operations test cases. See: https://github.com/ethereum/consensus-specs/tree/dev/tests/formats/sync | ||
""" | ||
|
||
use ExUnit.CaseTemplate | ||
use TestRunner | ||
|
||
@disabled_cases [ | ||
"from_syncing_to_invalid" | ||
] | ||
|
||
@impl TestRunner | ||
def skip?(%SpecTestCase{} = testcase) do | ||
Enum.member?(@disabled_cases, testcase.case) | ||
end | ||
|
||
@impl TestRunner | ||
def run_test_case(%SpecTestCase{} = testcase) do | ||
ForkChoiceTestRunner.run_test_case(testcase) | ||
end | ||
end |