Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simulators/portal: add test for if recursiveFindContent checks locally #1170

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion simulators/portal/src/suites/beacon/rpc_compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<Client>, _: ()) {
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");
}
}
}
}
53 changes: 52 additions & 1 deletion simulators/portal/src/suites/history/rpc_compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<Client>, _: ()) {
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");
}
}
}
}
53 changes: 52 additions & 1 deletion simulators/portal/src/suites/state/rpc_compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<Client>, _: ()) {
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");
}
}
}
}