v0.2.4-pre.008
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-onchain-transport-lib/unit_tests/rpc_economics.rs
|
||||
// version: 2
|
||||
// version: 3
|
||||
|
||||
#[test]
|
||||
fn inflation_reward_config_preserves_epoch_commitment_and_min_context_slot() {
|
||||
@@ -307,3 +307,186 @@ async fn typed_get_supply_preserves_scan_rpc_error() {
|
||||
assert_eq!(error.code(), crate::ERROR_CODE_RPC_APPLICATION_ERROR);
|
||||
handle.join().expect("fixture server must join");
|
||||
}
|
||||
|
||||
fn inflation_reward_fixture_pubkey(value: &str) -> ksp_core_lib::Pubkey {
|
||||
return value.parse::<ksp_core_lib::Pubkey>().expect("fixture inflation-reward pubkey must parse");
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn typed_get_inflation_reward_serializes_full_config_and_preserves_position_and_commission_states() {
|
||||
let (url, handle) = serve_once(include_str!("../fixtures/http/get_inflation_reward.success.json"));
|
||||
let pool = pool_for_url(url.as_str());
|
||||
let addresses = std::vec![
|
||||
inflation_reward_fixture_pubkey("11111111111111111111111111111111"),
|
||||
inflation_reward_fixture_pubkey("Vote111111111111111111111111111111111111111"),
|
||||
inflation_reward_fixture_pubkey("SysvarRent111111111111111111111111111111111"),
|
||||
inflation_reward_fixture_pubkey("Stake11111111111111111111111111111111111111"),
|
||||
];
|
||||
let config = crate::SolanaInflationRewardConfig::new(
|
||||
std::option::Option::Some(912),
|
||||
std::option::Option::Some(crate::SolanaCommitment::Finalized),
|
||||
std::option::Option::Some(431_000_000),
|
||||
);
|
||||
let rewards = pool
|
||||
.get_inflation_reward(&crate::HttpRoleName::new("default"), addresses.as_slice(), std::option::Option::Some(&config))
|
||||
.await
|
||||
.expect("inflation reward fixture must succeed");
|
||||
assert_eq!(rewards.len(), addresses.len());
|
||||
let first = rewards[0].as_ref().expect("first reward must be present");
|
||||
assert_eq!(first.epoch(), 912);
|
||||
assert_eq!(first.effective_slot(), 431_500_001);
|
||||
assert_eq!(first.amount(), 2_500_000);
|
||||
assert_eq!(first.post_balance(), 1_002_500_000);
|
||||
assert_eq!(first.commission(), std::option::Option::Some(7));
|
||||
assert_eq!(first.commission_bps().value(), std::option::Option::Some(&725));
|
||||
assert!(rewards[1].is_none());
|
||||
let third = rewards[2].as_ref().expect("third reward must be present");
|
||||
assert_eq!(third.commission(), std::option::Option::None);
|
||||
assert!(third.commission_bps().is_omitted());
|
||||
let fourth = rewards[3].as_ref().expect("fourth reward must be present");
|
||||
assert_eq!(fourth.commission(), std::option::Option::Some(3));
|
||||
assert!(fourth.commission_bps().is_null());
|
||||
|
||||
let request = handle.join().expect("fixture server must join");
|
||||
let body = request_body(request.as_str());
|
||||
assert_eq!(body["method"], serde_json::json!("getInflationReward"));
|
||||
assert_eq!(
|
||||
body["params"],
|
||||
serde_json::json!([
|
||||
[
|
||||
"11111111111111111111111111111111",
|
||||
"Vote111111111111111111111111111111111111111",
|
||||
"SysvarRent111111111111111111111111111111111",
|
||||
"Stake11111111111111111111111111111111111111"
|
||||
],
|
||||
{"epoch":912,"commitment":"finalized","minContextSlot":431000000}
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn typed_get_inflation_reward_preserves_duplicate_input_order_and_positional_nulls() {
|
||||
let (url, handle) = serve_once(include_str!("../fixtures/http/get_inflation_reward.duplicates.json"));
|
||||
let pool = pool_for_url(url.as_str());
|
||||
let first = inflation_reward_fixture_pubkey("11111111111111111111111111111111");
|
||||
let second = inflation_reward_fixture_pubkey("Vote111111111111111111111111111111111111111");
|
||||
let addresses = std::vec![first, second, first];
|
||||
let rewards = pool
|
||||
.get_inflation_reward(&crate::HttpRoleName::new("default"), addresses.as_slice(), std::option::Option::None)
|
||||
.await
|
||||
.expect("duplicate inflation reward fixture must succeed");
|
||||
assert_eq!(rewards.len(), 3);
|
||||
assert_eq!(rewards[0], rewards[2]);
|
||||
assert!(rewards[1].is_none());
|
||||
let request = handle.join().expect("fixture server must join");
|
||||
assert_eq!(
|
||||
request_body(request.as_str())["params"],
|
||||
serde_json::json!([["11111111111111111111111111111111", "Vote111111111111111111111111111111111111111", "11111111111111111111111111111111"]])
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn typed_get_inflation_reward_omits_absent_and_empty_config_but_keeps_address_parameter() {
|
||||
let role = crate::HttpRoleName::new("default");
|
||||
let address = inflation_reward_fixture_pubkey("11111111111111111111111111111111");
|
||||
let addresses = std::vec![address];
|
||||
let empty = crate::SolanaInflationRewardConfig::default();
|
||||
for config in [std::option::Option::None, std::option::Option::Some(&empty)] {
|
||||
let (url, handle) = serve_once(include_str!("../fixtures/http/get_inflation_reward.single_null.json"));
|
||||
let pool = pool_for_url(url.as_str());
|
||||
let rewards = pool.get_inflation_reward(&role, addresses.as_slice(), config).await.expect("single null inflation reward fixture must succeed");
|
||||
assert_eq!(rewards, std::vec![std::option::Option::None]);
|
||||
let request = handle.join().expect("fixture server must join");
|
||||
assert_eq!(request_body(request.as_str())["params"], serde_json::json!([["11111111111111111111111111111111"]]));
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn typed_get_inflation_reward_accepts_empty_address_list_without_inventing_a_minimum() {
|
||||
let (url, handle) = serve_once(include_str!("../fixtures/http/get_inflation_reward.empty.json"));
|
||||
let pool = pool_for_url(url.as_str());
|
||||
let rewards = pool
|
||||
.get_inflation_reward(&crate::HttpRoleName::new("default"), &[], std::option::Option::None)
|
||||
.await
|
||||
.expect("empty inflation reward fixture must succeed");
|
||||
assert!(rewards.is_empty());
|
||||
let request = handle.join().expect("fixture server must join");
|
||||
assert_eq!(request_body(request.as_str())["params"], serde_json::json!([[]]));
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn typed_get_inflation_reward_does_not_invent_a_256_address_limit() {
|
||||
let (url, handle) = serve_once(include_str!("../fixtures/http/get_inflation_reward.many_nulls.json"));
|
||||
let pool = pool_for_url(url.as_str());
|
||||
let address = inflation_reward_fixture_pubkey("11111111111111111111111111111111");
|
||||
let addresses = std::vec![address; 300];
|
||||
let rewards = pool
|
||||
.get_inflation_reward(&crate::HttpRoleName::new("default"), addresses.as_slice(), std::option::Option::None)
|
||||
.await
|
||||
.expect("300-address inflation reward fixture must succeed without local cardinality cap");
|
||||
assert_eq!(rewards.len(), 300);
|
||||
assert!(rewards.iter().all(std::option::Option::is_none));
|
||||
let request = handle.join().expect("fixture server must join");
|
||||
let body = request_body(request.as_str());
|
||||
assert_eq!(body["params"][0].as_array().expect("address parameter must be an array").len(), 300);
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn typed_get_inflation_reward_rejects_processed_commitment_before_io() {
|
||||
let role = crate::HttpRoleName::new("default");
|
||||
let pool = pool_for_url("http://127.0.0.1:1");
|
||||
let address = inflation_reward_fixture_pubkey("11111111111111111111111111111111");
|
||||
let config = crate::SolanaInflationRewardConfig::new(
|
||||
std::option::Option::Some(912),
|
||||
std::option::Option::Some(crate::SolanaCommitment::Processed),
|
||||
std::option::Option::None,
|
||||
);
|
||||
let result = pool.get_inflation_reward(&role, &[address], std::option::Option::Some(&config)).await;
|
||||
let error = result.expect_err("processed inflation-reward commitment must fail before I/O");
|
||||
assert_eq!(error.code(), crate::ERROR_CODE_INVALID_RPC_PARAMETERS);
|
||||
assert_eq!(error.context()[1].key(), "commitment");
|
||||
assert_eq!(error.context()[1].value(), "processed");
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn typed_get_inflation_reward_rejects_response_cardinality_mismatch() {
|
||||
let (url, handle) = serve_once(include_str!("../fixtures/http/get_inflation_reward.single_null.json"));
|
||||
let pool = pool_for_url(url.as_str());
|
||||
let first = inflation_reward_fixture_pubkey("11111111111111111111111111111111");
|
||||
let second = inflation_reward_fixture_pubkey("Vote111111111111111111111111111111111111111");
|
||||
let result = pool.get_inflation_reward(&crate::HttpRoleName::new("default"), &[first, second], std::option::Option::None).await;
|
||||
let error = result.expect_err("inflation reward response count mismatch must fail typed decoding");
|
||||
assert_eq!(error.code(), crate::ERROR_CODE_INVALID_RESPONSE);
|
||||
assert_eq!(error.context()[1].key(), "expected_count");
|
||||
assert_eq!(error.context()[1].value(), "2");
|
||||
assert_eq!(error.context()[2].key(), "actual_count");
|
||||
assert_eq!(error.context()[2].value(), "1");
|
||||
handle.join().expect("fixture server must join");
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn typed_get_inflation_reward_preserves_min_context_slot_rpc_error() {
|
||||
let (url, handle) = serve_once(include_str!("../fixtures/http/get_inflation_reward.error_min_context.json"));
|
||||
let pool = pool_for_url(url.as_str());
|
||||
let address = inflation_reward_fixture_pubkey("11111111111111111111111111111111");
|
||||
let config = crate::SolanaInflationRewardConfig::new(
|
||||
std::option::Option::Some(912),
|
||||
std::option::Option::Some(crate::SolanaCommitment::Confirmed),
|
||||
std::option::Option::Some(431_500_000),
|
||||
);
|
||||
let result = pool.get_inflation_reward(&crate::HttpRoleName::new("default"), &[address], std::option::Option::Some(&config)).await;
|
||||
let error = result.expect_err("inflation reward min-context RPC error must propagate");
|
||||
assert_eq!(error.code(), crate::ERROR_CODE_RPC_APPLICATION_ERROR);
|
||||
handle.join().expect("fixture server must join");
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn typed_get_inflation_reward_preserves_epoch_rewards_period_active_rpc_error() {
|
||||
let (url, handle) = serve_once(include_str!("../fixtures/http/get_inflation_reward.error_epoch_rewards_active.json"));
|
||||
let pool = pool_for_url(url.as_str());
|
||||
let address = inflation_reward_fixture_pubkey("11111111111111111111111111111111");
|
||||
let result = pool.get_inflation_reward(&crate::HttpRoleName::new("default"), &[address], std::option::Option::None).await;
|
||||
let error = result.expect_err("active epoch-rewards RPC error must propagate");
|
||||
assert_eq!(error.code(), crate::ERROR_CODE_RPC_APPLICATION_ERROR);
|
||||
handle.join().expect("fixture server must join");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user