v0.2.4-pre.005
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-onchain-transport-lib/unit_tests/rpc_blocks.rs
|
||||
// version: 3
|
||||
// version: 4
|
||||
|
||||
#[test]
|
||||
fn transaction_details_and_get_block_config_preserve_all_modern_options() {
|
||||
@@ -453,3 +453,85 @@ async fn typed_get_recent_performance_samples_rejects_above_720_before_io() {
|
||||
assert_eq!(error.context()[1].key(), "limit");
|
||||
assert_eq!(error.context()[1].value(), "721");
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn typed_get_block_production_serializes_full_config_and_decodes_contextual_result() {
|
||||
let identity = "11111111111111111111111111111111".parse::<ksp_core_lib::Pubkey>().expect("fixture identity must parse");
|
||||
let range = crate::SolanaBlockProductionRange::new(430_000_000, std::option::Option::Some(430_000_099));
|
||||
let config = crate::SolanaBlockProductionConfig::new(
|
||||
std::option::Option::Some(crate::SolanaCommitment::Finalized),
|
||||
std::option::Option::Some(identity),
|
||||
std::option::Option::Some(range),
|
||||
);
|
||||
let (url, handle) = serve_once(include_str!("../fixtures/http/get_block_production.success.json"));
|
||||
let pool = pool_for_url(url.as_str());
|
||||
let response = pool
|
||||
.get_block_production(&crate::HttpRoleName::new("default"), std::option::Option::Some(&config))
|
||||
.await
|
||||
.expect("block production fixture must succeed");
|
||||
assert_eq!(response.context().slot(), 430_000_123);
|
||||
assert_eq!(response.context().api_version(), std::option::Option::Some("4.2.1"));
|
||||
assert_eq!(response.value().by_identity().get(&identity), std::option::Option::Some(&(8, 7)));
|
||||
assert_eq!(response.value().range().first_slot(), 430_000_000);
|
||||
assert_eq!(response.value().range().last_slot(), 430_000_099);
|
||||
let request = handle.join().expect("fixture server must join");
|
||||
let body = request_body(request.as_str());
|
||||
assert_eq!(body["method"], serde_json::json!("getBlockProduction"));
|
||||
assert_eq!(
|
||||
body["params"],
|
||||
serde_json::json!([{
|
||||
"commitment":"finalized",
|
||||
"identity":"11111111111111111111111111111111",
|
||||
"range":{"firstSlot":430000000,"lastSlot":430000099}
|
||||
}])
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn typed_get_block_production_omits_empty_config_and_supports_open_range_with_processed_commitment() {
|
||||
let role = crate::HttpRoleName::new("default");
|
||||
let empty = crate::SolanaBlockProductionConfig::default();
|
||||
let (url, handle) = serve_once(include_str!("../fixtures/http/get_block_production.success.json"));
|
||||
let pool = pool_for_url(url.as_str());
|
||||
let response = pool.get_block_production(&role, std::option::Option::Some(&empty)).await.expect("empty block production config must succeed");
|
||||
assert_eq!(response.value().range().last_slot(), 430_000_099);
|
||||
let request = handle.join().expect("fixture server must join");
|
||||
assert_eq!(request_body(request.as_str())["params"], serde_json::json!([]));
|
||||
|
||||
let range = crate::SolanaBlockProductionRange::new(430_000_000, std::option::Option::None);
|
||||
let config = crate::SolanaBlockProductionConfig::new(
|
||||
std::option::Option::Some(crate::SolanaCommitment::Processed),
|
||||
std::option::Option::None,
|
||||
std::option::Option::Some(range),
|
||||
);
|
||||
let (url, handle) = serve_once(include_str!("../fixtures/http/get_block_production.success.json"));
|
||||
let pool = pool_for_url(url.as_str());
|
||||
pool.get_block_production(&role, std::option::Option::Some(&config)).await.expect("open block production range must succeed");
|
||||
let request = handle.join().expect("fixture server must join");
|
||||
assert_eq!(request_body(request.as_str())["params"], serde_json::json!([{"commitment":"processed","range":{"firstSlot":430000000}}]));
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn typed_get_block_production_rejects_reversed_range_before_io() {
|
||||
let range = crate::SolanaBlockProductionRange::new(430_000_100, std::option::Option::Some(430_000_099));
|
||||
let config = crate::SolanaBlockProductionConfig::new(std::option::Option::None, std::option::Option::None, std::option::Option::Some(range));
|
||||
let pool = pool_for_url("http://127.0.0.1:9");
|
||||
let result = pool.get_block_production(&crate::HttpRoleName::new("default"), std::option::Option::Some(&config)).await;
|
||||
let error = result.expect_err("reversed block production range must reject before I/O");
|
||||
assert_eq!(error.code(), crate::ERROR_CODE_INVALID_RPC_PARAMETERS);
|
||||
assert_eq!(error.context()[1].key(), "first_slot");
|
||||
assert_eq!(error.context()[1].value(), "430000100");
|
||||
assert_eq!(error.context()[2].key(), "last_slot");
|
||||
assert_eq!(error.context()[2].value(), "430000099");
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn typed_get_block_production_rejects_invalid_wire_identity_without_echoing_value() {
|
||||
let (url, handle) = serve_once(include_str!("../fixtures/http/get_block_production.invalid_identity.json"));
|
||||
let pool = pool_for_url(url.as_str());
|
||||
let result = pool.get_block_production(&crate::HttpRoleName::new("default"), std::option::Option::None).await;
|
||||
let error = result.expect_err("invalid block production identity must fail closed");
|
||||
assert_eq!(error.code(), crate::ERROR_CODE_INVALID_RESPONSE);
|
||||
assert!(!error.to_string().contains("not-a-pubkey"));
|
||||
handle.join().expect("fixture server must join");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user