Skip to content

Commit

Permalink
Governance-v2: Fix GovernanceProposal default
Browse files Browse the repository at this point in the history
  • Loading branch information
CostinCarabas committed Oct 30, 2023
1 parent 77c159b commit 6d87cf5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
12 changes: 10 additions & 2 deletions energy-integration/governance-v2/src/proposal.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use multiversx_sc::codec::{EncodeDefault, DecodeDefault};

multiversx_sc::imports!();
multiversx_sc::derive_imports!();

Expand Down Expand Up @@ -50,7 +52,7 @@ impl<M: ManagedTypeApi> From<GovernanceActionAsMultiArg<M>> for GovernanceAction
}
}

#[derive(TypeAbi, TopEncode, TopDecode, NestedEncode, NestedDecode, PartialEq, Debug)]
#[derive(TypeAbi, NestedEncode, NestedDecode, PartialEq, Debug, TopEncodeOrDefault, TopDecodeOrDefault)]
pub struct GovernanceProposal<M: ManagedTypeApi> {
pub proposal_id: usize,
pub proposer: ManagedAddress<M>,
Expand All @@ -66,7 +68,13 @@ pub struct GovernanceProposal<M: ManagedTypeApi> {
pub fee_withdrawn: bool,
}

impl<M: ManagedTypeApi> Default for GovernanceProposal<M> {
impl<M: ManagedTypeApi> EncodeDefault for GovernanceProposal<M> {
fn is_default(&self) -> bool {
self.proposal_id == 0
}
}

impl<M: ManagedTypeApi> DecodeDefault for GovernanceProposal<M> {
fn default() -> Self {
Self::new()
}
Expand Down
29 changes: 25 additions & 4 deletions energy-integration/governance-v2/tests/gov_rust_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,9 +723,17 @@ 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();
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::<Empty>(
Expand All @@ -740,7 +748,6 @@ fn gov_propose_cancel_proposal_id_test() {
.check_proposal_id_consistency(&first_user_addr, proposal_id)
.assert_ok();


// Proposal ID = 4
let (result, proposal_id) = gov_setup.propose(
&first_user_addr,
Expand All @@ -757,6 +764,20 @@ 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,
Expand Down

0 comments on commit 6d87cf5

Please sign in to comment.