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
+39 -30
View File
@@ -387,24 +387,27 @@ fn full_native_block_import_works() {
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::Balances(pallet_balances::Event::Withdraw(alice().into(), fees)),
event: Event::Balances(pallet_balances::Event::Withdraw {
who: alice().into(),
amount: fees,
}),
topics: vec![],
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::Balances(pallet_balances::Event::Transfer(
alice().into(),
bob().into(),
69 * DOLLARS,
)),
event: Event::Balances(pallet_balances::Event::Transfer {
from: alice().into(),
to: bob().into(),
amount: 69 * DOLLARS,
}),
topics: vec![],
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::Balances(pallet_balances::Event::Deposit(
pallet_treasury::Pallet::<Runtime>::account_id(),
fees * 8 / 10,
)),
event: Event::Balances(pallet_balances::Event::Deposit {
who: pallet_treasury::Pallet::<Runtime>::account_id(),
amount: fees * 8 / 10,
}),
topics: vec![],
},
EventRecord {
@@ -454,24 +457,27 @@ fn full_native_block_import_works() {
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::Balances(pallet_balances::Event::Withdraw(bob().into(), fees)),
event: Event::Balances(pallet_balances::Event::Withdraw {
who: bob().into(),
amount: fees,
}),
topics: vec![],
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::Balances(pallet_balances::Event::Transfer(
bob().into(),
alice().into(),
5 * DOLLARS,
)),
event: Event::Balances(pallet_balances::Event::Transfer {
from: bob().into(),
to: alice().into(),
amount: 5 * DOLLARS,
}),
topics: vec![],
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::Balances(pallet_balances::Event::Deposit(
pallet_treasury::Pallet::<Runtime>::account_id(),
fees * 8 / 10,
)),
event: Event::Balances(pallet_balances::Event::Deposit {
who: pallet_treasury::Pallet::<Runtime>::account_id(),
amount: fees * 8 / 10,
}),
topics: vec![],
},
EventRecord {
@@ -489,24 +495,27 @@ fn full_native_block_import_works() {
},
EventRecord {
phase: Phase::ApplyExtrinsic(2),
event: Event::Balances(pallet_balances::Event::Withdraw(alice().into(), fees)),
event: Event::Balances(pallet_balances::Event::Withdraw {
who: alice().into(),
amount: fees,
}),
topics: vec![],
},
EventRecord {
phase: Phase::ApplyExtrinsic(2),
event: Event::Balances(pallet_balances::Event::Transfer(
alice().into(),
bob().into(),
15 * DOLLARS,
)),
event: Event::Balances(pallet_balances::Event::Transfer {
from: alice().into(),
to: bob().into(),
amount: 15 * DOLLARS,
}),
topics: vec![],
},
EventRecord {
phase: Phase::ApplyExtrinsic(2),
event: Event::Balances(pallet_balances::Event::Deposit(
pallet_treasury::Pallet::<Runtime>::account_id(),
fees * 8 / 10,
)),
event: Event::Balances(pallet_balances::Event::Deposit {
who: pallet_treasury::Pallet::<Runtime>::account_id(),
amount: fees * 8 / 10,
}),
topics: vec![],
},
EventRecord {
+28 -28
View File
@@ -155,7 +155,7 @@ benchmarks_instance_pallet! {
T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T, I>::max_value());
}: _(SystemOrigin::Signed(caller.clone()), Default::default(), caller_lookup, 1u32.into())
verify {
assert_last_event::<T, I>(Event::Created(Default::default(), caller.clone(), caller).into());
assert_last_event::<T, I>(Event::Created { asset_id: Default::default(), creator: caller.clone(), owner: caller }.into());
}
force_create {
@@ -163,7 +163,7 @@ benchmarks_instance_pallet! {
let caller_lookup = T::Lookup::unlookup(caller.clone());
}: _(SystemOrigin::Root, Default::default(), caller_lookup, true, 1u32.into())
verify {
assert_last_event::<T, I>(Event::ForceCreated(Default::default(), caller).into());
assert_last_event::<T, I>(Event::ForceCreated { asset_id: Default::default(), owner: caller }.into());
}
destroy {
@@ -177,7 +177,7 @@ benchmarks_instance_pallet! {
let witness = Asset::<T, I>::get(T::AssetId::default()).unwrap().destroy_witness();
}: _(SystemOrigin::Signed(caller), Default::default(), witness)
verify {
assert_last_event::<T, I>(Event::Destroyed(Default::default()).into());
assert_last_event::<T, I>(Event::Destroyed { asset_id: Default::default() }.into());
}
mint {
@@ -185,7 +185,7 @@ benchmarks_instance_pallet! {
let amount = T::Balance::from(100u32);
}: _(SystemOrigin::Signed(caller.clone()), Default::default(), caller_lookup, amount)
verify {
assert_last_event::<T, I>(Event::Issued(Default::default(), caller, amount).into());
assert_last_event::<T, I>(Event::Issued { asset_id: Default::default(), owner: caller, total_supply: amount }.into());
}
burn {
@@ -193,7 +193,7 @@ benchmarks_instance_pallet! {
let (caller, caller_lookup) = create_default_minted_asset::<T, I>(true, amount);
}: _(SystemOrigin::Signed(caller.clone()), Default::default(), caller_lookup, amount)
verify {
assert_last_event::<T, I>(Event::Burned(Default::default(), caller, amount).into());
assert_last_event::<T, I>(Event::Burned { asset_id: Default::default(), owner: caller, balance: amount }.into());
}
transfer {
@@ -203,7 +203,7 @@ benchmarks_instance_pallet! {
let target_lookup = T::Lookup::unlookup(target.clone());
}: _(SystemOrigin::Signed(caller.clone()), Default::default(), target_lookup, amount)
verify {
assert_last_event::<T, I>(Event::Transferred(Default::default(), caller, target, amount).into());
assert_last_event::<T, I>(Event::Transferred { asset_id: Default::default(), from: caller, to: target, amount }.into());
}
transfer_keep_alive {
@@ -215,7 +215,7 @@ benchmarks_instance_pallet! {
}: _(SystemOrigin::Signed(caller.clone()), Default::default(), target_lookup, amount)
verify {
assert!(frame_system::Pallet::<T>::account_exists(&caller));
assert_last_event::<T, I>(Event::Transferred(Default::default(), caller, target, amount).into());
assert_last_event::<T, I>(Event::Transferred { asset_id: Default::default(), from: caller, to: target, amount }.into());
}
force_transfer {
@@ -226,7 +226,7 @@ benchmarks_instance_pallet! {
}: _(SystemOrigin::Signed(caller.clone()), Default::default(), caller_lookup, target_lookup, amount)
verify {
assert_last_event::<T, I>(
Event::Transferred(Default::default(), caller, target, amount).into()
Event::Transferred { asset_id: Default::default(), from: caller, to: target, amount }.into()
);
}
@@ -234,7 +234,7 @@ benchmarks_instance_pallet! {
let (caller, caller_lookup) = create_default_minted_asset::<T, I>(true, 100u32.into());
}: _(SystemOrigin::Signed(caller.clone()), Default::default(), caller_lookup)
verify {
assert_last_event::<T, I>(Event::Frozen(Default::default(), caller).into());
assert_last_event::<T, I>(Event::Frozen { asset_id: Default::default(), who: caller }.into());
}
thaw {
@@ -246,14 +246,14 @@ benchmarks_instance_pallet! {
)?;
}: _(SystemOrigin::Signed(caller.clone()), Default::default(), caller_lookup)
verify {
assert_last_event::<T, I>(Event::Thawed(Default::default(), caller).into());
assert_last_event::<T, I>(Event::Thawed { asset_id: Default::default(), who: caller }.into());
}
freeze_asset {
let (caller, caller_lookup) = create_default_minted_asset::<T, I>(true, 100u32.into());
}: _(SystemOrigin::Signed(caller.clone()), Default::default())
verify {
assert_last_event::<T, I>(Event::AssetFrozen(Default::default()).into());
assert_last_event::<T, I>(Event::AssetFrozen { asset_id: Default::default() }.into());
}
thaw_asset {
@@ -264,7 +264,7 @@ benchmarks_instance_pallet! {
)?;
}: _(SystemOrigin::Signed(caller.clone()), Default::default())
verify {
assert_last_event::<T, I>(Event::AssetThawed(Default::default()).into());
assert_last_event::<T, I>(Event::AssetThawed { asset_id: Default::default() }.into());
}
transfer_ownership {
@@ -273,7 +273,7 @@ benchmarks_instance_pallet! {
let target_lookup = T::Lookup::unlookup(target.clone());
}: _(SystemOrigin::Signed(caller), Default::default(), target_lookup)
verify {
assert_last_event::<T, I>(Event::OwnerChanged(Default::default(), target).into());
assert_last_event::<T, I>(Event::OwnerChanged { asset_id: Default::default(), owner: target }.into());
}
set_team {
@@ -283,12 +283,12 @@ benchmarks_instance_pallet! {
let target2 = T::Lookup::unlookup(account("target", 2, SEED));
}: _(SystemOrigin::Signed(caller), Default::default(), target0.clone(), target1.clone(), target2.clone())
verify {
assert_last_event::<T, I>(Event::TeamChanged(
Default::default(),
account("target", 0, SEED),
account("target", 1, SEED),
account("target", 2, SEED),
).into());
assert_last_event::<T, I>(Event::TeamChanged {
asset_id: Default::default(),
issuer: account("target", 0, SEED),
admin: account("target", 1, SEED),
freezer: account("target", 2, SEED),
}.into());
}
set_metadata {
@@ -304,7 +304,7 @@ benchmarks_instance_pallet! {
}: _(SystemOrigin::Signed(caller), Default::default(), name.clone(), symbol.clone(), decimals)
verify {
let id = Default::default();
assert_last_event::<T, I>(Event::MetadataSet(id, name, symbol, decimals, false).into());
assert_last_event::<T, I>(Event::MetadataSet { asset_id: id, name, symbol, decimals, is_frozen: false }.into());
}
clear_metadata {
@@ -315,7 +315,7 @@ benchmarks_instance_pallet! {
Assets::<T, I>::set_metadata(origin, Default::default(), dummy.clone(), dummy, 12)?;
}: _(SystemOrigin::Signed(caller), Default::default())
verify {
assert_last_event::<T, I>(Event::MetadataCleared(Default::default()).into());
assert_last_event::<T, I>(Event::MetadataCleared { asset_id: Default::default() }.into());
}
force_set_metadata {
@@ -339,7 +339,7 @@ benchmarks_instance_pallet! {
}: { call.dispatch_bypass_filter(origin)? }
verify {
let id = Default::default();
assert_last_event::<T, I>(Event::MetadataSet(id, name, symbol, decimals, false).into());
assert_last_event::<T, I>(Event::MetadataSet { asset_id: id, name, symbol, decimals, is_frozen: false }.into());
}
force_clear_metadata {
@@ -353,7 +353,7 @@ benchmarks_instance_pallet! {
let call = Call::<T, I>::force_clear_metadata { id: Default::default() };
}: { call.dispatch_bypass_filter(origin)? }
verify {
assert_last_event::<T, I>(Event::MetadataCleared(Default::default()).into());
assert_last_event::<T, I>(Event::MetadataCleared { asset_id: Default::default() }.into());
}
force_asset_status {
@@ -372,7 +372,7 @@ benchmarks_instance_pallet! {
};
}: { call.dispatch_bypass_filter(origin)? }
verify {
assert_last_event::<T, I>(Event::AssetStatusChanged(Default::default()).into());
assert_last_event::<T, I>(Event::AssetStatusChanged { asset_id: Default::default() }.into());
}
approve_transfer {
@@ -385,7 +385,7 @@ benchmarks_instance_pallet! {
let amount = 100u32.into();
}: _(SystemOrigin::Signed(caller.clone()), id, delegate_lookup, amount)
verify {
assert_last_event::<T, I>(Event::ApprovedTransfer(id, caller, delegate, amount).into());
assert_last_event::<T, I>(Event::ApprovedTransfer { asset_id: id, source: caller, delegate, amount }.into());
}
transfer_approved {
@@ -405,7 +405,7 @@ benchmarks_instance_pallet! {
}: _(SystemOrigin::Signed(delegate.clone()), id, owner_lookup, dest_lookup, amount)
verify {
assert!(T::Currency::reserved_balance(&owner).is_zero());
assert_event::<T, I>(Event::Transferred(id, owner, dest, amount).into());
assert_event::<T, I>(Event::Transferred { asset_id: id, from: owner, to: dest, amount }.into());
}
cancel_approval {
@@ -420,7 +420,7 @@ benchmarks_instance_pallet! {
Assets::<T, I>::approve_transfer(origin, id, delegate_lookup.clone(), amount)?;
}: _(SystemOrigin::Signed(caller.clone()), id, delegate_lookup)
verify {
assert_last_event::<T, I>(Event::ApprovalCancelled(id, caller, delegate).into());
assert_last_event::<T, I>(Event::ApprovalCancelled { asset_id: id, owner: caller, delegate }.into());
}
force_cancel_approval {
@@ -435,7 +435,7 @@ benchmarks_instance_pallet! {
Assets::<T, I>::approve_transfer(origin, id, delegate_lookup.clone(), amount)?;
}: _(SystemOrigin::Signed(caller.clone()), id, caller_lookup, delegate_lookup)
verify {
assert_last_event::<T, I>(Event::ApprovalCancelled(id, caller, delegate).into());
assert_last_event::<T, I>(Event::ApprovalCancelled { asset_id: id, owner: caller, delegate }.into());
}
impl_benchmark_test_suite!(Assets, crate::mock::new_test_ext(), crate::mock::Test)
+33 -8
View File
@@ -275,7 +275,11 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
details.supply = details.supply.saturating_add(amount);
Ok(())
})?;
Self::deposit_event(Event::Issued(id, beneficiary.clone(), amount));
Self::deposit_event(Event::Issued {
asset_id: id,
owner: beneficiary.clone(),
total_supply: amount,
});
Ok(())
}
@@ -342,7 +346,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
Ok(())
})?;
Self::deposit_event(Event::Burned(id, target.clone(), actual));
Self::deposit_event(Event::Burned { asset_id: id, owner: target.clone(), balance: actual });
Ok(actual)
}
@@ -415,7 +419,12 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
) -> Result<T::Balance, DispatchError> {
// Early exist if no-op.
if amount.is_zero() {
Self::deposit_event(Event::Transferred(id, source.clone(), dest.clone(), amount));
Self::deposit_event(Event::Transferred {
asset_id: id,
from: source.clone(),
to: dest.clone(),
amount,
});
return Ok(amount)
}
@@ -476,7 +485,12 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
Ok(())
})?;
Self::deposit_event(Event::Transferred(id, source.clone(), dest.clone(), credit));
Self::deposit_event(Event::Transferred {
asset_id: id,
from: source.clone(),
to: dest.clone(),
amount: credit,
});
Ok(credit)
}
@@ -514,7 +528,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
is_frozen: false,
},
);
Self::deposit_event(Event::ForceCreated(id, owner));
Self::deposit_event(Event::ForceCreated { asset_id: id, owner });
Ok(())
}
@@ -554,7 +568,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
for ((owner, _), approval) in Approvals::<T, I>::drain_prefix((&id,)) {
T::Currency::unreserve(&owner, approval.deposit);
}
Self::deposit_event(Event::Destroyed(id));
Self::deposit_event(Event::Destroyed { asset_id: id });
Ok(DestroyWitness {
accounts: details.accounts,
@@ -599,7 +613,12 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
},
)?;
Asset::<T, I>::insert(id, d);
Self::deposit_event(Event::ApprovedTransfer(id, owner.clone(), delegate.clone(), amount));
Self::deposit_event(Event::ApprovedTransfer {
asset_id: id,
source: owner.clone(),
delegate: delegate.clone(),
amount,
});
Ok(())
}
@@ -683,7 +702,13 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
is_frozen: false,
});
Self::deposit_event(Event::MetadataSet(id, name, symbol, decimals, false));
Self::deposit_event(Event::MetadataSet {
asset_id: id,
name,
symbol,
decimals,
is_frozen: false,
});
Ok(())
})
}
+77 -48
View File
@@ -379,47 +379,70 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config<I>, I: 'static = ()> {
/// Some asset class was created. \[asset_id, creator, owner\]
Created(T::AssetId, T::AccountId, T::AccountId),
/// Some assets were issued. \[asset_id, owner, total_supply\]
Issued(T::AssetId, T::AccountId, T::Balance),
/// Some assets were transferred. \[asset_id, from, to, amount\]
Transferred(T::AssetId, T::AccountId, T::AccountId, T::Balance),
/// Some assets were destroyed. \[asset_id, owner, balance\]
Burned(T::AssetId, T::AccountId, T::Balance),
/// The management team changed \[asset_id, issuer, admin, freezer\]
TeamChanged(T::AssetId, T::AccountId, T::AccountId, T::AccountId),
/// The owner changed \[asset_id, owner\]
OwnerChanged(T::AssetId, T::AccountId),
/// Some account `who` was frozen. \[asset_id, who\]
Frozen(T::AssetId, T::AccountId),
/// Some account `who` was thawed. \[asset_id, who\]
Thawed(T::AssetId, T::AccountId),
/// Some asset `asset_id` was frozen. \[asset_id\]
AssetFrozen(T::AssetId),
/// Some asset `asset_id` was thawed. \[asset_id\]
AssetThawed(T::AssetId),
/// Some asset class was created.
Created { asset_id: T::AssetId, creator: T::AccountId, owner: T::AccountId },
/// Some assets were issued.
Issued { asset_id: T::AssetId, owner: T::AccountId, total_supply: T::Balance },
/// Some assets were transferred.
Transferred {
asset_id: T::AssetId,
from: T::AccountId,
to: T::AccountId,
amount: T::Balance,
},
/// Some assets were destroyed.
Burned { asset_id: T::AssetId, owner: T::AccountId, balance: T::Balance },
/// The management team changed.
TeamChanged {
asset_id: T::AssetId,
issuer: T::AccountId,
admin: T::AccountId,
freezer: T::AccountId,
},
/// The owner changed.
OwnerChanged { asset_id: T::AssetId, owner: T::AccountId },
/// Some account `who` was frozen.
Frozen { asset_id: T::AssetId, who: T::AccountId },
/// Some account `who` was thawed.
Thawed { asset_id: T::AssetId, who: T::AccountId },
/// Some asset `asset_id` was frozen.
AssetFrozen { asset_id: T::AssetId },
/// Some asset `asset_id` was thawed.
AssetThawed { asset_id: T::AssetId },
/// An asset class was destroyed.
Destroyed(T::AssetId),
/// Some asset class was force-created. \[asset_id, owner\]
ForceCreated(T::AssetId, T::AccountId),
/// New metadata has been set for an asset. \[asset_id, name, symbol, decimals, is_frozen\]
MetadataSet(T::AssetId, Vec<u8>, Vec<u8>, u8, bool),
/// Metadata has been cleared for an asset. \[asset_id\]
MetadataCleared(T::AssetId),
Destroyed { asset_id: T::AssetId },
/// Some asset class was force-created.
ForceCreated { asset_id: T::AssetId, owner: T::AccountId },
/// New metadata has been set for an asset.
MetadataSet {
asset_id: T::AssetId,
name: Vec<u8>,
symbol: Vec<u8>,
decimals: u8,
is_frozen: bool,
},
/// Metadata has been cleared for an asset.
MetadataCleared { asset_id: T::AssetId },
/// (Additional) funds have been approved for transfer to a destination account.
/// \[asset_id, source, delegate, amount\]
ApprovedTransfer(T::AssetId, T::AccountId, T::AccountId, T::Balance),
ApprovedTransfer {
asset_id: T::AssetId,
source: T::AccountId,
delegate: T::AccountId,
amount: T::Balance,
},
/// An approval for account `delegate` was cancelled by `owner`.
/// \[id, owner, delegate\]
ApprovalCancelled(T::AssetId, T::AccountId, T::AccountId),
ApprovalCancelled { asset_id: T::AssetId, owner: T::AccountId, delegate: T::AccountId },
/// An `amount` was transferred in its entirety from `owner` to `destination` by
/// the approved `delegate`.
/// \[id, owner, delegate, destination\]
TransferredApproved(T::AssetId, T::AccountId, T::AccountId, T::AccountId, T::Balance),
TransferredApproved {
asset_id: T::AssetId,
owner: T::AccountId,
delegate: T::AccountId,
destination: T::AccountId,
amount: T::Balance,
},
/// An asset has had its attributes changed by the `Force` origin.
/// \[id\]
AssetStatusChanged(T::AssetId),
AssetStatusChanged { asset_id: T::AssetId },
}
#[pallet::error]
@@ -505,7 +528,7 @@ pub mod pallet {
is_frozen: false,
},
);
Self::deposit_event(Event::Created(id, owner, admin));
Self::deposit_event(Event::Created { asset_id: id, creator: owner, owner: admin });
Ok(())
}
@@ -761,7 +784,7 @@ pub mod pallet {
Account::<T, I>::mutate(id, &who, |a| a.is_frozen = true);
Self::deposit_event(Event::<T, I>::Frozen(id, who));
Self::deposit_event(Event::<T, I>::Frozen { asset_id: id, who });
Ok(())
}
@@ -790,7 +813,7 @@ pub mod pallet {
Account::<T, I>::mutate(id, &who, |a| a.is_frozen = false);
Self::deposit_event(Event::<T, I>::Thawed(id, who));
Self::deposit_event(Event::<T, I>::Thawed { asset_id: id, who });
Ok(())
}
@@ -816,7 +839,7 @@ pub mod pallet {
d.is_frozen = true;
Self::deposit_event(Event::<T, I>::AssetFrozen(id));
Self::deposit_event(Event::<T, I>::AssetFrozen { asset_id: id });
Ok(())
})
}
@@ -843,7 +866,7 @@ pub mod pallet {
d.is_frozen = false;
Self::deposit_event(Event::<T, I>::AssetThawed(id));
Self::deposit_event(Event::<T, I>::AssetThawed { asset_id: id });
Ok(())
})
}
@@ -882,7 +905,7 @@ pub mod pallet {
details.owner = owner.clone();
Self::deposit_event(Event::OwnerChanged(id, owner));
Self::deposit_event(Event::OwnerChanged { asset_id: id, owner });
Ok(())
})
}
@@ -920,7 +943,7 @@ pub mod pallet {
details.admin = admin.clone();
details.freezer = freezer.clone();
Self::deposit_event(Event::TeamChanged(id, issuer, admin, freezer));
Self::deposit_event(Event::TeamChanged { asset_id: id, issuer, admin, freezer });
Ok(())
})
}
@@ -977,7 +1000,7 @@ pub mod pallet {
Metadata::<T, I>::try_mutate_exists(id, |metadata| {
let deposit = metadata.take().ok_or(Error::<T, I>::Unknown)?.deposit;
T::Currency::unreserve(&d.owner, deposit);
Self::deposit_event(Event::MetadataCleared(id));
Self::deposit_event(Event::MetadataCleared { asset_id: id });
Ok(())
})
}
@@ -1024,7 +1047,13 @@ pub mod pallet {
is_frozen,
});
Self::deposit_event(Event::MetadataSet(id, name, symbol, decimals, is_frozen));
Self::deposit_event(Event::MetadataSet {
asset_id: id,
name,
symbol,
decimals,
is_frozen,
});
Ok(())
})
}
@@ -1051,7 +1080,7 @@ pub mod pallet {
Metadata::<T, I>::try_mutate_exists(id, |metadata| {
let deposit = metadata.take().ok_or(Error::<T, I>::Unknown)?.deposit;
T::Currency::unreserve(&d.owner, deposit);
Self::deposit_event(Event::MetadataCleared(id));
Self::deposit_event(Event::MetadataCleared { asset_id: id });
Ok(())
})
}
@@ -1103,7 +1132,7 @@ pub mod pallet {
asset.is_frozen = is_frozen;
*maybe_asset = Some(asset);
Self::deposit_event(Event::AssetStatusChanged(id));
Self::deposit_event(Event::AssetStatusChanged { asset_id: id });
Ok(())
})
}
@@ -1169,7 +1198,7 @@ pub mod pallet {
d.approvals.saturating_dec();
Asset::<T, I>::insert(id, d);
Self::deposit_event(Event::ApprovalCancelled(id, owner, delegate));
Self::deposit_event(Event::ApprovalCancelled { asset_id: id, owner, delegate });
Ok(())
}
@@ -1211,7 +1240,7 @@ pub mod pallet {
d.approvals.saturating_dec();
Asset::<T, I>::insert(id, d);
Self::deposit_event(Event::ApprovalCancelled(id, owner, delegate));
Self::deposit_event(Event::ApprovalCancelled { asset_id: id, owner, delegate });
Ok(())
}
+6 -1
View File
@@ -500,7 +500,12 @@ fn transferring_less_than_one_unit_is_fine() {
assert_ok!(Assets::mint(Origin::signed(1), 0, 1, 100));
assert_eq!(Assets::balance(0, 1), 100);
assert_ok!(Assets::transfer(Origin::signed(1), 0, 2, 0));
System::assert_last_event(mock::Event::Assets(crate::Event::Transferred(0, 1, 2, 0)));
System::assert_last_event(mock::Event::Assets(crate::Event::Transferred {
asset_id: 0,
from: 1,
to: 2,
amount: 0,
}));
});
}
+12 -9
View File
@@ -218,13 +218,12 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// Swap created. \[account, proof, swap\]
NewSwap(T::AccountId, HashedProof, PendingSwap<T>),
/// Swap created.
NewSwap { account: T::AccountId, proof: HashedProof, swap: PendingSwap<T> },
/// Swap claimed. The last parameter indicates whether the execution succeeds.
/// \[account, proof, success\]
SwapClaimed(T::AccountId, HashedProof, bool),
/// Swap cancelled. \[account, proof\]
SwapCancelled(T::AccountId, HashedProof),
SwapClaimed { account: T::AccountId, proof: HashedProof, success: bool },
/// Swap cancelled.
SwapCancelled { account: T::AccountId, proof: HashedProof },
}
/// Old name generated by `decl_event`.
@@ -268,7 +267,7 @@ pub mod pallet {
};
PendingSwaps::<T>::insert(target.clone(), hashed_proof.clone(), swap.clone());
Self::deposit_event(Event::NewSwap(target, hashed_proof, swap));
Self::deposit_event(Event::NewSwap { account: target, proof: hashed_proof, swap });
Ok(())
}
@@ -304,7 +303,11 @@ pub mod pallet {
PendingSwaps::<T>::remove(target.clone(), hashed_proof.clone());
Self::deposit_event(Event::SwapClaimed(target, hashed_proof, succeeded));
Self::deposit_event(Event::SwapClaimed {
account: target,
proof: hashed_proof,
success: succeeded,
});
Ok(())
}
@@ -333,7 +336,7 @@ pub mod pallet {
swap.action.cancel(&swap.source);
PendingSwaps::<T>::remove(&target, hashed_proof.clone());
Self::deposit_event(Event::SwapCancelled(target, hashed_proof));
Self::deposit_event(Event::SwapCancelled { account: target, proof: hashed_proof });
Ok(())
}
+3 -3
View File
@@ -168,8 +168,8 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(pub(crate) fn deposit_event)]
pub enum Event<T: Config> {
/// Moved an account from one bag to another. \[who, from, to\].
Rebagged(T::AccountId, VoteWeight, VoteWeight),
/// Moved an account from one bag to another.
Rebagged { who: T::AccountId, from: VoteWeight, to: VoteWeight },
}
#[pallet::call]
@@ -216,7 +216,7 @@ impl<T: Config> Pallet<T> {
let maybe_movement = list::Node::<T>::get(&account)
.and_then(|node| List::update_position_for(node, new_weight));
if let Some((from, to)) = maybe_movement {
Self::deposit_event(Event::<T>::Rebagged(account.clone(), from, to));
Self::deposit_event(Event::<T>::Rebagged { who: account.clone(), from, to });
};
maybe_movement
}
+64 -50
View File
@@ -346,7 +346,7 @@ pub mod pallet {
(account.free, account.reserved)
})?;
Self::deposit_event(Event::BalanceSet(who, free, reserved));
Self::deposit_event(Event::BalanceSet { who, free, reserved });
Ok(().into())
}
@@ -454,31 +454,33 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config<I>, I: 'static = ()> {
/// An account was created with some free balance. \[account, free_balance\]
Endowed(T::AccountId, T::Balance),
/// An account was created with some free balance.
Endowed { account: T::AccountId, free_balance: T::Balance },
/// An account was removed whose balance was non-zero but below ExistentialDeposit,
/// resulting in an outright loss. \[account, balance\]
DustLost(T::AccountId, T::Balance),
/// Transfer succeeded. \[from, to, value\]
Transfer(T::AccountId, T::AccountId, T::Balance),
/// A balance was set by root. \[who, free, reserved\]
BalanceSet(T::AccountId, T::Balance, T::Balance),
/// Some balance was reserved (moved from free to reserved). \[who, value\]
Reserved(T::AccountId, T::Balance),
/// Some balance was unreserved (moved from reserved to free). \[who, value\]
Unreserved(T::AccountId, T::Balance),
/// resulting in an outright loss.
DustLost { account: T::AccountId, amount: T::Balance },
/// Transfer succeeded.
Transfer { from: T::AccountId, to: T::AccountId, amount: T::Balance },
/// A balance was set by root.
BalanceSet { who: T::AccountId, free: T::Balance, reserved: T::Balance },
/// Some balance was reserved (moved from free to reserved).
Reserved { who: T::AccountId, amount: T::Balance },
/// Some balance was unreserved (moved from reserved to free).
Unreserved { who: T::AccountId, amount: T::Balance },
/// Some balance was moved from the reserve of the first account to the second account.
/// Final argument indicates the destination balance type.
/// \[from, to, balance, destination_status\]
ReserveRepatriated(T::AccountId, T::AccountId, T::Balance, Status),
/// Some amount was deposited into the account (e.g. for transaction fees). \[who,
/// deposit\]
Deposit(T::AccountId, T::Balance),
/// Some amount was withdrawn from the account (e.g. for transaction fees). \[who, value\]
Withdraw(T::AccountId, T::Balance),
/// Some amount was removed from the account (e.g. for misbehavior). \[who,
/// amount_slashed\]
Slashed(T::AccountId, T::Balance),
ReserveRepatriated {
from: T::AccountId,
to: T::AccountId,
amount: T::Balance,
destination_status: Status,
},
/// Some amount was deposited (e.g. for transaction fees).
Deposit { who: T::AccountId, amount: T::Balance },
/// Some amount was withdrawn from the account (e.g. for transaction fees).
Withdraw { who: T::AccountId, amount: T::Balance },
/// Some amount was removed from the account (e.g. for misbehavior).
Slashed { who: T::AccountId, amount: T::Balance },
}
/// Old name generated by `decl_event`.
@@ -742,7 +744,7 @@ pub struct DustCleaner<T: Config<I>, I: 'static = ()>(
impl<T: Config<I>, I: 'static> Drop for DustCleaner<T, I> {
fn drop(&mut self) {
if let Some((who, dust)) = self.0.take() {
Pallet::<T, I>::deposit_event(Event::DustLost(who, dust.peek()));
Pallet::<T, I>::deposit_event(Event::DustLost { account: who, amount: dust.peek() });
T::DustRemoval::on_unbalanced(dust);
}
}
@@ -939,7 +941,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
});
result.map(|(maybe_endowed, maybe_dust, result)| {
if let Some(endowed) = maybe_endowed {
Self::deposit_event(Event::Endowed(who.clone(), endowed));
Self::deposit_event(Event::Endowed { account: who.clone(), free_balance: endowed });
}
let dust_cleaner = DustCleaner(maybe_dust.map(|dust| (who.clone(), dust)));
(result, dust_cleaner)
@@ -1051,12 +1053,12 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
},
)?;
Self::deposit_event(Event::ReserveRepatriated(
slashed.clone(),
beneficiary.clone(),
actual,
status,
));
Self::deposit_event(Event::ReserveRepatriated {
from: slashed.clone(),
to: beneficiary.clone(),
amount: actual,
destination_status: status,
});
Ok(actual)
}
}
@@ -1109,7 +1111,7 @@ impl<T: Config<I>, I: 'static> fungible::Mutate<T::AccountId> for Pallet<T, I> {
Ok(())
})?;
TotalIssuance::<T, I>::mutate(|t| *t += amount);
Self::deposit_event(Event::Deposit(who.clone(), amount));
Self::deposit_event(Event::Deposit { who: who.clone(), amount });
Ok(())
}
@@ -1130,7 +1132,7 @@ impl<T: Config<I>, I: 'static> fungible::Mutate<T::AccountId> for Pallet<T, I> {
},
)?;
TotalIssuance::<T, I>::mutate(|t| *t -= actual);
Self::deposit_event(Event::Withdraw(who.clone(), amount));
Self::deposit_event(Event::Withdraw { who: who.clone(), amount });
Ok(actual)
}
}
@@ -1151,7 +1153,11 @@ impl<T: Config<I>, I: 'static> fungible::Unbalanced<T::AccountId> for Pallet<T,
fn set_balance(who: &T::AccountId, amount: Self::Balance) -> DispatchResult {
Self::mutate_account(who, |account| {
account.free = amount;
Self::deposit_event(Event::BalanceSet(who.clone(), account.free, account.reserved));
Self::deposit_event(Event::BalanceSet {
who: who.clone(),
free: account.free,
reserved: account.reserved,
});
})?;
Ok(())
}
@@ -1531,7 +1537,11 @@ where
)?;
// Emit transfer event.
Self::deposit_event(Event::Transfer(transactor.clone(), dest.clone(), value));
Self::deposit_event(Event::Transfer {
from: transactor.clone(),
to: dest.clone(),
amount: value,
});
Ok(())
}
@@ -1595,10 +1605,10 @@ where
},
) {
Ok((imbalance, not_slashed)) => {
Self::deposit_event(Event::Slashed(
who.clone(),
value.saturating_sub(not_slashed),
));
Self::deposit_event(Event::Slashed {
who: who.clone(),
amount: value.saturating_sub(not_slashed),
});
return (imbalance, not_slashed)
},
Err(_) => (),
@@ -1625,7 +1635,7 @@ where
|account, is_new| -> Result<Self::PositiveImbalance, DispatchError> {
ensure!(!is_new, Error::<T, I>::DeadAccount);
account.free = account.free.checked_add(&value).ok_or(ArithmeticError::Overflow)?;
Self::deposit_event(Event::Deposit(who.clone(), value));
Self::deposit_event(Event::Deposit { who: who.clone(), amount: value });
Ok(PositiveImbalance::new(value))
},
)
@@ -1658,7 +1668,7 @@ where
None => return Ok(Self::PositiveImbalance::zero()),
};
Self::deposit_event(Event::Deposit(who.clone(), value));
Self::deposit_event(Event::Deposit { who: who.clone(), amount: value });
Ok(PositiveImbalance::new(value))
},
)
@@ -1696,7 +1706,7 @@ where
account.free = new_free_account;
Self::deposit_event(Event::Withdraw(who.clone(), value));
Self::deposit_event(Event::Withdraw { who: who.clone(), amount: value });
Ok(NegativeImbalance::new(value))
},
)
@@ -1729,7 +1739,11 @@ where
SignedImbalance::Negative(NegativeImbalance::new(account.free - value))
};
account.free = value;
Self::deposit_event(Event::BalanceSet(who.clone(), account.free, account.reserved));
Self::deposit_event(Event::BalanceSet {
who: who.clone(),
free: account.free,
reserved: account.reserved,
});
Ok(imbalance)
},
)
@@ -1773,7 +1787,7 @@ where
Self::ensure_can_withdraw(&who, value.clone(), WithdrawReasons::RESERVE, account.free)
})?;
Self::deposit_event(Event::Reserved(who.clone(), value));
Self::deposit_event(Event::Reserved { who: who.clone(), amount: value });
Ok(())
}
@@ -1805,7 +1819,7 @@ where
},
};
Self::deposit_event(Event::Unreserved(who.clone(), actual.clone()));
Self::deposit_event(Event::Unreserved { who: who.clone(), amount: actual.clone() });
value - actual
}
@@ -1846,10 +1860,10 @@ where
(NegativeImbalance::new(actual), value - actual)
}) {
Ok((imbalance, not_slashed)) => {
Self::deposit_event(Event::Slashed(
who.clone(),
value.saturating_sub(not_slashed),
));
Self::deposit_event(Event::Slashed {
who: who.clone(),
amount: value.saturating_sub(not_slashed),
});
return (imbalance, not_slashed)
},
Err(_) => (),
@@ -1992,7 +2006,7 @@ where
// `actual <= to_change` and `to_change <= amount`; qed;
reserves[index].amount -= actual;
Self::deposit_event(Event::Slashed(who.clone(), actual));
Self::deposit_event(Event::Slashed { who: who.clone(), amount: actual });
(imb, value - actual)
},
Err(_) => (NegativeImbalance::zero(), value),
+15 -15
View File
@@ -314,7 +314,7 @@ macro_rules! decl_tests {
<$ext_builder>::default().monied(true).build().execute_with(|| {
assert_eq!(Balances::total_balance(&1), 10);
assert_ok!(Balances::deposit_into_existing(&1, 10).map(drop));
System::assert_last_event(Event::Balances(crate::Event::Deposit(1, 10)));
System::assert_last_event(Event::Balances(crate::Event::Deposit { who: 1, amount: 10 }));
assert_eq!(Balances::total_balance(&1), 20);
assert_eq!(<TotalIssuance<$test>>::get(), 120);
});
@@ -342,7 +342,7 @@ macro_rules! decl_tests {
fn balance_works() {
<$ext_builder>::default().build().execute_with(|| {
let _ = Balances::deposit_creating(&1, 42);
System::assert_has_event(Event::Balances(crate::Event::Deposit(1, 42)));
System::assert_has_event(Event::Balances(crate::Event::Deposit { who: 1, amount: 42 }));
assert_eq!(Balances::free_balance(1), 42);
assert_eq!(Balances::reserved_balance(1), 0);
assert_eq!(Balances::total_balance(&1), 42);
@@ -444,7 +444,7 @@ macro_rules! decl_tests {
let _ = Balances::withdraw(
&2, 11, WithdrawReasons::TRANSFER, ExistenceRequirement::KeepAlive
);
System::assert_last_event(Event::Balances(crate::Event::Withdraw(2, 11)));
System::assert_last_event(Event::Balances(crate::Event::Withdraw { who: 2, amount: 11 }));
assert_eq!(Balances::free_balance(2), 100);
assert_eq!(<TotalIssuance<$test>>::get(), 100);
});
@@ -505,7 +505,7 @@ macro_rules! decl_tests {
assert_ok!(Balances::reserve(&1, 110));
assert_ok!(Balances::repatriate_reserved(&1, &2, 41, Status::Free), 0);
System::assert_last_event(
Event::Balances(crate::Event::ReserveRepatriated(1, 2, 41, Status::Free))
Event::Balances(crate::Event::ReserveRepatriated { from: 1, to: 2, amount: 41, destination_status: Status::Free })
);
assert_eq!(Balances::reserved_balance(1), 69);
assert_eq!(Balances::free_balance(1), 0);
@@ -724,18 +724,18 @@ macro_rules! decl_tests {
System::set_block_number(2);
assert_ok!(Balances::reserve(&1, 10));
System::assert_last_event(Event::Balances(crate::Event::Reserved(1, 10)));
System::assert_last_event(Event::Balances(crate::Event::Reserved { who: 1, amount: 10 }));
System::set_block_number(3);
assert!(Balances::unreserve(&1, 5).is_zero());
System::assert_last_event(Event::Balances(crate::Event::Unreserved(1, 5)));
System::assert_last_event(Event::Balances(crate::Event::Unreserved { who: 1, amount: 5 }));
System::set_block_number(4);
assert_eq!(Balances::unreserve(&1, 6), 1);
// should only unreserve 5
System::assert_last_event(Event::Balances(crate::Event::Unreserved(1, 5)));
System::assert_last_event(Event::Balances(crate::Event::Unreserved { who: 1, amount: 5 }));
});
}
@@ -751,8 +751,8 @@ macro_rules! decl_tests {
events(),
[
Event::System(system::Event::NewAccount(1)),
Event::Balances(crate::Event::Endowed(1, 100)),
Event::Balances(crate::Event::BalanceSet(1, 100, 0)),
Event::Balances(crate::Event::Endowed { account: 1, free_balance: 100 }),
Event::Balances(crate::Event::BalanceSet { who: 1, free: 100, reserved: 0 }),
]
);
@@ -763,8 +763,8 @@ macro_rules! decl_tests {
events(),
[
Event::System(system::Event::KilledAccount(1)),
Event::Balances(crate::Event::DustLost(1, 99)),
Event::Balances(crate::Event::Slashed(1, 1)),
Event::Balances(crate::Event::DustLost { account: 1, amount: 99 }),
Event::Balances(crate::Event::Slashed { who: 1, amount: 1 }),
]
);
});
@@ -782,8 +782,8 @@ macro_rules! decl_tests {
events(),
[
Event::System(system::Event::NewAccount(1)),
Event::Balances(crate::Event::Endowed(1, 100)),
Event::Balances(crate::Event::BalanceSet(1, 100, 0)),
Event::Balances(crate::Event::Endowed { account: 1, free_balance: 100 }),
Event::Balances(crate::Event::BalanceSet { who: 1, free: 100, reserved: 0 }),
]
);
@@ -794,7 +794,7 @@ macro_rules! decl_tests {
events(),
[
Event::System(system::Event::KilledAccount(1)),
Event::Balances(crate::Event::Slashed(1, 100)),
Event::Balances(crate::Event::Slashed { who: 1, amount: 100 }),
]
);
});
@@ -814,7 +814,7 @@ macro_rules! decl_tests {
assert_eq!(Balances::slash(&1, 900), (NegativeImbalance::new(900), 0));
// Account is still alive
assert!(System::account_exists(&1));
System::assert_last_event(Event::Balances(crate::Event::Slashed(1, 900)));
System::assert_last_event(Event::Balances(crate::Event::Slashed { who: 1, amount: 900 }));
// SCENARIO: Slash will kill account because not enough balance left.
assert_ok!(Balances::set_balance(Origin::root(), 1, 1_000, 0));
+5 -5
View File
@@ -164,8 +164,8 @@ fn emit_events_with_no_existential_deposit_suicide_with_dust() {
events(),
[
Event::System(system::Event::NewAccount(1)),
Event::Balances(crate::Event::Endowed(1, 100)),
Event::Balances(crate::Event::BalanceSet(1, 100, 0)),
Event::Balances(crate::Event::Endowed { account: 1, free_balance: 100 }),
Event::Balances(crate::Event::BalanceSet { who: 1, free: 100, reserved: 0 }),
]
);
@@ -173,7 +173,7 @@ fn emit_events_with_no_existential_deposit_suicide_with_dust() {
assert_eq!(res, (NegativeImbalance::new(98), 0));
// no events
assert_eq!(events(), [Event::Balances(crate::Event::Slashed(1, 98))]);
assert_eq!(events(), [Event::Balances(crate::Event::Slashed { who: 1, amount: 98 })]);
let res = Balances::slash(&1, 1);
assert_eq!(res, (NegativeImbalance::new(1), 0));
@@ -182,8 +182,8 @@ fn emit_events_with_no_existential_deposit_suicide_with_dust() {
events(),
[
Event::System(system::Event::KilledAccount(1)),
Event::Balances(crate::Event::DustLost(1, 1)),
Event::Balances(crate::Event::Slashed(1, 1)),
Event::Balances(crate::Event::DustLost { account: 1, amount: 1 }),
Event::Balances(crate::Event::Slashed { who: 1, amount: 1 })
]
);
});
@@ -169,9 +169,16 @@ fn transfer_dust_removal_tst1_should_work() {
// Verify the events
assert_eq!(System::events().len(), 12);
System::assert_has_event(Event::Balances(crate::Event::Transfer(2, 3, 450)));
System::assert_has_event(Event::Balances(crate::Event::DustLost(2, 50)));
System::assert_has_event(Event::Balances(crate::Event::Deposit(1, 50)));
System::assert_has_event(Event::Balances(crate::Event::Transfer {
from: 2,
to: 3,
amount: 450,
}));
System::assert_has_event(Event::Balances(crate::Event::DustLost {
account: 2,
amount: 50,
}));
System::assert_has_event(Event::Balances(crate::Event::Deposit { who: 1, amount: 50 }));
});
}
@@ -197,9 +204,16 @@ fn transfer_dust_removal_tst2_should_work() {
// Verify the events
assert_eq!(System::events().len(), 10);
System::assert_has_event(Event::Balances(crate::Event::Transfer(2, 1, 450)));
System::assert_has_event(Event::Balances(crate::Event::DustLost(2, 50)));
System::assert_has_event(Event::Balances(crate::Event::Deposit(1, 50)));
System::assert_has_event(Event::Balances(crate::Event::Transfer {
from: 2,
to: 1,
amount: 450,
}));
System::assert_has_event(Event::Balances(crate::Event::DustLost {
account: 2,
amount: 50,
}));
System::assert_has_event(Event::Balances(crate::Event::Deposit { who: 1, amount: 50 }));
});
}
@@ -234,13 +248,18 @@ fn repatriating_reserved_balance_dust_removal_should_work() {
// Verify the events
assert_eq!(System::events().len(), 11);
System::assert_has_event(Event::Balances(crate::Event::ReserveRepatriated(
2,
1,
450,
Status::Free,
)));
System::assert_has_event(Event::Balances(crate::Event::DustLost(2, 50)));
System::assert_last_event(Event::Balances(crate::Event::Deposit(1, 50)));
System::assert_has_event(Event::Balances(crate::Event::ReserveRepatriated {
from: 2,
to: 1,
amount: 450,
destination_status: Status::Free,
}));
System::assert_has_event(Event::Balances(crate::Event::DustLost {
account: 2,
amount: 50,
}));
System::assert_last_event(Event::Balances(crate::Event::Deposit { who: 1, amount: 50 }));
});
}
+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);
@@ -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()
);
}
@@ -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()
);
}
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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);
+46 -31
View File
@@ -279,27 +279,31 @@ 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`.
@@ -442,10 +446,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| {
@@ -521,10 +525,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| {
@@ -552,7 +556,12 @@ 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
@@ -620,7 +629,13 @@ 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);
@@ -701,7 +716,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((
@@ -713,7 +728,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)),
@@ -746,7 +761,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((
@@ -758,7 +773,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())
}
@@ -848,15 +863,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
@@ -866,7 +881,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)
}
+303 -70
View File
@@ -216,11 +216,32 @@ fn close_works() {
assert_eq!(
System::events(),
vec![
record(Event::Collective(CollectiveEvent::Proposed(1, 0, hash, 3))),
record(Event::Collective(CollectiveEvent::Voted(1, hash, true, 1, 0))),
record(Event::Collective(CollectiveEvent::Voted(2, hash, true, 2, 0))),
record(Event::Collective(CollectiveEvent::Closed(hash, 2, 1))),
record(Event::Collective(CollectiveEvent::Disapproved(hash)))
record(Event::Collective(CollectiveEvent::Proposed {
account: 1,
proposal_index: 0,
proposal_hash: hash,
threshold: 3
})),
record(Event::Collective(CollectiveEvent::Voted {
account: 1,
proposal_hash: hash,
voted: true,
yes: 1,
no: 0
})),
record(Event::Collective(CollectiveEvent::Voted {
account: 2,
proposal_hash: hash,
voted: true,
yes: 2,
no: 0
})),
record(Event::Collective(CollectiveEvent::Closed {
proposal_hash: hash,
yes: 2,
no: 1
})),
record(Event::Collective(CollectiveEvent::Disapproved { proposal_hash: hash }))
]
);
});
@@ -315,11 +336,32 @@ fn close_with_prime_works() {
assert_eq!(
System::events(),
vec![
record(Event::Collective(CollectiveEvent::Proposed(1, 0, hash, 3))),
record(Event::Collective(CollectiveEvent::Voted(1, hash, true, 1, 0))),
record(Event::Collective(CollectiveEvent::Voted(2, hash, true, 2, 0))),
record(Event::Collective(CollectiveEvent::Closed(hash, 2, 1))),
record(Event::Collective(CollectiveEvent::Disapproved(hash)))
record(Event::Collective(CollectiveEvent::Proposed {
account: 1,
proposal_index: 0,
proposal_hash: hash,
threshold: 3
})),
record(Event::Collective(CollectiveEvent::Voted {
account: 1,
proposal_hash: hash,
voted: true,
yes: 1,
no: 0
})),
record(Event::Collective(CollectiveEvent::Voted {
account: 2,
proposal_hash: hash,
voted: true,
yes: 2,
no: 0
})),
record(Event::Collective(CollectiveEvent::Closed {
proposal_hash: hash,
yes: 2,
no: 1
})),
record(Event::Collective(CollectiveEvent::Disapproved { proposal_hash: hash }))
]
);
});
@@ -354,15 +396,36 @@ fn close_with_voting_prime_works() {
assert_eq!(
System::events(),
vec![
record(Event::Collective(CollectiveEvent::Proposed(1, 0, hash, 3))),
record(Event::Collective(CollectiveEvent::Voted(1, hash, true, 1, 0))),
record(Event::Collective(CollectiveEvent::Voted(2, hash, true, 2, 0))),
record(Event::Collective(CollectiveEvent::Closed(hash, 3, 0))),
record(Event::Collective(CollectiveEvent::Approved(hash))),
record(Event::Collective(CollectiveEvent::Executed(
hash,
Err(DispatchError::BadOrigin)
)))
record(Event::Collective(CollectiveEvent::Proposed {
account: 1,
proposal_index: 0,
proposal_hash: hash,
threshold: 3
})),
record(Event::Collective(CollectiveEvent::Voted {
account: 1,
proposal_hash: hash,
voted: true,
yes: 1,
no: 0
})),
record(Event::Collective(CollectiveEvent::Voted {
account: 2,
proposal_hash: hash,
voted: true,
yes: 2,
no: 0
})),
record(Event::Collective(CollectiveEvent::Closed {
proposal_hash: hash,
yes: 3,
no: 0
})),
record(Event::Collective(CollectiveEvent::Approved { proposal_hash: hash })),
record(Event::Collective(CollectiveEvent::Executed {
proposal_hash: hash,
result: Err(DispatchError::BadOrigin)
}))
]
);
});
@@ -404,16 +467,45 @@ fn close_with_no_prime_but_majority_works() {
assert_eq!(
System::events(),
vec![
record(Event::CollectiveMajority(CollectiveEvent::Proposed(1, 0, hash, 5))),
record(Event::CollectiveMajority(CollectiveEvent::Voted(1, hash, true, 1, 0))),
record(Event::CollectiveMajority(CollectiveEvent::Voted(2, hash, true, 2, 0))),
record(Event::CollectiveMajority(CollectiveEvent::Voted(3, hash, true, 3, 0))),
record(Event::CollectiveMajority(CollectiveEvent::Closed(hash, 5, 0))),
record(Event::CollectiveMajority(CollectiveEvent::Approved(hash))),
record(Event::CollectiveMajority(CollectiveEvent::Executed(
hash,
Err(DispatchError::BadOrigin)
)))
record(Event::CollectiveMajority(CollectiveEvent::Proposed {
account: 1,
proposal_index: 0,
proposal_hash: hash,
threshold: 5
})),
record(Event::CollectiveMajority(CollectiveEvent::Voted {
account: 1,
proposal_hash: hash,
voted: true,
yes: 1,
no: 0
})),
record(Event::CollectiveMajority(CollectiveEvent::Voted {
account: 2,
proposal_hash: hash,
voted: true,
yes: 2,
no: 0
})),
record(Event::CollectiveMajority(CollectiveEvent::Voted {
account: 3,
proposal_hash: hash,
voted: true,
yes: 3,
no: 0
})),
record(Event::CollectiveMajority(CollectiveEvent::Closed {
proposal_hash: hash,
yes: 5,
no: 0
})),
record(Event::CollectiveMajority(CollectiveEvent::Approved {
proposal_hash: hash
})),
record(Event::CollectiveMajority(CollectiveEvent::Executed {
proposal_hash: hash,
result: Err(DispatchError::BadOrigin)
}))
]
);
});
@@ -537,7 +629,12 @@ fn propose_works() {
assert_eq!(
System::events(),
vec![record(Event::Collective(CollectiveEvent::Proposed(1, 0, hash, 3)))]
vec![record(Event::Collective(CollectiveEvent::Proposed {
account: 1,
proposal_index: 0,
proposal_hash: hash,
threshold: 3
}))]
);
});
}
@@ -696,9 +793,26 @@ fn motions_vote_after_works() {
assert_eq!(
System::events(),
vec![
record(Event::Collective(CollectiveEvent::Proposed(1, 0, hash, 2))),
record(Event::Collective(CollectiveEvent::Voted(1, hash, true, 1, 0))),
record(Event::Collective(CollectiveEvent::Voted(1, hash, false, 0, 1))),
record(Event::Collective(CollectiveEvent::Proposed {
account: 1,
proposal_index: 0,
proposal_hash: hash,
threshold: 2
})),
record(Event::Collective(CollectiveEvent::Voted {
account: 1,
proposal_hash: hash,
voted: true,
yes: 1,
no: 0
})),
record(Event::Collective(CollectiveEvent::Voted {
account: 1,
proposal_hash: hash,
voted: false,
yes: 0,
no: 1
})),
]
);
});
@@ -812,15 +926,36 @@ fn motions_approval_with_enough_votes_and_lower_voting_threshold_works() {
assert_eq!(
System::events(),
vec![
record(Event::Collective(CollectiveEvent::Proposed(1, 0, hash, 2))),
record(Event::Collective(CollectiveEvent::Voted(1, hash, true, 1, 0))),
record(Event::Collective(CollectiveEvent::Voted(2, hash, true, 2, 0))),
record(Event::Collective(CollectiveEvent::Closed(hash, 2, 0))),
record(Event::Collective(CollectiveEvent::Approved(hash))),
record(Event::Collective(CollectiveEvent::Executed(
hash,
Err(DispatchError::BadOrigin)
))),
record(Event::Collective(CollectiveEvent::Proposed {
account: 1,
proposal_index: 0,
proposal_hash: hash,
threshold: 2
})),
record(Event::Collective(CollectiveEvent::Voted {
account: 1,
proposal_hash: hash,
voted: true,
yes: 1,
no: 0
})),
record(Event::Collective(CollectiveEvent::Voted {
account: 2,
proposal_hash: hash,
voted: true,
yes: 2,
no: 0
})),
record(Event::Collective(CollectiveEvent::Closed {
proposal_hash: hash,
yes: 2,
no: 0
})),
record(Event::Collective(CollectiveEvent::Approved { proposal_hash: hash })),
record(Event::Collective(CollectiveEvent::Executed {
proposal_hash: hash,
result: Err(DispatchError::BadOrigin)
})),
]
);
@@ -840,14 +975,44 @@ fn motions_approval_with_enough_votes_and_lower_voting_threshold_works() {
assert_eq!(
System::events(),
vec![
record(Event::Collective(CollectiveEvent::Proposed(1, 1, hash, 2))),
record(Event::Collective(CollectiveEvent::Voted(1, hash, true, 1, 0))),
record(Event::Collective(CollectiveEvent::Voted(2, hash, true, 2, 0))),
record(Event::Collective(CollectiveEvent::Voted(3, hash, true, 3, 0))),
record(Event::Collective(CollectiveEvent::Closed(hash, 3, 0))),
record(Event::Collective(CollectiveEvent::Approved(hash))),
record(Event::Collective(CollectiveEvent::Proposed {
account: 1,
proposal_index: 1,
proposal_hash: hash,
threshold: 2
})),
record(Event::Collective(CollectiveEvent::Voted {
account: 1,
proposal_hash: hash,
voted: true,
yes: 1,
no: 0
})),
record(Event::Collective(CollectiveEvent::Voted {
account: 2,
proposal_hash: hash,
voted: true,
yes: 2,
no: 0
})),
record(Event::Collective(CollectiveEvent::Voted {
account: 3,
proposal_hash: hash,
voted: true,
yes: 3,
no: 0
})),
record(Event::Collective(CollectiveEvent::Closed {
proposal_hash: hash,
yes: 3,
no: 0
})),
record(Event::Collective(CollectiveEvent::Approved { proposal_hash: hash })),
record(Event::Democracy(mock_democracy::pallet::Event::<Test>::ExternalProposed)),
record(Event::Collective(CollectiveEvent::Executed(hash, Ok(())))),
record(Event::Collective(CollectiveEvent::Executed {
proposal_hash: hash,
result: Ok(())
})),
]
);
});
@@ -873,11 +1038,32 @@ fn motions_disapproval_works() {
assert_eq!(
System::events(),
vec![
record(Event::Collective(CollectiveEvent::Proposed(1, 0, hash, 3))),
record(Event::Collective(CollectiveEvent::Voted(1, hash, true, 1, 0))),
record(Event::Collective(CollectiveEvent::Voted(2, hash, false, 1, 1))),
record(Event::Collective(CollectiveEvent::Closed(hash, 1, 1))),
record(Event::Collective(CollectiveEvent::Disapproved(hash))),
record(Event::Collective(CollectiveEvent::Proposed {
account: 1,
proposal_index: 0,
proposal_hash: hash,
threshold: 3
})),
record(Event::Collective(CollectiveEvent::Voted {
account: 1,
proposal_hash: hash,
voted: true,
yes: 1,
no: 0
})),
record(Event::Collective(CollectiveEvent::Voted {
account: 2,
proposal_hash: hash,
voted: false,
yes: 1,
no: 1
})),
record(Event::Collective(CollectiveEvent::Closed {
proposal_hash: hash,
yes: 1,
no: 1
})),
record(Event::Collective(CollectiveEvent::Disapproved { proposal_hash: hash })),
]
);
});
@@ -903,15 +1089,36 @@ fn motions_approval_works() {
assert_eq!(
System::events(),
vec![
record(Event::Collective(CollectiveEvent::Proposed(1, 0, hash, 2))),
record(Event::Collective(CollectiveEvent::Voted(1, hash, true, 1, 0))),
record(Event::Collective(CollectiveEvent::Voted(2, hash, true, 2, 0))),
record(Event::Collective(CollectiveEvent::Closed(hash, 2, 0))),
record(Event::Collective(CollectiveEvent::Approved(hash))),
record(Event::Collective(CollectiveEvent::Executed(
hash,
Err(DispatchError::BadOrigin)
))),
record(Event::Collective(CollectiveEvent::Proposed {
account: 1,
proposal_index: 0,
proposal_hash: hash,
threshold: 2
})),
record(Event::Collective(CollectiveEvent::Voted {
account: 1,
proposal_hash: hash,
voted: true,
yes: 1,
no: 0
})),
record(Event::Collective(CollectiveEvent::Voted {
account: 2,
proposal_hash: hash,
voted: true,
yes: 2,
no: 0
})),
record(Event::Collective(CollectiveEvent::Closed {
proposal_hash: hash,
yes: 2,
no: 0
})),
record(Event::Collective(CollectiveEvent::Approved { proposal_hash: hash })),
record(Event::Collective(CollectiveEvent::Executed {
proposal_hash: hash,
result: Err(DispatchError::BadOrigin)
})),
]
);
});
@@ -932,7 +1139,12 @@ fn motion_with_no_votes_closes_with_disapproval() {
));
assert_eq!(
System::events()[0],
record(Event::Collective(CollectiveEvent::Proposed(1, 0, hash, 3)))
record(Event::Collective(CollectiveEvent::Proposed {
account: 1,
proposal_index: 0,
proposal_hash: hash,
threshold: 3
}))
);
// Closing the motion too early is not possible because it has neither
@@ -951,11 +1163,15 @@ fn motion_with_no_votes_closes_with_disapproval() {
// Events show that the close ended in a disapproval.
assert_eq!(
System::events()[1],
record(Event::Collective(CollectiveEvent::Closed(hash, 0, 3)))
record(Event::Collective(CollectiveEvent::Closed {
proposal_hash: hash,
yes: 0,
no: 3
}))
);
assert_eq!(
System::events()[2],
record(Event::Collective(CollectiveEvent::Disapproved(hash)))
record(Event::Collective(CollectiveEvent::Disapproved { proposal_hash: hash }))
);
})
}
@@ -1015,10 +1231,27 @@ fn disapprove_proposal_works() {
assert_eq!(
System::events(),
vec![
record(Event::Collective(CollectiveEvent::Proposed(1, 0, hash, 2))),
record(Event::Collective(CollectiveEvent::Voted(1, hash, true, 1, 0))),
record(Event::Collective(CollectiveEvent::Voted(2, hash, true, 2, 0))),
record(Event::Collective(CollectiveEvent::Disapproved(hash))),
record(Event::Collective(CollectiveEvent::Proposed {
account: 1,
proposal_index: 0,
proposal_hash: hash,
threshold: 2
})),
record(Event::Collective(CollectiveEvent::Voted {
account: 1,
proposal_hash: hash,
voted: true,
yes: 1,
no: 0
})),
record(Event::Collective(CollectiveEvent::Voted {
account: 2,
proposal_hash: hash,
voted: true,
yes: 2,
no: 0
})),
record(Event::Collective(CollectiveEvent::Disapproved { proposal_hash: hash })),
]
);
})
+22 -16
View File
@@ -447,7 +447,10 @@ fn instantiate_and_call_and_deposit_event() {
vec![
EventRecord {
phase: Phase::Initialization,
event: Event::Balances(pallet_balances::Event::Deposit(ALICE, 1_000_000)),
event: Event::Balances(pallet_balances::Event::Deposit {
who: ALICE,
amount: 1_000_000
}),
topics: vec![],
},
EventRecord {
@@ -457,7 +460,10 @@ fn instantiate_and_call_and_deposit_event() {
},
EventRecord {
phase: Phase::Initialization,
event: Event::Balances(pallet_balances::Event::Endowed(ALICE, 1_000_000)),
event: Event::Balances(pallet_balances::Event::Endowed {
account: ALICE,
free_balance: 1_000_000
}),
topics: vec![],
},
EventRecord {
@@ -467,19 +473,19 @@ fn instantiate_and_call_and_deposit_event() {
},
EventRecord {
phase: Phase::Initialization,
event: Event::Balances(pallet_balances::Event::Endowed(
addr.clone(),
subsistence * 100
)),
event: Event::Balances(pallet_balances::Event::Endowed {
account: addr.clone(),
free_balance: subsistence * 100
}),
topics: vec![],
},
EventRecord {
phase: Phase::Initialization,
event: Event::Balances(pallet_balances::Event::Transfer(
ALICE,
addr.clone(),
subsistence * 100
)),
event: Event::Balances(pallet_balances::Event::Transfer {
from: ALICE,
to: addr.clone(),
amount: subsistence * 100
}),
topics: vec![],
},
EventRecord {
@@ -766,11 +772,11 @@ fn self_destruct_works() {
},
EventRecord {
phase: Phase::Initialization,
event: Event::Balances(pallet_balances::Event::Transfer(
addr.clone(),
DJANGO,
100_000,
)),
event: Event::Balances(pallet_balances::Event::Transfer {
from: addr.clone(),
to: DJANGO,
amount: 100_000,
}),
topics: vec![],
},
EventRecord {
@@ -774,7 +774,7 @@ benchmarks! {
}: enact_proposal(RawOrigin::Root, proposal_hash, 0)
verify {
// Fails due to mismatched origin
assert_last_event::<T>(Event::<T>::Executed(0, Err(BadOrigin.into())).into());
assert_last_event::<T>(Event::<T>::Executed { ref_index: 0, result: Err(BadOrigin.into()) }.into());
}
#[extra]
+62 -50
View File
@@ -507,45 +507,45 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// A motion has been proposed by a public account. \[proposal_index, deposit\]
Proposed(PropIndex, BalanceOf<T>),
/// A public proposal has been tabled for referendum vote. \[proposal_index, deposit,
/// depositors\]
Tabled(PropIndex, BalanceOf<T>, Vec<T::AccountId>),
/// A motion has been proposed by a public account.
Proposed { proposal_index: PropIndex, deposit: BalanceOf<T> },
/// A public proposal has been tabled for referendum vote.
Tabled { proposal_index: PropIndex, deposit: BalanceOf<T>, depositors: Vec<T::AccountId> },
/// An external proposal has been tabled.
ExternalTabled,
/// A referendum has begun. \[ref_index, threshold\]
Started(ReferendumIndex, VoteThreshold),
/// A proposal has been approved by referendum. \[ref_index\]
Passed(ReferendumIndex),
/// A proposal has been rejected by referendum. \[ref_index\]
NotPassed(ReferendumIndex),
/// A referendum has been cancelled. \[ref_index\]
Cancelled(ReferendumIndex),
/// A proposal has been enacted. \[ref_index, result\]
Executed(ReferendumIndex, DispatchResult),
/// An account has delegated their vote to another account. \[who, target\]
Delegated(T::AccountId, T::AccountId),
/// An \[account\] has cancelled a previous delegation operation.
Undelegated(T::AccountId),
/// An external proposal has been vetoed. \[who, proposal_hash, until\]
Vetoed(T::AccountId, T::Hash, T::BlockNumber),
/// A proposal's preimage was noted, and the deposit taken. \[proposal_hash, who, deposit\]
PreimageNoted(T::Hash, T::AccountId, BalanceOf<T>),
/// A referendum has begun.
Started { ref_index: ReferendumIndex, threshold: VoteThreshold },
/// A proposal has been approved by referendum.
Passed { ref_index: ReferendumIndex },
/// A proposal has been rejected by referendum.
NotPassed { ref_index: ReferendumIndex },
/// A referendum has been cancelled.
Cancelled { ref_index: ReferendumIndex },
/// A proposal has been enacted.
Executed { ref_index: ReferendumIndex, result: DispatchResult },
/// An account has delegated their vote to another account.
Delegated { who: T::AccountId, target: T::AccountId },
/// An account has cancelled a previous delegation operation.
Undelegated { account: T::AccountId },
/// An external proposal has been vetoed.
Vetoed { who: T::AccountId, proposal_hash: T::Hash, until: T::BlockNumber },
/// A proposal's preimage was noted, and the deposit taken.
PreimageNoted { proposal_hash: T::Hash, who: T::AccountId, deposit: BalanceOf<T> },
/// A proposal preimage was removed and used (the deposit was returned).
/// \[proposal_hash, provider, deposit\]
PreimageUsed(T::Hash, T::AccountId, BalanceOf<T>),
PreimageUsed { proposal_hash: T::Hash, provider: T::AccountId, deposit: BalanceOf<T> },
/// A proposal could not be executed because its preimage was invalid.
/// \[proposal_hash, ref_index\]
PreimageInvalid(T::Hash, ReferendumIndex),
PreimageInvalid { proposal_hash: T::Hash, ref_index: ReferendumIndex },
/// A proposal could not be executed because its preimage was missing.
/// \[proposal_hash, ref_index\]
PreimageMissing(T::Hash, ReferendumIndex),
PreimageMissing { proposal_hash: T::Hash, ref_index: ReferendumIndex },
/// A registered preimage was removed and the deposit collected by the reaper.
/// \[proposal_hash, provider, deposit, reaper\]
PreimageReaped(T::Hash, T::AccountId, BalanceOf<T>, T::AccountId),
/// A proposal \[hash\] has been blacklisted permanently.
Blacklisted(T::Hash),
PreimageReaped {
proposal_hash: T::Hash,
provider: T::AccountId,
deposit: BalanceOf<T>,
reaper: T::AccountId,
},
/// A proposal_hash has been blacklisted permanently.
Blacklisted { proposal_hash: T::Hash },
}
#[pallet::error]
@@ -657,7 +657,7 @@ pub mod pallet {
<PublicProps<T>>::append((index, proposal_hash, who));
Self::deposit_event(Event::<T>::Proposed(index, value));
Self::deposit_event(Event::<T>::Proposed { proposal_index: index, deposit: value });
Ok(())
}
@@ -882,7 +882,7 @@ pub mod pallet {
let until = <frame_system::Pallet<T>>::block_number() + T::CooloffPeriod::get();
<Blacklist<T>>::insert(&proposal_hash, (until, existing_vetoers));
Self::deposit_event(Event::<T>::Vetoed(who, proposal_hash, until));
Self::deposit_event(Event::<T>::Vetoed { who, proposal_hash, until });
<NextExternal<T>>::kill();
Ok(())
}
@@ -1104,7 +1104,12 @@ pub mod pallet {
T::Currency::repatriate_reserved(&provider, &who, deposit, BalanceStatus::Free);
debug_assert!(res.is_ok());
<Preimages<T>>::remove(&proposal_hash);
Self::deposit_event(Event::<T>::PreimageReaped(proposal_hash, provider, deposit, who));
Self::deposit_event(Event::<T>::PreimageReaped {
proposal_hash,
provider,
deposit,
reaper: who,
});
Ok(())
}
@@ -1249,7 +1254,7 @@ pub mod pallet {
}
}
Self::deposit_event(Event::<T>::Blacklisted(proposal_hash));
Self::deposit_event(Event::<T>::Blacklisted { proposal_hash });
Ok(())
}
@@ -1330,7 +1335,7 @@ impl<T: Config> Pallet<T> {
/// Remove a referendum.
pub fn internal_cancel_referendum(ref_index: ReferendumIndex) {
Self::deposit_event(Event::<T>::Cancelled(ref_index));
Self::deposit_event(Event::<T>::Cancelled { ref_index });
ReferendumInfoOf::<T>::remove(ref_index);
}
@@ -1532,7 +1537,7 @@ impl<T: Config> Pallet<T> {
T::Currency::extend_lock(DEMOCRACY_ID, &who, balance, WithdrawReasons::TRANSFER);
Ok(votes)
})?;
Self::deposit_event(Event::<T>::Delegated(who, target));
Self::deposit_event(Event::<T>::Delegated { who, target });
Ok(votes)
}
@@ -1558,7 +1563,7 @@ impl<T: Config> Pallet<T> {
Voting::Direct { .. } => Err(Error::<T>::NotDelegating.into()),
}
})?;
Self::deposit_event(Event::<T>::Undelegated(who));
Self::deposit_event(Event::<T>::Undelegated { account: who });
Ok(votes)
}
@@ -1589,7 +1594,7 @@ impl<T: Config> Pallet<T> {
ReferendumStatus { end, proposal_hash, threshold, delay, tally: Default::default() };
let item = ReferendumInfo::Ongoing(status);
<ReferendumInfoOf<T>>::insert(ref_index, item);
Self::deposit_event(Event::<T>::Started(ref_index, threshold));
Self::deposit_event(Event::<T>::Started { ref_index, threshold });
ref_index
}
@@ -1635,7 +1640,11 @@ impl<T: Config> Pallet<T> {
for d in &depositors {
T::Currency::unreserve(d, deposit);
}
Self::deposit_event(Event::<T>::Tabled(prop_index, deposit, depositors));
Self::deposit_event(Event::<T>::Tabled {
proposal_index: prop_index,
deposit,
depositors,
});
Self::inject_referendum(
now + T::VotingPeriod::get(),
proposal,
@@ -1655,22 +1664,25 @@ impl<T: Config> Pallet<T> {
if let Ok(proposal) = T::Proposal::decode(&mut &data[..]) {
let err_amount = T::Currency::unreserve(&provider, deposit);
debug_assert!(err_amount.is_zero());
Self::deposit_event(Event::<T>::PreimageUsed(proposal_hash, provider, deposit));
Self::deposit_event(Event::<T>::PreimageUsed { proposal_hash, provider, deposit });
let res = proposal
.dispatch(frame_system::RawOrigin::Root.into())
.map(|_| ())
.map_err(|e| e.error);
Self::deposit_event(Event::<T>::Executed(index, res));
Self::deposit_event(Event::<T>::Executed { ref_index: index, result: res });
Ok(())
} else {
T::Slash::on_unbalanced(T::Currency::slash_reserved(&provider, deposit).0);
Self::deposit_event(Event::<T>::PreimageInvalid(proposal_hash, index));
Self::deposit_event(Event::<T>::PreimageInvalid {
proposal_hash,
ref_index: index,
});
Err(Error::<T>::PreimageInvalid.into())
}
} else {
Self::deposit_event(Event::<T>::PreimageMissing(proposal_hash, index));
Self::deposit_event(Event::<T>::PreimageMissing { proposal_hash, ref_index: index });
Err(Error::<T>::PreimageMissing.into())
}
}
@@ -1684,7 +1696,7 @@ impl<T: Config> Pallet<T> {
let approved = status.threshold.approved(status.tally, total_issuance);
if approved {
Self::deposit_event(Event::<T>::Passed(index));
Self::deposit_event(Event::<T>::Passed { ref_index: index });
if status.delay.is_zero() {
let _ = Self::do_enact_proposal(status.proposal_hash, index);
} else {
@@ -1713,7 +1725,7 @@ impl<T: Config> Pallet<T> {
}
}
} else {
Self::deposit_event(Event::<T>::NotPassed(index));
Self::deposit_event(Event::<T>::NotPassed { ref_index: index });
}
approved
@@ -1870,7 +1882,7 @@ impl<T: Config> Pallet<T> {
};
<Preimages<T>>::insert(proposal_hash, a);
Self::deposit_event(Event::<T>::PreimageNoted(proposal_hash, who, deposit));
Self::deposit_event(Event::<T>::PreimageNoted { proposal_hash, who, deposit });
Ok(())
}
@@ -1896,7 +1908,7 @@ impl<T: Config> Pallet<T> {
};
<Preimages<T>>::insert(proposal_hash, a);
Self::deposit_event(Event::<T>::PreimageNoted(proposal_hash, who, free));
Self::deposit_event(Event::<T>::PreimageNoted { proposal_hash, who, deposit: free });
Ok(())
}
@@ -886,10 +886,10 @@ pub mod pallet {
log!(info, "queued unsigned solution with score {:?}", ready.score);
let ejected_a_solution = <QueuedSolution<T>>::exists();
<QueuedSolution<T>>::put(ready);
Self::deposit_event(Event::SolutionStored(
ElectionCompute::Unsigned,
ejected_a_solution,
));
Self::deposit_event(Event::SolutionStored {
election_compute: ElectionCompute::Unsigned,
prev_ejected: ejected_a_solution,
});
Ok(None.into())
}
@@ -1012,7 +1012,10 @@ pub mod pallet {
}
signed_submissions.put();
Self::deposit_event(Event::SolutionStored(ElectionCompute::Signed, ejected_a_solution));
Self::deposit_event(Event::SolutionStored {
election_compute: ElectionCompute::Signed,
prev_ejected: ejected_a_solution,
});
Ok(())
}
}
@@ -1026,18 +1029,18 @@ pub mod pallet {
/// solution is unsigned, this means that it has also been processed.
///
/// The `bool` is `true` when a previous solution was ejected to make room for this one.
SolutionStored(ElectionCompute, bool),
SolutionStored { election_compute: ElectionCompute, prev_ejected: bool },
/// The election has been finalized, with `Some` of the given computation, or else if the
/// election failed, `None`.
ElectionFinalized(Option<ElectionCompute>),
ElectionFinalized { election_compute: Option<ElectionCompute> },
/// An account has been rewarded for their signed submission being finalized.
Rewarded(<T as frame_system::Config>::AccountId, BalanceOf<T>),
Rewarded { account: <T as frame_system::Config>::AccountId, value: BalanceOf<T> },
/// An account has been slashed for submitting an invalid signed submission.
Slashed(<T as frame_system::Config>::AccountId, BalanceOf<T>),
Slashed { account: <T as frame_system::Config>::AccountId, value: BalanceOf<T> },
/// The signed phase of the given round has started.
SignedPhaseStarted(u32),
SignedPhaseStarted { round: u32 },
/// The unsigned phase of the given round has started.
UnsignedPhaseStarted(u32),
UnsignedPhaseStarted { round: u32 },
}
/// Error of the pallet that can be returned in response to dispatches.
@@ -1245,7 +1248,7 @@ impl<T: Config> Pallet<T> {
pub fn on_initialize_open_signed() {
log!(info, "Starting signed phase round {}.", Self::round());
<CurrentPhase<T>>::put(Phase::Signed);
Self::deposit_event(Event::SignedPhaseStarted(Self::round()));
Self::deposit_event(Event::SignedPhaseStarted { round: Self::round() });
}
/// Logic for [`<Pallet as Hooks<T>>::on_initialize`] when unsigned phase is being opened.
@@ -1253,7 +1256,7 @@ impl<T: Config> Pallet<T> {
let round = Self::round();
log!(info, "Starting unsigned phase round {} enabled {}.", round, enabled);
<CurrentPhase<T>>::put(Phase::Unsigned((enabled, now)));
Self::deposit_event(Event::UnsignedPhaseStarted(round));
Self::deposit_event(Event::UnsignedPhaseStarted { round });
}
/// Parts of [`create_snapshot`] that happen inside of this pallet.
@@ -1473,14 +1476,14 @@ impl<T: Config> Pallet<T> {
|ReadySolution { supports, compute, .. }| Ok((supports, compute)),
)
.map(|(supports, compute)| {
Self::deposit_event(Event::ElectionFinalized(Some(compute)));
Self::deposit_event(Event::ElectionFinalized { election_compute: Some(compute) });
if Self::round() != 1 {
log!(info, "Finalized election round with compute {:?}.", compute);
}
supports
})
.map_err(|err| {
Self::deposit_event(Event::ElectionFinalized(None));
Self::deposit_event(Event::ElectionFinalized { election_compute: None });
if Self::round() != 1 {
log!(warn, "Failed to finalize election round. reason {:?}", err);
}
@@ -1737,7 +1740,7 @@ mod tests {
roll_to(15);
assert_eq!(MultiPhase::current_phase(), Phase::Signed);
assert_eq!(multi_phase_events(), vec![Event::SignedPhaseStarted(1)]);
assert_eq!(multi_phase_events(), vec![Event::SignedPhaseStarted { round: 1 }]);
assert!(MultiPhase::snapshot().is_some());
assert_eq!(MultiPhase::round(), 1);
@@ -1750,7 +1753,10 @@ mod tests {
assert_eq!(MultiPhase::current_phase(), Phase::Unsigned((true, 25)));
assert_eq!(
multi_phase_events(),
vec![Event::SignedPhaseStarted(1), Event::UnsignedPhaseStarted(1)],
vec![
Event::SignedPhaseStarted { round: 1 },
Event::UnsignedPhaseStarted { round: 1 }
],
);
assert!(MultiPhase::snapshot().is_some());
@@ -1861,7 +1867,7 @@ mod tests {
assert_eq!(MultiPhase::current_phase(), Phase::Off);
roll_to(15);
assert_eq!(multi_phase_events(), vec![Event::SignedPhaseStarted(1)]);
assert_eq!(multi_phase_events(), vec![Event::SignedPhaseStarted { round: 1 }]);
assert_eq!(MultiPhase::current_phase(), Phase::Signed);
assert_eq!(MultiPhase::round(), 1);
@@ -1873,8 +1879,8 @@ mod tests {
assert_eq!(
multi_phase_events(),
vec![
Event::SignedPhaseStarted(1),
Event::ElectionFinalized(Some(ElectionCompute::Fallback))
Event::SignedPhaseStarted { round: 1 },
Event::ElectionFinalized { election_compute: Some(ElectionCompute::Fallback) }
],
);
// All storage items must be cleared.
@@ -1896,7 +1902,7 @@ mod tests {
assert_eq!(MultiPhase::current_phase(), Phase::Off);
roll_to(15);
assert_eq!(multi_phase_events(), vec![Event::SignedPhaseStarted(1)]);
assert_eq!(multi_phase_events(), vec![Event::SignedPhaseStarted { round: 1 }]);
assert_eq!(MultiPhase::current_phase(), Phase::Signed);
assert_eq!(MultiPhase::round(), 1);
@@ -429,7 +429,7 @@ impl<T: Config> Pallet<T> {
<QueuedSolution<T>>::put(ready_solution);
// emit reward event
Self::deposit_event(crate::Event::Rewarded(who.clone(), reward));
Self::deposit_event(crate::Event::Rewarded { account: who.clone(), value: reward });
// unreserve deposit.
let _remaining = T::Currency::unreserve(who, deposit);
@@ -446,7 +446,7 @@ impl<T: Config> Pallet<T> {
///
/// Infallible
pub fn finalize_signed_phase_reject_solution(who: &T::AccountId, deposit: BalanceOf<T>) {
Self::deposit_event(crate::Event::Slashed(who.clone(), deposit));
Self::deposit_event(crate::Event::Slashed { account: who.clone(), value: deposit });
let (negative_imbalance, _remaining) = T::Currency::slash_reserved(who, deposit);
debug_assert!(_remaining.is_zero());
T::SlashHandler::on_unbalanced(negative_imbalance);
+37 -26
View File
@@ -425,7 +425,7 @@ pub mod pallet {
Renouncing::Member => {
let _ = Self::remove_and_replace_member(&who, false)
.map_err(|_| Error::<T>::InvalidRenouncing)?;
Self::deposit_event(Event::Renounced(who));
Self::deposit_event(Event::Renounced { candidate: who });
},
Renouncing::RunnerUp => {
<RunnersUp<T>>::try_mutate::<_, Error<T>, _>(|runners_up| {
@@ -437,7 +437,7 @@ pub mod pallet {
let SeatHolder { deposit, .. } = runners_up.remove(index);
let _remainder = T::Currency::unreserve(&who, deposit);
debug_assert!(_remainder.is_zero());
Self::deposit_event(Event::Renounced(who));
Self::deposit_event(Event::Renounced { candidate: who });
Ok(())
})?;
},
@@ -450,7 +450,7 @@ pub mod pallet {
let (_removed, deposit) = candidates.remove(index);
let _remainder = T::Currency::unreserve(&who, deposit);
debug_assert!(_remainder.is_zero());
Self::deposit_event(Event::Renounced(who));
Self::deposit_event(Event::Renounced { candidate: who });
Ok(())
})?;
},
@@ -496,7 +496,7 @@ pub mod pallet {
let had_replacement = Self::remove_and_replace_member(&who, true)?;
debug_assert_eq!(has_replacement, had_replacement);
Self::deposit_event(Event::MemberKicked(who.clone()));
Self::deposit_event(Event::MemberKicked { member: who.clone() });
if !had_replacement {
Self::do_phragmen();
@@ -534,29 +534,32 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// A new term with \[new_members\]. This indicates that enough candidates existed to run
/// A new term with new_members. This indicates that enough candidates existed to run
/// the election, not that enough have has been elected. The inner value must be examined
/// for this purpose. A `NewTerm(\[\])` indicates that some candidates got their bond
/// slashed and none were elected, whilst `EmptyTerm` means that no candidates existed to
/// begin with.
NewTerm(Vec<(<T as frame_system::Config>::AccountId, BalanceOf<T>)>),
NewTerm { new_members: Vec<(<T as frame_system::Config>::AccountId, BalanceOf<T>)> },
/// No (or not enough) candidates existed for this round. This is different from
/// `NewTerm(\[\])`. See the description of `NewTerm`.
EmptyTerm,
/// Internal error happened while trying to perform election.
ElectionError,
/// A \[member\] has been removed. This should always be followed by either `NewTerm` or
/// A member has been removed. This should always be followed by either `NewTerm` or
/// `EmptyTerm`.
MemberKicked(<T as frame_system::Config>::AccountId),
MemberKicked { member: <T as frame_system::Config>::AccountId },
/// Someone has renounced their candidacy.
Renounced(<T as frame_system::Config>::AccountId),
/// A \[candidate\] was slashed by \[amount\] due to failing to obtain a seat as member or
Renounced { candidate: <T as frame_system::Config>::AccountId },
/// A candidate was slashed by amount due to failing to obtain a seat as member or
/// runner-up.
///
/// Note that old members and runners-up are also candidates.
CandidateSlashed(<T as frame_system::Config>::AccountId, BalanceOf<T>),
/// A \[seat holder\] was slashed by \[amount\] by being forcefully removed from the set.
SeatHolderSlashed(<T as frame_system::Config>::AccountId, BalanceOf<T>),
CandidateSlashed { candidate: <T as frame_system::Config>::AccountId, amount: BalanceOf<T> },
/// A seat holder was slashed by amount by being forcefully removed from the set.
SeatHolderSlashed {
seat_holder: <T as frame_system::Config>::AccountId,
amount: BalanceOf<T>,
},
}
#[deprecated(note = "use `Event` instead")]
@@ -748,7 +751,10 @@ impl<T: Config> Pallet<T> {
let (imbalance, _remainder) = T::Currency::slash_reserved(who, removed.deposit);
debug_assert!(_remainder.is_zero());
T::LoserCandidate::on_unbalanced(imbalance);
Self::deposit_event(Event::SeatHolderSlashed(who.clone(), removed.deposit));
Self::deposit_event(Event::SeatHolderSlashed {
seat_holder: who.clone(),
amount: removed.deposit,
});
} else {
T::Currency::unreserve(who, removed.deposit);
}
@@ -1001,7 +1007,10 @@ impl<T: Config> Pallet<T> {
{
let (imbalance, _) = T::Currency::slash_reserved(c, *d);
T::LoserCandidate::on_unbalanced(imbalance);
Self::deposit_event(Event::CandidateSlashed(c.clone(), *d));
Self::deposit_event(Event::CandidateSlashed {
candidate: c.clone(),
amount: *d,
});
}
});
@@ -1041,7 +1050,7 @@ impl<T: Config> Pallet<T> {
// clean candidates.
<Candidates<T>>::kill();
Self::deposit_event(Event::NewTerm(new_members_sorted_by_id));
Self::deposit_event(Event::NewTerm { new_members: new_members_sorted_by_id });
<ElectionRounds<T>>::mutate(|v| *v += 1);
})
.map_err(|e| {
@@ -2147,10 +2156,9 @@ mod tests {
System::set_block_number(5);
Elections::on_initialize(System::block_number());
System::assert_last_event(Event::Elections(super::Event::NewTerm(vec![
(4, 40),
(5, 50),
])));
System::assert_last_event(Event::Elections(super::Event::NewTerm {
new_members: vec![(4, 40), (5, 50)],
}));
assert_eq!(members_and_stake(), vec![(4, 40), (5, 50)]);
assert_eq!(runners_up_and_stake(), vec![]);
@@ -2161,7 +2169,9 @@ mod tests {
System::set_block_number(10);
Elections::on_initialize(System::block_number());
System::assert_last_event(Event::Elections(super::Event::NewTerm(vec![])));
System::assert_last_event(Event::Elections(super::Event::NewTerm {
new_members: vec![],
}));
// outgoing have lost their bond.
assert_eq!(balances(&4), (37, 0));
@@ -2231,7 +2241,9 @@ mod tests {
assert_eq!(Elections::election_rounds(), 1);
assert!(members_ids().is_empty());
System::assert_last_event(Event::Elections(super::Event::NewTerm(vec![])));
System::assert_last_event(Event::Elections(super::Event::NewTerm {
new_members: vec![],
}));
});
}
@@ -2583,10 +2595,9 @@ mod tests {
// 5 is an outgoing loser. will also get slashed.
assert_eq!(balances(&5), (45, 2));
System::assert_has_event(Event::Elections(super::Event::NewTerm(vec![
(4, 40),
(5, 50),
])));
System::assert_has_event(Event::Elections(super::Event::NewTerm {
new_members: vec![(4, 40), (5, 50)],
}));
})
}
+11 -12
View File
@@ -465,15 +465,14 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// Reaped \[voter, reaper\].
VoterReaped(T::AccountId, T::AccountId),
/// Slashed \[reaper\].
BadReaperSlashed(T::AccountId),
/// A tally (for approval votes of \[seats\]) has started.
TallyStarted(u32),
/// Reaped
VoterReaped { voter: T::AccountId, reaper: T::AccountId },
/// Slashed
BadReaperSlashed { reaper: T::AccountId },
/// A tally (for approval votes of seats) has started.
TallyStarted { seats: u32 },
/// A tally (for approval votes of seat(s)) has ended (with one or more new members).
/// \[incoming, outgoing\]
TallyFinalized(Vec<T::AccountId>, Vec<T::AccountId>),
TallyFinalized { incoming: Vec<T::AccountId>, outgoing: Vec<T::AccountId> },
}
#[pallet::call]
@@ -590,11 +589,11 @@ pub mod pallet {
T::VotingBond::get(),
BalanceStatus::Free,
)?;
Self::deposit_event(Event::<T>::VoterReaped(who, reporter));
Self::deposit_event(Event::<T>::VoterReaped { voter: who, reaper: reporter });
} else {
let imbalance = T::Currency::slash_reserved(&reporter, T::VotingBond::get()).0;
T::BadReaper::on_unbalanced(imbalance);
Self::deposit_event(Event::<T>::BadReaperSlashed(reporter));
Self::deposit_event(Event::<T>::BadReaperSlashed { reaper: reporter });
}
Ok(())
}
@@ -1024,7 +1023,7 @@ impl<T: Config> Pallet<T> {
leaderboard_size
]);
Self::deposit_event(Event::<T>::TallyStarted(empty_seats as u32));
Self::deposit_event(Event::<T>::TallyStarted { seats: empty_seats as u32 });
}
}
@@ -1118,7 +1117,7 @@ impl<T: Config> Pallet<T> {
new_candidates.truncate(last_index + 1);
}
Self::deposit_event(Event::<T>::TallyFinalized(incoming, outgoing));
Self::deposit_event(Event::<T>::TallyFinalized { incoming, outgoing });
<Candidates<T>>::put(new_candidates);
CandidateCount::<T>::put(count);
+12 -5
View File
@@ -525,7 +525,7 @@ pub mod pallet {
});
// Let's deposit an event to let the outside world know this happened.
Self::deposit_event(Event::AccumulateDummy(increase_by));
Self::deposit_event(Event::AccumulateDummy { balance: increase_by });
// All good, no refund.
Ok(())
@@ -557,7 +557,7 @@ pub mod pallet {
// Put the new value into storage.
<Dummy<T>>::put(new_value);
Self::deposit_event(Event::SetDummy(new_value));
Self::deposit_event(Event::SetDummy { balance: new_value });
// All good, no refund.
Ok(())
@@ -574,9 +574,16 @@ pub mod pallet {
pub enum Event<T: Config> {
// Just a normal `enum`, here's a dummy event to ensure it compiles.
/// Dummy event, just here so there's a generic type that's used.
AccumulateDummy(BalanceOf<T>),
SetDummy(BalanceOf<T>),
SetBar(T::AccountId, BalanceOf<T>),
AccumulateDummy {
balance: BalanceOf<T>,
},
SetDummy {
balance: BalanceOf<T>,
},
SetBar {
account: T::AccountId,
balance: BalanceOf<T>,
},
}
// pallet::storage attributes allow for type-safe usage of the Substrate storage database,
@@ -291,8 +291,7 @@ pub mod pallet {
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// Event generated when new price is accepted to contribute to the average.
/// \[price, who\]
NewPrice(u32, T::AccountId),
NewPrice { price: u32, who: T::AccountId },
}
#[pallet::validate_unsigned]
@@ -658,7 +657,7 @@ impl<T: Config> Pallet<T> {
.expect("The average is not empty, because it was just mutated; qed");
log::info!("Current average price is: {}", average);
// here we are raising the NewPrice event
Self::deposit_event(Event::NewPrice(price, who));
Self::deposit_event(Event::NewPrice { price, who });
}
/// Calculate current average price.
+24 -12
View File
@@ -272,17 +272,23 @@ pub mod pallet {
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// A bid was successfully placed.
/// \[ who, amount, duration \]
BidPlaced(T::AccountId, BalanceOf<T>, u32),
BidPlaced { who: T::AccountId, amount: BalanceOf<T>, duration: u32 },
/// A bid was successfully removed (before being accepted as a gilt).
/// \[ who, amount, duration \]
BidRetracted(T::AccountId, BalanceOf<T>, u32),
BidRetracted { who: T::AccountId, amount: BalanceOf<T>, duration: u32 },
/// A bid was accepted as a gilt. The balance may not be released until expiry.
/// \[ index, expiry, who, amount \]
GiltIssued(ActiveIndex, T::BlockNumber, T::AccountId, BalanceOf<T>),
GiltIssued {
index: ActiveIndex,
expiry: T::BlockNumber,
who: T::AccountId,
amount: BalanceOf<T>,
},
/// An expired gilt has been thawed.
/// \[ index, who, original_amount, additional_amount \]
GiltThawed(ActiveIndex, T::AccountId, BalanceOf<T>, BalanceOf<T>),
GiltThawed {
index: ActiveIndex,
who: T::AccountId,
original_amount: BalanceOf<T>,
additional_amount: BalanceOf<T>,
},
}
#[pallet::error]
@@ -376,7 +382,7 @@ pub mod pallet {
qs[queue_index].0 += net.0;
qs[queue_index].1 = qs[queue_index].1.saturating_add(net.1);
});
Self::deposit_event(Event::BidPlaced(who.clone(), amount, duration));
Self::deposit_event(Event::BidPlaced { who: who.clone(), amount, duration });
Ok(().into())
}
@@ -414,7 +420,7 @@ pub mod pallet {
});
T::Currency::unreserve(&bid.who, bid.amount);
Self::deposit_event(Event::BidRetracted(bid.who, bid.amount, duration));
Self::deposit_event(Event::BidRetracted { who: bid.who, amount: bid.amount, duration });
Ok(().into())
}
@@ -493,7 +499,12 @@ pub mod pallet {
debug_assert!(err_amt.is_zero());
}
let e = Event::GiltThawed(index, gilt.who, gilt.amount, gilt_value);
let e = Event::GiltThawed {
index,
who: gilt.who,
original_amount: gilt.amount,
additional_amount: gilt_value,
};
Self::deposit_event(e);
});
@@ -603,7 +614,8 @@ pub mod pallet {
totals.frozen += bid.amount;
totals.proportion = totals.proportion.saturating_add(proportion);
totals.index += 1;
let e = Event::GiltIssued(index, expiry, who.clone(), amount);
let e =
Event::GiltIssued { index, expiry, who: who.clone(), amount };
Self::deposit_event(e);
let gilt = ActiveGilt { amount, proportion, who, expiry };
Active::<T>::insert(index, gilt);
+5 -5
View File
@@ -154,9 +154,9 @@ pub mod pallet {
// enact the change if we've reached the enacting block
if block_number == pending_change.scheduled_at + pending_change.delay {
Self::set_grandpa_authorities(&pending_change.next_authorities);
Self::deposit_event(Event::NewAuthorities(
pending_change.next_authorities.to_vec(),
));
Self::deposit_event(Event::NewAuthorities {
authority_set: pending_change.next_authorities.to_vec(),
});
<PendingChange<T>>::kill();
}
}
@@ -255,8 +255,8 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(fn deposit_event)]
pub enum Event {
/// New authority set has been applied. \[authority_set\]
NewAuthorities(AuthorityList),
/// New authority set has been applied.
NewAuthorities { authority_set: AuthorityList },
/// Current authority set has been paused.
Paused,
/// Current authority set has been resumed.
+8 -2
View File
@@ -57,7 +57,10 @@ fn authorities_change_logged() {
System::events(),
vec![EventRecord {
phase: Phase::Finalization,
event: Event::NewAuthorities(to_authorities(vec![(4, 1), (5, 1), (6, 1)])).into(),
event: Event::NewAuthorities {
authority_set: to_authorities(vec![(4, 1), (5, 1), (6, 1)])
}
.into(),
topics: vec![],
},]
);
@@ -93,7 +96,10 @@ fn authorities_change_logged_after_delay() {
System::events(),
vec![EventRecord {
phase: Phase::Finalization,
event: Event::NewAuthorities(to_authorities(vec![(4, 1), (5, 1), (6, 1)])).into(),
event: Event::NewAuthorities {
authority_set: to_authorities(vec![(4, 1), (5, 1), (6, 1)])
}
.into(),
topics: vec![],
},]
);
+4 -4
View File
@@ -153,7 +153,7 @@ benchmarks! {
};
}: _(RawOrigin::Signed(caller.clone()), Box::new(create_identity_info::<T>(x)))
verify {
assert_last_event::<T>(Event::<T>::IdentitySet(caller).into());
assert_last_event::<T>(Event::<T>::IdentitySet { who: caller }.into());
}
// We need to split `set_subs` into two benchmarks to accurately isolate the potential
@@ -237,7 +237,7 @@ benchmarks! {
};
}: _(RawOrigin::Signed(caller.clone()), r - 1, 10u32.into())
verify {
assert_last_event::<T>(Event::<T>::JudgementRequested(caller, r-1).into());
assert_last_event::<T>(Event::<T>::JudgementRequested { who: caller, registrar_index: r-1 }.into());
}
cancel_request {
@@ -257,7 +257,7 @@ benchmarks! {
Identity::<T>::request_judgement(caller_origin, r - 1, 10u32.into())?;
}: _(RawOrigin::Signed(caller.clone()), r - 1)
verify {
assert_last_event::<T>(Event::<T>::JudgementUnrequested(caller, r-1).into());
assert_last_event::<T>(Event::<T>::JudgementUnrequested { who: caller, registrar_index: r-1 }.into());
}
set_fee {
@@ -328,7 +328,7 @@ benchmarks! {
Identity::<T>::request_judgement(user_origin.clone(), r, 10u32.into())?;
}: _(RawOrigin::Signed(caller), r, user_lookup, Judgement::Reasonable)
verify {
assert_last_event::<T>(Event::<T>::JudgementGiven(user, r).into())
assert_last_event::<T>(Event::<T>::JudgementGiven { target: user, registrar_index: r }.into())
}
kill_identity {
+39 -30
View File
@@ -241,28 +241,27 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// A name was set or reset (which will remove all judgements). \[who\]
IdentitySet(T::AccountId),
/// A name was cleared, and the given balance returned. \[who, deposit\]
IdentityCleared(T::AccountId, BalanceOf<T>),
/// A name was removed and the given balance slashed. \[who, deposit\]
IdentityKilled(T::AccountId, BalanceOf<T>),
/// A judgement was asked from a registrar. \[who, registrar_index\]
JudgementRequested(T::AccountId, RegistrarIndex),
/// A judgement request was retracted. \[who, registrar_index\]
JudgementUnrequested(T::AccountId, RegistrarIndex),
/// A judgement was given by a registrar. \[target, registrar_index\]
JudgementGiven(T::AccountId, RegistrarIndex),
/// A registrar was added. \[registrar_index\]
RegistrarAdded(RegistrarIndex),
/// A sub-identity was added to an identity and the deposit paid. \[sub, main, deposit\]
SubIdentityAdded(T::AccountId, T::AccountId, BalanceOf<T>),
/// A name was set or reset (which will remove all judgements).
IdentitySet { who: T::AccountId },
/// A name was cleared, and the given balance returned.
IdentityCleared { who: T::AccountId, deposit: BalanceOf<T> },
/// A name was removed and the given balance slashed.
IdentityKilled { who: T::AccountId, deposit: BalanceOf<T> },
/// A judgement was asked from a registrar.
JudgementRequested { who: T::AccountId, registrar_index: RegistrarIndex },
/// A judgement request was retracted.
JudgementUnrequested { who: T::AccountId, registrar_index: RegistrarIndex },
/// A judgement was given by a registrar.
JudgementGiven { target: T::AccountId, registrar_index: RegistrarIndex },
/// A registrar was added.
RegistrarAdded { registrar_index: RegistrarIndex },
/// A sub-identity was added to an identity and the deposit paid.
SubIdentityAdded { sub: T::AccountId, main: T::AccountId, deposit: BalanceOf<T> },
/// A sub-identity was removed from an identity and the deposit freed.
/// \[sub, main, deposit\]
SubIdentityRemoved(T::AccountId, T::AccountId, BalanceOf<T>),
SubIdentityRemoved { sub: T::AccountId, main: T::AccountId, deposit: BalanceOf<T> },
/// A sub-identity was cleared, and the given deposit repatriated from the
/// main identity account to the sub-identity account. \[sub, main, deposit\]
SubIdentityRevoked(T::AccountId, T::AccountId, BalanceOf<T>),
/// main identity account to the sub-identity account.
SubIdentityRevoked { sub: T::AccountId, main: T::AccountId, deposit: BalanceOf<T> },
}
#[pallet::call]
@@ -301,7 +300,7 @@ pub mod pallet {
},
)?;
Self::deposit_event(Event::RegistrarAdded(i));
Self::deposit_event(Event::RegistrarAdded { registrar_index: i });
Ok(Some(T::WeightInfo::add_registrar(registrar_count as u32)).into())
}
@@ -364,7 +363,7 @@ pub mod pallet {
let judgements = id.judgements.len();
<IdentityOf<T>>::insert(&sender, id);
Self::deposit_event(Event::IdentitySet(sender));
Self::deposit_event(Event::IdentitySet { who: sender });
Ok(Some(T::WeightInfo::set_identity(
judgements as u32, // R
@@ -489,7 +488,7 @@ pub mod pallet {
let err_amount = T::Currency::unreserve(&sender, deposit.clone());
debug_assert!(err_amount.is_zero());
Self::deposit_event(Event::IdentityCleared(sender, deposit));
Self::deposit_event(Event::IdentityCleared { who: sender, deposit });
Ok(Some(T::WeightInfo::clear_identity(
id.judgements.len() as u32, // R
@@ -558,7 +557,10 @@ pub mod pallet {
let extra_fields = id.info.additional.len();
<IdentityOf<T>>::insert(&sender, id);
Self::deposit_event(Event::JudgementRequested(sender, reg_index));
Self::deposit_event(Event::JudgementRequested {
who: sender,
registrar_index: reg_index,
});
Ok(Some(T::WeightInfo::request_judgement(judgements as u32, extra_fields as u32))
.into())
@@ -608,7 +610,10 @@ pub mod pallet {
let extra_fields = id.info.additional.len();
<IdentityOf<T>>::insert(&sender, id);
Self::deposit_event(Event::JudgementUnrequested(sender, reg_index));
Self::deposit_event(Event::JudgementUnrequested {
who: sender,
registrar_index: reg_index,
});
Ok(Some(T::WeightInfo::cancel_request(judgements as u32, extra_fields as u32)).into())
}
@@ -791,7 +796,7 @@ pub mod pallet {
let judgements = id.judgements.len();
let extra_fields = id.info.additional.len();
<IdentityOf<T>>::insert(&target, id);
Self::deposit_event(Event::JudgementGiven(target, reg_index));
Self::deposit_event(Event::JudgementGiven { target, registrar_index: reg_index });
Ok(Some(T::WeightInfo::provide_judgement(judgements as u32, extra_fields as u32))
.into())
@@ -839,7 +844,7 @@ pub mod pallet {
// Slash their deposit from them.
T::Slashed::on_unbalanced(T::Currency::slash_reserved(&target, deposit).0);
Self::deposit_event(Event::IdentityKilled(target, deposit));
Self::deposit_event(Event::IdentityKilled { who: target, deposit });
Ok(Some(T::WeightInfo::kill_identity(
id.judgements.len() as u32, // R
@@ -882,7 +887,7 @@ pub mod pallet {
sub_ids.try_push(sub.clone()).expect("sub ids length checked above; qed");
*subs_deposit = subs_deposit.saturating_add(deposit);
Self::deposit_event(Event::SubIdentityAdded(sub, sender.clone(), deposit));
Self::deposit_event(Event::SubIdentityAdded { sub, main: sender.clone(), deposit });
Ok(())
})
}
@@ -929,7 +934,7 @@ pub mod pallet {
*subs_deposit -= deposit;
let err_amount = T::Currency::unreserve(&sender, deposit);
debug_assert!(err_amount.is_zero());
Self::deposit_event(Event::SubIdentityRemoved(sub, sender, deposit));
Self::deposit_event(Event::SubIdentityRemoved { sub, main: sender, deposit });
});
Ok(())
}
@@ -954,7 +959,11 @@ pub mod pallet {
*subs_deposit -= deposit;
let _ =
T::Currency::repatriate_reserved(&sup, &sender, deposit, BalanceStatus::Free);
Self::deposit_event(Event::SubIdentityRevoked(sender, sup.clone(), deposit));
Self::deposit_event(Event::SubIdentityRevoked {
sub: sender,
main: sup.clone(),
deposit,
});
});
Ok(())
}
+6 -6
View File
@@ -374,12 +374,12 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// A new heartbeat was received from `AuthorityId` \[authority_id\]
HeartbeatReceived(T::AuthorityId),
/// A new heartbeat was received from `AuthorityId`.
HeartbeatReceived { authority_id: T::AuthorityId },
/// At the end of the session, no offence was committed.
AllGood,
/// At the end of the session, at least one validator was found to be \[offline\].
SomeOffline(Vec<IdentificationTuple<T>>),
/// At the end of the session, at least one validator was found to be offline.
SomeOffline { offline: Vec<IdentificationTuple<T>> },
}
#[pallet::error]
@@ -495,7 +495,7 @@ pub mod pallet {
let keys = Keys::<T>::get();
let public = keys.get(heartbeat.authority_index as usize);
if let (false, Some(public)) = (exists, public) {
Self::deposit_event(Event::<T>::HeartbeatReceived(public.clone()));
Self::deposit_event(Event::<T>::HeartbeatReceived { authority_id: public.clone() });
let network_state_bounded = BoundedOpaqueNetworkState::<
T::MaxPeerDataEncodingSize,
@@ -908,7 +908,7 @@ impl<T: Config> OneSessionHandler<T::AccountId> for Pallet<T> {
if offenders.is_empty() {
Self::deposit_event(Event::<T>::AllGood);
} else {
Self::deposit_event(Event::<T>::SomeOffline(offenders.clone()));
Self::deposit_event(Event::<T>::SomeOffline { offline: offenders.clone() });
let validator_set_count = keys.len() as u32;
let offence = UnresponsivenessOffence { session_index, validator_set_count, offenders };
+11 -11
View File
@@ -105,7 +105,7 @@ pub mod pallet {
*maybe_value = Some((who.clone(), T::Deposit::get(), false));
T::Currency::reserve(&who, T::Deposit::get())
})?;
Self::deposit_event(Event::IndexAssigned(who, index));
Self::deposit_event(Event::IndexAssigned { who, index });
Ok(())
}
@@ -146,7 +146,7 @@ pub mod pallet {
*maybe_value = Some((new.clone(), amount.saturating_sub(lost), false));
Ok(())
})?;
Self::deposit_event(Event::IndexAssigned(new, index));
Self::deposit_event(Event::IndexAssigned { who: new, index });
Ok(())
}
@@ -179,7 +179,7 @@ pub mod pallet {
T::Currency::unreserve(&who, amount);
Ok(())
})?;
Self::deposit_event(Event::IndexFreed(index));
Self::deposit_event(Event::IndexFreed { index });
Ok(())
}
@@ -219,7 +219,7 @@ pub mod pallet {
}
*maybe_value = Some((new.clone(), Zero::zero(), freeze));
});
Self::deposit_event(Event::IndexAssigned(new, index));
Self::deposit_event(Event::IndexAssigned { who: new, index });
Ok(())
}
@@ -253,7 +253,7 @@ pub mod pallet {
*maybe_value = Some((account, Zero::zero(), true));
Ok(())
})?;
Self::deposit_event(Event::IndexFrozen(index, who));
Self::deposit_event(Event::IndexFrozen { index, who });
Ok(())
}
}
@@ -261,12 +261,12 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// A account index was assigned. \[index, who\]
IndexAssigned(T::AccountId, T::AccountIndex),
/// A account index has been freed up (unassigned). \[index\]
IndexFreed(T::AccountIndex),
/// A account index has been frozen to its current account ID. \[index, who\]
IndexFrozen(T::AccountIndex, T::AccountId),
/// A account index was assigned.
IndexAssigned { who: T::AccountId, index: T::AccountIndex },
/// A account index has been freed up (unassigned).
IndexFreed { index: T::AccountIndex },
/// A account index has been frozen to its current account ID.
IndexFrozen { index: T::AccountIndex, who: T::AccountId },
}
/// Old name generated by `decl_event`.
+4 -4
View File
@@ -176,9 +176,9 @@ pub mod pallet {
/// A new set of calls have been set!
CallsUpdated,
/// A winner has been chosen!
Winner(T::AccountId, BalanceOf<T>),
Winner { winner: T::AccountId, lottery_balance: BalanceOf<T> },
/// A ticket has been bought!
TicketBought(T::AccountId, CallIndex),
TicketBought { who: T::AccountId, call_index: CallIndex },
}
#[pallet::error]
@@ -250,7 +250,7 @@ pub mod pallet {
);
debug_assert!(res.is_ok());
Self::deposit_event(Event::<T>::Winner(winner, lottery_balance));
Self::deposit_event(Event::<T>::Winner { winner, lottery_balance });
TicketsCount::<T>::kill();
@@ -452,7 +452,7 @@ impl<T: Config> Pallet<T> {
},
)?;
Self::deposit_event(Event::<T>::TicketBought(caller.clone(), call_index));
Self::deposit_event(Event::<T>::TicketBought { who: caller.clone(), call_index });
Ok(())
}
+1 -1
View File
@@ -143,7 +143,7 @@ pub mod pallet {
/// One of the members' keys changed.
KeyChanged,
/// Phantom member, never used.
Dummy(PhantomData<(T::AccountId, <T as Config<I>>::Event)>),
Dummy { _phantom_data: PhantomData<(T::AccountId, <T as Config<I>>::Event)> },
}
/// Old name generated by `decl_event`.
+41 -22
View File
@@ -205,21 +205,30 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// A new multisig operation has begun. \[approving, multisig, call_hash\]
NewMultisig(T::AccountId, T::AccountId, CallHash),
/// A new multisig operation has begun.
NewMultisig { approving: T::AccountId, multisig: T::AccountId, call_hash: CallHash },
/// A multisig operation has been approved by someone.
/// \[approving, timepoint, multisig, call_hash\]
MultisigApproval(T::AccountId, Timepoint<T::BlockNumber>, T::AccountId, CallHash),
/// A multisig operation has been executed. \[approving, timepoint, multisig, call_hash\]
MultisigExecuted(
T::AccountId,
Timepoint<T::BlockNumber>,
T::AccountId,
CallHash,
DispatchResult,
),
/// A multisig operation has been cancelled. \[canceling, timepoint, multisig, call_hash\]
MultisigCancelled(T::AccountId, Timepoint<T::BlockNumber>, T::AccountId, CallHash),
MultisigApproval {
approving: T::AccountId,
timepoint: Timepoint<T::BlockNumber>,
multisig: T::AccountId,
call_hash: CallHash,
},
/// A multisig operation has been executed.
MultisigExecuted {
approving: T::AccountId,
timepoint: Timepoint<T::BlockNumber>,
multisig: T::AccountId,
call_hash: CallHash,
result: DispatchResult,
},
/// A multisig operation has been cancelled.
MultisigCancelled {
cancelling: T::AccountId,
timepoint: Timepoint<T::BlockNumber>,
multisig: T::AccountId,
call_hash: CallHash,
},
}
#[pallet::hooks]
@@ -481,7 +490,12 @@ pub mod pallet {
<Multisigs<T>>::remove(&id, &call_hash);
Self::clear_call(&call_hash);
Self::deposit_event(Event::MultisigCancelled(who, timepoint, id, call_hash));
Self::deposit_event(Event::MultisigCancelled {
cancelling: who,
timepoint,
multisig: id,
call_hash,
});
Ok(())
}
}
@@ -557,13 +571,13 @@ impl<T: Config> Pallet<T> {
T::Currency::unreserve(&m.depositor, m.deposit);
let result = call.dispatch(RawOrigin::Signed(id.clone()).into());
Self::deposit_event(Event::MultisigExecuted(
who,
Self::deposit_event(Event::MultisigExecuted {
approving: who,
timepoint,
id,
multisig: id,
call_hash,
result.map(|_| ()).map_err(|e| e.error),
));
result: result.map(|_| ()).map_err(|e| e.error),
});
Ok(get_result_weight(result)
.map(|actual_weight| {
T::WeightInfo::as_multi_complete(
@@ -594,7 +608,12 @@ impl<T: Config> Pallet<T> {
// Record approval.
m.approvals.insert(pos, who.clone());
<Multisigs<T>>::insert(&id, call_hash, m);
Self::deposit_event(Event::MultisigApproval(who, timepoint, id, call_hash));
Self::deposit_event(Event::MultisigApproval {
approving: who,
timepoint,
multisig: id,
call_hash,
});
} else {
// If we already approved and didn't store the Call, then this was useless and
// we report an error.
@@ -638,7 +657,7 @@ impl<T: Config> Pallet<T> {
approvals: vec![who.clone()],
},
);
Self::deposit_event(Event::NewMultisig(who, id, call_hash));
Self::deposit_event(Event::NewMultisig { approving: who, multisig: id, call_hash });
let final_weight = if stored {
T::WeightInfo::as_multi_create_store(other_signatories_len as u32, call_len as u32)
+8 -1
View File
@@ -706,7 +706,14 @@ fn multisig_2_of_3_cannot_reissue_same_call() {
let err = DispatchError::from(BalancesError::<Test, _>::InsufficientBalance).stripped();
System::assert_last_event(
pallet_multisig::Event::MultisigExecuted(3, now(), multi, hash, Err(err)).into(),
pallet_multisig::Event::MultisigExecuted {
approving: 3,
timepoint: now(),
multisig: multi,
call_hash: hash,
result: Err(err),
}
.into(),
);
});
}
+15 -15
View File
@@ -89,16 +89,16 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// A name was set. \[who\]
NameSet(T::AccountId),
/// A name was forcibly set. \[target\]
NameForced(T::AccountId),
/// A name was changed. \[who\]
NameChanged(T::AccountId),
/// A name was cleared, and the given balance returned. \[who, deposit\]
NameCleared(T::AccountId, BalanceOf<T>),
/// A name was removed and the given balance slashed. \[target, deposit\]
NameKilled(T::AccountId, BalanceOf<T>),
/// A name was set.
NameSet { who: T::AccountId },
/// A name was forcibly set.
NameForced { target: T::AccountId },
/// A name was changed.
NameChanged { who: T::AccountId },
/// A name was cleared, and the given balance returned.
NameCleared { who: T::AccountId, deposit: BalanceOf<T> },
/// A name was removed and the given balance slashed.
NameKilled { target: T::AccountId, deposit: BalanceOf<T> },
}
/// Error for the nicks pallet.
@@ -147,12 +147,12 @@ pub mod pallet {
ensure!(name.len() <= T::MaxLength::get() as usize, Error::<T>::TooLong);
let deposit = if let Some((_, deposit)) = <NameOf<T>>::get(&sender) {
Self::deposit_event(Event::<T>::NameChanged(sender.clone()));
Self::deposit_event(Event::<T>::NameChanged { who: sender.clone() });
deposit
} else {
let deposit = T::ReservationFee::get();
T::Currency::reserve(&sender, deposit.clone())?;
Self::deposit_event(Event::<T>::NameSet(sender.clone()));
Self::deposit_event(Event::<T>::NameSet { who: sender.clone() });
deposit
};
@@ -179,7 +179,7 @@ pub mod pallet {
let err_amount = T::Currency::unreserve(&sender, deposit.clone());
debug_assert!(err_amount.is_zero());
Self::deposit_event(Event::<T>::NameCleared(sender, deposit));
Self::deposit_event(Event::<T>::NameCleared { who: sender, deposit });
Ok(())
}
@@ -210,7 +210,7 @@ pub mod pallet {
// Slash their deposit from them.
T::Slashed::on_unbalanced(T::Currency::slash_reserved(&target, deposit.clone()).0);
Self::deposit_event(Event::<T>::NameKilled(target, deposit));
Self::deposit_event(Event::<T>::NameKilled { target, deposit });
Ok(())
}
@@ -238,7 +238,7 @@ pub mod pallet {
let deposit = <NameOf<T>>::get(&target).map(|x| x.1).unwrap_or_else(Zero::zero);
<NameOf<T>>::insert(&target, (name, deposit));
Self::deposit_event(Event::<T>::NameForced(target));
Self::deposit_event(Event::<T>::NameForced { target });
Ok(())
}
}
+24 -18
View File
@@ -128,24 +128,24 @@ pub mod pallet {
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// The given well known node was added.
NodeAdded(PeerId, T::AccountId),
NodeAdded { peer_id: PeerId, who: T::AccountId },
/// The given well known node was removed.
NodeRemoved(PeerId),
NodeRemoved { peer_id: PeerId },
/// The given well known node was swapped; first item was removed,
/// the latter was added.
NodeSwapped(PeerId, PeerId),
NodeSwapped { removed: PeerId, added: PeerId },
/// The given well known nodes were reset.
NodesReset(Vec<(PeerId, T::AccountId)>),
NodesReset { nodes: Vec<(PeerId, T::AccountId)> },
/// The given node was claimed by a user.
NodeClaimed(PeerId, T::AccountId),
NodeClaimed { peer_id: PeerId, who: T::AccountId },
/// The given claim was removed by its owner.
ClaimRemoved(PeerId, T::AccountId),
ClaimRemoved { peer_id: PeerId, who: T::AccountId },
/// The node was transferred to another account.
NodeTransferred(PeerId, T::AccountId),
NodeTransferred { peer_id: PeerId, target: T::AccountId },
/// The allowed connections were added to a node.
ConnectionsAdded(PeerId, Vec<PeerId>),
ConnectionsAdded { peer_id: PeerId, allowed_connections: Vec<PeerId> },
/// The allowed connections were removed from a node.
ConnectionsRemoved(PeerId, Vec<PeerId>),
ConnectionsRemoved { peer_id: PeerId, allowed_connections: Vec<PeerId> },
}
#[pallet::error]
@@ -224,7 +224,7 @@ pub mod pallet {
WellKnownNodes::<T>::put(&nodes);
<Owners<T>>::insert(&node, &owner);
Self::deposit_event(Event::NodeAdded(node, owner));
Self::deposit_event(Event::NodeAdded { peer_id: node, who: owner });
Ok(())
}
@@ -248,7 +248,7 @@ pub mod pallet {
<Owners<T>>::remove(&node);
AdditionalConnections::<T>::remove(&node);
Self::deposit_event(Event::NodeRemoved(node));
Self::deposit_event(Event::NodeRemoved { peer_id: node });
Ok(())
}
@@ -284,7 +284,7 @@ pub mod pallet {
Owners::<T>::swap(&remove, &add);
AdditionalConnections::<T>::swap(&remove, &add);
Self::deposit_event(Event::NodeSwapped(remove, add));
Self::deposit_event(Event::NodeSwapped { removed: remove, added: add });
Ok(())
}
@@ -305,7 +305,7 @@ pub mod pallet {
Self::initialize_nodes(&nodes);
Self::deposit_event(Event::NodesReset(nodes));
Self::deposit_event(Event::NodesReset { nodes });
Ok(())
}
@@ -321,7 +321,7 @@ pub mod pallet {
ensure!(!Owners::<T>::contains_key(&node), Error::<T>::AlreadyClaimed);
Owners::<T>::insert(&node, &sender);
Self::deposit_event(Event::NodeClaimed(node, sender));
Self::deposit_event(Event::NodeClaimed { peer_id: node, who: sender });
Ok(())
}
@@ -342,7 +342,7 @@ pub mod pallet {
Owners::<T>::remove(&node);
AdditionalConnections::<T>::remove(&node);
Self::deposit_event(Event::ClaimRemoved(node, sender));
Self::deposit_event(Event::ClaimRemoved { peer_id: node, who: sender });
Ok(())
}
@@ -364,7 +364,7 @@ pub mod pallet {
Owners::<T>::insert(&node, &owner);
Self::deposit_event(Event::NodeTransferred(node, owner));
Self::deposit_event(Event::NodeTransferred { peer_id: node, target: owner });
Ok(())
}
@@ -395,7 +395,10 @@ pub mod pallet {
AdditionalConnections::<T>::insert(&node, nodes);
Self::deposit_event(Event::ConnectionsAdded(node, connections));
Self::deposit_event(Event::ConnectionsAdded {
peer_id: node,
allowed_connections: connections,
});
Ok(())
}
@@ -423,7 +426,10 @@ pub mod pallet {
AdditionalConnections::<T>::insert(&node, nodes);
Self::deposit_event(Event::ConnectionsRemoved(node, connections));
Self::deposit_event(Event::ConnectionsRemoved {
peer_id: node,
allowed_connections: connections,
});
Ok(())
}
}
@@ -315,13 +315,13 @@ benchmarks! {
<T as StakingConfig>::Event::from(StakingEvent::<T>::Slashed(id, BalanceOf::<T>::from(slash_amount)))
);
let balance_slash = |id| core::iter::once(
<T as BalancesConfig>::Event::from(pallet_balances::Event::<T>::Slashed(id, slash_amount.into()))
<T as BalancesConfig>::Event::from(pallet_balances::Event::<T>::Slashed{who: id, amount: slash_amount.into()})
);
let chill = |id| core::iter::once(
<T as StakingConfig>::Event::from(StakingEvent::<T>::Chilled(id))
);
let balance_deposit = |id, amount: u32|
<T as BalancesConfig>::Event::from(pallet_balances::Event::<T>::Deposit(id, amount.into()));
<T as BalancesConfig>::Event::from(pallet_balances::Event::<T>::Deposit{who: id, amount: amount.into()});
let mut first = true;
let slash_events = raw_offenders.into_iter()
.flat_map(|offender| {
@@ -344,7 +344,7 @@ benchmarks! {
balance_deposit(reporter.clone(), reward.into()).into(),
frame_system::Event::<T>::NewAccount(reporter.clone()).into(),
<T as BalancesConfig>::Event::from(
pallet_balances::Event::<T>::Endowed(reporter.clone(), reward.into())
pallet_balances::Event::<T>::Endowed{account: reporter.clone(), free_balance: reward.into()}
).into(),
])
.collect::<Vec<_>>();
@@ -371,10 +371,10 @@ benchmarks! {
std::iter::empty()
.chain(slash_events.into_iter().map(Into::into))
.chain(std::iter::once(<T as OffencesConfig>::Event::from(
pallet_offences::Event::Offence(
UnresponsivenessOffence::<T>::ID,
0_u32.to_le_bytes().to_vec(),
)
pallet_offences::Event::Offence{
kind: UnresponsivenessOffence::<T>::ID,
timeslot: 0_u32.to_le_bytes().to_vec(),
}
).into()))
);
}
+2 -2
View File
@@ -108,7 +108,7 @@ pub mod pallet {
/// There is an offence reported of the given `kind` happened at the `session_index` and
/// (kind-specific) time slot. This event is not deposited for duplicate slashes.
/// \[kind, timeslot\].
Offence(Kind, OpaqueTimeSlot),
Offence { kind: Kind, timeslot: OpaqueTimeSlot },
}
#[pallet::hooks]
@@ -153,7 +153,7 @@ where
);
// Deposit the event.
Self::deposit_event(Event::Offence(O::ID, time_slot.encode()));
Self::deposit_event(Event::Offence { kind: O::ID, timeslot: time_slot.encode() });
Ok(())
}
+8 -2
View File
@@ -114,7 +114,10 @@ fn should_deposit_event() {
System::events(),
vec![EventRecord {
phase: Phase::Initialization,
event: Event::Offences(crate::Event::Offence(KIND, time_slot.encode())),
event: Event::Offences(crate::Event::Offence {
kind: KIND,
timeslot: time_slot.encode()
}),
topics: vec![],
}]
);
@@ -145,7 +148,10 @@ fn doesnt_deposit_event_for_dups() {
System::events(),
vec![EventRecord {
phase: Phase::Initialization,
event: Event::Offences(crate::Event::Offence(KIND, time_slot.encode())),
event: Event::Offences(crate::Event::Offence {
kind: KIND,
timeslot: time_slot.encode()
}),
topics: vec![],
}]
);
+9 -9
View File
@@ -86,7 +86,7 @@ benchmarks! {
let call: <T as Config>::Call = frame_system::Call::<T>::remark { remark: vec![] }.into();
}: _(RawOrigin::Signed(caller), real, Some(T::ProxyType::default()), Box::new(call))
verify {
assert_last_event::<T>(Event::ProxyExecuted(Ok(())).into())
assert_last_event::<T>(Event::ProxyExecuted { result: Ok(()) }.into())
}
proxy_announced {
@@ -107,7 +107,7 @@ benchmarks! {
add_announcements::<T>(a, Some(delegate.clone()), None)?;
}: _(RawOrigin::Signed(caller), delegate, real, Some(T::ProxyType::default()), Box::new(call))
verify {
assert_last_event::<T>(Event::ProxyExecuted(Ok(())).into())
assert_last_event::<T>(Event::ProxyExecuted { result: Ok(()) }.into())
}
remove_announcement {
@@ -165,7 +165,7 @@ benchmarks! {
let call_hash = T::CallHasher::hash_of(&call);
}: _(RawOrigin::Signed(caller.clone()), real.clone(), call_hash)
verify {
assert_last_event::<T>(Event::Announced(real, caller, call_hash).into());
assert_last_event::<T>(Event::Announced { real, proxy: caller, call_hash }.into());
}
add_proxy {
@@ -216,12 +216,12 @@ benchmarks! {
)
verify {
let anon_account = Pallet::<T>::anonymous_account(&caller, &T::ProxyType::default(), 0, None);
assert_last_event::<T>(Event::AnonymousCreated(
anon_account,
caller,
T::ProxyType::default(),
0,
).into());
assert_last_event::<T>(Event::AnonymousCreated {
anonymous: anon_account,
who: caller,
proxy_type: T::ProxyType::default(),
disambiguation_index: 0,
}.into());
}
kill_anonymous {
+29 -15
View File
@@ -327,7 +327,12 @@ pub mod pallet {
T::Currency::reserve(&who, deposit)?;
Proxies::<T>::insert(&anonymous, (bounded_proxies, deposit));
Self::deposit_event(Event::AnonymousCreated(anonymous, who, proxy_type, index));
Self::deposit_event(Event::AnonymousCreated {
anonymous,
who,
proxy_type,
disambiguation_index: index,
});
Ok(())
}
@@ -427,7 +432,7 @@ pub mod pallet {
})
.map(|d| *deposit = d)
})?;
Self::deposit_event(Event::Announced(real, who, call_hash));
Self::deposit_event(Event::Announced { real, proxy: who, call_hash });
Ok(())
}
@@ -547,16 +552,25 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// A proxy was executed correctly, with the given \[result\].
ProxyExecuted(DispatchResult),
/// A proxy was executed correctly, with the given.
ProxyExecuted { result: DispatchResult },
/// Anonymous account has been created by new proxy with given
/// disambiguation index and proxy type. \[anonymous, who, proxy_type,
/// disambiguation_index\]
AnonymousCreated(T::AccountId, T::AccountId, T::ProxyType, u16),
/// An announcement was placed to make a call in the future. \[real, proxy, call_hash\]
Announced(T::AccountId, T::AccountId, CallHashOf<T>),
/// A proxy was added. \[delegator, delegatee, proxy_type, delay\]
ProxyAdded(T::AccountId, T::AccountId, T::ProxyType, T::BlockNumber),
/// disambiguation index and proxy type.
AnonymousCreated {
anonymous: T::AccountId,
who: T::AccountId,
proxy_type: T::ProxyType,
disambiguation_index: u16,
},
/// An announcement was placed to make a call in the future.
Announced { real: T::AccountId, proxy: T::AccountId, call_hash: CallHashOf<T> },
/// A proxy was added.
ProxyAdded {
delegator: T::AccountId,
delegatee: T::AccountId,
proxy_type: T::ProxyType,
delay: T::BlockNumber,
},
}
/// Old name generated by `decl_event`.
@@ -672,12 +686,12 @@ impl<T: Config> Pallet<T> {
T::Currency::unreserve(delegator, *deposit - new_deposit);
}
*deposit = new_deposit;
Self::deposit_event(Event::<T>::ProxyAdded(
delegator.clone(),
Self::deposit_event(Event::<T>::ProxyAdded {
delegator: delegator.clone(),
delegatee,
proxy_type,
delay,
));
});
Ok(())
})
}
@@ -800,6 +814,6 @@ impl<T: Config> Pallet<T> {
}
});
let e = call.dispatch(origin);
Self::deposit_event(Event::ProxyExecuted(e.map(|_| ()).map_err(|e| e.error)));
Self::deposit_event(Event::ProxyExecuted { result: e.map(|_| ()).map_err(|e| e.error) });
}
}
+38 -24
View File
@@ -211,7 +211,15 @@ fn call_transfer(dest: u64, value: u64) -> Call {
fn announcement_works() {
new_test_ext().execute_with(|| {
assert_ok!(Proxy::add_proxy(Origin::signed(1), 3, ProxyType::Any, 1));
System::assert_last_event(ProxyEvent::ProxyAdded(1, 3, ProxyType::Any, 1).into());
System::assert_last_event(
ProxyEvent::ProxyAdded {
delegator: 1,
delegatee: 3,
proxy_type: ProxyType::Any,
delay: 1,
}
.into(),
);
assert_ok!(Proxy::add_proxy(Origin::signed(2), 3, ProxyType::Any, 1));
assert_eq!(Balances::reserved_balance(3), 0);
@@ -332,12 +340,12 @@ fn filtering_works() {
let call = Box::new(call_transfer(6, 1));
assert_ok!(Proxy::proxy(Origin::signed(2), 1, None, call.clone()));
System::assert_last_event(ProxyEvent::ProxyExecuted(Ok(())).into());
System::assert_last_event(ProxyEvent::ProxyExecuted { result: Ok(()) }.into());
assert_ok!(Proxy::proxy(Origin::signed(3), 1, None, call.clone()));
System::assert_last_event(ProxyEvent::ProxyExecuted(Ok(())).into());
System::assert_last_event(ProxyEvent::ProxyExecuted { result: Ok(()) }.into());
assert_ok!(Proxy::proxy(Origin::signed(4), 1, None, call.clone()));
System::assert_last_event(
ProxyEvent::ProxyExecuted(Err(SystemError::CallFiltered.into())).into(),
ProxyEvent::ProxyExecuted { result: Err(SystemError::CallFiltered.into()) }.into(),
);
let derivative_id = Utility::derivative_account_id(1, 0);
@@ -347,31 +355,31 @@ fn filtering_works() {
let call =
Box::new(Call::Utility(UtilityCall::as_derivative { index: 0, call: inner.clone() }));
assert_ok!(Proxy::proxy(Origin::signed(2), 1, None, call.clone()));
System::assert_last_event(ProxyEvent::ProxyExecuted(Ok(())).into());
System::assert_last_event(ProxyEvent::ProxyExecuted { result: Ok(()) }.into());
assert_ok!(Proxy::proxy(Origin::signed(3), 1, None, call.clone()));
System::assert_last_event(
ProxyEvent::ProxyExecuted(Err(SystemError::CallFiltered.into())).into(),
ProxyEvent::ProxyExecuted { result: Err(SystemError::CallFiltered.into()) }.into(),
);
assert_ok!(Proxy::proxy(Origin::signed(4), 1, None, call.clone()));
System::assert_last_event(
ProxyEvent::ProxyExecuted(Err(SystemError::CallFiltered.into())).into(),
ProxyEvent::ProxyExecuted { result: Err(SystemError::CallFiltered.into()) }.into(),
);
let call = Box::new(Call::Utility(UtilityCall::batch { calls: vec![*inner] }));
assert_ok!(Proxy::proxy(Origin::signed(2), 1, None, call.clone()));
expect_events(vec![
UtilityEvent::BatchCompleted.into(),
ProxyEvent::ProxyExecuted(Ok(())).into(),
ProxyEvent::ProxyExecuted { result: Ok(()) }.into(),
]);
assert_ok!(Proxy::proxy(Origin::signed(3), 1, None, call.clone()));
System::assert_last_event(
ProxyEvent::ProxyExecuted(Err(SystemError::CallFiltered.into())).into(),
ProxyEvent::ProxyExecuted { result: Err(SystemError::CallFiltered.into()) }.into(),
);
assert_ok!(Proxy::proxy(Origin::signed(4), 1, None, call.clone()));
expect_events(vec![
UtilityEvent::BatchInterrupted { index: 0, error: SystemError::CallFiltered.into() }
.into(),
ProxyEvent::ProxyExecuted(Ok(())).into(),
ProxyEvent::ProxyExecuted { result: Ok(()) }.into(),
]);
let inner =
@@ -380,32 +388,32 @@ fn filtering_works() {
assert_ok!(Proxy::proxy(Origin::signed(2), 1, None, call.clone()));
expect_events(vec![
UtilityEvent::BatchCompleted.into(),
ProxyEvent::ProxyExecuted(Ok(())).into(),
ProxyEvent::ProxyExecuted { result: Ok(()) }.into(),
]);
assert_ok!(Proxy::proxy(Origin::signed(3), 1, None, call.clone()));
System::assert_last_event(
ProxyEvent::ProxyExecuted(Err(SystemError::CallFiltered.into())).into(),
ProxyEvent::ProxyExecuted { result: Err(SystemError::CallFiltered.into()) }.into(),
);
assert_ok!(Proxy::proxy(Origin::signed(4), 1, None, call.clone()));
expect_events(vec![
UtilityEvent::BatchInterrupted { index: 0, error: SystemError::CallFiltered.into() }
.into(),
ProxyEvent::ProxyExecuted(Ok(())).into(),
ProxyEvent::ProxyExecuted { result: Ok(()) }.into(),
]);
let call = Box::new(Call::Proxy(ProxyCall::remove_proxies {}));
assert_ok!(Proxy::proxy(Origin::signed(3), 1, None, call.clone()));
System::assert_last_event(
ProxyEvent::ProxyExecuted(Err(SystemError::CallFiltered.into())).into(),
ProxyEvent::ProxyExecuted { result: Err(SystemError::CallFiltered.into()) }.into(),
);
assert_ok!(Proxy::proxy(Origin::signed(4), 1, None, call.clone()));
System::assert_last_event(
ProxyEvent::ProxyExecuted(Err(SystemError::CallFiltered.into())).into(),
ProxyEvent::ProxyExecuted { result: Err(SystemError::CallFiltered.into()) }.into(),
);
assert_ok!(Proxy::proxy(Origin::signed(2), 1, None, call.clone()));
expect_events(vec![
BalancesEvent::<Test>::Unreserved(1, 5).into(),
ProxyEvent::ProxyExecuted(Ok(())).into(),
BalancesEvent::<Test>::Unreserved { who: 1, amount: 5 }.into(),
ProxyEvent::ProxyExecuted { result: Ok(()) }.into(),
]);
});
}
@@ -476,13 +484,13 @@ fn proxying_works() {
Error::<Test>::NotProxy
);
assert_ok!(Proxy::proxy(Origin::signed(2), 1, None, call.clone()));
System::assert_last_event(ProxyEvent::ProxyExecuted(Ok(())).into());
System::assert_last_event(ProxyEvent::ProxyExecuted { result: Ok(()) }.into());
assert_eq!(Balances::free_balance(6), 1);
let call = Box::new(Call::System(SystemCall::set_code { code: vec![] }));
assert_ok!(Proxy::proxy(Origin::signed(3), 1, None, call.clone()));
System::assert_last_event(
ProxyEvent::ProxyExecuted(Err(SystemError::CallFiltered.into())).into(),
ProxyEvent::ProxyExecuted { result: Err(SystemError::CallFiltered.into()) }.into(),
);
let call =
@@ -490,10 +498,10 @@ fn proxying_works() {
assert_ok!(Call::Proxy(super::Call::new_call_variant_proxy(1, None, call.clone()))
.dispatch(Origin::signed(2)));
System::assert_last_event(
ProxyEvent::ProxyExecuted(Err(SystemError::CallFiltered.into())).into(),
ProxyEvent::ProxyExecuted { result: Err(SystemError::CallFiltered.into()) }.into(),
);
assert_ok!(Proxy::proxy(Origin::signed(3), 1, None, call.clone()));
System::assert_last_event(ProxyEvent::ProxyExecuted(Ok(())).into());
System::assert_last_event(ProxyEvent::ProxyExecuted { result: Ok(()) }.into());
assert_eq!(Balances::free_balance(6), 2);
});
}
@@ -504,7 +512,13 @@ fn anonymous_works() {
assert_ok!(Proxy::anonymous(Origin::signed(1), ProxyType::Any, 0, 0));
let anon = Proxy::anonymous_account(&1, &ProxyType::Any, 0, None);
System::assert_last_event(
ProxyEvent::AnonymousCreated(anon.clone(), 1, ProxyType::Any, 0).into(),
ProxyEvent::AnonymousCreated {
anonymous: anon.clone(),
who: 1,
proxy_type: ProxyType::Any,
disambiguation_index: 0,
}
.into(),
);
// other calls to anonymous allowed as long as they're not exactly the same.
@@ -525,7 +539,7 @@ fn anonymous_works() {
let call = Box::new(call_transfer(6, 1));
assert_ok!(Balances::transfer(Origin::signed(3), anon, 5));
assert_ok!(Proxy::proxy(Origin::signed(1), anon, None, call));
System::assert_last_event(ProxyEvent::ProxyExecuted(Ok(())).into());
System::assert_last_event(ProxyEvent::ProxyExecuted { result: Ok(()) }.into());
assert_eq!(Balances::free_balance(6), 1);
let call = Box::new(Call::Proxy(ProxyCall::new_call_variant_kill_anonymous(
@@ -537,7 +551,7 @@ fn anonymous_works() {
)));
assert_ok!(Proxy::proxy(Origin::signed(2), anon2, None, call.clone()));
let de = DispatchError::from(Error::<Test>::NoPermission).stripped();
System::assert_last_event(ProxyEvent::ProxyExecuted(Err(de)).into());
System::assert_last_event(ProxyEvent::ProxyExecuted { result: Err(de) }.into());
assert_noop!(
Proxy::kill_anonymous(Origin::signed(1), 1, ProxyType::Any, 0, 1, 0),
Error::<Test>::NoPermission
+1 -1
View File
@@ -190,7 +190,7 @@ pub(crate) struct SpanRecord<Balance> {
impl<Balance> SpanRecord<Balance> {
/// The value of stash balance slashed in this span.
#[cfg(test)]
pub(crate) fn amount_slashed(&self) -> &Balance {
pub(crate) fn amount(&self) -> &Balance {
&self.slashed
}
}
+2 -2
View File
@@ -2469,7 +2469,7 @@ fn garbage_collection_after_slashing() {
assert_eq!(Balances::free_balance(11), 2000 - 200);
assert!(<Staking as crate::Store>::SlashingSpans::get(&11).is_some());
assert_eq!(<Staking as crate::Store>::SpanSlash::get(&(11, 0)).amount_slashed(), &200);
assert_eq!(<Staking as crate::Store>::SpanSlash::get(&(11, 0)).amount(), &200);
on_offence_now(
&[OffenceDetails {
@@ -2496,7 +2496,7 @@ fn garbage_collection_after_slashing() {
assert_ok!(Staking::reap_stash(Origin::signed(20), 11, 2));
assert!(<Staking as crate::Store>::SlashingSpans::get(&11).is_none());
assert_eq!(<Staking as crate::Store>::SpanSlash::get(&(11, 0)).amount_slashed(), &0);
assert_eq!(<Staking as crate::Store>::SpanSlash::get(&(11, 0)).amount(), &0);
})
}
@@ -1363,9 +1363,11 @@ mod tests {
));
assert_eq!(Balances::free_balance(2), 0);
// Transfer Event
System::assert_has_event(Event::Balances(pallet_balances::Event::Transfer(
2, 3, 80,
)));
System::assert_has_event(Event::Balances(pallet_balances::Event::Transfer {
from: 2,
to: 3,
amount: 80,
}));
// Killed Event
System::assert_has_event(Event::System(system::Event::KilledAccount(2)));
});