From 412c3056e42f9590ff74ec7cba2148e9dfd56a2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Fri, 8 Dec 2023 17:00:37 +0200 Subject: [PATCH 1/2] Governance-v2:Allow users with 0 energy to propose --- energy-integration/governance-v2/src/configurable.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/energy-integration/governance-v2/src/configurable.rs b/energy-integration/governance-v2/src/configurable.rs index 3fe44e7b0..a2c626935 100644 --- a/energy-integration/governance-v2/src/configurable.rs +++ b/energy-integration/governance-v2/src/configurable.rs @@ -86,8 +86,6 @@ pub trait ConfigurablePropertiesModule: } fn try_change_min_energy_for_propose(&self, new_value: BigUint) { - require!(new_value != 0, "Min energy for proposal can't be set to 0"); - self.min_energy_for_propose().set(&new_value); } From 143aebc15b59bf709d264776a8c82c6d68ddd29c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Mon, 11 Dec 2023 09:57:43 +0200 Subject: [PATCH 2/2] Add test for propose with 0 energy --- energy-integration/governance-v2/src/lib.rs | 2 +- .../governance-v2/tests/gov_rust_test.rs | 14 ++++++-------- .../governance-v2/tests/gov_test_setup/mod.rs | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/energy-integration/governance-v2/src/lib.rs b/energy-integration/governance-v2/src/lib.rs index 9c9de7613..325c0e198 100644 --- a/energy-integration/governance-v2/src/lib.rs +++ b/energy-integration/governance-v2/src/lib.rs @@ -88,7 +88,7 @@ pub trait GovernanceV2: EXEEDED_MAX_ACTIONS ); - let user_energy = self.get_energy_amount_non_zero(&proposer); + let user_energy = self.get_energy_amount(&proposer); let min_energy_for_propose = self.min_energy_for_propose().get(); require!(user_energy >= min_energy_for_propose, NOT_ENOUGH_ENERGY); diff --git a/energy-integration/governance-v2/tests/gov_rust_test.rs b/energy-integration/governance-v2/tests/gov_rust_test.rs index 573278722..05f61c7cc 100644 --- a/energy-integration/governance-v2/tests/gov_rust_test.rs +++ b/energy-integration/governance-v2/tests/gov_rust_test.rs @@ -88,16 +88,18 @@ fn gov_propose_test() { fn gov_propose_total_energy_0_test() { let mut gov_setup = GovSetup::new(governance_v2::contract_obj); - let first_user_addr = gov_setup.first_user.clone(); + let no_energy_user = gov_setup.no_energy_user.clone(); let sc_addr = gov_setup.gov_wrapper.address_ref().clone(); let min_fee = rust_biguint!(MIN_FEE_FOR_PROPOSE) * DECIMALS_CONST; // Give proposer the minimum fee gov_setup .b_mock - .set_nft_balance(&first_user_addr, WXMEX_TOKEN_ID, 1, &min_fee, &Empty); + .set_nft_balance(&no_energy_user, WXMEX_TOKEN_ID, 1, &min_fee, &Empty); + + gov_setup.change_min_energy(0).assert_ok(); let (result, proposal_id) = gov_setup.propose( - &first_user_addr, + &no_energy_user, &min_fee, &sc_addr, b"changeTODO", @@ -105,16 +107,12 @@ fn gov_propose_total_energy_0_test() { ); result.assert_ok(); assert_eq!(proposal_id, 1); - gov_setup.increment_block_nonce(VOTING_PERIOD_BLOCKS + VOTING_DELAY_BLOCKS); gov_setup .b_mock .execute_query(&gov_setup.gov_wrapper, |sc| { - let mut proposal = sc.proposals().get(1); - proposal.total_quorum = managed_biguint!(0); - sc.proposals().set(1, &proposal); assert!( - sc.get_proposal_status(1) == GovernanceProposalStatus::Defeated, + sc.get_proposal_status(1) == GovernanceProposalStatus::Pending, "Action should have been Defeated" ); }) diff --git a/energy-integration/governance-v2/tests/gov_test_setup/mod.rs b/energy-integration/governance-v2/tests/gov_test_setup/mod.rs index 520b5b0b4..c195ff877 100644 --- a/energy-integration/governance-v2/tests/gov_test_setup/mod.rs +++ b/energy-integration/governance-v2/tests/gov_test_setup/mod.rs @@ -50,6 +50,7 @@ where pub first_user: Address, pub second_user: Address, pub third_user: Address, + pub no_energy_user: Address, pub gov_wrapper: ContractObjWrapper, GovBuilder>, pub current_block: u64, } @@ -65,6 +66,7 @@ where let first_user = b_mock.create_user_account(&rust_zero); let second_user = b_mock.create_user_account(&rust_zero); let third_user = b_mock.create_user_account(&rust_zero); + let no_energy_user = b_mock.create_user_account(&rust_zero); // init energy factory let energy_factory_wrapper = b_mock.create_sc_account( @@ -103,6 +105,12 @@ where 0, managed_biguint!(0), )); + sc.user_energy(&managed_address!(&no_energy_user)) + .set(&Energy::new( + BigInt::from(managed_biguint!(0)), + 0, + managed_biguint!(0), + )); }) .assert_ok(); @@ -192,6 +200,7 @@ where first_user, second_user, third_user, + no_energy_user, gov_wrapper, current_block: 0, } @@ -278,6 +287,13 @@ where }) } + pub fn change_min_energy(&mut self, min_energy_for_propose: usize) -> TxResult { + self.b_mock + .execute_tx(&self.owner, &self.gov_wrapper, &rust_biguint!(0), |sc| { + sc.min_energy_for_propose().set(&managed_biguint!(min_energy_for_propose)); + }) + } + pub fn cancel_proposal(&mut self, caller: &Address, proposal_id: usize) -> TxResult { self.b_mock .execute_tx(caller, &self.gov_wrapper, &rust_biguint!(0), |sc| {