mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 16:47:57 +00:00
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 <shawntabrizi@gmail.com>
This commit is contained in:
@@ -241,7 +241,10 @@ fn block_weight_capacity_report() {
|
||||
let mut xts = (0..num_transfers)
|
||||
.map(|i| CheckedExtrinsic {
|
||||
signed: Some((charlie(), signed_extra(nonce + i as Index, 0))),
|
||||
function: Call::Balances(pallet_balances::Call::transfer(bob().into(), 0)),
|
||||
function: Call::Balances(pallet_balances::Call::transfer {
|
||||
dest: bob().into(),
|
||||
value: 0,
|
||||
}),
|
||||
})
|
||||
.collect::<Vec<CheckedExtrinsic>>();
|
||||
|
||||
@@ -249,7 +252,7 @@ fn block_weight_capacity_report() {
|
||||
0,
|
||||
CheckedExtrinsic {
|
||||
signed: None,
|
||||
function: Call::Timestamp(pallet_timestamp::Call::set(time * 1000)),
|
||||
function: Call::Timestamp(pallet_timestamp::Call::set { now: time * 1000 }),
|
||||
},
|
||||
);
|
||||
|
||||
@@ -319,7 +322,7 @@ fn block_length_capacity_report() {
|
||||
vec![
|
||||
CheckedExtrinsic {
|
||||
signed: None,
|
||||
function: Call::Timestamp(pallet_timestamp::Call::set(time * 1000)),
|
||||
function: Call::Timestamp(pallet_timestamp::Call::set { now: time * 1000 }),
|
||||
},
|
||||
CheckedExtrinsic {
|
||||
signed: Some((charlie(), signed_extra(nonce, 0))),
|
||||
|
||||
@@ -150,7 +150,7 @@ pub mod pallet {
|
||||
ensure!(sender == Self::key(), Error::<T>::RequireSudo);
|
||||
|
||||
let res = call.dispatch_bypass_filter(frame_system::RawOrigin::Root.into());
|
||||
Self::deposit_event(Event::Sudid(res.map(|_| ()).map_err(|e| e.error)));
|
||||
Self::deposit_event(Event::Sudid { sudo_result: res.map(|_| ()).map_err(|e| e.error) });
|
||||
// Sudo user does not pay a fee.
|
||||
Ok(Pays::No.into())
|
||||
}
|
||||
@@ -176,7 +176,7 @@ pub mod pallet {
|
||||
ensure!(sender == Self::key(), Error::<T>::RequireSudo);
|
||||
|
||||
let res = call.dispatch_bypass_filter(frame_system::RawOrigin::Root.into());
|
||||
Self::deposit_event(Event::Sudid(res.map(|_| ()).map_err(|e| e.error)));
|
||||
Self::deposit_event(Event::Sudid { sudo_result: res.map(|_| ()).map_err(|e| e.error) });
|
||||
// Sudo user does not pay a fee.
|
||||
Ok(Pays::No.into())
|
||||
}
|
||||
@@ -201,7 +201,7 @@ pub mod pallet {
|
||||
ensure!(sender == Self::key(), Error::<T>::RequireSudo);
|
||||
let new = T::Lookup::lookup(new)?;
|
||||
|
||||
Self::deposit_event(Event::KeyChanged(Self::key()));
|
||||
Self::deposit_event(Event::KeyChanged { new_sudoer: Self::key() });
|
||||
<Key<T>>::put(new);
|
||||
// Sudo user does not pay a fee.
|
||||
Ok(Pays::No.into())
|
||||
@@ -241,7 +241,9 @@ pub mod pallet {
|
||||
|
||||
let res = call.dispatch_bypass_filter(frame_system::RawOrigin::Signed(who).into());
|
||||
|
||||
Self::deposit_event(Event::SudoAsDone(res.map(|_| ()).map_err(|e| e.error)));
|
||||
Self::deposit_event(Event::SudoAsDone {
|
||||
sudo_result: res.map(|_| ()).map_err(|e| e.error),
|
||||
});
|
||||
// Sudo user does not pay a fee.
|
||||
Ok(Pays::No.into())
|
||||
}
|
||||
@@ -251,11 +253,11 @@ pub mod pallet {
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
pub enum Event<T: Config> {
|
||||
/// A sudo just took place. \[result\]
|
||||
Sudid(DispatchResult),
|
||||
Sudid { sudo_result: DispatchResult },
|
||||
/// The \[sudoer\] just switched identity; the old key is supplied.
|
||||
KeyChanged(T::AccountId),
|
||||
KeyChanged { new_sudoer: T::AccountId },
|
||||
/// A sudo just took place. \[result\]
|
||||
SudoAsDone(DispatchResult),
|
||||
SudoAsDone { sudo_result: DispatchResult },
|
||||
}
|
||||
|
||||
#[pallet::error]
|
||||
|
||||
@@ -58,7 +58,7 @@ pub mod logger {
|
||||
// Ensure that the `origin` is `Root`.
|
||||
ensure_root(origin)?;
|
||||
<I32Log<T>>::append(i);
|
||||
Self::deposit_event(Event::AppendI32(i, weight));
|
||||
Self::deposit_event(Event::AppendI32 { value: i, weight });
|
||||
Ok(().into())
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ pub mod logger {
|
||||
let sender = ensure_signed(origin)?;
|
||||
<I32Log<T>>::append(i);
|
||||
<AccountLog<T>>::append(sender.clone());
|
||||
Self::deposit_event(Event::AppendI32AndAccount(sender, i, weight));
|
||||
Self::deposit_event(Event::AppendI32AndAccount { sender, value: i, weight });
|
||||
Ok(().into())
|
||||
}
|
||||
}
|
||||
@@ -80,8 +80,8 @@ pub mod logger {
|
||||
#[pallet::event]
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
pub enum Event<T: Config> {
|
||||
AppendI32(i32, Weight),
|
||||
AppendI32AndAccount(T::AccountId, i32, Weight),
|
||||
AppendI32 { value: i32, weight: Weight },
|
||||
AppendI32AndAccount { sender: T::AccountId, value: i32, weight: Weight },
|
||||
}
|
||||
|
||||
#[pallet::storage]
|
||||
|
||||
@@ -58,7 +58,7 @@ fn sudo_emits_events_correctly() {
|
||||
// Should emit event to indicate success when called with the root `key` and `call` is `Ok`.
|
||||
let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log { i: 42, weight: 1 }));
|
||||
assert_ok!(Sudo::sudo(Origin::signed(1), call));
|
||||
System::assert_has_event(TestEvent::Sudo(Event::Sudid(Ok(()))));
|
||||
System::assert_has_event(TestEvent::Sudo(Event::Sudid { sudo_result: Ok(()) }));
|
||||
})
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ fn sudo_unchecked_weight_emits_events_correctly() {
|
||||
// Should emit event to indicate success when called with the root `key` and `call` is `Ok`.
|
||||
let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log { i: 42, weight: 1 }));
|
||||
assert_ok!(Sudo::sudo_unchecked_weight(Origin::signed(1), call, 1_000));
|
||||
System::assert_has_event(TestEvent::Sudo(Event::Sudid(Ok(()))));
|
||||
System::assert_has_event(TestEvent::Sudo(Event::Sudid { sudo_result: Ok(()) }));
|
||||
})
|
||||
}
|
||||
|
||||
@@ -123,10 +123,10 @@ fn set_key_emits_events_correctly() {
|
||||
|
||||
// A root `key` can change the root `key`.
|
||||
assert_ok!(Sudo::set_key(Origin::signed(1), 2));
|
||||
System::assert_has_event(TestEvent::Sudo(Event::KeyChanged(1)));
|
||||
System::assert_has_event(TestEvent::Sudo(Event::KeyChanged { new_sudoer: 1 }));
|
||||
// Double check.
|
||||
assert_ok!(Sudo::set_key(Origin::signed(2), 4));
|
||||
System::assert_has_event(TestEvent::Sudo(Event::KeyChanged(2)));
|
||||
System::assert_has_event(TestEvent::Sudo(Event::KeyChanged { new_sudoer: 2 }));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -161,6 +161,6 @@ fn sudo_as_emits_events_correctly() {
|
||||
// A non-privileged function will work when passed to `sudo_as` with the root `key`.
|
||||
let call = Box::new(Call::Logger(LoggerCall::non_privileged_log { i: 42, weight: 1 }));
|
||||
assert_ok!(Sudo::sudo_as(Origin::signed(1), 2, call));
|
||||
System::assert_has_event(TestEvent::Sudo(Event::SudoAsDone(Ok(()))));
|
||||
System::assert_has_event(TestEvent::Sudo(Event::SudoAsDone { sudo_result: Ok(()) }));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -179,16 +179,16 @@ pub mod pallet {
|
||||
#[pallet::event]
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
pub enum Event<T: Config> {
|
||||
/// A new tip suggestion has been opened. \[tip_hash\]
|
||||
NewTip(T::Hash),
|
||||
/// A tip suggestion has reached threshold and is closing. \[tip_hash\]
|
||||
TipClosing(T::Hash),
|
||||
/// A tip suggestion has been closed. \[tip_hash, who, payout\]
|
||||
TipClosed(T::Hash, T::AccountId, BalanceOf<T>),
|
||||
/// A tip suggestion has been retracted. \[tip_hash\]
|
||||
TipRetracted(T::Hash),
|
||||
/// A tip suggestion has been slashed. \[tip_hash, finder, deposit\]
|
||||
TipSlashed(T::Hash, T::AccountId, BalanceOf<T>),
|
||||
/// A new tip suggestion has been opened.
|
||||
NewTip { tip_hash: T::Hash },
|
||||
/// A tip suggestion has reached threshold and is closing.
|
||||
TipClosing { tip_hash: T::Hash },
|
||||
/// A tip suggestion has been closed.
|
||||
TipClosed { tip_hash: T::Hash, who: T::AccountId, payout: BalanceOf<T> },
|
||||
/// A tip suggestion has been retracted.
|
||||
TipRetracted { tip_hash: T::Hash },
|
||||
/// A tip suggestion has been slashed.
|
||||
TipSlashed { tip_hash: T::Hash, finder: T::AccountId, deposit: BalanceOf<T> },
|
||||
}
|
||||
|
||||
/// Old name generated by `decl_event`.
|
||||
@@ -265,7 +265,7 @@ pub mod pallet {
|
||||
finders_fee: true,
|
||||
};
|
||||
Tips::<T>::insert(&hash, tip);
|
||||
Self::deposit_event(Event::NewTip(hash));
|
||||
Self::deposit_event(Event::NewTip { tip_hash: hash });
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -300,7 +300,7 @@ pub mod pallet {
|
||||
let err_amount = T::Currency::unreserve(&who, tip.deposit);
|
||||
debug_assert!(err_amount.is_zero());
|
||||
}
|
||||
Self::deposit_event(Event::TipRetracted(hash));
|
||||
Self::deposit_event(Event::TipRetracted { tip_hash: hash });
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -340,7 +340,7 @@ pub mod pallet {
|
||||
let hash = T::Hashing::hash_of(&(&reason_hash, &who));
|
||||
|
||||
Reasons::<T>::insert(&reason_hash, &reason);
|
||||
Self::deposit_event(Event::NewTip(hash.clone()));
|
||||
Self::deposit_event(Event::NewTip { tip_hash: hash.clone() });
|
||||
let tips = vec![(tipper.clone(), tip_value)];
|
||||
let tip = OpenTip {
|
||||
reason: reason_hash,
|
||||
@@ -390,7 +390,7 @@ pub mod pallet {
|
||||
|
||||
let mut tip = Tips::<T>::get(hash).ok_or(Error::<T>::UnknownTip)?;
|
||||
if Self::insert_tip_and_check_closing(&mut tip, tipper, tip_value) {
|
||||
Self::deposit_event(Event::TipClosing(hash.clone()));
|
||||
Self::deposit_event(Event::TipClosing { tip_hash: hash.clone() });
|
||||
}
|
||||
Tips::<T>::insert(&hash, tip);
|
||||
Ok(())
|
||||
@@ -449,7 +449,11 @@ pub mod pallet {
|
||||
T::OnSlash::on_unbalanced(imbalance);
|
||||
}
|
||||
Reasons::<T>::remove(&tip.reason);
|
||||
Self::deposit_event(Event::TipSlashed(hash, tip.finder, tip.deposit));
|
||||
Self::deposit_event(Event::TipSlashed {
|
||||
tip_hash: hash,
|
||||
finder: tip.finder,
|
||||
deposit: tip.deposit,
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -544,7 +548,7 @@ impl<T: Config> Pallet<T> {
|
||||
// same as above: best-effort only.
|
||||
let res = T::Currency::transfer(&treasury, &tip.who, payout, KeepAlive);
|
||||
debug_assert!(res.is_ok());
|
||||
Self::deposit_event(Event::TipClosed(hash, tip.who, payout));
|
||||
Self::deposit_event(Event::TipClosed { tip_hash: hash, who: tip.who, payout });
|
||||
}
|
||||
|
||||
pub fn migrate_retract_tip_for_tip_new(module: &[u8], item: &[u8]) {
|
||||
|
||||
@@ -267,7 +267,7 @@ fn close_tip_works() {
|
||||
|
||||
let h = tip_hash();
|
||||
|
||||
assert_eq!(last_event(), TipEvent::NewTip(h));
|
||||
assert_eq!(last_event(), TipEvent::NewTip { tip_hash: h });
|
||||
|
||||
assert_ok!(Tips::tip(Origin::signed(11), h.clone(), 10));
|
||||
|
||||
@@ -275,7 +275,7 @@ fn close_tip_works() {
|
||||
|
||||
assert_ok!(Tips::tip(Origin::signed(12), h.clone(), 10));
|
||||
|
||||
assert_eq!(last_event(), TipEvent::TipClosing(h));
|
||||
assert_eq!(last_event(), TipEvent::TipClosing { tip_hash: h });
|
||||
|
||||
assert_noop!(Tips::close_tip(Origin::signed(0), h.into()), Error::<Test>::Premature);
|
||||
|
||||
@@ -284,7 +284,7 @@ fn close_tip_works() {
|
||||
assert_ok!(Tips::close_tip(Origin::signed(0), h.into()));
|
||||
assert_eq!(Balances::free_balance(3), 10);
|
||||
|
||||
assert_eq!(last_event(), TipEvent::TipClosed(h, 3, 10));
|
||||
assert_eq!(last_event(), TipEvent::TipClosed { tip_hash: h, who: 3, payout: 10 });
|
||||
|
||||
assert_noop!(Tips::close_tip(Origin::signed(100), h.into()), Error::<Test>::UnknownTip);
|
||||
});
|
||||
@@ -306,14 +306,14 @@ fn slash_tip_works() {
|
||||
assert_eq!(Balances::free_balance(0), 88);
|
||||
|
||||
let h = tip_hash();
|
||||
assert_eq!(last_event(), TipEvent::NewTip(h));
|
||||
assert_eq!(last_event(), TipEvent::NewTip { tip_hash: h });
|
||||
|
||||
// can't remove from any origin
|
||||
assert_noop!(Tips::slash_tip(Origin::signed(0), h.clone()), BadOrigin);
|
||||
|
||||
// can remove from root.
|
||||
assert_ok!(Tips::slash_tip(Origin::root(), h.clone()));
|
||||
assert_eq!(last_event(), TipEvent::TipSlashed(h, 0, 12));
|
||||
assert_eq!(last_event(), TipEvent::TipSlashed { tip_hash: h, finder: 0, deposit: 12 });
|
||||
|
||||
// tipper slashed
|
||||
assert_eq!(Balances::reserved_balance(0), 0);
|
||||
|
||||
@@ -16,6 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"]
|
||||
jsonrpsee = { version = "0.4.1", features = ["ws-client", "macros"] }
|
||||
|
||||
env_logger = "0.9"
|
||||
frame-support = { path = "../../../frame/support", optional = true }
|
||||
log = "0.4.11"
|
||||
codec = { package = "parity-scale-codec", version = "2.0.0" }
|
||||
serde_json = "1.0"
|
||||
@@ -32,4 +33,4 @@ pallet-elections-phragmen = { path = "../../../frame/elections-phragmen", versio
|
||||
frame-support = { path = "../../../frame/support", version = "4.0.0-dev" }
|
||||
|
||||
[features]
|
||||
remote-test = []
|
||||
remote-test = ["frame-support"]
|
||||
|
||||
Reference in New Issue
Block a user