Newer
Older
contribute_fund::<T>(&contributor, fund_index);
Shaun Wang
committed
frame_system::Pallet::<T>::set_block_number(200u32.into());
}: _(RawOrigin::Signed(caller), contributor.clone(), fund_index)
verify {
assert_last_event::<T>(Event::<T>::Withdrew(contributor, fund_index, T::MinContribution::get()).into());
// Worst case: Refund removes `RemoveKeysLimit` keys, and is fully refunded.
let k in 0 .. T::RemoveKeysLimit::get();
let (lpl, offset) = T::Auctioneer::lease_period_length();
let end = lpl + offset;
let fund_index = create_fund::<T>(1337, end);
// Dissolve will remove at most `RemoveKeysLimit` at once.
contribute_fund::<T>(&account("contributor", i, 0), fund_index);
}
let caller: T::AccountId = whitelisted_caller();
frame_system::Pallet::<T>::set_block_number(200u32.into());
}: _(RawOrigin::Signed(caller), fund_index)
verify {
assert_last_event::<T>(Event::<T>::AllRefunded(fund_index).into());
let (lpl, offset) = T::Auctioneer::lease_period_length();
let end = lpl + offset;
let fund_index = create_fund::<T>(1337, end);
let caller: T::AccountId = whitelisted_caller();
Shaun Wang
committed
frame_system::Pallet::<T>::set_block_number(T::BlockNumber::max_value());
}: _(RawOrigin::Signed(caller.clone()), fund_index)
verify {
assert_last_event::<T>(Event::<T>::Dissolved(fund_index).into());
edit {
let para_id = ParaId::from(1);
let cap = BalanceOf::<T>::max_value();
let first_period = 0u32.into();
let last_period = 3u32.into();
let (lpl, offset) = T::Auctioneer::lease_period_length();
let end = lpl + offset;
let caller: T::AccountId = whitelisted_caller();
let head_data = T::Registrar::worst_head_data();
let validation_code = T::Registrar::worst_validation_code();
let verifier: MultiSigner = account("verifier", 0, 0);
CurrencyOf::<T>::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
T::Registrar::register(caller.clone(), para_id, head_data, validation_code)?;
T::Registrar::execute_pending_transitions();
Crowdloan::<T>::create(
RawOrigin::Signed(caller).into(),
para_id, cap, first_period, last_period, end, Some(verifier.clone()),
)?;
// Doesn't matter what we edit to, so use the same values.
}: _(RawOrigin::Root, para_id, cap, first_period, last_period, end, Some(verifier))
assert_last_event::<T>(Event::<T>::Edited(para_id).into())
let (lpl, offset) = T::Auctioneer::lease_period_length();
let end = lpl + offset;
let fund_index = create_fund::<T>(1, end);
let caller: T::AccountId = whitelisted_caller();
contribute_fund::<T>(&caller, fund_index);
let worst_memo = vec![42; T::MaxMemoLength::get().into()];
}: _(RawOrigin::Signed(caller.clone()), fund_index, worst_memo.clone())
verify {
let fund = Funds::<T>::get(fund_index).expect("fund was created...");
assert_eq!(
Crowdloan::<T>::contribution_get(fund.trie_index, &caller),
(T::MinContribution::get(), worst_memo),
);
}
let (lpl, offset) = T::Auctioneer::lease_period_length();
let end = lpl + offset;
let fund_index = create_fund::<T>(1, end);
let caller: T::AccountId = whitelisted_caller();
contribute_fund::<T>(&caller, fund_index);
NewRaise::<T>::kill();
assert!(NewRaise::<T>::get().is_empty());
}: _(RawOrigin::Signed(caller), fund_index)
verify {
assert!(!NewRaise::<T>::get().is_empty());
assert_last_event::<T>(Event::<T>::AddedToNewRaise(fund_index).into())
// Worst case scenario: N funds are all in the `NewRaise` list, we are
// in the beginning of the ending period, and each fund outbids the next
on_initialize {
// We test the complexity over different number of new raise
let n in 2 .. 100;
let (lpl, offset) = T::Auctioneer::lease_period_length();
let end_block = lpl + offset - 1u32.into();
let pubkey = crypto::create_ed25519_pubkey(b"//verifier".to_vec());
let fund_index = create_fund::<T>(i, end_block);
let contributor: T::AccountId = account("contributor", i, 0);
let contribution = T::MinContribution::get() * (i + 1).into();
let payload = (fund_index, &contributor, BalanceOf::<T>::default(), contribution);
let sig = crypto::create_ed25519_signature(&payload.encode(), pubkey.clone());
CurrencyOf::<T>::make_free_balance_be(&contributor, BalanceOf::<T>::max_value());
Crowdloan::<T>::contribute(RawOrigin::Signed(contributor).into(), fund_index, contribution, Some(sig))?;
let now = frame_system::Pallet::<T>::block_number();
let (lease_period_index, _) = T::Auctioneer::lease_period_index(now).unwrap_or_default();
Shaun Wang
committed
.checked_sub(&frame_system::Pallet::<T>::block_number())
.ok_or("duration of auction less than zero")?;
T::Auctioneer::new_auction(duration, lease_period_index)?;
assert_eq!(T::Auctioneer::auction_status(end_block).is_ending(), Some((0u32.into(), 0u32.into())));
assert_eq!(NewRaise::<T>::get().len(), n as usize);
let old_endings_count = EndingsCount::<T>::get();
}: {
Crowdloan::<T>::on_initialize(end_block);
} verify {
assert_eq!(EndingsCount::<T>::get(), old_endings_count + 1);
assert_last_event::<T>(Event::<T>::HandleBidResult((n - 1).into(), Ok(())).into());
impl_benchmark_test_suite!(
Crowdloan,
crate::integration_tests::new_test_ext_with_offset(10),
crate::integration_tests::Test,
);
}