Skip to content

Commit 691fff9

Browse files
authored
Fix for #269 (#273)
* fixes * fmt
1 parent 445f8f6 commit 691fff9

File tree

5 files changed

+53
-43
lines changed

5 files changed

+53
-43
lines changed

Cargo.lock

Lines changed: 0 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ members = [
1717
"pallets/proposals",
1818
"pallets/briefs",
1919
"pallets/grants",
20-
"pallets/crowdfunding",
2120
"pallets/deposits",
2221
"pallets/disputes",
2322
"pallets/fellowship",

pallets/proposals/src/impls/pallet_impls.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,34 +103,29 @@ impl<T: Config> Pallet<T> {
103103
} else {
104104
vote.nay = vote.nay.saturating_add(contribution_amount);
105105
}
106-
107-
//check if the everyone has voted and its still less than the
108-
// funding threshold just reject it
109-
if vote.yay + vote.nay == project.raised_funds && vote.yay < funding_threshold {
110-
Self::close_voting_round(project_key, user_has_voted_key)?;
111-
Self::deposit_event(Event::MilestoneRejected(project_key, milestone_key));
112-
}
113106
Ok::<Vote<BalanceOf<T>>, DispatchError>(vote.clone())
114107
} else {
115108
Err(Error::<T>::VotingRoundNotStarted.into())
116109
}
117110
})?;
118111

112+
Self::deposit_event(Event::VoteSubmitted(
113+
who.clone(),
114+
project_key,
115+
milestone_key,
116+
approve_milestone,
117+
now,
118+
));
119+
119120
Self::try_auto_finalise_milestone_voting(
120121
project_key,
121122
&vote,
122123
funding_threshold,
123124
user_has_voted_key,
124-
who.clone(),
125+
who,
126+
project.raised_funds,
125127
)?;
126128

127-
Self::deposit_event(Event::VoteSubmitted(
128-
who,
129-
project_key,
130-
milestone_key,
131-
approve_milestone,
132-
now,
133-
));
134129
Ok(().into())
135130
}
136131

@@ -437,6 +432,7 @@ impl<T: Config> Pallet<T> {
437432
funding_threshold: BalanceOf<T>,
438433
user_has_voted_key: (ProjectKey, RoundType, MilestoneKey),
439434
who: AccountIdOf<T>,
435+
raised_funds: BalanceOf<T>,
440436
) -> Result<(), DispatchError> {
441437
// If the yay votes is over the funding threshold then the milestone is approved.
442438
if vote.yay >= funding_threshold {
@@ -458,7 +454,9 @@ impl<T: Config> Pallet<T> {
458454
));
459455
}
460456

461-
if vote.nay >= funding_threshold {
457+
if vote.nay >= funding_threshold
458+
|| (vote.yay.saturating_add(vote.nay) == raised_funds && vote.yay < funding_threshold)
459+
{
462460
Self::close_voting_round(project_key, user_has_voted_key)?;
463461
Self::deposit_event(Event::MilestoneRejected(
464462
user_has_voted_key.0,

pallets/proposals/src/mock.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ pub static ALICE: AccountId = 125;
235235
pub static BOB: AccountId = 126;
236236
pub static CHARLIE: AccountId = 127;
237237
pub static DAVE: AccountId = 128;
238+
pub static STEVE: AccountId = 254;
238239
pub static JOHN: AccountId = 255;
239240

240241
pub(crate) fn build_test_externality() -> sp_io::TestExternalities {
@@ -251,6 +252,7 @@ pub(crate) fn build_test_externality() -> sp_io::TestExternalities {
251252
let _ = Tokens::deposit(CurrencyId::Native, &CHARLIE, initial_balance);
252253
let _ = Tokens::deposit(CurrencyId::Native, &DAVE, initial_balance);
253254
let _ = Tokens::deposit(CurrencyId::Native, &JOHN, initial_balance);
255+
let _ = Tokens::deposit(CurrencyId::Native, &STEVE, initial_balance);
254256
});
255257
ext
256258
}

pallets/proposals/src/tests/pallet.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,43 @@ fn vote_on_milestone_actually_adds_to_vote() {
553553
});
554554
}
555555

556+
#[test]
557+
fn vote_on_milestone_autofinalises_on_all_voted_and_fail() {
558+
build_test_externality().execute_with(|| {
559+
let cont = get_contributions::<Test>(vec![BOB, CHARLIE, DAVE], 100_000);
560+
let prop_milestones = get_milestones(10);
561+
let project_key = create_project::<Test>(ALICE, cont, prop_milestones, CurrencyId::Native);
562+
let milestone_key = 0;
563+
assert_ok!(Proposals::submit_milestone(
564+
RuntimeOrigin::signed(ALICE),
565+
project_key,
566+
milestone_key
567+
));
568+
assert_ok!(Proposals::vote_on_milestone(
569+
RuntimeOrigin::signed(BOB),
570+
project_key,
571+
milestone_key,
572+
false
573+
));
574+
assert_ok!(Proposals::vote_on_milestone(
575+
RuntimeOrigin::signed(CHARLIE),
576+
project_key,
577+
milestone_key,
578+
false
579+
));
580+
assert_ok!(Proposals::vote_on_milestone(
581+
RuntimeOrigin::signed(DAVE),
582+
project_key,
583+
milestone_key,
584+
true
585+
));
586+
587+
assert_last_event::<Test>(
588+
Event::<Test>::MilestoneRejected(project_key, milestone_key).into(),
589+
)
590+
});
591+
}
592+
556593
#[test]
557594
fn withdraw_not_initiator() {
558595
build_test_externality().execute_with(|| {

0 commit comments

Comments
 (0)