-
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.
Merge branch 'main' into optimize-process_operations
- Loading branch information
Showing
6 changed files
with
205 additions
and
166 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
defmodule RandomTestRunner do | ||
@moduledoc """ | ||
Runner for random test cases. See: https://github.com/ethereum/consensus-specs/tree/dev/tests/formats/random | ||
""" | ||
|
||
use ExUnit.CaseTemplate | ||
use TestRunner | ||
|
||
@disabled_cases [ | ||
"randomized_0", | ||
# "randomized_1", | ||
"randomized_2", | ||
"randomized_3", | ||
# "randomized_4", | ||
"randomized_5", | ||
"randomized_6", | ||
"randomized_7", | ||
# "randomized_8", | ||
# "randomized_9", | ||
"randomized_10", | ||
# "randomized_11", | ||
"randomized_12", | ||
"randomized_13", | ||
"randomized_14", | ||
"randomized_15" | ||
] | ||
|
||
@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
Oops, something went wrong.