Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove fields in expected status endpoint response #485

Merged
merged 2 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Added `read_state_subnet_metrics` to `Agent` to access subnet metrics, such as total spent cycles.
* Types passed to the `to_request_id` function can now contain nested structs, signed integers, and externally tagged enums.
* `Envelope` struct is public also outside of the crate.
* Remove non-optional `ic_api_version` field (whose value is not meaningfully populated by the replica) and optional `impl_source` and `impl_revision` fields (that are not populated by the replica) from the expected `/api/v2/status` endpoint response.

## [0.29.0] - 2023-09-29

Expand Down
15 changes: 3 additions & 12 deletions ic-agent/src/agent/agent_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,7 @@ async fn call_rejected_without_error_code() -> Result<(), AgentError> {
#[cfg_attr(not(target_family = "wasm"), tokio::test)]
#[cfg_attr(target_family = "wasm", wasm_bindgen_test)]
async fn status() -> Result<(), AgentError> {
let ic_api_version = "1.2.3".to_string();
let mut map = BTreeMap::new();
map.insert(
serde_cbor::Value::Text("ic_api_version".to_owned()),
serde_cbor::Value::Text(ic_api_version.clone()),
);
let map = BTreeMap::new();
let response = serde_cbor::Value::Map(map);
let (read_mock, url) = mock(
"GET",
Expand All @@ -248,19 +243,15 @@ async fn status() -> Result<(), AgentError> {
let result = agent.status().await;

assert_mock(read_mock).await;
assert!(matches!(result, Ok(Status { ic_api_version: v, .. }) if v == ic_api_version));
assert!(matches!(result, Ok(Status { .. })));

Ok(())
}

#[cfg_attr(not(target_family = "wasm"), tokio::test)]
#[cfg_attr(target_family = "wasm", wasm_bindgen_test)]
async fn status_okay() -> Result<(), AgentError> {
let mut map = BTreeMap::new();
map.insert(
serde_cbor::Value::Text("ic_api_version".to_owned()),
serde_cbor::Value::Text("1.2.3".to_owned()),
);
let map = BTreeMap::new();
let response = serde_cbor::Value::Map(map);
let (read_mock, url) = mock(
"GET",
Expand Down
42 changes: 1 addition & 41 deletions ic-agent/src/agent/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,9 @@ impl std::fmt::Display for Value {
/// by the status endpoint of a replica.
#[derive(Debug, Ord, PartialOrd, PartialEq, Eq)]
pub struct Status {
/// Identifies the interface version supported, i.e. the version of the present document that
/// the internet computer aims to support, e.g. 0.8.1. The implementation may also return
/// unversioned to indicate that it does not comply to a particular version, e.g. in between
/// releases.
pub ic_api_version: String,

/// Optional. Identifies the implementation of the Internet Computer, by convention with the
/// canonical location of the source code.
pub impl_source: Option<String>,

/// Optional. If the user is talking to a released version of an Internet Computer
/// implementation, this is the version number. For non-released versions, output of
/// `git describe` like 0.1.13-13-g2414721 would also be very suitable.
/// Optional. The precise git revision of the Internet Computer Protocol implementation.
pub impl_version: Option<String>,

/// Optional. The precise git revision of the Internet Computer implementation.
pub impl_revision: Option<String>,

/// Optional. The health status of the replica. One hopes it's "healthy".
pub replica_health_status: Option<String>,

Expand Down Expand Up @@ -121,35 +106,13 @@ impl std::convert::TryFrom<&serde_cbor::Value> for Status {

match v {
Value::Map(map) => {
// This field is not optional.
let ic_api_version = map.get("ic_api_version").ok_or(()).and_then(|v| {
if let Value::String(s) = v.as_ref() {
Ok(s.to_owned())
} else {
Err(())
}
})?;
let impl_source = map.get("impl_source").and_then(|v| {
if let Value::String(s) = v.as_ref() {
Some(s.to_owned())
} else {
None
}
});
let impl_version: Option<String> = map.get("impl_version").and_then(|v| {
if let Value::String(s) = v.as_ref() {
Some(s.to_owned())
} else {
None
}
});
let impl_revision: Option<String> = map.get("impl_revision").and_then(|v| {
if let Value::String(s) = v.as_ref() {
Some(s.to_owned())
} else {
None
}
});
let replica_health_status: Option<String> =
map.get("replica_health_status").and_then(|v| {
if let Value::String(s) = v.as_ref() {
Expand All @@ -167,10 +130,7 @@ impl std::convert::TryFrom<&serde_cbor::Value> for Status {
});

Ok(Status {
ic_api_version,
impl_source,
impl_version,
impl_revision,
replica_health_status,
root_key,
values: map,
Expand Down
14 changes: 0 additions & 14 deletions ref-tests/tests/ic-ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
//! use case being tested).
use ref_tests::{universal_canister, with_agent};

const EXPECTED_IC_API_VERSION: &str = "0.18.0";

#[ignore]
#[test]
fn status_endpoint() {
Expand All @@ -24,18 +22,6 @@ fn status_endpoint() {
})
}

#[ignore]
#[test]
fn spec_compliance_claimed() {
with_agent(|agent| async move {
let status = agent.status().await?;

assert_eq!(status.ic_api_version, EXPECTED_IC_API_VERSION);

Ok(())
});
}

mod management_canister {
use candid::CandidType;
use ic_agent::{
Expand Down
Loading