Skip to content

Commit

Permalink
refactor to policy_module_irrevocable
Browse files Browse the repository at this point in the history
  • Loading branch information
baoskee committed Dec 28, 2022
1 parent c635cca commit b8e34e3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
10 changes: 6 additions & 4 deletions contracts/proposal/cwd-proposal-delegate/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ pub fn execute(
policy_irrevocable,
policy_preserve_on_failure,
} => {
let policy_irrevocable = policy_irrevocable.unwrap_or(DEFAULT_POLICY_IRREVOCABLE);
let policy_module_irrevocable =
policy_irrevocable.unwrap_or(DEFAULT_POLICY_IRREVOCABLE);
let policy_preserve_on_failure =
policy_preserve_on_failure.unwrap_or(DEFAULT_POLICY_PRESERVE_ON_FAILURE);
let delegate = deps.api.addr_validate(&delegate)?;
Expand All @@ -64,7 +65,7 @@ pub fn execute(
delegate,
msgs,
expiration,
policy_irrevocable,
policy_module_irrevocable,
policy_preserve_on_failure,
},
)
Expand Down Expand Up @@ -158,9 +159,10 @@ pub fn execute_remove_delegation(
}
// If delegation is irrevocable, return Error
let Delegation {
policy_irrevocable, ..
policy_module_irrevocable,
..
} = DELEGATIONS.load(deps.storage, delegation_id)?;
if policy_irrevocable {
if policy_module_irrevocable {
return Err(ContractError::DelegationIrrevocable {});
}
// Else remove the delegation
Expand Down
2 changes: 1 addition & 1 deletion contracts/proposal/cwd-proposal-delegate/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct Delegation {
pub msgs: Vec<CosmosMsg<Empty>>,
pub expiration: Option<Expiration>,

pub policy_irrevocable: bool,
pub policy_module_irrevocable: bool,
pub policy_preserve_on_failure: bool,
}

Expand Down
18 changes: 9 additions & 9 deletions contracts/proposal/cwd-proposal-delegate/src/testing/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn test_unauthorized_delegation() {
delegate: Addr::unchecked("dest_addr"),
msgs: Vec::new(),
expiration: None,
policy_irrevocable: false,
policy_module_irrevocable: false,
policy_preserve_on_failure: true,
},
)
Expand All @@ -58,7 +58,7 @@ fn test_unauthorized_delegation() {
delegate: Addr::unchecked("dest_addr"),
msgs: Vec::new(),
expiration: None,
policy_irrevocable: false,
policy_module_irrevocable: false,
policy_preserve_on_failure: false,
},
)
Expand Down Expand Up @@ -93,7 +93,7 @@ fn test_execute_authorization() {
delegate: Addr::unchecked("dest_addr"),
msgs: Vec::new(),
expiration: None,
policy_irrevocable: false,
policy_module_irrevocable: false,
policy_preserve_on_failure: false,
},
)
Expand Down Expand Up @@ -145,7 +145,7 @@ fn test_execute_authorization() {
delegate: Addr::unchecked("dest_addr_2"),
msgs: Vec::new(),
expiration: None,
policy_irrevocable: false,
policy_module_irrevocable: false,
policy_preserve_on_failure: false,
},
)
Expand Down Expand Up @@ -211,7 +211,7 @@ fn test_execute_on_failure_policy() {
delegate: Addr::unchecked("dest_addr"),
msgs: Vec::new(),
expiration: None,
policy_irrevocable: false,
policy_module_irrevocable: false,
policy_preserve_on_failure: false,
},
)
Expand Down Expand Up @@ -241,7 +241,7 @@ fn test_execute_on_failure_policy() {
delegate: Addr::unchecked("dest_addr"),
msgs: Vec::new(),
expiration: None,
policy_irrevocable: false,
policy_module_irrevocable: false,
policy_preserve_on_failure: true,
},
)
Expand Down Expand Up @@ -306,7 +306,7 @@ fn test_execute_on_expired() {
delegate: Addr::unchecked("dest_addr"),
msgs: Vec::new(),
expiration: Some(Expiration::AtHeight(10)),
policy_irrevocable: false,
policy_module_irrevocable: false,
policy_preserve_on_failure: false,
},
)
Expand Down Expand Up @@ -358,7 +358,7 @@ fn test_revocable_policy() {
delegate: Addr::unchecked("dest_addr"),
msgs: Vec::new(),
expiration: None,
policy_irrevocable: true, // Make it irrevocable
policy_module_irrevocable: true, // Make it irrevocable
policy_preserve_on_failure: false,
},
)
Expand All @@ -381,7 +381,7 @@ fn test_revocable_policy() {
delegate: Addr::unchecked("dest_addr"),
msgs: Vec::new(),
expiration: None,
policy_irrevocable: false,
policy_module_irrevocable: false,
policy_preserve_on_failure: false,
},
)
Expand Down

0 comments on commit b8e34e3

Please sign in to comment.