Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Commit

Permalink
Map 404 to null when verifying trusted delegate (#808)
Browse files Browse the repository at this point in the history
When the contract info is not found (404) the response of the /v1/chains/<chain_id>/transactions/<tx_id> 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)
  • Loading branch information
fmrsabino authored Feb 21, 2022
1 parent dcbaa76 commit 3971e9d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/routes/transactions/converters/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,16 @@ pub async fn is_trusted_delegate_call(
info_provider: &(impl InfoProvider + Sync),
) -> ApiResult<Option<bool>> {
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()
Expand Down
31 changes: 29 additions & 2 deletions src/routes/transactions/converters/tests/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<DataDecoded>(crate::tests::json::DATA_DECODED_MULTI_SEND).unwrap();
let mut mock_info_provider = MockInfoProvider::new();
Expand All @@ -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::<DataDecoded>(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()),
Expand Down

0 comments on commit 3971e9d

Please sign in to comment.