diff --git a/energy-integration/governance-v2/src/proposal.rs b/energy-integration/governance-v2/src/proposal.rs index 8c60bc280..94c66a131 100644 --- a/energy-integration/governance-v2/src/proposal.rs +++ b/energy-integration/governance-v2/src/proposal.rs @@ -1,3 +1,5 @@ +use multiversx_sc::codec::{DecodeDefault, EncodeDefault}; + multiversx_sc::imports!(); multiversx_sc::derive_imports!(); @@ -50,7 +52,9 @@ impl From> for GovernanceAction } } -#[derive(TypeAbi, TopEncode, TopDecode, PartialEq, Debug)] +#[derive( + TypeAbi, NestedEncode, NestedDecode, PartialEq, Debug, TopEncodeOrDefault, TopDecodeOrDefault, +)] pub struct GovernanceProposal { pub proposal_id: usize, pub proposer: ManagedAddress, @@ -65,3 +69,44 @@ pub struct GovernanceProposal { pub proposal_start_block: u64, pub fee_withdrawn: bool, } + +impl EncodeDefault for GovernanceProposal { + fn is_default(&self) -> bool { + self.proposal_id == 0 + } +} + +impl DecodeDefault for GovernanceProposal { + fn default() -> Self { + Self::new() + } +} + +impl Default for GovernanceProposal { + fn default() -> Self { + Self::new() + } +} + +impl GovernanceProposal { + pub fn new() -> Self { + GovernanceProposal { + proposal_id: 0, + proposer: ManagedAddress::default(), + actions: ArrayVec::default(), + description: ManagedBuffer::default(), + fee_payment: EsdtTokenPayment { + token_identifier: TokenIdentifier::from(""), + token_nonce: 0, + amount: BigUint::zero(), + }, + minimum_quorum: BigUint::default(), + voting_delay_in_blocks: 0, + voting_period_in_blocks: 0, + withdraw_percentage_defeated: 0, + total_quorum: BigUint::default(), + proposal_start_block: 0, + fee_withdrawn: false, + } + } +} diff --git a/energy-integration/governance-v2/tests/gov_rust_test.rs b/energy-integration/governance-v2/tests/gov_rust_test.rs index 929e36945..573278722 100644 --- a/energy-integration/governance-v2/tests/gov_rust_test.rs +++ b/energy-integration/governance-v2/tests/gov_rust_test.rs @@ -722,6 +722,19 @@ fn gov_propose_cancel_proposal_id_test() { gov_setup.cancel_proposal(&first_user_addr, 2).assert_ok(); + // Try to retrieve the cancelled proposal + gov_setup + .b_mock + .execute_tx( + &gov_setup.first_user.clone(), + &gov_setup.gov_wrapper, + &rust_biguint!(0), + |sc| { + sc.proposals().get(2); + }, + ) + .assert_ok(); + // Check proposer balance (fee should be refunded) gov_setup.b_mock.check_nft_balance::( &first_user_addr, @@ -730,6 +743,10 @@ fn gov_propose_cancel_proposal_id_test() { &min_fee, None, ); + assert_eq!(proposal_id, 3); + gov_setup + .check_proposal_id_consistency(&first_user_addr, proposal_id) + .assert_ok(); // Proposal ID = 4 let (result, proposal_id) = gov_setup.propose( @@ -747,6 +764,19 @@ fn gov_propose_cancel_proposal_id_test() { gov_setup.cancel_proposal(&first_user_addr, 4).assert_ok(); + // Try to retrieve the cancelled proposal + gov_setup + .b_mock + .execute_tx( + &gov_setup.first_user.clone(), + &gov_setup.gov_wrapper, + &rust_biguint!(0), + |sc| { + sc.proposals().get(4); + }, + ) + .assert_ok(); + // Proposal ID = 5 let (result, proposal_id) = gov_setup.propose( &first_user_addr,