53 lines
2.8 KiB
Rust
53 lines
2.8 KiB
Rust
// file: crates/ksp-onchain-transport-lib/unit_tests/rpc_cluster.rs
|
|
// version: 1
|
|
|
|
#[test]
|
|
fn cluster_node_fixture_preserves_v4_client_id_and_optional_fields() {
|
|
let value: serde_json::Value = serde_json::from_str(include_str!("../fixtures/http/cluster_node.v4_2_1.json")).expect("fixture must decode");
|
|
let node = crate::SolanaClusterNode::decode_wire("getClusterNodes", value).expect("cluster node must decode");
|
|
assert_eq!(node.client_id(), std::option::Option::Some("Agave"));
|
|
assert_eq!(node.rpc(), std::option::Option::Some("127.0.0.1:8899"));
|
|
assert_eq!(node.pubsub(), std::option::Option::None);
|
|
}
|
|
|
|
#[test]
|
|
fn vote_account_fixture_preserves_optional_basis_point_commission_and_epoch_credit_triples() {
|
|
let value: serde_json::Value = serde_json::from_str(include_str!("../fixtures/http/vote_account.v4_2_1.json")).expect("fixture must decode");
|
|
let info = crate::SolanaVoteAccountInfo::decode_wire("getVoteAccounts", value).expect("vote account must decode");
|
|
assert_eq!(info.commission(), 8);
|
|
assert_eq!(info.inflation_rewards_commission_bps(), std::option::Option::Some(750));
|
|
assert_eq!(info.epoch_credits().len(), 2);
|
|
assert_eq!(info.epoch_credits()[0].epoch(), 700);
|
|
assert_eq!(info.epoch_credits()[0].previous_credits(), 90);
|
|
}
|
|
|
|
#[test]
|
|
fn vote_account_wire_accepts_nodes_predating_basis_point_commission_field() {
|
|
let value = serde_json::json!({
|
|
"votePubkey":"11111111111111111111111111111111",
|
|
"nodePubkey":"11111111111111111111111111111111",
|
|
"activatedStake":1,
|
|
"commission":5,
|
|
"epochVoteAccount":true,
|
|
"epochCredits":[],
|
|
"lastVote":2,
|
|
"rootSlot":1
|
|
});
|
|
let info = crate::SolanaVoteAccountInfo::decode_wire("getVoteAccounts", value).expect("legacy node shape must decode");
|
|
assert_eq!(info.inflation_rewards_commission_bps(), std::option::Option::None);
|
|
}
|
|
|
|
#[test]
|
|
fn leader_schedule_request_encodes_current_epoch_and_slot_overloads_without_ambiguous_arrays() {
|
|
let identity = "11111111111111111111111111111111".parse::<ksp_core_lib::Pubkey>().expect("fixture pubkey must parse");
|
|
let config = crate::SolanaLeaderScheduleConfig::new(std::option::Option::Some(identity), std::option::Option::Some(crate::SolanaCommitment::Finalized));
|
|
assert_eq!(
|
|
crate::SolanaLeaderScheduleRequest::CurrentEpoch(std::option::Option::Some(config.clone())).to_json_params(),
|
|
std::vec![serde_json::json!({"identity":"11111111111111111111111111111111","commitment":"finalized"})]
|
|
);
|
|
assert_eq!(
|
|
crate::SolanaLeaderScheduleRequest::Slot { slot: 123, config: std::option::Option::Some(config) }.to_json_params(),
|
|
std::vec![serde_json::json!(123), serde_json::json!({"identity":"11111111111111111111111111111111","commitment":"finalized"})]
|
|
);
|
|
}
|