Migrate some Pallets to Named Events (#5423)

* auctions

* claims

* registrar

* Update purchase.rs

* crowdloan

* slots

* comma
This commit is contained in:
Shawn Tabrizi
2022-05-13 12:49:19 -04:00
committed by GitHub
parent 511891dcce
commit 432cae1a2b
7 changed files with 169 additions and 123 deletions
+41 -38
View File
@@ -254,27 +254,27 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// Create a new crowdloaning campaign. `[fund_index]`
Created(ParaId),
/// Contributed to a crowd sale. `[who, fund_index, amount]`
Contributed(T::AccountId, ParaId, BalanceOf<T>),
/// Withdrew full balance of a contributor. `[who, fund_index, amount]`
Withdrew(T::AccountId, ParaId, BalanceOf<T>),
/// Create a new crowdloaning campaign.
Created { para_id: ParaId },
/// Contributed to a crowd sale.
Contributed { who: T::AccountId, fund_index: ParaId, amount: BalanceOf<T> },
/// Withdrew full balance of a contributor.
Withdrew { who: T::AccountId, fund_index: ParaId, amount: BalanceOf<T> },
/// The loans in a fund have been partially dissolved, i.e. there are some left
/// over child keys that still need to be killed. `[fund_index]`
PartiallyRefunded(ParaId),
/// All loans in a fund have been refunded. `[fund_index]`
AllRefunded(ParaId),
/// Fund is dissolved. `[fund_index]`
Dissolved(ParaId),
/// over child keys that still need to be killed.
PartiallyRefunded { para_id: ParaId },
/// All loans in a fund have been refunded.
AllRefunded { para_id: ParaId },
/// Fund is dissolved.
Dissolved { para_id: ParaId },
/// The result of trying to submit a new bid to the Slots pallet.
HandleBidResult(ParaId, DispatchResult),
/// The configuration to a crowdloan has been edited. `[fund_index]`
Edited(ParaId),
/// A memo has been updated. `[who, fund_index, memo]`
MemoUpdated(T::AccountId, ParaId, Vec<u8>),
HandleBidResult { para_id: ParaId, result: DispatchResult },
/// The configuration to a crowdloan has been edited.
Edited { para_id: ParaId },
/// A memo has been updated.
MemoUpdated { who: T::AccountId, para_id: ParaId, memo: Vec<u8> },
/// A parachain has been moved to `NewRaise`
AddedToNewRaise(ParaId),
AddedToNewRaise { para_id: ParaId },
}
#[pallet::error]
@@ -351,7 +351,7 @@ pub mod pallet {
fund.raised,
);
Self::deposit_event(Event::<T>::HandleBidResult(para_id, result));
Self::deposit_event(Event::<T>::HandleBidResult { para_id, result });
}
T::WeightInfo::on_initialize(new_raise_len)
} else {
@@ -437,7 +437,7 @@ pub mod pallet {
// Add a lock to the para so that the configuration cannot be changed.
T::Registrar::apply_lock(index);
Self::deposit_event(Event::<T>::Created(index));
Self::deposit_event(Event::<T>::Created { para_id: index });
Ok(())
}
@@ -494,7 +494,7 @@ pub mod pallet {
Funds::<T>::insert(index, &fund);
Self::deposit_event(Event::<T>::Withdrew(who, index, balance));
Self::deposit_event(Event::<T>::Withdrew { who, fund_index: index, amount: balance });
Ok(())
}
@@ -536,11 +536,11 @@ pub mod pallet {
Funds::<T>::insert(index, &fund);
if all_refunded {
Self::deposit_event(Event::<T>::AllRefunded(index));
Self::deposit_event(Event::<T>::AllRefunded { para_id: index });
// Refund for unused refund count.
Ok(Some(T::WeightInfo::refund(refund_count)).into())
} else {
Self::deposit_event(Event::<T>::PartiallyRefunded(index));
Self::deposit_event(Event::<T>::PartiallyRefunded { para_id: index });
// No weight to refund since we did not finish the loop.
Ok(().into())
}
@@ -567,7 +567,7 @@ pub mod pallet {
CurrencyOf::<T>::unreserve(&fund.depositor, fund.deposit);
Funds::<T>::remove(index);
Self::deposit_event(Event::<T>::Dissolved(index));
Self::deposit_event(Event::<T>::Dissolved { para_id: index });
Ok(())
}
@@ -604,7 +604,7 @@ pub mod pallet {
},
);
Self::deposit_event(Event::<T>::Edited(index));
Self::deposit_event(Event::<T>::Edited { para_id: index });
Ok(())
}
@@ -622,7 +622,7 @@ pub mod pallet {
ensure!(balance > Zero::zero(), Error::<T>::NoContributions);
Self::contribution_put(fund.fund_index, &who, &balance, &memo);
Self::deposit_event(Event::<T>::MemoUpdated(who, index, memo));
Self::deposit_event(Event::<T>::MemoUpdated { who, para_id: index, memo });
Ok(())
}
@@ -636,7 +636,7 @@ pub mod pallet {
ensure!(!fund.raised.is_zero(), Error::<T>::NoContributions);
ensure!(!NewRaise::<T>::get().contains(&index), Error::<T>::AlreadyInNewRaise);
NewRaise::<T>::append(index);
Self::deposit_event(Event::<T>::AddedToNewRaise(index));
Self::deposit_event(Event::<T>::AddedToNewRaise { para_id: index });
Ok(())
}
@@ -810,7 +810,7 @@ impl<T: Config> Pallet<T> {
Funds::<T>::insert(index, &fund);
Self::deposit_event(Event::<T>::Contributed(who, index, value));
Self::deposit_event(Event::<T>::Contributed { who, fund_index: index, amount: value });
Ok(())
}
}
@@ -1648,14 +1648,17 @@ mod tests {
// Move to the end of the crowdloan
run_to_block(10);
assert_ok!(Crowdloan::refund(Origin::signed(1337), para));
assert_eq!(last_event(), super::Event::<Test>::PartiallyRefunded(para).into());
assert_eq!(
last_event(),
super::Event::<Test>::PartiallyRefunded { para_id: para }.into()
);
// Funds still left over
assert!(!Balances::free_balance(account_id).is_zero());
// Call again
assert_ok!(Crowdloan::refund(Origin::signed(1337), para));
assert_eq!(last_event(), super::Event::<Test>::AllRefunded(para).into());
assert_eq!(last_event(), super::Event::<Test>::AllRefunded { para_id: para }.into());
// Funds are returned
assert_eq!(Balances::free_balance(account_id), 0);
@@ -1983,7 +1986,7 @@ mod benchmarking {
}: _(RawOrigin::Signed(caller), para_id, cap, first_period, last_period, end, Some(verifier))
verify {
assert_last_event::<T>(Event::<T>::Created(para_id).into())
assert_last_event::<T>(Event::<T>::Created { para_id }.into())
}
// Contribute has two arms: PreEnding and Ending, but both are equal complexity.
@@ -2004,7 +2007,7 @@ mod benchmarking {
verify {
// NewRaise is appended to, so we don't need to fill it up for worst case scenario.
assert!(!NewRaise::<T>::get().is_empty());
assert_last_event::<T>(Event::<T>::Contributed(caller, fund_index, contribution).into());
assert_last_event::<T>(Event::<T>::Contributed { who: caller, fund_index, amount: contribution }.into());
}
withdraw {
@@ -2017,7 +2020,7 @@ mod benchmarking {
frame_system::Pallet::<T>::set_block_number(T::BlockNumber::max_value());
}: _(RawOrigin::Signed(caller), contributor.clone(), fund_index)
verify {
assert_last_event::<T>(Event::<T>::Withdrew(contributor, fund_index, T::MinContribution::get()).into());
assert_last_event::<T>(Event::<T>::Withdrew { who: contributor, fund_index, amount: T::MinContribution::get() }.into());
}
// Worst case: Refund removes `RemoveKeysLimit` keys, and is fully refunded.
@@ -2037,7 +2040,7 @@ mod benchmarking {
frame_system::Pallet::<T>::set_block_number(T::BlockNumber::max_value());
}: _(RawOrigin::Signed(caller), fund_index)
verify {
assert_last_event::<T>(Event::<T>::AllRefunded(fund_index).into());
assert_last_event::<T>(Event::<T>::AllRefunded { para_id: fund_index }.into());
}
dissolve {
@@ -2048,7 +2051,7 @@ mod benchmarking {
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());
assert_last_event::<T>(Event::<T>::Dissolved { para_id: fund_index }.into());
}
edit {
@@ -2077,7 +2080,7 @@ mod benchmarking {
// Doesn't matter what we edit to, so use the same values.
}: _(RawOrigin::Root, para_id, cap, first_period, last_period, end, Some(verifier))
verify {
assert_last_event::<T>(Event::<T>::Edited(para_id).into())
assert_last_event::<T>(Event::<T>::Edited { para_id }.into())
}
add_memo {
@@ -2107,7 +2110,7 @@ mod benchmarking {
}: _(RawOrigin::Signed(caller), fund_index)
verify {
assert!(!NewRaise::<T>::get().is_empty());
assert_last_event::<T>(Event::<T>::AddedToNewRaise(fund_index).into())
assert_last_event::<T>(Event::<T>::AddedToNewRaise { para_id: fund_index }.into())
}
// Worst case scenario: N funds are all in the `NewRaise` list, we are
@@ -2146,7 +2149,7 @@ mod benchmarking {
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());
assert_last_event::<T>(Event::<T>::HandleBidResult { para_id: (n - 1).into(), result: Ok(()) }.into());
}
impl_benchmark_test_suite!(