Skip to content

Commit

Permalink
Merge branch 'main' into spofford/0.33.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lwshang authored Feb 20, 2024
2 parents 0b4486b + f5ce76b commit 6d22ffe
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
dfx: [ '0.8.4', '0.9.2', '0.10.1', '0.11.1' ]

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Cache Cargo
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/fmt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
os: [ubuntu-latest]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Cache Cargo
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/ic-ref.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ jobs:
os: ubuntu-latest

steps:
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 16
node-version: 20

- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Install dfx
uses: dfinity/setup-dfx@main
with:
dfx-version: "0.15.3-largewasm.0"
dfx-version: "0.16.1"

- name: Cargo cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ jobs:
os: [ubuntu-latest]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: actions/cache@v2
- uses: actions/cache@v4
with:
path: |
~/.cargo/registry
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/netlify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: actions/cache@v2
- uses: actions/cache@v4
with:
path: |
~/.cargo/registry
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
binary_path: target/x86_64-apple-darwin/release
binary_files: icx
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v4

- name: Setup environment variables
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
# ubuntu-latest has shellcheck 0.4.6, while macos-latest has 0.7.1
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Install shellcheck
run: |
mkdir $HOME/bin
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: actions/cache@v2
- uses: actions/cache@v4
with:
path: |
~/.cargo/registry
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Changed the return type of `stored_chunks` to a struct.
* Added a prime256v1-based `Identity` impl to complement the ed25519 and secp256k1 `Identity` impls.
* Added serde and candid serialization traits to the `Status` type.
* Changed the type of `InstallMode.skip_pre_upgrade` from `bool` to `Option<bool>` to match the interface specification.

## [0.32.0] - 2024-01-18

Expand Down
1 change: 1 addition & 0 deletions ic-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ web-sys = { version = "0.3", features = ["Window"], optional = true }

[dev-dependencies]
serde_json = "1.0.79"
candid = { workspace = true, features = ["value"]}

[target.'cfg(not(target_family = "wasm"))'.dev-dependencies]
tokio = { version = "1.24.2", features = ["full"] }
Expand Down
49 changes: 47 additions & 2 deletions ic-agent/src/agent/status.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
//! Types for interacting with the status endpoint of a replica. See [`Status`] for details.
use candid::{CandidType, Deserialize};
use serde::Serialize;
use std::{collections::BTreeMap, fmt::Debug};

/// Value returned by the status endpoint of a replica. This is a loose mapping to CBOR values.
/// Because the agent should not return [`serde_cbor::Value`] directly across API boundaries,
/// we reimplement it as [`Value`] here.
#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Clone, Hash)]
#[derive(
Debug, Ord, PartialOrd, Eq, PartialEq, Clone, Hash, CandidType, Serialize, Deserialize,
)]
pub enum Value {
/// See [`Null`](serde_cbor::Value::Null).
Null,
Expand Down Expand Up @@ -40,7 +44,7 @@ impl std::fmt::Display for Value {

/// The structure returned by [`super::Agent::status`], containing the information returned
/// by the status endpoint of a replica.
#[derive(Debug, Ord, PartialOrd, PartialEq, Eq)]
#[derive(Debug, Ord, PartialOrd, PartialEq, Eq, CandidType, Deserialize, Serialize)]
pub struct Status {
/// Optional. The precise git revision of the Internet Computer Protocol implementation.
pub impl_version: Option<String>,
Expand All @@ -55,6 +59,47 @@ pub struct Status {
pub values: BTreeMap<String, Box<Value>>,
}

#[test]
fn can_serilaize_status_as_json() {
let status = Status {
impl_version: None,
replica_health_status: None,
root_key: None,
values: BTreeMap::new(),
};
let expected_json =
r#"{"impl_version":null,"replica_health_status":null,"root_key":null,"values":{}}"#;
let actual_json = serde_json::to_string(&status).expect("Failed to serialize as JSON");
assert_eq!(expected_json, actual_json);
}
#[test]
fn can_serialize_status_as_idl() {
use candid::types::value::IDLValue;
use candid::{Encode, IDLArgs, Result as CandidResult, TypeEnv};
let status = Status {
impl_version: Some("Foo".to_string()),
replica_health_status: None,
root_key: None,
values: BTreeMap::new(),
};
// Expresses data as IDLValue. Then use .to_string() to convert to text-form candid.
// TODO: This function has been added to the Candid library and will be available in the next
// release. Then, this definition here can be deleted.
pub fn try_from_candid_type<T>(data: &T) -> CandidResult<IDLValue>
where
T: CandidType,
{
let blob = Encode!(data)?;
let args = IDLArgs::from_bytes_with_types(&blob, &TypeEnv::default(), &[T::ty()])?;
Ok(args.args[0].clone())
}
let expected_idl = "record {\n values = vec {};\n replica_health_status = null;\n impl_version = opt \"Foo\";\n root_key = null;\n}";
let actual_idl = try_from_candid_type(&status)
.expect("Failed to convert to idl")
.to_string();
assert_eq!(expected_idl, actual_idl);
}

impl std::fmt::Display for Status {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("{\n")?;
Expand Down
6 changes: 3 additions & 3 deletions ic-utils/src/interfaces/management_canister/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct CanisterSettings {
pub controllers: Option<Vec<Principal>>,
/// The allocation percentage (between 0 and 100 inclusive) for *guaranteed* compute capacity.
///
/// The settings update will be rejected if the IC can't commit to allocating this much compupte capacity.
/// The settings update will be rejected if the IC can't commit to allocating this much compute capacity.
///
/// If unspecified and a canister is being created with these settings, defaults to 0, i.e. best-effort.
pub compute_allocation: Option<Nat>,
Expand Down Expand Up @@ -392,7 +392,7 @@ pub enum InstallMode {
#[serde(rename = "upgrade")]
Upgrade {
/// If true, skip a canister's `#[pre_upgrade]` function.
skip_pre_upgrade: bool,
skip_pre_upgrade: Option<bool>,
},
}

Expand All @@ -419,7 +419,7 @@ impl FromStr for InstallMode {
"install" => Ok(InstallMode::Install),
"reinstall" => Ok(InstallMode::Reinstall),
"upgrade" => Ok(InstallMode::Upgrade {
skip_pre_upgrade: false,
skip_pre_upgrade: Some(false),
}),
&_ => Err(format!("Invalid install mode: {}", s)),
}
Expand Down
6 changes: 3 additions & 3 deletions ref-tests/tests/ic-ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ mod management_canister {
// Upgrade should succeed.
ic00.install_code(&canister_id, &canister_wasm)
.with_mode(InstallMode::Upgrade {
skip_pre_upgrade: false,
skip_pre_upgrade: None,
})
.call_and_wait()
.await?;
Expand All @@ -171,7 +171,7 @@ mod management_canister {
let result = other_ic00
.install_code(&canister_id, &canister_wasm)
.with_mode(InstallMode::Upgrade {
skip_pre_upgrade: false,
skip_pre_upgrade: None,
})
.call_and_wait()
.await;
Expand Down Expand Up @@ -486,7 +486,7 @@ mod management_canister {
// Upgrade should succeed
ic00.install_code(&canister_id, &canister_wasm)
.with_mode(InstallMode::Upgrade {
skip_pre_upgrade: false,
skip_pre_upgrade: None,
})
.call_and_wait()
.await?;
Expand Down

0 comments on commit 6d22ffe

Please sign in to comment.