v0.2.4-pre.002
This commit is contained in:
150
crates/ksp-onchain-transport-lib/unit_tests/rpc_blocks.rs
Normal file
150
crates/ksp-onchain-transport-lib/unit_tests/rpc_blocks.rs
Normal file
@@ -0,0 +1,150 @@
|
||||
// file: crates/ksp-onchain-transport-lib/unit_tests/rpc_blocks.rs
|
||||
// version: 1
|
||||
|
||||
#[test]
|
||||
fn transaction_details_and_get_block_config_preserve_all_modern_options() {
|
||||
assert_eq!(crate::SolanaTransactionDetails::Full.as_str(), "full");
|
||||
assert_eq!(crate::SolanaTransactionDetails::Signatures.as_str(), "signatures");
|
||||
assert_eq!(crate::SolanaTransactionDetails::None.as_str(), "none");
|
||||
assert_eq!(crate::SolanaTransactionDetails::Accounts.as_str(), "accounts");
|
||||
let config = crate::SolanaGetBlockConfig::new(
|
||||
std::option::Option::Some(crate::SolanaCommitment::Confirmed),
|
||||
std::option::Option::Some(crate::SolanaTransactionEncoding::JsonParsed),
|
||||
std::option::Option::Some(crate::SolanaTransactionDetails::Accounts),
|
||||
std::option::Option::Some(1),
|
||||
std::option::Option::Some(false),
|
||||
);
|
||||
assert_eq!(config.commitment(), std::option::Option::Some(crate::SolanaCommitment::Confirmed));
|
||||
assert_eq!(config.encoding(), std::option::Option::Some(crate::SolanaTransactionEncoding::JsonParsed));
|
||||
assert_eq!(config.transaction_details(), std::option::Option::Some(crate::SolanaTransactionDetails::Accounts));
|
||||
assert_eq!(config.max_supported_transaction_version(), std::option::Option::Some(1));
|
||||
assert_eq!(config.rewards(), std::option::Option::Some(false));
|
||||
assert_eq!(
|
||||
config.to_json_value(),
|
||||
serde_json::json!({
|
||||
"commitment":"confirmed",
|
||||
"encoding":"jsonParsed",
|
||||
"transactionDetails":"accounts",
|
||||
"maxSupportedTransactionVersion":1,
|
||||
"rewards":false
|
||||
})
|
||||
);
|
||||
assert!(crate::SolanaGetBlockConfig::default().is_empty());
|
||||
assert_eq!(crate::SolanaGetBlockConfig::default().to_json_value(), serde_json::json!({}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn block_production_config_preserves_identity_range_and_commitment() {
|
||||
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),
|
||||
);
|
||||
assert_eq!(config.identity(), std::option::Option::Some(&identity));
|
||||
assert_eq!(config.range().expect("range must be present").first_slot(), 430_000_000);
|
||||
assert_eq!(config.range().expect("range must be present").last_slot(), std::option::Option::Some(430_000_099));
|
||||
assert_eq!(
|
||||
config.to_json_value(),
|
||||
serde_json::json!({
|
||||
"commitment":"finalized",
|
||||
"identity":"11111111111111111111111111111111",
|
||||
"range":{"firstSlot":430000000,"lastSlot":430000099}
|
||||
})
|
||||
);
|
||||
assert!(crate::SolanaBlockProductionConfig::default().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn block_commitment_fixture_preserves_nullable_distribution() {
|
||||
let values = serde_json::from_str::<std::vec::Vec<serde_json::Value>>(include_str!("../fixtures/http/block_commitment.variants.json"))
|
||||
.expect("block commitment fixtures must decode");
|
||||
let present = crate::SolanaBlockCommitment::decode_wire("getBlockCommitment", values[0].clone()).expect("present commitment must decode");
|
||||
let absent = crate::SolanaBlockCommitment::decode_wire("getBlockCommitment", values[1].clone()).expect("null commitment must decode");
|
||||
assert_eq!(present.commitment(), std::option::Option::Some(&[1, 2, 3, 4][..]));
|
||||
assert_eq!(present.total_stake(), 1_000_000_000);
|
||||
assert_eq!(absent.commitment(), std::option::Option::None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn block_production_fixture_types_identity_keys_and_preserves_counts() {
|
||||
let value =
|
||||
serde_json::from_str::<serde_json::Value>(include_str!("../fixtures/http/block_production.v4_2_1.json")).expect("block production fixture must decode");
|
||||
let result = crate::SolanaBlockProduction::decode_wire("getBlockProduction", value).expect("block production result must decode");
|
||||
let identity = "11111111111111111111111111111111".parse::<ksp_core_lib::Pubkey>().expect("fixture identity must parse");
|
||||
assert_eq!(result.by_identity().get(&identity), std::option::Option::Some(&(8, 7)));
|
||||
assert_eq!(result.range().first_slot(), 430_000_000);
|
||||
assert_eq!(result.range().last_slot(), 430_000_099);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn confirmed_block_fixture_preserves_rich_wire_and_simd_extensions() {
|
||||
let value =
|
||||
serde_json::from_str::<serde_json::Value>(include_str!("../fixtures/http/confirmed_block.v4_2_1.json")).expect("confirmed block fixture must decode");
|
||||
let block = crate::SolanaConfirmedBlock::decode_wire("getBlock", value).expect("confirmed block must decode");
|
||||
assert_eq!(block.parent_slot(), 430_000_122);
|
||||
assert_eq!(block.block_time(), std::option::Option::Some(1_787_072_400));
|
||||
assert_eq!(block.block_height(), std::option::Option::Some(410_000_000));
|
||||
assert_eq!(block.num_reward_partitions().value(), std::option::Option::Some(&4));
|
||||
let transactions = block.transactions().value().expect("transactions must be present");
|
||||
assert_eq!(transactions.len(), 2);
|
||||
assert!(matches!(transactions[0].version(), crate::SolanaWireField::Value(crate::SolanaTransactionVersion::Number(1))));
|
||||
assert!(transactions[1].version().is_omitted());
|
||||
assert!(transactions[1].meta().is_null());
|
||||
let rewards = block.rewards().value().expect("rewards must be present");
|
||||
assert_eq!(rewards.len(), 2);
|
||||
assert_eq!(rewards[0].reward_type(), std::option::Option::Some("Fee"));
|
||||
assert_eq!(rewards[0].commission(), std::option::Option::None);
|
||||
assert_eq!(rewards[0].commission_bps().value(), std::option::Option::Some(&1_234));
|
||||
assert_eq!(rewards[1].commission(), std::option::Option::Some(5));
|
||||
assert!(rewards[1].commission_bps().is_omitted());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn confirmed_block_fixture_distinguishes_omitted_and_explicit_null_fields() {
|
||||
let values = serde_json::from_str::<std::vec::Vec<serde_json::Value>>(include_str!("../fixtures/http/confirmed_block.omissions.json"))
|
||||
.expect("confirmed block omission fixtures must decode");
|
||||
let omitted = crate::SolanaConfirmedBlock::decode_wire("getBlock", values[0].clone()).expect("omitted-fields block must decode");
|
||||
let nulls = crate::SolanaConfirmedBlock::decode_wire("getBlock", values[1].clone()).expect("null-fields block must decode");
|
||||
assert!(omitted.transactions().is_omitted());
|
||||
assert!(omitted.signatures().is_omitted());
|
||||
assert!(omitted.rewards().is_omitted());
|
||||
assert!(omitted.num_reward_partitions().is_omitted());
|
||||
assert!(nulls.transactions().is_null());
|
||||
assert!(nulls.signatures().is_null());
|
||||
assert!(nulls.rewards().is_null());
|
||||
assert!(nulls.num_reward_partitions().is_null());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn performance_sample_fixture_accepts_current_and_older_shapes() {
|
||||
let values = serde_json::from_str::<std::vec::Vec<serde_json::Value>>(include_str!("../fixtures/http/performance_sample.variants.json"))
|
||||
.expect("performance sample fixtures must decode");
|
||||
let current = crate::SolanaPerformanceSample::decode_wire("getRecentPerformanceSamples", values[0].clone()).expect("current sample must decode");
|
||||
let older = crate::SolanaPerformanceSample::decode_wire("getRecentPerformanceSamples", values[1].clone()).expect("older sample must decode");
|
||||
assert_eq!(current.slot(), 430_000_123);
|
||||
assert_eq!(current.num_transactions(), 250_000);
|
||||
assert_eq!(current.num_non_vote_transactions(), std::option::Option::Some(175_000));
|
||||
assert_eq!(current.num_slots(), 120);
|
||||
assert_eq!(current.sample_period_secs(), 60);
|
||||
assert_eq!(older.num_non_vote_transactions(), std::option::Option::None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn block_reward_rejects_invalid_pubkey_without_echoing_value() {
|
||||
let result = crate::SolanaConfirmedBlock::decode_wire(
|
||||
"getBlock",
|
||||
serde_json::json!({
|
||||
"previousBlockhash":"previous",
|
||||
"blockhash":"block",
|
||||
"parentSlot":1,
|
||||
"rewards":[{"pubkey":"not-a-pubkey","lamports":1,"postBalance":2,"rewardType":"Fee","commission":null}],
|
||||
"blockTime":null,
|
||||
"blockHeight":null
|
||||
}),
|
||||
);
|
||||
let error = result.expect_err("invalid reward pubkey must fail closed");
|
||||
assert_eq!(error.code(), crate::ERROR_CODE_INVALID_RESPONSE);
|
||||
assert!(!error.to_string().contains("not-a-pubkey"));
|
||||
}
|
||||
86
crates/ksp-onchain-transport-lib/unit_tests/rpc_economics.rs
Normal file
86
crates/ksp-onchain-transport-lib/unit_tests/rpc_economics.rs
Normal file
@@ -0,0 +1,86 @@
|
||||
// file: crates/ksp-onchain-transport-lib/unit_tests/rpc_economics.rs
|
||||
// version: 1
|
||||
|
||||
#[test]
|
||||
fn inflation_reward_config_preserves_epoch_commitment_and_min_context_slot() {
|
||||
let config = crate::SolanaInflationRewardConfig::new(
|
||||
std::option::Option::Some(811),
|
||||
std::option::Option::Some(crate::SolanaCommitment::Finalized),
|
||||
std::option::Option::Some(429_000_000),
|
||||
);
|
||||
assert_eq!(config.epoch(), std::option::Option::Some(811));
|
||||
assert_eq!(config.commitment(), std::option::Option::Some(crate::SolanaCommitment::Finalized));
|
||||
assert_eq!(config.min_context_slot(), std::option::Option::Some(429_000_000));
|
||||
assert_eq!(config.to_json_value(), serde_json::json!({"epoch":811,"commitment":"finalized","minContextSlot":429000000}));
|
||||
assert!(crate::SolanaInflationRewardConfig::default().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn supply_config_distinguishes_omitted_from_explicit_false() {
|
||||
let omitted = crate::SolanaSupplyConfig::default();
|
||||
let explicit_false = crate::SolanaSupplyConfig::new(std::option::Option::Some(crate::SolanaCommitment::Confirmed), std::option::Option::Some(false));
|
||||
assert!(omitted.is_empty());
|
||||
assert_eq!(omitted.to_json_value(), serde_json::json!({}));
|
||||
assert_eq!(explicit_false.exclude_non_circulating_accounts_list(), std::option::Option::Some(false));
|
||||
assert_eq!(explicit_false.to_json_value(), serde_json::json!({"commitment":"confirmed","excludeNonCirculatingAccountsList":false}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inflation_governor_and_rate_fixtures_preserve_runtime_values() {
|
||||
let governor_value = serde_json::from_str::<serde_json::Value>(include_str!("../fixtures/http/inflation_governor.v4_2_1.json"))
|
||||
.expect("inflation governor fixture must decode");
|
||||
let rate_value =
|
||||
serde_json::from_str::<serde_json::Value>(include_str!("../fixtures/http/inflation_rate.v4_2_1.json")).expect("inflation rate fixture must decode");
|
||||
let governor = crate::SolanaInflationGovernor::decode_wire("getInflationGovernor", governor_value).expect("inflation governor must decode");
|
||||
let rate = crate::SolanaInflationRate::decode_wire("getInflationRate", rate_value).expect("inflation rate must decode");
|
||||
assert_eq!(governor.initial(), 0.08);
|
||||
assert_eq!(governor.terminal(), 0.015);
|
||||
assert_eq!(governor.taper(), 0.15);
|
||||
assert_eq!(governor.foundation(), 0.05);
|
||||
assert_eq!(governor.foundation_term(), 7.0);
|
||||
assert_eq!(rate.total(), 0.042);
|
||||
assert_eq!(rate.validator(), 0.041);
|
||||
assert_eq!(rate.foundation(), 0.001);
|
||||
assert_eq!(rate.epoch(), 812);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inflation_reward_fixture_preserves_position_null_and_commission_bps_states() {
|
||||
let values = serde_json::from_str::<std::vec::Vec<serde_json::Value>>(include_str!("../fixtures/http/inflation_reward.variants.json"))
|
||||
.expect("inflation reward fixtures must decode");
|
||||
let first = crate::SolanaInflationReward::decode_wire("getInflationReward", values[0].clone()).expect("first reward must decode");
|
||||
let third = crate::SolanaInflationReward::decode_wire("getInflationReward", values[2].clone()).expect("third reward must decode");
|
||||
assert_eq!(values.len(), 3);
|
||||
assert!(values[1].is_null());
|
||||
assert_eq!(first.epoch(), 811);
|
||||
assert_eq!(first.effective_slot(), 429_900_000);
|
||||
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_eq!(third.commission(), std::option::Option::None);
|
||||
assert!(third.commission_bps().is_omitted());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn supply_fixture_types_non_circulating_accounts_and_preserves_order() {
|
||||
let value = serde_json::from_str::<serde_json::Value>(include_str!("../fixtures/http/supply.v4_2_1.json")).expect("supply fixture must decode");
|
||||
let supply = crate::SolanaSupply::decode_wire("getSupply", value).expect("supply must decode");
|
||||
assert_eq!(supply.total(), 600_000_000_000_000_000);
|
||||
assert_eq!(supply.circulating(), 500_000_000_000_000_000);
|
||||
assert_eq!(supply.non_circulating(), 100_000_000_000_000_000);
|
||||
assert_eq!(supply.non_circulating_accounts().len(), 2);
|
||||
assert_eq!(supply.non_circulating_accounts()[0].to_string(), "11111111111111111111111111111111");
|
||||
assert_eq!(supply.non_circulating_accounts()[1].to_string(), "Vote111111111111111111111111111111111111111");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn supply_rejects_invalid_non_circulating_pubkey_without_echoing_value() {
|
||||
let result = crate::SolanaSupply::decode_wire(
|
||||
"getSupply",
|
||||
serde_json::json!({"total":3,"circulating":2,"nonCirculating":1,"nonCirculatingAccounts":["invalid-pubkey"]}),
|
||||
);
|
||||
let error = result.expect_err("invalid supply pubkey must fail closed");
|
||||
assert_eq!(error.code(), crate::ERROR_CODE_INVALID_RESPONSE);
|
||||
assert!(!error.to_string().contains("invalid-pubkey"));
|
||||
}
|
||||
Reference in New Issue
Block a user