v0.3.10-pre.004-fix.001
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
// file: crates/ksp-job-backfill-lib/tests/http_block_material.rs
|
||||
// version: 1
|
||||
// version: 2
|
||||
|
||||
//! Cross-layer canary for the future Worker-owned HTTP block adapter without changing production ownership.
|
||||
|
||||
fn pool_for_url(url: &str) -> ksp_onchain_transport_lib::HttpTransportPool {
|
||||
fn pool_for_url(url: &str) -> ksp_core_lib::Result<ksp_onchain_transport_lib::HttpTransportPool> {
|
||||
let endpoint_url = match ksp_onchain_transport_lib::HttpEndpointUrl::parse(url) {
|
||||
Ok(endpoint_url) => endpoint_url,
|
||||
Err(error) => return Err(error),
|
||||
};
|
||||
let role = ksp_onchain_transport_lib::HttpEndpointRoleSettings::new(
|
||||
ksp_onchain_transport_lib::HttpRoleName::new("default"),
|
||||
true,
|
||||
@@ -21,7 +25,7 @@ fn pool_for_url(url: &str) -> ksp_onchain_transport_lib::HttpTransportPool {
|
||||
true,
|
||||
ksp_onchain_transport_lib::HttpProviderName::new("fixture-provider"),
|
||||
ksp_onchain_transport_lib::HttpClusterName::new("devnet"),
|
||||
ksp_onchain_transport_lib::HttpEndpointUrl::parse(url).expect("fixture URL must parse"),
|
||||
endpoint_url,
|
||||
std::time::Duration::from_secs(1),
|
||||
std::time::Duration::from_secs(1),
|
||||
std::option::Option::Some(1),
|
||||
@@ -30,19 +34,30 @@ fn pool_for_url(url: &str) -> ksp_onchain_transport_lib::HttpTransportPool {
|
||||
return ksp_onchain_transport_lib::HttpTransportPool::new(ksp_onchain_transport_lib::HttpTransportSettings::new(
|
||||
std::vec![endpoint],
|
||||
ksp_onchain_transport_lib::HttpRetrySettings::new(0, std::time::Duration::from_millis(1), std::time::Duration::from_millis(1)),
|
||||
))
|
||||
.expect("fixture pool must build");
|
||||
));
|
||||
}
|
||||
|
||||
fn serve_once(body: &'static str) -> (std::string::String, std::thread::JoinHandle<()>) {
|
||||
let listener = std::net::TcpListener::bind("127.0.0.1:0").expect("fixture listener must bind");
|
||||
let address = listener.local_addr().expect("fixture listener address must resolve");
|
||||
fn serve_once(body: &'static str) -> std::io::Result<(std::string::String, std::thread::JoinHandle<std::io::Result<()>>)> {
|
||||
let listener = match std::net::TcpListener::bind("127.0.0.1:0") {
|
||||
Ok(listener) => listener,
|
||||
Err(error) => return Err(error),
|
||||
};
|
||||
let address = match listener.local_addr() {
|
||||
Ok(address) => address,
|
||||
Err(error) => return Err(error),
|
||||
};
|
||||
let handle = std::thread::spawn(move || {
|
||||
let (mut stream, _) = listener.accept().expect("fixture server must accept one request");
|
||||
let (mut stream, _) = match listener.accept() {
|
||||
Ok(accepted) => accepted,
|
||||
Err(error) => return Err(error),
|
||||
};
|
||||
let mut bytes = std::vec::Vec::new();
|
||||
let mut buffer = [0_u8; 1024];
|
||||
loop {
|
||||
let count = std::io::Read::read(&mut stream, &mut buffer).expect("fixture request must read");
|
||||
let count = match std::io::Read::read(&mut stream, &mut buffer) {
|
||||
Ok(count) => count,
|
||||
Err(error) => return Err(error),
|
||||
};
|
||||
if count == 0 {
|
||||
break;
|
||||
}
|
||||
@@ -52,10 +67,12 @@ fn serve_once(body: &'static str) -> (std::string::String, std::thread::JoinHand
|
||||
}
|
||||
}
|
||||
let response = format!("HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{}", body.len(), body);
|
||||
std::io::Write::write_all(&mut stream, response.as_bytes()).expect("fixture response must write");
|
||||
return;
|
||||
if let Err(error) = std::io::Write::write_all(&mut stream, response.as_bytes()) {
|
||||
return Err(error);
|
||||
}
|
||||
return Ok(());
|
||||
});
|
||||
return (format!("http://{address}"), handle);
|
||||
return Ok((format!("http://{address}"), handle));
|
||||
}
|
||||
|
||||
fn map_meta(field: &ksp_onchain_transport_lib::SolanaWireField<serde_json::Value>) -> ksp_raw_transaction_lib::RawTransactionWireField<serde_json::Value> {
|
||||
@@ -91,8 +108,8 @@ async fn pre_004_http_observed_block_projects_each_base64_transaction_to_common_
|
||||
"{\"transaction\":[\"AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEA\",",
|
||||
"\"base64\"],\"meta\":{\"err\":null,\"fee\":6000},\"version\":0}]},\"id\":1}",
|
||||
);
|
||||
let (url, handle) = serve_once(BODY);
|
||||
let pool = pool_for_url(url.as_str());
|
||||
let (url, handle) = serve_once(BODY).expect("fixture server must start");
|
||||
let pool = pool_for_url(url.as_str()).expect("fixture pool must build");
|
||||
let config = ksp_onchain_transport_lib::SolanaGetBlockConfig::new(
|
||||
std::option::Option::Some(ksp_onchain_transport_lib::SolanaCommitment::Confirmed),
|
||||
std::option::Option::Some(ksp_onchain_transport_lib::SolanaTransactionEncoding::Base64),
|
||||
@@ -136,6 +153,6 @@ async fn pre_004_http_observed_block_projects_each_base64_transaction_to_common_
|
||||
assert_eq!(raw.block_time().map(|value| return value.unix_millis()), std::option::Option::Some(1_787_072_400_000));
|
||||
assert!(raw.payload().bytes().ends_with(format!("\"transactionIndex\":{transaction_index}}}").as_bytes()));
|
||||
}
|
||||
handle.join().expect("fixture server must join");
|
||||
handle.join().expect("fixture server must join").expect("fixture server must complete successfully");
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user