-
Notifications
You must be signed in to change notification settings - Fork 79
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: Add serialization traits to Status #499
Conversation
Note: The cla test is hanging. Is this a known issue? |
ic-agent/Cargo.toml
Outdated
@@ -17,7 +17,7 @@ include = ["src", "Cargo.toml", "../LICENSE", "README.md"] | |||
[dependencies] | |||
backoff = "0.4.0" | |||
cached = { version = "0.46", features = ["ahash"], default-features = false } | |||
candid = { workspace = true } | |||
candid = { workspace = true, features = ["value"] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: I am not super happy about enabling a feature in code that may be used as a library. IDLValue is needed for tests only, but AFAIK there is no way of enabling a feature for tests only. Maybe the test is overkill. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bitdivine maybe you're looking for [dev-dependencies]
, would that work?
https://doc.rust-lang.org/rust-by-example/testing/dev_dependencies.html
https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#development-dependencies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK a different version of a crate can be added to dev-dependencies under an alias, but not the same version of the same crate with a different feature set. But I can try it just to be sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Let me know, I'm curious
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes: Experiment:
- I dropped the "values" feature from the candid dependency.
- I added a the candid crate under an alias in the dev dependencies.
- cargo check complained about the duplicate:
max@sinkpad:~/dfn/agent-rs (14:27)$ git diff
diff --git a/ic-agent/Cargo.toml b/ic-agent/Cargo.toml
index 8308d2b..5b41a89 100644
--- a/ic-agent/Cargo.toml
+++ b/ic-agent/Cargo.toml
@@ -17,7 +17,7 @@ include = ["src", "Cargo.toml", "../LICENSE", "README.md"]
[dependencies]
backoff = "0.4.0"
cached = { version = "0.46", features = ["ahash"], default-features = false }
-candid = { workspace = true, features = ["value"] }
+candid = { workspace = true }
ed25519-consensus = { version = "2" }
futures-util = "0.3.21"
hex = { workspace = true }
@@ -75,6 +75,7 @@ web-sys = { version = "0.3", features = ["Window"], optional = true }
[dev-dependencies]
serde_json = "1.0.79"
+dev_candid = { package = "candid", version = "0.10.0", features = ["value"]}
[target.'cfg(not(target_family = "wasm"))'.dev-dependencies]
tokio = { version = "1.24.2", features = ["full"] }
diff --git a/ic-agent/src/agent/status.rs b/ic-agent/src/agent/status.rs
index e54ea25..a53d2f3 100644
--- a/ic-agent/src/agent/status.rs
+++ b/ic-agent/src/agent/status.rs
@@ -74,8 +74,8 @@ fn can_serilaize_status_as_json() {
}
#[test]
fn can_serialize_status_as_idl() {
- use candid::types::value::IDLValue;
- use candid::{Encode, IDLArgs, Result as CandidResult, TypeEnv};
+ use dev_candid::types::value::IDLValue;
+ use dev_candid::{Encode, IDLArgs, Result as CandidResult, TypeEnv};
let status = Status {
impl_version: Some("Foo".to_string()),
replica_health_status: None,
max@sinkpad:~/dfn/agent-rs (14:29)$
max@sinkpad:~/dfn/agent-rs (14:32)$
max@sinkpad:~/dfn/agent-rs (14:32)$ cargo check
error: the crate `ic-agent v0.31.0 (/home/max/dfn/agent-rs/ic-agent)` depends on crate `candid v0.10.0` multiple times with different names
max@sinkpad:~/dfn/agent-rs (14:38)$
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have looked at the "value" feature and don't really understand the repercussions of adding the feature. It changes some low level behaviour in corner cases. I think that the right answer in this context is to drop the test and not change the feature set. The CandidType and Deserialize traits are pretty well tested elsewhere so it's not likely that they will break here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, I don't have strong opinion about adding value
feature despite not being used in production code... maybe its ok and not worth the hassle to play the cargo here. Was only trying to be helpful ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe silly question, but is it necessary to use the alias?
OOh, cool! I didn't know that was possible. Thanks! Yes, I think that is the way to go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. CI got stuck. All green now apart from cla, which is hanging. Do you know how to un-stick that?
This reverts commit f216c74.
Description
We would like to express the Status response printed by dfx as IDL and/or JSON. This requires corresponding serialization traits to be implemented for Status.
Contributes towards fixing: https://dfinity.atlassian.net/browse/SDK-1319
How Has This Been Tested?
Unit tests are included for serialization to JSON and IDL.
Checklist: