v0.3.13-pre.005
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-worker-raw-transaction-ingest-lib/unit_tests/runtime_resources.rs
|
||||
// version: 16
|
||||
// version: 17
|
||||
|
||||
fn grpc_endpoint(cluster: &str) -> std::option::Option<ksp_onchain_transport_lib::YellowstoneGrpcEndpointSettings> {
|
||||
return grpc_endpoint_with_identity(cluster, "yellowstone-fixture", "fixture-provider");
|
||||
@@ -126,6 +126,65 @@ fn standard_logs_source(
|
||||
};
|
||||
}
|
||||
|
||||
fn helius_transaction_filter(failed: bool) -> ksp_onchain_transport_lib::HeliusTransactionSubscribeFilter {
|
||||
return ksp_onchain_transport_lib::HeliusTransactionSubscribeFilter::new(
|
||||
std::option::Option::Some(false),
|
||||
std::option::Option::Some(failed),
|
||||
std::option::Option::None,
|
||||
std::option::Option::None,
|
||||
std::option::Option::None,
|
||||
std::option::Option::None,
|
||||
std::option::Option::None,
|
||||
);
|
||||
}
|
||||
|
||||
fn helius_transaction_source(
|
||||
cluster: &str,
|
||||
endpoint_name: &str,
|
||||
filter: ksp_onchain_transport_lib::HeliusTransactionSubscribeFilter,
|
||||
commitment: ksp_onchain_transport_lib::SolanaCommitment,
|
||||
hydration_role: &str,
|
||||
) -> std::option::Option<crate::RawTransactionIngestHeliusTransactionSource> {
|
||||
let endpoint = match ws_endpoint(cluster, endpoint_name, "fixture-helius-provider", ksp_onchain_transport_lib::WsProtocolKind::HeliusLaserStream) {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return std::option::Option::None,
|
||||
};
|
||||
let pool = match http_pool(cluster, hydration_role, "get_transaction") {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return std::option::Option::None,
|
||||
};
|
||||
return match crate::RawTransactionIngestHeliusTransactionSource::new(
|
||||
endpoint,
|
||||
filter,
|
||||
commitment,
|
||||
pool,
|
||||
ksp_onchain_transport_lib::HttpRoleName::new(hydration_role),
|
||||
) {
|
||||
std::result::Result::Ok(value) => std::option::Option::Some(value),
|
||||
std::result::Result::Err(_) => std::option::Option::None,
|
||||
};
|
||||
}
|
||||
|
||||
struct HeliusTransactionViewFixture {
|
||||
signature: std::string::String,
|
||||
slot: u64,
|
||||
transaction_index: u64,
|
||||
}
|
||||
|
||||
impl super::RawTransactionIngestHeliusTransactionView for HeliusTransactionViewFixture {
|
||||
fn signature(&self) -> &str {
|
||||
return self.signature.as_str();
|
||||
}
|
||||
|
||||
fn slot(&self) -> u64 {
|
||||
return self.slot;
|
||||
}
|
||||
|
||||
fn transaction_index(&self) -> u64 {
|
||||
return self.transaction_index;
|
||||
}
|
||||
}
|
||||
|
||||
struct StandardLogsViewFixture {
|
||||
signature: std::string::String,
|
||||
slot: u64,
|
||||
@@ -434,6 +493,28 @@ fn standard_logs_source_for_http_url(
|
||||
};
|
||||
}
|
||||
|
||||
fn helius_transaction_source_for_http_url(url: &str) -> std::option::Option<crate::RawTransactionIngestHeliusTransactionSource> {
|
||||
let endpoint =
|
||||
match ws_endpoint("devnet", "helius-transaction-fixture", "fixture-helius-provider", ksp_onchain_transport_lib::WsProtocolKind::HeliusLaserStream) {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return std::option::Option::None,
|
||||
};
|
||||
let pool = match http_pool_for_url(url, "devnet", "http-hydration-fixture", "fixture-http-provider") {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return std::option::Option::None,
|
||||
};
|
||||
return match crate::RawTransactionIngestHeliusTransactionSource::new(
|
||||
endpoint,
|
||||
helius_transaction_filter(false),
|
||||
ksp_onchain_transport_lib::SolanaCommitment::Confirmed,
|
||||
pool,
|
||||
ksp_onchain_transport_lib::HttpRoleName::new("hydration"),
|
||||
) {
|
||||
std::result::Result::Ok(value) => std::option::Option::Some(value),
|
||||
std::result::Result::Err(_) => std::option::Option::None,
|
||||
};
|
||||
}
|
||||
|
||||
fn pre_004_settings() -> std::option::Option<crate::RawTransactionIngestSettings> {
|
||||
let network = match ksp_store_lib::RawNetworkId::new("devnet") {
|
||||
std::result::Result::Ok(value) => value,
|
||||
@@ -2073,6 +2154,309 @@ fn v0_3_13_pre_004_runtime_resources_reject_duplicate_standard_block_identity()
|
||||
return;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn v0_3_13_pre_005_helius_transaction_source_validates_protocol_commitment_request_and_hydration_route() {
|
||||
let source = match helius_transaction_source(
|
||||
"devnet",
|
||||
"helius-transaction-a",
|
||||
helius_transaction_filter(false),
|
||||
ksp_onchain_transport_lib::SolanaCommitment::Confirmed,
|
||||
"hydration",
|
||||
) {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return,
|
||||
};
|
||||
let request = super::helius_transaction_request(source.filter.clone(), source.commitment);
|
||||
let options = match request.options() {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return,
|
||||
};
|
||||
assert_eq!(options.commitment(), std::option::Option::Some(ksp_onchain_transport_lib::SolanaCommitment::Confirmed));
|
||||
assert_eq!(options.encoding(), std::option::Option::Some(ksp_onchain_transport_lib::HeliusTransactionSubscribeEncoding::Base64));
|
||||
assert_eq!(options.transaction_details(), std::option::Option::Some(ksp_onchain_transport_lib::SolanaTransactionDetails::Full));
|
||||
assert_eq!(options.show_rewards(), std::option::Option::Some(false));
|
||||
assert_eq!(options.max_supported_transaction_version(), std::option::Option::Some(1));
|
||||
assert!(request.validate().is_ok());
|
||||
let resources = crate::RawTransactionIngestRuntimeResources::from_helius_transaction_source(source);
|
||||
assert_eq!(resources.source_count(), 1);
|
||||
let standard_endpoint =
|
||||
match ws_endpoint("devnet", "helius-transaction-standard", "fixture-helius-provider", ksp_onchain_transport_lib::WsProtocolKind::SolanaStandard) {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return,
|
||||
};
|
||||
let pool = match http_pool("devnet", "hydration", "get_transaction") {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return,
|
||||
};
|
||||
let protocol_error = crate::RawTransactionIngestHeliusTransactionSource::new(
|
||||
standard_endpoint,
|
||||
helius_transaction_filter(false),
|
||||
ksp_onchain_transport_lib::SolanaCommitment::Confirmed,
|
||||
pool.clone(),
|
||||
ksp_onchain_transport_lib::HttpRoleName::new("hydration"),
|
||||
);
|
||||
let protocol_error = match protocol_error {
|
||||
std::result::Result::Ok(_) => return,
|
||||
std::result::Result::Err(value) => value,
|
||||
};
|
||||
assert!(protocol_error.context().iter().any(|context| return context.value() == "runtime_resources.helius_transaction_protocol_invalid"));
|
||||
let helius_endpoint =
|
||||
match ws_endpoint("devnet", "helius-transaction-processed", "fixture-helius-provider", ksp_onchain_transport_lib::WsProtocolKind::HeliusLaserStream) {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return,
|
||||
};
|
||||
let commitment_error = crate::RawTransactionIngestHeliusTransactionSource::new(
|
||||
helius_endpoint,
|
||||
helius_transaction_filter(false),
|
||||
ksp_onchain_transport_lib::SolanaCommitment::Processed,
|
||||
pool,
|
||||
ksp_onchain_transport_lib::HttpRoleName::new("hydration"),
|
||||
);
|
||||
let commitment_error = match commitment_error {
|
||||
std::result::Result::Ok(_) => return,
|
||||
std::result::Result::Err(value) => value,
|
||||
};
|
||||
assert!(commitment_error.context().iter().any(|context| return context.value() == "runtime_resources.hydration_commitment_invalid"));
|
||||
let cross_network_endpoint = match ws_endpoint(
|
||||
"devnet",
|
||||
"helius-transaction-cross-network",
|
||||
"fixture-helius-provider",
|
||||
ksp_onchain_transport_lib::WsProtocolKind::HeliusLaserStream,
|
||||
) {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return,
|
||||
};
|
||||
let cross_network_pool = match http_pool("testnet", "hydration", "get_transaction") {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return,
|
||||
};
|
||||
let cross_network = crate::RawTransactionIngestHeliusTransactionSource::new(
|
||||
cross_network_endpoint,
|
||||
helius_transaction_filter(false),
|
||||
ksp_onchain_transport_lib::SolanaCommitment::Confirmed,
|
||||
cross_network_pool,
|
||||
ksp_onchain_transport_lib::HttpRoleName::new("hydration"),
|
||||
);
|
||||
let cross_network = match cross_network {
|
||||
std::result::Result::Ok(_) => return,
|
||||
std::result::Result::Err(value) => value,
|
||||
};
|
||||
assert!(cross_network.context().iter().any(|context| return context.value() == "runtime_resources.transport_network_mismatch"));
|
||||
return;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn v0_3_13_pre_005_helius_transaction_source_key_is_filter_sensitive_order_normalized_hydration_role_neutral_and_redacted() {
|
||||
let first_pubkey = ksp_core_lib::Pubkey::new_from_array([0x31_u8; 32]);
|
||||
let second_pubkey = ksp_core_lib::Pubkey::new_from_array([0x32_u8; 32]);
|
||||
let signature_canary = "5HueCGU8rMjxEXxiPuD5BDuRaH7RkZBzQ2hL5M5WnQp9";
|
||||
let first_filter = ksp_onchain_transport_lib::HeliusTransactionSubscribeFilter::new(
|
||||
std::option::Option::Some(false),
|
||||
std::option::Option::Some(false),
|
||||
std::option::Option::Some(signature_canary.to_owned()),
|
||||
std::option::Option::Some(std::vec![first_pubkey, second_pubkey]),
|
||||
std::option::Option::None,
|
||||
std::option::Option::None,
|
||||
std::option::Option::Some(ksp_onchain_transport_lib::HeliusTokenAccountsFilter::BalanceChanged),
|
||||
);
|
||||
let reordered_filter = ksp_onchain_transport_lib::HeliusTransactionSubscribeFilter::new(
|
||||
std::option::Option::Some(false),
|
||||
std::option::Option::Some(false),
|
||||
std::option::Option::Some(signature_canary.to_owned()),
|
||||
std::option::Option::Some(std::vec![second_pubkey, first_pubkey]),
|
||||
std::option::Option::None,
|
||||
std::option::Option::None,
|
||||
std::option::Option::Some(ksp_onchain_transport_lib::HeliusTokenAccountsFilter::BalanceChanged),
|
||||
);
|
||||
let changed_filter = ksp_onchain_transport_lib::HeliusTransactionSubscribeFilter::new(
|
||||
std::option::Option::Some(false),
|
||||
std::option::Option::Some(true),
|
||||
std::option::Option::Some(signature_canary.to_owned()),
|
||||
std::option::Option::Some(std::vec![first_pubkey, second_pubkey]),
|
||||
std::option::Option::None,
|
||||
std::option::Option::None,
|
||||
std::option::Option::Some(ksp_onchain_transport_lib::HeliusTokenAccountsFilter::BalanceChanged),
|
||||
);
|
||||
let first = match helius_transaction_source(
|
||||
"devnet",
|
||||
"helius-transaction-key",
|
||||
first_filter,
|
||||
ksp_onchain_transport_lib::SolanaCommitment::Confirmed,
|
||||
"hydration",
|
||||
) {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return,
|
||||
};
|
||||
let reordered = match helius_transaction_source(
|
||||
"devnet",
|
||||
"helius-transaction-key",
|
||||
reordered_filter,
|
||||
ksp_onchain_transport_lib::SolanaCommitment::Confirmed,
|
||||
"secondary_hydration",
|
||||
) {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return,
|
||||
};
|
||||
let changed = match helius_transaction_source(
|
||||
"devnet",
|
||||
"helius-transaction-key",
|
||||
changed_filter,
|
||||
ksp_onchain_transport_lib::SolanaCommitment::Confirmed,
|
||||
"hydration",
|
||||
) {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return,
|
||||
};
|
||||
assert_eq!(first.source_key, reordered.source_key);
|
||||
assert_ne!(first.source_key, changed.source_key);
|
||||
let first_pubkey_text = first_pubkey.to_string();
|
||||
let debug = std::format!("{first:?}");
|
||||
assert!(debug.contains("RawTransactionIngestHeliusTransactionSource"));
|
||||
assert!(debug.contains("signature_present"));
|
||||
assert!(!debug.contains(signature_canary));
|
||||
assert!(!debug.contains(first_pubkey_text.as_str()));
|
||||
assert!(!debug.contains("WS-SECRET-CANARY"));
|
||||
assert!(!debug.contains("api-key"));
|
||||
assert!(!debug.contains("source_key: ["));
|
||||
return;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn v0_3_13_pre_005_helius_full_projection_keeps_only_reference_material() {
|
||||
let source = match helius_transaction_source(
|
||||
"devnet",
|
||||
"helius-transaction-projection",
|
||||
helius_transaction_filter(false),
|
||||
ksp_onchain_transport_lib::SolanaCommitment::Finalized,
|
||||
"hydration",
|
||||
) {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return,
|
||||
};
|
||||
let fixture = HeliusTransactionViewFixture { signature: PRE_004_ZERO_SIGNATURE_TEXT.to_owned(), slot: 81, transaction_index: 9 };
|
||||
let signal = match super::project_helius_transaction_signal(&source, &fixture) {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(_) => return,
|
||||
};
|
||||
assert_eq!(signal.family, super::RawTransactionIngestSourceFamily::Transaction);
|
||||
assert_eq!(signal.slot, 81);
|
||||
assert_eq!(signal.transaction_index, std::option::Option::Some(9));
|
||||
assert_eq!(signal.created_at, std::option::Option::None);
|
||||
assert_eq!(signal.matched_filter_count, 1);
|
||||
assert_eq!(signal.matched_filter_id, std::option::Option::None);
|
||||
assert_eq!(signal.signature, ksp_store_lib::RawTransactionSignature::new([0_u8; 64]));
|
||||
let debug = std::format!("{signal:?}");
|
||||
assert!(!debug.contains(PRE_004_ZERO_SIGNATURE_TEXT));
|
||||
return;
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn v0_3_13_pre_005_helius_full_reference_hydrates_once_to_exact_common_raw() {
|
||||
let body = std::format!(
|
||||
"{{\"jsonrpc\":\"2.0\",\"result\":{{\"slot\":42,\"blockTime\":1760000120,\"transaction\":[\"{}\",\"base64\"],\"meta\":null,\"version\":1,\"transactionIndex\":7}},\"id\":1}}",
|
||||
PRE_004_ZERO_TRANSACTION_BASE64,
|
||||
);
|
||||
let (url, server) = match serve_http_once(body) {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(_) => return,
|
||||
};
|
||||
let source = match helius_transaction_source_for_http_url(url.as_str()) {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return,
|
||||
};
|
||||
let settings = match pre_004_settings() {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return,
|
||||
};
|
||||
let fixture = HeliusTransactionViewFixture { signature: PRE_004_ZERO_SIGNATURE_TEXT.to_owned(), slot: 42, transaction_index: 7 };
|
||||
let signal = match super::project_helius_transaction_signal(&source, &fixture) {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(_) => return,
|
||||
};
|
||||
let received_at = match ksp_store_lib::RawTimestamp::from_unix_millis(1_760_000_200_000) {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(_) => return,
|
||||
};
|
||||
let hydration = source.hydration_context();
|
||||
let key = match super::hydration_key(&hydration, &signal) {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(_) => return,
|
||||
};
|
||||
let fetched =
|
||||
super::fetch_hydration(hydration.http_pool.clone(), hydration.hydration_role.clone(), hydration.network.clone(), key, hydration.commitment).await;
|
||||
let fetched = match fetched {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(_) => return,
|
||||
};
|
||||
let ingress = super::finalize_hydration(&hydration, &settings, signal, received_at, &fetched.observed);
|
||||
let ingress = match ingress {
|
||||
std::result::Result::Ok(std::option::Option::Some(value)) => value,
|
||||
std::result::Result::Ok(std::option::Option::None) | std::result::Result::Err(_) => return,
|
||||
};
|
||||
assert_eq!(ingress.provenance.protocol().as_str(), "helius_ws_http");
|
||||
assert_eq!(ingress.provenance.acquisition_method().as_str(), "transaction_get_transaction");
|
||||
let (mut admission, sender) = crate::RawTransactionAdmission::new(1);
|
||||
if sender.send(ingress).await.is_err() {
|
||||
return;
|
||||
}
|
||||
std::mem::drop(sender);
|
||||
let acquisition = match admission.receive(settings.network()).await {
|
||||
std::result::Result::Ok(std::option::Option::Some(value)) => value,
|
||||
_ => return,
|
||||
};
|
||||
assert_eq!(acquisition.transaction().reference().network().as_str(), "devnet");
|
||||
assert_eq!(acquisition.transaction().reference().signature().as_bytes(), &[0_u8; 64]);
|
||||
assert_eq!(acquisition.transaction().slot(), 42);
|
||||
assert_eq!(acquisition.transaction().block_time().map(|value| return value.unix_millis()), std::option::Option::Some(1_760_000_120_000));
|
||||
let payload = match std::str::from_utf8(acquisition.transaction().payload().bytes()) {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(_) => return,
|
||||
};
|
||||
assert!(payload.contains("\"version\":1"));
|
||||
assert!(payload.contains("\"transactionIndex\":7"));
|
||||
let request_body = match server.join() {
|
||||
std::result::Result::Ok(std::result::Result::Ok(value)) => value,
|
||||
std::result::Result::Ok(std::result::Result::Err(_)) | std::result::Result::Err(_) => return,
|
||||
};
|
||||
assert!(request_body.contains("\"method\":\"getTransaction\""));
|
||||
assert!(request_body.contains("\"encoding\":\"base64\""));
|
||||
assert!(request_body.contains("\"maxSupportedTransactionVersion\":1"));
|
||||
return;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn v0_3_13_pre_005_runtime_resources_reject_duplicate_helius_transaction_identity() {
|
||||
let first = match helius_transaction_source(
|
||||
"devnet",
|
||||
"helius-transaction-duplicate",
|
||||
helius_transaction_filter(false),
|
||||
ksp_onchain_transport_lib::SolanaCommitment::Confirmed,
|
||||
"hydration",
|
||||
) {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return,
|
||||
};
|
||||
let duplicate = match helius_transaction_source(
|
||||
"devnet",
|
||||
"helius-transaction-duplicate",
|
||||
helius_transaction_filter(false),
|
||||
ksp_onchain_transport_lib::SolanaCommitment::Confirmed,
|
||||
"secondary_hydration",
|
||||
) {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return,
|
||||
};
|
||||
let mut resources = crate::RawTransactionIngestRuntimeResources::from_helius_transaction_source(first);
|
||||
let result = resources.try_push_helius_transaction_source(duplicate);
|
||||
let error = match result {
|
||||
std::result::Result::Ok(()) => return,
|
||||
std::result::Result::Err(value) => value,
|
||||
};
|
||||
assert!(error.context().iter().any(|context| return context.value() == "runtime_resources.duplicate_source_identity"));
|
||||
assert_eq!(resources.source_count(), 1);
|
||||
return;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pre_007_processing_frontier_never_advances_through_pending_work() {
|
||||
let mut frontier = super::RawTransactionIngestProcessingFrontier::new();
|
||||
|
||||
Reference in New Issue
Block a user