From 9fb1887cd23eb272844d63640b0b2d9ba3e549a1 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Tue, 12 Apr 2022 11:45:30 +0200 Subject: [PATCH 1/6] Box events Signed-off-by: Oliver Tale-Yazdi --- .../procedural/src/construct_runtime/expand/event.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/frame/support/procedural/src/construct_runtime/expand/event.rs b/frame/support/procedural/src/construct_runtime/expand/event.rs index b242f9641562..12a1b49d14c4 100644 --- a/frame/support/procedural/src/construct_runtime/expand/event.rs +++ b/frame/support/procedural/src/construct_runtime/expand/event.rs @@ -100,16 +100,16 @@ fn expand_event_variant( match instance { Some(inst) if part_is_generic => { - quote!(#[codec(index = #index)] #variant_name(#path::Event<#runtime, #path::#inst>),) + quote!(#[codec(index = #index)] #variant_name(Box<#path::Event<#runtime, #path::#inst>>),) }, Some(inst) => { - quote!(#[codec(index = #index)] #variant_name(#path::Event<#path::#inst>),) + quote!(#[codec(index = #index)] #variant_name(Box<#path::Event<#path::#inst>>),) }, None if part_is_generic => { - quote!(#[codec(index = #index)] #variant_name(#path::Event<#runtime>),) + quote!(#[codec(index = #index)] #variant_name(Box<#path::Event<#runtime>>),) }, None => { - quote!(#[codec(index = #index)] #variant_name(#path::Event),) + quote!(#[codec(index = #index)] #variant_name(Box<#path::Event>),) }, } } @@ -124,7 +124,7 @@ fn expand_event_conversion( quote! { impl From<#pallet_event> for Event { fn from(x: #pallet_event) -> Self { - Event::#variant_name(x) + Event::#variant_name(Box::new(x)) } } impl TryInto<#pallet_event> for Event { @@ -132,7 +132,7 @@ fn expand_event_conversion( fn try_into(self) -> #scrate::sp_std::result::Result<#pallet_event, Self::Error> { match self { - Self::#variant_name(evt) => Ok(evt), + Self::#variant_name(evt) => Ok(*evt), _ => Err(()), } } From 981c50f23a7c514c9527299734bc6bc5b77a817f Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Tue, 12 Apr 2022 16:39:18 +0200 Subject: [PATCH 2/6] Fix tests Signed-off-by: Oliver Tale-Yazdi --- bin/node/executor/tests/basic.rs | 175 +++-- frame/assets/src/tests.rs | 9 +- frame/balances/src/tests.rs | 38 +- frame/balances/src/tests_local.rs | 14 +- frame/balances/src/tests_reentrancy.rs | 48 +- frame/bounties/src/tests.rs | 2 +- frame/child-bounties/src/tests.rs | 2 +- frame/collective/src/tests.rs | 713 ++++++++++-------- frame/contracts/src/exec.rs | 29 +- frame/contracts/src/tests.rs | 493 +++++++----- .../election-provider-multi-phase/src/mock.rs | 2 +- frame/elections-phragmen/src/lib.rs | 22 +- frame/offences/src/tests.rs | 14 +- frame/staking/src/mock.rs | 2 +- frame/sudo/src/tests.rs | 15 +- frame/support/test/tests/pallet.rs | 28 +- frame/support/test/tests/pallet_instance.rs | 16 +- frame/tips/src/tests.rs | 2 +- frame/transaction-payment/src/lib.rs | 12 +- 19 files changed, 916 insertions(+), 720 deletions(-) diff --git a/bin/node/executor/tests/basic.rs b/bin/node/executor/tests/basic.rs index da0f4e6afb31..e458b78af57a 100644 --- a/bin/node/executor/tests/basic.rs +++ b/bin/node/executor/tests/basic.rs @@ -378,50 +378,66 @@ fn full_native_block_import_works() { let events = vec![ EventRecord { phase: Phase::ApplyExtrinsic(0), - event: Event::System(frame_system::Event::ExtrinsicSuccess { - dispatch_info: DispatchInfo { - weight: timestamp_weight, - class: DispatchClass::Mandatory, - ..Default::default() - }, - }), + event: Event::System( + frame_system::Event::ExtrinsicSuccess { + dispatch_info: DispatchInfo { + weight: timestamp_weight, + class: DispatchClass::Mandatory, + ..Default::default() + }, + } + .into(), + ), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(1), - event: Event::Balances(pallet_balances::Event::Withdraw { - who: alice().into(), - amount: fees, - }), + event: Event::Balances( + pallet_balances::Event::Withdraw { who: alice().into(), amount: fees }.into(), + ), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(1), - event: Event::Balances(pallet_balances::Event::Transfer { - from: alice().into(), - to: bob().into(), - amount: 69 * DOLLARS, - }), + event: Event::Balances( + pallet_balances::Event::Transfer { + from: alice().into(), + to: bob().into(), + amount: 69 * DOLLARS, + } + .into(), + ), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(1), - event: Event::Balances(pallet_balances::Event::Deposit { - who: pallet_treasury::Pallet::::account_id(), - amount: fees * 8 / 10, - }), + event: Event::Balances( + pallet_balances::Event::Deposit { + who: pallet_treasury::Pallet::::account_id(), + amount: fees * 8 / 10, + } + .into(), + ), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(1), - event: Event::Treasury(pallet_treasury::Event::Deposit { value: fees * 8 / 10 }), + event: Event::Treasury( + pallet_treasury::Event::Deposit { value: fees * 8 / 10 }.into(), + ), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(1), - event: Event::System(frame_system::Event::ExtrinsicSuccess { - dispatch_info: DispatchInfo { weight: transfer_weight, ..Default::default() }, - }), + event: Event::System( + frame_system::Event::ExtrinsicSuccess { + dispatch_info: DispatchInfo { + weight: transfer_weight, + ..Default::default() + }, + } + .into(), + ), topics: vec![], }, ]; @@ -449,87 +465,116 @@ fn full_native_block_import_works() { let events = vec![ EventRecord { phase: Phase::ApplyExtrinsic(0), - event: Event::System(frame_system::Event::ExtrinsicSuccess { - dispatch_info: DispatchInfo { - weight: timestamp_weight, - class: DispatchClass::Mandatory, - ..Default::default() - }, - }), + event: Event::System( + frame_system::Event::ExtrinsicSuccess { + dispatch_info: DispatchInfo { + weight: timestamp_weight, + class: DispatchClass::Mandatory, + ..Default::default() + }, + } + .into(), + ), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(1), - event: Event::Balances(pallet_balances::Event::Withdraw { - who: bob().into(), - amount: fees, - }), + event: Event::Balances( + pallet_balances::Event::Withdraw { who: bob().into(), amount: fees }.into(), + ), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(1), - event: Event::Balances(pallet_balances::Event::Transfer { - from: bob().into(), - to: alice().into(), - amount: 5 * DOLLARS, - }), + event: Event::Balances( + pallet_balances::Event::Transfer { + from: bob().into(), + to: alice().into(), + amount: 5 * DOLLARS, + } + .into(), + ), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(1), - event: Event::Balances(pallet_balances::Event::Deposit { - who: pallet_treasury::Pallet::::account_id(), - amount: fees * 8 / 10, - }), + event: Event::Balances( + pallet_balances::Event::Deposit { + who: pallet_treasury::Pallet::::account_id(), + amount: fees * 8 / 10, + } + .into(), + ), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(1), - event: Event::Treasury(pallet_treasury::Event::Deposit { value: fees * 8 / 10 }), + event: Event::Treasury( + pallet_treasury::Event::Deposit { value: fees * 8 / 10 }.into(), + ), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(1), - event: Event::System(frame_system::Event::ExtrinsicSuccess { - dispatch_info: DispatchInfo { weight: transfer_weight, ..Default::default() }, - }), + event: Event::System( + frame_system::Event::ExtrinsicSuccess { + dispatch_info: DispatchInfo { + weight: transfer_weight, + ..Default::default() + }, + } + .into(), + ), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(2), - event: Event::Balances(pallet_balances::Event::Withdraw { - who: alice().into(), - amount: fees, - }), + event: Event::Balances( + pallet_balances::Event::Withdraw { who: alice().into(), amount: fees }.into(), + ), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(2), - event: Event::Balances(pallet_balances::Event::Transfer { - from: alice().into(), - to: bob().into(), - amount: 15 * DOLLARS, - }), + event: Event::Balances( + pallet_balances::Event::Transfer { + from: alice().into(), + to: bob().into(), + amount: 15 * DOLLARS, + } + .into(), + ), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(2), - event: Event::Balances(pallet_balances::Event::Deposit { - who: pallet_treasury::Pallet::::account_id(), - amount: fees * 8 / 10, - }), + event: Event::Balances( + pallet_balances::Event::Deposit { + who: pallet_treasury::Pallet::::account_id(), + amount: fees * 8 / 10, + } + .into(), + ), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(2), - event: Event::Treasury(pallet_treasury::Event::Deposit { value: fees * 8 / 10 }), + event: Event::Treasury( + pallet_treasury::Event::Deposit { value: fees * 8 / 10 }.into(), + ), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(2), - event: Event::System(frame_system::Event::ExtrinsicSuccess { - dispatch_info: DispatchInfo { weight: transfer_weight, ..Default::default() }, - }), + event: Event::System( + frame_system::Event::ExtrinsicSuccess { + dispatch_info: DispatchInfo { + weight: transfer_weight, + ..Default::default() + }, + } + .into(), + ), topics: vec![], }, ]; diff --git a/frame/assets/src/tests.rs b/frame/assets/src/tests.rs index 7430b742e7d2..2bf332f2cdcc 100644 --- a/frame/assets/src/tests.rs +++ b/frame/assets/src/tests.rs @@ -620,12 +620,9 @@ 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 { - asset_id: 0, - from: 1, - to: 2, - amount: 0, - })); + System::assert_last_event( + crate::Event::Transferred { asset_id: 0, from: 1, to: 2, amount: 0 }.into(), + ); }); } diff --git a/frame/balances/src/tests.rs b/frame/balances/src/tests.rs index 8f5470ae3cac..247fa0dacd94 100644 --- a/frame/balances/src/tests.rs +++ b/frame/balances/src/tests.rs @@ -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 { who: 1, amount: 10 })); + System::assert_last_event(crate::Event::Deposit { who: 1, amount: 10 }.into()); assert_eq!(Balances::total_balance(&1), 20); assert_eq!(>::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 { who: 1, amount: 42 })); + System::assert_has_event(crate::Event::Deposit { who: 1, amount: 42 }.into()); 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 { who: 2, amount: 11 })); + System::assert_last_event(crate::Event::Withdraw { who: 2, amount: 11 }.into()); assert_eq!(Balances::free_balance(2), 100); assert_eq!(>::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 { from: 1, to: 2, amount: 41, destination_status: Status::Free }) + crate::Event::ReserveRepatriated { from: 1, to: 2, amount: 41, destination_status: Status::Free }.into() ); 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 { who: 1, amount: 10 })); + System::assert_last_event(crate::Event::Reserved { who: 1, amount: 10 }.into()); System::set_block_number(3); assert!(Balances::unreserve(&1, 5).is_zero()); - System::assert_last_event(Event::Balances(crate::Event::Unreserved { who: 1, amount: 5 })); + System::assert_last_event(crate::Event::Unreserved { who: 1, amount: 5 }.into()); 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 { who: 1, amount: 5 })); + System::assert_last_event(crate::Event::Unreserved { who: 1, amount: 5 }.into()); }); } @@ -750,9 +750,9 @@ macro_rules! decl_tests { assert_eq!( events(), [ - Event::System(system::Event::NewAccount { account: 1 }), - Event::Balances(crate::Event::Endowed { account: 1, free_balance: 100 }), - Event::Balances(crate::Event::BalanceSet { who: 1, free: 100, reserved: 0 }), + system::Event::NewAccount { account: 1 }.into(), + crate::Event::Endowed { account: 1, free_balance: 100 }.into(), + crate::Event::BalanceSet { who: 1, free: 100, reserved: 0 }.into(), ] ); @@ -762,9 +762,9 @@ macro_rules! decl_tests { assert_eq!( events(), [ - Event::System(system::Event::KilledAccount { account: 1 }), - Event::Balances(crate::Event::DustLost { account: 1, amount: 99 }), - Event::Balances(crate::Event::Slashed { who: 1, amount: 1 }), + system::Event::KilledAccount { account: 1 }.into(), + crate::Event::DustLost { account: 1, amount: 99 }.into(), + crate::Event::Slashed { who: 1, amount: 1 }.into(), ] ); }); @@ -781,9 +781,9 @@ macro_rules! decl_tests { assert_eq!( events(), [ - Event::System(system::Event::NewAccount { account: 1 }), - Event::Balances(crate::Event::Endowed { account: 1, free_balance: 100 }), - Event::Balances(crate::Event::BalanceSet { who: 1, free: 100, reserved: 0 }), + system::Event::NewAccount { account: 1 }.into(), + crate::Event::Endowed { account: 1, free_balance: 100 }.into(), + crate::Event::BalanceSet { who: 1, free: 100, reserved: 0 }.into(), ] ); @@ -793,8 +793,8 @@ macro_rules! decl_tests { assert_eq!( events(), [ - Event::System(system::Event::KilledAccount { account: 1 }), - Event::Balances(crate::Event::Slashed { who: 1, amount: 100 }), + system::Event::KilledAccount { account: 1 }.into(), + crate::Event::Slashed { who: 1, amount: 100 }.into(), ] ); }); @@ -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 { who: 1, amount: 900 })); + System::assert_last_event(crate::Event::Slashed { who: 1, amount: 900 }.into()); // SCENARIO: Slash will kill account because not enough balance left. assert_ok!(Balances::set_balance(Origin::root(), 1, 1_000, 0)); diff --git a/frame/balances/src/tests_local.rs b/frame/balances/src/tests_local.rs index cfc7f84ab3a3..d00d3cbfab52 100644 --- a/frame/balances/src/tests_local.rs +++ b/frame/balances/src/tests_local.rs @@ -157,9 +157,9 @@ fn emit_events_with_no_existential_deposit_suicide_with_dust() { assert_eq!( events(), [ - Event::System(system::Event::NewAccount { account: 1 }), - Event::Balances(crate::Event::Endowed { account: 1, free_balance: 100 }), - Event::Balances(crate::Event::BalanceSet { who: 1, free: 100, reserved: 0 }), + system::Event::NewAccount { account: 1 }.into(), + crate::Event::Endowed { account: 1, free_balance: 100 }.into(), + crate::Event::BalanceSet { who: 1, free: 100, reserved: 0 }.into(), ] ); @@ -167,7 +167,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 { who: 1, amount: 98 })]); + assert_eq!(events(), [crate::Event::Slashed { who: 1, amount: 98 }.into()]); let res = Balances::slash(&1, 1); assert_eq!(res, (NegativeImbalance::new(1), 0)); @@ -175,9 +175,9 @@ fn emit_events_with_no_existential_deposit_suicide_with_dust() { assert_eq!( events(), [ - Event::System(system::Event::KilledAccount { account: 1 }), - Event::Balances(crate::Event::DustLost { account: 1, amount: 1 }), - Event::Balances(crate::Event::Slashed { who: 1, amount: 1 }) + system::Event::KilledAccount { account: 1 }.into(), + crate::Event::DustLost { account: 1, amount: 1 }.into(), + crate::Event::Slashed { who: 1, amount: 1 }.into() ] ); }); diff --git a/frame/balances/src/tests_reentrancy.rs b/frame/balances/src/tests_reentrancy.rs index 7037e9615afd..3d4ad95f8ed5 100644 --- a/frame/balances/src/tests_reentrancy.rs +++ b/frame/balances/src/tests_reentrancy.rs @@ -167,16 +167,9 @@ 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 { - 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 })); + System::assert_has_event(crate::Event::Transfer { from: 2, to: 3, amount: 450 }.into()); + System::assert_has_event(crate::Event::DustLost { account: 2, amount: 50 }.into()); + System::assert_has_event(crate::Event::Deposit { who: 1, amount: 50 }.into()); }); } @@ -202,16 +195,9 @@ 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 { - 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 })); + System::assert_has_event(crate::Event::Transfer { from: 2, to: 1, amount: 450 }.into()); + System::assert_has_event(crate::Event::DustLost { account: 2, amount: 50 }.into()); + System::assert_has_event(crate::Event::Deposit { who: 1, amount: 50 }.into()); }); } @@ -246,18 +232,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 { - from: 2, - to: 1, - amount: 450, - destination_status: Status::Free, - })); + System::assert_has_event( + crate::Event::ReserveRepatriated { + from: 2, + to: 1, + amount: 450, + destination_status: Status::Free, + } + .into(), + ); - System::assert_has_event(Event::Balances(crate::Event::DustLost { - account: 2, - amount: 50, - })); + System::assert_has_event(crate::Event::DustLost { account: 2, amount: 50 }.into()); - System::assert_last_event(Event::Balances(crate::Event::Deposit { who: 1, amount: 50 })); + System::assert_last_event(crate::Event::Deposit { who: 1, amount: 50 }.into()); }); } diff --git a/frame/bounties/src/tests.rs b/frame/bounties/src/tests.rs index 9a84bd687abc..03a31ec6bccd 100644 --- a/frame/bounties/src/tests.rs +++ b/frame/bounties/src/tests.rs @@ -169,7 +169,7 @@ fn last_event() -> BountiesEvent { System::events() .into_iter() .map(|r| r.event) - .filter_map(|e| if let Event::Bounties(inner) = e { Some(inner) } else { None }) + .filter_map(|e| if let Event::Bounties(inner) = e { Some(*inner) } else { None }) .last() .unwrap() } diff --git a/frame/child-bounties/src/tests.rs b/frame/child-bounties/src/tests.rs index 61545561a26c..2ac00b1e44af 100644 --- a/frame/child-bounties/src/tests.rs +++ b/frame/child-bounties/src/tests.rs @@ -175,7 +175,7 @@ fn last_event() -> ChildBountiesEvent { System::events() .into_iter() .map(|r| r.event) - .filter_map(|e| if let Event::ChildBounties(inner) = e { Some(inner) } else { None }) + .filter_map(|e| if let Event::ChildBounties(inner) = e { Some(*inner) } else { None }) .last() .unwrap() } diff --git a/frame/collective/src/tests.rs b/frame/collective/src/tests.rs index a8abfb0c5235..b13d8b9da328 100644 --- a/frame/collective/src/tests.rs +++ b/frame/collective/src/tests.rs @@ -216,32 +216,41 @@ fn close_works() { assert_eq!( System::events(), vec![ - 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 })) + record(Event::Collective( + CollectiveEvent::Proposed { + account: 1, + proposal_index: 0, + proposal_hash: hash, + threshold: 3 + } + .into() + )), + record(Event::Collective( + CollectiveEvent::Voted { + account: 1, + proposal_hash: hash, + voted: true, + yes: 1, + no: 0 + } + .into() + )), + record(Event::Collective( + CollectiveEvent::Voted { + account: 2, + proposal_hash: hash, + voted: true, + yes: 2, + no: 0 + } + .into() + )), + record(Event::Collective( + CollectiveEvent::Closed { proposal_hash: hash, yes: 2, no: 1 }.into() + )), + record(Event::Collective( + CollectiveEvent::Disapproved { proposal_hash: hash }.into() + )) ] ); }); @@ -336,32 +345,41 @@ fn close_with_prime_works() { assert_eq!( System::events(), vec![ - 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 })) + record(Event::Collective( + CollectiveEvent::Proposed { + account: 1, + proposal_index: 0, + proposal_hash: hash, + threshold: 3 + } + .into() + )), + record(Event::Collective( + CollectiveEvent::Voted { + account: 1, + proposal_hash: hash, + voted: true, + yes: 1, + no: 0 + } + .into() + )), + record(Event::Collective( + CollectiveEvent::Voted { + account: 2, + proposal_hash: hash, + voted: true, + yes: 2, + no: 0 + } + .into() + )), + record(Event::Collective( + CollectiveEvent::Closed { proposal_hash: hash, yes: 2, no: 1 }.into() + )), + record(Event::Collective( + CollectiveEvent::Disapproved { proposal_hash: hash }.into() + )) ] ); }); @@ -396,36 +414,46 @@ fn close_with_voting_prime_works() { assert_eq!( System::events(), vec![ - 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) - })) + record(Event::Collective( + CollectiveEvent::Proposed { + account: 1, + proposal_index: 0, + proposal_hash: hash, + threshold: 3 + } + .into() + )), + record(Event::Collective( + CollectiveEvent::Voted { + account: 1, + proposal_hash: hash, + voted: true, + yes: 1, + no: 0 + } + .into() + )), + record(Event::Collective( + CollectiveEvent::Voted { + account: 2, + proposal_hash: hash, + voted: true, + yes: 2, + no: 0 + } + .into() + )), + record(Event::Collective( + CollectiveEvent::Closed { proposal_hash: hash, yes: 3, no: 0 }.into() + )), + record(Event::Collective(CollectiveEvent::Approved { proposal_hash: hash }.into())), + record(Event::Collective( + CollectiveEvent::Executed { + proposal_hash: hash, + result: Err(DispatchError::BadOrigin) + } + .into() + )) ] ); }); @@ -467,45 +495,58 @@ fn close_with_no_prime_but_majority_works() { assert_eq!( System::events(), vec![ - 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) - })) + record(Event::CollectiveMajority( + CollectiveEvent::Proposed { + account: 1, + proposal_index: 0, + proposal_hash: hash, + threshold: 5 + } + .into() + )), + record(Event::CollectiveMajority( + CollectiveEvent::Voted { + account: 1, + proposal_hash: hash, + voted: true, + yes: 1, + no: 0 + } + .into() + )), + record(Event::CollectiveMajority( + CollectiveEvent::Voted { + account: 2, + proposal_hash: hash, + voted: true, + yes: 2, + no: 0 + } + .into() + )), + record(Event::CollectiveMajority( + CollectiveEvent::Voted { + account: 3, + proposal_hash: hash, + voted: true, + yes: 3, + no: 0 + } + .into() + )), + record(Event::CollectiveMajority( + CollectiveEvent::Closed { proposal_hash: hash, yes: 5, no: 0 }.into() + )), + record(Event::CollectiveMajority( + CollectiveEvent::Approved { proposal_hash: hash }.into() + )), + record(Event::CollectiveMajority( + CollectiveEvent::Executed { + proposal_hash: hash, + result: Err(DispatchError::BadOrigin) + } + .into() + )) ] ); }); @@ -629,12 +670,15 @@ fn propose_works() { assert_eq!( System::events(), - vec![record(Event::Collective(CollectiveEvent::Proposed { - account: 1, - proposal_index: 0, - proposal_hash: hash, - threshold: 3 - }))] + vec![record(Event::Collective( + CollectiveEvent::Proposed { + account: 1, + proposal_index: 0, + proposal_hash: hash, + threshold: 3 + } + .into() + ))] ); }); } @@ -793,26 +837,35 @@ fn motions_vote_after_works() { assert_eq!( System::events(), vec![ - 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 - })), + record(Event::Collective( + CollectiveEvent::Proposed { + account: 1, + proposal_index: 0, + proposal_hash: hash, + threshold: 2 + } + .into() + )), + record(Event::Collective( + CollectiveEvent::Voted { + account: 1, + proposal_hash: hash, + voted: true, + yes: 1, + no: 0 + } + .into() + )), + record(Event::Collective( + CollectiveEvent::Voted { + account: 1, + proposal_hash: hash, + voted: false, + yes: 0, + no: 1 + } + .into() + )), ] ); }); @@ -926,36 +979,46 @@ fn motions_approval_with_enough_votes_and_lower_voting_threshold_works() { assert_eq!( System::events(), vec![ - 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) - })), + record(Event::Collective( + CollectiveEvent::Proposed { + account: 1, + proposal_index: 0, + proposal_hash: hash, + threshold: 2 + } + .into() + )), + record(Event::Collective( + CollectiveEvent::Voted { + account: 1, + proposal_hash: hash, + voted: true, + yes: 1, + no: 0 + } + .into() + )), + record(Event::Collective( + CollectiveEvent::Voted { + account: 2, + proposal_hash: hash, + voted: true, + yes: 2, + no: 0 + } + .into() + )), + record(Event::Collective( + CollectiveEvent::Closed { proposal_hash: hash, yes: 2, no: 0 }.into() + )), + record(Event::Collective(CollectiveEvent::Approved { proposal_hash: hash }.into())), + record(Event::Collective( + CollectiveEvent::Executed { + proposal_hash: hash, + result: Err(DispatchError::BadOrigin) + } + .into() + )), ] ); @@ -975,44 +1038,55 @@ fn motions_approval_with_enough_votes_and_lower_voting_threshold_works() { assert_eq!( System::events(), vec![ - 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::::ExternalProposed)), - record(Event::Collective(CollectiveEvent::Executed { - proposal_hash: hash, - result: Ok(()) - })), + record(Event::Collective( + CollectiveEvent::Proposed { + account: 1, + proposal_index: 1, + proposal_hash: hash, + threshold: 2 + } + .into() + )), + record(Event::Collective( + CollectiveEvent::Voted { + account: 1, + proposal_hash: hash, + voted: true, + yes: 1, + no: 0 + } + .into() + )), + record(Event::Collective( + CollectiveEvent::Voted { + account: 2, + proposal_hash: hash, + voted: true, + yes: 2, + no: 0 + } + .into() + )), + record(Event::Collective( + CollectiveEvent::Voted { + account: 3, + proposal_hash: hash, + voted: true, + yes: 3, + no: 0 + } + .into() + )), + record(Event::Collective( + CollectiveEvent::Closed { proposal_hash: hash, yes: 3, no: 0 }.into() + )), + record(Event::Collective(CollectiveEvent::Approved { proposal_hash: hash }.into())), + record(Event::Democracy( + mock_democracy::pallet::Event::::ExternalProposed.into() + )), + record(Event::Collective( + CollectiveEvent::Executed { proposal_hash: hash, result: Ok(()) }.into() + )), ] ); }); @@ -1038,32 +1112,41 @@ fn motions_disapproval_works() { assert_eq!( System::events(), vec![ - 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 })), + record(Event::Collective( + CollectiveEvent::Proposed { + account: 1, + proposal_index: 0, + proposal_hash: hash, + threshold: 3 + } + .into() + )), + record(Event::Collective( + CollectiveEvent::Voted { + account: 1, + proposal_hash: hash, + voted: true, + yes: 1, + no: 0 + } + .into() + )), + record(Event::Collective( + CollectiveEvent::Voted { + account: 2, + proposal_hash: hash, + voted: false, + yes: 1, + no: 1 + } + .into() + )), + record(Event::Collective( + CollectiveEvent::Closed { proposal_hash: hash, yes: 1, no: 1 }.into() + )), + record(Event::Collective( + CollectiveEvent::Disapproved { proposal_hash: hash }.into() + )), ] ); }); @@ -1089,36 +1172,46 @@ fn motions_approval_works() { assert_eq!( System::events(), vec![ - 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) - })), + record(Event::Collective( + CollectiveEvent::Proposed { + account: 1, + proposal_index: 0, + proposal_hash: hash, + threshold: 2 + } + .into() + )), + record(Event::Collective( + CollectiveEvent::Voted { + account: 1, + proposal_hash: hash, + voted: true, + yes: 1, + no: 0 + } + .into() + )), + record(Event::Collective( + CollectiveEvent::Voted { + account: 2, + proposal_hash: hash, + voted: true, + yes: 2, + no: 0 + } + .into() + )), + record(Event::Collective( + CollectiveEvent::Closed { proposal_hash: hash, yes: 2, no: 0 }.into() + )), + record(Event::Collective(CollectiveEvent::Approved { proposal_hash: hash }.into())), + record(Event::Collective( + CollectiveEvent::Executed { + proposal_hash: hash, + result: Err(DispatchError::BadOrigin) + } + .into() + )), ] ); }); @@ -1139,12 +1232,15 @@ fn motion_with_no_votes_closes_with_disapproval() { )); assert_eq!( System::events()[0], - record(Event::Collective(CollectiveEvent::Proposed { - account: 1, - proposal_index: 0, - proposal_hash: hash, - threshold: 3 - })) + record(Event::Collective( + CollectiveEvent::Proposed { + account: 1, + proposal_index: 0, + proposal_hash: hash, + threshold: 3 + } + .into() + )) ); // Closing the motion too early is not possible because it has neither @@ -1163,15 +1259,13 @@ 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 { - proposal_hash: hash, - yes: 0, - no: 3 - })) + record(Event::Collective( + CollectiveEvent::Closed { proposal_hash: hash, yes: 0, no: 3 }.into() + )) ); assert_eq!( System::events()[2], - record(Event::Collective(CollectiveEvent::Disapproved { proposal_hash: hash })) + record(Event::Collective(CollectiveEvent::Disapproved { proposal_hash: hash }.into())) ); }) } @@ -1231,27 +1325,38 @@ fn disapprove_proposal_works() { assert_eq!( System::events(), vec![ - 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 })), + record(Event::Collective( + CollectiveEvent::Proposed { + account: 1, + proposal_index: 0, + proposal_hash: hash, + threshold: 2 + } + .into() + )), + record(Event::Collective( + CollectiveEvent::Voted { + account: 1, + proposal_hash: hash, + voted: true, + yes: 1, + no: 0 + } + .into() + )), + record(Event::Collective( + CollectiveEvent::Voted { + account: 2, + proposal_hash: hash, + voted: true, + yes: 2, + no: 0 + } + .into() + )), + record(Event::Collective( + CollectiveEvent::Disapproved { proposal_hash: hash }.into() + )), ] ); }) diff --git a/frame/contracts/src/exec.rs b/frame/contracts/src/exec.rs index 7aa5c0b731fa..26ca2e4bb446 100644 --- a/frame/contracts/src/exec.rs +++ b/frame/contracts/src/exec.rs @@ -1289,7 +1289,7 @@ mod tests { System::events() .into_iter() .filter_map(|meta| match meta.event { - MetaEvent::Contracts(contract_event) => Some(contract_event), + MetaEvent::Contracts(contract_event) => Some(*contract_event), _ => None, }) .collect() @@ -2434,10 +2434,9 @@ mod tests { System::events(), vec![EventRecord { phase: Phase::Initialization, - event: MetaEvent::System(frame_system::Event::Remarked { - sender: BOB, - hash: remark_hash - }), + event: MetaEvent::System( + frame_system::Event::Remarked { sender: BOB, hash: remark_hash }.into() + ), topics: vec![], },] ); @@ -2506,23 +2505,25 @@ mod tests { vec![ EventRecord { phase: Phase::Initialization, - event: MetaEvent::System(frame_system::Event::Remarked { - sender: BOB, - hash: remark_hash - }), + event: MetaEvent::System( + frame_system::Event::Remarked { sender: BOB, hash: remark_hash }.into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: MetaEvent::Utility(pallet_utility::Event::ItemCompleted), + event: MetaEvent::Utility(pallet_utility::Event::ItemCompleted.into()), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: MetaEvent::Utility(pallet_utility::Event::BatchInterrupted { - index: 1, - error: frame_system::Error::::CallFiltered.into() - },), + event: MetaEvent::Utility( + pallet_utility::Event::BatchInterrupted { + index: 1, + error: frame_system::Error::::CallFiltered.into() + } + .into(), + ), topics: vec![], }, ] diff --git a/frame/contracts/src/tests.rs b/frame/contracts/src/tests.rs index ce59f5bb858a..bf909a81c5fd 100644 --- a/frame/contracts/src/tests.rs +++ b/frame/contracts/src/tests.rs @@ -407,57 +407,71 @@ fn instantiate_and_call_and_deposit_event() { vec![ EventRecord { phase: Phase::Initialization, - event: Event::System(frame_system::Event::NewAccount { account: addr.clone() }), + event: Event::System( + frame_system::Event::NewAccount { account: addr.clone() }.into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Endowed { - account: addr.clone(), - free_balance: min_balance, - }), + event: Event::Balances( + pallet_balances::Event::Endowed { + account: addr.clone(), + free_balance: min_balance, + } + .into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Transfer { - from: ALICE, - to: addr.clone(), - amount: min_balance, - }), + event: Event::Balances( + pallet_balances::Event::Transfer { + from: ALICE, + to: addr.clone(), + amount: min_balance, + } + .into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Reserved { - who: addr.clone(), - amount: min_balance, - }), + event: Event::Balances( + pallet_balances::Event::Reserved { who: addr.clone(), amount: min_balance } + .into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Transfer { - from: ALICE, - to: addr.clone(), - amount: value, - }), + event: Event::Balances( + pallet_balances::Event::Transfer { + from: ALICE, + to: addr.clone(), + amount: value, + } + .into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Contracts(crate::Event::ContractEmitted { - contract: addr.clone(), - data: vec![1, 2, 3, 4] - }), + event: Event::Contracts( + crate::Event::ContractEmitted { + contract: addr.clone(), + data: vec![1, 2, 3, 4] + } + .into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Contracts(crate::Event::Instantiated { - deployer: ALICE, - contract: addr.clone() - }), + event: Event::Contracts( + crate::Event::Instantiated { deployer: ALICE, contract: addr.clone() } + .into() + ), topics: vec![], }, ] @@ -699,60 +713,78 @@ fn deploy_and_call_other_contract() { vec![ EventRecord { phase: Phase::Initialization, - event: Event::System(frame_system::Event::NewAccount { - account: callee_addr.clone() - }), + event: Event::System( + frame_system::Event::NewAccount { account: callee_addr.clone() }.into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Endowed { - account: callee_addr.clone(), - free_balance: min_balance, - }), + event: Event::Balances( + pallet_balances::Event::Endowed { + account: callee_addr.clone(), + free_balance: min_balance, + } + .into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Transfer { - from: ALICE, - to: callee_addr.clone(), - amount: min_balance, - }), + event: Event::Balances( + pallet_balances::Event::Transfer { + from: ALICE, + to: callee_addr.clone(), + amount: min_balance, + } + .into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Reserved { - who: callee_addr.clone(), - amount: min_balance, - }), + event: Event::Balances( + pallet_balances::Event::Reserved { + who: callee_addr.clone(), + amount: min_balance, + } + .into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Transfer { - from: caller_addr.clone(), - to: callee_addr.clone(), - amount: 32768, // hard coded in wasm - }), + event: Event::Balances( + pallet_balances::Event::Transfer { + from: caller_addr.clone(), + to: callee_addr.clone(), + amount: 32768, // hard coded in wasm + } + .into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Contracts(crate::Event::Instantiated { - deployer: caller_addr.clone(), - contract: callee_addr.clone(), - }), + event: Event::Contracts( + crate::Event::Instantiated { + deployer: caller_addr.clone(), + contract: callee_addr.clone(), + } + .into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Transfer { - from: caller_addr.clone(), - to: callee_addr.clone(), - amount: 32768, - }), + event: Event::Balances( + pallet_balances::Event::Transfer { + from: caller_addr.clone(), + to: callee_addr.clone(), + amount: 32768, + } + .into() + ), topics: vec![], }, ] @@ -948,20 +980,22 @@ fn cannot_self_destruct_by_refund_after_slash() { vec![ EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Slashed { - who: addr.clone(), - amount: 90, - }), + event: Event::Balances( + pallet_balances::Event::Slashed { who: addr.clone(), amount: 90 }.into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::ReserveRepatriated { - from: addr.clone(), - to: ALICE, - amount: 10, - destination_status: BalanceStatus::Free, - }), + event: Event::Balances( + pallet_balances::Event::ReserveRepatriated { + from: addr.clone(), + to: ALICE, + amount: 10, + destination_status: BalanceStatus::Free, + } + .into() + ), topics: vec![], }, ] @@ -1048,36 +1082,42 @@ fn self_destruct_works() { vec![ EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Transfer { - from: addr.clone(), - to: DJANGO, - amount: 100_000, - }), + event: Event::Balances( + pallet_balances::Event::Transfer { + from: addr.clone(), + to: DJANGO, + amount: 100_000, + } + .into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Contracts(crate::Event::Terminated { - contract: addr.clone(), - beneficiary: DJANGO - }), + event: Event::Contracts( + crate::Event::Terminated { contract: addr.clone(), beneficiary: DJANGO } + .into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::System(frame_system::Event::KilledAccount { - account: addr.clone() - }), + event: Event::System( + frame_system::Event::KilledAccount { account: addr.clone() }.into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::ReserveRepatriated { - from: addr.clone(), - to: ALICE, - amount: 1_000, - destination_status: BalanceStatus::Free, - }), + event: Event::Balances( + pallet_balances::Event::ReserveRepatriated { + from: addr.clone(), + to: ALICE, + amount: 1_000, + destination_status: BalanceStatus::Free, + } + .into() + ), topics: vec![], }, ], @@ -2352,15 +2392,14 @@ fn upload_code_works() { vec![ EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Reserved { - who: ALICE, - amount: 240, - }), + event: Event::Balances( + pallet_balances::Event::Reserved { who: ALICE, amount: 240 }.into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Contracts(crate::Event::CodeStored { code_hash }), + event: Event::Contracts(crate::Event::CodeStored { code_hash }.into()), topics: vec![], }, ] @@ -2431,28 +2470,26 @@ fn remove_code_works() { vec![ EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Reserved { - who: ALICE, - amount: 240, - }), + event: Event::Balances( + pallet_balances::Event::Reserved { who: ALICE, amount: 240 }.into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Contracts(crate::Event::CodeStored { code_hash }), + event: Event::Contracts(crate::Event::CodeStored { code_hash }.into()), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Unreserved { - who: ALICE, - amount: 240, - }), + event: Event::Balances( + pallet_balances::Event::Unreserved { who: ALICE, amount: 240 }.into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Contracts(crate::Event::CodeRemoved { code_hash }), + event: Event::Contracts(crate::Event::CodeRemoved { code_hash }.into()), topics: vec![], }, ] @@ -2486,15 +2523,14 @@ fn remove_code_wrong_origin() { vec![ EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Reserved { - who: ALICE, - amount: 240, - }), + event: Event::Balances( + pallet_balances::Event::Reserved { who: ALICE, amount: 240 }.into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Contracts(crate::Event::CodeStored { code_hash }), + event: Event::Contracts(crate::Event::CodeStored { code_hash }.into()), topics: vec![], }, ] @@ -2587,53 +2623,60 @@ fn instantiate_with_zero_balance_works() { vec![ EventRecord { phase: Phase::Initialization, - event: Event::System(frame_system::Event::NewAccount { account: addr.clone() }), + event: Event::System( + frame_system::Event::NewAccount { account: addr.clone() }.into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Endowed { - account: addr.clone(), - free_balance: min_balance, - }), + event: Event::Balances( + pallet_balances::Event::Endowed { + account: addr.clone(), + free_balance: min_balance, + } + .into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Transfer { - from: ALICE, - to: addr.clone(), - amount: min_balance, - }), + event: Event::Balances( + pallet_balances::Event::Transfer { + from: ALICE, + to: addr.clone(), + amount: min_balance, + } + .into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Reserved { - who: addr.clone(), - amount: min_balance, - }), + event: Event::Balances( + pallet_balances::Event::Reserved { who: addr.clone(), amount: min_balance } + .into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Reserved { - who: ALICE, - amount: 240, - }), + event: Event::Balances( + pallet_balances::Event::Reserved { who: ALICE, amount: 240 }.into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Contracts(crate::Event::CodeStored { code_hash }), + event: Event::Contracts(crate::Event::CodeStored { code_hash }.into()), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Contracts(crate::Event::Instantiated { - deployer: ALICE, - contract: addr.clone(), - }), + event: Event::Contracts( + crate::Event::Instantiated { deployer: ALICE, contract: addr.clone() } + .into() + ), topics: vec![], }, ] @@ -2678,62 +2721,72 @@ fn instantiate_with_below_existential_deposit_works() { vec![ EventRecord { phase: Phase::Initialization, - event: Event::System(frame_system::Event::NewAccount { account: addr.clone() }), + event: Event::System( + frame_system::Event::NewAccount { account: addr.clone() }.into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Endowed { - account: addr.clone(), - free_balance: min_balance, - }), + event: Event::Balances( + pallet_balances::Event::Endowed { + account: addr.clone(), + free_balance: min_balance, + } + .into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Transfer { - from: ALICE, - to: addr.clone(), - amount: min_balance, - }), + event: Event::Balances( + pallet_balances::Event::Transfer { + from: ALICE, + to: addr.clone(), + amount: min_balance, + } + .into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Reserved { - who: addr.clone(), - amount: min_balance, - }), + event: Event::Balances( + pallet_balances::Event::Reserved { who: addr.clone(), amount: min_balance } + .into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Transfer { - from: ALICE, - to: addr.clone(), - amount: 50, - }), + event: Event::Balances( + pallet_balances::Event::Transfer { + from: ALICE, + to: addr.clone(), + amount: 50, + } + .into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Reserved { - who: ALICE, - amount: 240, - }), + event: Event::Balances( + pallet_balances::Event::Reserved { who: ALICE, amount: 240 }.into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Contracts(crate::Event::CodeStored { code_hash }), + event: Event::Contracts(crate::Event::CodeStored { code_hash }.into()), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Contracts(crate::Event::Instantiated { - deployer: ALICE, - contract: addr.clone(), - }), + event: Event::Contracts( + crate::Event::Instantiated { deployer: ALICE, contract: addr.clone() } + .into() + ), topics: vec![], }, ] @@ -2807,55 +2860,67 @@ fn storage_deposit_works() { vec![ EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Transfer { - from: ALICE, - to: addr.clone(), - amount: 42, - }), + event: Event::Balances( + pallet_balances::Event::Transfer { + from: ALICE, + to: addr.clone(), + amount: 42, + } + .into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Transfer { - from: ALICE, - to: addr.clone(), - amount: charged0, - }), + event: Event::Balances( + pallet_balances::Event::Transfer { + from: ALICE, + to: addr.clone(), + amount: charged0, + } + .into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Reserved { - who: addr.clone(), - amount: charged0, - }), + event: Event::Balances( + pallet_balances::Event::Reserved { who: addr.clone(), amount: charged0 } + .into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Transfer { - from: ALICE, - to: addr.clone(), - amount: charged1, - }), + event: Event::Balances( + pallet_balances::Event::Transfer { + from: ALICE, + to: addr.clone(), + amount: charged1, + } + .into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Reserved { - who: addr.clone(), - amount: charged1, - }), + event: Event::Balances( + pallet_balances::Event::Reserved { who: addr.clone(), amount: charged1 } + .into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::ReserveRepatriated { - from: addr.clone(), - to: ALICE, - amount: refunded0, - destination_status: BalanceStatus::Free, - }), + event: Event::Balances( + pallet_balances::Event::ReserveRepatriated { + from: addr.clone(), + to: ALICE, + amount: refunded0, + destination_status: BalanceStatus::Free, + } + .into() + ), topics: vec![], }, ] @@ -2931,39 +2996,50 @@ fn call_after_killed_account_needs_funding() { vec![ EventRecord { phase: Phase::Initialization, - event: Event::System(frame_system::Event::KilledAccount { - account: addr.clone() - }), + event: Event::System( + frame_system::Event::KilledAccount { account: addr.clone() }.into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Slashed { - who: addr.clone(), - amount: min_balance + 700 - }), + event: Event::Balances( + pallet_balances::Event::Slashed { + who: addr.clone(), + amount: min_balance + 700 + } + .into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::System(frame_system::Event::NewAccount { account: addr.clone() }), + event: Event::System( + frame_system::Event::NewAccount { account: addr.clone() }.into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Endowed { - account: addr.clone(), - free_balance: min_balance - }), + event: Event::Balances( + pallet_balances::Event::Endowed { + account: addr.clone(), + free_balance: min_balance + } + .into() + ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances(pallet_balances::Event::Transfer { - from: ALICE, - to: addr.clone(), - amount: min_balance - }), + event: Event::Balances( + pallet_balances::Event::Transfer { + from: ALICE, + to: addr.clone(), + amount: min_balance + } + .into() + ), topics: vec![], }, ] @@ -3141,11 +3217,14 @@ fn set_code_hash() { System::events().pop().unwrap(), EventRecord { phase: Phase::Initialization, - event: Event::Contracts(crate::Event::ContractCodeUpdated { - contract: contract_addr.clone(), - new_code_hash: new_code_hash.clone(), - old_code_hash: code_hash.clone(), - }), + event: Event::Contracts( + crate::Event::ContractCodeUpdated { + contract: contract_addr.clone(), + new_code_hash: new_code_hash.clone(), + old_code_hash: code_hash.clone(), + } + .into() + ), topics: vec![], }, ); diff --git a/frame/election-provider-multi-phase/src/mock.rs b/frame/election-provider-multi-phase/src/mock.rs index d6f040363dba..0499390135a3 100644 --- a/frame/election-provider-multi-phase/src/mock.rs +++ b/frame/election-provider-multi-phase/src/mock.rs @@ -83,7 +83,7 @@ pub(crate) fn multi_phase_events() -> Vec> { System::events() .into_iter() .map(|r| r.event) - .filter_map(|e| if let Event::MultiPhase(inner) = e { Some(inner) } else { None }) + .filter_map(|e| if let Event::MultiPhase(inner) = e { Some(*inner) } else { None }) .collect::>() } diff --git a/frame/elections-phragmen/src/lib.rs b/frame/elections-phragmen/src/lib.rs index 4758c793cfef..7189545ca419 100644 --- a/frame/elections-phragmen/src/lib.rs +++ b/frame/elections-phragmen/src/lib.rs @@ -2163,7 +2163,7 @@ mod tests { System::set_block_number(5); Elections::on_initialize(System::block_number()); - System::assert_last_event(Event::Elections(super::Event::EmptyTerm)); + System::assert_last_event(super::Event::EmptyTerm.into()); }) } @@ -2179,9 +2179,9 @@ mod tests { System::set_block_number(5); Elections::on_initialize(System::block_number()); - System::assert_last_event(Event::Elections(super::Event::NewTerm { - new_members: vec![(4, 35), (5, 45)], - })); + System::assert_last_event( + super::Event::NewTerm { new_members: vec![(4, 35), (5, 45)] }.into(), + ); assert_eq!(members_and_stake(), vec![(4, 35), (5, 45)]); assert_eq!(runners_up_and_stake(), vec![]); @@ -2192,9 +2192,7 @@ mod tests { System::set_block_number(10); Elections::on_initialize(System::block_number()); - System::assert_last_event(Event::Elections(super::Event::NewTerm { - new_members: vec![], - })); + System::assert_last_event(super::Event::NewTerm { new_members: vec![] }.into()); // outgoing have lost their bond. assert_eq!(balances(&4), (37, 0)); @@ -2264,9 +2262,7 @@ mod tests { assert_eq!(Elections::election_rounds(), 1); assert!(members_ids().is_empty()); - System::assert_last_event(Event::Elections(super::Event::NewTerm { - new_members: vec![], - })); + System::assert_last_event(super::Event::NewTerm { new_members: vec![] }.into()); }); } @@ -2618,9 +2614,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 { - new_members: vec![(4, 35), (5, 45)], - })); + System::assert_has_event( + super::Event::NewTerm { new_members: vec![(4, 35), (5, 45)] }.into(), + ); }) } diff --git a/frame/offences/src/tests.rs b/frame/offences/src/tests.rs index 49bd2fb5a692..1c071adabc3e 100644 --- a/frame/offences/src/tests.rs +++ b/frame/offences/src/tests.rs @@ -21,8 +21,8 @@ use super::*; use crate::mock::{ - new_test_ext, offence_reports, report_id, with_on_offence_fractions, Event, Offence, Offences, - System, KIND, + new_test_ext, offence_reports, report_id, with_on_offence_fractions, Offence, Offences, System, + KIND, }; use frame_system::{EventRecord, Phase}; use sp_runtime::Perbill; @@ -114,10 +114,7 @@ fn should_deposit_event() { System::events(), vec![EventRecord { phase: Phase::Initialization, - event: Event::Offences(crate::Event::Offence { - kind: KIND, - timeslot: time_slot.encode() - }), + event: crate::Event::Offence { kind: KIND, timeslot: time_slot.encode() }.into(), topics: vec![], }] ); @@ -148,10 +145,7 @@ fn doesnt_deposit_event_for_dups() { System::events(), vec![EventRecord { phase: Phase::Initialization, - event: Event::Offences(crate::Event::Offence { - kind: KIND, - timeslot: time_slot.encode() - }), + event: crate::Event::Offence { kind: KIND, timeslot: time_slot.encode() }.into(), topics: vec![], }] ); diff --git a/frame/staking/src/mock.rs b/frame/staking/src/mock.rs index bb90aded852e..92325df67bea 100644 --- a/frame/staking/src/mock.rs +++ b/frame/staking/src/mock.rs @@ -857,7 +857,7 @@ pub(crate) fn staking_events() -> Vec> { System::events() .into_iter() .map(|r| r.event) - .filter_map(|e| if let Event::Staking(inner) = e { Some(inner) } else { None }) + .filter_map(|e| if let Event::Staking(inner) = e { Some(*inner) } else { None }) .collect() } diff --git a/frame/sudo/src/tests.rs b/frame/sudo/src/tests.rs index 84c8e0c5c254..77d7893c5924 100644 --- a/frame/sudo/src/tests.rs +++ b/frame/sudo/src/tests.rs @@ -19,10 +19,7 @@ use super::*; use frame_support::{assert_noop, assert_ok}; -use mock::{ - new_test_ext, Call, Event as TestEvent, Logger, LoggerCall, Origin, Sudo, SudoCall, System, - Test, -}; +use mock::{new_test_ext, Call, Logger, LoggerCall, Origin, Sudo, SudoCall, System, Test}; #[test] fn test_setup_works() { @@ -58,7 +55,7 @@ fn sudo_emits_events_correctly() { // Should emit event to indicate success when called with the root `key` and `call` is `Ok`. let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log { i: 42, weight: 1 })); assert_ok!(Sudo::sudo(Origin::signed(1), call)); - System::assert_has_event(TestEvent::Sudo(Event::Sudid { sudo_result: Ok(()) })); + System::assert_has_event(Event::Sudid { sudo_result: Ok(()) }.into()); }) } @@ -96,7 +93,7 @@ fn sudo_unchecked_weight_emits_events_correctly() { // Should emit event to indicate success when called with the root `key` and `call` is `Ok`. let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log { i: 42, weight: 1 })); assert_ok!(Sudo::sudo_unchecked_weight(Origin::signed(1), call, 1_000)); - System::assert_has_event(TestEvent::Sudo(Event::Sudid { sudo_result: Ok(()) })); + System::assert_has_event(Event::Sudid { sudo_result: Ok(()) }.into()); }) } @@ -123,10 +120,10 @@ fn set_key_emits_events_correctly() { // A root `key` can change the root `key`. assert_ok!(Sudo::set_key(Origin::signed(1), 2)); - System::assert_has_event(TestEvent::Sudo(Event::KeyChanged { old_sudoer: Some(1) })); + System::assert_has_event(Event::KeyChanged { old_sudoer: Some(1) }.into()); // Double check. assert_ok!(Sudo::set_key(Origin::signed(2), 4)); - System::assert_has_event(TestEvent::Sudo(Event::KeyChanged { old_sudoer: Some(2) })); + System::assert_has_event(Event::KeyChanged { old_sudoer: Some(2) }.into()); }); } @@ -161,6 +158,6 @@ fn sudo_as_emits_events_correctly() { // A non-privileged function will work when passed to `sudo_as` with the root `key`. let call = Box::new(Call::Logger(LoggerCall::non_privileged_log { i: 42, weight: 1 })); assert_ok!(Sudo::sudo_as(Origin::signed(1), 2, call)); - System::assert_has_event(TestEvent::Sudo(Event::SudoAsDone { sudo_result: Ok(()) })); + System::assert_has_event(Event::SudoAsDone { sudo_result: Ok(()) }.into()); }); } diff --git a/frame/support/test/tests/pallet.rs b/frame/support/test/tests/pallet.rs index 83f6a722f93a..c17364cee8b6 100644 --- a/frame/support/test/tests/pallet.rs +++ b/frame/support/test/tests/pallet.rs @@ -628,7 +628,7 @@ fn transactional_works() { .iter() .map(|e| &e.event) .collect::>(), - vec![&Event::Example(pallet::Event::Something(0))], + vec![&Event::Example(pallet::Event::Something(0).into())], ); }) } @@ -884,7 +884,7 @@ fn pallet_expand_deposit_event() { .unwrap(); assert_eq!( frame_system::Pallet::::events()[0].event, - Event::Example(pallet::Event::Something(3)), + Event::Example(pallet::Event::Something(3).into()), ); }) } @@ -991,27 +991,27 @@ fn pallet_hooks_expand() { assert_eq!( frame_system::Pallet::::events()[0].event, - Event::Example(pallet::Event::Something(10)), + Event::Example(pallet::Event::Something(10).into()), ); assert_eq!( frame_system::Pallet::::events()[1].event, - Event::Example2(pallet2::Event::Something(11)), + Event::Example2(pallet2::Event::Something(11).into()), ); assert_eq!( frame_system::Pallet::::events()[2].event, - Event::Example(pallet::Event::Something(20)), + Event::Example(pallet::Event::Something(20).into()), ); assert_eq!( frame_system::Pallet::::events()[3].event, - Event::Example2(pallet2::Event::Something(21)), + Event::Example2(pallet2::Event::Something(21).into()), ); assert_eq!( frame_system::Pallet::::events()[4].event, - Event::Example(pallet::Event::Something(30)), + Event::Example(pallet::Event::Something(30).into()), ); assert_eq!( frame_system::Pallet::::events()[5].event, - Event::Example2(pallet2::Event::Something(31)), + Event::Example2(pallet2::Event::Something(31).into()), ); }) } @@ -1031,27 +1031,27 @@ fn all_pallets_type_reversed_order_is_correct() { assert_eq!( frame_system::Pallet::::events()[0].event, - Event::Example2(pallet2::Event::Something(11)), + Event::Example2(pallet2::Event::Something(11).into()), ); assert_eq!( frame_system::Pallet::::events()[1].event, - Event::Example(pallet::Event::Something(10)), + Event::Example(pallet::Event::Something(10).into()), ); assert_eq!( frame_system::Pallet::::events()[2].event, - Event::Example2(pallet2::Event::Something(21)), + Event::Example2(pallet2::Event::Something(21).into()), ); assert_eq!( frame_system::Pallet::::events()[3].event, - Event::Example(pallet::Event::Something(20)), + Event::Example(pallet::Event::Something(20).into()), ); assert_eq!( frame_system::Pallet::::events()[4].event, - Event::Example2(pallet2::Event::Something(31)), + Event::Example2(pallet2::Event::Something(31).into()), ); assert_eq!( frame_system::Pallet::::events()[5].event, - Event::Example(pallet::Event::Something(30)), + Event::Example(pallet::Event::Something(30).into()), ); }) } diff --git a/frame/support/test/tests/pallet_instance.rs b/frame/support/test/tests/pallet_instance.rs index 118794e2fa20..d69b52a0f6d7 100644 --- a/frame/support/test/tests/pallet_instance.rs +++ b/frame/support/test/tests/pallet_instance.rs @@ -385,7 +385,7 @@ fn pallet_expand_deposit_event() { .unwrap(); assert_eq!( frame_system::Pallet::::events()[0].event, - Event::Example(pallet::Event::Something(3)), + Event::Example(pallet::Event::Something(3).into()), ); }); @@ -396,7 +396,7 @@ fn pallet_expand_deposit_event() { .unwrap(); assert_eq!( frame_system::Pallet::::events()[0].event, - Event::Instance1Example(pallet::Event::Something(3)), + Event::Instance1Example(pallet::Event::Something(3).into()), ); }); } @@ -562,27 +562,27 @@ fn pallet_hooks_expand() { assert_eq!( frame_system::Pallet::::events()[0].event, - Event::Example(pallet::Event::Something(10)), + Event::Example(pallet::Event::Something(10).into()), ); assert_eq!( frame_system::Pallet::::events()[1].event, - Event::Instance1Example(pallet::Event::Something(11)), + Event::Instance1Example(pallet::Event::Something(11).into()), ); assert_eq!( frame_system::Pallet::::events()[2].event, - Event::Example(pallet::Event::Something(20)), + Event::Example(pallet::Event::Something(20).into()), ); assert_eq!( frame_system::Pallet::::events()[3].event, - Event::Instance1Example(pallet::Event::Something(21)), + Event::Instance1Example(pallet::Event::Something(21).into()), ); assert_eq!( frame_system::Pallet::::events()[4].event, - Event::Example(pallet::Event::Something(30)), + Event::Example(pallet::Event::Something(30).into()), ); assert_eq!( frame_system::Pallet::::events()[5].event, - Event::Instance1Example(pallet::Event::Something(31)), + Event::Instance1Example(pallet::Event::Something(31).into()), ); }) } diff --git a/frame/tips/src/tests.rs b/frame/tips/src/tests.rs index 0c58a949958f..a01d86711250 100644 --- a/frame/tips/src/tests.rs +++ b/frame/tips/src/tests.rs @@ -175,7 +175,7 @@ fn last_event() -> TipEvent { System::events() .into_iter() .map(|r| r.event) - .filter_map(|e| if let Event::Tips(inner) = e { Some(inner) } else { None }) + .filter_map(|e| if let Event::Tips(inner) = e { Some(*inner) } else { None }) .last() .unwrap() } diff --git a/frame/transaction-payment/src/lib.rs b/frame/transaction-payment/src/lib.rs index 1462faaa0706..112527447f3f 100644 --- a/frame/transaction-payment/src/lib.rs +++ b/frame/transaction-payment/src/lib.rs @@ -1374,15 +1374,11 @@ mod tests { )); assert_eq!(Balances::free_balance(2), 0); // Transfer Event - System::assert_has_event(Event::Balances(pallet_balances::Event::Transfer { - from: 2, - to: 3, - amount: 80, - })); + System::assert_has_event( + pallet_balances::Event::Transfer { from: 2, to: 3, amount: 80 }.into(), + ); // Killed Event - System::assert_has_event(Event::System(system::Event::KilledAccount { - account: 2, - })); + System::assert_has_event(system::Event::KilledAccount { account: 2 }.into()); }); } From 115337cf858e2588c7cf5fbdea5b2e1b53007d64 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Tue, 12 Apr 2022 21:07:30 +0200 Subject: [PATCH 3/6] Revert "Box events" This reverts commit 9fb1887cd23eb272844d63640b0b2d9ba3e549a1. --- .../procedural/src/construct_runtime/expand/event.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/frame/support/procedural/src/construct_runtime/expand/event.rs b/frame/support/procedural/src/construct_runtime/expand/event.rs index 12a1b49d14c4..b242f9641562 100644 --- a/frame/support/procedural/src/construct_runtime/expand/event.rs +++ b/frame/support/procedural/src/construct_runtime/expand/event.rs @@ -100,16 +100,16 @@ fn expand_event_variant( match instance { Some(inst) if part_is_generic => { - quote!(#[codec(index = #index)] #variant_name(Box<#path::Event<#runtime, #path::#inst>>),) + quote!(#[codec(index = #index)] #variant_name(#path::Event<#runtime, #path::#inst>),) }, Some(inst) => { - quote!(#[codec(index = #index)] #variant_name(Box<#path::Event<#path::#inst>>),) + quote!(#[codec(index = #index)] #variant_name(#path::Event<#path::#inst>),) }, None if part_is_generic => { - quote!(#[codec(index = #index)] #variant_name(Box<#path::Event<#runtime>>),) + quote!(#[codec(index = #index)] #variant_name(#path::Event<#runtime>),) }, None => { - quote!(#[codec(index = #index)] #variant_name(Box<#path::Event>),) + quote!(#[codec(index = #index)] #variant_name(#path::Event),) }, } } @@ -124,7 +124,7 @@ fn expand_event_conversion( quote! { impl From<#pallet_event> for Event { fn from(x: #pallet_event) -> Self { - Event::#variant_name(Box::new(x)) + Event::#variant_name(x) } } impl TryInto<#pallet_event> for Event { @@ -132,7 +132,7 @@ fn expand_event_conversion( fn try_into(self) -> #scrate::sp_std::result::Result<#pallet_event, Self::Error> { match self { - Self::#variant_name(evt) => Ok(*evt), + Self::#variant_name(evt) => Ok(evt), _ => Err(()), } } From 3df82e26f5ca3eaeff4a5c67af4da10224035b0a Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Tue, 12 Apr 2022 21:07:41 +0200 Subject: [PATCH 4/6] Revert "Fix tests" This reverts commit 981c50f23a7c514c9527299734bc6bc5b77a817f. --- bin/node/executor/tests/basic.rs | 175 ++--- frame/assets/src/tests.rs | 9 +- frame/balances/src/tests.rs | 38 +- frame/balances/src/tests_local.rs | 14 +- frame/balances/src/tests_reentrancy.rs | 48 +- frame/bounties/src/tests.rs | 2 +- frame/child-bounties/src/tests.rs | 2 +- frame/collective/src/tests.rs | 713 ++++++++---------- frame/contracts/src/exec.rs | 29 +- frame/contracts/src/tests.rs | 493 +++++------- .../election-provider-multi-phase/src/mock.rs | 2 +- frame/elections-phragmen/src/lib.rs | 22 +- frame/offences/src/tests.rs | 14 +- frame/staking/src/mock.rs | 2 +- frame/sudo/src/tests.rs | 15 +- frame/support/test/tests/pallet.rs | 28 +- frame/support/test/tests/pallet_instance.rs | 16 +- frame/tips/src/tests.rs | 2 +- frame/transaction-payment/src/lib.rs | 12 +- 19 files changed, 720 insertions(+), 916 deletions(-) diff --git a/bin/node/executor/tests/basic.rs b/bin/node/executor/tests/basic.rs index e458b78af57a..da0f4e6afb31 100644 --- a/bin/node/executor/tests/basic.rs +++ b/bin/node/executor/tests/basic.rs @@ -378,66 +378,50 @@ fn full_native_block_import_works() { let events = vec![ EventRecord { phase: Phase::ApplyExtrinsic(0), - event: Event::System( - frame_system::Event::ExtrinsicSuccess { - dispatch_info: DispatchInfo { - weight: timestamp_weight, - class: DispatchClass::Mandatory, - ..Default::default() - }, - } - .into(), - ), + event: Event::System(frame_system::Event::ExtrinsicSuccess { + dispatch_info: DispatchInfo { + weight: timestamp_weight, + class: DispatchClass::Mandatory, + ..Default::default() + }, + }), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(1), - event: Event::Balances( - pallet_balances::Event::Withdraw { who: alice().into(), amount: fees }.into(), - ), + 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 { - from: alice().into(), - to: bob().into(), - amount: 69 * DOLLARS, - } - .into(), - ), + 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 { - who: pallet_treasury::Pallet::::account_id(), - amount: fees * 8 / 10, - } - .into(), - ), + event: Event::Balances(pallet_balances::Event::Deposit { + who: pallet_treasury::Pallet::::account_id(), + amount: fees * 8 / 10, + }), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(1), - event: Event::Treasury( - pallet_treasury::Event::Deposit { value: fees * 8 / 10 }.into(), - ), + event: Event::Treasury(pallet_treasury::Event::Deposit { value: fees * 8 / 10 }), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(1), - event: Event::System( - frame_system::Event::ExtrinsicSuccess { - dispatch_info: DispatchInfo { - weight: transfer_weight, - ..Default::default() - }, - } - .into(), - ), + event: Event::System(frame_system::Event::ExtrinsicSuccess { + dispatch_info: DispatchInfo { weight: transfer_weight, ..Default::default() }, + }), topics: vec![], }, ]; @@ -465,116 +449,87 @@ fn full_native_block_import_works() { let events = vec![ EventRecord { phase: Phase::ApplyExtrinsic(0), - event: Event::System( - frame_system::Event::ExtrinsicSuccess { - dispatch_info: DispatchInfo { - weight: timestamp_weight, - class: DispatchClass::Mandatory, - ..Default::default() - }, - } - .into(), - ), + event: Event::System(frame_system::Event::ExtrinsicSuccess { + dispatch_info: DispatchInfo { + weight: timestamp_weight, + class: DispatchClass::Mandatory, + ..Default::default() + }, + }), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(1), - event: Event::Balances( - pallet_balances::Event::Withdraw { who: bob().into(), amount: fees }.into(), - ), + 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 { - from: bob().into(), - to: alice().into(), - amount: 5 * DOLLARS, - } - .into(), - ), + 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 { - who: pallet_treasury::Pallet::::account_id(), - amount: fees * 8 / 10, - } - .into(), - ), + event: Event::Balances(pallet_balances::Event::Deposit { + who: pallet_treasury::Pallet::::account_id(), + amount: fees * 8 / 10, + }), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(1), - event: Event::Treasury( - pallet_treasury::Event::Deposit { value: fees * 8 / 10 }.into(), - ), + event: Event::Treasury(pallet_treasury::Event::Deposit { value: fees * 8 / 10 }), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(1), - event: Event::System( - frame_system::Event::ExtrinsicSuccess { - dispatch_info: DispatchInfo { - weight: transfer_weight, - ..Default::default() - }, - } - .into(), - ), + event: Event::System(frame_system::Event::ExtrinsicSuccess { + dispatch_info: DispatchInfo { weight: transfer_weight, ..Default::default() }, + }), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(2), - event: Event::Balances( - pallet_balances::Event::Withdraw { who: alice().into(), amount: fees }.into(), - ), + 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 { - from: alice().into(), - to: bob().into(), - amount: 15 * DOLLARS, - } - .into(), - ), + 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 { - who: pallet_treasury::Pallet::::account_id(), - amount: fees * 8 / 10, - } - .into(), - ), + event: Event::Balances(pallet_balances::Event::Deposit { + who: pallet_treasury::Pallet::::account_id(), + amount: fees * 8 / 10, + }), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(2), - event: Event::Treasury( - pallet_treasury::Event::Deposit { value: fees * 8 / 10 }.into(), - ), + event: Event::Treasury(pallet_treasury::Event::Deposit { value: fees * 8 / 10 }), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(2), - event: Event::System( - frame_system::Event::ExtrinsicSuccess { - dispatch_info: DispatchInfo { - weight: transfer_weight, - ..Default::default() - }, - } - .into(), - ), + event: Event::System(frame_system::Event::ExtrinsicSuccess { + dispatch_info: DispatchInfo { weight: transfer_weight, ..Default::default() }, + }), topics: vec![], }, ]; diff --git a/frame/assets/src/tests.rs b/frame/assets/src/tests.rs index 2bf332f2cdcc..7430b742e7d2 100644 --- a/frame/assets/src/tests.rs +++ b/frame/assets/src/tests.rs @@ -620,9 +620,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( - crate::Event::Transferred { asset_id: 0, from: 1, to: 2, amount: 0 }.into(), - ); + System::assert_last_event(mock::Event::Assets(crate::Event::Transferred { + asset_id: 0, + from: 1, + to: 2, + amount: 0, + })); }); } diff --git a/frame/balances/src/tests.rs b/frame/balances/src/tests.rs index 247fa0dacd94..8f5470ae3cac 100644 --- a/frame/balances/src/tests.rs +++ b/frame/balances/src/tests.rs @@ -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(crate::Event::Deposit { who: 1, amount: 10 }.into()); + System::assert_last_event(Event::Balances(crate::Event::Deposit { who: 1, amount: 10 })); assert_eq!(Balances::total_balance(&1), 20); assert_eq!(>::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(crate::Event::Deposit { who: 1, amount: 42 }.into()); + 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(crate::Event::Withdraw { who: 2, amount: 11 }.into()); + System::assert_last_event(Event::Balances(crate::Event::Withdraw { who: 2, amount: 11 })); assert_eq!(Balances::free_balance(2), 100); assert_eq!(>::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( - crate::Event::ReserveRepatriated { from: 1, to: 2, amount: 41, destination_status: Status::Free }.into() + 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(crate::Event::Reserved { who: 1, amount: 10 }.into()); + 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(crate::Event::Unreserved { who: 1, amount: 5 }.into()); + 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(crate::Event::Unreserved { who: 1, amount: 5 }.into()); + System::assert_last_event(Event::Balances(crate::Event::Unreserved { who: 1, amount: 5 })); }); } @@ -750,9 +750,9 @@ macro_rules! decl_tests { assert_eq!( events(), [ - system::Event::NewAccount { account: 1 }.into(), - crate::Event::Endowed { account: 1, free_balance: 100 }.into(), - crate::Event::BalanceSet { who: 1, free: 100, reserved: 0 }.into(), + Event::System(system::Event::NewAccount { account: 1 }), + Event::Balances(crate::Event::Endowed { account: 1, free_balance: 100 }), + Event::Balances(crate::Event::BalanceSet { who: 1, free: 100, reserved: 0 }), ] ); @@ -762,9 +762,9 @@ macro_rules! decl_tests { assert_eq!( events(), [ - system::Event::KilledAccount { account: 1 }.into(), - crate::Event::DustLost { account: 1, amount: 99 }.into(), - crate::Event::Slashed { who: 1, amount: 1 }.into(), + Event::System(system::Event::KilledAccount { account: 1 }), + Event::Balances(crate::Event::DustLost { account: 1, amount: 99 }), + Event::Balances(crate::Event::Slashed { who: 1, amount: 1 }), ] ); }); @@ -781,9 +781,9 @@ macro_rules! decl_tests { assert_eq!( events(), [ - system::Event::NewAccount { account: 1 }.into(), - crate::Event::Endowed { account: 1, free_balance: 100 }.into(), - crate::Event::BalanceSet { who: 1, free: 100, reserved: 0 }.into(), + Event::System(system::Event::NewAccount { account: 1 }), + Event::Balances(crate::Event::Endowed { account: 1, free_balance: 100 }), + Event::Balances(crate::Event::BalanceSet { who: 1, free: 100, reserved: 0 }), ] ); @@ -793,8 +793,8 @@ macro_rules! decl_tests { assert_eq!( events(), [ - system::Event::KilledAccount { account: 1 }.into(), - crate::Event::Slashed { who: 1, amount: 100 }.into(), + Event::System(system::Event::KilledAccount { account: 1 }), + 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(crate::Event::Slashed { who: 1, amount: 900 }.into()); + 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)); diff --git a/frame/balances/src/tests_local.rs b/frame/balances/src/tests_local.rs index d00d3cbfab52..cfc7f84ab3a3 100644 --- a/frame/balances/src/tests_local.rs +++ b/frame/balances/src/tests_local.rs @@ -157,9 +157,9 @@ fn emit_events_with_no_existential_deposit_suicide_with_dust() { assert_eq!( events(), [ - system::Event::NewAccount { account: 1 }.into(), - crate::Event::Endowed { account: 1, free_balance: 100 }.into(), - crate::Event::BalanceSet { who: 1, free: 100, reserved: 0 }.into(), + Event::System(system::Event::NewAccount { account: 1 }), + Event::Balances(crate::Event::Endowed { account: 1, free_balance: 100 }), + Event::Balances(crate::Event::BalanceSet { who: 1, free: 100, reserved: 0 }), ] ); @@ -167,7 +167,7 @@ fn emit_events_with_no_existential_deposit_suicide_with_dust() { assert_eq!(res, (NegativeImbalance::new(98), 0)); // no events - assert_eq!(events(), [crate::Event::Slashed { who: 1, amount: 98 }.into()]); + 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)); @@ -175,9 +175,9 @@ fn emit_events_with_no_existential_deposit_suicide_with_dust() { assert_eq!( events(), [ - system::Event::KilledAccount { account: 1 }.into(), - crate::Event::DustLost { account: 1, amount: 1 }.into(), - crate::Event::Slashed { who: 1, amount: 1 }.into() + Event::System(system::Event::KilledAccount { account: 1 }), + Event::Balances(crate::Event::DustLost { account: 1, amount: 1 }), + Event::Balances(crate::Event::Slashed { who: 1, amount: 1 }) ] ); }); diff --git a/frame/balances/src/tests_reentrancy.rs b/frame/balances/src/tests_reentrancy.rs index 3d4ad95f8ed5..7037e9615afd 100644 --- a/frame/balances/src/tests_reentrancy.rs +++ b/frame/balances/src/tests_reentrancy.rs @@ -167,9 +167,16 @@ fn transfer_dust_removal_tst1_should_work() { // Verify the events assert_eq!(System::events().len(), 12); - System::assert_has_event(crate::Event::Transfer { from: 2, to: 3, amount: 450 }.into()); - System::assert_has_event(crate::Event::DustLost { account: 2, amount: 50 }.into()); - System::assert_has_event(crate::Event::Deposit { who: 1, amount: 50 }.into()); + 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 })); }); } @@ -195,9 +202,16 @@ fn transfer_dust_removal_tst2_should_work() { // Verify the events assert_eq!(System::events().len(), 10); - System::assert_has_event(crate::Event::Transfer { from: 2, to: 1, amount: 450 }.into()); - System::assert_has_event(crate::Event::DustLost { account: 2, amount: 50 }.into()); - System::assert_has_event(crate::Event::Deposit { who: 1, amount: 50 }.into()); + 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 })); }); } @@ -232,18 +246,18 @@ fn repatriating_reserved_balance_dust_removal_should_work() { // Verify the events assert_eq!(System::events().len(), 11); - System::assert_has_event( - crate::Event::ReserveRepatriated { - from: 2, - to: 1, - amount: 450, - destination_status: Status::Free, - } - .into(), - ); + System::assert_has_event(Event::Balances(crate::Event::ReserveRepatriated { + from: 2, + to: 1, + amount: 450, + destination_status: Status::Free, + })); - System::assert_has_event(crate::Event::DustLost { account: 2, amount: 50 }.into()); + System::assert_has_event(Event::Balances(crate::Event::DustLost { + account: 2, + amount: 50, + })); - System::assert_last_event(crate::Event::Deposit { who: 1, amount: 50 }.into()); + System::assert_last_event(Event::Balances(crate::Event::Deposit { who: 1, amount: 50 })); }); } diff --git a/frame/bounties/src/tests.rs b/frame/bounties/src/tests.rs index 03a31ec6bccd..9a84bd687abc 100644 --- a/frame/bounties/src/tests.rs +++ b/frame/bounties/src/tests.rs @@ -169,7 +169,7 @@ fn last_event() -> BountiesEvent { System::events() .into_iter() .map(|r| r.event) - .filter_map(|e| if let Event::Bounties(inner) = e { Some(*inner) } else { None }) + .filter_map(|e| if let Event::Bounties(inner) = e { Some(inner) } else { None }) .last() .unwrap() } diff --git a/frame/child-bounties/src/tests.rs b/frame/child-bounties/src/tests.rs index 2ac00b1e44af..61545561a26c 100644 --- a/frame/child-bounties/src/tests.rs +++ b/frame/child-bounties/src/tests.rs @@ -175,7 +175,7 @@ fn last_event() -> ChildBountiesEvent { System::events() .into_iter() .map(|r| r.event) - .filter_map(|e| if let Event::ChildBounties(inner) = e { Some(*inner) } else { None }) + .filter_map(|e| if let Event::ChildBounties(inner) = e { Some(inner) } else { None }) .last() .unwrap() } diff --git a/frame/collective/src/tests.rs b/frame/collective/src/tests.rs index b13d8b9da328..a8abfb0c5235 100644 --- a/frame/collective/src/tests.rs +++ b/frame/collective/src/tests.rs @@ -216,41 +216,32 @@ fn close_works() { assert_eq!( System::events(), vec![ - record(Event::Collective( - CollectiveEvent::Proposed { - account: 1, - proposal_index: 0, - proposal_hash: hash, - threshold: 3 - } - .into() - )), - record(Event::Collective( - CollectiveEvent::Voted { - account: 1, - proposal_hash: hash, - voted: true, - yes: 1, - no: 0 - } - .into() - )), - record(Event::Collective( - CollectiveEvent::Voted { - account: 2, - proposal_hash: hash, - voted: true, - yes: 2, - no: 0 - } - .into() - )), - record(Event::Collective( - CollectiveEvent::Closed { proposal_hash: hash, yes: 2, no: 1 }.into() - )), - record(Event::Collective( - CollectiveEvent::Disapproved { proposal_hash: hash }.into() - )) + 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 })) ] ); }); @@ -345,41 +336,32 @@ fn close_with_prime_works() { assert_eq!( System::events(), vec![ - record(Event::Collective( - CollectiveEvent::Proposed { - account: 1, - proposal_index: 0, - proposal_hash: hash, - threshold: 3 - } - .into() - )), - record(Event::Collective( - CollectiveEvent::Voted { - account: 1, - proposal_hash: hash, - voted: true, - yes: 1, - no: 0 - } - .into() - )), - record(Event::Collective( - CollectiveEvent::Voted { - account: 2, - proposal_hash: hash, - voted: true, - yes: 2, - no: 0 - } - .into() - )), - record(Event::Collective( - CollectiveEvent::Closed { proposal_hash: hash, yes: 2, no: 1 }.into() - )), - record(Event::Collective( - CollectiveEvent::Disapproved { proposal_hash: hash }.into() - )) + 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 })) ] ); }); @@ -414,46 +396,36 @@ fn close_with_voting_prime_works() { assert_eq!( System::events(), vec![ - record(Event::Collective( - CollectiveEvent::Proposed { - account: 1, - proposal_index: 0, - proposal_hash: hash, - threshold: 3 - } - .into() - )), - record(Event::Collective( - CollectiveEvent::Voted { - account: 1, - proposal_hash: hash, - voted: true, - yes: 1, - no: 0 - } - .into() - )), - record(Event::Collective( - CollectiveEvent::Voted { - account: 2, - proposal_hash: hash, - voted: true, - yes: 2, - no: 0 - } - .into() - )), - record(Event::Collective( - CollectiveEvent::Closed { proposal_hash: hash, yes: 3, no: 0 }.into() - )), - record(Event::Collective(CollectiveEvent::Approved { proposal_hash: hash }.into())), - record(Event::Collective( - CollectiveEvent::Executed { - proposal_hash: hash, - result: Err(DispatchError::BadOrigin) - } - .into() - )) + 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) + })) ] ); }); @@ -495,58 +467,45 @@ fn close_with_no_prime_but_majority_works() { assert_eq!( System::events(), vec![ - record(Event::CollectiveMajority( - CollectiveEvent::Proposed { - account: 1, - proposal_index: 0, - proposal_hash: hash, - threshold: 5 - } - .into() - )), - record(Event::CollectiveMajority( - CollectiveEvent::Voted { - account: 1, - proposal_hash: hash, - voted: true, - yes: 1, - no: 0 - } - .into() - )), - record(Event::CollectiveMajority( - CollectiveEvent::Voted { - account: 2, - proposal_hash: hash, - voted: true, - yes: 2, - no: 0 - } - .into() - )), - record(Event::CollectiveMajority( - CollectiveEvent::Voted { - account: 3, - proposal_hash: hash, - voted: true, - yes: 3, - no: 0 - } - .into() - )), - record(Event::CollectiveMajority( - CollectiveEvent::Closed { proposal_hash: hash, yes: 5, no: 0 }.into() - )), - record(Event::CollectiveMajority( - CollectiveEvent::Approved { proposal_hash: hash }.into() - )), - record(Event::CollectiveMajority( - CollectiveEvent::Executed { - proposal_hash: hash, - result: Err(DispatchError::BadOrigin) - } - .into() - )) + 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) + })) ] ); }); @@ -670,15 +629,12 @@ fn propose_works() { assert_eq!( System::events(), - vec![record(Event::Collective( - CollectiveEvent::Proposed { - account: 1, - proposal_index: 0, - proposal_hash: hash, - threshold: 3 - } - .into() - ))] + vec![record(Event::Collective(CollectiveEvent::Proposed { + account: 1, + proposal_index: 0, + proposal_hash: hash, + threshold: 3 + }))] ); }); } @@ -837,35 +793,26 @@ fn motions_vote_after_works() { assert_eq!( System::events(), vec![ - record(Event::Collective( - CollectiveEvent::Proposed { - account: 1, - proposal_index: 0, - proposal_hash: hash, - threshold: 2 - } - .into() - )), - record(Event::Collective( - CollectiveEvent::Voted { - account: 1, - proposal_hash: hash, - voted: true, - yes: 1, - no: 0 - } - .into() - )), - record(Event::Collective( - CollectiveEvent::Voted { - account: 1, - proposal_hash: hash, - voted: false, - yes: 0, - no: 1 - } - .into() - )), + 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 + })), ] ); }); @@ -979,46 +926,36 @@ fn motions_approval_with_enough_votes_and_lower_voting_threshold_works() { assert_eq!( System::events(), vec![ - record(Event::Collective( - CollectiveEvent::Proposed { - account: 1, - proposal_index: 0, - proposal_hash: hash, - threshold: 2 - } - .into() - )), - record(Event::Collective( - CollectiveEvent::Voted { - account: 1, - proposal_hash: hash, - voted: true, - yes: 1, - no: 0 - } - .into() - )), - record(Event::Collective( - CollectiveEvent::Voted { - account: 2, - proposal_hash: hash, - voted: true, - yes: 2, - no: 0 - } - .into() - )), - record(Event::Collective( - CollectiveEvent::Closed { proposal_hash: hash, yes: 2, no: 0 }.into() - )), - record(Event::Collective(CollectiveEvent::Approved { proposal_hash: hash }.into())), - record(Event::Collective( - CollectiveEvent::Executed { - proposal_hash: hash, - result: Err(DispatchError::BadOrigin) - } - .into() - )), + 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) + })), ] ); @@ -1038,55 +975,44 @@ fn motions_approval_with_enough_votes_and_lower_voting_threshold_works() { assert_eq!( System::events(), vec![ - record(Event::Collective( - CollectiveEvent::Proposed { - account: 1, - proposal_index: 1, - proposal_hash: hash, - threshold: 2 - } - .into() - )), - record(Event::Collective( - CollectiveEvent::Voted { - account: 1, - proposal_hash: hash, - voted: true, - yes: 1, - no: 0 - } - .into() - )), - record(Event::Collective( - CollectiveEvent::Voted { - account: 2, - proposal_hash: hash, - voted: true, - yes: 2, - no: 0 - } - .into() - )), - record(Event::Collective( - CollectiveEvent::Voted { - account: 3, - proposal_hash: hash, - voted: true, - yes: 3, - no: 0 - } - .into() - )), - record(Event::Collective( - CollectiveEvent::Closed { proposal_hash: hash, yes: 3, no: 0 }.into() - )), - record(Event::Collective(CollectiveEvent::Approved { proposal_hash: hash }.into())), - record(Event::Democracy( - mock_democracy::pallet::Event::::ExternalProposed.into() - )), - record(Event::Collective( - CollectiveEvent::Executed { proposal_hash: hash, result: Ok(()) }.into() - )), + 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::::ExternalProposed)), + record(Event::Collective(CollectiveEvent::Executed { + proposal_hash: hash, + result: Ok(()) + })), ] ); }); @@ -1112,41 +1038,32 @@ fn motions_disapproval_works() { assert_eq!( System::events(), vec![ - record(Event::Collective( - CollectiveEvent::Proposed { - account: 1, - proposal_index: 0, - proposal_hash: hash, - threshold: 3 - } - .into() - )), - record(Event::Collective( - CollectiveEvent::Voted { - account: 1, - proposal_hash: hash, - voted: true, - yes: 1, - no: 0 - } - .into() - )), - record(Event::Collective( - CollectiveEvent::Voted { - account: 2, - proposal_hash: hash, - voted: false, - yes: 1, - no: 1 - } - .into() - )), - record(Event::Collective( - CollectiveEvent::Closed { proposal_hash: hash, yes: 1, no: 1 }.into() - )), - record(Event::Collective( - CollectiveEvent::Disapproved { proposal_hash: hash }.into() - )), + 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 })), ] ); }); @@ -1172,46 +1089,36 @@ fn motions_approval_works() { assert_eq!( System::events(), vec![ - record(Event::Collective( - CollectiveEvent::Proposed { - account: 1, - proposal_index: 0, - proposal_hash: hash, - threshold: 2 - } - .into() - )), - record(Event::Collective( - CollectiveEvent::Voted { - account: 1, - proposal_hash: hash, - voted: true, - yes: 1, - no: 0 - } - .into() - )), - record(Event::Collective( - CollectiveEvent::Voted { - account: 2, - proposal_hash: hash, - voted: true, - yes: 2, - no: 0 - } - .into() - )), - record(Event::Collective( - CollectiveEvent::Closed { proposal_hash: hash, yes: 2, no: 0 }.into() - )), - record(Event::Collective(CollectiveEvent::Approved { proposal_hash: hash }.into())), - record(Event::Collective( - CollectiveEvent::Executed { - proposal_hash: hash, - result: Err(DispatchError::BadOrigin) - } - .into() - )), + 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) + })), ] ); }); @@ -1232,15 +1139,12 @@ fn motion_with_no_votes_closes_with_disapproval() { )); assert_eq!( System::events()[0], - record(Event::Collective( - CollectiveEvent::Proposed { - account: 1, - proposal_index: 0, - proposal_hash: hash, - threshold: 3 - } - .into() - )) + 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 @@ -1259,13 +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 { proposal_hash: hash, yes: 0, no: 3 }.into() - )) + record(Event::Collective(CollectiveEvent::Closed { + proposal_hash: hash, + yes: 0, + no: 3 + })) ); assert_eq!( System::events()[2], - record(Event::Collective(CollectiveEvent::Disapproved { proposal_hash: hash }.into())) + record(Event::Collective(CollectiveEvent::Disapproved { proposal_hash: hash })) ); }) } @@ -1325,38 +1231,27 @@ fn disapprove_proposal_works() { assert_eq!( System::events(), vec![ - record(Event::Collective( - CollectiveEvent::Proposed { - account: 1, - proposal_index: 0, - proposal_hash: hash, - threshold: 2 - } - .into() - )), - record(Event::Collective( - CollectiveEvent::Voted { - account: 1, - proposal_hash: hash, - voted: true, - yes: 1, - no: 0 - } - .into() - )), - record(Event::Collective( - CollectiveEvent::Voted { - account: 2, - proposal_hash: hash, - voted: true, - yes: 2, - no: 0 - } - .into() - )), - record(Event::Collective( - CollectiveEvent::Disapproved { proposal_hash: hash }.into() - )), + 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 })), ] ); }) diff --git a/frame/contracts/src/exec.rs b/frame/contracts/src/exec.rs index 26ca2e4bb446..7aa5c0b731fa 100644 --- a/frame/contracts/src/exec.rs +++ b/frame/contracts/src/exec.rs @@ -1289,7 +1289,7 @@ mod tests { System::events() .into_iter() .filter_map(|meta| match meta.event { - MetaEvent::Contracts(contract_event) => Some(*contract_event), + MetaEvent::Contracts(contract_event) => Some(contract_event), _ => None, }) .collect() @@ -2434,9 +2434,10 @@ mod tests { System::events(), vec![EventRecord { phase: Phase::Initialization, - event: MetaEvent::System( - frame_system::Event::Remarked { sender: BOB, hash: remark_hash }.into() - ), + event: MetaEvent::System(frame_system::Event::Remarked { + sender: BOB, + hash: remark_hash + }), topics: vec![], },] ); @@ -2505,25 +2506,23 @@ mod tests { vec![ EventRecord { phase: Phase::Initialization, - event: MetaEvent::System( - frame_system::Event::Remarked { sender: BOB, hash: remark_hash }.into() - ), + event: MetaEvent::System(frame_system::Event::Remarked { + sender: BOB, + hash: remark_hash + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: MetaEvent::Utility(pallet_utility::Event::ItemCompleted.into()), + event: MetaEvent::Utility(pallet_utility::Event::ItemCompleted), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: MetaEvent::Utility( - pallet_utility::Event::BatchInterrupted { - index: 1, - error: frame_system::Error::::CallFiltered.into() - } - .into(), - ), + event: MetaEvent::Utility(pallet_utility::Event::BatchInterrupted { + index: 1, + error: frame_system::Error::::CallFiltered.into() + },), topics: vec![], }, ] diff --git a/frame/contracts/src/tests.rs b/frame/contracts/src/tests.rs index bf909a81c5fd..ce59f5bb858a 100644 --- a/frame/contracts/src/tests.rs +++ b/frame/contracts/src/tests.rs @@ -407,71 +407,57 @@ fn instantiate_and_call_and_deposit_event() { vec![ EventRecord { phase: Phase::Initialization, - event: Event::System( - frame_system::Event::NewAccount { account: addr.clone() }.into() - ), + event: Event::System(frame_system::Event::NewAccount { account: addr.clone() }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Endowed { - account: addr.clone(), - free_balance: min_balance, - } - .into() - ), + event: Event::Balances(pallet_balances::Event::Endowed { + account: addr.clone(), + free_balance: min_balance, + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Transfer { - from: ALICE, - to: addr.clone(), - amount: min_balance, - } - .into() - ), + event: Event::Balances(pallet_balances::Event::Transfer { + from: ALICE, + to: addr.clone(), + amount: min_balance, + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Reserved { who: addr.clone(), amount: min_balance } - .into() - ), + event: Event::Balances(pallet_balances::Event::Reserved { + who: addr.clone(), + amount: min_balance, + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Transfer { - from: ALICE, - to: addr.clone(), - amount: value, - } - .into() - ), + event: Event::Balances(pallet_balances::Event::Transfer { + from: ALICE, + to: addr.clone(), + amount: value, + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Contracts( - crate::Event::ContractEmitted { - contract: addr.clone(), - data: vec![1, 2, 3, 4] - } - .into() - ), + event: Event::Contracts(crate::Event::ContractEmitted { + contract: addr.clone(), + data: vec![1, 2, 3, 4] + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Contracts( - crate::Event::Instantiated { deployer: ALICE, contract: addr.clone() } - .into() - ), + event: Event::Contracts(crate::Event::Instantiated { + deployer: ALICE, + contract: addr.clone() + }), topics: vec![], }, ] @@ -713,78 +699,60 @@ fn deploy_and_call_other_contract() { vec![ EventRecord { phase: Phase::Initialization, - event: Event::System( - frame_system::Event::NewAccount { account: callee_addr.clone() }.into() - ), + event: Event::System(frame_system::Event::NewAccount { + account: callee_addr.clone() + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Endowed { - account: callee_addr.clone(), - free_balance: min_balance, - } - .into() - ), + event: Event::Balances(pallet_balances::Event::Endowed { + account: callee_addr.clone(), + free_balance: min_balance, + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Transfer { - from: ALICE, - to: callee_addr.clone(), - amount: min_balance, - } - .into() - ), + event: Event::Balances(pallet_balances::Event::Transfer { + from: ALICE, + to: callee_addr.clone(), + amount: min_balance, + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Reserved { - who: callee_addr.clone(), - amount: min_balance, - } - .into() - ), + event: Event::Balances(pallet_balances::Event::Reserved { + who: callee_addr.clone(), + amount: min_balance, + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Transfer { - from: caller_addr.clone(), - to: callee_addr.clone(), - amount: 32768, // hard coded in wasm - } - .into() - ), + event: Event::Balances(pallet_balances::Event::Transfer { + from: caller_addr.clone(), + to: callee_addr.clone(), + amount: 32768, // hard coded in wasm + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Contracts( - crate::Event::Instantiated { - deployer: caller_addr.clone(), - contract: callee_addr.clone(), - } - .into() - ), + event: Event::Contracts(crate::Event::Instantiated { + deployer: caller_addr.clone(), + contract: callee_addr.clone(), + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Transfer { - from: caller_addr.clone(), - to: callee_addr.clone(), - amount: 32768, - } - .into() - ), + event: Event::Balances(pallet_balances::Event::Transfer { + from: caller_addr.clone(), + to: callee_addr.clone(), + amount: 32768, + }), topics: vec![], }, ] @@ -980,22 +948,20 @@ fn cannot_self_destruct_by_refund_after_slash() { vec![ EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Slashed { who: addr.clone(), amount: 90 }.into() - ), + event: Event::Balances(pallet_balances::Event::Slashed { + who: addr.clone(), + amount: 90, + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::ReserveRepatriated { - from: addr.clone(), - to: ALICE, - amount: 10, - destination_status: BalanceStatus::Free, - } - .into() - ), + event: Event::Balances(pallet_balances::Event::ReserveRepatriated { + from: addr.clone(), + to: ALICE, + amount: 10, + destination_status: BalanceStatus::Free, + }), topics: vec![], }, ] @@ -1082,42 +1048,36 @@ fn self_destruct_works() { vec![ EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Transfer { - from: addr.clone(), - to: DJANGO, - amount: 100_000, - } - .into() - ), + event: Event::Balances(pallet_balances::Event::Transfer { + from: addr.clone(), + to: DJANGO, + amount: 100_000, + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Contracts( - crate::Event::Terminated { contract: addr.clone(), beneficiary: DJANGO } - .into() - ), + event: Event::Contracts(crate::Event::Terminated { + contract: addr.clone(), + beneficiary: DJANGO + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::System( - frame_system::Event::KilledAccount { account: addr.clone() }.into() - ), + event: Event::System(frame_system::Event::KilledAccount { + account: addr.clone() + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::ReserveRepatriated { - from: addr.clone(), - to: ALICE, - amount: 1_000, - destination_status: BalanceStatus::Free, - } - .into() - ), + event: Event::Balances(pallet_balances::Event::ReserveRepatriated { + from: addr.clone(), + to: ALICE, + amount: 1_000, + destination_status: BalanceStatus::Free, + }), topics: vec![], }, ], @@ -2392,14 +2352,15 @@ fn upload_code_works() { vec![ EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Reserved { who: ALICE, amount: 240 }.into() - ), + event: Event::Balances(pallet_balances::Event::Reserved { + who: ALICE, + amount: 240, + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Contracts(crate::Event::CodeStored { code_hash }.into()), + event: Event::Contracts(crate::Event::CodeStored { code_hash }), topics: vec![], }, ] @@ -2470,26 +2431,28 @@ fn remove_code_works() { vec![ EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Reserved { who: ALICE, amount: 240 }.into() - ), + event: Event::Balances(pallet_balances::Event::Reserved { + who: ALICE, + amount: 240, + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Contracts(crate::Event::CodeStored { code_hash }.into()), + event: Event::Contracts(crate::Event::CodeStored { code_hash }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Unreserved { who: ALICE, amount: 240 }.into() - ), + event: Event::Balances(pallet_balances::Event::Unreserved { + who: ALICE, + amount: 240, + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Contracts(crate::Event::CodeRemoved { code_hash }.into()), + event: Event::Contracts(crate::Event::CodeRemoved { code_hash }), topics: vec![], }, ] @@ -2523,14 +2486,15 @@ fn remove_code_wrong_origin() { vec![ EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Reserved { who: ALICE, amount: 240 }.into() - ), + event: Event::Balances(pallet_balances::Event::Reserved { + who: ALICE, + amount: 240, + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Contracts(crate::Event::CodeStored { code_hash }.into()), + event: Event::Contracts(crate::Event::CodeStored { code_hash }), topics: vec![], }, ] @@ -2623,60 +2587,53 @@ fn instantiate_with_zero_balance_works() { vec![ EventRecord { phase: Phase::Initialization, - event: Event::System( - frame_system::Event::NewAccount { account: addr.clone() }.into() - ), + event: Event::System(frame_system::Event::NewAccount { account: addr.clone() }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Endowed { - account: addr.clone(), - free_balance: min_balance, - } - .into() - ), + event: Event::Balances(pallet_balances::Event::Endowed { + account: addr.clone(), + free_balance: min_balance, + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Transfer { - from: ALICE, - to: addr.clone(), - amount: min_balance, - } - .into() - ), + event: Event::Balances(pallet_balances::Event::Transfer { + from: ALICE, + to: addr.clone(), + amount: min_balance, + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Reserved { who: addr.clone(), amount: min_balance } - .into() - ), + event: Event::Balances(pallet_balances::Event::Reserved { + who: addr.clone(), + amount: min_balance, + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Reserved { who: ALICE, amount: 240 }.into() - ), + event: Event::Balances(pallet_balances::Event::Reserved { + who: ALICE, + amount: 240, + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Contracts(crate::Event::CodeStored { code_hash }.into()), + event: Event::Contracts(crate::Event::CodeStored { code_hash }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Contracts( - crate::Event::Instantiated { deployer: ALICE, contract: addr.clone() } - .into() - ), + event: Event::Contracts(crate::Event::Instantiated { + deployer: ALICE, + contract: addr.clone(), + }), topics: vec![], }, ] @@ -2721,72 +2678,62 @@ fn instantiate_with_below_existential_deposit_works() { vec![ EventRecord { phase: Phase::Initialization, - event: Event::System( - frame_system::Event::NewAccount { account: addr.clone() }.into() - ), + event: Event::System(frame_system::Event::NewAccount { account: addr.clone() }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Endowed { - account: addr.clone(), - free_balance: min_balance, - } - .into() - ), + event: Event::Balances(pallet_balances::Event::Endowed { + account: addr.clone(), + free_balance: min_balance, + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Transfer { - from: ALICE, - to: addr.clone(), - amount: min_balance, - } - .into() - ), + event: Event::Balances(pallet_balances::Event::Transfer { + from: ALICE, + to: addr.clone(), + amount: min_balance, + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Reserved { who: addr.clone(), amount: min_balance } - .into() - ), + event: Event::Balances(pallet_balances::Event::Reserved { + who: addr.clone(), + amount: min_balance, + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Transfer { - from: ALICE, - to: addr.clone(), - amount: 50, - } - .into() - ), + event: Event::Balances(pallet_balances::Event::Transfer { + from: ALICE, + to: addr.clone(), + amount: 50, + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Reserved { who: ALICE, amount: 240 }.into() - ), + event: Event::Balances(pallet_balances::Event::Reserved { + who: ALICE, + amount: 240, + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Contracts(crate::Event::CodeStored { code_hash }.into()), + event: Event::Contracts(crate::Event::CodeStored { code_hash }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Contracts( - crate::Event::Instantiated { deployer: ALICE, contract: addr.clone() } - .into() - ), + event: Event::Contracts(crate::Event::Instantiated { + deployer: ALICE, + contract: addr.clone(), + }), topics: vec![], }, ] @@ -2860,67 +2807,55 @@ fn storage_deposit_works() { vec![ EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Transfer { - from: ALICE, - to: addr.clone(), - amount: 42, - } - .into() - ), + event: Event::Balances(pallet_balances::Event::Transfer { + from: ALICE, + to: addr.clone(), + amount: 42, + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Transfer { - from: ALICE, - to: addr.clone(), - amount: charged0, - } - .into() - ), + event: Event::Balances(pallet_balances::Event::Transfer { + from: ALICE, + to: addr.clone(), + amount: charged0, + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Reserved { who: addr.clone(), amount: charged0 } - .into() - ), + event: Event::Balances(pallet_balances::Event::Reserved { + who: addr.clone(), + amount: charged0, + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Transfer { - from: ALICE, - to: addr.clone(), - amount: charged1, - } - .into() - ), + event: Event::Balances(pallet_balances::Event::Transfer { + from: ALICE, + to: addr.clone(), + amount: charged1, + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Reserved { who: addr.clone(), amount: charged1 } - .into() - ), + event: Event::Balances(pallet_balances::Event::Reserved { + who: addr.clone(), + amount: charged1, + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::ReserveRepatriated { - from: addr.clone(), - to: ALICE, - amount: refunded0, - destination_status: BalanceStatus::Free, - } - .into() - ), + event: Event::Balances(pallet_balances::Event::ReserveRepatriated { + from: addr.clone(), + to: ALICE, + amount: refunded0, + destination_status: BalanceStatus::Free, + }), topics: vec![], }, ] @@ -2996,50 +2931,39 @@ fn call_after_killed_account_needs_funding() { vec![ EventRecord { phase: Phase::Initialization, - event: Event::System( - frame_system::Event::KilledAccount { account: addr.clone() }.into() - ), + event: Event::System(frame_system::Event::KilledAccount { + account: addr.clone() + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Slashed { - who: addr.clone(), - amount: min_balance + 700 - } - .into() - ), + event: Event::Balances(pallet_balances::Event::Slashed { + who: addr.clone(), + amount: min_balance + 700 + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::System( - frame_system::Event::NewAccount { account: addr.clone() }.into() - ), + event: Event::System(frame_system::Event::NewAccount { account: addr.clone() }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Endowed { - account: addr.clone(), - free_balance: min_balance - } - .into() - ), + event: Event::Balances(pallet_balances::Event::Endowed { + account: addr.clone(), + free_balance: min_balance + }), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::Balances( - pallet_balances::Event::Transfer { - from: ALICE, - to: addr.clone(), - amount: min_balance - } - .into() - ), + event: Event::Balances(pallet_balances::Event::Transfer { + from: ALICE, + to: addr.clone(), + amount: min_balance + }), topics: vec![], }, ] @@ -3217,14 +3141,11 @@ fn set_code_hash() { System::events().pop().unwrap(), EventRecord { phase: Phase::Initialization, - event: Event::Contracts( - crate::Event::ContractCodeUpdated { - contract: contract_addr.clone(), - new_code_hash: new_code_hash.clone(), - old_code_hash: code_hash.clone(), - } - .into() - ), + event: Event::Contracts(crate::Event::ContractCodeUpdated { + contract: contract_addr.clone(), + new_code_hash: new_code_hash.clone(), + old_code_hash: code_hash.clone(), + }), topics: vec![], }, ); diff --git a/frame/election-provider-multi-phase/src/mock.rs b/frame/election-provider-multi-phase/src/mock.rs index 0499390135a3..d6f040363dba 100644 --- a/frame/election-provider-multi-phase/src/mock.rs +++ b/frame/election-provider-multi-phase/src/mock.rs @@ -83,7 +83,7 @@ pub(crate) fn multi_phase_events() -> Vec> { System::events() .into_iter() .map(|r| r.event) - .filter_map(|e| if let Event::MultiPhase(inner) = e { Some(*inner) } else { None }) + .filter_map(|e| if let Event::MultiPhase(inner) = e { Some(inner) } else { None }) .collect::>() } diff --git a/frame/elections-phragmen/src/lib.rs b/frame/elections-phragmen/src/lib.rs index 7189545ca419..4758c793cfef 100644 --- a/frame/elections-phragmen/src/lib.rs +++ b/frame/elections-phragmen/src/lib.rs @@ -2163,7 +2163,7 @@ mod tests { System::set_block_number(5); Elections::on_initialize(System::block_number()); - System::assert_last_event(super::Event::EmptyTerm.into()); + System::assert_last_event(Event::Elections(super::Event::EmptyTerm)); }) } @@ -2179,9 +2179,9 @@ mod tests { System::set_block_number(5); Elections::on_initialize(System::block_number()); - System::assert_last_event( - super::Event::NewTerm { new_members: vec![(4, 35), (5, 45)] }.into(), - ); + System::assert_last_event(Event::Elections(super::Event::NewTerm { + new_members: vec![(4, 35), (5, 45)], + })); assert_eq!(members_and_stake(), vec![(4, 35), (5, 45)]); assert_eq!(runners_up_and_stake(), vec![]); @@ -2192,7 +2192,9 @@ mod tests { System::set_block_number(10); Elections::on_initialize(System::block_number()); - System::assert_last_event(super::Event::NewTerm { new_members: vec![] }.into()); + System::assert_last_event(Event::Elections(super::Event::NewTerm { + new_members: vec![], + })); // outgoing have lost their bond. assert_eq!(balances(&4), (37, 0)); @@ -2262,7 +2264,9 @@ mod tests { assert_eq!(Elections::election_rounds(), 1); assert!(members_ids().is_empty()); - System::assert_last_event(super::Event::NewTerm { new_members: vec![] }.into()); + System::assert_last_event(Event::Elections(super::Event::NewTerm { + new_members: vec![], + })); }); } @@ -2614,9 +2618,9 @@ mod tests { // 5 is an outgoing loser. will also get slashed. assert_eq!(balances(&5), (45, 2)); - System::assert_has_event( - super::Event::NewTerm { new_members: vec![(4, 35), (5, 45)] }.into(), - ); + System::assert_has_event(Event::Elections(super::Event::NewTerm { + new_members: vec![(4, 35), (5, 45)], + })); }) } diff --git a/frame/offences/src/tests.rs b/frame/offences/src/tests.rs index 1c071adabc3e..49bd2fb5a692 100644 --- a/frame/offences/src/tests.rs +++ b/frame/offences/src/tests.rs @@ -21,8 +21,8 @@ use super::*; use crate::mock::{ - new_test_ext, offence_reports, report_id, with_on_offence_fractions, Offence, Offences, System, - KIND, + new_test_ext, offence_reports, report_id, with_on_offence_fractions, Event, Offence, Offences, + System, KIND, }; use frame_system::{EventRecord, Phase}; use sp_runtime::Perbill; @@ -114,7 +114,10 @@ fn should_deposit_event() { System::events(), vec![EventRecord { phase: Phase::Initialization, - event: crate::Event::Offence { kind: KIND, timeslot: time_slot.encode() }.into(), + 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: crate::Event::Offence { kind: KIND, timeslot: time_slot.encode() }.into(), + event: Event::Offences(crate::Event::Offence { + kind: KIND, + timeslot: time_slot.encode() + }), topics: vec![], }] ); diff --git a/frame/staking/src/mock.rs b/frame/staking/src/mock.rs index 92325df67bea..bb90aded852e 100644 --- a/frame/staking/src/mock.rs +++ b/frame/staking/src/mock.rs @@ -857,7 +857,7 @@ pub(crate) fn staking_events() -> Vec> { System::events() .into_iter() .map(|r| r.event) - .filter_map(|e| if let Event::Staking(inner) = e { Some(*inner) } else { None }) + .filter_map(|e| if let Event::Staking(inner) = e { Some(inner) } else { None }) .collect() } diff --git a/frame/sudo/src/tests.rs b/frame/sudo/src/tests.rs index 77d7893c5924..84c8e0c5c254 100644 --- a/frame/sudo/src/tests.rs +++ b/frame/sudo/src/tests.rs @@ -19,7 +19,10 @@ use super::*; use frame_support::{assert_noop, assert_ok}; -use mock::{new_test_ext, Call, Logger, LoggerCall, Origin, Sudo, SudoCall, System, Test}; +use mock::{ + new_test_ext, Call, Event as TestEvent, Logger, LoggerCall, Origin, Sudo, SudoCall, System, + Test, +}; #[test] fn test_setup_works() { @@ -55,7 +58,7 @@ fn sudo_emits_events_correctly() { // Should emit event to indicate success when called with the root `key` and `call` is `Ok`. let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log { i: 42, weight: 1 })); assert_ok!(Sudo::sudo(Origin::signed(1), call)); - System::assert_has_event(Event::Sudid { sudo_result: Ok(()) }.into()); + System::assert_has_event(TestEvent::Sudo(Event::Sudid { sudo_result: Ok(()) })); }) } @@ -93,7 +96,7 @@ fn sudo_unchecked_weight_emits_events_correctly() { // Should emit event to indicate success when called with the root `key` and `call` is `Ok`. let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log { i: 42, weight: 1 })); assert_ok!(Sudo::sudo_unchecked_weight(Origin::signed(1), call, 1_000)); - System::assert_has_event(Event::Sudid { sudo_result: Ok(()) }.into()); + System::assert_has_event(TestEvent::Sudo(Event::Sudid { sudo_result: Ok(()) })); }) } @@ -120,10 +123,10 @@ fn set_key_emits_events_correctly() { // A root `key` can change the root `key`. assert_ok!(Sudo::set_key(Origin::signed(1), 2)); - System::assert_has_event(Event::KeyChanged { old_sudoer: Some(1) }.into()); + System::assert_has_event(TestEvent::Sudo(Event::KeyChanged { old_sudoer: Some(1) })); // Double check. assert_ok!(Sudo::set_key(Origin::signed(2), 4)); - System::assert_has_event(Event::KeyChanged { old_sudoer: Some(2) }.into()); + System::assert_has_event(TestEvent::Sudo(Event::KeyChanged { old_sudoer: Some(2) })); }); } @@ -158,6 +161,6 @@ fn sudo_as_emits_events_correctly() { // A non-privileged function will work when passed to `sudo_as` with the root `key`. let call = Box::new(Call::Logger(LoggerCall::non_privileged_log { i: 42, weight: 1 })); assert_ok!(Sudo::sudo_as(Origin::signed(1), 2, call)); - System::assert_has_event(Event::SudoAsDone { sudo_result: Ok(()) }.into()); + System::assert_has_event(TestEvent::Sudo(Event::SudoAsDone { sudo_result: Ok(()) })); }); } diff --git a/frame/support/test/tests/pallet.rs b/frame/support/test/tests/pallet.rs index c17364cee8b6..83f6a722f93a 100644 --- a/frame/support/test/tests/pallet.rs +++ b/frame/support/test/tests/pallet.rs @@ -628,7 +628,7 @@ fn transactional_works() { .iter() .map(|e| &e.event) .collect::>(), - vec![&Event::Example(pallet::Event::Something(0).into())], + vec![&Event::Example(pallet::Event::Something(0))], ); }) } @@ -884,7 +884,7 @@ fn pallet_expand_deposit_event() { .unwrap(); assert_eq!( frame_system::Pallet::::events()[0].event, - Event::Example(pallet::Event::Something(3).into()), + Event::Example(pallet::Event::Something(3)), ); }) } @@ -991,27 +991,27 @@ fn pallet_hooks_expand() { assert_eq!( frame_system::Pallet::::events()[0].event, - Event::Example(pallet::Event::Something(10).into()), + Event::Example(pallet::Event::Something(10)), ); assert_eq!( frame_system::Pallet::::events()[1].event, - Event::Example2(pallet2::Event::Something(11).into()), + Event::Example2(pallet2::Event::Something(11)), ); assert_eq!( frame_system::Pallet::::events()[2].event, - Event::Example(pallet::Event::Something(20).into()), + Event::Example(pallet::Event::Something(20)), ); assert_eq!( frame_system::Pallet::::events()[3].event, - Event::Example2(pallet2::Event::Something(21).into()), + Event::Example2(pallet2::Event::Something(21)), ); assert_eq!( frame_system::Pallet::::events()[4].event, - Event::Example(pallet::Event::Something(30).into()), + Event::Example(pallet::Event::Something(30)), ); assert_eq!( frame_system::Pallet::::events()[5].event, - Event::Example2(pallet2::Event::Something(31).into()), + Event::Example2(pallet2::Event::Something(31)), ); }) } @@ -1031,27 +1031,27 @@ fn all_pallets_type_reversed_order_is_correct() { assert_eq!( frame_system::Pallet::::events()[0].event, - Event::Example2(pallet2::Event::Something(11).into()), + Event::Example2(pallet2::Event::Something(11)), ); assert_eq!( frame_system::Pallet::::events()[1].event, - Event::Example(pallet::Event::Something(10).into()), + Event::Example(pallet::Event::Something(10)), ); assert_eq!( frame_system::Pallet::::events()[2].event, - Event::Example2(pallet2::Event::Something(21).into()), + Event::Example2(pallet2::Event::Something(21)), ); assert_eq!( frame_system::Pallet::::events()[3].event, - Event::Example(pallet::Event::Something(20).into()), + Event::Example(pallet::Event::Something(20)), ); assert_eq!( frame_system::Pallet::::events()[4].event, - Event::Example2(pallet2::Event::Something(31).into()), + Event::Example2(pallet2::Event::Something(31)), ); assert_eq!( frame_system::Pallet::::events()[5].event, - Event::Example(pallet::Event::Something(30).into()), + Event::Example(pallet::Event::Something(30)), ); }) } diff --git a/frame/support/test/tests/pallet_instance.rs b/frame/support/test/tests/pallet_instance.rs index d69b52a0f6d7..118794e2fa20 100644 --- a/frame/support/test/tests/pallet_instance.rs +++ b/frame/support/test/tests/pallet_instance.rs @@ -385,7 +385,7 @@ fn pallet_expand_deposit_event() { .unwrap(); assert_eq!( frame_system::Pallet::::events()[0].event, - Event::Example(pallet::Event::Something(3).into()), + Event::Example(pallet::Event::Something(3)), ); }); @@ -396,7 +396,7 @@ fn pallet_expand_deposit_event() { .unwrap(); assert_eq!( frame_system::Pallet::::events()[0].event, - Event::Instance1Example(pallet::Event::Something(3).into()), + Event::Instance1Example(pallet::Event::Something(3)), ); }); } @@ -562,27 +562,27 @@ fn pallet_hooks_expand() { assert_eq!( frame_system::Pallet::::events()[0].event, - Event::Example(pallet::Event::Something(10).into()), + Event::Example(pallet::Event::Something(10)), ); assert_eq!( frame_system::Pallet::::events()[1].event, - Event::Instance1Example(pallet::Event::Something(11).into()), + Event::Instance1Example(pallet::Event::Something(11)), ); assert_eq!( frame_system::Pallet::::events()[2].event, - Event::Example(pallet::Event::Something(20).into()), + Event::Example(pallet::Event::Something(20)), ); assert_eq!( frame_system::Pallet::::events()[3].event, - Event::Instance1Example(pallet::Event::Something(21).into()), + Event::Instance1Example(pallet::Event::Something(21)), ); assert_eq!( frame_system::Pallet::::events()[4].event, - Event::Example(pallet::Event::Something(30).into()), + Event::Example(pallet::Event::Something(30)), ); assert_eq!( frame_system::Pallet::::events()[5].event, - Event::Instance1Example(pallet::Event::Something(31).into()), + Event::Instance1Example(pallet::Event::Something(31)), ); }) } diff --git a/frame/tips/src/tests.rs b/frame/tips/src/tests.rs index a01d86711250..0c58a949958f 100644 --- a/frame/tips/src/tests.rs +++ b/frame/tips/src/tests.rs @@ -175,7 +175,7 @@ fn last_event() -> TipEvent { System::events() .into_iter() .map(|r| r.event) - .filter_map(|e| if let Event::Tips(inner) = e { Some(*inner) } else { None }) + .filter_map(|e| if let Event::Tips(inner) = e { Some(inner) } else { None }) .last() .unwrap() } diff --git a/frame/transaction-payment/src/lib.rs b/frame/transaction-payment/src/lib.rs index 112527447f3f..1462faaa0706 100644 --- a/frame/transaction-payment/src/lib.rs +++ b/frame/transaction-payment/src/lib.rs @@ -1374,11 +1374,15 @@ mod tests { )); assert_eq!(Balances::free_balance(2), 0); // Transfer Event - System::assert_has_event( - pallet_balances::Event::Transfer { from: 2, to: 3, amount: 80 }.into(), - ); + System::assert_has_event(Event::Balances(pallet_balances::Event::Transfer { + from: 2, + to: 3, + amount: 80, + })); // Killed Event - System::assert_has_event(system::Event::KilledAccount { account: 2 }.into()); + System::assert_has_event(Event::System(system::Event::KilledAccount { + account: 2, + })); }); } From 5cf70c452653646fe5c78eb78076c8f62d0ba900 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Tue, 12 Apr 2022 21:06:44 +0200 Subject: [PATCH 5/6] Use simpler approach Signed-off-by: Oliver Tale-Yazdi --- frame/system/src/lib.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/frame/system/src/lib.rs b/frame/system/src/lib.rs index 9b30e7b45227..3dbadae0611f 100644 --- a/frame/system/src/lib.rs +++ b/frame/system/src/lib.rs @@ -591,11 +591,14 @@ pub mod pallet { /// Events deposited for the current block. /// - /// NOTE: This storage item is explicitly unbounded since it is never intended to be read - /// from within the runtime. + /// NOTE: The item is unbound and should therefore never be read from storage. + /// It could otherwise inflate the PoV size of a block. + /// + /// Events have a large in-memory size. Box the events to not go out-of-memory + /// just in case someone still reads them from within the runtime. #[pallet::storage] pub(super) type Events = - StorageValue<_, Vec>, ValueQuery>; + StorageValue<_, Vec>>, ValueQuery>; /// The number of events in the `Events` list. #[pallet::storage] @@ -1213,7 +1216,7 @@ impl Pallet { old_event_count }; - Events::::append(&event); + Events::::append(event); for topic in topics { >::append(topic, &(block_number, event_idx)); @@ -1380,14 +1383,16 @@ impl Pallet { /// items for any behavior like this. #[cfg(any(feature = "std", feature = "runtime-benchmarks", test))] pub fn events() -> Vec> { - Self::read_events_no_consensus() + // Dereferencing the events here is fine since we are not in the + // memory-restricted runtime. + Self::read_events_no_consensus().into_iter().map(|e| *e).collect() } /// Get the current events deposited by the runtime. /// /// Should only be called if you know what you are doing and outside of the runtime block /// execution else it can have a large impact on the PoV size of a block. - pub fn read_events_no_consensus() -> Vec> { + pub fn read_events_no_consensus() -> Vec>> { Events::::get() } From 3f5ad28fec2dc289344f7cdd1457acfca7198987 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Wed, 13 Apr 2022 11:50:26 +0200 Subject: [PATCH 6/6] Update doc Signed-off-by: Oliver Tale-Yazdi --- frame/system/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/system/src/lib.rs b/frame/system/src/lib.rs index 3dbadae0611f..0eefc23a6b5d 100644 --- a/frame/system/src/lib.rs +++ b/frame/system/src/lib.rs @@ -591,7 +591,7 @@ pub mod pallet { /// Events deposited for the current block. /// - /// NOTE: The item is unbound and should therefore never be read from storage. + /// NOTE: The item is unbound and should therefore never be read on chain. /// It could otherwise inflate the PoV size of a block. /// /// Events have a large in-memory size. Box the events to not go out-of-memory