Skip to content

Commit

Permalink
Merge pull request #791 from multiversx/governance-v2-mainnet-setup
Browse files Browse the repository at this point in the history
Update tests setup to the mainnet setup
  • Loading branch information
CostinCarabas authored Dec 12, 2023
2 parents fc4b8e8 + 18c1868 commit bf85891
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 148 deletions.
28 changes: 14 additions & 14 deletions energy-integration/governance-v2/src/configurable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub trait ConfigurablePropertiesModule:

#[only_owner]
#[endpoint(changeQuorumPercentage)]
fn change_quorum_percentage(&self, new_value: BigUint) {
fn change_quorum_percentage(&self, new_value: u64) {
self.try_change_quorum_percentage(new_value);
}

Expand Down Expand Up @@ -102,40 +102,40 @@ pub trait ConfigurablePropertiesModule:
self.min_fee_for_propose().set(&new_value);
}

fn try_change_quorum_percentage(&self, new_value: BigUint) {
fn try_change_quorum_percentage(&self, new_quorum_percentage: u64) {
require!(
new_value > MIN_QUORUM && new_value < MAX_QUORUM,
(MIN_QUORUM..MAX_QUORUM).contains(&new_quorum_percentage),
"Not valid value for Quorum!"
);

self.quorum_percentage().set(&new_value);
self.quorum_percentage().set(new_quorum_percentage);
}

fn try_change_voting_delay_in_blocks(&self, new_value: u64) {
fn try_change_voting_delay_in_blocks(&self, new_voting_delay: u64) {
require!(
new_value > MIN_VOTING_DELAY && new_value < MAX_VOTING_DELAY,
(MIN_VOTING_DELAY..MAX_VOTING_DELAY).contains(&new_voting_delay),
"Not valid value for voting delay!"
);

self.voting_delay_in_blocks().set(new_value);
self.voting_delay_in_blocks().set(new_voting_delay);
}

fn try_change_voting_period_in_blocks(&self, new_value: u64) {
fn try_change_voting_period_in_blocks(&self, new_voting_period: u64) {
require!(
new_value > MIN_VOTING_PERIOD && new_value < MAX_VOTING_PERIOD,
(MIN_VOTING_PERIOD..MAX_VOTING_PERIOD).contains(&new_voting_period),
"Not valid value for voting period!"
);

self.voting_period_in_blocks().set(new_value);
self.voting_period_in_blocks().set(new_voting_period);
}

fn try_change_withdraw_percentage_defeated(&self, new_value: u64) {
fn try_change_withdraw_percentage_defeated(&self, new_withdraw_percentage: u64) {
require!(
new_value <= FULL_PERCENTAGE,
new_withdraw_percentage <= FULL_PERCENTAGE,
"Not valid value for withdraw percentage if defeated!"
);

self.withdraw_percentage_defeated().set(new_value);
self.withdraw_percentage_defeated().set(new_withdraw_percentage);
}

fn try_change_fee_token_id(&self, fee_token_id: TokenIdentifier) {
Expand All @@ -157,7 +157,7 @@ pub trait ConfigurablePropertiesModule:

#[view(getQuorum)]
#[storage_mapper("quorumPercentage")]
fn quorum_percentage(&self) -> SingleValueMapper<BigUint>;
fn quorum_percentage(&self) -> SingleValueMapper<u64>;

#[view(getVotingDelayInBlocks)]
#[storage_mapper("votingDelayInBlocks")]
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 @@ -42,7 +42,7 @@ pub trait GovernanceV2:
&self,
min_energy_for_propose: BigUint,
min_fee_for_propose: BigUint,
quorum_percentage: BigUint,
quorum_percentage: u64,
voting_delay_in_blocks: u64,
voting_period_in_blocks: u64,
withdraw_percentage_defeated: u64,
Expand Down
4 changes: 2 additions & 2 deletions energy-integration/governance-v2/src/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub struct GovernanceProposal<M: ManagedTypeApi> {
pub actions: ArrayVec<GovernanceAction<M>, MAX_GOVERNANCE_PROPOSAL_ACTIONS>,
pub description: ManagedBuffer<M>,
pub fee_payment: EsdtTokenPayment<M>,
pub minimum_quorum: BigUint<M>,
pub minimum_quorum: u64,
pub voting_delay_in_blocks: u64,
pub voting_period_in_blocks: u64,
pub withdraw_percentage_defeated: u64,
Expand Down Expand Up @@ -100,7 +100,7 @@ impl<M: ManagedTypeApi> GovernanceProposal<M> {
token_nonce: 0,
amount: BigUint::zero(),
},
minimum_quorum: BigUint::default(),
minimum_quorum: 0,
voting_delay_in_blocks: 0,
voting_period_in_blocks: 0,
withdraw_percentage_defeated: 0,
Expand Down
2 changes: 1 addition & 1 deletion energy-integration/governance-v2/src/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub trait ViewsModule:
fn quorum_reached(&self, proposal_id: ProposalId) -> bool {
let proposal = self.proposals().get(proposal_id);
let total_quorum_for_proposal = proposal.total_quorum;
let required_minimum_percentage = proposal.minimum_quorum;
let required_minimum_percentage = BigUint::from(proposal.minimum_quorum);
let current_quorum = self.proposal_votes(proposal_id).get().quorum;

current_quorum * FULL_PERCENTAGE >= required_minimum_percentage * total_quorum_for_proposal
Expand Down
Loading

0 comments on commit bf85891

Please sign in to comment.