v0.3.13-pre.002
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-worker-raw-transaction-ingest-lib/unit_tests/runtime_resources.rs
|
||||
// version: 11
|
||||
// version: 12
|
||||
|
||||
fn grpc_endpoint(cluster: &str) -> std::option::Option<ksp_onchain_transport_lib::YellowstoneGrpcEndpointSettings> {
|
||||
return grpc_endpoint_with_identity(cluster, "yellowstone-fixture", "fixture-provider");
|
||||
@@ -191,6 +191,51 @@ fn filter_names(values: &[&str]) -> std::option::Option<std::vec::Vec<ksp_onchai
|
||||
return std::option::Option::Some(filters);
|
||||
}
|
||||
|
||||
fn source_with_identity(
|
||||
cluster: &str,
|
||||
endpoint_name: &str,
|
||||
filter_name: &str,
|
||||
failed: std::option::Option<bool>,
|
||||
) -> std::option::Option<crate::RawTransactionIngestYellowstoneSource> {
|
||||
return source_with_identity_and_hydration_role(cluster, endpoint_name, filter_name, failed, "hydration");
|
||||
}
|
||||
|
||||
fn source_with_identity_and_hydration_role(
|
||||
cluster: &str,
|
||||
endpoint_name: &str,
|
||||
filter_name: &str,
|
||||
failed: std::option::Option<bool>,
|
||||
hydration_role: &str,
|
||||
) -> std::option::Option<crate::RawTransactionIngestYellowstoneSource> {
|
||||
let endpoint = match grpc_endpoint_with_identity(cluster, endpoint_name, "fixture-provider") {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return std::option::Option::None,
|
||||
};
|
||||
let channel = match ksp_onchain_transport_lib::YellowstoneGrpcChannel::prepare(&endpoint) {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(_) => return std::option::Option::None,
|
||||
};
|
||||
let name = match ksp_onchain_transport_lib::YellowstoneSubscribeFilterName::new(filter_name) {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(_) => return std::option::Option::None,
|
||||
};
|
||||
let mut filter = ksp_onchain_transport_lib::YellowstoneSubscribeTransactionFilter::new();
|
||||
filter.set_failed(failed);
|
||||
let mut request = ksp_onchain_transport_lib::YellowstoneSubscribeRequest::new();
|
||||
if request.insert_transaction_filter(name, filter).is_err() {
|
||||
return std::option::Option::None;
|
||||
}
|
||||
request.set_commitment(std::option::Option::Some(ksp_onchain_transport_lib::SolanaCommitment::Confirmed));
|
||||
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::RawTransactionIngestYellowstoneSource::new(channel, request, 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,
|
||||
};
|
||||
}
|
||||
|
||||
fn signal_source() -> std::option::Option<crate::RawTransactionIngestYellowstoneSource> {
|
||||
let endpoint = match grpc_endpoint("devnet") {
|
||||
std::option::Option::Some(value) => value,
|
||||
@@ -544,9 +589,11 @@ async fn pre_002_runtime_resource_debug_is_safe_and_exposes_no_client_inner() {
|
||||
let resources = crate::RawTransactionIngestRuntimeResources::new(source);
|
||||
let debug = std::format!("{resources:?}");
|
||||
assert!(debug.contains("RawTransactionIngestRuntimeResources"));
|
||||
assert!(debug.contains("devnet"));
|
||||
assert!(debug.contains("blocks_meta_filter_count"));
|
||||
assert!(debug.contains("slot_filter_count"));
|
||||
assert!(debug.contains("source_count"));
|
||||
assert!(debug.contains("1"));
|
||||
assert!(!debug.contains("devnet"));
|
||||
assert!(!debug.contains("blocks_meta_filter_count"));
|
||||
assert!(!debug.contains("slot_filter_count"));
|
||||
assert!(!debug.contains("GRPC-SECRET-CANARY"));
|
||||
assert!(!debug.contains("HTTP-SECRET-CANARY"));
|
||||
assert!(!debug.contains("127.0.0.1"));
|
||||
@@ -591,6 +638,116 @@ async fn pre_002_runtime_resources_reject_worker_network_mismatch_without_starti
|
||||
return;
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn v0_3_13_pre_002_live_source_key_is_stable_and_request_sensitive() {
|
||||
let first = match source_with_identity("devnet", "source-a", "tx-a", std::option::Option::Some(false)) {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return,
|
||||
};
|
||||
let same = match source_with_identity("devnet", "source-a", "tx-a", std::option::Option::Some(false)) {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return,
|
||||
};
|
||||
let changed_filter = match source_with_identity("devnet", "source-a", "tx-a", std::option::Option::Some(true)) {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return,
|
||||
};
|
||||
let changed_endpoint = match source_with_identity("devnet", "source-b", "tx-a", std::option::Option::Some(false)) {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return,
|
||||
};
|
||||
let changed_hydration_role = match source_with_identity_and_hydration_role("devnet", "source-a", "tx-a", std::option::Option::Some(false), "secondary") {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return,
|
||||
};
|
||||
assert_eq!(first.source_key, same.source_key);
|
||||
assert_eq!(first.source_key, changed_hydration_role.source_key);
|
||||
assert_ne!(first.source_key, changed_filter.source_key);
|
||||
assert_ne!(first.source_key, changed_endpoint.source_key);
|
||||
return;
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn v0_3_13_pre_002_runtime_resources_accept_exact_bound_and_reject_excess_transactionally() {
|
||||
let first = match source_with_identity("devnet", "source-00", "tx", std::option::Option::None) {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return,
|
||||
};
|
||||
let mut resources = crate::RawTransactionIngestRuntimeResources::new(first);
|
||||
for index in 1..crate::MAX_RAW_TRANSACTION_INGEST_LIVE_SOURCES {
|
||||
let endpoint_name = std::format!("source-{index:02}");
|
||||
let source = match source_with_identity("devnet", endpoint_name.as_str(), "tx", std::option::Option::None) {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return,
|
||||
};
|
||||
assert!(resources.try_push_yellowstone_source(source).is_ok());
|
||||
}
|
||||
assert_eq!(resources.source_count(), crate::MAX_RAW_TRANSACTION_INGEST_LIVE_SOURCES);
|
||||
let excess = match source_with_identity("devnet", "source-excess", "tx", std::option::Option::None) {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return,
|
||||
};
|
||||
let error = match resources.try_push_yellowstone_source(excess) {
|
||||
std::result::Result::Ok(()) => return,
|
||||
std::result::Result::Err(error) => error,
|
||||
};
|
||||
assert_eq!(error.code(), crate::ERROR_CODE_RAW_TRANSACTION_INGEST_RUNTIME_INVALID);
|
||||
assert!(error.context().iter().any(|context| return context.value() == "runtime_resources.source_count_exceeded"));
|
||||
assert_eq!(resources.source_count(), crate::MAX_RAW_TRANSACTION_INGEST_LIVE_SOURCES);
|
||||
return;
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn v0_3_13_pre_002_runtime_resources_reject_duplicate_and_cross_network_source_before_activation() {
|
||||
let first = match source_with_identity("devnet", "source-a", "tx", std::option::Option::None) {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return,
|
||||
};
|
||||
let duplicate = match source_with_identity("devnet", "source-a", "tx", std::option::Option::None) {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return,
|
||||
};
|
||||
let other_network = match source_with_identity("mainnet", "source-b", "tx", std::option::Option::None) {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return,
|
||||
};
|
||||
let mut resources = crate::RawTransactionIngestRuntimeResources::new(first);
|
||||
let duplicate_error = match resources.try_push_yellowstone_source(duplicate) {
|
||||
std::result::Result::Ok(()) => return,
|
||||
std::result::Result::Err(error) => error,
|
||||
};
|
||||
assert!(duplicate_error.context().iter().any(|context| return context.value() == "runtime_resources.duplicate_source_identity"));
|
||||
assert_eq!(resources.source_count(), 1);
|
||||
let network_error = match resources.try_push_yellowstone_source(other_network) {
|
||||
std::result::Result::Ok(()) => return,
|
||||
std::result::Result::Err(error) => error,
|
||||
};
|
||||
assert!(network_error.context().iter().any(|context| return context.value() == "runtime_resources.source_network_mismatch"));
|
||||
assert_eq!(resources.source_count(), 1);
|
||||
return;
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn v0_3_13_pre_002_multi_source_activation_fails_closed_until_supervisor_tranche() {
|
||||
let first = match source_with_identity("devnet", "source-a", "tx", std::option::Option::None) {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return,
|
||||
};
|
||||
let second = match source_with_identity("devnet", "source-b", "tx", std::option::Option::None) {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return,
|
||||
};
|
||||
let mut resources = crate::RawTransactionIngestRuntimeResources::new(first);
|
||||
assert!(resources.try_push_yellowstone_source(second).is_ok());
|
||||
let error = match resources.into_yellowstone_source() {
|
||||
std::result::Result::Ok(_) => return,
|
||||
std::result::Result::Err(error) => error,
|
||||
};
|
||||
assert_eq!(error.code(), crate::ERROR_CODE_RAW_TRANSACTION_INGEST_RUNTIME_INVALID);
|
||||
assert!(error.context().iter().any(|context| return context.value() == "runtime_resources.multi_source_activation_pending"));
|
||||
return;
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn pre_003_transaction_signal_fixture_preserves_exact_source_neutral_identity() {
|
||||
let source = match signal_source() {
|
||||
|
||||
Reference in New Issue
Block a user