@@ -5,11 +5,8 @@ use ethportal_api::types::beacon::ContentInfo;
55use ethportal_api:: utils:: bytes:: hex_encode;
66use ethportal_api:: {
77 BeaconContentKey , BeaconContentValue , BeaconNetworkApiClient , ContentValue , Discv5ApiClient ,
8- OverlayContentKey ,
98} ;
109use hivesim:: types:: ClientDefinition ;
11- use hivesim:: types:: ContentKeyValue ;
12- use hivesim:: types:: TestData ;
1310use hivesim:: { dyn_async, Client , NClientTestSpec , Test } ;
1411use itertools:: Itertools ;
1512use serde_json:: json;
@@ -20,21 +17,13 @@ use std::collections::HashMap;
2017const MAX_PORTAL_CONTENT_PAYLOAD_SIZE : usize = 1165 ;
2118const BOOTSTRAP_KEY : & str = "0x10bd9f42d9a42d972bdaf4dee84e5b419dd432b52867258acb7bcc7f567b6e3af1" ;
2219
23- fn content_pair_to_string_pair (
24- content_pair : ( BeaconContentKey , BeaconContentValue ) ,
25- ) -> ContentKeyValue {
26- let ( content_key, content_value) = content_pair;
27- ContentKeyValue {
28- key : content_key. to_hex ( ) ,
29- value : hex_encode ( content_value. encode ( ) ) ,
30- }
31- }
20+ type TestData = ( BeaconContentKey , BeaconContentValue ) ;
3221
3322/// Processed content data for beacon tests
3423struct ProcessedContent {
3524 content_type : String ,
3625 identifier : String ,
37- test_data : Vec < ContentKeyValue > ,
26+ test_data : TestData ,
3827}
3928
4029fn process_content ( content : Vec < ( BeaconContentKey , BeaconContentValue ) > ) -> Vec < ProcessedContent > {
@@ -44,30 +33,30 @@ fn process_content(content: Vec<(BeaconContentKey, BeaconContentValue)>) -> Vec<
4433 BeaconContentKey :: LightClientBootstrap ( bootstrap) => (
4534 "Bootstrap" . to_string ( ) ,
4635 hex_encode ( bootstrap. block_hash ) ,
47- vec ! [ content_pair_to_string_pair ( beacon_content) ] ,
36+ beacon_content,
4837 ) ,
4938 BeaconContentKey :: LightClientUpdatesByRange ( updates_by_range) => (
5039 "Updates by Range" . to_string ( ) ,
5140 format ! (
5241 "start period: {} count: {}" ,
5342 updates_by_range. start_period, updates_by_range. count
5443 ) ,
55- vec ! [ content_pair_to_string_pair ( beacon_content) ] ,
44+ beacon_content,
5645 ) ,
5746 BeaconContentKey :: LightClientFinalityUpdate ( finality_update) => (
5847 "Finality Update" . to_string ( ) ,
5948 format ! ( "finalized slot: {}" , finality_update. finalized_slot) ,
60- vec ! [ content_pair_to_string_pair ( beacon_content) ] ,
49+ beacon_content,
6150 ) ,
6251 BeaconContentKey :: LightClientOptimisticUpdate ( optimistic_update) => (
6352 "Optimistic Update" . to_string ( ) ,
6453 format ! ( "optimistic slot: {}" , optimistic_update. signature_slot) ,
65- vec ! [ content_pair_to_string_pair ( beacon_content) ] ,
54+ beacon_content,
6655 ) ,
6756 BeaconContentKey :: HistoricalSummariesWithProof ( historical_summaries) => (
6857 "Historical Summaries" . to_string ( ) ,
6958 format ! ( "historical summaries epoch: {}" , historical_summaries. epoch) ,
70- vec ! [ content_pair_to_string_pair ( beacon_content) ] ,
59+ beacon_content,
7160 ) ,
7261 } ;
7362 result. push ( ProcessedContent {
@@ -107,7 +96,7 @@ dyn_async! {
10796 always_run: false ,
10897 run: test_recursive_find_content,
10998 environments: Some ( vec![ Some ( HashMap :: from( [ ( HIVE_PORTAL_NETWORKS_SELECTED . to_string( ) , BEACON_STRING . to_string( ) ) ] ) ) , Some ( HashMap :: from( [ ( HIVE_PORTAL_NETWORKS_SELECTED . to_string( ) , BEACON_STRING . to_string( ) ) ] ) ) ] ) ,
110- test_data: Some ( TestData :: ContentList ( test_data. clone( ) ) ) ,
99+ test_data: test_data. clone( ) ,
111100 clients: vec![ client_a. clone( ) , client_b. clone( ) ] ,
112101 }
113102 ) . await ;
@@ -119,7 +108,7 @@ dyn_async! {
119108 always_run: false ,
120109 run: test_find_content,
121110 environments: Some ( vec![ Some ( HashMap :: from( [ ( HIVE_PORTAL_NETWORKS_SELECTED . to_string( ) , BEACON_STRING . to_string( ) ) ] ) ) , Some ( HashMap :: from( [ ( HIVE_PORTAL_NETWORKS_SELECTED . to_string( ) , BEACON_STRING . to_string( ) ) ] ) ) ] ) ,
122- test_data: Some ( TestData :: ContentList ( test_data ) ) ,
111+ test_data,
123112 clients: vec![ client_a. clone( ) , client_b. clone( ) ] ,
124113 }
125114 ) . await ;
@@ -132,7 +121,7 @@ dyn_async! {
132121 always_run: false ,
133122 run: test_ping,
134123 environments: Some ( vec![ Some ( HashMap :: from( [ ( HIVE_PORTAL_NETWORKS_SELECTED . to_string( ) , BEACON_STRING . to_string( ) ) ] ) ) , Some ( HashMap :: from( [ ( HIVE_PORTAL_NETWORKS_SELECTED . to_string( ) , BEACON_STRING . to_string( ) ) ] ) ) ] ) ,
135- test_data: None ,
124+ test_data: ( ) ,
136125 clients: vec![ client_a. clone( ) , client_b. clone( ) ] ,
137126 }
138127 ) . await ;
@@ -144,7 +133,7 @@ dyn_async! {
144133 always_run: false ,
145134 run: test_find_content_non_present,
146135 environments: Some ( vec![ Some ( HashMap :: from( [ ( HIVE_PORTAL_NETWORKS_SELECTED . to_string( ) , BEACON_STRING . to_string( ) ) ] ) ) , Some ( HashMap :: from( [ ( HIVE_PORTAL_NETWORKS_SELECTED . to_string( ) , BEACON_STRING . to_string( ) ) ] ) ) ] ) ,
147- test_data: None ,
136+ test_data: ( ) ,
148137 clients: vec![ client_a. clone( ) , client_b. clone( ) ] ,
149138 }
150139 ) . await ;
@@ -156,7 +145,7 @@ dyn_async! {
156145 always_run: false ,
157146 run: test_find_nodes_zero_distance,
158147 environments: Some ( vec![ Some ( HashMap :: from( [ ( HIVE_PORTAL_NETWORKS_SELECTED . to_string( ) , BEACON_STRING . to_string( ) ) ] ) ) , Some ( HashMap :: from( [ ( HIVE_PORTAL_NETWORKS_SELECTED . to_string( ) , BEACON_STRING . to_string( ) ) ] ) ) ] ) ,
159- test_data: None ,
148+ test_data: ( ) ,
160149 clients: vec![ client_a. clone( ) , client_b. clone( ) ] ,
161150 }
162151 ) . await ;
@@ -166,7 +155,7 @@ dyn_async! {
166155
167156dyn_async ! {
168157 // test that a node will not return content via FINDCONTENT.
169- async fn test_find_content_non_present<' a>( clients: Vec <Client >, _: Option < TestData > ) {
158+ async fn test_find_content_non_present<' a>( clients: Vec <Client >, _: ( ) ) {
170159 let ( client_a, client_b) = match clients. iter( ) . collect_tuple( ) {
171160 Some ( ( client_a, client_b) ) => ( client_a, client_b) ,
172161 None => {
@@ -208,7 +197,7 @@ dyn_async! {
208197}
209198
210199dyn_async ! {
211- async fn test_ping<' a>( clients: Vec <Client >, _: Option < TestData > ) {
200+ async fn test_ping<' a>( clients: Vec <Client >, _: ( ) ) {
212201 let ( client_a, client_b) = match clients. iter( ) . collect_tuple( ) {
213202 Some ( ( client_a, client_b) ) => ( client_a, client_b) ,
214203 None => {
@@ -249,7 +238,7 @@ dyn_async! {
249238}
250239
251240dyn_async ! {
252- async fn test_find_nodes_zero_distance<' a>( clients: Vec <Client >, _: Option < TestData > ) {
241+ async fn test_find_nodes_zero_distance<' a>( clients: Vec <Client >, _: ( ) ) {
253242 let ( client_a, client_b) = match clients. iter( ) . collect_tuple( ) {
254243 Some ( ( client_a, client_b) ) => ( client_a, client_b) ,
255244 None => {
@@ -285,23 +274,14 @@ dyn_async! {
285274
286275dyn_async ! {
287276 // test that a node will return a content via RECURSIVEFINDCONTENT template that it has stored locally
288- async fn test_recursive_find_content<' a>( clients: Vec <Client >, test_data: Option < TestData > ) {
277+ async fn test_recursive_find_content<' a>( clients: Vec <Client >, test_data: TestData ) {
289278 let ( client_a, client_b) = match clients. iter( ) . collect_tuple( ) {
290279 Some ( ( client_a, client_b) ) => ( client_a, client_b) ,
291280 None => {
292281 panic!( "Unable to get expected amount of clients from NClientTestSpec" ) ;
293282 }
294283 } ;
295- let test_data = match test_data. map( |data| data. content_list( ) ) {
296- Some ( test_data) => test_data,
297- None => panic!( "Expected test data non was provided" ) ,
298- } ;
299-
300- let ContentKeyValue { key: target_key, value: target_value } = test_data. first( ) . expect( "Target content is required for this test" ) ;
301- let target_key: BeaconContentKey =
302- serde_json:: from_value( json!( target_key) ) . unwrap( ) ;
303- let target_value: BeaconContentValue =
304- serde_json:: from_value( json!( target_value) ) . unwrap( ) ;
284+ let ( target_key, target_value) = test_data;
305285 match client_b. rpc. store( target_key. clone( ) , target_value. clone( ) ) . await {
306286 Ok ( result) => if !result {
307287 panic!( "Error storing target content for recursive find content" ) ;
@@ -356,22 +336,14 @@ dyn_async! {
356336
357337dyn_async ! {
358338 // test that a node will return a x content via FINDCONTENT that it has stored locally
359- async fn test_find_content<' a> ( clients: Vec <Client >, test_data: Option < TestData > ) {
339+ async fn test_find_content<' a> ( clients: Vec <Client >, test_data: TestData ) {
360340 let ( client_a, client_b) = match clients. iter( ) . collect_tuple( ) {
361341 Some ( ( client_a, client_b) ) => ( client_a, client_b) ,
362342 None => {
363343 panic!( "Unable to get expected amount of clients from NClientTestSpec" ) ;
364344 }
365345 } ;
366- let test_data = match test_data. map( |data| data. content_list( ) ) {
367- Some ( test_data) => test_data,
368- None => panic!( "Expected test data none was provided" ) ,
369- } ;
370- let ContentKeyValue { key: target_key, value: target_value } = test_data. first( ) . expect( "Target content is required for this test" ) ;
371- let target_key: BeaconContentKey =
372- serde_json:: from_value( json!( target_key) ) . unwrap( ) ;
373- let target_value: BeaconContentValue =
374- serde_json:: from_value( json!( target_value) ) . unwrap( ) ;
346+ let ( target_key, target_value) = test_data;
375347 match client_b. rpc. store( target_key. clone( ) , target_value. clone( ) ) . await {
376348 Ok ( result) => if !result {
377349 panic!( "Error storing target content for find content" ) ;
0 commit comments