Add field names to pallet Event variants (#9993)

* convert pallet-assets events to struct types

* updated events of a couple pallets

* updated pallet event field names

* update pallet event field names

* updated events in test files

* cargo fmt

* minorfixes

* fix assertion error

* minor fix

* formatting fix

* fmt
This commit is contained in:
David Salami
2021-11-16 02:56:00 +01:00
committed by GitHub
parent fb3c7326c2
commit 120894fdb7
48 changed files with 1181 additions and 681 deletions
+3 -3
View File
@@ -172,7 +172,7 @@ benchmarks! {
let bounty_id = BountyCount::<T>::get() - 1;
}: close_bounty(RawOrigin::Root, bounty_id)
verify {
assert_last_event::<T>(Event::BountyCanceled(bounty_id).into())
assert_last_event::<T>(Event::BountyCanceled { index: bounty_id }.into())
}
extend_bounty_expiry {
@@ -184,7 +184,7 @@ benchmarks! {
let curator = T::Lookup::lookup(curator_lookup).map_err(<&str>::from)?;
}: _(RawOrigin::Signed(curator), bounty_id, Vec::new())
verify {
assert_last_event::<T>(Event::BountyExtended(bounty_id).into())
assert_last_event::<T>(Event::BountyExtended { index: bounty_id }.into())
}
spend_funds {
@@ -207,7 +207,7 @@ benchmarks! {
verify {
ensure!(budget_remaining < BalanceOf::<T>::max_value(), "Budget not used");
ensure!(missed_any == false, "Missed some");
assert_last_event::<T>(Event::BountyBecameActive(b - 1).into())
assert_last_event::<T>(Event::BountyBecameActive { index: b - 1 }.into())
}
impl_benchmark_test_suite!(Bounties, crate::tests::new_test_ext(), crate::tests::Test)
+28 -21
View File
@@ -228,20 +228,20 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// New bounty proposal. \[index\]
BountyProposed(BountyIndex),
/// A bounty proposal was rejected; funds were slashed. \[index, bond\]
BountyRejected(BountyIndex, BalanceOf<T>),
/// A bounty proposal is funded and became active. \[index\]
BountyBecameActive(BountyIndex),
/// A bounty is awarded to a beneficiary. \[index, beneficiary\]
BountyAwarded(BountyIndex, T::AccountId),
/// A bounty is claimed by beneficiary. \[index, payout, beneficiary\]
BountyClaimed(BountyIndex, BalanceOf<T>, T::AccountId),
/// A bounty is cancelled. \[index\]
BountyCanceled(BountyIndex),
/// A bounty expiry is extended. \[index\]
BountyExtended(BountyIndex),
/// New bounty proposal.
BountyProposed { index: BountyIndex },
/// A bounty proposal was rejected; funds were slashed.
BountyRejected { index: BountyIndex, bond: BalanceOf<T> },
/// A bounty proposal is funded and became active.
BountyBecameActive { index: BountyIndex },
/// A bounty is awarded to a beneficiary.
BountyAwarded { index: BountyIndex, beneficiary: T::AccountId },
/// A bounty is claimed by beneficiary.
BountyClaimed { index: BountyIndex, payout: BalanceOf<T>, beneficiary: T::AccountId },
/// A bounty is cancelled.
BountyCanceled { index: BountyIndex },
/// A bounty expiry is extended.
BountyExtended { index: BountyIndex },
}
/// Number of bounty proposals that have been made.
@@ -526,7 +526,7 @@ pub mod pallet {
Ok(())
})?;
Self::deposit_event(Event::<T>::BountyAwarded(bounty_id, beneficiary));
Self::deposit_event(Event::<T>::BountyAwarded { index: bounty_id, beneficiary });
Ok(())
}
@@ -571,7 +571,11 @@ pub mod pallet {
BountyDescriptions::<T>::remove(bounty_id);
Self::deposit_event(Event::<T>::BountyClaimed(bounty_id, payout, beneficiary));
Self::deposit_event(Event::<T>::BountyClaimed {
index: bounty_id,
payout,
beneficiary,
});
Ok(())
} else {
Err(Error::<T>::UnexpectedStatus.into())
@@ -612,7 +616,10 @@ pub mod pallet {
T::OnSlash::on_unbalanced(imbalance);
*maybe_bounty = None;
Self::deposit_event(Event::<T>::BountyRejected(bounty_id, value));
Self::deposit_event(Event::<T>::BountyRejected {
index: bounty_id,
bond: value,
});
// Return early, nothing else to do.
return Ok(
Some(<T as Config>::WeightInfo::close_bounty_proposed()).into()
@@ -656,7 +663,7 @@ pub mod pallet {
debug_assert!(res.is_ok());
*maybe_bounty = None;
Self::deposit_event(Event::<T>::BountyCanceled(bounty_id));
Self::deposit_event(Event::<T>::BountyCanceled { index: bounty_id });
Ok(Some(<T as Config>::WeightInfo::close_bounty_active()).into())
},
)
@@ -696,7 +703,7 @@ pub mod pallet {
Ok(())
})?;
Self::deposit_event(Event::<T>::BountyExtended(bounty_id));
Self::deposit_event(Event::<T>::BountyExtended { index: bounty_id });
Ok(())
}
}
@@ -753,7 +760,7 @@ impl<T: Config> Pallet<T> {
Bounties::<T>::insert(index, &bounty);
BountyDescriptions::<T>::insert(index, description);
Self::deposit_event(Event::<T>::BountyProposed(index));
Self::deposit_event(Event::<T>::BountyProposed { index });
Ok(())
}
@@ -787,7 +794,7 @@ impl<T: Config> pallet_treasury::SpendFunds<T> for Pallet<T> {
bounty.value,
));
Self::deposit_event(Event::<T>::BountyBecameActive(index));
Self::deposit_event(Event::<T>::BountyBecameActive { index });
false
} else {
*missed_any = true;
+11 -5
View File
@@ -398,7 +398,7 @@ fn propose_bounty_works() {
assert_ok!(Bounties::propose_bounty(Origin::signed(0), 10, b"1234567890".to_vec()));
assert_eq!(last_event(), BountiesEvent::BountyProposed(0));
assert_eq!(last_event(), BountiesEvent::BountyProposed { index: 0 });
let deposit: u64 = 85 + 5;
assert_eq!(Balances::reserved_balance(0), deposit);
@@ -460,7 +460,7 @@ fn close_bounty_works() {
let deposit: u64 = 80 + 5;
assert_eq!(last_event(), BountiesEvent::BountyRejected(0, deposit));
assert_eq!(last_event(), BountiesEvent::BountyRejected { index: 0, bond: deposit });
assert_eq!(Balances::reserved_balance(0), 0);
assert_eq!(Balances::free_balance(0), 100 - deposit);
@@ -692,7 +692,10 @@ fn award_and_claim_bounty_works() {
assert_ok!(Bounties::claim_bounty(Origin::signed(1), 0));
assert_eq!(last_event(), BountiesEvent::BountyClaimed(0, 56, 3));
assert_eq!(
last_event(),
BountiesEvent::BountyClaimed { index: 0, payout: 56, beneficiary: 3 }
);
assert_eq!(Balances::free_balance(4), 14); // initial 10 + fee 4
@@ -731,7 +734,10 @@ fn claim_handles_high_fee() {
assert_ok!(Bounties::claim_bounty(Origin::signed(1), 0));
assert_eq!(last_event(), BountiesEvent::BountyClaimed(0, 0, 3));
assert_eq!(
last_event(),
BountiesEvent::BountyClaimed { index: 0, payout: 0, beneficiary: 3 }
);
assert_eq!(Balances::free_balance(4), 70); // 30 + 50 - 10
assert_eq!(Balances::free_balance(3), 0);
@@ -808,7 +814,7 @@ fn award_and_cancel() {
assert_ok!(Bounties::unassign_curator(Origin::root(), 0));
assert_ok!(Bounties::close_bounty(Origin::root(), 0));
assert_eq!(last_event(), BountiesEvent::BountyCanceled(0));
assert_eq!(last_event(), BountiesEvent::BountyCanceled { index: 0 });
assert_eq!(Balances::free_balance(Bounties::bounty_account_id(0)), 0);