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: Add error code to certified rejects #620

Merged
merged 6 commits into from
Dec 20, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/ic-ref.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Install dfx
uses: dfinity/setup-dfx@main
with:
dfx-version: "0.24.2"
dfx-version: "0.24.3"

- name: Cargo cache
uses: actions/cache@v4
Expand Down
20 changes: 19 additions & 1 deletion ic-agent/src/agent/response_authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,12 @@ pub(crate) fn lookup_rejection<Storage: AsRef<[u8]>>(
) -> Result<RequestStatusResponse, AgentError> {
let reject_code = lookup_reject_code(certificate, request_id)?;
let reject_message = lookup_reject_message(certificate, request_id)?;
let error_code = lookup_error_code(certificate, request_id)?;

Ok(RequestStatusResponse::Rejected(RejectResponse {
reject_code,
reject_message,
error_code: None,
error_code,
}))
}

Expand Down Expand Up @@ -144,6 +145,23 @@ pub(crate) fn lookup_reject_message<Storage: AsRef<[u8]>>(
Ok(from_utf8(msg)?.to_string())
}

pub(crate) fn lookup_error_code<Storage: AsRef<[u8]>>(
certificate: &Certificate<Storage>,
request_id: &RequestId,
) -> Result<Option<String>, AgentError> {
let path = [
"request_status".as_bytes(),
request_id.as_slice(),
"error_code".as_bytes(),
];
let msg = lookup_value(&certificate.tree, path);
match msg {
Ok(val) => Ok(Some(from_utf8(val)?.to_string())),
Err(AgentError::LookupPathAbsent(_)) => Ok(None),
Err(e) => Err(e),
}
}

pub(crate) fn lookup_reply<Storage: AsRef<[u8]>>(
certificate: &Certificate<Storage>,
request_id: &RequestId,
Expand Down
9 changes: 5 additions & 4 deletions ref-tests/tests/ic-ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,9 @@ mod management_canister {
Err(AgentError::CertifiedReject(RejectResponse {
reject_code: RejectCode::CanisterError,
reject_message,
error_code: None,
error_code: Some(error_code),
})) if reject_message.contains(&format!("Canister {canister_id}: Canister has no update method 'update'"))
&& error_code == "IC0536"
),
"wrong error: {result:?}"
);
Expand Down Expand Up @@ -739,7 +740,7 @@ mod management_canister {

let args = Argument::from_candid((create_args,));

let creation_fee = 100_000_000_000;
let creation_fee = 500_000_000_000;
let canister_initial_balance = 4_000_000_000;
let (create_result,): (CreateResult,) = wallet
.call(
Expand Down Expand Up @@ -1247,8 +1248,8 @@ mod extras {
Err(AgentError::CertifiedReject(RejectResponse {
reject_code: RejectCode::CanisterError,
reject_message,
error_code: None,
})) if reject_message.contains("Canister iimsn-6yaaa-aaaaa-afiaa-cai is already installed")
error_code: Some(code),
})) if reject_message.contains("Canister iimsn-6yaaa-aaaaa-afiaa-cai is already installed") && code == "IC0538"
),
"wrong error: {result:?}"
);
Expand Down
4 changes: 2 additions & 2 deletions ref-tests/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,12 @@ fn canister_reject_call() {
Err(AgentError::CertifiedReject(RejectResponse {
reject_code: RejectCode::CanisterError,
reject_message,
error_code: None,
error_code: Some(error_code),
..
})) if reject_message.contains(&format!(
"Canister {}: Canister has no update method 'wallet_send'",
alice.canister_id()
))
)) && error_code == "IC0536"
),
"wrong error: {result:?}"
);
Expand Down
Loading