Skip to content

Commit e4d802f

Browse files
committed
make crowdloan finalizable when cap is reached but before end
1 parent 6d3ab3a commit e4d802f

File tree

2 files changed

+2
-55
lines changed

2 files changed

+2
-55
lines changed

pallets/crowdloan/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -565,14 +565,12 @@ pub mod pallet {
565565
#[pallet::compact] crowdloan_id: CrowdloanId,
566566
) -> DispatchResult {
567567
let who = ensure_signed(origin)?;
568-
let now = frame_system::Pallet::<T>::block_number();
569568

570569
let mut crowdloan = Self::ensure_crowdloan_exists(crowdloan_id)?;
571570

572-
// Ensure the origin is the creator of the crowdloan and the crowdloan has ended,
573-
// raised the cap and is not finalized.
571+
// Ensure the origin is the creator of the crowdloan and the crowdloan has raised the cap
572+
// and is not finalized.
574573
ensure!(who == crowdloan.creator, Error::<T>::InvalidOrigin);
575-
ensure!(now >= crowdloan.end, Error::<T>::ContributionPeriodNotEnded);
576574
ensure!(crowdloan.raised == crowdloan.cap, Error::<T>::CapNotRaised);
577575
ensure!(!crowdloan.finalized, Error::<T>::AlreadyFinalized);
578576

pallets/crowdloan/src/tests.rs

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,9 +1147,6 @@ fn test_finalize_succeeds() {
11471147
amount
11481148
));
11491149

1150-
// run some more blocks past the end of the contribution period
1151-
run_to_block(60);
1152-
11531150
// finalize the crowdloan
11541151
assert_ok!(Crowdloan::finalize(
11551152
RuntimeOrigin::signed(creator),
@@ -1340,54 +1337,6 @@ fn test_finalize_fails_if_not_creator_origin() {
13401337
});
13411338
}
13421339

1343-
#[test]
1344-
fn test_finalize_fails_if_crowdloan_has_not_ended() {
1345-
TestState::default()
1346-
.with_balance(U256::from(1), 100)
1347-
.with_balance(U256::from(2), 100)
1348-
.build_and_execute(|| {
1349-
// create a crowdloan
1350-
let creator: AccountOf<Test> = U256::from(1);
1351-
let deposit: BalanceOf<Test> = 50;
1352-
let min_contribution: BalanceOf<Test> = 10;
1353-
let cap: BalanceOf<Test> = 100;
1354-
let end: BlockNumberFor<Test> = 50;
1355-
1356-
assert_ok!(Crowdloan::create(
1357-
RuntimeOrigin::signed(creator),
1358-
deposit,
1359-
min_contribution,
1360-
cap,
1361-
end,
1362-
Some(noop_call()),
1363-
None,
1364-
));
1365-
1366-
// run some blocks
1367-
run_to_block(10);
1368-
1369-
// some contribution
1370-
let crowdloan_id: CrowdloanId = 0;
1371-
let contributor: AccountOf<Test> = U256::from(2);
1372-
let amount: BalanceOf<Test> = 50;
1373-
1374-
assert_ok!(Crowdloan::contribute(
1375-
RuntimeOrigin::signed(contributor),
1376-
crowdloan_id,
1377-
amount
1378-
));
1379-
1380-
// run some more blocks before end of contribution period
1381-
run_to_block(10);
1382-
1383-
// try to finalize
1384-
assert_err!(
1385-
Crowdloan::finalize(RuntimeOrigin::signed(creator), crowdloan_id),
1386-
pallet_crowdloan::Error::<Test>::ContributionPeriodNotEnded
1387-
);
1388-
});
1389-
}
1390-
13911340
#[test]
13921341
fn test_finalize_fails_if_crowdloan_cap_is_not_raised() {
13931342
TestState::default()

0 commit comments

Comments
 (0)