From 3971e9d6b733a2fe5be46be59c9d3eacc31840aa Mon Sep 17 00:00:00 2001 From: Frederico Sabino <3332770+fmrsabino@users.noreply.github.com> Date: Mon, 21 Feb 2022 13:06:41 +0000 Subject: [PATCH] Map 404 to null when verifying trusted delegate (#808) When the contract info is not found (404) the response of the /v1/chains//transactions/ route was mapped to a 404 This changes the mapping of that 404 to a successful case (null) and the transaction data is therefore returned and the response is successful (200) --- src/routes/transactions/converters/details.rs | 11 ++++++- .../transactions/converters/tests/details.rs | 31 +++++++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/routes/transactions/converters/details.rs b/src/routes/transactions/converters/details.rs index aff3ad121..5f970ea85 100644 --- a/src/routes/transactions/converters/details.rs +++ b/src/routes/transactions/converters/details.rs @@ -181,7 +181,16 @@ pub async fn is_trusted_delegate_call( info_provider: &(impl InfoProvider + Sync), ) -> ApiResult> { if operation == &Operation::DELEGATE { - let contract_info = info_provider.contract_info(to).await?; + let contract_info = info_provider.contract_info(to).await; + let contract_info = match contract_info { + Ok(contract_info) => contract_info, + Err(api_error) => { + return match api_error.status { + 404 => Ok(None), + _ => Err(api_error), + }; + } + }; let has_nested_delegate_calls = !data_decoded .as_ref() diff --git a/src/routes/transactions/converters/tests/details.rs b/src/routes/transactions/converters/tests/details.rs index 9d1f4d126..8e8271330 100644 --- a/src/routes/transactions/converters/tests/details.rs +++ b/src/routes/transactions/converters/tests/details.rs @@ -462,7 +462,7 @@ async fn is_trusted_delegate_with_delegate() { } #[rocket::async_test] -async fn is_trusted_delegate_with_contract_request_failure() { +async fn is_trusted_delegate_with_contract_request_404() { let data_decoded = serde_json::from_str::(crate::tests::json::DATA_DECODED_MULTI_SEND).unwrap(); let mut mock_info_provider = MockInfoProvider::new(); @@ -485,10 +485,37 @@ async fn is_trusted_delegate_with_contract_request_failure() { ) .await; + assert_eq!(actual.unwrap(), None); +} + +#[rocket::async_test] +async fn is_trusted_delegate_with_contract_request_failure() { + let data_decoded = + serde_json::from_str::(crate::tests::json::DATA_DECODED_MULTI_SEND).unwrap(); + let mut mock_info_provider = MockInfoProvider::new(); + mock_info_provider + .expect_contract_info() + .with(eq("0x1230B3d59858296A31053C1b8562Ecf89A2f888b")) + .times(1) + .return_once(move |_| { + Err(ApiError::from_http_response(&Response { + body: String::new(), + status_code: 500, + })) + }); + + let actual = is_trusted_delegate_call( + &Operation::DELEGATE, + "0x1230B3d59858296A31053C1b8562Ecf89A2f888b", + &Some(data_decoded), + &mock_info_provider, + ) + .await; + assert_eq!( actual.unwrap_err(), ApiError { - status: 404, + status: 500, details: ErrorDetails { code: 1337, message: Some("".to_string()),