diff --git a/.github/workflows/ic-ref.yml b/.github/workflows/ic-ref.yml index eb94f4ef..d865e1a6 100644 --- a/.github/workflows/ic-ref.yml +++ b/.github/workflows/ic-ref.yml @@ -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 diff --git a/ic-agent/src/agent/response_authentication.rs b/ic-agent/src/agent/response_authentication.rs index 3f252f6b..4a50a18b 100644 --- a/ic-agent/src/agent/response_authentication.rs +++ b/ic-agent/src/agent/response_authentication.rs @@ -108,11 +108,12 @@ pub(crate) fn lookup_rejection>( ) -> Result { 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, })) } @@ -144,6 +145,23 @@ pub(crate) fn lookup_reject_message>( Ok(from_utf8(msg)?.to_string()) } +pub(crate) fn lookup_error_code>( + certificate: &Certificate, + request_id: &RequestId, +) -> Result, 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>( certificate: &Certificate, request_id: &RequestId, diff --git a/ref-tests/tests/ic-ref.rs b/ref-tests/tests/ic-ref.rs index b0ab8b5e..edb371cf 100644 --- a/ref-tests/tests/ic-ref.rs +++ b/ref-tests/tests/ic-ref.rs @@ -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:?}" ); @@ -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( @@ -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:?}" ); diff --git a/ref-tests/tests/integration.rs b/ref-tests/tests/integration.rs index b026c206..17127112 100644 --- a/ref-tests/tests/integration.rs +++ b/ref-tests/tests/integration.rs @@ -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:?}" );