Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 5d22361

Browse files
tuple to struct event variants (#10206)
* update sudo pallet * Update mock.rs * cargo +nightly fmt * frame-support remote-externalities * AFNPEV tips * AFNPEV bin & update sudo * cargo +nightly fmt * optional dependency remote-test feature * fmt Co-authored-by: Shawn Tabrizi <[email protected]>
1 parent 2208ac4 commit 5d22361

File tree

7 files changed

+51
-41
lines changed

7 files changed

+51
-41
lines changed

bin/node/executor/tests/fees.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,18 @@ fn block_weight_capacity_report() {
241241
let mut xts = (0..num_transfers)
242242
.map(|i| CheckedExtrinsic {
243243
signed: Some((charlie(), signed_extra(nonce + i as Index, 0))),
244-
function: Call::Balances(pallet_balances::Call::transfer(bob().into(), 0)),
244+
function: Call::Balances(pallet_balances::Call::transfer {
245+
dest: bob().into(),
246+
value: 0,
247+
}),
245248
})
246249
.collect::<Vec<CheckedExtrinsic>>();
247250

248251
xts.insert(
249252
0,
250253
CheckedExtrinsic {
251254
signed: None,
252-
function: Call::Timestamp(pallet_timestamp::Call::set(time * 1000)),
255+
function: Call::Timestamp(pallet_timestamp::Call::set { now: time * 1000 }),
253256
},
254257
);
255258

@@ -319,7 +322,7 @@ fn block_length_capacity_report() {
319322
vec![
320323
CheckedExtrinsic {
321324
signed: None,
322-
function: Call::Timestamp(pallet_timestamp::Call::set(time * 1000)),
325+
function: Call::Timestamp(pallet_timestamp::Call::set { now: time * 1000 }),
323326
},
324327
CheckedExtrinsic {
325328
signed: Some((charlie(), signed_extra(nonce, 0))),

frame/sudo/src/lib.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ pub mod pallet {
150150
ensure!(sender == Self::key(), Error::<T>::RequireSudo);
151151

152152
let res = call.dispatch_bypass_filter(frame_system::RawOrigin::Root.into());
153-
Self::deposit_event(Event::Sudid(res.map(|_| ()).map_err(|e| e.error)));
153+
Self::deposit_event(Event::Sudid { sudo_result: res.map(|_| ()).map_err(|e| e.error) });
154154
// Sudo user does not pay a fee.
155155
Ok(Pays::No.into())
156156
}
@@ -176,7 +176,7 @@ pub mod pallet {
176176
ensure!(sender == Self::key(), Error::<T>::RequireSudo);
177177

178178
let res = call.dispatch_bypass_filter(frame_system::RawOrigin::Root.into());
179-
Self::deposit_event(Event::Sudid(res.map(|_| ()).map_err(|e| e.error)));
179+
Self::deposit_event(Event::Sudid { sudo_result: res.map(|_| ()).map_err(|e| e.error) });
180180
// Sudo user does not pay a fee.
181181
Ok(Pays::No.into())
182182
}
@@ -201,7 +201,7 @@ pub mod pallet {
201201
ensure!(sender == Self::key(), Error::<T>::RequireSudo);
202202
let new = T::Lookup::lookup(new)?;
203203

204-
Self::deposit_event(Event::KeyChanged(Self::key()));
204+
Self::deposit_event(Event::KeyChanged { new_sudoer: Self::key() });
205205
<Key<T>>::put(new);
206206
// Sudo user does not pay a fee.
207207
Ok(Pays::No.into())
@@ -241,7 +241,9 @@ pub mod pallet {
241241

242242
let res = call.dispatch_bypass_filter(frame_system::RawOrigin::Signed(who).into());
243243

244-
Self::deposit_event(Event::SudoAsDone(res.map(|_| ()).map_err(|e| e.error)));
244+
Self::deposit_event(Event::SudoAsDone {
245+
sudo_result: res.map(|_| ()).map_err(|e| e.error),
246+
});
245247
// Sudo user does not pay a fee.
246248
Ok(Pays::No.into())
247249
}
@@ -251,11 +253,11 @@ pub mod pallet {
251253
#[pallet::generate_deposit(pub(super) fn deposit_event)]
252254
pub enum Event<T: Config> {
253255
/// A sudo just took place. \[result\]
254-
Sudid(DispatchResult),
256+
Sudid { sudo_result: DispatchResult },
255257
/// The \[sudoer\] just switched identity; the old key is supplied.
256-
KeyChanged(T::AccountId),
258+
KeyChanged { new_sudoer: T::AccountId },
257259
/// A sudo just took place. \[result\]
258-
SudoAsDone(DispatchResult),
260+
SudoAsDone { sudo_result: DispatchResult },
259261
}
260262

261263
#[pallet::error]

frame/sudo/src/mock.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub mod logger {
5858
// Ensure that the `origin` is `Root`.
5959
ensure_root(origin)?;
6060
<I32Log<T>>::append(i);
61-
Self::deposit_event(Event::AppendI32(i, weight));
61+
Self::deposit_event(Event::AppendI32 { value: i, weight });
6262
Ok(().into())
6363
}
6464

@@ -72,16 +72,16 @@ pub mod logger {
7272
let sender = ensure_signed(origin)?;
7373
<I32Log<T>>::append(i);
7474
<AccountLog<T>>::append(sender.clone());
75-
Self::deposit_event(Event::AppendI32AndAccount(sender, i, weight));
75+
Self::deposit_event(Event::AppendI32AndAccount { sender, value: i, weight });
7676
Ok(().into())
7777
}
7878
}
7979

8080
#[pallet::event]
8181
#[pallet::generate_deposit(pub(super) fn deposit_event)]
8282
pub enum Event<T: Config> {
83-
AppendI32(i32, Weight),
84-
AppendI32AndAccount(T::AccountId, i32, Weight),
83+
AppendI32 { value: i32, weight: Weight },
84+
AppendI32AndAccount { sender: T::AccountId, value: i32, weight: Weight },
8585
}
8686

8787
#[pallet::storage]

frame/sudo/src/tests.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn sudo_emits_events_correctly() {
5858
// Should emit event to indicate success when called with the root `key` and `call` is `Ok`.
5959
let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log { i: 42, weight: 1 }));
6060
assert_ok!(Sudo::sudo(Origin::signed(1), call));
61-
System::assert_has_event(TestEvent::Sudo(Event::Sudid(Ok(()))));
61+
System::assert_has_event(TestEvent::Sudo(Event::Sudid { sudo_result: Ok(()) }));
6262
})
6363
}
6464

@@ -96,7 +96,7 @@ fn sudo_unchecked_weight_emits_events_correctly() {
9696
// Should emit event to indicate success when called with the root `key` and `call` is `Ok`.
9797
let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log { i: 42, weight: 1 }));
9898
assert_ok!(Sudo::sudo_unchecked_weight(Origin::signed(1), call, 1_000));
99-
System::assert_has_event(TestEvent::Sudo(Event::Sudid(Ok(()))));
99+
System::assert_has_event(TestEvent::Sudo(Event::Sudid { sudo_result: Ok(()) }));
100100
})
101101
}
102102

@@ -123,10 +123,10 @@ fn set_key_emits_events_correctly() {
123123

124124
// A root `key` can change the root `key`.
125125
assert_ok!(Sudo::set_key(Origin::signed(1), 2));
126-
System::assert_has_event(TestEvent::Sudo(Event::KeyChanged(1)));
126+
System::assert_has_event(TestEvent::Sudo(Event::KeyChanged { new_sudoer: 1 }));
127127
// Double check.
128128
assert_ok!(Sudo::set_key(Origin::signed(2), 4));
129-
System::assert_has_event(TestEvent::Sudo(Event::KeyChanged(2)));
129+
System::assert_has_event(TestEvent::Sudo(Event::KeyChanged { new_sudoer: 2 }));
130130
});
131131
}
132132

@@ -161,6 +161,6 @@ fn sudo_as_emits_events_correctly() {
161161
// A non-privileged function will work when passed to `sudo_as` with the root `key`.
162162
let call = Box::new(Call::Logger(LoggerCall::non_privileged_log { i: 42, weight: 1 }));
163163
assert_ok!(Sudo::sudo_as(Origin::signed(1), 2, call));
164-
System::assert_has_event(TestEvent::Sudo(Event::SudoAsDone(Ok(()))));
164+
System::assert_has_event(TestEvent::Sudo(Event::SudoAsDone { sudo_result: Ok(()) }));
165165
});
166166
}

frame/tips/src/lib.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -179,16 +179,16 @@ pub mod pallet {
179179
#[pallet::event]
180180
#[pallet::generate_deposit(pub(super) fn deposit_event)]
181181
pub enum Event<T: Config> {
182-
/// A new tip suggestion has been opened. \[tip_hash\]
183-
NewTip(T::Hash),
184-
/// A tip suggestion has reached threshold and is closing. \[tip_hash\]
185-
TipClosing(T::Hash),
186-
/// A tip suggestion has been closed. \[tip_hash, who, payout\]
187-
TipClosed(T::Hash, T::AccountId, BalanceOf<T>),
188-
/// A tip suggestion has been retracted. \[tip_hash\]
189-
TipRetracted(T::Hash),
190-
/// A tip suggestion has been slashed. \[tip_hash, finder, deposit\]
191-
TipSlashed(T::Hash, T::AccountId, BalanceOf<T>),
182+
/// A new tip suggestion has been opened.
183+
NewTip { tip_hash: T::Hash },
184+
/// A tip suggestion has reached threshold and is closing.
185+
TipClosing { tip_hash: T::Hash },
186+
/// A tip suggestion has been closed.
187+
TipClosed { tip_hash: T::Hash, who: T::AccountId, payout: BalanceOf<T> },
188+
/// A tip suggestion has been retracted.
189+
TipRetracted { tip_hash: T::Hash },
190+
/// A tip suggestion has been slashed.
191+
TipSlashed { tip_hash: T::Hash, finder: T::AccountId, deposit: BalanceOf<T> },
192192
}
193193

194194
/// Old name generated by `decl_event`.
@@ -265,7 +265,7 @@ pub mod pallet {
265265
finders_fee: true,
266266
};
267267
Tips::<T>::insert(&hash, tip);
268-
Self::deposit_event(Event::NewTip(hash));
268+
Self::deposit_event(Event::NewTip { tip_hash: hash });
269269
Ok(())
270270
}
271271

@@ -300,7 +300,7 @@ pub mod pallet {
300300
let err_amount = T::Currency::unreserve(&who, tip.deposit);
301301
debug_assert!(err_amount.is_zero());
302302
}
303-
Self::deposit_event(Event::TipRetracted(hash));
303+
Self::deposit_event(Event::TipRetracted { tip_hash: hash });
304304
Ok(())
305305
}
306306

@@ -340,7 +340,7 @@ pub mod pallet {
340340
let hash = T::Hashing::hash_of(&(&reason_hash, &who));
341341

342342
Reasons::<T>::insert(&reason_hash, &reason);
343-
Self::deposit_event(Event::NewTip(hash.clone()));
343+
Self::deposit_event(Event::NewTip { tip_hash: hash.clone() });
344344
let tips = vec![(tipper.clone(), tip_value)];
345345
let tip = OpenTip {
346346
reason: reason_hash,
@@ -390,7 +390,7 @@ pub mod pallet {
390390

391391
let mut tip = Tips::<T>::get(hash).ok_or(Error::<T>::UnknownTip)?;
392392
if Self::insert_tip_and_check_closing(&mut tip, tipper, tip_value) {
393-
Self::deposit_event(Event::TipClosing(hash.clone()));
393+
Self::deposit_event(Event::TipClosing { tip_hash: hash.clone() });
394394
}
395395
Tips::<T>::insert(&hash, tip);
396396
Ok(())
@@ -449,7 +449,11 @@ pub mod pallet {
449449
T::OnSlash::on_unbalanced(imbalance);
450450
}
451451
Reasons::<T>::remove(&tip.reason);
452-
Self::deposit_event(Event::TipSlashed(hash, tip.finder, tip.deposit));
452+
Self::deposit_event(Event::TipSlashed {
453+
tip_hash: hash,
454+
finder: tip.finder,
455+
deposit: tip.deposit,
456+
});
453457
Ok(())
454458
}
455459
}
@@ -544,7 +548,7 @@ impl<T: Config> Pallet<T> {
544548
// same as above: best-effort only.
545549
let res = T::Currency::transfer(&treasury, &tip.who, payout, KeepAlive);
546550
debug_assert!(res.is_ok());
547-
Self::deposit_event(Event::TipClosed(hash, tip.who, payout));
551+
Self::deposit_event(Event::TipClosed { tip_hash: hash, who: tip.who, payout });
548552
}
549553

550554
pub fn migrate_retract_tip_for_tip_new(module: &[u8], item: &[u8]) {

frame/tips/src/tests.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,15 @@ fn close_tip_works() {
267267

268268
let h = tip_hash();
269269

270-
assert_eq!(last_event(), TipEvent::NewTip(h));
270+
assert_eq!(last_event(), TipEvent::NewTip { tip_hash: h });
271271

272272
assert_ok!(Tips::tip(Origin::signed(11), h.clone(), 10));
273273

274274
assert_noop!(Tips::close_tip(Origin::signed(0), h.into()), Error::<Test>::StillOpen);
275275

276276
assert_ok!(Tips::tip(Origin::signed(12), h.clone(), 10));
277277

278-
assert_eq!(last_event(), TipEvent::TipClosing(h));
278+
assert_eq!(last_event(), TipEvent::TipClosing { tip_hash: h });
279279

280280
assert_noop!(Tips::close_tip(Origin::signed(0), h.into()), Error::<Test>::Premature);
281281

@@ -284,7 +284,7 @@ fn close_tip_works() {
284284
assert_ok!(Tips::close_tip(Origin::signed(0), h.into()));
285285
assert_eq!(Balances::free_balance(3), 10);
286286

287-
assert_eq!(last_event(), TipEvent::TipClosed(h, 3, 10));
287+
assert_eq!(last_event(), TipEvent::TipClosed { tip_hash: h, who: 3, payout: 10 });
288288

289289
assert_noop!(Tips::close_tip(Origin::signed(100), h.into()), Error::<Test>::UnknownTip);
290290
});
@@ -306,14 +306,14 @@ fn slash_tip_works() {
306306
assert_eq!(Balances::free_balance(0), 88);
307307

308308
let h = tip_hash();
309-
assert_eq!(last_event(), TipEvent::NewTip(h));
309+
assert_eq!(last_event(), TipEvent::NewTip { tip_hash: h });
310310

311311
// can't remove from any origin
312312
assert_noop!(Tips::slash_tip(Origin::signed(0), h.clone()), BadOrigin);
313313

314314
// can remove from root.
315315
assert_ok!(Tips::slash_tip(Origin::root(), h.clone()));
316-
assert_eq!(last_event(), TipEvent::TipSlashed(h, 0, 12));
316+
assert_eq!(last_event(), TipEvent::TipSlashed { tip_hash: h, finder: 0, deposit: 12 });
317317

318318
// tipper slashed
319319
assert_eq!(Balances::reserved_balance(0), 0);

utils/frame/remote-externalities/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"]
1616
jsonrpsee = { version = "0.4.1", features = ["ws-client", "macros"] }
1717

1818
env_logger = "0.9"
19+
frame-support = { path = "../../../frame/support", optional = true }
1920
log = "0.4.11"
2021
codec = { package = "parity-scale-codec", version = "2.0.0" }
2122
serde_json = "1.0"
@@ -32,4 +33,4 @@ pallet-elections-phragmen = { path = "../../../frame/elections-phragmen", versio
3233
frame-support = { path = "../../../frame/support", version = "4.0.0-dev" }
3334

3435
[features]
35-
remote-test = []
36+
remote-test = ["frame-support"]

0 commit comments

Comments
 (0)