@@ -23,7 +23,7 @@ class PreviewSimpleHashSessionTest {
2323
2424 @ BeforeEach
2525 void setUp () throws IOException , ParseException {
26- sampleBlockInfo = BlockUtils .getSampleBlockInfo (BlockUtils . SAMPLE_BLOCKS .HAPI_0_68_0_BLOCK_14 );
26+ sampleBlockInfo = BlockUtils .getSampleBlockInfo (SAMPLE_BLOCKS .HAPI_0_64_0_BLOCK_14 );
2727 blockItems = sampleBlockInfo .blockUnparsed ().blockItems ();
2828 }
2929
@@ -169,164 +169,4 @@ void invalidHash_chunked() throws ParseException {
169169 // to:do (PR #1865) revert when 0.68 verification is supported
170170 // Assertions.assertFalse(blockNotification.success(), "The block notification should be unsuccessful");
171171 }
172-
173- /**
174- * Happy path test for the VerificationSession class.
175- * */
176- @ Test
177- void happyPathPre068 () throws ParseException , IOException {
178- BlockUtils .SampleBlockInfo sampleBlockInfo064 =
179- BlockUtils .getSampleBlockInfo (SAMPLE_BLOCKS .HAPI_0_64_0_BLOCK_14 );
180- List <BlockItemUnparsed > blockItems064 =
181- sampleBlockInfo064 .blockUnparsed ().blockItems ();
182-
183- BlockHeader blockHeader =
184- BlockHeader .PROTOBUF .parse (blockItems064 .getFirst ().blockHeaderOrThrow ());
185-
186- long blockNumber = blockHeader .number ();
187-
188- PreviewSimpleHashSession session = new PreviewSimpleHashSession (blockNumber , BlockSource .PUBLISHER );
189-
190- VerificationNotification blockNotification = session .processBlockItems (blockItems064 );
191-
192- Assertions .assertArrayEquals (
193- blockItems064 .toArray (),
194- session .blockItems .toArray (),
195- "The internal block items should be the same as ones sent in" );
196-
197- Assertions .assertArrayEquals (
198- blockItems064 .toArray (),
199- blockNotification .block ().blockItems ().toArray (),
200- "The notification's block items should be the same as ones sent in" );
201-
202- Assertions .assertEquals (
203- blockNumber ,
204- blockNotification .blockNumber (),
205- "The block number should be the same as the one in the block header" );
206-
207- Assertions .assertEquals (
208- sampleBlockInfo064 .blockRootHash (),
209- blockNotification .blockHash (),
210- "The block hash should be the same as the one in the block header" );
211-
212- Assertions .assertTrue (blockNotification .success (), "The block notification should be successful" );
213-
214- Assertions .assertEquals (
215- sampleBlockInfo064 .blockUnparsed (),
216- blockNotification .block (),
217- "The block should be the same as the one sent" );
218- }
219-
220- /**
221- * Happy path test for the VerificationSession class with chunked list of items, to simulate actual usage.
222- * */
223- @ Test
224- void happyPathChunkedPre068 () throws ParseException , IOException {
225- BlockUtils .SampleBlockInfo sampleBlockInfo064 =
226- BlockUtils .getSampleBlockInfo (SAMPLE_BLOCKS .HAPI_0_64_0_BLOCK_14 );
227- List <BlockItemUnparsed > blockItems064 =
228- sampleBlockInfo064 .blockUnparsed ().blockItems ();
229- List <List <BlockItemUnparsed >> chunkifiedItems = ChunkUtils .chunkify (blockItems064 , 2 );
230- int currentChunk = 0 ;
231- long blockNumber = sampleBlockInfo064 .blockNumber ();
232-
233- PreviewSimpleHashSession session = new PreviewSimpleHashSession (blockNumber , BlockSource .PUBLISHER );
234-
235- VerificationNotification blockNotification = session .processBlockItems (chunkifiedItems .get (currentChunk ));
236-
237- while (blockNotification == null ) {
238- currentChunk ++;
239- blockNotification = session .processBlockItems (chunkifiedItems .get (currentChunk ));
240- }
241-
242- Assertions .assertEquals (
243- blockNumber ,
244- blockNotification .blockNumber (),
245- "The block number should be the same as the one in the block header" );
246-
247- Assertions .assertEquals (
248- sampleBlockInfo064 .blockRootHash (),
249- blockNotification .blockHash (),
250- "The block hash should be the same as the one in the block header" );
251-
252- Assertions .assertTrue (blockNotification .success (), "The block notification should be successful" );
253-
254- Assertions .assertArrayEquals (
255- blockItems064 .toArray (),
256- session .blockItems .toArray (),
257- "The internal block items should be the same as ones sent in" );
258-
259- Assertions .assertArrayEquals (
260- blockItems064 .toArray (),
261- blockNotification .block ().blockItems ().toArray (),
262- "The notification's block items should be the same as ones sent in" );
263- }
264-
265- /**
266- * Non-Happy path test for the VerificationSession class with invalid hash
267- * */
268- @ Test
269- void invalidHashPre068 () throws ParseException , IOException {
270- BlockUtils .SampleBlockInfo sampleBlockInfo064 =
271- BlockUtils .getSampleBlockInfo (SAMPLE_BLOCKS .HAPI_0_64_0_BLOCK_14 );
272- List <BlockItemUnparsed > blockItems064 =
273- sampleBlockInfo064 .blockUnparsed ().blockItems ();
274- // if we remove a block item, the hash will be different
275- blockItems064 .remove (5 );
276-
277- long blockNumber = sampleBlockInfo064 .blockNumber ();
278- VerificationSession session = new PreviewSimpleHashSession (blockNumber , BlockSource .PUBLISHER );
279- VerificationNotification blockNotification = session .processBlockItems (blockItems064 );
280-
281- Assertions .assertEquals (
282- blockNumber ,
283- blockNotification .blockNumber (),
284- "The block number should be the same as the one in the block header" );
285-
286- Assertions .assertNotEquals (
287- sampleBlockInfo064 .blockRootHash (),
288- blockNotification .blockHash (),
289- "The block hash should not be the same as the one in the block header" );
290-
291- // to:do (PR #1865) revert when 0.68 verification is supported
292- // Assertions.assertFalse(blockNotification.success(), "The block notification should be unsuccessful");
293- }
294-
295- /**
296- * Non-Happy path test for the VerificationSession class with invalid hash with chunked list of items, to simulate actual usage.
297- * */
298- @ Test
299- void invalidHashChunkedPre068 () throws ParseException , IOException {
300- BlockUtils .SampleBlockInfo sampleBlockInfo064 =
301- BlockUtils .getSampleBlockInfo (SAMPLE_BLOCKS .HAPI_0_64_0_BLOCK_14 );
302- List <BlockItemUnparsed > blockItems064 =
303- sampleBlockInfo064 .blockUnparsed ().blockItems ();
304- // remove a block item, the hash will be different
305- blockItems064 .remove (5 );
306- // chunkify the list of items
307- List <List <BlockItemUnparsed >> chunkifiedItems = ChunkUtils .chunkify (blockItems064 , 2 );
308- int currentChunk = 0 ;
309- long blockNumber = sampleBlockInfo064 .blockNumber ();
310-
311- VerificationSession session = new PreviewSimpleHashSession (blockNumber , BlockSource .PUBLISHER );
312- VerificationNotification blockNotification = session .processBlockItems (chunkifiedItems .get (currentChunk ));
313-
314- while (blockNotification == null ) {
315- currentChunk ++;
316- blockNotification = session .processBlockItems (chunkifiedItems .get (currentChunk ));
317- }
318-
319- Assertions .assertEquals (
320- blockNumber ,
321- blockNotification .blockNumber (),
322- "The block number should be the same as the one in the block header" );
323-
324- Assertions .assertNotEquals (
325- sampleBlockInfo064 .blockRootHash (),
326- blockNotification .blockHash (),
327- "The block hash should not be the same as the one in the block header" );
328-
329- // to:do (PR #1865) revert when 0.68 verification is supported
330- // Assertions.assertFalse(blockNotification.success(), "The block notification should be unsuccessful");
331- }
332172}
0 commit comments