Skip to content

Commit

Permalink
Add pallet names to Events (paritytech#10296)
Browse files Browse the repository at this point in the history
* chore: add pallet names to events

* chore: add pallet names to events

* chore: add pallet names to events

* chore: add pallet names to events

* chore: add pallet names to events

* chore: add pallet names to events

* chore: add pallet names to events

* chore: add pallet names to events

* chore: add pallet names to events

* chore: add pallet names to events

* chore: add pallet names to events

* chore: add pallet names to events

* chore: add pallet names to events

* chore: add pallet names to events

* chore: formatted pallet name changes in events

* chore: formatted pallet name changes in events

* chore: formatted pallet name changes in events

* chore: formatted pallet name changes in events

* chore: formatted pallet name changes in events

* chore: formatted pallet name changes in events

* chore: formatted pallet name changes in events

* chore: formatted pallet name changes in events

* chore: formatted pallet name changes in events

* fix: add fix to tests for event variants

* chore: modified comments for event variants

* chore: modified comments for event variants

* chore: modified comments for event variants

* chore: modified comments for event variants

* chore: modified system pallet event variants

* chore: modified system pallet event variants

* chore: modified system pallet event variants

* chore: modified system pallet event variants

* chore: modified system pallet event variants

* chore: modified system pallet event variants

* chore: modified system pallet event variants

* chore: modified system pallet event variants

* chore: modified system pallet event variants

* chore: updated transaction-storage pallet event variants

* chore: updated transaction-storage pallet event variants

* chore: formatted contracts pallet

* chore: update treasury event variants
  • Loading branch information
ECJ222 authored and ark0f committed Feb 27, 2023
1 parent 8a9519a commit cf4dce5
Show file tree
Hide file tree
Showing 15 changed files with 209 additions and 184 deletions.
51 changes: 26 additions & 25 deletions bin/node/executor/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,13 @@ fn full_native_block_import_works() {
let events = vec![
EventRecord {
phase: Phase::ApplyExtrinsic(0),
event: Event::System(frame_system::Event::ExtrinsicSuccess(DispatchInfo {
weight: timestamp_weight,
class: DispatchClass::Mandatory,
..Default::default()
})),
event: Event::System(frame_system::Event::ExtrinsicSuccess {
dispatch_info: DispatchInfo {
weight: timestamp_weight,
class: DispatchClass::Mandatory,
..Default::default()
},
}),
topics: vec![],
},
EventRecord {
Expand Down Expand Up @@ -412,15 +414,14 @@ fn full_native_block_import_works() {
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::Treasury(pallet_treasury::Event::Deposit(fees * 8 / 10)),
event: Event::Treasury(pallet_treasury::Event::Deposit { value: fees * 8 / 10 }),
topics: vec![],
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::System(frame_system::Event::ExtrinsicSuccess(DispatchInfo {
weight: transfer_weight,
..Default::default()
})),
event: Event::System(frame_system::Event::ExtrinsicSuccess {
dispatch_info: DispatchInfo { weight: transfer_weight, ..Default::default() },
}),
topics: vec![],
},
];
Expand Down Expand Up @@ -448,11 +449,13 @@ fn full_native_block_import_works() {
let events = vec![
EventRecord {
phase: Phase::ApplyExtrinsic(0),
event: Event::System(frame_system::Event::ExtrinsicSuccess(DispatchInfo {
weight: timestamp_weight,
class: DispatchClass::Mandatory,
..Default::default()
})),
event: Event::System(frame_system::Event::ExtrinsicSuccess {
dispatch_info: DispatchInfo {
weight: timestamp_weight,
class: DispatchClass::Mandatory,
..Default::default()
},
}),
topics: vec![],
},
EventRecord {
Expand Down Expand Up @@ -482,15 +485,14 @@ fn full_native_block_import_works() {
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::Treasury(pallet_treasury::Event::Deposit(fees * 8 / 10)),
event: Event::Treasury(pallet_treasury::Event::Deposit { value: fees * 8 / 10 }),
topics: vec![],
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::System(frame_system::Event::ExtrinsicSuccess(DispatchInfo {
weight: transfer_weight,
..Default::default()
})),
event: Event::System(frame_system::Event::ExtrinsicSuccess {
dispatch_info: DispatchInfo { weight: transfer_weight, ..Default::default() },
}),
topics: vec![],
},
EventRecord {
Expand Down Expand Up @@ -520,15 +522,14 @@ fn full_native_block_import_works() {
},
EventRecord {
phase: Phase::ApplyExtrinsic(2),
event: Event::Treasury(pallet_treasury::Event::Deposit(fees * 8 / 10)),
event: Event::Treasury(pallet_treasury::Event::Deposit { value: fees * 8 / 10 }),
topics: vec![],
},
EventRecord {
phase: Phase::ApplyExtrinsic(2),
event: Event::System(frame_system::Event::ExtrinsicSuccess(DispatchInfo {
weight: transfer_weight,
..Default::default()
})),
event: Event::System(frame_system::Event::ExtrinsicSuccess {
dispatch_info: DispatchInfo { weight: transfer_weight, ..Default::default() },
}),
topics: vec![],
},
];
Expand Down
8 changes: 4 additions & 4 deletions frame/balances/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ macro_rules! decl_tests {
assert_eq!(
events(),
[
Event::System(system::Event::NewAccount(1)),
Event::System(system::Event::NewAccount { account: 1 }),
Event::Balances(crate::Event::Endowed { account: 1, free_balance: 100 }),
Event::Balances(crate::Event::BalanceSet { who: 1, free: 100, reserved: 0 }),
]
Expand All @@ -762,7 +762,7 @@ macro_rules! decl_tests {
assert_eq!(
events(),
[
Event::System(system::Event::KilledAccount(1)),
Event::System(system::Event::KilledAccount { account: 1 }),
Event::Balances(crate::Event::DustLost { account: 1, amount: 99 }),
Event::Balances(crate::Event::Slashed { who: 1, amount: 1 }),
]
Expand All @@ -781,7 +781,7 @@ macro_rules! decl_tests {
assert_eq!(
events(),
[
Event::System(system::Event::NewAccount(1)),
Event::System(system::Event::NewAccount { account: 1 }),
Event::Balances(crate::Event::Endowed { account: 1, free_balance: 100 }),
Event::Balances(crate::Event::BalanceSet { who: 1, free: 100, reserved: 0 }),
]
Expand All @@ -793,7 +793,7 @@ macro_rules! decl_tests {
assert_eq!(
events(),
[
Event::System(system::Event::KilledAccount(1)),
Event::System(system::Event::KilledAccount { account: 1 }),
Event::Balances(crate::Event::Slashed { who: 1, amount: 100 }),
]
);
Expand Down
4 changes: 2 additions & 2 deletions frame/balances/src/tests_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ fn emit_events_with_no_existential_deposit_suicide_with_dust() {
assert_eq!(
events(),
[
Event::System(system::Event::NewAccount(1)),
Event::System(system::Event::NewAccount { account: 1 }),
Event::Balances(crate::Event::Endowed { account: 1, free_balance: 100 }),
Event::Balances(crate::Event::BalanceSet { who: 1, free: 100, reserved: 0 }),
]
Expand All @@ -181,7 +181,7 @@ fn emit_events_with_no_existential_deposit_suicide_with_dust() {
assert_eq!(
events(),
[
Event::System(system::Event::KilledAccount(1)),
Event::System(system::Event::KilledAccount { account: 1 }),
Event::Balances(crate::Event::DustLost { account: 1, amount: 1 }),
Event::Balances(crate::Event::Slashed { who: 1, amount: 1 })
]
Expand Down
10 changes: 8 additions & 2 deletions frame/contracts/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2089,7 +2089,10 @@ mod tests {
System::events(),
vec![EventRecord {
phase: Phase::Initialization,
event: MetaEvent::System(frame_system::Event::Remarked(BOB, remark_hash)),
event: MetaEvent::System(frame_system::Event::Remarked {
sender: BOB,
hash: remark_hash
}),
topics: vec![],
},]
);
Expand Down Expand Up @@ -2147,7 +2150,10 @@ mod tests {
vec![
EventRecord {
phase: Phase::Initialization,
event: MetaEvent::System(frame_system::Event::Remarked(BOB, remark_hash)),
event: MetaEvent::System(frame_system::Event::Remarked {
sender: BOB,
hash: remark_hash
}),
topics: vec![],
},
EventRecord {
Expand Down
10 changes: 7 additions & 3 deletions frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,9 @@ fn instantiate_and_call_and_deposit_event() {
},
EventRecord {
phase: Phase::Initialization,
event: Event::System(frame_system::Event::NewAccount(ALICE.clone())),
event: Event::System(frame_system::Event::NewAccount {
account: ALICE.clone()
}),
topics: vec![],
},
EventRecord {
Expand All @@ -468,7 +470,7 @@ fn instantiate_and_call_and_deposit_event() {
},
EventRecord {
phase: Phase::Initialization,
event: Event::System(frame_system::Event::NewAccount(addr.clone())),
event: Event::System(frame_system::Event::NewAccount { account: addr.clone() }),
topics: vec![],
},
EventRecord {
Expand Down Expand Up @@ -767,7 +769,9 @@ fn self_destruct_works() {
vec![
EventRecord {
phase: Phase::Initialization,
event: Event::System(frame_system::Event::KilledAccount(addr.clone())),
event: Event::System(frame_system::Event::KilledAccount {
account: addr.clone()
}),
topics: vec![],
},
EventRecord {
Expand Down
2 changes: 1 addition & 1 deletion frame/offences/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ benchmarks! {
let mut reward_events = reporters.clone().into_iter()
.flat_map(|reporter| vec![
balance_deposit(reporter.clone(), reward.into()).into(),
frame_system::Event::<T>::NewAccount(reporter.clone()).into(),
frame_system::Event::<T>::NewAccount { account: reporter.clone() }.into(),
<T as BalancesConfig>::Event::from(
pallet_balances::Event::<T>::Endowed{account: reporter.clone(), free_balance: reward.into()}
).into(),
Expand Down
42 changes: 23 additions & 19 deletions frame/scheduler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,16 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// Scheduled some task. \[when, index\]
Scheduled(T::BlockNumber, u32),
/// Canceled some task. \[when, index\]
Canceled(T::BlockNumber, u32),
/// Dispatched some task. \[task, id, result\]
Dispatched(TaskAddress<T::BlockNumber>, Option<Vec<u8>>, DispatchResult),
/// Scheduled some task.
Scheduled { when: T::BlockNumber, index: u32 },
/// Canceled some task.
Canceled { when: T::BlockNumber, index: u32 },
/// Dispatched some task.
Dispatched {
task: TaskAddress<T::BlockNumber>,
id: Option<Vec<u8>>,
result: DispatchResult,
},
}

#[pallet::error]
Expand Down Expand Up @@ -319,11 +323,11 @@ pub mod pallet {
Lookup::<T>::remove(id);
}
}
Self::deposit_event(Event::Dispatched(
(now, index),
maybe_id,
r.map(|_| ()).map_err(|e| e.error),
));
Self::deposit_event(Event::Dispatched {
task: (now, index),
id: maybe_id,
result: r.map(|_| ()).map_err(|e| e.error),
});
total_weight = cumulative_weight;
None
} else {
Expand Down Expand Up @@ -563,7 +567,7 @@ impl<T: Config> Pallet<T> {
expected from the runtime configuration. An update might be needed.",
);
}
Self::deposit_event(Event::Scheduled(when, index));
Self::deposit_event(Event::Scheduled { when, index });

Ok((when, index))
}
Expand Down Expand Up @@ -592,7 +596,7 @@ impl<T: Config> Pallet<T> {
if let Some(id) = s.maybe_id {
Lookup::<T>::remove(id);
}
Self::deposit_event(Event::Canceled(when, index));
Self::deposit_event(Event::Canceled { when, index });
Ok(())
} else {
Err(Error::<T>::NotFound)?
Expand All @@ -617,8 +621,8 @@ impl<T: Config> Pallet<T> {
})?;

let new_index = Agenda::<T>::decode_len(new_time).unwrap_or(1) as u32 - 1;
Self::deposit_event(Event::Canceled(when, index));
Self::deposit_event(Event::Scheduled(new_time, new_index));
Self::deposit_event(Event::Canceled { when, index });
Self::deposit_event(Event::Scheduled { when: new_time, index: new_index });

Ok((new_time, new_index))
}
Expand Down Expand Up @@ -663,7 +667,7 @@ impl<T: Config> Pallet<T> {
}
let address = (when, index);
Lookup::<T>::insert(&id, &address);
Self::deposit_event(Event::Scheduled(when, index));
Self::deposit_event(Event::Scheduled { when, index });

Ok(address)
}
Expand All @@ -686,7 +690,7 @@ impl<T: Config> Pallet<T> {
}
Ok(())
})?;
Self::deposit_event(Event::Canceled(when, index));
Self::deposit_event(Event::Canceled { when, index });
Ok(())
} else {
Err(Error::<T>::NotFound)?
Expand Down Expand Up @@ -718,8 +722,8 @@ impl<T: Config> Pallet<T> {
})?;

let new_index = Agenda::<T>::decode_len(new_time).unwrap_or(1) as u32 - 1;
Self::deposit_event(Event::Canceled(when, index));
Self::deposit_event(Event::Scheduled(new_time, new_index));
Self::deposit_event(Event::Canceled { when, index });
Self::deposit_event(Event::Scheduled { when: new_time, index: new_index });

*lookup = Some((new_time, new_index));

Expand Down
Loading

0 comments on commit cf4dce5

Please sign in to comment.