diff --git a/simulators/portal/src/suites/beacon/rpc_compat.rs b/simulators/portal/src/suites/beacon/rpc_compat.rs index 46f740330d..1a8f552441 100644 --- a/simulators/portal/src/suites/beacon/rpc_compat.rs +++ b/simulators/portal/src/suites/beacon/rpc_compat.rs @@ -7,6 +7,7 @@ use crate::suites::beacon::constants::{ use crate::suites::environment::PortalNetwork; use alloy_primitives::Bytes; use ethportal_api::types::enr::generate_random_remote_enr; +use ethportal_api::types::portal::ContentInfo; use ethportal_api::Discv5ApiClient; use ethportal_api::{BeaconContentKey, BeaconNetworkApiClient}; use hivesim::types::ClientDefinition; @@ -192,6 +193,18 @@ dyn_async! { clients: vec![client.clone()], } ).await; + + test.run( + NClientTestSpec { + name: "portal_beaconRecursiveFindContent Content Present Locally".to_string(), + description: "".to_string(), + always_run: false, + run: test_recursive_find_content_content_present_locally, + environments: environments.clone(), + test_data: (), + clients: vec![client.clone()], + } + ).await; } } } @@ -257,7 +270,7 @@ dyn_async! { // seed CONTENT_KEY/content_value onto the local node to test local_content expect content present if let Err(err) = BeaconNetworkApiClient::store(&client.rpc, content_key.clone(), raw_content_value.clone()).await { - panic!("{}", &err.to_string()); + panic!("Failed to store data: {}", &err.to_string()); } // Here we are calling local_content RPC to test if the content is present @@ -523,3 +536,40 @@ dyn_async! { } } } + +dyn_async! { + // test that a node will return a PresentContent via RecursiveFindContent when the data is stored locally + async fn test_recursive_find_content_content_present_locally<'a>(clients: Vec, _: ()) { + let client = match clients.into_iter().next() { + Some((client)) => client, + None => { + panic!("Unable to get expected amount of clients from NClientTestSpec"); + } + }; + + let content_key: BeaconContentKey = serde_json::from_value(json!(CONSTANT_CONTENT_KEY)).unwrap(); + let raw_content_value = Bytes::from_str(CONSTANT_CONTENT_VALUE).expect("unable to convert content value to bytes"); + + // seed content_key/content_value onto the local node to test recursive_find_content expect content present + if let Err(err) = BeaconNetworkApiClient::store(&client.rpc, content_key.clone(), raw_content_value.clone()).await { + panic!("Failed to store data: {}", &err.to_string()); + } + + match BeaconNetworkApiClient::recursive_find_content(&client.rpc, content_key).await { + Ok(ContentInfo::Content { content, utp_transfer }) => { + if utp_transfer { + panic!("Error: Expected utp_transfer to be false"); + } + if content != raw_content_value { + panic!("Error receiving content: Expected content: {raw_content_value:?}, Received content: {content:?}"); + } + } + Err(err) => { + panic!("Expected RecursiveFindContent to not throw an error {}", &err.to_string()); + } + _ => { + panic!("Error: Expected RecursiveFindContent to return ContentInfo::Content"); + } + } + } +} diff --git a/simulators/portal/src/suites/history/rpc_compat.rs b/simulators/portal/src/suites/history/rpc_compat.rs index 549f010006..93ad182284 100644 --- a/simulators/portal/src/suites/history/rpc_compat.rs +++ b/simulators/portal/src/suites/history/rpc_compat.rs @@ -3,6 +3,7 @@ use std::str::FromStr; use crate::suites::history::constants::TRIN_BRIDGE_CLIENT_TYPE; use alloy_primitives::Bytes; use ethportal_api::types::enr::generate_random_remote_enr; +use ethportal_api::types::portal::ContentInfo; use ethportal_api::Discv5ApiClient; use ethportal_api::{HistoryContentKey, HistoryNetworkApiClient}; use hivesim::types::ClientDefinition; @@ -189,6 +190,18 @@ dyn_async! { clients: vec![client.clone()], } ).await; + + test.run( + NClientTestSpec { + name: "portal_historyRecursiveFindContent Content Present Locally".to_string(), + description: "".to_string(), + always_run: false, + run: test_recursive_find_content_content_present_locally, + environments: None, + test_data: (), + clients: vec![client.clone()], + } + ).await; } } } @@ -254,7 +267,7 @@ dyn_async! { // seed content_key/content_value onto the local node to test local_content expect content present if let Err(err) = HistoryNetworkApiClient::store(&client.rpc, content_key.clone(), raw_content_value.clone()).await { - panic!("{}", &err.to_string()); + panic!("Failed to store data: {}", &err.to_string()); } // Here we are calling local_content RPC to test if the content is present @@ -520,3 +533,41 @@ dyn_async! { } } } + +dyn_async! { + // test that a node will return a PresentContent via RecursiveFindContent when the data is stored locally + async fn test_recursive_find_content_content_present_locally<'a>(clients: Vec, _: ()) { + let client = match clients.into_iter().next() { + Some((client)) => client, + None => { + panic!("Unable to get expected amount of clients from NClientTestSpec"); + } + }; + + + let content_key: HistoryContentKey = serde_json::from_value(json!(CONTENT_KEY)).unwrap(); + let raw_content_value = Bytes::from_str(CONTENT_VALUE).expect("unable to convert content value to bytes"); + + // seed content_key/content_value onto the local node to test recursive_find_content expect content present + if let Err(err) = HistoryNetworkApiClient::store(&client.rpc, content_key.clone(), raw_content_value.clone()).await { + panic!("Failed to store data: {}", &err.to_string()); + } + + match HistoryNetworkApiClient::recursive_find_content(&client.rpc, content_key).await { + Ok(ContentInfo::Content { content, utp_transfer }) => { + if utp_transfer { + panic!("Error: Expected utp_transfer to be false"); + } + if content != raw_content_value { + panic!("Error receiving content: Expected content: {raw_content_value:?}, Received content: {content:?}"); + } + } + Err(err) => { + panic!("Expected RecursiveFindContent to not throw an error {}", &err.to_string()); + } + _ => { + panic!("Error: Expected RecursiveFindContent to return ContentInfo::Content"); + } + } + } +} diff --git a/simulators/portal/src/suites/state/rpc_compat.rs b/simulators/portal/src/suites/state/rpc_compat.rs index a4d7ca92fe..2d249f21c2 100644 --- a/simulators/portal/src/suites/state/rpc_compat.rs +++ b/simulators/portal/src/suites/state/rpc_compat.rs @@ -7,6 +7,7 @@ use crate::suites::state::constants::{ }; use alloy_primitives::Bytes; use ethportal_api::types::enr::generate_random_remote_enr; +use ethportal_api::types::portal::ContentInfo; use ethportal_api::Discv5ApiClient; use ethportal_api::{StateContentKey, StateNetworkApiClient}; use hivesim::types::ClientDefinition; @@ -192,6 +193,18 @@ dyn_async! { clients: vec![client.clone()], } ).await; + + test.run( + NClientTestSpec { + name: "portal_stateRecursiveFindContent Content Present Locally".to_string(), + description: "".to_string(), + always_run: false, + run: test_recursive_find_content_content_present_locally, + environments: environments.clone(), + test_data: (), + clients: vec![client.clone()], + } + ).await; } } } @@ -258,7 +271,7 @@ dyn_async! { if let Err(err) = StateNetworkApiClient::store(&client.rpc, content_key.clone(), raw_content_offer_value).await { - panic!("{}", &err.to_string()); + panic!("Failed to store data: {}", &err.to_string()); } // Here we are calling local_content RPC to test if the content is present @@ -524,3 +537,41 @@ dyn_async! { } } } + +dyn_async! { + // test that a node will return a PresentContent via RecursiveFindContent when the data is stored locally + async fn test_recursive_find_content_content_present_locally<'a>(clients: Vec, _: ()) { + let client = match clients.into_iter().next() { + Some((client)) => client, + None => { + panic!("Unable to get expected amount of clients from NClientTestSpec"); + } + }; + + let content_key: StateContentKey = serde_json::from_value(json!(CONTENT_KEY)).unwrap(); + let raw_content_offer_value = Bytes::from_str(CONTENT_OFFER_VALUE).unwrap(); + let raw_content_lookup_value = Bytes::from_str(CONTENT_LOOKUP_VALUE).unwrap(); + + // seed content_key/content_value onto the local node to test recursive_find_content expect content present + if let Err(err) = StateNetworkApiClient::store(&client.rpc, content_key.clone(), raw_content_offer_value).await { + panic!("Failed to store data: {}", &err.to_string()); + } + + match StateNetworkApiClient::recursive_find_content(&client.rpc, content_key).await { + Ok(ContentInfo::Content { content, utp_transfer }) => { + if utp_transfer { + panic!("Error: Expected utp_transfer to be false"); + } + if content != raw_content_lookup_value { + panic!("Error receiving content: Expected content: {raw_content_lookup_value:?}, Received content: {content:?}"); + } + } + Err(err) => { + panic!("Expected RecursiveFindContent to not throw an error {}", &err.to_string()); + } + _ => { + panic!("Error: Expected RecursiveFindContent to return ContentInfo::Content"); + } + } + } +}