// file: crates/ksp-onchain-transport-lib/unit_tests/rpc_cluster.rs // version: 2 #[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::().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"})] ); } #[test] fn staged_epoch_snapshot_and_leader_helpers_preserve_wire_shapes() { let epoch = crate::SolanaEpochInfo::decode_wire( "getEpochInfo", serde_json::json!({"absoluteSlot":10,"blockHeight":9,"epoch":2,"slotIndex":3,"slotsInEpoch":32,"transactionCount":null}), ) .expect("epoch info must decode"); assert_eq!(epoch.transaction_count(), std::option::Option::None); let schedule = crate::SolanaEpochSchedule::decode_wire( "getEpochSchedule", serde_json::json!({"firstNormalEpoch":1,"firstNormalSlot":32,"leaderScheduleSlotOffset":32,"slotsPerEpoch":64,"warmup":false}), ) .expect("epoch schedule must decode"); assert_eq!(schedule.slots_per_epoch(), 64); let snapshot = crate::SolanaSnapshotSlotInfo::decode_wire("getHighestSnapshotSlot", serde_json::json!({"full":100,"incremental":null})) .expect("snapshot info must decode"); assert_eq!(snapshot.full(), 100); assert_eq!(snapshot.incremental(), std::option::Option::None); let leader = crate::SolanaLeaderSchedule::decode_wire("getLeaderSchedule", serde_json::json!({"11111111111111111111111111111111":[0,2,4]})) .expect("leader schedule must decode"); assert_eq!(leader.entries().len(), 1); } #[test] fn staged_vote_status_and_config_helpers_preserve_wire_shapes() { let vote_pubkey = "11111111111111111111111111111111".parse::().expect("fixture pubkey must parse"); let config = crate::SolanaVoteAccountsConfig::new( std::option::Option::Some(crate::SolanaCommitment::Finalized), std::option::Option::Some(vote_pubkey), std::option::Option::Some(true), std::option::Option::Some(128), ); assert_eq!( config.to_json_value(), serde_json::json!({"commitment":"finalized","votePubkey":"11111111111111111111111111111111","keepUnstakedDelinquents":true,"delinquentSlotDistance":128}) ); let status = crate::SolanaVoteAccountStatus::decode_wire( "getVoteAccounts", serde_json::json!({ "current":[{ "votePubkey":"11111111111111111111111111111111", "nodePubkey":"11111111111111111111111111111111", "activatedStake":1, "commission":5, "epochVoteAccount":true, "epochCredits":[], "lastVote":2, "rootSlot":1 }], "delinquent":[] }), ) .expect("vote account status must decode"); assert_eq!(status.current().len(), 1); assert!(status.delinquent().is_empty()); }