Skip to content

Commit

Permalink
Add field names to pallet Event variants (paritytech#9993)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Wizdave97 authored and ark0f committed Feb 27, 2023
1 parent f9a4616 commit c08cc21
Show file tree
Hide file tree
Showing 48 changed files with 1,181 additions and 681 deletions.
69 changes: 39 additions & 30 deletions bin/node/executor/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
56 changes: 28 additions & 28 deletions frame/assets/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ 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 {
let caller: T::AccountId = whitelisted_caller();
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 {
Expand All @@ -177,23 +177,23 @@ 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 {
let (caller, caller_lookup) = create_default_asset::<T, I>(true);
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 {
let amount = T::Balance::from(100u32);
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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -226,15 +226,15 @@ 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()
);
}

freeze {
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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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)
Expand Down
Loading

0 comments on commit c08cc21

Please sign in to comment.