v0.2.4-pre.007
This commit is contained in:
@@ -0,0 +1 @@
|
||||
{"jsonrpc":"2.0","result":{"initial":0.07123456789,"terminal":0.0123456789,"taper":0.2718281828,"foundation":0.0042,"foundationTerm":6.25},"id":1}
|
||||
@@ -0,0 +1 @@
|
||||
{"jsonrpc":"2.0","result":{"total":0.0387654321,"validator":0.037654321,"foundation":0.0011111111,"epoch":913},"id":1}
|
||||
@@ -0,0 +1 @@
|
||||
{"jsonrpc":"2.0","error":{"code":-32016,"message":"Minimum context slot has not been reached","data":{"contextSlot":430999999}},"id":1}
|
||||
@@ -0,0 +1 @@
|
||||
{"jsonrpc":"2.0","result":{"context":{"slot":431000123,"apiVersion":"4.2.1"},"value":42424242},"id":1}
|
||||
@@ -0,0 +1 @@
|
||||
{"jsonrpc":"2.0","error":{"code":-32012,"message":"scan failed"},"id":1}
|
||||
@@ -0,0 +1 @@
|
||||
{"jsonrpc":"2.0","result":{"context":{"slot":431000125,"apiVersion":"4.2.1"},"value":{"total":610000000000000000,"circulating":510000000000000000,"nonCirculating":100000000000000000,"nonCirculatingAccounts":[]}},"id":1}
|
||||
@@ -0,0 +1 @@
|
||||
{"jsonrpc":"2.0","result":{"context":{"slot":431000124,"apiVersion":"4.2.1"},"value":{"total":610000000000000000,"circulating":510000000000000000,"nonCirculating":100000000000000000,"nonCirculatingAccounts":["11111111111111111111111111111111","Vote111111111111111111111111111111111111111"]}},"id":1}
|
||||
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-onchain-transport-lib/src/rpc_economics.rs
|
||||
// version: 2
|
||||
// version: 3
|
||||
|
||||
/// Inflation-governor values returned by `getInflationGovernor`.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
@@ -43,7 +43,6 @@ impl SolanaInflationGovernor {
|
||||
}
|
||||
|
||||
/// Decodes an inflation-governor result from its Solana JSON wire shape.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn decode_wire(method: &str, value: serde_json::Value) -> ksp_core_lib::Result<Self> {
|
||||
let decoded = crate::decode_wire_json::<WireInflationGovernor>(method, value);
|
||||
return match decoded {
|
||||
@@ -94,7 +93,6 @@ impl SolanaInflationRate {
|
||||
}
|
||||
|
||||
/// Decodes an inflation-rate result from its Solana JSON wire shape.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn decode_wire(method: &str, value: serde_json::Value) -> ksp_core_lib::Result<Self> {
|
||||
let decoded = crate::decode_wire_json::<WireInflationRate>(method, value);
|
||||
return match decoded {
|
||||
@@ -260,14 +258,12 @@ impl SolanaSupplyConfig {
|
||||
}
|
||||
|
||||
/// Returns whether this config would serialize to an empty object.
|
||||
#[cfg(test)]
|
||||
pub(crate) const fn is_empty(&self) -> bool {
|
||||
return self.commitment.is_none() && self.exclude_non_circulating_accounts_list.is_none();
|
||||
}
|
||||
|
||||
/// Serializes this config to the exact Solana JSON-RPC object.
|
||||
#[must_use]
|
||||
#[cfg(test)]
|
||||
pub(crate) fn to_json_value(self) -> serde_json::Value {
|
||||
let mut object = serde_json::Map::new();
|
||||
if let std::option::Option::Some(commitment) = self.commitment {
|
||||
@@ -315,7 +311,6 @@ impl SolanaSupply {
|
||||
}
|
||||
|
||||
/// Decodes a supply result from its Solana JSON wire shape.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn decode_wire(method: &str, value: serde_json::Value) -> ksp_core_lib::Result<Self> {
|
||||
let decoded = crate::decode_wire_json::<WireSupply>(method, value);
|
||||
let wire = match decoded {
|
||||
@@ -339,7 +334,152 @@ impl SolanaSupply {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl crate::HttpTransportPool {
|
||||
/// Executes typed `getInflationGovernor` and returns the runtime-provided schedule values unchanged.
|
||||
pub async fn get_inflation_governor(
|
||||
&self,
|
||||
role: &crate::HttpRoleName,
|
||||
config: std::option::Option<&crate::SolanaCommitmentConfig>,
|
||||
) -> ksp_core_lib::Result<crate::SolanaInflationGovernor> {
|
||||
let mut params = std::vec::Vec::new();
|
||||
push_economics_commitment_config(&mut params, config);
|
||||
let value = self.execute_economics_rpc("getInflationGovernor", role, params).await;
|
||||
return match value {
|
||||
std::result::Result::Ok(value) => crate::SolanaInflationGovernor::decode_wire("getInflationGovernor", value),
|
||||
std::result::Result::Err(error) => std::result::Result::Err(error),
|
||||
};
|
||||
}
|
||||
|
||||
/// Executes typed `getInflationRate` without locally recalculating the inflation schedule.
|
||||
pub async fn get_inflation_rate(&self, role: &crate::HttpRoleName) -> ksp_core_lib::Result<crate::SolanaInflationRate> {
|
||||
let value = self.execute_economics_rpc("getInflationRate", role, std::vec::Vec::new()).await;
|
||||
return match value {
|
||||
std::result::Result::Ok(value) => crate::SolanaInflationRate::decode_wire("getInflationRate", value),
|
||||
std::result::Result::Err(error) => std::result::Result::Err(error),
|
||||
};
|
||||
}
|
||||
|
||||
/// Executes typed `getStakeMinimumDelegation` and preserves the contextual runtime value in lamports.
|
||||
pub async fn get_stake_minimum_delegation(
|
||||
&self,
|
||||
role: &crate::HttpRoleName,
|
||||
config: std::option::Option<&crate::SolanaContextConfig>,
|
||||
) -> ksp_core_lib::Result<crate::SolanaRpcResponse<u64>> {
|
||||
let mut params = std::vec::Vec::new();
|
||||
push_economics_context_config(&mut params, config);
|
||||
let value = self.execute_economics_rpc("getStakeMinimumDelegation", role, params).await;
|
||||
let value = match value {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
||||
};
|
||||
return decode_economics_u64_response("getStakeMinimumDelegation", value);
|
||||
}
|
||||
|
||||
/// Executes typed `getSupply`, preserving the explicit account-list exclusion flag and contextual totals.
|
||||
pub async fn get_supply(
|
||||
&self,
|
||||
role: &crate::HttpRoleName,
|
||||
config: std::option::Option<&crate::SolanaSupplyConfig>,
|
||||
) -> ksp_core_lib::Result<crate::SolanaRpcResponse<crate::SolanaSupply>> {
|
||||
let mut params = std::vec::Vec::new();
|
||||
if let std::option::Option::Some(config) = config
|
||||
&& !config.is_empty()
|
||||
{
|
||||
params.push((*config).to_json_value());
|
||||
}
|
||||
let value = self.execute_economics_rpc("getSupply", role, params).await;
|
||||
let value = match value {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
||||
};
|
||||
return decode_supply_response("getSupply", value);
|
||||
}
|
||||
|
||||
async fn execute_economics_rpc(
|
||||
&self,
|
||||
method_name: &'static str,
|
||||
role: &crate::HttpRoleName,
|
||||
params: std::vec::Vec<serde_json::Value>,
|
||||
) -> ksp_core_lib::Result<serde_json::Value> {
|
||||
let descriptor = economics_descriptor(method_name);
|
||||
let descriptor = match descriptor {
|
||||
std::result::Result::Ok(descriptor) => descriptor,
|
||||
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
||||
};
|
||||
return self.execute_standard_rpc(role, descriptor, params).await;
|
||||
}
|
||||
}
|
||||
|
||||
fn push_economics_commitment_config(params: &mut std::vec::Vec<serde_json::Value>, config: std::option::Option<&crate::SolanaCommitmentConfig>) {
|
||||
if let std::option::Option::Some(config) = config
|
||||
&& config.commitment().is_some()
|
||||
{
|
||||
params.push((*config).to_json_value());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
fn push_economics_context_config(params: &mut std::vec::Vec<serde_json::Value>, config: std::option::Option<&crate::SolanaContextConfig>) {
|
||||
if let std::option::Option::Some(config) = config
|
||||
&& (config.commitment().is_some() || config.min_context_slot().is_some())
|
||||
{
|
||||
params.push((*config).to_json_value());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
fn decode_economics_u64_response(method: &str, value: serde_json::Value) -> ksp_core_lib::Result<crate::SolanaRpcResponse<u64>> {
|
||||
let decoded = crate::decode_wire_json::<WireEconomicsRpcResponse<u64>>(method, value);
|
||||
let wire = match decoded {
|
||||
std::result::Result::Ok(wire) => wire,
|
||||
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
||||
};
|
||||
let context = crate::SolanaRpcContext::decode_wire(method, wire.context);
|
||||
return match context {
|
||||
std::result::Result::Ok(context) => std::result::Result::Ok(crate::SolanaRpcResponse::new(context, wire.value)),
|
||||
std::result::Result::Err(error) => std::result::Result::Err(error),
|
||||
};
|
||||
}
|
||||
|
||||
fn decode_supply_response(method: &str, value: serde_json::Value) -> ksp_core_lib::Result<crate::SolanaRpcResponse<crate::SolanaSupply>> {
|
||||
let decoded = crate::decode_wire_json::<WireEconomicsRpcResponse<serde_json::Value>>(method, value);
|
||||
let wire = match decoded {
|
||||
std::result::Result::Ok(wire) => wire,
|
||||
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
||||
};
|
||||
let context = crate::SolanaRpcContext::decode_wire(method, wire.context);
|
||||
let context = match context {
|
||||
std::result::Result::Ok(context) => context,
|
||||
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
||||
};
|
||||
let supply = crate::SolanaSupply::decode_wire(method, wire.value);
|
||||
return match supply {
|
||||
std::result::Result::Ok(supply) => std::result::Result::Ok(crate::SolanaRpcResponse::new(context, supply)),
|
||||
std::result::Result::Err(error) => std::result::Result::Err(error),
|
||||
};
|
||||
}
|
||||
|
||||
fn economics_descriptor(method: &str) -> ksp_core_lib::Result<&'static crate::HttpRpcMethodDescriptor> {
|
||||
let descriptor = crate::find_http_rpc_method(method);
|
||||
return match descriptor {
|
||||
std::option::Option::Some(descriptor)
|
||||
if descriptor.category() == crate::HttpRpcCategory::Economics && descriptor.coverage_release() == crate::HttpRpcCoverageRelease::V0_2_4 =>
|
||||
{
|
||||
std::result::Result::Ok(descriptor)
|
||||
},
|
||||
_ => std::result::Result::Err(
|
||||
ksp_core_lib::Error::new(crate::ERROR_CODE_INVALID_RESPONSE, "typed Economics descriptor is missing from the audited 0.2.4 registry")
|
||||
.with_context("rpc_method", method),
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
struct WireEconomicsRpcResponse<T> {
|
||||
context: serde_json::Value,
|
||||
value: T,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct WireInflationGovernor {
|
||||
@@ -350,7 +490,6 @@ struct WireInflationGovernor {
|
||||
foundation_term: f64,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[derive(serde::Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct WireInflationRate {
|
||||
@@ -374,7 +513,6 @@ struct WireInflationReward {
|
||||
commission_bps: crate::SolanaWireField<u16>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[derive(serde::Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct WireSupply {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-onchain-transport-lib/tests/public_api.rs
|
||||
// version: 20
|
||||
// version: 21
|
||||
|
||||
//! Integration tests for the public `ksp-onchain-transport-lib` consumer contract.
|
||||
|
||||
@@ -435,3 +435,18 @@ fn public_v0_2_4_pre_006_get_block_complete_request_forms_are_available_from_cra
|
||||
assert_eq!(config.max_supported_transaction_version(), std::option::Option::Some(1));
|
||||
assert_eq!(config.rewards(), std::option::Option::Some(true));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn public_v0_2_4_pre_007_simple_economics_wrappers_are_available_from_crate_root() {
|
||||
let _get_inflation_governor = ksp_onchain_transport_lib::HttpTransportPool::get_inflation_governor;
|
||||
let _get_inflation_rate = ksp_onchain_transport_lib::HttpTransportPool::get_inflation_rate;
|
||||
let _get_stake_minimum_delegation = ksp_onchain_transport_lib::HttpTransportPool::get_stake_minimum_delegation;
|
||||
let _get_supply = ksp_onchain_transport_lib::HttpTransportPool::get_supply;
|
||||
|
||||
let supply_config = ksp_onchain_transport_lib::SolanaSupplyConfig::new(
|
||||
std::option::Option::Some(ksp_onchain_transport_lib::SolanaCommitment::Processed),
|
||||
std::option::Option::Some(false),
|
||||
);
|
||||
assert_eq!(supply_config.commitment(), std::option::Option::Some(ksp_onchain_transport_lib::SolanaCommitment::Processed));
|
||||
assert_eq!(supply_config.exclude_non_circulating_accounts_list(), std::option::Option::Some(false));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-onchain-transport-lib/tests/release_completeness.rs
|
||||
// version: 18
|
||||
// version: 19
|
||||
|
||||
//! Release-level completeness canaries for the staged HTTP wrapper sequence.
|
||||
|
||||
@@ -563,3 +563,29 @@ fn release_v0_2_4_pre_006_get_block_completes_all_ten_block_wrappers_with_legacy
|
||||
let get_block = ksp_onchain_transport_lib::find_http_rpc_method("getBlock").expect("getBlock descriptor must exist");
|
||||
assert!(get_block.request_form_status().has_deprecated_legacy());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn release_v0_2_4_pre_007_simple_economics_subset_is_exact_and_retry_safe() {
|
||||
let mut expected = std::vec!["getInflationGovernor", "getInflationRate", "getStakeMinimumDelegation", "getSupply"];
|
||||
let mut actual = std::vec::Vec::new();
|
||||
for descriptor in ksp_onchain_transport_lib::current_http_rpc_methods() {
|
||||
if descriptor.coverage_release() != ksp_onchain_transport_lib::HttpRpcCoverageRelease::V0_2_4
|
||||
|| descriptor.category() != ksp_onchain_transport_lib::HttpRpcCategory::Economics
|
||||
{
|
||||
continue;
|
||||
}
|
||||
assert!(matches!(
|
||||
descriptor.method(),
|
||||
"getInflationGovernor" | "getInflationRate" | "getInflationReward" | "getStakeMinimumDelegation" | "getSupply"
|
||||
));
|
||||
if descriptor.method() != "getInflationReward" {
|
||||
assert_eq!(descriptor.operation_kind(), ksp_onchain_transport_lib::RpcOperationKind::Read);
|
||||
assert_eq!(descriptor.transport_retry_class(), ksp_onchain_transport_lib::TransportRetryClass::RetrySafe);
|
||||
actual.push(descriptor.method());
|
||||
}
|
||||
}
|
||||
actual.sort_unstable();
|
||||
expected.sort_unstable();
|
||||
assert_eq!(actual, expected);
|
||||
assert_eq!(actual.len(), 4);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-onchain-transport-lib/unit_tests/rpc_economics.rs
|
||||
// version: 1
|
||||
// version: 2
|
||||
|
||||
#[test]
|
||||
fn inflation_reward_config_preserves_epoch_commitment_and_min_context_slot() {
|
||||
@@ -84,3 +84,226 @@ fn supply_rejects_invalid_non_circulating_pubkey_without_echoing_value() {
|
||||
assert_eq!(error.code(), crate::ERROR_CODE_INVALID_RESPONSE);
|
||||
assert!(!error.to_string().contains("invalid-pubkey"));
|
||||
}
|
||||
|
||||
fn pool_for_url(url: &str) -> crate::HttpTransportPool {
|
||||
let role = crate::HttpEndpointRoleSettings::new(
|
||||
crate::HttpRoleName::new("default"),
|
||||
true,
|
||||
std::vec![crate::HttpRequestKind::wildcard()],
|
||||
10,
|
||||
crate::HttpRoleLimits::new(std::option::Option::None, std::option::Option::None, std::option::Option::None, std::option::Option::None),
|
||||
);
|
||||
let endpoint = crate::HttpEndpointSettings::new(
|
||||
"fixture",
|
||||
true,
|
||||
crate::HttpProviderName::new("fixture"),
|
||||
crate::HttpClusterName::new("local"),
|
||||
crate::HttpEndpointUrl::parse(url).expect("fixture URL must parse"),
|
||||
std::time::Duration::from_secs(1),
|
||||
std::time::Duration::from_secs(1),
|
||||
std::option::Option::Some(1),
|
||||
std::vec![role],
|
||||
);
|
||||
let settings = crate::HttpTransportSettings::new(
|
||||
std::vec![endpoint],
|
||||
crate::HttpRetrySettings::new(0, std::time::Duration::from_millis(1), std::time::Duration::from_millis(1)),
|
||||
);
|
||||
return crate::HttpTransportPool::new(settings).expect("fixture pool must build");
|
||||
}
|
||||
|
||||
fn serve_once(body: &'static str) -> (std::string::String, std::thread::JoinHandle<std::string::String>) {
|
||||
let listener = std::net::TcpListener::bind("127.0.0.1:0").expect("fixture listener must bind");
|
||||
let address = listener.local_addr().expect("fixture listener address must resolve");
|
||||
let handle = std::thread::spawn(move || {
|
||||
let (mut stream, _) = listener.accept().expect("fixture server must accept one request");
|
||||
let request = read_request(&mut stream);
|
||||
let response = format!("HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{}", body.len(), body);
|
||||
std::io::Write::write_all(&mut stream, response.as_bytes()).expect("fixture response must write");
|
||||
return request;
|
||||
});
|
||||
return (format!("http://{address}"), handle);
|
||||
}
|
||||
|
||||
fn read_request(stream: &mut std::net::TcpStream) -> std::string::String {
|
||||
let mut bytes = std::vec::Vec::new();
|
||||
let mut buffer = [0_u8; 1024];
|
||||
loop {
|
||||
let count = std::io::Read::read(stream, &mut buffer).expect("fixture request must read");
|
||||
if count == 0 {
|
||||
break;
|
||||
}
|
||||
bytes.extend_from_slice(&buffer[..count]);
|
||||
if request_complete(bytes.as_slice()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return std::string::String::from_utf8(bytes).expect("fixture request must be UTF-8");
|
||||
}
|
||||
|
||||
fn request_complete(bytes: &[u8]) -> bool {
|
||||
let text = match std::str::from_utf8(bytes) {
|
||||
std::result::Result::Ok(text) => text,
|
||||
std::result::Result::Err(_) => return false,
|
||||
};
|
||||
let header_end = match text.find("\r\n\r\n") {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return false,
|
||||
};
|
||||
let mut content_length = 0_usize;
|
||||
for line in text[..header_end].lines() {
|
||||
let (name, value) = match line.split_once(':') {
|
||||
std::option::Option::Some(parts) => parts,
|
||||
std::option::Option::None => continue,
|
||||
};
|
||||
if name.eq_ignore_ascii_case("content-length") {
|
||||
content_length = value.trim().parse::<usize>().expect("content length must parse");
|
||||
}
|
||||
}
|
||||
return bytes.len() >= header_end.saturating_add(4).saturating_add(content_length);
|
||||
}
|
||||
|
||||
fn request_body(request: &str) -> serde_json::Value {
|
||||
let body = request.split("\r\n\r\n").nth(1).expect("fixture request body must exist");
|
||||
return serde_json::from_str(body).expect("fixture request body must be JSON");
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn typed_get_inflation_governor_serializes_processed_commitment_and_preserves_runtime_values() {
|
||||
let (url, handle) = serve_once(include_str!("../fixtures/http/get_inflation_governor.success.json"));
|
||||
let pool = pool_for_url(url.as_str());
|
||||
let config = crate::SolanaCommitmentConfig::new(std::option::Option::Some(crate::SolanaCommitment::Processed));
|
||||
let governor = pool
|
||||
.get_inflation_governor(&crate::HttpRoleName::new("default"), std::option::Option::Some(&config))
|
||||
.await
|
||||
.expect("inflation governor fixture must succeed");
|
||||
assert_eq!(governor.initial(), 0.07123456789);
|
||||
assert_eq!(governor.terminal(), 0.0123456789);
|
||||
assert_eq!(governor.taper(), 0.2718281828);
|
||||
assert_eq!(governor.foundation(), 0.0042);
|
||||
assert_eq!(governor.foundation_term(), 6.25);
|
||||
let request = handle.join().expect("fixture server must join");
|
||||
let body = request_body(request.as_str());
|
||||
assert_eq!(body["method"], serde_json::json!("getInflationGovernor"));
|
||||
assert_eq!(body["params"], serde_json::json!([{"commitment":"processed"}]));
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn typed_get_inflation_governor_omits_absent_and_empty_config() {
|
||||
let role = crate::HttpRoleName::new("default");
|
||||
let empty = crate::SolanaCommitmentConfig::default();
|
||||
for config in [std::option::Option::None, std::option::Option::Some(&empty)] {
|
||||
let (url, handle) = serve_once(include_str!("../fixtures/http/get_inflation_governor.success.json"));
|
||||
let pool = pool_for_url(url.as_str());
|
||||
pool.get_inflation_governor(&role, config).await.expect("inflation governor fixture must succeed");
|
||||
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_rate_has_no_params_and_preserves_runtime_values() {
|
||||
let (url, handle) = serve_once(include_str!("../fixtures/http/get_inflation_rate.success.json"));
|
||||
let pool = pool_for_url(url.as_str());
|
||||
let rate = pool.get_inflation_rate(&crate::HttpRoleName::new("default")).await.expect("inflation rate fixture must succeed");
|
||||
assert_eq!(rate.total(), 0.0387654321);
|
||||
assert_eq!(rate.validator(), 0.037654321);
|
||||
assert_eq!(rate.foundation(), 0.0011111111);
|
||||
assert_eq!(rate.epoch(), 913);
|
||||
let request = handle.join().expect("fixture server must join");
|
||||
let body = request_body(request.as_str());
|
||||
assert_eq!(body["method"], serde_json::json!("getInflationRate"));
|
||||
assert_eq!(body["params"], serde_json::json!([]));
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn typed_get_stake_minimum_delegation_preserves_context_and_runtime_value_without_local_minimum() {
|
||||
let (url, handle) = serve_once(include_str!("../fixtures/http/get_stake_minimum_delegation.success.json"));
|
||||
let pool = pool_for_url(url.as_str());
|
||||
let config = crate::SolanaContextConfig::new(std::option::Option::Some(crate::SolanaCommitment::Processed), std::option::Option::Some(431_000_000));
|
||||
let result = pool
|
||||
.get_stake_minimum_delegation(&crate::HttpRoleName::new("default"), std::option::Option::Some(&config))
|
||||
.await
|
||||
.expect("stake minimum delegation fixture must succeed");
|
||||
assert_eq!(*result.value(), 42_424_242);
|
||||
assert_eq!(result.context().slot(), 431_000_123);
|
||||
assert_eq!(result.context().api_version(), std::option::Option::Some("4.2.1"));
|
||||
let request = handle.join().expect("fixture server must join");
|
||||
assert_eq!(request_body(request.as_str())["params"], serde_json::json!([{"commitment":"processed","minContextSlot":431000000}]));
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn typed_get_stake_minimum_delegation_omits_absent_and_empty_config() {
|
||||
let role = crate::HttpRoleName::new("default");
|
||||
let empty = crate::SolanaContextConfig::default();
|
||||
for config in [std::option::Option::None, std::option::Option::Some(&empty)] {
|
||||
let (url, handle) = serve_once(include_str!("../fixtures/http/get_stake_minimum_delegation.success.json"));
|
||||
let pool = pool_for_url(url.as_str());
|
||||
pool.get_stake_minimum_delegation(&role, config).await.expect("stake minimum delegation fixture must succeed");
|
||||
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_supply_preserves_explicit_false_full_account_list_and_context() {
|
||||
let (url, handle) = serve_once(include_str!("../fixtures/http/get_supply.success.json"));
|
||||
let pool = pool_for_url(url.as_str());
|
||||
let config = crate::SolanaSupplyConfig::new(std::option::Option::Some(crate::SolanaCommitment::Processed), std::option::Option::Some(false));
|
||||
let result = pool.get_supply(&crate::HttpRoleName::new("default"), std::option::Option::Some(&config)).await.expect("supply fixture must succeed");
|
||||
assert_eq!(result.context().slot(), 431_000_124);
|
||||
assert_eq!(result.value().total(), 610_000_000_000_000_000);
|
||||
assert_eq!(result.value().circulating(), 510_000_000_000_000_000);
|
||||
assert_eq!(result.value().non_circulating(), 100_000_000_000_000_000);
|
||||
assert_eq!(result.value().non_circulating_accounts().len(), 2);
|
||||
let request = handle.join().expect("fixture server must join");
|
||||
assert_eq!(request_body(request.as_str())["params"], serde_json::json!([{"commitment":"processed","excludeNonCirculatingAccountsList":false}]));
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn typed_get_supply_preserves_explicit_true_as_empty_runtime_account_list() {
|
||||
let (url, handle) = serve_once(include_str!("../fixtures/http/get_supply.excluded.success.json"));
|
||||
let pool = pool_for_url(url.as_str());
|
||||
let config = crate::SolanaSupplyConfig::new(std::option::Option::None, std::option::Option::Some(true));
|
||||
let result = pool
|
||||
.get_supply(&crate::HttpRoleName::new("default"), std::option::Option::Some(&config))
|
||||
.await
|
||||
.expect("excluded supply fixture must succeed");
|
||||
assert_eq!(result.value().non_circulating_accounts(), &[]);
|
||||
assert_eq!(result.value().non_circulating(), 100_000_000_000_000_000);
|
||||
let request = handle.join().expect("fixture server must join");
|
||||
assert_eq!(request_body(request.as_str())["params"], serde_json::json!([{"excludeNonCirculatingAccountsList":true}]));
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn typed_get_supply_omits_absent_and_empty_config() {
|
||||
let role = crate::HttpRoleName::new("default");
|
||||
let empty = crate::SolanaSupplyConfig::default();
|
||||
for config in [std::option::Option::None, std::option::Option::Some(&empty)] {
|
||||
let (url, handle) = serve_once(include_str!("../fixtures/http/get_supply.success.json"));
|
||||
let pool = pool_for_url(url.as_str());
|
||||
pool.get_supply(&role, config).await.expect("supply fixture must succeed");
|
||||
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_stake_minimum_delegation_preserves_min_context_slot_rpc_error() {
|
||||
let (url, handle) = serve_once(include_str!("../fixtures/http/get_stake_minimum_delegation.error_min_context.json"));
|
||||
let pool = pool_for_url(url.as_str());
|
||||
let config = crate::SolanaContextConfig::new(std::option::Option::None, std::option::Option::Some(431_000_000));
|
||||
let result = pool.get_stake_minimum_delegation(&crate::HttpRoleName::new("default"), std::option::Option::Some(&config)).await;
|
||||
let error = result.expect_err("min-context-slot 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_supply_preserves_scan_rpc_error() {
|
||||
let (url, handle) = serve_once(include_str!("../fixtures/http/get_supply.error_scan.json"));
|
||||
let pool = pool_for_url(url.as_str());
|
||||
let result = pool.get_supply(&crate::HttpRoleName::new("default"), std::option::Option::None).await;
|
||||
let error = result.expect_err("supply scan 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