From 1038a7e5a66ab5010631f635982837567414b3dc Mon Sep 17 00:00:00 2001 From: Amit Yadav Date: Fri, 22 Sep 2023 01:24:06 +0530 Subject: [PATCH 1/9] add cooldown parameter --- README.md | 1 + astra/TestPlan.md | 6 ++++++ astra/src/lib.rs | 1 + astra/src/policy.rs | 7 +++++++ astra/src/proposals.rs | 1 + astra/tests/test_general.rs | 1 + 6 files changed, 17 insertions(+) diff --git a/README.md b/README.md index 9db27735..b9bc41f2 100644 --- a/README.md +++ b/README.md @@ -204,6 +204,7 @@ near view $ASTRA_ID get_policy }, "proposal_bond": "1000000000000000000000000", "proposal_period": "604800000000000", + "cooldown": "0", "bounty_bond": "1000000000000000000000000", "bounty_forgiveness_period": "86400000000000" } diff --git a/astra/TestPlan.md b/astra/TestPlan.md index ab916a7d..3c5a7a97 100644 --- a/astra/TestPlan.md +++ b/astra/TestPlan.md @@ -135,6 +135,7 @@ Confirm the default policy acts as it should. }, "proposal_bond": "1000000000000000000000000", "proposal_period": "604800000000000", + "cooldown": "0", "bounty_bond": "1000000000000000000000000", "bounty_forgiveness_period": "86400000000000" } @@ -194,6 +195,7 @@ Each }, "proposal_bond": "1000000000000000000000000", "proposal_period": "604800000000000", + "cooldown": "0", "bounty_bond": "1000000000000000000000000", "bounty_forgiveness_period": "86400000000000" } @@ -253,6 +255,7 @@ Each }, "proposal_bond": "1000000000000000000000000", "proposal_period": "604800000000000", + "cooldown": "0", "bounty_bond": "1000000000000000000000000", "bounty_forgiveness_period": "86400000000000" } @@ -312,6 +315,7 @@ Each }, "proposal_bond": "1000000000000000000000000", "proposal_period": "604800000000000", + "cooldown": "0", "bounty_bond": "1000000000000000000000000", "bounty_forgiveness_period": "86400000000000" } @@ -371,6 +375,7 @@ Each }, "proposal_bond": "1000000000000000000000000", "proposal_period": "604800000000000", + "cooldown": "0", "bounty_bond": "1000000000000000000000000", "bounty_forgiveness_period": "86400000000000" } @@ -446,6 +451,7 @@ Each group council can have different threshold criteria for consensus. Confirm }, "proposal_bond": "1000000000000000000000000", "proposal_period": "604800000000000", + "cooldown": "0", "bounty_bond": "1000000000000000000000000", "bounty_forgiveness_period": "86400000000000" } diff --git a/astra/src/lib.rs b/astra/src/lib.rs index 23a00262..4de890da 100644 --- a/astra/src/lib.rs +++ b/astra/src/lib.rs @@ -322,6 +322,7 @@ mod tests { default_vote_policy: VotePolicy::default(), proposal_bond: U128(10u128.pow(24)), proposal_period: U64::from(1_000_000_000 * 60 * 60 * 24 * 7), + cooldown: U64::from(0), bounty_bond: U128(10u128.pow(24)), bounty_forgiveness_period: U64::from(1_000_000_000 * 60 * 60 * 24), } diff --git a/astra/src/policy.rs b/astra/src/policy.rs index b4bed5b3..2f43f5e0 100644 --- a/astra/src/policy.rs +++ b/astra/src/policy.rs @@ -154,6 +154,8 @@ pub struct Policy { pub proposal_bond: U128, /// Expiration period for proposals. pub proposal_period: U64, + /// Proposal can be executed only after cooldown period is complete( in milliseconds ) + pub cooldown: U64, /// Bond for claiming a bounty. pub bounty_bond: U128, /// Period in which giving up on bounty is not punished. @@ -204,6 +206,7 @@ pub fn default_policy(council: Vec) -> Policy { default_vote_policy: VotePolicy::default(), proposal_bond: U128(10u128.pow(24)), proposal_period: U64::from(1_000_000_000 * 60 * 60 * 24 * 7), + cooldown: U64::from(0), bounty_bond: U128(10u128.pow(24)), bounty_forgiveness_period: U64::from(1_000_000_000 * 60 * 60 * 24), } @@ -274,6 +277,9 @@ impl Policy { if parameters.proposal_period.is_some() { self.proposal_period = parameters.proposal_period.unwrap(); } + if parameters.cooldown.is_some() { + self.cooldown = parameters.cooldown.unwrap(); + } if parameters.bounty_bond.is_some() { self.bounty_bond = parameters.bounty_bond.unwrap(); } @@ -616,6 +622,7 @@ mod tests { proposal_bond: Some(U128(10u128.pow(26))), proposal_period: None, bounty_bond: None, + cooldown: None, bounty_forgiveness_period: Some(U64::from(1_000_000_000 * 60 * 60 * 24 * 5)), }; policy.update_parameters(&new_parameters); diff --git a/astra/src/proposals.rs b/astra/src/proposals.rs index 79ba9df6..34a3ea27 100644 --- a/astra/src/proposals.rs +++ b/astra/src/proposals.rs @@ -52,6 +52,7 @@ pub struct ActionCall { pub struct PolicyParameters { pub proposal_bond: Option, pub proposal_period: Option, + pub cooldown: Option, pub bounty_bond: Option, pub bounty_forgiveness_period: Option, } diff --git a/astra/tests/test_general.rs b/astra/tests/test_general.rs index d385dd3b..692d1f7e 100644 --- a/astra/tests/test_general.rs +++ b/astra/tests/test_general.rs @@ -125,6 +125,7 @@ async fn test_multi_council() -> anyhow::Result<()> { default_vote_policy: VotePolicy::default(), proposal_bond: U128(10u128.pow(24)), proposal_period: U64::from(1_000_000_000 * 60 * 60 * 24 * 7), + cooldown: U64::from(0), bounty_bond: U128(10u128.pow(24)), bounty_forgiveness_period: U64::from(1_000_000_000 * 60 * 60 * 24), }; From 3cc77099978e52193e01e39e97b3f2d0420cecd9 Mon Sep 17 00:00:00 2001 From: Amit Yadav Date: Fri, 22 Sep 2023 01:38:23 +0530 Subject: [PATCH 2/9] add tests --- astra/src/lib.rs | 23 ++++++++++++++++++++++- astra/src/proposals.rs | 13 ++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/astra/src/lib.rs b/astra/src/lib.rs index 4de890da..772fc83f 100644 --- a/astra/src/lib.rs +++ b/astra/src/lib.rs @@ -265,7 +265,7 @@ mod tests { use near_sdk::{testing_env, VMContext}; use near_units::parse_near; - use crate::proposals::ProposalStatus; + use crate::proposals::{ProposalStatus, PolicyParameters}; use crate::test_utils::*; use super::*; @@ -520,6 +520,27 @@ mod tests { contract.act_proposal(id, Action::Execute, None, None); } + #[test] + #[should_panic(expected = "ERR_PROPOSAL_COOLDOWN_LEFT")] + fn test_cooldown() { + let (_, mut contract, id) = setup_for_proposals(); + let mut policy = contract.policy.get().unwrap().to_policy(); + policy.update_parameters(&PolicyParameters{ + cooldown: Some(U64::from(1_000_000_000 * 60 * 60)), proposal_bond: None, + proposal_period: None, bounty_bond: None, + bounty_forgiveness_period: None + }); + + contract.act_proposal(id, Action::VoteApprove, None, None); + // verify proposal wasn't executed during final vote + assert_eq!( + contract.get_proposal(id).proposal.status, + ProposalStatus::Approved + ); + + contract.act_proposal(id, Action::Execute, None, None); + } + #[test] #[should_panic(expected = "ERR_INVALID_POLICY")] fn test_fails_adding_invalid_policy() { diff --git a/astra/src/proposals.rs b/astra/src/proposals.rs index 34a3ea27..5928db6f 100644 --- a/astra/src/proposals.rs +++ b/astra/src/proposals.rs @@ -546,9 +546,10 @@ impl Contract { if self.status == ContractStatus::Dissolved { panic!("Cannot perform this action, dao is dissolved!") } - let execute = !skip_execution.unwrap_or(false); let mut proposal: Proposal = self.proposals.get(&id).expect("ERR_NO_PROPOSAL").into(); let policy = self.policy.get().unwrap().to_policy(); + + let execute = !skip_execution.unwrap_or(false) && self.assert_cooldown(proposal.submission_time, policy.cooldown); // Check permissions for the given action. let (roles, allowed) = policy.can_execute_action(self.internal_user_info(), &proposal.kind, &action); @@ -623,6 +624,7 @@ impl Contract { Action::MoveToHub => false, Action::Execute => { require!(proposal.status != ProposalStatus::Executed, "ERR_PROPOSAL_ALREADY_EXECUTED"); + require!(self.assert_cooldown(proposal.submission_time, policy.cooldown), "ERR_PROPOSAL_COOLDOWN_LEFT"); // recompute status to check if the proposal is not expired. proposal.status = policy.proposal_status(&proposal, roles, self.total_delegation_amount); require!(proposal.status == ProposalStatus::Approved, "ERR_PROPOSAL_NOT_APPROVED"); @@ -669,4 +671,13 @@ impl Contract { .insert(&proposal_id, &VersionedProposal::Default(proposal)); result } + + /// Returns true if cooldown is over else false + #[private] + pub fn assert_cooldown(&mut self, submission_time: U64, cooldown: U64) -> bool { + if env::block_timestamp_ms() > cooldown.0 + submission_time.0 { + return true; + } + return false; + } } From 273d0f1f8996af9c90e9fde8e910015226c9575b Mon Sep 17 00:00:00 2001 From: Amit Yadav Date: Fri, 22 Sep 2023 01:39:12 +0530 Subject: [PATCH 3/9] check --- astra/src/proposals.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/astra/src/proposals.rs b/astra/src/proposals.rs index 5928db6f..33d3707f 100644 --- a/astra/src/proposals.rs +++ b/astra/src/proposals.rs @@ -602,6 +602,7 @@ impl Contract { // - if the number of votes in the group has changed (new members has been added) - // the proposal can loose it's approved state. In this case new proposal needs to be made, this one can only expire. Action::Finalize => { + require!(self.assert_cooldown(proposal.submission_time, policy.cooldown), "ERR_PROPOSAL_COOLDOWN_LEFT"); proposal.status = policy.proposal_status( &proposal, policy.roles.iter().map(|r| r.name.clone()).collect(), From 5ce9f567cb4da236672c7db8228ae8173d3ea81a Mon Sep 17 00:00:00 2001 From: Amit Yadav Date: Fri, 22 Sep 2023 01:42:46 +0530 Subject: [PATCH 4/9] lint --- astra/src/lib.rs | 4 ++-- astra/src/proposals.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/astra/src/lib.rs b/astra/src/lib.rs index 772fc83f..b0c53923 100644 --- a/astra/src/lib.rs +++ b/astra/src/lib.rs @@ -355,7 +355,7 @@ mod tests { ndc_trust() ); let id = create_proposal(&mut context, &mut contract); - return (context.build(), contract, id) + (context.build(), contract, id) } #[test] @@ -657,7 +657,7 @@ mod tests { assert!(!res.roles.is_empty()); context.predecessor_account_id = acc_voting_body(); - testing_env!(context.clone()); + testing_env!(context); contract.dissolve_hook(); res = contract.policy.get().unwrap().to_policy(); assert!(res.roles.is_empty()); diff --git a/astra/src/proposals.rs b/astra/src/proposals.rs index 33d3707f..1d18b1dd 100644 --- a/astra/src/proposals.rs +++ b/astra/src/proposals.rs @@ -679,6 +679,6 @@ impl Contract { if env::block_timestamp_ms() > cooldown.0 + submission_time.0 { return true; } - return false; + false } } From 2fbe34451a6cf8eb8fa8e5bc7dc055977a9dc7ba Mon Sep 17 00:00:00 2001 From: Amit Yadav Date: Fri, 22 Sep 2023 19:04:02 +0530 Subject: [PATCH 5/9] Apply suggestions from code review Co-authored-by: sczembor <43810037+sczembor@users.noreply.github.com> --- astra/src/policy.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/astra/src/policy.rs b/astra/src/policy.rs index 2f43f5e0..62e7ea39 100644 --- a/astra/src/policy.rs +++ b/astra/src/policy.rs @@ -154,7 +154,7 @@ pub struct Policy { pub proposal_bond: U128, /// Expiration period for proposals. pub proposal_period: U64, - /// Proposal can be executed only after cooldown period is complete( in milliseconds ) + /// The execution of the proposal can only occur once the cooldown period has elapsed (measured in milliseconds). pub cooldown: U64, /// Bond for claiming a bounty. pub bounty_bond: U128, @@ -277,9 +277,9 @@ impl Policy { if parameters.proposal_period.is_some() { self.proposal_period = parameters.proposal_period.unwrap(); } - if parameters.cooldown.is_some() { - self.cooldown = parameters.cooldown.unwrap(); - } +if let Some(cooldown) = parameters.cooldown { + self.cooldown = cooldown; +} if parameters.bounty_bond.is_some() { self.bounty_bond = parameters.bounty_bond.unwrap(); } From eb9e5c59486c2fd5574b4b0d58a06560cf54db98 Mon Sep 17 00:00:00 2001 From: Amit Yadav Date: Fri, 22 Sep 2023 19:23:46 +0530 Subject: [PATCH 6/9] updates --- CHANGELOG.md | 14 +++++++++++++- astra/src/lib.rs | 1 + astra/src/proposals.rs | 10 +++++----- astra/tests/test_general.rs | 2 +- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e332421..bd114d90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,16 +20,28 @@ Change log entries are to be added to the Unreleased section. Example entry: ## Unreleased ++ Update repo to the latest near-sdk and related deps ++ Integrate hooks ++ Add option to act_proposal to not execute the proposal ++ Add events to veto and dissolve hooks ++ Integrate cooldown + ### Features New methods: -- A.. +- `veto_hook`: Vetos any proposal.(must be called by authority with permission) +- `dissolve_hook`: Dissolves the DAO by removing all members, closing all active proposals and returning bonds. Extended types: +- ProposalStatus: `Executed` +- Action: `Veto` and `Dissolve` + New types: +- `ContractStatus`: Active or Dissolved + ### Breaking Changes - B... diff --git a/astra/src/lib.rs b/astra/src/lib.rs index b0c53923..f32b478a 100644 --- a/astra/src/lib.rs +++ b/astra/src/lib.rs @@ -530,6 +530,7 @@ mod tests { proposal_period: None, bounty_bond: None, bounty_forgiveness_period: None }); + contract.policy.set(&VersionedPolicy::Current(policy)); contract.act_proposal(id, Action::VoteApprove, None, None); // verify proposal wasn't executed during final vote diff --git a/astra/src/proposals.rs b/astra/src/proposals.rs index 1d18b1dd..2d8526cc 100644 --- a/astra/src/proposals.rs +++ b/astra/src/proposals.rs @@ -549,7 +549,7 @@ impl Contract { let mut proposal: Proposal = self.proposals.get(&id).expect("ERR_NO_PROPOSAL").into(); let policy = self.policy.get().unwrap().to_policy(); - let execute = !skip_execution.unwrap_or(false) && self.assert_cooldown(proposal.submission_time, policy.cooldown); + let execute = !skip_execution.unwrap_or(false) && self.is_past_cooldown(proposal.submission_time, policy.cooldown); // Check permissions for the given action. let (roles, allowed) = policy.can_execute_action(self.internal_user_info(), &proposal.kind, &action); @@ -602,7 +602,7 @@ impl Contract { // - if the number of votes in the group has changed (new members has been added) - // the proposal can loose it's approved state. In this case new proposal needs to be made, this one can only expire. Action::Finalize => { - require!(self.assert_cooldown(proposal.submission_time, policy.cooldown), "ERR_PROPOSAL_COOLDOWN_LEFT"); + require!(self.is_past_cooldown(proposal.submission_time, policy.cooldown), "ERR_PROPOSAL_COOLDOWN_LEFT"); proposal.status = policy.proposal_status( &proposal, policy.roles.iter().map(|r| r.name.clone()).collect(), @@ -625,7 +625,7 @@ impl Contract { Action::MoveToHub => false, Action::Execute => { require!(proposal.status != ProposalStatus::Executed, "ERR_PROPOSAL_ALREADY_EXECUTED"); - require!(self.assert_cooldown(proposal.submission_time, policy.cooldown), "ERR_PROPOSAL_COOLDOWN_LEFT"); + require!(self.is_past_cooldown(proposal.submission_time, policy.cooldown), "ERR_PROPOSAL_COOLDOWN_LEFT"); // recompute status to check if the proposal is not expired. proposal.status = policy.proposal_status(&proposal, roles, self.total_delegation_amount); require!(proposal.status == ProposalStatus::Approved, "ERR_PROPOSAL_NOT_APPROVED"); @@ -675,8 +675,8 @@ impl Contract { /// Returns true if cooldown is over else false #[private] - pub fn assert_cooldown(&mut self, submission_time: U64, cooldown: U64) -> bool { - if env::block_timestamp_ms() > cooldown.0 + submission_time.0 { + fn is_past_cooldown(&mut self, submission_time: U64, cooldown: U64) -> bool { + if env::block_timestamp_ms() >= cooldown.0 + submission_time.0 { return true; } false diff --git a/astra/tests/test_general.rs b/astra/tests/test_general.rs index 692d1f7e..8ca41a35 100644 --- a/astra/tests/test_general.rs +++ b/astra/tests/test_general.rs @@ -106,7 +106,7 @@ async fn test_multi_council() -> anyhow::Result<()> { RolePermission { name: "all".to_string(), kind: RoleKind::Everyone, - permissions: vec!["*:AddProposal".to_string()].into_iter().collect(), + permissions: vec!["*:Execute".to_string(), "*:AddProposal".to_string()].into_iter().collect(), vote_policy: HashMap::default(), }, RolePermission { From 6cb4589f6d3a76a38326951c1440c38e42119736 Mon Sep 17 00:00:00 2001 From: Amit Yadav Date: Fri, 22 Sep 2023 19:46:48 +0530 Subject: [PATCH 7/9] conversion --- astra/src/lib.rs | 2 +- astra/src/proposals.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/astra/src/lib.rs b/astra/src/lib.rs index f32b478a..cbbad40f 100644 --- a/astra/src/lib.rs +++ b/astra/src/lib.rs @@ -526,7 +526,7 @@ mod tests { let (_, mut contract, id) = setup_for_proposals(); let mut policy = contract.policy.get().unwrap().to_policy(); policy.update_parameters(&PolicyParameters{ - cooldown: Some(U64::from(1_000_000_000 * 60 * 60)), proposal_bond: None, + cooldown: Some(U64::from(1_000 * 60 * 60)), proposal_bond: None, proposal_period: None, bounty_bond: None, bounty_forgiveness_period: None }); diff --git a/astra/src/proposals.rs b/astra/src/proposals.rs index 2d8526cc..82982592 100644 --- a/astra/src/proposals.rs +++ b/astra/src/proposals.rs @@ -676,7 +676,7 @@ impl Contract { /// Returns true if cooldown is over else false #[private] fn is_past_cooldown(&mut self, submission_time: U64, cooldown: U64) -> bool { - if env::block_timestamp_ms() >= cooldown.0 + submission_time.0 { + if env::block_timestamp() >= (cooldown.0 * 1_000_000) + submission_time.0 { return true; } false From a578ed89d1f9efc307adf308a78df2c6f3832183 Mon Sep 17 00:00:00 2001 From: Amit Yadav Date: Sat, 23 Sep 2023 00:49:53 +0530 Subject: [PATCH 8/9] updates --- astra/src/policy.rs | 30 +++++++++++++++++++----------- astra/src/proposals.rs | 17 ++++------------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/astra/src/policy.rs b/astra/src/policy.rs index 62e7ea39..cb7446da 100644 --- a/astra/src/policy.rs +++ b/astra/src/policy.rs @@ -271,20 +271,20 @@ impl Policy { } pub fn update_parameters(&mut self, parameters: &PolicyParameters) { - if parameters.proposal_bond.is_some() { - self.proposal_bond = parameters.proposal_bond.unwrap(); + if let Some(proposal_bond) = parameters.proposal_bond { + self.proposal_bond = proposal_bond; } - if parameters.proposal_period.is_some() { - self.proposal_period = parameters.proposal_period.unwrap(); + if let Some(proposal_period) = parameters.proposal_period { + self.proposal_period = proposal_period; } -if let Some(cooldown) = parameters.cooldown { - self.cooldown = cooldown; -} - if parameters.bounty_bond.is_some() { - self.bounty_bond = parameters.bounty_bond.unwrap(); + if let Some(cooldown) = parameters.cooldown { + self.cooldown = cooldown; + } + if let Some(bounty_bond) = parameters.bounty_bond { + self.bounty_bond = bounty_bond; } - if parameters.bounty_forgiveness_period.is_some() { - self.bounty_forgiveness_period = parameters.bounty_forgiveness_period.unwrap(); + if let Some(bounty_forgiveness_period) = parameters.bounty_forgiveness_period { + self.bounty_forgiveness_period = bounty_forgiveness_period; } env::log_str("Successfully updated the policy parameters."); } @@ -450,6 +450,14 @@ if let Some(cooldown) = parameters.cooldown { } proposal.status.clone() } + + /// Returns true if cooldown is over else false + pub fn is_past_cooldown(&mut self, submission_time: U64) -> bool { + if env::block_timestamp() >= (self.cooldown.0 * 1_000_000) + submission_time.0 { + return true; + } + false + } } #[cfg(test)] diff --git a/astra/src/proposals.rs b/astra/src/proposals.rs index 82982592..f0628399 100644 --- a/astra/src/proposals.rs +++ b/astra/src/proposals.rs @@ -547,9 +547,9 @@ impl Contract { panic!("Cannot perform this action, dao is dissolved!") } let mut proposal: Proposal = self.proposals.get(&id).expect("ERR_NO_PROPOSAL").into(); - let policy = self.policy.get().unwrap().to_policy(); + let mut policy = self.policy.get().unwrap().to_policy(); - let execute = !skip_execution.unwrap_or(false) && self.is_past_cooldown(proposal.submission_time, policy.cooldown); + let execute = !skip_execution.unwrap_or(false) && policy.is_past_cooldown(proposal.submission_time); // Check permissions for the given action. let (roles, allowed) = policy.can_execute_action(self.internal_user_info(), &proposal.kind, &action); @@ -602,7 +602,7 @@ impl Contract { // - if the number of votes in the group has changed (new members has been added) - // the proposal can loose it's approved state. In this case new proposal needs to be made, this one can only expire. Action::Finalize => { - require!(self.is_past_cooldown(proposal.submission_time, policy.cooldown), "ERR_PROPOSAL_COOLDOWN_LEFT"); + require!(policy.is_past_cooldown(proposal.submission_time), "ERR_PROPOSAL_COOLDOWN_LEFT"); proposal.status = policy.proposal_status( &proposal, policy.roles.iter().map(|r| r.name.clone()).collect(), @@ -625,7 +625,7 @@ impl Contract { Action::MoveToHub => false, Action::Execute => { require!(proposal.status != ProposalStatus::Executed, "ERR_PROPOSAL_ALREADY_EXECUTED"); - require!(self.is_past_cooldown(proposal.submission_time, policy.cooldown), "ERR_PROPOSAL_COOLDOWN_LEFT"); + require!(policy.is_past_cooldown(proposal.submission_time), "ERR_PROPOSAL_COOLDOWN_LEFT"); // recompute status to check if the proposal is not expired. proposal.status = policy.proposal_status(&proposal, roles, self.total_delegation_amount); require!(proposal.status == ProposalStatus::Approved, "ERR_PROPOSAL_NOT_APPROVED"); @@ -672,13 +672,4 @@ impl Contract { .insert(&proposal_id, &VersionedProposal::Default(proposal)); result } - - /// Returns true if cooldown is over else false - #[private] - fn is_past_cooldown(&mut self, submission_time: U64, cooldown: U64) -> bool { - if env::block_timestamp() >= (cooldown.0 * 1_000_000) + submission_time.0 { - return true; - } - false - } } From 3225cbaa813c3b5931459810c1d724ad9e068608 Mon Sep 17 00:00:00 2001 From: Amit Yadav Date: Sat, 23 Sep 2023 00:51:34 +0530 Subject: [PATCH 9/9] error message --- astra/src/lib.rs | 2 +- astra/src/proposals.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/astra/src/lib.rs b/astra/src/lib.rs index cbbad40f..c8bd24ca 100644 --- a/astra/src/lib.rs +++ b/astra/src/lib.rs @@ -521,7 +521,7 @@ mod tests { } #[test] - #[should_panic(expected = "ERR_PROPOSAL_COOLDOWN_LEFT")] + #[should_panic(expected = "ERR_PROPOSAL_STILL_ACTIVE")] fn test_cooldown() { let (_, mut contract, id) = setup_for_proposals(); let mut policy = contract.policy.get().unwrap().to_policy(); diff --git a/astra/src/proposals.rs b/astra/src/proposals.rs index f0628399..9e03aedc 100644 --- a/astra/src/proposals.rs +++ b/astra/src/proposals.rs @@ -602,7 +602,7 @@ impl Contract { // - if the number of votes in the group has changed (new members has been added) - // the proposal can loose it's approved state. In this case new proposal needs to be made, this one can only expire. Action::Finalize => { - require!(policy.is_past_cooldown(proposal.submission_time), "ERR_PROPOSAL_COOLDOWN_LEFT"); + require!(policy.is_past_cooldown(proposal.submission_time), "ERR_PROPOSAL_STILL_ACTIVE"); proposal.status = policy.proposal_status( &proposal, policy.roles.iter().map(|r| r.name.clone()).collect(), @@ -625,7 +625,7 @@ impl Contract { Action::MoveToHub => false, Action::Execute => { require!(proposal.status != ProposalStatus::Executed, "ERR_PROPOSAL_ALREADY_EXECUTED"); - require!(policy.is_past_cooldown(proposal.submission_time), "ERR_PROPOSAL_COOLDOWN_LEFT"); + require!(policy.is_past_cooldown(proposal.submission_time), "ERR_PROPOSAL_STILL_ACTIVE"); // recompute status to check if the proposal is not expired. proposal.status = policy.proposal_status(&proposal, roles, self.total_delegation_amount); require!(proposal.status == ProposalStatus::Approved, "ERR_PROPOSAL_NOT_APPROVED");