@@ -548,32 +548,22 @@ impl ContentValue for BeaconContentValue {
548
548
549
549
#[ cfg( test) ]
550
550
mod test {
551
- use std:: str:: FromStr ;
552
-
553
- use alloy:: primitives:: Bytes ;
554
551
use serde:: Deserialize ;
555
- use serde_yaml:: Value ;
556
552
557
553
use super :: * ;
558
- use crate :: test_utils:: read_file_from_tests_submodule ;
554
+ use crate :: test_utils:: { read_yaml_portal_spec_tests_file , types :: ContentItem } ;
559
555
560
556
#[ rstest:: rstest]
561
557
#[ case( "capella" , 6718368 ) ]
562
558
#[ case( "deneb" , 10248000 ) ]
563
559
fn light_client_bootstrap_encode_decode ( #[ case] fork_name : & str , #[ case] expected_slot : u64 ) {
564
- let file = read_file_from_tests_submodule ( format ! (
560
+ let test_data : ContentItem < BeaconContentKey > = read_yaml_portal_spec_tests_file ( format ! (
565
561
"tests/mainnet/beacon_chain/light_client/{fork_name}/bootstrap.yaml" ,
566
562
) )
567
563
. unwrap ( ) ;
564
+ let content_value: BeaconContentValue = test_data. content_value ( ) . unwrap ( ) ;
568
565
569
- let value: Value = serde_yaml:: from_str ( & file) . unwrap ( ) ;
570
- let content_key: BeaconContentKey =
571
- serde_yaml:: from_value ( value[ "content_key" ] . clone ( ) ) . unwrap ( ) ;
572
- let raw_content_value = Bytes :: from_str ( value[ "content_value" ] . as_str ( ) . unwrap ( ) ) . unwrap ( ) ;
573
- let content_value = BeaconContentValue :: decode ( & content_key, raw_content_value. as_ref ( ) )
574
- . expect ( "unable to decode content value" ) ;
575
-
576
- assert_str_roundtrip ( content_key, content_value. clone ( ) ) ;
566
+ assert_str_roundtrip ( test_data. content_key , content_value. clone ( ) ) ;
577
567
578
568
match content_value {
579
569
BeaconContentValue :: LightClientBootstrap ( value) => {
@@ -590,19 +580,13 @@ mod test {
590
580
#[ case] fork_name : & str ,
591
581
#[ case] expected_slot : u64 ,
592
582
) {
593
- let file = read_file_from_tests_submodule ( format ! (
583
+ let test_data : ContentItem < BeaconContentKey > = read_yaml_portal_spec_tests_file ( format ! (
594
584
"tests/mainnet/beacon_chain/light_client/{fork_name}/updates.yaml" ,
595
585
) )
596
586
. unwrap ( ) ;
587
+ let content_value: BeaconContentValue = test_data. content_value ( ) . unwrap ( ) ;
597
588
598
- let value: Value = serde_yaml:: from_str ( & file) . unwrap ( ) ;
599
- let content_key: BeaconContentKey =
600
- serde_yaml:: from_value ( value[ "content_key" ] . clone ( ) ) . unwrap ( ) ;
601
- let raw_content_value = Bytes :: from_str ( value[ "content_value" ] . as_str ( ) . unwrap ( ) ) . unwrap ( ) ;
602
- let content_value = BeaconContentValue :: decode ( & content_key, raw_content_value. as_ref ( ) )
603
- . expect ( "unable to decode content value" ) ;
604
-
605
- assert_str_roundtrip ( content_key, content_value. clone ( ) ) ;
589
+ assert_str_roundtrip ( test_data. content_key , content_value. clone ( ) ) ;
606
590
607
591
let update = match content_value {
608
592
BeaconContentValue :: LightClientUpdatesByRange ( value) => value[ 0 ] . update . clone ( ) ,
@@ -623,19 +607,13 @@ mod test {
623
607
#[ case] fork_name : & str ,
624
608
#[ case] expected_slot : u64 ,
625
609
) {
626
- let file = read_file_from_tests_submodule ( format ! (
610
+ let test_data : ContentItem < BeaconContentKey > = read_yaml_portal_spec_tests_file ( format ! (
627
611
"tests/mainnet/beacon_chain/light_client/{fork_name}/optimistic_update.yaml" ,
628
612
) )
629
613
. unwrap ( ) ;
614
+ let content_value: BeaconContentValue = test_data. content_value ( ) . unwrap ( ) ;
630
615
631
- let value: Value = serde_yaml:: from_str ( & file) . unwrap ( ) ;
632
- let content_key: BeaconContentKey =
633
- serde_yaml:: from_value ( value[ "content_key" ] . clone ( ) ) . unwrap ( ) ;
634
- let raw_content_value = Bytes :: from_str ( value[ "content_value" ] . as_str ( ) . unwrap ( ) ) . unwrap ( ) ;
635
- let content_value = BeaconContentValue :: decode ( & content_key, raw_content_value. as_ref ( ) )
636
- . expect ( "unable to decode content value" ) ;
637
-
638
- assert_str_roundtrip ( content_key, content_value. clone ( ) ) ;
616
+ assert_str_roundtrip ( test_data. content_key , content_value. clone ( ) ) ;
639
617
640
618
let update = match content_value {
641
619
BeaconContentValue :: LightClientOptimisticUpdate ( value) => value. update ,
@@ -656,19 +634,13 @@ mod test {
656
634
#[ case] fork_name : & str ,
657
635
#[ case] expected_slot : u64 ,
658
636
) {
659
- let file = read_file_from_tests_submodule ( format ! (
660
- "tests/mainnet/beacon_chain/light_client/{fork_name}/finality_update.yaml"
637
+ let test_data : ContentItem < BeaconContentKey > = read_yaml_portal_spec_tests_file ( format ! (
638
+ "tests/mainnet/beacon_chain/light_client/{fork_name}/finality_update.yaml" ,
661
639
) )
662
640
. unwrap ( ) ;
641
+ let content_value: BeaconContentValue = test_data. content_value ( ) . unwrap ( ) ;
663
642
664
- let value: Value = serde_yaml:: from_str ( & file) . unwrap ( ) ;
665
- let content_key: BeaconContentKey =
666
- serde_yaml:: from_value ( value[ "content_key" ] . clone ( ) ) . unwrap ( ) ;
667
- let raw_content_value = Bytes :: from_str ( value[ "content_value" ] . as_str ( ) . unwrap ( ) ) . unwrap ( ) ;
668
- let content_value = BeaconContentValue :: decode ( & content_key, raw_content_value. as_ref ( ) )
669
- . expect ( "unable to decode content value" ) ;
670
-
671
- assert_str_roundtrip ( content_key, content_value. clone ( ) ) ;
643
+ assert_str_roundtrip ( test_data. content_key , content_value. clone ( ) ) ;
672
644
673
645
let update = match content_value {
674
646
BeaconContentValue :: LightClientFinalityUpdate ( value) => value. update ,
@@ -684,10 +656,9 @@ mod test {
684
656
685
657
#[ test]
686
658
fn deneb_historical_summaries_with_proof_encode_decode ( ) {
687
- let file = read_file_from_tests_submodule (
659
+ let value : serde_yaml :: Value = read_yaml_portal_spec_tests_file (
688
660
"tests/mainnet/beacon_chain/historical_summaries_with_proof/deneb/historical_summaries_with_proof.yaml" ,
689
661
) . unwrap ( ) ;
690
- let value: serde_yaml:: Value = serde_yaml:: from_str ( & file) . unwrap ( ) ;
691
662
let content_key = BeaconContentKey :: deserialize ( & value[ "content_key" ] ) . unwrap ( ) ;
692
663
let content_bytes = RawContentValue :: deserialize ( & value[ "content_value" ] ) . unwrap ( ) ;
693
664
let beacon_content = BeaconContentValue :: decode ( & content_key, & content_bytes) . unwrap ( ) ;
0 commit comments