Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d32c5c2
convert pallet-assets events to struct types
Wizdave97 Oct 6, 2021
d9ec48f
updated events of a couple pallets
Wizdave97 Oct 9, 2021
39ad825
updated pallet event field names
Wizdave97 Oct 11, 2021
5572b6d
update pallet event field names
Wizdave97 Oct 11, 2021
98b3178
updated events in test files
Wizdave97 Oct 26, 2021
e1c8fa6
cargo fmt
Wizdave97 Oct 26, 2021
dbe4f5a
Merge branch 'master' of https://github.com/paritytech/substrate into…
Wizdave97 Oct 29, 2021
8290edd
minorfixes
Wizdave97 Nov 1, 2021
6367485
Merge branch 'master' of https://github.com/paritytech/substrate into…
Wizdave97 Nov 1, 2021
1937c41
merge changes from master
Wizdave97 Nov 4, 2021
b34a471
fix assertion error
Wizdave97 Nov 5, 2021
cb1731d
minor fix
Wizdave97 Nov 5, 2021
474ded6
Merge branch 'master' of https://github.com/paritytech/substrate into…
Wizdave97 Nov 9, 2021
4ac4479
Merge branch 'master' of https://github.com/paritytech/substrate into…
Wizdave97 Nov 10, 2021
8189bed
Merge branch 'master' of https://github.com/paritytech/substrate into…
Wizdave97 Nov 11, 2021
0128a1d
formatting fix
Wizdave97 Nov 11, 2021
a98368c
Merge branch 'master' of https://github.com/paritytech/substrate into…
Wizdave97 Nov 11, 2021
510d053
fmt
Wizdave97 Nov 12, 2021
fd0b3b3
Merge branch 'master' of https://github.com/paritytech/substrate into…
Wizdave97 Nov 12, 2021
a44f50e
fix conflicts
Wizdave97 Nov 15, 2021
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
Prev Previous commit
Next Next commit
updated pallet event field names
  • Loading branch information
Wizdave97 committed Oct 26, 2021
commit 39ad82501024c02b3365645a4abccb31e795c96c
6 changes: 3 additions & 3 deletions frame/bounties/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assert_last_event::<T>(Event::BountyCanceled{index: bounty_id}.into())
assert_last_event::<T>(Event::BountyCanceled{ index: bounty_id }.into())

Copy link
Contributor

Choose a reason for hiding this comment

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

Same in the rest of the file

}

extend_bounty_expiry {
Expand All @@ -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 {
Expand All @@ -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)
Expand Down
42 changes: 21 additions & 21 deletions frame/bounties/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(())
}

Expand Down Expand Up @@ -571,7 +571,7 @@ 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())
Expand Down Expand Up @@ -612,7 +612,7 @@ 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()
Expand Down Expand Up @@ -656,7 +656,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())
},
)
Expand Down Expand Up @@ -696,7 +696,7 @@ pub mod pallet {
Ok(())
})?;

Self::deposit_event(Event::<T>::BountyExtended(bounty_id));
Self::deposit_event(Event::<T>::BountyExtended{index: bounty_id});
Ok(())
}
}
Expand Down Expand Up @@ -753,7 +753,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(())
}
Expand Down Expand Up @@ -787,7 +787,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;
Expand Down
10 changes: 5 additions & 5 deletions frame/bounties/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -692,7 +692,7 @@ 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

Expand Down Expand Up @@ -731,7 +731,7 @@ 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);
Expand Down Expand Up @@ -808,7 +808,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);

Expand Down
16 changes: 8 additions & 8 deletions frame/collective/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ benchmarks_instance_pallet! {
let proposal_hash = T::Hashing::hash_of(&proposal);
// Note that execution fails due to mis-matched origin
assert_last_event::<T, I>(
Event::MemberExecuted(proposal_hash, Err(DispatchError::BadOrigin)).into()
Event::MemberExecuted{proposal_hash, result: Err(DispatchError::BadOrigin)}.into()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Event::MemberExecuted{proposal_hash, result: Err(DispatchError::BadOrigin)}.into()
Event::MemberExecuted{ proposal_hash, result: Err(DispatchError::BadOrigin) }.into()

Copy link
Contributor

Choose a reason for hiding this comment

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

Same for the rest of the file

);
}

Expand Down Expand Up @@ -159,7 +159,7 @@ benchmarks_instance_pallet! {
let proposal_hash = T::Hashing::hash_of(&proposal);
// Note that execution fails due to mis-matched origin
assert_last_event::<T, I>(
Event::Executed(proposal_hash, Err(DispatchError::BadOrigin)).into()
Event::Executed{proposal_hash, result: Err(DispatchError::BadOrigin)}.into()
);
}

Expand Down Expand Up @@ -203,7 +203,7 @@ benchmarks_instance_pallet! {
// New proposal is recorded
assert_eq!(Collective::<T, I>::proposals().len(), p as usize);
let proposal_hash = T::Hashing::hash_of(&proposal);
assert_last_event::<T, I>(Event::Proposed(caller, p - 1, proposal_hash, threshold).into());
assert_last_event::<T, I>(Event::Proposed{account: caller, proposal_index: p - 1, proposal_hash, threshold}.into());
}

vote {
Expand Down Expand Up @@ -359,7 +359,7 @@ benchmarks_instance_pallet! {
verify {
// The last proposal is removed.
assert_eq!(Collective::<T, I>::proposals().len(), (p - 1) as usize);
assert_last_event::<T, I>(Event::Disapproved(last_hash).into());
assert_last_event::<T, I>(Event::Disapproved{proposal_hash: last_hash}.into());
}

close_early_approved {
Expand Down Expand Up @@ -440,7 +440,7 @@ benchmarks_instance_pallet! {
verify {
// The last proposal is removed.
assert_eq!(Collective::<T, I>::proposals().len(), (p - 1) as usize);
assert_last_event::<T, I>(Event::Executed(last_hash, Err(DispatchError::BadOrigin)).into());
assert_last_event::<T, I>(Event::Executed{proposal_hash: last_hash, result: Err(DispatchError::BadOrigin)}.into());
}

close_disapproved {
Expand Down Expand Up @@ -514,7 +514,7 @@ benchmarks_instance_pallet! {
}: close(SystemOrigin::Signed(caller), last_hash, index, Weight::max_value(), bytes_in_storage)
verify {
assert_eq!(Collective::<T, I>::proposals().len(), (p - 1) as usize);
assert_last_event::<T, I>(Event::Disapproved(last_hash).into());
assert_last_event::<T, I>(Event::Disapproved{proposal_hash: last_hash}.into());
}

close_approved {
Expand Down Expand Up @@ -586,7 +586,7 @@ benchmarks_instance_pallet! {
}: close(SystemOrigin::Signed(caller), last_hash, p - 1, Weight::max_value(), bytes_in_storage)
verify {
assert_eq!(Collective::<T, I>::proposals().len(), (p - 1) as usize);
assert_last_event::<T, I>(Event::Executed(last_hash, Err(DispatchError::BadOrigin)).into());
assert_last_event::<T, I>(Event::Executed{proposal_hash: last_hash, result: Err(DispatchError::BadOrigin)}.into());
}

disapprove_proposal {
Expand Down Expand Up @@ -634,7 +634,7 @@ benchmarks_instance_pallet! {
}: _(SystemOrigin::Root, last_hash)
verify {
assert_eq!(Collective::<T, I>::proposals().len(), (p - 1) as usize);
assert_last_event::<T, I>(Event::Disapproved(last_hash).into());
assert_last_event::<T, I>(Event::Disapproved{proposal_hash: last_hash}.into());
}

impl_benchmark_test_suite!(Collective, crate::tests::new_test_ext(), crate::tests::Test);
Expand Down
55 changes: 24 additions & 31 deletions frame/collective/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,27 +279,20 @@ pub mod pallet {
pub enum Event<T: Config<I>, I: 'static = ()> {
/// A motion (given hash) has been proposed (by given account) with a threshold (given
/// `MemberCount`).
/// \[account, proposal_index, proposal_hash, threshold\]
Proposed(T::AccountId, ProposalIndex, T::Hash, MemberCount),
Proposed{account: T::AccountId, proposal_index: ProposalIndex, proposal_hash: T::Hash, threshold: MemberCount},
/// A motion (given hash) has been voted on by given account, leaving
/// a tally (yes votes and no votes given respectively as `MemberCount`).
/// \[account, proposal_hash, voted, yes, no\]
Voted(T::AccountId, T::Hash, bool, MemberCount, MemberCount),
Voted{account: T::AccountId, proposal_hash: T::Hash, voted: bool, yes: MemberCount, no: MemberCount},
/// A motion was approved by the required threshold.
/// \[proposal_hash\]
Approved(T::Hash),
Approved{proposal_hash: T::Hash},
/// A motion was not approved by the required threshold.
/// \[proposal_hash\]
Disapproved(T::Hash),
Disapproved{proposal_hash: T::Hash},
/// A motion was executed; result will be `Ok` if it returned without error.
/// \[proposal_hash, result\]
Executed(T::Hash, DispatchResult),
Executed{proposal_hash: T::Hash, result: DispatchResult},
/// A single member did some action; result will be `Ok` if it returned without error.
/// \[proposal_hash, result\]
MemberExecuted(T::Hash, DispatchResult),
MemberExecuted{proposal_hash: T::Hash, result: DispatchResult},
/// A proposal was closed because its threshold was reached or after its duration was up.
/// \[proposal_hash, yes, no\]
Closed(T::Hash, MemberCount, MemberCount),
Closed{proposal_hash: T::Hash, yes: MemberCount, no: MemberCount},
}

/// Old name generated by `decl_event`.
Expand Down Expand Up @@ -435,10 +428,10 @@ pub mod pallet {

let proposal_hash = T::Hashing::hash_of(&proposal);
let result = proposal.dispatch(RawOrigin::Member(who).into());
Self::deposit_event(Event::MemberExecuted(
Self::deposit_event(Event::MemberExecuted{
proposal_hash,
result.map(|_| ()).map_err(|e| e.error),
));
result: result.map(|_| ()).map_err(|e| e.error),
});

Ok(get_result_weight(result)
.map(|w| {
Expand Down Expand Up @@ -514,10 +507,10 @@ pub mod pallet {
if threshold < 2 {
let seats = Self::members().len() as MemberCount;
let result = proposal.dispatch(RawOrigin::Members(1, seats).into());
Self::deposit_event(Event::Executed(
Self::deposit_event(Event::Executed{
proposal_hash,
result.map(|_| ()).map_err(|e| e.error),
));
result: result.map(|_| ()).map_err(|e| e.error),
});

Ok(get_result_weight(result)
.map(|w| {
Expand Down Expand Up @@ -545,7 +538,7 @@ pub mod pallet {
};
<Voting<T, I>>::insert(proposal_hash, votes);

Self::deposit_event(Event::Proposed(who, index, proposal_hash, threshold));
Self::deposit_event(Event::Proposed{account: who, proposal_index: index, proposal_hash, threshold});

Ok(Some(T::WeightInfo::propose_proposed(
proposal_len as u32, // B
Expand Down Expand Up @@ -613,7 +606,7 @@ pub mod pallet {

let yes_votes = voting.ayes.len() as MemberCount;
let no_votes = voting.nays.len() as MemberCount;
Self::deposit_event(Event::Voted(who, proposal, approve, yes_votes, no_votes));
Self::deposit_event(Event::Voted{account: who, proposal_hash: proposal, voted: approve, yes: yes_votes, no: no_votes});

Voting::<T, I>::insert(&proposal, voting);

Expand Down Expand Up @@ -694,7 +687,7 @@ pub mod pallet {
length_bound,
proposal_weight_bound,
)?;
Self::deposit_event(Event::Closed(proposal_hash, yes_votes, no_votes));
Self::deposit_event(Event::Closed{proposal_hash, yes: yes_votes, no: no_votes});
let (proposal_weight, proposal_count) =
Self::do_approve_proposal(seats, yes_votes, proposal_hash, proposal);
return Ok((
Expand All @@ -706,7 +699,7 @@ pub mod pallet {
)
.into())
} else if disapproved {
Self::deposit_event(Event::Closed(proposal_hash, yes_votes, no_votes));
Self::deposit_event(Event::Closed{proposal_hash, yes: yes_votes, no: no_votes});
let proposal_count = Self::do_disapprove_proposal(proposal_hash);
return Ok((
Some(T::WeightInfo::close_early_disapproved(seats, proposal_count)),
Expand Down Expand Up @@ -739,7 +732,7 @@ pub mod pallet {
length_bound,
proposal_weight_bound,
)?;
Self::deposit_event(Event::Closed(proposal_hash, yes_votes, no_votes));
Self::deposit_event(Event::Closed{proposal_hash, yes: yes_votes, no: no_votes});
let (proposal_weight, proposal_count) =
Self::do_approve_proposal(seats, yes_votes, proposal_hash, proposal);
Ok((
Expand All @@ -751,7 +744,7 @@ pub mod pallet {
)
.into())
} else {
Self::deposit_event(Event::Closed(proposal_hash, yes_votes, no_votes));
Self::deposit_event(Event::Closed{proposal_hash, yes: yes_votes, no: no_votes});
let proposal_count = Self::do_disapprove_proposal(proposal_hash);
Ok((Some(T::WeightInfo::close_disapproved(seats, proposal_count)), Pays::No).into())
}
Expand Down Expand Up @@ -841,15 +834,15 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
proposal_hash: T::Hash,
proposal: <T as Config<I>>::Proposal,
) -> (Weight, u32) {
Self::deposit_event(Event::Approved(proposal_hash));
Self::deposit_event(Event::Approved{proposal_hash});

let dispatch_weight = proposal.get_dispatch_info().weight;
let origin = RawOrigin::Members(yes_votes, seats).into();
let result = proposal.dispatch(origin);
Self::deposit_event(Event::Executed(
Self::deposit_event(Event::Executed{
proposal_hash,
result.map(|_| ()).map_err(|e| e.error),
));
result: result.map(|_| ()).map_err(|e| e.error),
});
// default to the dispatch info weight for safety
let proposal_weight = get_result_weight(result).unwrap_or(dispatch_weight); // P1

Expand All @@ -859,7 +852,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {

fn do_disapprove_proposal(proposal_hash: T::Hash) -> u32 {
// disapproved
Self::deposit_event(Event::Disapproved(proposal_hash));
Self::deposit_event(Event::Disapproved{proposal_hash});
Self::remove_proposal(proposal_hash)
}

Expand Down
Loading