@@ -2,24 +2,60 @@ defmodule SszStaticTestRunner do
2
2
@ moduledoc """
3
3
Runner for SSZ test cases. `run_test_case/1` is the main entrypoint.
4
4
"""
5
+ alias LambdaEthereumConsensus.SszEx
5
6
alias LambdaEthereumConsensus.Utils.Diff
6
7
7
8
use ExUnit.CaseTemplate
8
9
use TestRunner
9
- import Aja
10
10
11
11
@ disabled [
12
- "ContributionAndProof" ,
13
- "Eth1Block" ,
12
+ # "DepositData",
13
+ # "DepositMessage",
14
+ # "Eth1Data",
15
+ # "ProposerSlashing",
16
+ # "SignedBeaconBlockHeader",
17
+ # "SignedVoluntaryExit",
18
+ # "Validator",
19
+ # "VoluntaryExit",
20
+ # "Attestation",
21
+ # "AttestationData",
22
+ # "BLSToExecutionChange",
23
+ # "BeaconBlockHeader",
24
+ # "Checkpoint",
25
+ # "Deposit",
26
+ # "SignedBLSToExecutionChange",
27
+ # "SigningData",
28
+ # "SyncCommittee",
29
+ # "Withdrawal",
30
+ # "AttesterSlashing",
31
+ # "HistoricalSummary",
32
+ # "PendingAttestation",
33
+ # "Fork",
34
+ # "ForkData",
35
+ # "HistoricalBatch",
36
+ # "IndexedAttestation",
37
+ "ExecutionPayload" ,
38
+ "ExecutionPayloadHeader" ,
39
+ "SignedBeaconBlock" ,
40
+ "SyncAggregate" ,
41
+ "AggregateAndProof" ,
42
+ "BeaconBlock" ,
43
+ "BeaconBlockBody" ,
44
+ "BeaconState" ,
45
+ "SignedAggregateAndProof" ,
46
+ # -- not defined yet
14
47
"LightClientBootstrap" ,
15
- "LightClientFinalityUpdate" ,
16
- "LightClientHeader" ,
17
48
"LightClientOptimisticUpdate" ,
18
49
"LightClientUpdate" ,
50
+ "Eth1Block" ,
19
51
"PowBlock" ,
20
52
"SignedContributionAndProof" ,
53
+ "SignedData" ,
21
54
"SyncAggregatorSelectionData" ,
22
55
"SyncCommitteeContribution" ,
56
+ "ContributionAndProof" ,
57
+ "LightClientFinalityUpdate" ,
58
+ "LightClientHeader" ,
23
59
"SyncCommitteeMessage"
24
60
]
25
61
@@ -40,46 +76,25 @@ defmodule SszStaticTestRunner do
40
76
expected =
41
77
YamlElixir . read_from_file! ( case_dir <> "/value.yaml" )
42
78
|> SpecTestUtils . sanitize_yaml ( )
79
+ |> SpecTestUtils . sanitize_ssz ( schema )
43
80
44
81
% { "root" => expected_root } = YamlElixir . read_from_file! ( case_dir <> "/roots.yaml" )
45
82
expected_root = expected_root |> SpecTestUtils . sanitize_yaml ( )
46
83
47
84
assert_ssz ( schema , decompressed , expected , expected_root )
48
85
end
49
86
50
- defp assert_ssz ( schema , real_serialized , real_deserialized , expected_root ) do
51
- { :ok , deserialized } = Ssz . from_ssz ( real_serialized , schema )
52
- real_deserialized = to_struct_checked ( deserialized , real_deserialized )
53
-
87
+ defp assert_ssz ( schema , real_serialized , real_deserialized , _expected_root ) do
88
+ { :ok , deserialized } = SszEx . decode ( real_serialized , schema )
54
89
assert Diff . diff ( deserialized , real_deserialized ) == :unchanged
55
-
56
- { :ok , serialized } = Ssz . to_ssz ( real_deserialized )
90
+ { :ok , serialized } = SszEx . encode ( real_deserialized , schema )
57
91
assert serialized == real_serialized
58
92
59
- root = Ssz . hash_tree_root! ( real_deserialized )
60
- assert root == expected_root
61
- end
62
-
63
- defp to_struct_checked ( actual , expected ) when is_list ( actual ) and is_list ( expected ) do
64
- Stream . zip ( actual , expected ) |> Enum . map ( fn { a , e } -> to_struct_checked ( a , e ) end )
65
- end
66
-
67
- defp to_struct_checked ( vec ( _ ) = actual , vec ( _ ) = expected ) do
68
- actual
69
- |> Aja.Enum . to_list ( )
70
- |> to_struct_checked ( Aja.Enum . to_list ( expected ) )
71
- |> Aja.Vector . new ( )
72
- end
73
-
74
- defp to_struct_checked ( % name { } = actual , % { } = expected ) do
75
- expected
76
- |> Stream . map ( fn { k , v } -> { k , to_struct_checked ( Map . get ( actual , k ) , v ) } end )
77
- |> Map . new ( )
78
- |> then ( & struct! ( name , & 1 ) )
93
+ ## TODO Enable when merklelization is enable
94
+ # root = SszEx.hash_tree_root!(real_deserialized)
95
+ # assert root == expected_root
79
96
end
80
97
81
- defp to_struct_checked ( _actual , expected ) , do: expected
82
-
83
98
defp parse_type ( % SpecTestCase { handler: handler } ) do
84
99
Module . concat ( Types , handler )
85
100
end
0 commit comments