From 0ed683ca139ce584b952682b5feb4ea3f010bb2e Mon Sep 17 00:00:00 2001 From: Guillaume Thiolliere Date: Sat, 6 Feb 2021 21:12:46 +0100 Subject: [PATCH] Use construct_runtime in tests (#8059) * impl some more * add serde * remove unused * fix staking fuzz * fix system bench Co-authored-by: Shawn Tabrizi --- substrate/Cargo.lock | 3 + substrate/frame/benchmarking/Cargo.toml | 1 + substrate/frame/benchmarking/src/tests.rs | 392 +++++++++--------- .../example-offchain-worker/src/tests.rs | 61 +-- substrate/frame/example-parallel/Cargo.toml | 3 + substrate/frame/example-parallel/src/tests.rs | 38 +- substrate/frame/example/src/lib.rs | 69 +-- substrate/frame/grandpa/src/mock.rs | 71 ++-- substrate/frame/grandpa/src/tests.rs | 2 +- .../frame/session/benchmarking/src/mock.rs | 40 +- substrate/frame/staking/fuzzer/Cargo.toml | 6 + substrate/frame/staking/fuzzer/src/mock.rs | 44 +- substrate/frame/system/benches/bench.rs | 27 +- .../frame/system/benchmarking/src/mock.rs | 36 +- .../system/src/extensions/check_mortality.rs | 2 +- substrate/frame/system/src/mock.rs | 52 +-- substrate/frame/system/src/offchain.rs | 10 +- substrate/frame/system/src/tests.rs | 34 +- 18 files changed, 446 insertions(+), 445 deletions(-) diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index 0405105157..b02baa3064 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -1644,6 +1644,7 @@ dependencies = [ "linregress", "parity-scale-codec", "paste 1.0.4", + "serde", "sp-api", "sp-io", "sp-runtime", @@ -4730,6 +4731,7 @@ dependencies = [ "frame-support", "frame-system", "parity-scale-codec", + "serde", "sp-core", "sp-io", "sp-runtime", @@ -5150,6 +5152,7 @@ dependencies = [ "pallet-staking-reward-curve", "pallet-timestamp", "parity-scale-codec", + "serde", "sp-core", "sp-io", "sp-npos-elections", diff --git a/substrate/frame/benchmarking/Cargo.toml b/substrate/frame/benchmarking/Cargo.toml index 2cec36698d..4fdb31dca5 100644 --- a/substrate/frame/benchmarking/Cargo.toml +++ b/substrate/frame/benchmarking/Cargo.toml @@ -27,6 +27,7 @@ frame-system = { version = "2.0.0", default-features = false, path = "../system" [dev-dependencies] hex-literal = "0.3.1" +serde = "1.0.101" [features] default = [ "std" ] diff --git a/substrate/frame/benchmarking/src/tests.rs b/substrate/frame/benchmarking/src/tests.rs index 2a2daaffba..53093fdf06 100644 --- a/substrate/frame/benchmarking/src/tests.rs +++ b/substrate/frame/benchmarking/src/tests.rs @@ -21,59 +21,65 @@ use super::*; use sp_std::prelude::*; -use sp_runtime::{traits::{BlakeTwo256, IdentityLookup}, testing::{H256, Header}}; -use frame_support::{ - dispatch::DispatchResult, - decl_module, decl_storage, impl_outer_origin, assert_ok, assert_err, ensure, - parameter_types, pallet_prelude::Get, -}; -use frame_system::{RawOrigin, ensure_signed, ensure_none}; +use sp_runtime::{traits::{BlakeTwo256, IdentityLookup}, testing::{H256, Header}, BuildStorage}; +use frame_support::parameter_types; -decl_storage! { - trait Store for Module as Test where - ::OtherEvent: Into<::Event> +mod pallet_test { + use frame_support::pallet_prelude::Get; + + frame_support::decl_storage! { + trait Store for Module as Test where + ::OtherEvent: Into<::Event> + { + pub Value get(fn value): Option; + } + } + + frame_support::decl_module! { + pub struct Module for enum Call where + origin: T::Origin, ::OtherEvent: Into<::Event> + { + #[weight = 0] + fn set_value(origin, n: u32) -> frame_support::dispatch::DispatchResult { + let _sender = frame_system::ensure_signed(origin)?; + Value::put(n); + Ok(()) + } + + #[weight = 0] + fn dummy(origin, _n: u32) -> frame_support::dispatch::DispatchResult { + let _sender = frame_system::ensure_none(origin)?; + Ok(()) + } + } + } + + pub trait OtherConfig { + type OtherEvent; + } + + pub trait Config: frame_system::Config + OtherConfig + where Self::OtherEvent: Into<::Event> { - Value get(fn value): Option; + type Event; + type LowerBound: Get; + type UpperBound: Get; } } -decl_module! { - pub struct Module for enum Call where - origin: T::Origin, ::OtherEvent: Into<::Event> +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; + +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, { - #[weight = 0] - fn set_value(origin, n: u32) -> DispatchResult { - let _sender = ensure_signed(origin)?; - Value::put(n); - Ok(()) - } - - #[weight = 0] - fn dummy(origin, _n: u32) -> DispatchResult { - let _sender = ensure_none(origin)?; - Ok(()) - } + System: frame_system::{Module, Call, Config, Storage, Event}, + TestPallet: pallet_test::{Module, Call, Storage}, } -} - -impl_outer_origin! { - pub enum Origin for Test where system = frame_system {} -} - -pub trait OtherConfig { - type OtherEvent; -} - -pub trait Config: frame_system::Config + OtherConfig - where Self::OtherEvent: Into<::Event> -{ - type Event; - type LowerBound: Get; - type UpperBound: Get; -} - -#[derive(Clone, Eq, PartialEq)] -pub struct Test; +); impl frame_system::Config for Test { type BaseCallFilter = (); @@ -84,15 +90,15 @@ impl frame_system::Config for Test { type Index = u64; type BlockNumber = u64; type Hash = H256; - type Call = (); + type Call = Call; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; type Header = Header; - type Event = (); + type Event = Event; type BlockHashCount = (); type Version = (); - type PalletInfo = (); + type PalletInfo = PalletInfo; type AccountData = (); type OnNewAccount = (); type OnKilledAccount = (); @@ -105,163 +111,177 @@ parameter_types!{ pub const UpperBound: u32 = 100; } -impl Config for Test { - type Event = (); +impl pallet_test::Config for Test { + type Event = Event; type LowerBound = LowerBound; type UpperBound = UpperBound; } -impl OtherConfig for Test { - type OtherEvent = (); +impl pallet_test::OtherConfig for Test { + type OtherEvent = Event; } fn new_test_ext() -> sp_io::TestExternalities { - frame_system::GenesisConfig::default().build_storage::().unwrap().into() + GenesisConfig::default().build_storage().unwrap().into() } -benchmarks!{ - where_clause { where ::OtherEvent: Into<::Event> } +mod benchmarks { + use sp_std::prelude::*; + use frame_system::RawOrigin; + use super::{Test, pallet_test::{self, Value}, new_test_ext}; + use frame_support::{assert_ok, assert_err, ensure, traits::Get, StorageValue}; + use crate::{BenchmarkingSetup, BenchmarkParameter, account}; - set_value { - let b in 1 .. 1000; - let caller = account::("caller", 0, 0); - }: _ (RawOrigin::Signed(caller), b.into()) - verify { - assert_eq!(Value::get(), Some(b)); - } + // Additional used internally by the benchmark macro. + use super::pallet_test::{Call, Config, Module}; - other_name { - let b in 1 .. 1000; - }: dummy (RawOrigin::None, b.into()) - - sort_vector { - let x in 1 .. 10000; - let mut m = Vec::::new(); - for i in (0..x).rev() { - m.push(i); + crate::benchmarks!{ + where_clause { + where + ::OtherEvent: Into<::Event> } - }: { - m.sort(); - } verify { - ensure!(m[0] == 0, "You forgot to sort!") - } - bad_origin { - let b in 1 .. 1000; - let caller = account::("caller", 0, 0); - }: dummy (RawOrigin::Signed(caller), b.into()) - - bad_verify { - let x in 1 .. 10000; - let mut m = Vec::::new(); - for i in (0..x).rev() { - m.push(i); + set_value { + let b in 1 .. 1000; + let caller = account::("caller", 0, 0); + }: _ (RawOrigin::Signed(caller), b.into()) + verify { + assert_eq!(Value::get(), Some(b)); } - }: { } - verify { - ensure!(m[0] == 0, "You forgot to sort!") + + other_name { + let b in 1 .. 1000; + }: dummy (RawOrigin::None, b.into()) + + sort_vector { + let x in 1 .. 10000; + let mut m = Vec::::new(); + for i in (0..x).rev() { + m.push(i); + } + }: { + m.sort(); + } verify { + ensure!(m[0] == 0, "You forgot to sort!") + } + + bad_origin { + let b in 1 .. 1000; + let caller = account::("caller", 0, 0); + }: dummy (RawOrigin::Signed(caller), b.into()) + + bad_verify { + let x in 1 .. 10000; + let mut m = Vec::::new(); + for i in (0..x).rev() { + m.push(i); + } + }: { } + verify { + ensure!(m[0] == 0, "You forgot to sort!") + } + + no_components { + let caller = account::("caller", 0, 0); + }: set_value(RawOrigin::Signed(caller), 0) + + variable_components { + let b in ( T::LowerBound::get() ) .. T::UpperBound::get(); + }: dummy (RawOrigin::None, b.into()) } - no_components { - let caller = account::("caller", 0, 0); - }: set_value(RawOrigin::Signed(caller), 0) + #[test] + fn benchmarks_macro_works() { + // Check benchmark creation for `set_value`. + let selected = SelectedBenchmark::set_value; - variable_components { - let b in ( T::LowerBound::get() ) .. T::UpperBound::get(); - }: dummy (RawOrigin::None, b.into()) -} + let components = >::components(&selected); + assert_eq!(components, vec![(BenchmarkParameter::b, 1, 1000)]); -#[test] -fn benchmarks_macro_works() { - // Check benchmark creation for `set_value`. - let selected = SelectedBenchmark::set_value; + let closure = >::instance( + &selected, + &[(BenchmarkParameter::b, 1)], + true, + ).expect("failed to create closure"); - let components = >::components(&selected); - assert_eq!(components, vec![(BenchmarkParameter::b, 1, 1000)]); + new_test_ext().execute_with(|| { + assert_ok!(closure()); + }); + } - let closure = >::instance( - &selected, - &[(BenchmarkParameter::b, 1)], - true, - ).expect("failed to create closure"); + #[test] + fn benchmarks_macro_rename_works() { + // Check benchmark creation for `other_dummy`. + let selected = SelectedBenchmark::other_name; + let components = >::components(&selected); + assert_eq!(components, vec![(BenchmarkParameter::b, 1, 1000)]); + + let closure = >::instance( + &selected, + &[(BenchmarkParameter::b, 1)], + true, + ).expect("failed to create closure"); + + new_test_ext().execute_with(|| { + assert_ok!(closure()); + }); + } + + #[test] + fn benchmarks_macro_works_for_non_dispatchable() { + let selected = SelectedBenchmark::sort_vector; + + let components = >::components(&selected); + assert_eq!(components, vec![(BenchmarkParameter::x, 1, 10000)]); + + let closure = >::instance( + &selected, + &[(BenchmarkParameter::x, 1)], + true, + ).expect("failed to create closure"); - new_test_ext().execute_with(|| { assert_ok!(closure()); - }); -} - -#[test] -fn benchmarks_macro_rename_works() { - // Check benchmark creation for `other_dummy`. - let selected = SelectedBenchmark::other_name; - let components = >::components(&selected); - assert_eq!(components, vec![(BenchmarkParameter::b, 1, 1000)]); - - let closure = >::instance( - &selected, - &[(BenchmarkParameter::b, 1)], - true, - ).expect("failed to create closure"); - - new_test_ext().execute_with(|| { - assert_ok!(closure()); - }); -} - -#[test] -fn benchmarks_macro_works_for_non_dispatchable() { - let selected = SelectedBenchmark::sort_vector; - - let components = >::components(&selected); - assert_eq!(components, vec![(BenchmarkParameter::x, 1, 10000)]); - - let closure = >::instance( - &selected, - &[(BenchmarkParameter::x, 1)], - true, - ).expect("failed to create closure"); - - assert_ok!(closure()); -} - -#[test] -fn benchmarks_macro_verify_works() { - // Check postcondition for benchmark `set_value` is valid. - let selected = SelectedBenchmark::set_value; - - let closure = >::instance( - &selected, - &[(BenchmarkParameter::b, 1)], - true, - ).expect("failed to create closure"); - - new_test_ext().execute_with(|| { - assert_ok!(closure()); - }); - - // Check postcondition for benchmark `bad_verify` is invalid. - let selected = SelectedBenchmark::bad_verify; - - let closure = >::instance( - &selected, - &[(BenchmarkParameter::x, 10000)], - true, - ).expect("failed to create closure"); - - new_test_ext().execute_with(|| { - assert_err!(closure(), "You forgot to sort!"); - }); -} - -#[test] -fn benchmarks_generate_unit_tests() { - new_test_ext().execute_with(|| { - assert_ok!(test_benchmark_set_value::()); - assert_ok!(test_benchmark_other_name::()); - assert_ok!(test_benchmark_sort_vector::()); - assert_err!(test_benchmark_bad_origin::(), "Bad origin"); - assert_err!(test_benchmark_bad_verify::(), "You forgot to sort!"); - assert_ok!(test_benchmark_no_components::()); - assert_ok!(test_benchmark_variable_components::()); - }); + } + + #[test] + fn benchmarks_macro_verify_works() { + // Check postcondition for benchmark `set_value` is valid. + let selected = SelectedBenchmark::set_value; + + let closure = >::instance( + &selected, + &[(BenchmarkParameter::b, 1)], + true, + ).expect("failed to create closure"); + + new_test_ext().execute_with(|| { + assert_ok!(closure()); + }); + + // Check postcondition for benchmark `bad_verify` is invalid. + let selected = SelectedBenchmark::bad_verify; + + let closure = >::instance( + &selected, + &[(BenchmarkParameter::x, 10000)], + true, + ).expect("failed to create closure"); + + new_test_ext().execute_with(|| { + assert_err!(closure(), "You forgot to sort!"); + }); + } + + #[test] + fn benchmarks_generate_unit_tests() { + new_test_ext().execute_with(|| { + assert_ok!(test_benchmark_set_value::()); + assert_ok!(test_benchmark_other_name::()); + assert_ok!(test_benchmark_sort_vector::()); + assert_err!(test_benchmark_bad_origin::(), "Bad origin"); + assert_err!(test_benchmark_bad_verify::(), "You forgot to sort!"); + assert_ok!(test_benchmark_no_components::()); + assert_ok!(test_benchmark_variable_components::()); + }); + } } diff --git a/substrate/frame/example-offchain-worker/src/tests.rs b/substrate/frame/example-offchain-worker/src/tests.rs index 882c2d6057..6f73ffcb9e 100644 --- a/substrate/frame/example-offchain-worker/src/tests.rs +++ b/substrate/frame/example-offchain-worker/src/tests.rs @@ -16,11 +16,10 @@ // limitations under the License. use crate::*; +use crate as example_offchain_worker; use std::sync::Arc; -use codec::{Encode, Decode}; -use frame_support::{ - assert_ok, impl_outer_origin, parameter_types, -}; +use codec::Decode; +use frame_support::{assert_ok, parameter_types}; use sp_core::{ H256, offchain::{OffchainExt, TransactionPoolExt, testing}, @@ -40,15 +39,21 @@ use sp_runtime::{ }, }; -impl_outer_origin! { - pub enum Origin for Test where system = frame_system {} -} +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; + +// For testing the module, we construct a mock runtime. +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Module, Call, Config, Storage, Event}, + Example: example_offchain_worker::{Module, Call, Storage, Event, ValidateUnsigned}, + } +); -// For testing the module, we construct most of a mock runtime. This means -// first constructing a configuration type (`Test`) which `impl`s each of the -// configuration traits of modules we want to use. -#[derive(Clone, Eq, PartialEq, Encode, Decode)] -pub struct Test; parameter_types! { pub const BlockHashCount: u64 = 250; pub BlockWeights: frame_system::limits::BlockWeights = @@ -60,7 +65,7 @@ impl frame_system::Config for Test { type BlockLength = (); type DbWeight = (); type Origin = Origin; - type Call = (); + type Call = Call; type Index = u64; type BlockNumber = u64; type Hash = H256; @@ -68,10 +73,10 @@ impl frame_system::Config for Test { type AccountId = sp_core::sr25519::Public; type Lookup = IdentityLookup; type Header = Header; - type Event = (); + type Event = Event; type BlockHashCount = BlockHashCount; type Version = (); - type PalletInfo = (); + type PalletInfo = PalletInfo; type AccountData = (); type OnNewAccount = (); type OnKilledAccount = (); @@ -79,7 +84,7 @@ impl frame_system::Config for Test { type SS58Prefix = (); } -type Extrinsic = TestXt, ()>; +type Extrinsic = TestXt; type AccountId = <::Signer as IdentifyAccount>::AccountId; impl frame_system::offchain::SigningTypes for Test { @@ -88,21 +93,21 @@ impl frame_system::offchain::SigningTypes for Test { } impl frame_system::offchain::SendTransactionTypes for Test where - Call: From, + Call: From, { - type OverarchingCall = Call; + type OverarchingCall = Call; type Extrinsic = Extrinsic; } impl frame_system::offchain::CreateSignedTransaction for Test where - Call: From, + Call: From, { fn create_transaction>( - call: Call, + call: Call, _public: ::Signer, _account: AccountId, nonce: u64, - ) -> Option<(Call, ::SignaturePayload)> { + ) -> Option<(Call, ::SignaturePayload)> { Some((call, (nonce, ()))) } } @@ -114,16 +119,14 @@ parameter_types! { } impl Config for Test { - type Event = (); + type Event = Event; type AuthorityId = crypto::TestAuthId; - type Call = Call; + type Call = Call; type GracePeriod = GracePeriod; type UnsignedInterval = UnsignedInterval; type UnsignedPriority = UnsignedPriority; } -type Example = Module; - #[test] fn it_aggregates_the_price() { sp_io::TestExternalities::default().execute_with(|| { @@ -228,7 +231,7 @@ fn should_submit_signed_transaction_on_chain() { assert!(pool_state.read().transactions.is_empty()); let tx = Extrinsic::decode(&mut &*tx).unwrap(); assert_eq!(tx.signature.unwrap().0, 0); - assert_eq!(tx.call, Call::submit_price(15523)); + assert_eq!(tx.call, Call::Example(crate::Call::submit_price(15523))); }); } @@ -272,7 +275,7 @@ fn should_submit_unsigned_transaction_on_chain_for_any_account() { let tx = pool_state.write().transactions.pop().unwrap(); let tx = Extrinsic::decode(&mut &*tx).unwrap(); assert_eq!(tx.signature, None); - if let Call::submit_price_unsigned_with_signed_payload(body, signature) = tx.call { + if let Call::Example(crate::Call::submit_price_unsigned_with_signed_payload(body, signature)) = tx.call { assert_eq!(body, price_payload); let signature_valid = ; +type Block = frame_system::mocking::MockBlock; + +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Module, Call, Config, Storage, Event}, + Example: pallet_example_parallel::{Module, Call, Storage, Event}, + } +); -#[derive(Clone, Eq, PartialEq, Encode, Decode)] -pub struct Test; parameter_types! { pub const BlockHashCount: u64 = 250; pub const AvailableBlockRatio: Perbill = Perbill::one(); @@ -40,8 +46,8 @@ parameter_types! { impl frame_system::Config for Test { type BaseCallFilter = (); type Origin = Origin; - type Call = (); - type PalletInfo = (); + type Call = Call; + type PalletInfo = PalletInfo; type Index = u64; type BlockNumber = u64; type Hash = H256; @@ -49,7 +55,7 @@ impl frame_system::Config for Test { type AccountId = sp_core::sr25519::Public; type Lookup = IdentityLookup; type Header = Header; - type Event = (); + type Event = Event; type BlockHashCount = BlockHashCount; type DbWeight = (); type BlockWeights = (); @@ -69,12 +75,10 @@ parameter_types! { } impl Config for Test { - type Event = (); - type Call = Call; + type Event = Event; + type Call = Call; } -type Example = Module; - #[test] fn it_can_enlist() { use sp_core::Pair; diff --git a/substrate/frame/example/src/lib.rs b/substrate/frame/example/src/lib.rs index cfb72a5c15..335c277b7c 100644 --- a/substrate/frame/example/src/lib.rs +++ b/substrate/frame/example/src/lib.rs @@ -707,32 +707,35 @@ mod tests { use super::*; use frame_support::{ - assert_ok, impl_outer_origin, parameter_types, impl_outer_dispatch, + assert_ok, parameter_types, weights::{DispatchInfo, GetDispatchInfo}, traits::{OnInitialize, OnFinalize} }; use sp_core::H256; // The testing primitives are very useful for avoiding having to work with signatures // or public keys. `u64` is used as the `AccountId` and no `Signature`s are required. use sp_runtime::{ - testing::Header, + testing::Header, BuildStorage, traits::{BlakeTwo256, IdentityLookup}, }; + // Reexport crate as its pallet name for construct_runtime. + use crate as pallet_example; - impl_outer_origin! { - pub enum Origin for Test where system = frame_system {} - } + type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; + type Block = frame_system::mocking::MockBlock; - impl_outer_dispatch! { - pub enum OuterCall for Test where origin: Origin { - self::Example, + // For testing the pallet, we construct a mock runtime. + frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Module, Call, Config, Storage, Event}, + Balances: pallet_balances::{Module, Call, Storage, Config, Event}, + Example: pallet_example::{Module, Call, Storage, Config, Event}, } - } + ); - // For testing the pallet, we construct most of a mock runtime. This means - // first constructing a configuration type (`Test`) which `impl`s each of the - // configuration traits of pallets we want to use. - #[derive(Clone, Eq, PartialEq)] - pub struct Test; parameter_types! { pub const BlockHashCount: u64 = 250; pub BlockWeights: frame_system::limits::BlockWeights = @@ -747,15 +750,15 @@ mod tests { type Index = u64; type BlockNumber = u64; type Hash = H256; - type Call = OuterCall; + type Call = Call; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; type Header = Header; - type Event = (); + type Event = Event; type BlockHashCount = BlockHashCount; type Version = (); - type PalletInfo = (); + type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; type OnNewAccount = (); type OnKilledAccount = (); @@ -769,29 +772,29 @@ mod tests { type MaxLocks = (); type Balance = u64; type DustRemoval = (); - type Event = (); + type Event = Event; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = (); } impl Config for Test { - type Event = (); + type Event = Event; } - type System = frame_system::Module; - type Example = Module; // This function basically just builds a genesis storage key/value store according to // our desired mockup. pub fn new_test_ext() -> sp_io::TestExternalities { - let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); - // We use default for brevity, but you can configure as desired if needed. - pallet_balances::GenesisConfig::::default().assimilate_storage(&mut t).unwrap(); - GenesisConfig::{ - dummy: 42, - // we configure the map with (key, value) pairs. - bar: vec![(1, 2), (2, 3)], - foo: 24, - }.assimilate_storage(&mut t).unwrap(); + let t = GenesisConfig { + // We use default for brevity, but you can configure as desired if needed. + frame_system: Some(Default::default()), + pallet_balances: Some(Default::default()), + pallet_example: Some(pallet_example::GenesisConfig { + dummy: 42, + // we configure the map with (key, value) pairs. + bar: vec![(1, 2), (2, 3)], + foo: 24, + }), + }.build_storage().unwrap(); t.into() } @@ -828,7 +831,7 @@ mod tests { #[test] fn signed_ext_watch_dummy_works() { new_test_ext().execute_with(|| { - let call = >::set_dummy(10).into(); + let call = >::set_dummy(10).into(); let info = DispatchInfo::default(); assert_eq!( @@ -847,13 +850,13 @@ mod tests { #[test] fn weights_work() { // must have a defined weight. - let default_call = >::accumulate_dummy(10); + let default_call = >::accumulate_dummy(10); let info = default_call.get_dispatch_info(); // aka. `let info = as GetDispatchInfo>::get_dispatch_info(&default_call);` assert_eq!(info.weight, 0); // must have a custom weight of `100 * arg = 2000` - let custom_call = >::set_dummy(20); + let custom_call = >::set_dummy(20); let info = custom_call.get_dispatch_info(); assert_eq!(info.weight, 2000); } diff --git a/substrate/frame/grandpa/src/mock.rs b/substrate/frame/grandpa/src/mock.rs index fd7230fd9c..4aeaa5a237 100644 --- a/substrate/frame/grandpa/src/mock.rs +++ b/substrate/frame/grandpa/src/mock.rs @@ -19,11 +19,11 @@ #![cfg(test)] -use crate::{AuthorityId, AuthorityList, ConsensusLog, Module, Config}; +use crate::{AuthorityId, AuthorityList, ConsensusLog, Config, self as pallet_grandpa}; use ::grandpa as finality_grandpa; use codec::Encode; use frame_support::{ - impl_outer_dispatch, impl_outer_event, impl_outer_origin, parameter_types, + parameter_types, traits::{KeyOwnerProofSystem, OnFinalize, OnInitialize}, weights::Weight, }; @@ -40,17 +40,27 @@ use sp_runtime::{ DigestItem, Perbill, }; use sp_staking::SessionIndex; +use pallet_session::historical as pallet_session_historical; -impl_outer_origin! { - pub enum Origin for Test {} -} +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; -impl_outer_dispatch! { - pub enum Call for Test where origin: Origin { - pallet_grandpa::Grandpa, - pallet_staking::Staking, +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Module, Call, Config, Storage, Event}, + Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent}, + Balances: pallet_balances::{Module, Call, Storage, Config, Event}, + Staking: pallet_staking::{Module, Call, Config, Storage, Event, ValidateUnsigned}, + Session: pallet_session::{Module, Call, Storage, Event, Config}, + Grandpa: pallet_grandpa::{Module, Call, Storage, Config, Event, ValidateUnsigned}, + Offences: pallet_offences::{Module, Call, Storage, Event}, + Historical: pallet_session_historical::{Module}, } -} +); impl_opaque_keys! { pub struct TestSessionKeys { @@ -58,20 +68,6 @@ impl_opaque_keys! { } } -impl_outer_event! { - pub enum TestEvent for Test { - frame_system, - pallet_balances, - pallet_grandpa, - pallet_offences, - pallet_session, - pallet_staking, - } -} - -#[derive(Clone, Eq, PartialEq)] -pub struct Test; - parameter_types! { pub const BlockHashCount: u64 = 250; pub BlockWeights: frame_system::limits::BlockWeights = @@ -92,10 +88,10 @@ impl frame_system::Config for Test { type AccountId = u64; type Lookup = IdentityLookup; type Header = Header; - type Event = TestEvent; + type Event = Event; type BlockHashCount = BlockHashCount; type Version = (); - type PalletInfo = (); + type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; type OnNewAccount = (); type OnKilledAccount = (); @@ -119,7 +115,7 @@ parameter_types! { /// Custom `SessionHandler` since we use `TestSessionKeys` as `Keys`. impl pallet_session::Config for Test { - type Event = TestEvent; + type Event = Event; type ValidatorId = u64; type ValidatorIdOf = pallet_staking::StashOf; type ShouldEndSession = pallet_session::PeriodicSessions; @@ -155,7 +151,7 @@ impl pallet_balances::Config for Test { type MaxLocks = (); type Balance = u128; type DustRemoval = (); - type Event = TestEvent; + type Event = Event; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = (); @@ -197,7 +193,7 @@ parameter_types! { impl pallet_staking::Config for Test { type RewardRemainder = (); type CurrencyToVote = frame_support::traits::SaturatingCurrencyToVote; - type Event = TestEvent; + type Event = Event; type Currency = Balances; type Slash = (); type Reward = (); @@ -224,14 +220,14 @@ parameter_types! { } impl pallet_offences::Config for Test { - type Event = TestEvent; + type Event = Event; type IdentificationTuple = pallet_session::historical::IdentificationTuple; type OnOffenceHandler = Staking; type WeightSoftLimit = OffencesWeightSoftLimit; } impl Config for Test { - type Event = TestEvent; + type Event = Event; type Call = Call; type KeyOwnerProofSystem = Historical; @@ -249,19 +245,6 @@ impl Config for Test { type WeightInfo = (); } -mod pallet_grandpa { - pub use crate::Event; -} - -pub type Balances = pallet_balances::Module; -pub type Historical = pallet_session::historical::Module; -pub type Offences = pallet_offences::Module; -pub type Session = pallet_session::Module; -pub type Staking = pallet_staking::Module; -pub type System = frame_system::Module; -pub type Timestamp = pallet_timestamp::Module; -pub type Grandpa = Module; - pub fn grandpa_log(log: ConsensusLog) -> DigestItem { DigestItem::Consensus(GRANDPA_ENGINE_ID, log.encode()) } diff --git a/substrate/frame/grandpa/src/tests.rs b/substrate/frame/grandpa/src/tests.rs index 0964be5993..cd5e0c3563 100644 --- a/substrate/frame/grandpa/src/tests.rs +++ b/substrate/frame/grandpa/src/tests.rs @@ -19,7 +19,7 @@ #![cfg(test)] -use super::{Call, *}; +use super::{Call, Event, *}; use crate::mock::*; use codec::{Decode, Encode}; use fg_primitives::ScheduledChange; diff --git a/substrate/frame/session/benchmarking/src/mock.rs b/substrate/frame/session/benchmarking/src/mock.rs index 711cde8e8e..b25b169c82 100644 --- a/substrate/frame/session/benchmarking/src/mock.rs +++ b/substrate/frame/session/benchmarking/src/mock.rs @@ -20,30 +20,28 @@ #![cfg(test)] use sp_runtime::traits::IdentityLookup; -use frame_support::{impl_outer_origin, impl_outer_dispatch, parameter_types}; +use frame_support::parameter_types; type AccountId = u64; type AccountIndex = u32; type BlockNumber = u64; type Balance = u64; -type System = frame_system::Module; -type Balances = pallet_balances::Module; -type Staking = pallet_staking::Module; -type Session = pallet_session::Module; +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; -impl_outer_origin! { - pub enum Origin for Test where system = frame_system {} -} - -impl_outer_dispatch! { - pub enum Call for Test where origin: Origin { - pallet_staking::Staking, +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Module, Call, Config, Storage, Event}, + Balances: pallet_balances::{Module, Call, Storage, Config, Event}, + Staking: pallet_staking::{Module, Call, Config, Storage, Event, ValidateUnsigned}, + Session: pallet_session::{Module, Call, Storage, Event, Config}, } -} - -#[derive(Clone, Eq, PartialEq, Debug)] -pub struct Test; +); impl frame_system::Config for Test { type BaseCallFilter = (); @@ -59,10 +57,10 @@ impl frame_system::Config for Test { type AccountId = AccountId; type Lookup = IdentityLookup; type Header = sp_runtime::testing::Header; - type Event = (); + type Event = Event; type BlockHashCount = (); type Version = (); - type PalletInfo = (); + type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; type OnNewAccount = (); type OnKilledAccount = (); @@ -75,7 +73,7 @@ parameter_types! { impl pallet_balances::Config for Test { type MaxLocks = (); type Balance = Balance; - type Event = (); + type Event = Event; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; @@ -123,7 +121,7 @@ impl pallet_session::Config for Test { type ShouldEndSession = pallet_session::PeriodicSessions<(), ()>; type NextSessionRotation = pallet_session::PeriodicSessions<(), ()>; type SessionHandler = TestSessionHandler; - type Event = (); + type Event = Event; type ValidatorId = AccountId; type ValidatorIdOf = pallet_staking::StashOf; type DisabledValidatorsThreshold = (); @@ -159,7 +157,7 @@ impl pallet_staking::Config for Test { type UnixTime = pallet_timestamp::Module; type CurrencyToVote = frame_support::traits::SaturatingCurrencyToVote; type RewardRemainder = (); - type Event = (); + type Event = Event; type Slash = (); type Reward = (); type SessionsPerEra = (); diff --git a/substrate/frame/staking/fuzzer/Cargo.toml b/substrate/frame/staking/fuzzer/Cargo.toml index 920f53c869..9940adaa00 100644 --- a/substrate/frame/staking/fuzzer/Cargo.toml +++ b/substrate/frame/staking/fuzzer/Cargo.toml @@ -28,6 +28,12 @@ sp-io ={ version = "2.0.0", path = "../../../primitives/io" } sp-core = { version = "2.0.0", path = "../../../primitives/core" } sp-npos-elections = { version = "2.0.0", path = "../../../primitives/npos-elections" } sp-runtime = { version = "2.0.0", path = "../../../primitives/runtime" } +serde = "1.0.101" + +[features] +# Note feature std is required so that impl_opaque_keys derive serde. +default = ["std"] +std = [] [[bin]] name = "submit_solution" diff --git a/substrate/frame/staking/fuzzer/src/mock.rs b/substrate/frame/staking/fuzzer/src/mock.rs index 75e67fa365..88b001c7e6 100644 --- a/substrate/frame/staking/fuzzer/src/mock.rs +++ b/substrate/frame/staking/fuzzer/src/mock.rs @@ -17,31 +17,29 @@ //! Mock file for staking fuzzing. -use frame_support::{impl_outer_origin, impl_outer_dispatch, parameter_types}; +use frame_support::parameter_types; type AccountId = u64; type AccountIndex = u32; type BlockNumber = u64; type Balance = u64; -pub type System = frame_system::Module; -pub type Balances = pallet_balances::Module; -pub type Staking = pallet_staking::Module; -pub type Indices = pallet_indices::Module; -pub type Session = pallet_session::Module; +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; -impl_outer_origin! { - pub enum Origin for Test where system = frame_system {} -} - -impl_outer_dispatch! { - pub enum Call for Test where origin: Origin { - staking::Staking, +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Module, Call, Config, Storage, Event}, + Balances: pallet_balances::{Module, Call, Storage, Config, Event}, + Staking: pallet_staking::{Module, Call, Config, Storage, Event, ValidateUnsigned}, + Indices: pallet_indices::{Module, Call, Storage, Config, Event}, + Session: pallet_session::{Module, Call, Storage, Event, Config}, } -} - -#[derive(Clone, Eq, PartialEq, Debug)] -pub struct Test; +); impl frame_system::Config for Test { type BaseCallFilter = (); @@ -57,10 +55,10 @@ impl frame_system::Config for Test { type AccountId = AccountId; type Lookup = Indices; type Header = sp_runtime::testing::Header; - type Event = (); + type Event = Event; type BlockHashCount = (); type Version = (); - type PalletInfo = (); + type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; type OnNewAccount = (); type OnKilledAccount = (); @@ -73,7 +71,7 @@ parameter_types! { impl pallet_balances::Config for Test { type MaxLocks = (); type Balance = Balance; - type Event = (); + type Event = Event; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; @@ -81,7 +79,7 @@ impl pallet_balances::Config for Test { } impl pallet_indices::Config for Test { type AccountIndex = AccountIndex; - type Event = (); + type Event = Event; type Currency = Balances; type Deposit = (); type WeightInfo = (); @@ -127,7 +125,7 @@ impl pallet_session::Config for Test { type ShouldEndSession = pallet_session::PeriodicSessions<(), ()>; type NextSessionRotation = pallet_session::PeriodicSessions<(), ()>; type SessionHandler = TestSessionHandler; - type Event = (); + type Event = Event; type ValidatorId = AccountId; type ValidatorIdOf = pallet_staking::StashOf; type DisabledValidatorsThreshold = (); @@ -163,7 +161,7 @@ impl pallet_staking::Config for Test { type UnixTime = pallet_timestamp::Module; type CurrencyToVote = frame_support::traits::SaturatingCurrencyToVote; type RewardRemainder = (); - type Event = (); + type Event = Event; type Slash = (); type Reward = (); type SessionsPerEra = (); diff --git a/substrate/frame/system/benches/bench.rs b/substrate/frame/system/benches/bench.rs index 5bebeaf932..6ed3d45682 100644 --- a/substrate/frame/system/benches/bench.rs +++ b/substrate/frame/system/benches/bench.rs @@ -17,7 +17,7 @@ use criterion::{Criterion, criterion_group, criterion_main, black_box}; use frame_system as system; -use frame_support::{decl_module, decl_event, impl_outer_origin, impl_outer_event}; +use frame_support::{decl_module, decl_event}; use sp_core::H256; use sp_runtime::{Perbill, traits::{BlakeTwo256, IdentityLookup}, testing::Header}; @@ -41,16 +41,19 @@ mod module { ); } -impl_outer_origin!{ - pub enum Origin for Runtime {} -} +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; -impl_outer_event! { - pub enum Event for Runtime { - system, - module, +frame_support::construct_runtime!( + pub enum Runtime where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Module, Call, Config, Storage, Event}, + Module: module::{Module, Call, Event}, } -} +); frame_support::parameter_types! { pub const BlockHashCount: u64 = 250; @@ -63,8 +66,6 @@ frame_support::parameter_types! { 4 * 1024 * 1024, Perbill::from_percent(75), ); } -#[derive(Clone, Eq, PartialEq)] -pub struct Runtime; impl system::Config for Runtime { type BaseCallFilter = (); type BlockWeights = (); @@ -73,7 +74,7 @@ impl system::Config for Runtime { type Origin = Origin; type Index = u64; type BlockNumber = u64; - type Call = (); + type Call = Call; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u64; @@ -82,7 +83,7 @@ impl system::Config for Runtime { type Event = Event; type BlockHashCount = BlockHashCount; type Version = (); - type PalletInfo = (); + type PalletInfo = PalletInfo; type AccountData = (); type OnNewAccount = (); type OnKilledAccount = (); diff --git a/substrate/frame/system/benchmarking/src/mock.rs b/substrate/frame/system/benchmarking/src/mock.rs index 87f9113a49..edc5dfebbd 100644 --- a/substrate/frame/system/benchmarking/src/mock.rs +++ b/substrate/frame/system/benchmarking/src/mock.rs @@ -20,35 +20,23 @@ #![cfg(test)] use sp_runtime::traits::IdentityLookup; -use frame_support::{ - impl_outer_origin, - dispatch::{Dispatchable, DispatchInfo, PostDispatchInfo}, -}; type AccountId = u64; type AccountIndex = u32; type BlockNumber = u64; -impl_outer_origin! { - pub enum Origin for Test where system = frame_system {} -} +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; -#[derive(Debug, codec::Encode, codec::Decode)] -pub struct Call; - -impl Dispatchable for Call { - type Origin = (); - type Config = (); - type Info = DispatchInfo; - type PostInfo = PostDispatchInfo; - fn dispatch(self, _origin: Self::Origin) - -> sp_runtime::DispatchResultWithInfo { - panic!("Do not use dummy implementation for dispatch."); +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Module, Call, Config, Storage, Event}, } -} - -#[derive(Clone, Eq, PartialEq, Debug)] -pub struct Test; +); impl frame_system::Config for Test { type BaseCallFilter = (); @@ -64,10 +52,10 @@ impl frame_system::Config for Test { type AccountId = AccountId; type Lookup = IdentityLookup; type Header = sp_runtime::testing::Header; - type Event = (); + type Event = Event; type BlockHashCount = (); type Version = (); - type PalletInfo = (); + type PalletInfo = PalletInfo; type AccountData = (); type OnNewAccount = (); type OnKilledAccount = (); diff --git a/substrate/frame/system/src/extensions/check_mortality.rs b/substrate/frame/system/src/extensions/check_mortality.rs index f1951baba5..1e8eb32a3d 100644 --- a/substrate/frame/system/src/extensions/check_mortality.rs +++ b/substrate/frame/system/src/extensions/check_mortality.rs @@ -110,7 +110,7 @@ mod tests { let normal = DispatchInfo { weight: 100, class: DispatchClass::Normal, pays_fee: Pays::Yes }; let len = 0_usize; let ext = ( - crate::CheckWeight::::default(), + crate::CheckWeight::::new(), CheckMortality::::from(Era::mortal(16, 256)), ); System::set_block_number(17); diff --git a/substrate/frame/system/src/mock.rs b/substrate/frame/system/src/mock.rs index d67f00917f..2b31929b5d 100644 --- a/substrate/frame/system/src/mock.rs +++ b/substrate/frame/system/src/mock.rs @@ -15,24 +15,27 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::*; +use crate::{self as frame_system, *}; use sp_std::cell::RefCell; use sp_core::H256; use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup}, - testing::Header, -}; -use frame_support::{ - impl_outer_origin, parameter_types, - weights::PostDispatchInfo, + testing::Header, BuildStorage, }; +use frame_support::parameter_types; -impl_outer_origin! { - pub enum Origin for Test where system = super {} -} +type UncheckedExtrinsic = mocking::MockUncheckedExtrinsic; +type Block = mocking::MockBlock; -#[derive(Clone, Eq, PartialEq, Debug, Default)] -pub struct Test; +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Module, Call, Config, Storage, Event}, + } +); const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); const MAX_BLOCK_WEIGHT: Weight = 1024; @@ -81,20 +84,6 @@ impl OnKilledAccount for RecordKilled { fn on_killed_account(who: &u64) { KILLED.with(|r| r.borrow_mut().push(*who)) } } -#[derive(Debug, codec::Encode, codec::Decode)] -pub struct Call; - -impl Dispatchable for Call { - type Origin = Origin; - type Config = (); - type Info = DispatchInfo; - type PostInfo = PostDispatchInfo; - fn dispatch(self, _origin: Self::Origin) - -> sp_runtime::DispatchResultWithInfo { - panic!("Do not use dummy implementation for dispatch."); - } -} - impl Config for Test { type BaseCallFilter = (); type BlockWeights = RuntimeBlockWeights; @@ -108,11 +97,11 @@ impl Config for Test { type AccountId = u64; type Lookup = IdentityLookup; type Header = Header; - type Event = Event; + type Event = Event; type BlockHashCount = BlockHashCount; type DbWeight = DbWeight; type Version = Version; - type PalletInfo = (); + type PalletInfo = PalletInfo; type AccountData = u32; type OnNewAccount = (); type OnKilledAccount = RecordKilled; @@ -120,14 +109,15 @@ impl Config for Test { type SS58Prefix = (); } -pub type System = Module; -pub type SysEvent = ::Event; +pub type SysEvent = frame_system::Event; -pub const CALL: &::Call = &Call; +/// A simple call, which one doesn't matter. +pub const CALL: &::Call = &Call::System(frame_system::Call::set_heap_pages(0u64)); /// Create new externalities for `System` module tests. pub fn new_test_ext() -> sp_io::TestExternalities { - let mut ext: sp_io::TestExternalities = GenesisConfig::default().build_storage::().unwrap().into(); + let mut ext: sp_io::TestExternalities = GenesisConfig::default() + .build_storage().unwrap().into(); // Add to each test the initial weight of a block ext.execute_with(|| System::register_extra_weight_unchecked( ::BlockWeights::get().base_block, diff --git a/substrate/frame/system/src/offchain.rs b/substrate/frame/system/src/offchain.rs index 05a5882ee3..f2f446913c 100644 --- a/substrate/frame/system/src/offchain.rs +++ b/substrate/frame/system/src/offchain.rs @@ -637,7 +637,7 @@ pub trait SignedPayload: Encode { mod tests { use super::*; use codec::Decode; - use crate::mock::{Test as TestRuntime, Call}; + use crate::mock::{Test as TestRuntime, Call, CALL}; use sp_core::offchain::{testing, TransactionPoolExt}; use sp_runtime::testing::{UintAuthorityId, TestSignature, TestXt}; @@ -708,7 +708,7 @@ mod tests { public: account.public.clone() }, |_payload, _signature| { - Call + CALL.clone() } ); @@ -749,7 +749,7 @@ mod tests { public: account.public.clone() }, |_payload, _signature| { - Call + CALL.clone() } ); @@ -787,7 +787,7 @@ mod tests { public: account.public.clone() }, |_payload, _signature| { - Call + CALL.clone() } ); @@ -827,7 +827,7 @@ mod tests { public: account.public.clone() }, |_payload, _signature| { - Call + CALL.clone() } ); diff --git a/substrate/frame/system/src/tests.rs b/substrate/frame/system/src/tests.rs index d1992a14e0..ca17edcf4b 100644 --- a/substrate/frame/system/src/tests.rs +++ b/substrate/frame/system/src/tests.rs @@ -71,7 +71,7 @@ fn deposit_event_should_work() { vec![ EventRecord { phase: Phase::Finalization, - event: SysEvent::CodeUpdated, + event: SysEvent::CodeUpdated.into(), topics: vec![], } ] @@ -99,17 +99,17 @@ fn deposit_event_should_work() { vec![ EventRecord { phase: Phase::Initialization, - event: SysEvent::NewAccount(32), + event: SysEvent::NewAccount(32).into(), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(0), - event: SysEvent::KilledAccount(42), + event: SysEvent::KilledAccount(42).into(), topics: vec![] }, EventRecord { phase: Phase::ApplyExtrinsic(0), - event: SysEvent::ExtrinsicSuccess(Default::default()), + event: SysEvent::ExtrinsicSuccess(Default::default()).into(), topics: vec![] }, EventRecord { @@ -117,12 +117,12 @@ fn deposit_event_should_work() { event: SysEvent::ExtrinsicFailed( DispatchError::BadOrigin.into(), Default::default() - ), + ).into(), topics: vec![] }, EventRecord { phase: Phase::Finalization, - event: SysEvent::NewAccount(3), + event: SysEvent::NewAccount(3).into(), topics: vec![] }, ] @@ -173,7 +173,7 @@ fn deposit_event_uses_actual_weight() { weight: 300, .. Default::default() }, - ), + ).into(), topics: vec![] }, EventRecord { @@ -183,7 +183,7 @@ fn deposit_event_uses_actual_weight() { weight: 1000, .. Default::default() }, - ), + ).into(), topics: vec![] }, EventRecord { @@ -193,7 +193,7 @@ fn deposit_event_uses_actual_weight() { weight: 1000, .. Default::default() }, - ), + ).into(), topics: vec![] }, EventRecord { @@ -204,7 +204,7 @@ fn deposit_event_uses_actual_weight() { weight: 999, .. Default::default() }, - ), + ).into(), topics: vec![] }, ] @@ -232,9 +232,9 @@ fn deposit_event_topics() { ]; // We deposit a few events with different sets of topics. - System::deposit_event_indexed(&topics[0..3], SysEvent::NewAccount(1)); - System::deposit_event_indexed(&topics[0..1], SysEvent::NewAccount(2)); - System::deposit_event_indexed(&topics[1..2], SysEvent::NewAccount(3)); + System::deposit_event_indexed(&topics[0..3], SysEvent::NewAccount(1).into()); + System::deposit_event_indexed(&topics[0..1], SysEvent::NewAccount(2).into()); + System::deposit_event_indexed(&topics[1..2], SysEvent::NewAccount(3).into()); System::finalize(); @@ -244,17 +244,17 @@ fn deposit_event_topics() { vec![ EventRecord { phase: Phase::Finalization, - event: SysEvent::NewAccount(1), + event: SysEvent::NewAccount(1).into(), topics: topics[0..3].to_vec(), }, EventRecord { phase: Phase::Finalization, - event: SysEvent::NewAccount(2), + event: SysEvent::NewAccount(2).into(), topics: topics[0..1].to_vec(), }, EventRecord { phase: Phase::Finalization, - event: SysEvent::NewAccount(3), + event: SysEvent::NewAccount(3).into(), topics: topics[1..2].to_vec(), } ] @@ -375,7 +375,7 @@ fn set_code_with_real_wasm_blob() { System::events(), vec![EventRecord { phase: Phase::Initialization, - event: SysEvent::CodeUpdated, + event: SysEvent::CodeUpdated.into(), topics: vec![], }], );