Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add edit fund interface & Some fix #457

Merged
merged 2 commits into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions pallets/salp-lite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,46 @@ pub mod pallet {

Ok(())
}

/// Edit the configuration for an in-progress crowdloan.
///
/// Can only be called by Root origin.
#[pallet::weight((
0,
DispatchClass::Normal,
Pays::No
))]
pub fn edit(
origin: OriginFor<T>,
#[pallet::compact] index: ParaId,
#[pallet::compact] cap: BalanceOf<T>,
#[pallet::compact] raised: BalanceOf<T>,
#[pallet::compact] first_slot: LeasePeriod,
#[pallet::compact] last_slot: LeasePeriod,
fund_status: Option<FundStatus>,
) -> DispatchResult {
T::EnsureConfirmAsGovernance::ensure_origin(origin)?;

let fund = Self::funds(index).ok_or(Error::<T>::InvalidParaId)?;

let status = match fund_status {
None => fund.status,
Some(status) => status,
};
Funds::<T>::insert(
index,
Some(FundInfo {
cap,
first_slot,
last_slot,
status,
raised,
trie_index: fund.trie_index,
}),
);
Self::deposit_event(Event::<T>::Edited(index));
Ok(())
}
}

#[pallet::hooks]
Expand Down
22 changes: 22 additions & 0 deletions pallets/salp-lite/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,3 +866,25 @@ fn refund_meanwhile_issue_should_work() {
assert_noop!(Salp::redeem(Some(BRUCE).into(), 3_000, 50), Error::<Test>::InvalidParaId);
});
}

#[test]
fn edit_fund_should_work() {
new_test_ext().execute_with(|| {
assert_ok!(Salp::create(Some(ALICE).into(), 3_000, 1_000, 1, SlotLength::get()));
assert_ok!(Salp::issue(Some(ALICE).into(), BRUCE, 3_000, 100, CONTRIBUTON_INDEX));
assert_ok!(Salp::fund_fail(Some(ALICE).into(), 3_000));

assert_ok!(Salp::edit(
Some(ALICE).into(),
3_000,
1_000,
150,
2,
SlotLength::get() + 1,
Some(FundStatus::Ongoing)
));
let fund = Salp::funds(3_000).unwrap();
assert_eq!(fund.raised, 150);
assert_eq!(fund.status, FundStatus::Ongoing);
});
}
8 changes: 7 additions & 1 deletion pallets/salp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ pub mod pallet {
origin: OriginFor<T>,
#[pallet::compact] index: ParaId,
#[pallet::compact] cap: BalanceOf<T>,
#[pallet::compact] raised: BalanceOf<T>,
#[pallet::compact] first_slot: LeasePeriod,
#[pallet::compact] last_slot: LeasePeriod,
fund_status: Option<FundStatus>,
Expand All @@ -484,7 +485,7 @@ pub mod pallet {
first_slot,
last_slot,
status,
raised: fund.raised,
raised,
trie_index: fund.trie_index,
}),
);
Expand Down Expand Up @@ -792,6 +793,8 @@ pub mod pallet {

fund.raised = fund.raised.saturating_sub(contributed);

Funds::<T>::insert(index, Some(fund.clone()));

T::MultiCurrency::slash_reserved(vsToken, &who, contributed);
T::MultiCurrency::slash_reserved(vsBond, &who, contributed);

Expand Down Expand Up @@ -853,6 +856,8 @@ pub mod pallet {
}
}

Funds::<T>::insert(index, Some(fund));

if all_refunded {
Self::deposit_event(Event::<T>::AllRefunded(index));
}
Expand Down Expand Up @@ -901,6 +906,7 @@ pub mod pallet {
}

fund.raised = fund.raised.saturating_sub(value);
Funds::<T>::insert(index, Some(fund.clone()));

if T::TransactType::get() == ParachainTransactType::Xcm {
T::MultiCurrency::transfer(
Expand Down
12 changes: 11 additions & 1 deletion pallets/salp/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1195,20 +1195,30 @@ fn edit_fund_should_work() {
CONTRIBUTON_INDEX
));
assert_ok!(Salp::fund_fail(Some(ALICE).into(), 3_000));
assert_ok!(Salp::edit(Some(ALICE).into(), 3_000, 1_000, 2, SlotLength::get() + 1, None));
assert_ok!(Salp::edit(
Some(ALICE).into(),
3_000,
1_000,
200,
2,
SlotLength::get() + 1,
None
));
let mut fund = Salp::funds(3_000).unwrap();
assert_eq!(fund.first_slot, 2);
assert_eq!(fund.status, FundStatus::Failed);
assert_ok!(Salp::edit(
Some(ALICE).into(),
3_000,
1_000,
200,
2,
SlotLength::get() + 1,
Some(FundStatus::Ongoing),
));
fund = Salp::funds(3_000).unwrap();
assert_eq!(fund.status, FundStatus::Ongoing);
assert_eq!(fund.raised, 200);
})
}

Expand Down
28 changes: 28 additions & 0 deletions runtime/bifrost/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1987,6 +1987,34 @@ impl_runtime_apis! {
}
}

pub struct CustomOnRuntimeUpgrade;
impl OnRuntimeUpgrade for CustomOnRuntimeUpgrade {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
#[allow(unused_imports)]
use frame_support::{migration, Identity};
log::info!("Bifrost `pre_upgrade`...");
Ok(())
}

fn on_runtime_upgrade() -> Weight {
log::info!("Bifrost `on_runtime_upgrade`...");
Salp::set_multisig_account(ConfirmMuitiSigAccount::get());
SalpLite::set_multisig_account(PolkaConfirmAsMultiSig::get());
log::info!("Bifrost `on_runtime_upgrade finished`");
RocksDbWeight::get().writes(1)
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
let mut account = Salp::multisig_confirm_account();
log::info!("after salp migration multisig account as {:?}", account);
account = SalpLite::multisig_confirm_account();
log::info!("after salp-lite migration multisig account as {:?}", account);
Ok(())
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CustomOnRuntimeUpgrade is not used, remove this section.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not enable in executor and would suggest we reserve the template codes

struct CheckInherents;

impl cumulus_pallet_parachain_system::CheckInherents<Block> for CheckInherents {
Expand Down