Skip to content

Commit cef1fcc

Browse files
committed
make crowdloan refund before the end possible
1 parent e4d802f commit cef1fcc

File tree

2 files changed

+6
-41
lines changed

2 files changed

+6
-41
lines changed

pallets/crowdloan/src/lib.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ pub mod pallet {
547547
Ok(())
548548
}
549549

550-
/// Finalize a successful crowdloan.
550+
/// Finalize crowdloan that has reached the cap.
551551
///
552552
/// The call will transfer the raised amount to the target address if it was provided when the crowdloan was created
553553
/// and dispatch the call that was provided using the creator origin. The CurrentCrowdloanId will be set to the
@@ -619,7 +619,7 @@ pub mod pallet {
619619
Ok(())
620620
}
621621

622-
/// Refund a failed crowdloan.
622+
/// Refund a crowdloan that has not reached the cap and has ended.
623623
///
624624
/// The call will try to refund all contributors (excluding the creator) up to the limit defined by the `RefundContributorsLimit`.
625625
/// If the limit is reached, the call will stop and the crowdloan will be marked as partially refunded.
@@ -635,13 +635,11 @@ pub mod pallet {
635635
origin: OriginFor<T>,
636636
#[pallet::compact] crowdloan_id: CrowdloanId,
637637
) -> DispatchResultWithPostInfo {
638-
let now = frame_system::Pallet::<T>::block_number();
639638
ensure_signed(origin)?;
640639

641640
let mut crowdloan = Self::ensure_crowdloan_exists(crowdloan_id)?;
642641

643-
// Ensure the crowdloan has ended and is not finalized
644-
ensure!(now >= crowdloan.end, Error::<T>::ContributionPeriodNotEnded);
642+
// Ensure the crowdloan is not finalized
645643
ensure!(!crowdloan.finalized, Error::<T>::AlreadyFinalized);
646644

647645
let mut refunded_contributors: Vec<T::AccountId> = vec![];

pallets/crowdloan/src/tests.rs

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,8 +1534,8 @@ fn test_refund_succeeds() {
15341534
.is_some_and(|c| c.contributors_count == 7)
15351535
);
15361536

1537-
// run some more blocks past the end of the contribution period
1538-
run_to_block(60);
1537+
// run some more blocks before the end of the contribution period
1538+
run_to_block(20);
15391539

15401540
// first round of refund
15411541
assert_ok!(Crowdloan::refund(
@@ -1563,7 +1563,7 @@ fn test_refund_succeeds() {
15631563
pallet_crowdloan::Event::<Test>::PartiallyRefunded { crowdloan_id }.into()
15641564
);
15651565

1566-
// run some more blocks
1566+
// run some more blocks past the end of the contribution period
15671567
run_to_block(70);
15681568

15691569
// second round of refund
@@ -1649,39 +1649,6 @@ fn test_refund_fails_if_crowdloan_does_not_exist() {
16491649
});
16501650
}
16511651

1652-
#[test]
1653-
fn test_refund_fails_if_crowdloan_has_not_ended() {
1654-
TestState::default()
1655-
.with_balance(U256::from(1), 100)
1656-
.build_and_execute(|| {
1657-
// create a crowdloan
1658-
let creator: AccountOf<Test> = U256::from(1);
1659-
let initial_deposit: BalanceOf<Test> = 50;
1660-
let min_contribution: BalanceOf<Test> = 10;
1661-
let cap: BalanceOf<Test> = 300;
1662-
let end: BlockNumberFor<Test> = 50;
1663-
assert_ok!(Crowdloan::create(
1664-
RuntimeOrigin::signed(creator),
1665-
initial_deposit,
1666-
min_contribution,
1667-
cap,
1668-
end,
1669-
Some(noop_call()),
1670-
None,
1671-
));
1672-
1673-
// run some blocks
1674-
run_to_block(10);
1675-
1676-
// try to refund
1677-
let crowdloan_id: CrowdloanId = 0;
1678-
assert_err!(
1679-
Crowdloan::refund(RuntimeOrigin::signed(creator), crowdloan_id),
1680-
pallet_crowdloan::Error::<Test>::ContributionPeriodNotEnded
1681-
);
1682-
});
1683-
}
1684-
16851652
#[test]
16861653
fn test_dissolve_succeeds() {
16871654
TestState::default()

0 commit comments

Comments
 (0)