candiff::Value::from_str fails to parse exported service
I recently added the following to my own project:
https://github.com/dfinity/cdk-rs/blob/d823c7c5bb2a3b07c13e2210239e74a15669ba59/src/ic-certified-assets/src/lib.rs#L214-L232
This works well, but I made a lot of changes and now the test is failing. I’ve manually gone over it for a while and still can’t spot why.
So, I turned to candiff:
#[test]
fn candid_interface_compatibility() {
use ic_cdk::export::candid::utils::{service_compatible, CandidSource};
use std::path::PathBuf;
use std::str::FromStr;
ic_cdk::export::candid::export_service!();
let exported_interface = __export_service();
let on_disk_interface =
PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()).join("src/myproject.did");
let exported =
candiff::Value::from_str(&exported_interface).expect("Failed to parse exported interface");
let on_disk =
candiff::Value::from_str(&exported_interface).expect("Failed to parse on disk interface"); // FIXME
let diff = candiff::value_diff(&exported, &on_disk, &None);
println!("{}", candiff::pretty::value_edit(&diff).pretty(80));
println!("Exported interface: {}", exported_interface);
service_compatible(
CandidSource::Text(&exported_interface),
CandidSource::File(on_disk_interface.as_path()),
)
.expect("The canister interface is not compatible with the .did file");
}
However, this fails with:
thread 'candid_interface_compatibility' panicked at 'Failed to parse exported interface: Parse(UnrecognizedToken { token: (0, Type, 4), expected: ["\"(\"", "\"blob\"", "\"bool\"", "\"decimal\"", "\"float\"", "\"func\"", "\"hex\"", "\"null\"", "\"opt\"", "\"principal\"", "\"record\"", "\"service\"", "\"sign\"", "\"text\"", "\"variant\"", "\"vec\""] })', src/myproject/src/lib.rs:179:55
I’m using ic-cdk = "0.5.0".