@@ -120,3 +120,80 @@ impl PreMergeAccumulator {
120
120
)
121
121
}
122
122
}
123
+
124
+ #[ cfg( test) ]
125
+ mod tests {
126
+ use std:: fs;
127
+
128
+ use alloy:: primitives:: map:: HashMap ;
129
+ use ethportal_api:: {
130
+ types:: execution:: header_with_proof:: { BlockHeaderProof , HeaderWithProof } ,
131
+ HistoryContentKey , HistoryContentValue ,
132
+ } ;
133
+ use rstest:: rstest;
134
+ use trin_utils:: {
135
+ submodules:: {
136
+ read_json_portal_spec_tests_file, read_ssz_portal_spec_tests_file,
137
+ read_yaml_portal_spec_tests_file,
138
+ } ,
139
+ testing:: ContentItem ,
140
+ } ;
141
+
142
+ use super :: * ;
143
+
144
+ #[ rstest]
145
+ fn construct_proof (
146
+ #[ values(
147
+ 1_000_001 , 1_000_002 , 1_000_003 , 1_000_004 , 1_000_005 , 1_000_006 , 1_000_007 , 1_000_008 ,
148
+ 1_000_009 , 1_000_010
149
+ ) ]
150
+ block_number : u64 ,
151
+ ) {
152
+ let all_test_data: HashMap < u64 , ContentItem < HistoryContentKey > > =
153
+ read_json_portal_spec_tests_file (
154
+ "tests/mainnet/history/headers_with_proof/1000001-1000010.json" ,
155
+ )
156
+ . unwrap ( ) ;
157
+ let test_data = all_test_data[ & block_number] . clone ( ) ;
158
+
159
+ let epoch_accumulator = read_ssz_portal_spec_tests_file (
160
+ "tests/mainnet/history/accumulator/epoch-record-00122.ssz" ,
161
+ )
162
+ . unwrap ( ) ;
163
+
164
+ test_construct_proof ( test_data, epoch_accumulator) ;
165
+ }
166
+
167
+ #[ rstest]
168
+ fn construct_proof_from_partial_epoch ( #[ values( 15_537_392 , 15_537_393 ) ] block_number : u64 ) {
169
+ let test_data: ContentItem < HistoryContentKey > = read_yaml_portal_spec_tests_file ( format ! (
170
+ "tests/mainnet/history/headers_with_proof/{block_number}.yaml"
171
+ ) )
172
+ . unwrap ( ) ;
173
+
174
+ let epoch_accumulator_bytes = fs:: read ( "./src/assets/epoch_accs/0xe6ebe562c89bc8ecb94dc9b2889a27a816ec05d3d6bd1625acad72227071e721.bin" ) . unwrap ( ) ;
175
+ let epoch_accumulator = EpochAccumulator :: from_ssz_bytes ( & epoch_accumulator_bytes) . unwrap ( ) ;
176
+ assert_eq ! ( epoch_accumulator. len( ) , 5362 ) ;
177
+
178
+ test_construct_proof ( test_data, epoch_accumulator) ;
179
+ }
180
+
181
+ fn test_construct_proof (
182
+ content_item : ContentItem < HistoryContentKey > ,
183
+ epoch_accumulator : EpochAccumulator ,
184
+ ) {
185
+ let HistoryContentValue :: BlockHeaderWithProof ( HeaderWithProof { header, proof } ) =
186
+ content_item. content_value ( ) . unwrap ( )
187
+ else {
188
+ panic ! ( "Expected BlockHeaderWithProof content value" ) ;
189
+ } ;
190
+
191
+ let BlockHeaderProof :: HistoricalHashes ( expected_proof) = proof else {
192
+ panic ! ( "Expected HistoricalHashes proof" )
193
+ } ;
194
+
195
+ let generated_proof =
196
+ PreMergeAccumulator :: construct_proof ( & header, & epoch_accumulator) . unwrap ( ) ;
197
+ assert_eq ! ( generated_proof, expected_proof) ;
198
+ }
199
+ }
0 commit comments