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

Commit

Permalink
Merge pull request #799 from gnosis/fix-contract-error-mapping
Browse files Browse the repository at this point in the history
Map contracts endpoint error to ApiResult
  • Loading branch information
fmrsabino authored Feb 14, 2022
2 parents cc07a61 + 4167410 commit 8738367
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "safe-client-gateway"
version = "3.16.0"
version = "3.16.1"
authors = ["jpalvarezl <[email protected]>", "rmeissner <[email protected]>", "fmrsabino <[email protected]>"]
edition = "2018"

Expand Down
31 changes: 15 additions & 16 deletions src/routes/transactions/converters/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ impl MultisigTransaction {
&self.safe_transaction.data_decoded,
info_provider,
)
.await;
.await?;

Ok(TransactionDetails {
safe_address: self.safe_transaction.safe.to_owned(),
tx_id: self.generate_id(),
Expand Down Expand Up @@ -141,7 +142,8 @@ impl ModuleTransaction {
&safe_transaction.data_decoded,
info_provider,
)
.await;
.await?;

Ok(TransactionDetails {
safe_address: self.safe_transaction.safe.to_owned(),
tx_id: self.generate_id(),
Expand Down Expand Up @@ -177,21 +179,18 @@ pub async fn is_trusted_delegate_call(
to: &str,
data_decoded: &Option<DataDecoded>,
info_provider: &(impl InfoProvider + Sync),
) -> Option<bool> {
) -> ApiResult<Option<bool>> {
if operation == &Operation::DELEGATE {
info_provider
.contract_info(to)
.await
.map(|contract_info| {
// In the case of a known `multiSend` method call, we can still have internal transactions with DELEGATE calls
// which is why we only check when `trusted_for_delegate_call = true`
contract_info.trusted_for_delegate_call
&& !data_decoded
.as_ref()
.map_or(false, |data_decoded| data_decoded.has_nested_delegated())
})
.ok()
let contract_info = info_provider.contract_info(to).await?;

let has_nested_delegate_calls = !data_decoded
.as_ref()
.map_or(false, |data_decoded| data_decoded.has_nested_delegated());

let is_trusted_delegate_call =
contract_info.trusted_for_delegate_call && has_nested_delegate_calls;
return Ok(Some(is_trusted_delegate_call));
} else {
None
Ok(None)
}
}
36 changes: 25 additions & 11 deletions src/routes/transactions/converters/tests/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::routes::transactions::models::{
Custom, Erc721Transfer, TransactionInfo, TransactionStatus, Transfer, TransferDirection,
TransferInfo,
};
use crate::utils::errors::ApiError;
use crate::utils::errors::{ApiError, ErrorDetails};
use crate::utils::http_client::Response;

#[rocket::async_test]
Expand Down Expand Up @@ -74,14 +74,14 @@ async fn multisig_custom_transaction_to_transaction_details() {
param_type: "uint256".to_string(),
value: SingleValue(String::from("500000000000000")),
value_decoded: None,
}
},
]),
}),
to: AddressEx::address_only("0xD9BA894E0097f8cC2BBc9D24D308b98e36dc6D02"),
value: Some(String::from("0")),
operation: Operation::CALL,
address_info_index: None,
trusted_delegate_call_target: None
trusted_delegate_call_target: None,
}),
detailed_execution_info: Some(DetailedExecutionInfo::Multisig(
MultisigExecutionDetails {
Expand All @@ -99,7 +99,7 @@ async fn multisig_custom_transaction_to_transaction_details() {
AddressEx::address_only("0x37e9F140A9Df5DCBc783C6c220660a4E15CBFe72"),
AddressEx::address_only("0xA3DAa0d9Ae02dAA17a664c232aDa1B739eF5ae8D"),
AddressEx::address_only("0xF2CeA96575d6b10f51d9aF3b10e3e4E5738aa6bd"),
AddressEx::address_only("0x65F8236309e5A99Ff0d129d04E486EBCE20DC7B0")
AddressEx::address_only("0x65F8236309e5A99Ff0d129d04E486EBCE20DC7B0"),
],
confirmations_required: 2,
confirmations: vec![
Expand Down Expand Up @@ -171,7 +171,7 @@ async fn module_transaction_to_transaction_details_module_info_success() {
value: Some(String::from("0")),
operation: Operation::CALL,
address_info_index: None,
trusted_delegate_call_target: None
trusted_delegate_call_target: None,
}),
detailed_execution_info: Some(DetailedExecutionInfo::Module(
ModuleExecutionDetails {
Expand Down Expand Up @@ -229,7 +229,7 @@ async fn module_transaction_to_transaction_details_success() {
value: Some(String::from("0")),
operation: Operation::CALL,
address_info_index: None,
trusted_delegate_call_target: None
trusted_delegate_call_target: None,
}),
detailed_execution_info: Some(DetailedExecutionInfo::Module(
ModuleExecutionDetails {
Expand Down Expand Up @@ -283,7 +283,7 @@ async fn module_transaction_to_transaction_details_failed() {
value: Some(String::from("0")),
operation: Operation::CALL,
address_info_index: None,
trusted_delegate_call_target: None
trusted_delegate_call_target: None,
}),
detailed_execution_info: Some(DetailedExecutionInfo::Module(
ModuleExecutionDetails {
Expand Down Expand Up @@ -423,7 +423,8 @@ async fn is_trusted_delegate_with_call() {
&Some(data_decoded),
&mock_info_provider,
)
.await;
.await
.unwrap();

assert_eq!(actual, None);
}
Expand Down Expand Up @@ -454,7 +455,8 @@ async fn is_trusted_delegate_with_delegate() {
&Some(data_decoded),
&mock_info_provider,
)
.await;
.await
.unwrap();

assert_eq!(actual, Some(false));
}
Expand Down Expand Up @@ -483,7 +485,18 @@ async fn is_trusted_delegate_with_contract_request_failure() {
)
.await;

assert_eq!(actual, None);
assert_eq!(
actual.unwrap_err(),
ApiError {
status: 404,
details: ErrorDetails {
code: 1337,
message: Some("".to_string()),
debug: None,
arguments: None
}
}
);
}

#[rocket::async_test]
Expand Down Expand Up @@ -514,7 +527,8 @@ async fn is_trusted_delegate_with_call_but_nested_delegate() {
&Some(data_decoded),
&mock_info_provider,
)
.await;
.await
.unwrap();

assert_eq!(actual, Some(false));
}

0 comments on commit 8738367

Please sign in to comment.