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

Commit

Permalink
New SetGuard and DeleteGuard variants added to SettingsInfo (#824)
Browse files Browse the repository at this point in the history
* Added branches for SetGuard and DeleteGuard

* Added unit tests

* Removed left over comment from the implementation
  • Loading branch information
jpalvarezl authored Mar 4, 2022
1 parent ee906fb commit 779f007
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/common/converters/data_decoded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use crate::providers::info::InfoProvider;
use crate::routes::transactions::models::SettingsInfo;
use crate::utils::{
ADD_OWNER_WITH_THRESHOLD, CHANGE_MASTER_COPY, CHANGE_THRESHOLD, DISABLE_MODULE, ENABLE_MODULE,
MULTI_SEND, MULTI_SEND_TRANSACTIONS_PARAM, REMOVE_OWNER, SET_FALLBACK_HANDLER, SWAP_OWNER,
MULTI_SEND, MULTI_SEND_TRANSACTIONS_PARAM, REMOVE_OWNER, SET_FALLBACK_HANDLER, SET_GUARD,
SWAP_OWNER,
};
use std::collections::HashMap;

Expand Down Expand Up @@ -75,6 +76,18 @@ impl DataDecoded {
CHANGE_THRESHOLD => Some(SettingsInfo::ChangeThreshold {
threshold: self.get_parameter_single_value_at(0)?.parse().ok()?,
}),
SET_GUARD => {
let guard = self.get_parameter_single_value_at(0)?;
let settings_info = if guard != "0x0000000000000000000000000000000000000000" {
let guard = info_provider
.address_ex_from_contracts_or_default(&guard)
.await;
SettingsInfo::SetGuard { guard }
} else {
SettingsInfo::DeleteGuard
};
Some(settings_info)
}
_ => None,
}
}
Expand Down
73 changes: 73 additions & 0 deletions src/common/converters/tests/data_decoded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,79 @@ async fn data_decoded_unknown_to_settings_info() {
assert_eq!(expected.settings_info, actual);
}

#[rocket::async_test]
async fn data_decoded_set_guard_address_known() {
let guard = AddressEx {
value: "0xf2565317F3Ae8Ae9EA98E9Fe1e7FADC77F823cbD".to_string(),
name: Some("Cool guard contract".to_string()),
logo_uri: Some("logo.url".to_string()),
};
let mut mock_info_provider = MockInfoProvider::new();
let data_decoded =
serde_json::from_str::<DataDecoded>(crate::tests::json::DATA_DECODED_SET_GUARD).unwrap();
mock_info_provider
.expect_address_ex_from_contracts()
.with(eq("0xf2565317F3Ae8Ae9EA98E9Fe1e7FADC77F823cbD"))
.times(1)
.return_once(move |_| {
Ok(AddressEx {
value: "0xf2565317F3Ae8Ae9EA98E9Fe1e7FADC77F823cbD".to_string(),
name: Some("Cool guard contract".to_string()),
logo_uri: Some("logo.url".to_string()),
})
});

let expected = SettingsChange {
data_decoded: data_decoded.clone(),
settings_info: Some(SettingsInfo::SetGuard { guard }),
};

let actual = DataDecoded::to_settings_info(&data_decoded, &mut mock_info_provider).await;

assert_eq!(expected.settings_info, actual);
}

#[rocket::async_test]
async fn data_decoded_set_guard_address_unknown() {
let mut mock_info_provider = MockInfoProvider::new();
mock_info_provider
.expect_address_ex_from_contracts()
.with(eq("0xf2565317F3Ae8Ae9EA98E9Fe1e7FADC77F823cbD"))
.times(1)
.return_once(move |_| bail!("Some http error"));

let data_decoded =
serde_json::from_str::<DataDecoded>(crate::tests::json::DATA_DECODED_SET_GUARD).unwrap();

let expected = SettingsChange {
data_decoded: data_decoded.clone(),
settings_info: Some(SettingsInfo::SetGuard {
guard: AddressEx::address_only("0xf2565317F3Ae8Ae9EA98E9Fe1e7FADC77F823cbD"),
}),
};

let actual = DataDecoded::to_settings_info(&data_decoded, &mut mock_info_provider).await;

assert_eq!(expected.settings_info, actual);
}

#[rocket::async_test]
async fn data_decoded_delete_guard() {
let mut mock_info_provider = MockInfoProvider::new();

let data_decoded =
serde_json::from_str::<DataDecoded>(crate::tests::json::DATA_DECODED_DELETE_GUARD).unwrap();

let expected = SettingsChange {
data_decoded: data_decoded.clone(),
settings_info: Some(SettingsInfo::DeleteGuard),
};

let actual = DataDecoded::to_settings_info(&data_decoded, &mut mock_info_provider).await;

assert_eq!(expected.settings_info, actual);
}

#[test]
fn data_decoded_with_nested_safe_transaction() {
let data_decoded = serde_json::from_str::<DataDecoded>(
Expand Down
4 changes: 4 additions & 0 deletions src/routes/transactions/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ pub enum SettingsInfo {
EnableModule { module: AddressEx },
#[serde(rename_all = "camelCase")]
DisableModule { module: AddressEx },
#[serde(rename_all = "camelCase")]
SetGuard { guard: AddressEx },
#[serde(rename_all = "camelCase")]
DeleteGuard,
}

#[derive(Serialize, Debug, PartialEq)]
Expand Down
10 changes: 10 additions & 0 deletions src/tests/json/commons/data_decoded_delete_guard.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"method": "setGuard",
"parameters": [
{
"name": "guard",
"type": "address",
"value": "0x0000000000000000000000000000000000000000"
}
]
}
10 changes: 10 additions & 0 deletions src/tests/json/commons/data_decoded_set_guard.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"method": "setGuard",
"parameters": [
{
"name": "guard",
"type": "address",
"value": "0xf2565317F3Ae8Ae9EA98E9Fe1e7FADC77F823cbD"
}
]
}
2 changes: 2 additions & 0 deletions src/tests/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ pub const DOCTORED_DATA_DECODED_NESTED_MULTI_SENDS: &str =
include_str!("commons/DOCTORED_data_decoded_nested_multi_sends.json");
pub const DOCTORED_DATA_DECODED_MULTI_SEND_NESTED_DELEGATE: &str =
include_str!("commons/DOCTORED_data_decoded_multi_send_nested_delegate.json");
pub const DATA_DECODED_SET_GUARD: &str = include_str!("commons/data_decoded_set_guard.json");
pub const DATA_DECODED_DELETE_GUARD: &str = include_str!("commons/data_decoded_delete_guard.json");

pub const BALANCE_ETHER: &str = include_str!("balances/balance_ether.json");
pub const BALANCE_COMPOUND_ETHER: &str = include_str!("balances/balance_compound_ether.json");
Expand Down
2 changes: 2 additions & 0 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub const CHANGE_THRESHOLD: &'static str = "changeThreshold";
pub const CHANGE_MASTER_COPY: &'static str = "changeMasterCopy";
pub const ENABLE_MODULE: &'static str = "enableModule";
pub const DISABLE_MODULE: &'static str = "disableModule";
pub const SET_GUARD: &'static str = "setGuard";

pub const MULTI_SEND: &'static str = "multiSend";
pub const MULTI_SEND_TRANSACTIONS_PARAM: &'static str = "transactions";
Expand All @@ -45,6 +46,7 @@ pub const SETTINGS_CHANGE_METHODS: &[&str] = &[
CHANGE_MASTER_COPY,
ENABLE_MODULE,
DISABLE_MODULE,
SET_GUARD,
];

impl DataDecoded {
Expand Down

0 comments on commit 779f007

Please sign in to comment.