87 lines
4.8 KiB
Rust
87 lines
4.8 KiB
Rust
// 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"));
|
|
}
|