Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
f-gate committed Nov 21, 2023
1 parent 445f8f6 commit f5ebbce
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 43 deletions.
26 changes: 0 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ members = [
"pallets/proposals",
"pallets/briefs",
"pallets/grants",
"pallets/crowdfunding",
"pallets/deposits",
"pallets/disputes",
"pallets/fellowship",
Expand Down
29 changes: 13 additions & 16 deletions pallets/proposals/src/impls/pallet_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,34 +103,30 @@ impl<T: Config> Pallet<T> {
} else {
vote.nay = vote.nay.saturating_add(contribution_amount);
}

//check if the everyone has voted and its still less than the
// funding threshold just reject it
if vote.yay + vote.nay == project.raised_funds && vote.yay < funding_threshold {
Self::close_voting_round(project_key, user_has_voted_key)?;
Self::deposit_event(Event::MilestoneRejected(project_key, milestone_key));
}
Ok::<Vote<BalanceOf<T>>, DispatchError>(vote.clone())
} else {
Err(Error::<T>::VotingRoundNotStarted.into())
}
})?;

Self::deposit_event(Event::VoteSubmitted(
who.clone(),
project_key,
milestone_key,
approve_milestone,
now,
));

Self::try_auto_finalise_milestone_voting(
project_key,
&vote,
funding_threshold,
user_has_voted_key,
who.clone(),
who,
project.raised_funds,
)?;

Self::deposit_event(Event::VoteSubmitted(
who,
project_key,
milestone_key,
approve_milestone,
now,
));

Ok(().into())
}

Expand Down Expand Up @@ -437,6 +433,7 @@ impl<T: Config> Pallet<T> {
funding_threshold: BalanceOf<T>,
user_has_voted_key: (ProjectKey, RoundType, MilestoneKey),
who: AccountIdOf<T>,
raised_funds: BalanceOf<T>,
) -> Result<(), DispatchError> {
// If the yay votes is over the funding threshold then the milestone is approved.
if vote.yay >= funding_threshold {
Expand All @@ -458,7 +455,7 @@ impl<T: Config> Pallet<T> {
));
}

if vote.nay >= funding_threshold {
if vote.nay >= funding_threshold || (vote.yay.saturating_add(vote.nay) == raised_funds && vote.yay < funding_threshold) {
Self::close_voting_round(project_key, user_has_voted_key)?;
Self::deposit_event(Event::MilestoneRejected(
user_has_voted_key.0,
Expand Down
2 changes: 2 additions & 0 deletions pallets/proposals/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ pub static ALICE: AccountId = 125;
pub static BOB: AccountId = 126;
pub static CHARLIE: AccountId = 127;
pub static DAVE: AccountId = 128;
pub static STEVE: AccountId = 254;
pub static JOHN: AccountId = 255;

pub(crate) fn build_test_externality() -> sp_io::TestExternalities {
Expand All @@ -251,6 +252,7 @@ pub(crate) fn build_test_externality() -> sp_io::TestExternalities {
let _ = Tokens::deposit(CurrencyId::Native, &CHARLIE, initial_balance);
let _ = Tokens::deposit(CurrencyId::Native, &DAVE, initial_balance);
let _ = Tokens::deposit(CurrencyId::Native, &JOHN, initial_balance);
let _ = Tokens::deposit(CurrencyId::Native, &STEVE, initial_balance);
});
ext
}
Expand Down
40 changes: 40 additions & 0 deletions pallets/proposals/src/tests/pallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,46 @@ fn vote_on_milestone_actually_adds_to_vote() {
});
}

#[test]
fn vote_on_milestone_autofinalises_on_all_voted_and_fail() {
build_test_externality().execute_with(|| {
let cont = get_contributions::<Test>(vec![BOB, CHARLIE, DAVE], 100_000);
let prop_milestones = get_milestones(10);
let project_key = create_project::<Test>(ALICE, cont, prop_milestones, CurrencyId::Native);
let milestone_key = 0;
assert_ok!(Proposals::submit_milestone(
RuntimeOrigin::signed(ALICE),
project_key,
milestone_key
));
assert_ok!(Proposals::vote_on_milestone(
RuntimeOrigin::signed(BOB),
project_key,
milestone_key,
false
));
assert_ok!(Proposals::vote_on_milestone(
RuntimeOrigin::signed(CHARLIE),
project_key,
milestone_key,
false
));
assert_ok!(Proposals::vote_on_milestone(
RuntimeOrigin::signed(DAVE),
project_key,
milestone_key,
true
));



assert_last_event::<Test>(
Event::<Test>::MilestoneRejected(project_key, milestone_key).into()
)
});
}


#[test]
fn withdraw_not_initiator() {
build_test_externality().execute_with(|| {
Expand Down

0 comments on commit f5ebbce

Please sign in to comment.