@@ -548,32 +548,22 @@ impl ContentValue for BeaconContentValue {
548548
549549#[ cfg( test) ]
550550mod test {
551- use std:: str:: FromStr ;
552-
553- use alloy:: primitives:: Bytes ;
554551 use serde:: Deserialize ;
555- use serde_yaml:: Value ;
556552
557553 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 } ;
559555
560556 #[ rstest:: rstest]
561557 #[ case( "capella" , 6718368 ) ]
562558 #[ case( "deneb" , 10248000 ) ]
563559 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 ! (
565561 "tests/mainnet/beacon_chain/light_client/{fork_name}/bootstrap.yaml" ,
566562 ) )
567563 . unwrap ( ) ;
564+ let content_value: BeaconContentValue = test_data. content_value ( ) . unwrap ( ) ;
568565
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 ( ) ) ;
577567
578568 match content_value {
579569 BeaconContentValue :: LightClientBootstrap ( value) => {
@@ -590,19 +580,13 @@ mod test {
590580 #[ case] fork_name : & str ,
591581 #[ case] expected_slot : u64 ,
592582 ) {
593- let file = read_file_from_tests_submodule ( format ! (
583+ let test_data : ContentItem < BeaconContentKey > = read_yaml_portal_spec_tests_file ( format ! (
594584 "tests/mainnet/beacon_chain/light_client/{fork_name}/updates.yaml" ,
595585 ) )
596586 . unwrap ( ) ;
587+ let content_value: BeaconContentValue = test_data. content_value ( ) . unwrap ( ) ;
597588
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 ( ) ) ;
606590
607591 let update = match content_value {
608592 BeaconContentValue :: LightClientUpdatesByRange ( value) => value[ 0 ] . update . clone ( ) ,
@@ -623,19 +607,13 @@ mod test {
623607 #[ case] fork_name : & str ,
624608 #[ case] expected_slot : u64 ,
625609 ) {
626- let file = read_file_from_tests_submodule ( format ! (
610+ let test_data : ContentItem < BeaconContentKey > = read_yaml_portal_spec_tests_file ( format ! (
627611 "tests/mainnet/beacon_chain/light_client/{fork_name}/optimistic_update.yaml" ,
628612 ) )
629613 . unwrap ( ) ;
614+ let content_value: BeaconContentValue = test_data. content_value ( ) . unwrap ( ) ;
630615
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 ( ) ) ;
639617
640618 let update = match content_value {
641619 BeaconContentValue :: LightClientOptimisticUpdate ( value) => value. update ,
@@ -656,19 +634,13 @@ mod test {
656634 #[ case] fork_name : & str ,
657635 #[ case] expected_slot : u64 ,
658636 ) {
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" ,
661639 ) )
662640 . unwrap ( ) ;
641+ let content_value: BeaconContentValue = test_data. content_value ( ) . unwrap ( ) ;
663642
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 ( ) ) ;
672644
673645 let update = match content_value {
674646 BeaconContentValue :: LightClientFinalityUpdate ( value) => value. update ,
@@ -684,10 +656,9 @@ mod test {
684656
685657 #[ test]
686658 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 (
688660 "tests/mainnet/beacon_chain/historical_summaries_with_proof/deneb/historical_summaries_with_proof.yaml" ,
689661 ) . unwrap ( ) ;
690- let value: serde_yaml:: Value = serde_yaml:: from_str ( & file) . unwrap ( ) ;
691662 let content_key = BeaconContentKey :: deserialize ( & value[ "content_key" ] ) . unwrap ( ) ;
692663 let content_bytes = RawContentValue :: deserialize ( & value[ "content_value" ] ) . unwrap ( ) ;
693664 let beacon_content = BeaconContentValue :: decode ( & content_key, & content_bytes) . unwrap ( ) ;
0 commit comments