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

Commit 8738367

Browse files
authored
Merge pull request #799 from gnosis/fix-contract-error-mapping
Map contracts endpoint error to ApiResult
2 parents cc07a61 + 4167410 commit 8738367

File tree

4 files changed

+42
-29
lines changed

4 files changed

+42
-29
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "safe-client-gateway"
3-
version = "3.16.0"
3+
version = "3.16.1"
44
authors = ["jpalvarezl <[email protected]>", "rmeissner <[email protected]>", "fmrsabino <[email protected]>"]
55
edition = "2018"
66

src/routes/transactions/converters/details.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ impl MultisigTransaction {
2929
&self.safe_transaction.data_decoded,
3030
info_provider,
3131
)
32-
.await;
32+
.await?;
33+
3334
Ok(TransactionDetails {
3435
safe_address: self.safe_transaction.safe.to_owned(),
3536
tx_id: self.generate_id(),
@@ -141,7 +142,8 @@ impl ModuleTransaction {
141142
&safe_transaction.data_decoded,
142143
info_provider,
143144
)
144-
.await;
145+
.await?;
146+
145147
Ok(TransactionDetails {
146148
safe_address: self.safe_transaction.safe.to_owned(),
147149
tx_id: self.generate_id(),
@@ -177,21 +179,18 @@ pub async fn is_trusted_delegate_call(
177179
to: &str,
178180
data_decoded: &Option<DataDecoded>,
179181
info_provider: &(impl InfoProvider + Sync),
180-
) -> Option<bool> {
182+
) -> ApiResult<Option<bool>> {
181183
if operation == &Operation::DELEGATE {
182-
info_provider
183-
.contract_info(to)
184-
.await
185-
.map(|contract_info| {
186-
// In the case of a known `multiSend` method call, we can still have internal transactions with DELEGATE calls
187-
// which is why we only check when `trusted_for_delegate_call = true`
188-
contract_info.trusted_for_delegate_call
189-
&& !data_decoded
190-
.as_ref()
191-
.map_or(false, |data_decoded| data_decoded.has_nested_delegated())
192-
})
193-
.ok()
184+
let contract_info = info_provider.contract_info(to).await?;
185+
186+
let has_nested_delegate_calls = !data_decoded
187+
.as_ref()
188+
.map_or(false, |data_decoded| data_decoded.has_nested_delegated());
189+
190+
let is_trusted_delegate_call =
191+
contract_info.trusted_for_delegate_call && has_nested_delegate_calls;
192+
return Ok(Some(is_trusted_delegate_call));
194193
} else {
195-
None
194+
Ok(None)
196195
}
197196
}

src/routes/transactions/converters/tests/details.rs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::routes::transactions::models::{
1616
Custom, Erc721Transfer, TransactionInfo, TransactionStatus, Transfer, TransferDirection,
1717
TransferInfo,
1818
};
19-
use crate::utils::errors::ApiError;
19+
use crate::utils::errors::{ApiError, ErrorDetails};
2020
use crate::utils::http_client::Response;
2121

2222
#[rocket::async_test]
@@ -74,14 +74,14 @@ async fn multisig_custom_transaction_to_transaction_details() {
7474
param_type: "uint256".to_string(),
7575
value: SingleValue(String::from("500000000000000")),
7676
value_decoded: None,
77-
}
77+
},
7878
]),
7979
}),
8080
to: AddressEx::address_only("0xD9BA894E0097f8cC2BBc9D24D308b98e36dc6D02"),
8181
value: Some(String::from("0")),
8282
operation: Operation::CALL,
8383
address_info_index: None,
84-
trusted_delegate_call_target: None
84+
trusted_delegate_call_target: None,
8585
}),
8686
detailed_execution_info: Some(DetailedExecutionInfo::Multisig(
8787
MultisigExecutionDetails {
@@ -99,7 +99,7 @@ async fn multisig_custom_transaction_to_transaction_details() {
9999
AddressEx::address_only("0x37e9F140A9Df5DCBc783C6c220660a4E15CBFe72"),
100100
AddressEx::address_only("0xA3DAa0d9Ae02dAA17a664c232aDa1B739eF5ae8D"),
101101
AddressEx::address_only("0xF2CeA96575d6b10f51d9aF3b10e3e4E5738aa6bd"),
102-
AddressEx::address_only("0x65F8236309e5A99Ff0d129d04E486EBCE20DC7B0")
102+
AddressEx::address_only("0x65F8236309e5A99Ff0d129d04E486EBCE20DC7B0"),
103103
],
104104
confirmations_required: 2,
105105
confirmations: vec![
@@ -171,7 +171,7 @@ async fn module_transaction_to_transaction_details_module_info_success() {
171171
value: Some(String::from("0")),
172172
operation: Operation::CALL,
173173
address_info_index: None,
174-
trusted_delegate_call_target: None
174+
trusted_delegate_call_target: None,
175175
}),
176176
detailed_execution_info: Some(DetailedExecutionInfo::Module(
177177
ModuleExecutionDetails {
@@ -229,7 +229,7 @@ async fn module_transaction_to_transaction_details_success() {
229229
value: Some(String::from("0")),
230230
operation: Operation::CALL,
231231
address_info_index: None,
232-
trusted_delegate_call_target: None
232+
trusted_delegate_call_target: None,
233233
}),
234234
detailed_execution_info: Some(DetailedExecutionInfo::Module(
235235
ModuleExecutionDetails {
@@ -283,7 +283,7 @@ async fn module_transaction_to_transaction_details_failed() {
283283
value: Some(String::from("0")),
284284
operation: Operation::CALL,
285285
address_info_index: None,
286-
trusted_delegate_call_target: None
286+
trusted_delegate_call_target: None,
287287
}),
288288
detailed_execution_info: Some(DetailedExecutionInfo::Module(
289289
ModuleExecutionDetails {
@@ -423,7 +423,8 @@ async fn is_trusted_delegate_with_call() {
423423
&Some(data_decoded),
424424
&mock_info_provider,
425425
)
426-
.await;
426+
.await
427+
.unwrap();
427428

428429
assert_eq!(actual, None);
429430
}
@@ -454,7 +455,8 @@ async fn is_trusted_delegate_with_delegate() {
454455
&Some(data_decoded),
455456
&mock_info_provider,
456457
)
457-
.await;
458+
.await
459+
.unwrap();
458460

459461
assert_eq!(actual, Some(false));
460462
}
@@ -483,7 +485,18 @@ async fn is_trusted_delegate_with_contract_request_failure() {
483485
)
484486
.await;
485487

486-
assert_eq!(actual, None);
488+
assert_eq!(
489+
actual.unwrap_err(),
490+
ApiError {
491+
status: 404,
492+
details: ErrorDetails {
493+
code: 1337,
494+
message: Some("".to_string()),
495+
debug: None,
496+
arguments: None
497+
}
498+
}
499+
);
487500
}
488501

489502
#[rocket::async_test]
@@ -514,7 +527,8 @@ async fn is_trusted_delegate_with_call_but_nested_delegate() {
514527
&Some(data_decoded),
515528
&mock_info_provider,
516529
)
517-
.await;
530+
.await
531+
.unwrap();
518532

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

0 commit comments

Comments
 (0)