Skip to content

Commit

Permalink
Merge pull request #790 from multiversx/governance-v2-allow-zero-ener…
Browse files Browse the repository at this point in the history
…gy-propose

Governance-v2:Allow users with 0 energy to propose
  • Loading branch information
CostinCarabas authored Dec 11, 2023
2 parents fdfa965 + 143aebc commit fc4b8e8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
2 changes: 0 additions & 2 deletions energy-integration/governance-v2/src/configurable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion energy-integration/governance-v2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
14 changes: 6 additions & 8 deletions energy-integration/governance-v2/tests/gov_rust_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,33 +88,31 @@ 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",
vec![1_000u64.to_be_bytes().to_vec()],
);
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"
);
})
Expand Down
16 changes: 16 additions & 0 deletions energy-integration/governance-v2/tests/gov_test_setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<governance_v2::ContractObj<DebugApi>, GovBuilder>,
pub current_block: u64,
}
Expand All @@ -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(
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -192,6 +200,7 @@ where
first_user,
second_user,
third_user,
no_energy_user,
gov_wrapper,
current_block: 0,
}
Expand Down Expand Up @@ -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| {
Expand Down

0 comments on commit fc4b8e8

Please sign in to comment.