From c079eb2e507631285297cade5b2cd8cec9889c6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Mon, 11 Dec 2023 14:30:52 +0200 Subject: [PATCH 1/3] Fix clippy issues --- .../governance-v2/src/configurable.rs | 28 +++++----- energy-integration/governance-v2/src/lib.rs | 2 +- .../governance-v2/src/proposal.rs | 4 +- energy-integration/governance-v2/src/views.rs | 2 +- .../governance-v2/tests/gov_rust_test.rs | 56 +++++++++---------- .../governance-v2/tests/gov_test_setup/mod.rs | 26 ++++----- 6 files changed, 58 insertions(+), 60 deletions(-) diff --git a/energy-integration/governance-v2/src/configurable.rs b/energy-integration/governance-v2/src/configurable.rs index a2c626935..6ff4151d1 100644 --- a/energy-integration/governance-v2/src/configurable.rs +++ b/energy-integration/governance-v2/src/configurable.rs @@ -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); } @@ -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_percetange: u64) { require!( - new_value > MIN_QUORUM && new_value < MAX_QUORUM, + (MIN_QUORUM..MAX_QUORUM).contains(&new_quorum_percetange), "Not valid value for Quorum!" ); - self.quorum_percentage().set(&new_value); + self.quorum_percentage().set(new_quorum_percetange); } - 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) { @@ -157,7 +157,7 @@ pub trait ConfigurablePropertiesModule: #[view(getQuorum)] #[storage_mapper("quorumPercentage")] - fn quorum_percentage(&self) -> SingleValueMapper; + fn quorum_percentage(&self) -> SingleValueMapper; #[view(getVotingDelayInBlocks)] #[storage_mapper("votingDelayInBlocks")] diff --git a/energy-integration/governance-v2/src/lib.rs b/energy-integration/governance-v2/src/lib.rs index 325c0e198..0fcb53dca 100644 --- a/energy-integration/governance-v2/src/lib.rs +++ b/energy-integration/governance-v2/src/lib.rs @@ -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, diff --git a/energy-integration/governance-v2/src/proposal.rs b/energy-integration/governance-v2/src/proposal.rs index 94c66a131..e26591817 100644 --- a/energy-integration/governance-v2/src/proposal.rs +++ b/energy-integration/governance-v2/src/proposal.rs @@ -61,7 +61,7 @@ pub struct GovernanceProposal { pub actions: ArrayVec, MAX_GOVERNANCE_PROPOSAL_ACTIONS>, pub description: ManagedBuffer, pub fee_payment: EsdtTokenPayment, - pub minimum_quorum: BigUint, + pub minimum_quorum: u64, pub voting_delay_in_blocks: u64, pub voting_period_in_blocks: u64, pub withdraw_percentage_defeated: u64, @@ -100,7 +100,7 @@ impl GovernanceProposal { 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, diff --git a/energy-integration/governance-v2/src/views.rs b/energy-integration/governance-v2/src/views.rs index 79b33c20c..84b53c537 100644 --- a/energy-integration/governance-v2/src/views.rs +++ b/energy-integration/governance-v2/src/views.rs @@ -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 diff --git a/energy-integration/governance-v2/tests/gov_rust_test.rs b/energy-integration/governance-v2/tests/gov_rust_test.rs index 05f61c7cc..a6fd55feb 100644 --- a/energy-integration/governance-v2/tests/gov_rust_test.rs +++ b/energy-integration/governance-v2/tests/gov_rust_test.rs @@ -8,7 +8,7 @@ use governance_v2::{ proposal_storage::ProposalStorageModule, views::ViewsModule, }; use multiversx_sc::{codec::Empty, types::ManagedVec}; -use multiversx_sc_scenario::{managed_biguint, managed_buffer, rust_biguint}; +use multiversx_sc_scenario::{managed_buffer, rust_biguint}; #[test] fn init_gov_test() { @@ -26,7 +26,7 @@ fn gov_propose_test() { // 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(&first_user_addr, MEX_TOKEN_ID, 1, &min_fee, &Empty); let (result, proposal_id) = gov_setup.propose( &first_user_addr, @@ -94,7 +94,7 @@ fn gov_propose_total_energy_0_test() { // Give proposer the minimum fee gov_setup .b_mock - .set_nft_balance(&no_energy_user, WXMEX_TOKEN_ID, 1, &min_fee, &Empty); + .set_nft_balance(&no_energy_user, MEX_TOKEN_ID, 1, &min_fee, &Empty); gov_setup.change_min_energy(0).assert_ok(); @@ -131,7 +131,7 @@ fn gov_no_veto_vote_test() { // 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(&first_user_addr, MEX_TOKEN_ID, 1, &min_fee, &Empty); let (result, proposal_id) = gov_setup.propose( &first_user_addr, @@ -148,7 +148,7 @@ fn gov_no_veto_vote_test() { .execute_query(&gov_setup.gov_wrapper, |sc| { assert_eq!( sc.quorum_percentage().get(), - managed_biguint!(QUORUM_PERCENTAGE) + QUORUM_PERCENTAGE ); }) .assert_ok(); @@ -189,7 +189,7 @@ fn gov_abstain_vote_test() { // 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(&first_user_addr, MEX_TOKEN_ID, 1, &min_fee, &Empty); let (result, proposal_id) = gov_setup.propose( &first_user_addr, @@ -231,7 +231,7 @@ fn gov_no_quorum_test() { // 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(&first_user_addr, MEX_TOKEN_ID, 1, &min_fee, &Empty); let (result, proposal_id) = gov_setup.propose( &first_user_addr, @@ -270,7 +270,7 @@ fn gov_modify_quorum_after_end_vote_test() { // 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(&first_user_addr, MEX_TOKEN_ID, 1, &min_fee, &Empty); let (result, proposal_id) = gov_setup.propose( &first_user_addr, @@ -295,8 +295,8 @@ fn gov_modify_quorum_after_end_vote_test() { sc.get_proposal_status(1) == GovernanceProposalStatus::Defeated, "Action should have been Defeated" ); - sc.try_change_quorum_percentage(managed_biguint!(QUORUM_PERCENTAGE / 2)); - assert!(sc.quorum_percentage().get() == managed_biguint!(QUORUM_PERCENTAGE / 2)); + sc.try_change_quorum_percentage(QUORUM_PERCENTAGE / 2); + assert!(sc.quorum_percentage().get() == QUORUM_PERCENTAGE / 2); assert!( sc.get_proposal_status(1) == GovernanceProposalStatus::Defeated, @@ -317,7 +317,7 @@ fn gov_withdraw_defeated_proposal_test() { // 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(&first_user_addr, MEX_TOKEN_ID, 1, &min_fee, &Empty); let (result, proposal_id) = gov_setup.propose( &first_user_addr, @@ -332,7 +332,7 @@ fn gov_withdraw_defeated_proposal_test() { // Check proposer balance gov_setup.b_mock.check_nft_balance::( &first_user_addr, - WXMEX_TOKEN_ID, + MEX_TOKEN_ID, 1, &rust_biguint!(0), None, @@ -370,7 +370,7 @@ fn gov_withdraw_defeated_proposal_test() { // Check proposer balance (fee) gov_setup.b_mock.check_nft_balance::( &first_user_addr, - WXMEX_TOKEN_ID, + MEX_TOKEN_ID, 1, &min_fee, None, @@ -388,7 +388,7 @@ fn gov_modify_withdraw_defeated_proposal_test() { // 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(&first_user_addr, MEX_TOKEN_ID, 1, &min_fee, &Empty); let (result, proposal_id) = gov_setup.propose( &first_user_addr, @@ -403,7 +403,7 @@ fn gov_modify_withdraw_defeated_proposal_test() { // Check proposer balance gov_setup.b_mock.check_nft_balance::( &first_user_addr, - WXMEX_TOKEN_ID, + MEX_TOKEN_ID, 1, &rust_biguint!(0), None, @@ -449,7 +449,7 @@ fn gov_modify_withdraw_defeated_proposal_test() { // Check proposer balance (fee) gov_setup.b_mock.check_nft_balance::( &first_user_addr, - WXMEX_TOKEN_ID, + MEX_TOKEN_ID, 1, &min_fee, None, @@ -467,7 +467,7 @@ fn gov_withdraw_no_with_veto_defeated_proposal_test() { // 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(&first_user_addr, MEX_TOKEN_ID, 1, &min_fee, &Empty); let (result, proposal_id) = gov_setup.propose( &first_user_addr, @@ -482,7 +482,7 @@ fn gov_withdraw_no_with_veto_defeated_proposal_test() { // Check proposer balance gov_setup.b_mock.check_nft_balance::( &first_user_addr, - WXMEX_TOKEN_ID, + MEX_TOKEN_ID, 1, &rust_biguint!(0), None, @@ -515,7 +515,7 @@ fn gov_withdraw_no_with_veto_defeated_proposal_test() { // Check proposer balance (fee) gov_setup.b_mock.check_nft_balance::( &first_user_addr, - WXMEX_TOKEN_ID, + MEX_TOKEN_ID, 1, &(min_fee / 2u64), None, @@ -538,7 +538,7 @@ fn gov_withdraw_no_with_veto_penalty_limits_test() { // 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(&first_user_addr, MEX_TOKEN_ID, 1, &min_fee, &Empty); gov_setup.change_withdraw_percentage(0).assert_ok(); let (result, proposal_id) = gov_setup.propose( @@ -554,7 +554,7 @@ fn gov_withdraw_no_with_veto_penalty_limits_test() { // Check proposer balance gov_setup.b_mock.check_nft_balance::( &first_user_addr, - WXMEX_TOKEN_ID, + MEX_TOKEN_ID, 1, &rust_biguint!(0), None, @@ -587,7 +587,7 @@ fn gov_withdraw_no_with_veto_penalty_limits_test() { // Check proposer balance (fee) gov_setup.b_mock.check_nft_balance::( &first_user_addr, - WXMEX_TOKEN_ID, + MEX_TOKEN_ID, 1, &rust_biguint!(0), None, @@ -596,7 +596,7 @@ fn gov_withdraw_no_with_veto_penalty_limits_test() { // 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(&first_user_addr, MEX_TOKEN_ID, 1, &min_fee, &Empty); gov_setup.change_withdraw_percentage(10_000).assert_ok(); let (result, proposal_id) = gov_setup.propose( @@ -612,7 +612,7 @@ fn gov_withdraw_no_with_veto_penalty_limits_test() { // Check proposer balance gov_setup.b_mock.check_nft_balance::( &first_user_addr, - WXMEX_TOKEN_ID, + MEX_TOKEN_ID, 1, &rust_biguint!(0), None, @@ -645,7 +645,7 @@ fn gov_withdraw_no_with_veto_penalty_limits_test() { // Check proposer balance (fee) gov_setup.b_mock.check_nft_balance::( &first_user_addr, - WXMEX_TOKEN_ID, + MEX_TOKEN_ID, 1, &min_fee, None, @@ -662,7 +662,7 @@ fn gov_propose_cancel_proposal_id_test() { // Give proposer the minimum fee gov_setup.b_mock.set_nft_balance( &first_user_addr, - WXMEX_TOKEN_ID, + MEX_TOKEN_ID, 1, &(min_fee.clone() * 3u64), &Empty, @@ -712,7 +712,7 @@ fn gov_propose_cancel_proposal_id_test() { // Check proposer balance (fee = 0) gov_setup.b_mock.check_nft_balance::( &first_user_addr, - WXMEX_TOKEN_ID, + MEX_TOKEN_ID, 1, &rust_biguint!(0), None, @@ -736,7 +736,7 @@ fn gov_propose_cancel_proposal_id_test() { // Check proposer balance (fee should be refunded) gov_setup.b_mock.check_nft_balance::( &first_user_addr, - WXMEX_TOKEN_ID, + MEX_TOKEN_ID, 1, &min_fee, None, 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 c195ff877..d31d0f77d 100644 --- a/energy-integration/governance-v2/tests/gov_test_setup/mod.rs +++ b/energy-integration/governance-v2/tests/gov_test_setup/mod.rs @@ -20,15 +20,14 @@ use multiversx_sc_scenario::{ }; use num_bigint::BigUint; -pub const MIN_ENERGY_FOR_PROPOSE: u64 = 500_000; -pub const MIN_FEE_FOR_PROPOSE: u64 = 3_000_000; -pub const QUORUM_PERCENTAGE: u64 = 5000; -pub const VOTING_DELAY_BLOCKS: u64 = 10; -pub const VOTING_PERIOD_BLOCKS: u64 = 14_500; +pub const MIN_ENERGY_FOR_PROPOSE: u64 = 0; +pub const MIN_FEE_FOR_PROPOSE: u64 = 1_000_000_000; // 1B MEX +pub const QUORUM_PERCENTAGE: u64 = 4_000; // 40% +pub const VOTING_DELAY_BLOCKS: u64 = 1; +pub const VOTING_PERIOD_BLOCKS: u64 = 144_000; // 10 days pub const LOCKING_PERIOD_BLOCKS: u64 = 30; pub const WITHDRAW_PERCENTAGE: u64 = 5_000; // 50% -pub static WXMEX_TOKEN_ID: &[u8] = b"WXMEX-123456"; -pub const LOCKED_TOKEN_ID: &[u8] = b"LOCKED-abcdef"; +pub const MEX_TOKEN_ID: &[u8] = b"MEX-123456"; pub const DECIMALS_CONST: u64 = 1_000_000_000_000_000_000; pub const FULL_PERCENTAGE: u64 = 10_000; pub const USER_ENERGY: u64 = 1_000_000; @@ -117,7 +116,7 @@ where b_mock .execute_tx(&owner, &fees_collector_wrapper, &rust_biguint!(0), |sc| { sc.init( - managed_token_id!(LOCKED_TOKEN_ID), + managed_token_id!(MEX_TOKEN_ID), managed_address!(energy_factory_wrapper.address_ref()), ); }) @@ -160,26 +159,25 @@ where let gov_wrapper = b_mock.create_sc_account(&rust_zero, Some(&owner), gov_builder, "gov path"); - // let min_fee = managed_biguint!(MIN_FEE_FOR_PROPOSE )* managed_biguint!(DECIMALS_CONST); b_mock .execute_tx(&owner, &gov_wrapper, &rust_zero, |sc| { sc.init( managed_biguint!(MIN_ENERGY_FOR_PROPOSE), managed_biguint!(MIN_FEE_FOR_PROPOSE) * DECIMALS_CONST, - managed_biguint!(QUORUM_PERCENTAGE), + QUORUM_PERCENTAGE, VOTING_DELAY_BLOCKS, VOTING_PERIOD_BLOCKS, WITHDRAW_PERCENTAGE, managed_address!(energy_factory_wrapper.address_ref()), managed_address!(fees_collector_wrapper.address_ref()), - managed_token_id!(WXMEX_TOKEN_ID), + managed_token_id!(MEX_TOKEN_ID), ); }) .assert_ok(); b_mock .execute_tx(&owner, &gov_wrapper, &rust_zero, |sc| { - sc.fee_token_id().set(managed_token_id!(WXMEX_TOKEN_ID)); + sc.fee_token_id().set(managed_token_id!(MEX_TOKEN_ID)); }) .assert_ok(); @@ -190,7 +188,7 @@ where ]; b_mock.set_esdt_local_roles( gov_wrapper.address_ref(), - WXMEX_TOKEN_ID, + MEX_TOKEN_ID, &vote_nft_roles[..], ); @@ -218,7 +216,7 @@ where let result = self.b_mock.execute_esdt_transfer( proposer, &self.gov_wrapper, - WXMEX_TOKEN_ID, + MEX_TOKEN_ID, 1u64, fee_amount, |sc| { From 9668b071a872f4ec1dd90bcd6263d30595754a4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Mon, 11 Dec 2023 14:49:27 +0200 Subject: [PATCH 2/3] Fix typo --- energy-integration/governance-v2/src/configurable.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/energy-integration/governance-v2/src/configurable.rs b/energy-integration/governance-v2/src/configurable.rs index 6ff4151d1..a6e5891b8 100644 --- a/energy-integration/governance-v2/src/configurable.rs +++ b/energy-integration/governance-v2/src/configurable.rs @@ -102,13 +102,13 @@ pub trait ConfigurablePropertiesModule: self.min_fee_for_propose().set(&new_value); } - fn try_change_quorum_percentage(&self, new_quorum_percetange: u64) { + fn try_change_quorum_percentage(&self, new_quorum_percentage: u64) { require!( - (MIN_QUORUM..MAX_QUORUM).contains(&new_quorum_percetange), + (MIN_QUORUM..MAX_QUORUM).contains(&new_quorum_percentage), "Not valid value for Quorum!" ); - self.quorum_percentage().set(new_quorum_percetange); + self.quorum_percentage().set(new_quorum_percentage); } fn try_change_voting_delay_in_blocks(&self, new_voting_delay: u64) { From 9384ff33428250881001749df77796f585dbf488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Mon, 11 Dec 2023 15:17:29 +0200 Subject: [PATCH 3/3] Governance-v2 tests:Change MEX from SFT to FT --- .../governance-v2/tests/gov_rust_test.rs | 161 ++++++------------ .../governance-v2/tests/gov_test_setup/mod.rs | 10 +- 2 files changed, 57 insertions(+), 114 deletions(-) diff --git a/energy-integration/governance-v2/tests/gov_rust_test.rs b/energy-integration/governance-v2/tests/gov_rust_test.rs index a6fd55feb..d5f371bc2 100644 --- a/energy-integration/governance-v2/tests/gov_rust_test.rs +++ b/energy-integration/governance-v2/tests/gov_rust_test.rs @@ -7,7 +7,7 @@ use governance_v2::{ configurable::ConfigurablePropertiesModule, proposal::GovernanceProposalStatus, proposal_storage::ProposalStorageModule, views::ViewsModule, }; -use multiversx_sc::{codec::Empty, types::ManagedVec}; +use multiversx_sc::{types::ManagedVec}; use multiversx_sc_scenario::{managed_buffer, rust_biguint}; #[test] @@ -26,7 +26,7 @@ fn gov_propose_test() { // Give proposer the minimum fee gov_setup .b_mock - .set_nft_balance(&first_user_addr, MEX_TOKEN_ID, 1, &min_fee, &Empty); + .set_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &min_fee); let (result, proposal_id) = gov_setup.propose( &first_user_addr, @@ -94,7 +94,7 @@ fn gov_propose_total_energy_0_test() { // Give proposer the minimum fee gov_setup .b_mock - .set_nft_balance(&no_energy_user, MEX_TOKEN_ID, 1, &min_fee, &Empty); + .set_esdt_balance(&no_energy_user, MEX_TOKEN_ID, &min_fee); gov_setup.change_min_energy(0).assert_ok(); @@ -131,7 +131,7 @@ fn gov_no_veto_vote_test() { // Give proposer the minimum fee gov_setup .b_mock - .set_nft_balance(&first_user_addr, MEX_TOKEN_ID, 1, &min_fee, &Empty); + .set_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &min_fee); let (result, proposal_id) = gov_setup.propose( &first_user_addr, @@ -146,10 +146,7 @@ fn gov_no_veto_vote_test() { gov_setup .b_mock .execute_query(&gov_setup.gov_wrapper, |sc| { - assert_eq!( - sc.quorum_percentage().get(), - QUORUM_PERCENTAGE - ); + assert_eq!(sc.quorum_percentage().get(), QUORUM_PERCENTAGE); }) .assert_ok(); @@ -189,7 +186,7 @@ fn gov_abstain_vote_test() { // Give proposer the minimum fee gov_setup .b_mock - .set_nft_balance(&first_user_addr, MEX_TOKEN_ID, 1, &min_fee, &Empty); + .set_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &min_fee); let (result, proposal_id) = gov_setup.propose( &first_user_addr, @@ -231,7 +228,7 @@ fn gov_no_quorum_test() { // Give proposer the minimum fee gov_setup .b_mock - .set_nft_balance(&first_user_addr, MEX_TOKEN_ID, 1, &min_fee, &Empty); + .set_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &min_fee); let (result, proposal_id) = gov_setup.propose( &first_user_addr, @@ -270,7 +267,7 @@ fn gov_modify_quorum_after_end_vote_test() { // Give proposer the minimum fee gov_setup .b_mock - .set_nft_balance(&first_user_addr, MEX_TOKEN_ID, 1, &min_fee, &Empty); + .set_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &min_fee); let (result, proposal_id) = gov_setup.propose( &first_user_addr, @@ -317,7 +314,7 @@ fn gov_withdraw_defeated_proposal_test() { // Give proposer the minimum fee gov_setup .b_mock - .set_nft_balance(&first_user_addr, MEX_TOKEN_ID, 1, &min_fee, &Empty); + .set_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &min_fee); let (result, proposal_id) = gov_setup.propose( &first_user_addr, @@ -329,14 +326,9 @@ fn gov_withdraw_defeated_proposal_test() { result.assert_ok(); assert_eq!(proposal_id, 1); - // Check proposer balance - gov_setup.b_mock.check_nft_balance::( - &first_user_addr, - MEX_TOKEN_ID, - 1, - &rust_biguint!(0), - None, - ); + gov_setup + .b_mock + .check_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &rust_biguint!(0)); gov_setup.increment_block_nonce(VOTING_PERIOD_BLOCKS); @@ -367,14 +359,9 @@ fn gov_withdraw_defeated_proposal_test() { .withdraw_after_defeated(&first_user_addr, proposal_id) .assert_ok(); - // Check proposer balance (fee) - gov_setup.b_mock.check_nft_balance::( - &first_user_addr, - MEX_TOKEN_ID, - 1, - &min_fee, - None, - ); + gov_setup + .b_mock + .check_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &min_fee); } #[test] @@ -388,7 +375,7 @@ fn gov_modify_withdraw_defeated_proposal_test() { // Give proposer the minimum fee gov_setup .b_mock - .set_nft_balance(&first_user_addr, MEX_TOKEN_ID, 1, &min_fee, &Empty); + .set_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &min_fee); let (result, proposal_id) = gov_setup.propose( &first_user_addr, @@ -401,13 +388,9 @@ fn gov_modify_withdraw_defeated_proposal_test() { assert_eq!(proposal_id, 1); // Check proposer balance - gov_setup.b_mock.check_nft_balance::( - &first_user_addr, - MEX_TOKEN_ID, - 1, - &rust_biguint!(0), - None, - ); + gov_setup + .b_mock + .check_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &rust_biguint!(0)); gov_setup.increment_block_nonce(VOTING_PERIOD_BLOCKS); @@ -447,13 +430,9 @@ fn gov_modify_withdraw_defeated_proposal_test() { .assert_ok(); // Check proposer balance (fee) - gov_setup.b_mock.check_nft_balance::( - &first_user_addr, - MEX_TOKEN_ID, - 1, - &min_fee, - None, - ); + gov_setup + .b_mock + .check_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &min_fee); } #[test] @@ -467,7 +446,7 @@ fn gov_withdraw_no_with_veto_defeated_proposal_test() { // Give proposer the minimum fee gov_setup .b_mock - .set_nft_balance(&first_user_addr, MEX_TOKEN_ID, 1, &min_fee, &Empty); + .set_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &min_fee); let (result, proposal_id) = gov_setup.propose( &first_user_addr, @@ -480,13 +459,9 @@ fn gov_withdraw_no_with_veto_defeated_proposal_test() { assert_eq!(proposal_id, 1); // Check proposer balance - gov_setup.b_mock.check_nft_balance::( - &first_user_addr, - MEX_TOKEN_ID, - 1, - &rust_biguint!(0), - None, - ); + gov_setup + .b_mock + .check_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &rust_biguint!(0)); gov_setup.increment_block_nonce(VOTING_PERIOD_BLOCKS); @@ -513,13 +488,9 @@ fn gov_withdraw_no_with_veto_defeated_proposal_test() { .assert_ok(); // Check proposer balance (fee) - gov_setup.b_mock.check_nft_balance::( - &first_user_addr, - MEX_TOKEN_ID, - 1, - &(min_fee / 2u64), - None, - ); + gov_setup + .b_mock + .check_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &(&min_fee / 2u64)); // Withdraw the fee twice - error gov_setup @@ -538,7 +509,7 @@ fn gov_withdraw_no_with_veto_penalty_limits_test() { // Give proposer the minimum fee gov_setup .b_mock - .set_nft_balance(&first_user_addr, MEX_TOKEN_ID, 1, &min_fee, &Empty); + .set_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &min_fee); gov_setup.change_withdraw_percentage(0).assert_ok(); let (result, proposal_id) = gov_setup.propose( @@ -552,13 +523,9 @@ fn gov_withdraw_no_with_veto_penalty_limits_test() { assert_eq!(proposal_id, 1); // Check proposer balance - gov_setup.b_mock.check_nft_balance::( - &first_user_addr, - MEX_TOKEN_ID, - 1, - &rust_biguint!(0), - None, - ); + gov_setup + .b_mock + .check_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &rust_biguint!(0)); gov_setup.increment_block_nonce(VOTING_PERIOD_BLOCKS); @@ -585,18 +552,14 @@ fn gov_withdraw_no_with_veto_penalty_limits_test() { .assert_ok(); // Check proposer balance (fee) - gov_setup.b_mock.check_nft_balance::( - &first_user_addr, - MEX_TOKEN_ID, - 1, - &rust_biguint!(0), - None, - ); + gov_setup + .b_mock + .check_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &rust_biguint!(0)); // Give proposer the minimum fee gov_setup .b_mock - .set_nft_balance(&first_user_addr, MEX_TOKEN_ID, 1, &min_fee, &Empty); + .set_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &min_fee); gov_setup.change_withdraw_percentage(10_000).assert_ok(); let (result, proposal_id) = gov_setup.propose( @@ -610,13 +573,9 @@ fn gov_withdraw_no_with_veto_penalty_limits_test() { assert_eq!(proposal_id, 2); // Check proposer balance - gov_setup.b_mock.check_nft_balance::( - &first_user_addr, - MEX_TOKEN_ID, - 1, - &rust_biguint!(0), - None, - ); + gov_setup + .b_mock + .check_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &rust_biguint!(0)); gov_setup.increment_block_nonce(VOTING_PERIOD_BLOCKS); @@ -643,13 +602,9 @@ fn gov_withdraw_no_with_veto_penalty_limits_test() { .assert_ok(); // Check proposer balance (fee) - gov_setup.b_mock.check_nft_balance::( - &first_user_addr, - MEX_TOKEN_ID, - 1, - &min_fee, - None, - ); + gov_setup + .b_mock + .check_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &min_fee); } #[test] @@ -660,13 +615,9 @@ fn gov_propose_cancel_proposal_id_test() { 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, - MEX_TOKEN_ID, - 1, - &(min_fee.clone() * 3u64), - &Empty, - ); + gov_setup + .b_mock + .set_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &(&min_fee * 3u64)); let (result, proposal_id) = gov_setup.propose( &first_user_addr, @@ -710,13 +661,9 @@ fn gov_propose_cancel_proposal_id_test() { .assert_ok(); // Check proposer balance (fee = 0) - gov_setup.b_mock.check_nft_balance::( - &first_user_addr, - MEX_TOKEN_ID, - 1, - &rust_biguint!(0), - None, - ); + gov_setup + .b_mock + .check_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &rust_biguint!(0)); gov_setup.cancel_proposal(&first_user_addr, 2).assert_ok(); @@ -734,13 +681,9 @@ fn gov_propose_cancel_proposal_id_test() { .assert_ok(); // Check proposer balance (fee should be refunded) - gov_setup.b_mock.check_nft_balance::( - &first_user_addr, - MEX_TOKEN_ID, - 1, - &min_fee, - None, - ); + gov_setup + .b_mock + .check_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &min_fee); assert_eq!(proposal_id, 3); gov_setup .check_proposal_id_consistency(&first_user_addr, proposal_id) 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 d31d0f77d..3c13e70c7 100644 --- a/energy-integration/governance-v2/tests/gov_test_setup/mod.rs +++ b/energy-integration/governance-v2/tests/gov_test_setup/mod.rs @@ -28,6 +28,7 @@ pub const VOTING_PERIOD_BLOCKS: u64 = 144_000; // 10 days pub const LOCKING_PERIOD_BLOCKS: u64 = 30; pub const WITHDRAW_PERCENTAGE: u64 = 5_000; // 50% pub const MEX_TOKEN_ID: &[u8] = b"MEX-123456"; +pub const XMEX_TOKEN_ID: &[u8] = b"XMEX-123456"; pub const DECIMALS_CONST: u64 = 1_000_000_000_000_000_000; pub const FULL_PERCENTAGE: u64 = 10_000; pub const USER_ENERGY: u64 = 1_000_000; @@ -116,7 +117,7 @@ where b_mock .execute_tx(&owner, &fees_collector_wrapper, &rust_biguint!(0), |sc| { sc.init( - managed_token_id!(MEX_TOKEN_ID), + managed_token_id!(XMEX_TOKEN_ID), managed_address!(energy_factory_wrapper.address_ref()), ); }) @@ -182,9 +183,8 @@ where .assert_ok(); let vote_nft_roles = [ - EsdtLocalRole::NftCreate, - EsdtLocalRole::NftBurn, - EsdtLocalRole::NftUpdateAttributes, + EsdtLocalRole::Mint, + EsdtLocalRole::Burn, ]; b_mock.set_esdt_local_roles( gov_wrapper.address_ref(), @@ -217,7 +217,7 @@ where proposer, &self.gov_wrapper, MEX_TOKEN_ID, - 1u64, + 0, fee_amount, |sc| { let mut args_managed = ManagedVec::new();