diff --git a/bin/node-template/node/src/chain_spec.rs b/bin/node-template/node/src/chain_spec.rs index f7ed87251391e..5093a77b571e9 100644 --- a/bin/node-template/node/src/chain_spec.rs +++ b/bin/node-template/node/src/chain_spec.rs @@ -134,22 +134,22 @@ fn testnet_genesis( _enable_println: bool, ) -> GenesisConfig { GenesisConfig { - frame_system: SystemConfig { + system: SystemConfig { // Add Wasm runtime to storage. code: wasm_binary.to_vec(), changes_trie_config: Default::default(), }, - pallet_balances: BalancesConfig { + balances: BalancesConfig { // Configure endowed accounts with initial balance of 1 << 60. balances: endowed_accounts.iter().cloned().map(|k|(k, 1 << 60)).collect(), }, - pallet_aura: AuraConfig { + aura: AuraConfig { authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(), }, - pallet_grandpa: GrandpaConfig { + grandpa: GrandpaConfig { authorities: initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect(), }, - pallet_sudo: SudoConfig { + sudo: SudoConfig { // Assign network admin rights. key: root_key, }, diff --git a/bin/node/cli/src/chain_spec.rs b/bin/node/cli/src/chain_spec.rs index 3454aa83c24d4..e3ba16b9de6f3 100644 --- a/bin/node/cli/src/chain_spec.rs +++ b/bin/node/cli/src/chain_spec.rs @@ -261,19 +261,19 @@ pub fn testnet_genesis( const STASH: Balance = ENDOWMENT / 1000; GenesisConfig { - frame_system: SystemConfig { + system: SystemConfig { code: wasm_binary_unwrap().to_vec(), changes_trie_config: Default::default(), }, - pallet_balances: BalancesConfig { + balances: BalancesConfig { balances: endowed_accounts.iter().cloned() .map(|x| (x, ENDOWMENT)) .collect() }, - pallet_indices: IndicesConfig { + indices: IndicesConfig { indices: vec![], }, - pallet_session: SessionConfig { + session: SessionConfig { keys: initial_authorities.iter().map(|x| { (x.0.clone(), x.0.clone(), session_keys( x.2.clone(), @@ -283,7 +283,7 @@ pub fn testnet_genesis( )) }).collect::>(), }, - pallet_staking: StakingConfig { + staking: StakingConfig { validator_count: initial_authorities.len() as u32, minimum_validator_count: initial_authorities.len() as u32, invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(), @@ -291,41 +291,41 @@ pub fn testnet_genesis( stakers, .. Default::default() }, - pallet_democracy: DemocracyConfig::default(), - pallet_elections_phragmen: ElectionsConfig { + democracy: DemocracyConfig::default(), + elections: ElectionsConfig { members: endowed_accounts.iter() .take((num_endowed_accounts + 1) / 2) .cloned() .map(|member| (member, STASH)) .collect(), }, - pallet_collective_Instance1: CouncilConfig::default(), - pallet_collective_Instance2: TechnicalCommitteeConfig { + council: CouncilConfig::default(), + technical_committee: TechnicalCommitteeConfig { members: endowed_accounts.iter() .take((num_endowed_accounts + 1) / 2) .cloned() .collect(), phantom: Default::default(), }, - pallet_sudo: SudoConfig { + sudo: SudoConfig { key: root_key, }, - pallet_babe: BabeConfig { + babe: BabeConfig { authorities: vec![], epoch_config: Some(node_runtime::BABE_GENESIS_EPOCH_CONFIG), }, - pallet_im_online: ImOnlineConfig { + im_online: ImOnlineConfig { keys: vec![], }, - pallet_authority_discovery: AuthorityDiscoveryConfig { + authority_discovery: AuthorityDiscoveryConfig { keys: vec![], }, - pallet_grandpa: GrandpaConfig { + grandpa: GrandpaConfig { authorities: vec![], }, - pallet_membership_Instance1: Default::default(), - pallet_treasury: Default::default(), - pallet_society: SocietyConfig { + technical_membership: Default::default(), + treasury: Default::default(), + society: SocietyConfig { members: endowed_accounts.iter() .take((num_endowed_accounts + 1) / 2) .cloned() @@ -333,9 +333,9 @@ pub fn testnet_genesis( pot: 0, max_members: 999, }, - pallet_vesting: Default::default(), - pallet_gilt: Default::default(), - pallet_transaction_storage: Default::default(), + vesting: Default::default(), + gilt: Default::default(), + transaction_storage: Default::default(), } } diff --git a/bin/node/executor/tests/basic.rs b/bin/node/executor/tests/basic.rs index fe3ae5f14cc37..8c7b1eae5dec1 100644 --- a/bin/node/executor/tests/basic.rs +++ b/bin/node/executor/tests/basic.rs @@ -347,14 +347,14 @@ fn full_native_block_import_works() { let events = vec![ EventRecord { phase: Phase::ApplyExtrinsic(0), - event: Event::frame_system(frame_system::Event::ExtrinsicSuccess( + event: Event::System(frame_system::Event::ExtrinsicSuccess( DispatchInfo { weight: timestamp_weight, class: DispatchClass::Mandatory, ..Default::default() } )), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(1), - event: Event::pallet_balances(pallet_balances::Event::Transfer( + event: Event::Balances(pallet_balances::Event::Transfer( alice().into(), bob().into(), 69 * DOLLARS, @@ -363,12 +363,12 @@ fn full_native_block_import_works() { }, EventRecord { phase: Phase::ApplyExtrinsic(1), - event: Event::pallet_treasury(pallet_treasury::RawEvent::Deposit(fees * 8 / 10)), + event: Event::Treasury(pallet_treasury::RawEvent::Deposit(fees * 8 / 10)), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(1), - event: Event::frame_system(frame_system::Event::ExtrinsicSuccess( + event: Event::System(frame_system::Event::ExtrinsicSuccess( DispatchInfo { weight: transfer_weight, ..Default::default() } )), topics: vec![], @@ -399,14 +399,14 @@ fn full_native_block_import_works() { let events = vec![ EventRecord { phase: Phase::ApplyExtrinsic(0), - event: Event::frame_system(frame_system::Event::ExtrinsicSuccess( + event: Event::System(frame_system::Event::ExtrinsicSuccess( DispatchInfo { weight: timestamp_weight, class: DispatchClass::Mandatory, ..Default::default() } )), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(1), - event: Event::pallet_balances( + event: Event::Balances( pallet_balances::Event::Transfer( bob().into(), alice().into(), @@ -417,19 +417,19 @@ fn full_native_block_import_works() { }, EventRecord { phase: Phase::ApplyExtrinsic(1), - event: Event::pallet_treasury(pallet_treasury::RawEvent::Deposit(fees * 8 / 10)), + event: Event::Treasury(pallet_treasury::RawEvent::Deposit(fees * 8 / 10)), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(1), - event: Event::frame_system(frame_system::Event::ExtrinsicSuccess( + event: Event::System(frame_system::Event::ExtrinsicSuccess( DispatchInfo { weight: transfer_weight, ..Default::default() } )), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(2), - event: Event::pallet_balances( + event: Event::Balances( pallet_balances::Event::Transfer( alice().into(), bob().into(), @@ -440,12 +440,12 @@ fn full_native_block_import_works() { }, EventRecord { phase: Phase::ApplyExtrinsic(2), - event: Event::pallet_treasury(pallet_treasury::RawEvent::Deposit(fees * 8 / 10)), + event: Event::Treasury(pallet_treasury::RawEvent::Deposit(fees * 8 / 10)), topics: vec![], }, EventRecord { phase: Phase::ApplyExtrinsic(2), - event: Event::frame_system(frame_system::Event::ExtrinsicSuccess( + event: Event::System(frame_system::Event::ExtrinsicSuccess( DispatchInfo { weight: transfer_weight, ..Default::default() } )), topics: vec![], diff --git a/bin/node/testing/src/genesis.rs b/bin/node/testing/src/genesis.rs index 6f884d1f73b62..3a6d51f1971ed 100644 --- a/bin/node/testing/src/genesis.rs +++ b/bin/node/testing/src/genesis.rs @@ -56,20 +56,20 @@ pub fn config_endowed( ); GenesisConfig { - frame_system: SystemConfig { + system: SystemConfig { changes_trie_config: if support_changes_trie { Some(ChangesTrieConfiguration { digest_interval: 2, digest_levels: 2, }) } else { None }, code: code.map(|x| x.to_vec()).unwrap_or_else(|| wasm_binary_unwrap().to_vec()), }, - pallet_indices: IndicesConfig { + indices: IndicesConfig { indices: vec![], }, - pallet_balances: BalancesConfig { + balances: BalancesConfig { balances: endowed, }, - pallet_session: SessionConfig { + session: SessionConfig { keys: vec![ (dave(), alice(), to_session_keys( &Ed25519Keyring::Alice, @@ -85,7 +85,7 @@ pub fn config_endowed( )), ] }, - pallet_staking: StakingConfig { + staking: StakingConfig { stakers: vec![ (dave(), alice(), 111 * DOLLARS, StakerStatus::Validator), (eve(), bob(), 100 * DOLLARS, StakerStatus::Validator), @@ -97,29 +97,29 @@ pub fn config_endowed( invulnerables: vec![alice(), bob(), charlie()], .. Default::default() }, - pallet_babe: BabeConfig { + babe: BabeConfig { authorities: vec![], epoch_config: Some(BABE_GENESIS_EPOCH_CONFIG), }, - pallet_grandpa: GrandpaConfig { + grandpa: GrandpaConfig { authorities: vec![], }, - pallet_im_online: Default::default(), - pallet_authority_discovery: Default::default(), - pallet_democracy: Default::default(), - pallet_collective_Instance1: Default::default(), - pallet_collective_Instance2: Default::default(), - pallet_membership_Instance1: Default::default(), - pallet_elections_phragmen: Default::default(), - pallet_sudo: Default::default(), - pallet_treasury: Default::default(), - pallet_society: SocietyConfig { + im_online: Default::default(), + authority_discovery: Default::default(), + democracy: Default::default(), + council: Default::default(), + technical_committee: Default::default(), + technical_membership: Default::default(), + elections: Default::default(), + sudo: Default::default(), + treasury: Default::default(), + society: SocietyConfig { members: vec![alice(), bob()], pot: 0, max_members: 999, }, - pallet_vesting: Default::default(), - pallet_gilt: Default::default(), - pallet_transaction_storage: Default::default(), + vesting: Default::default(), + gilt: Default::default(), + transaction_storage: Default::default(), } } diff --git a/frame/assets/src/tests.rs b/frame/assets/src/tests.rs index 3ee8f9a9cfa47..6bef5b962de74 100644 --- a/frame/assets/src/tests.rs +++ b/frame/assets/src/tests.rs @@ -397,7 +397,7 @@ 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::pallet_assets(crate::Event::Transferred(0, 1, 2, 0))); + System::assert_last_event(mock::Event::Assets(crate::Event::Transferred(0, 1, 2, 0))); }); } diff --git a/frame/balances/src/tests.rs b/frame/balances/src/tests.rs index 9589fb25805b4..ef420bb946522 100644 --- a/frame/balances/src/tests.rs +++ b/frame/balances/src/tests.rs @@ -464,7 +464,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::pallet_balances(crate::Event::ReserveRepatriated(1, 2, 41, Status::Free)) + Event::Balances(crate::Event::ReserveRepatriated(1, 2, 41, Status::Free)) ); assert_eq!(Balances::reserved_balance(1), 69); assert_eq!(Balances::free_balance(1), 0); @@ -683,18 +683,18 @@ macro_rules! decl_tests { System::set_block_number(2); assert_ok!(Balances::reserve(&1, 10)); - System::assert_last_event(Event::pallet_balances(crate::Event::Reserved(1, 10))); + System::assert_last_event(Event::Balances(crate::Event::Reserved(1, 10))); System::set_block_number(3); assert!(Balances::unreserve(&1, 5).is_zero()); - System::assert_last_event(Event::pallet_balances(crate::Event::Unreserved(1, 5))); + System::assert_last_event(Event::Balances(crate::Event::Unreserved(1, 5))); System::set_block_number(4); assert_eq!(Balances::unreserve(&1, 6), 1); // should only unreserve 5 - System::assert_last_event(Event::pallet_balances(crate::Event::Unreserved(1, 5))); + System::assert_last_event(Event::Balances(crate::Event::Unreserved(1, 5))); }); } @@ -709,9 +709,9 @@ macro_rules! decl_tests { assert_eq!( events(), [ - Event::frame_system(system::Event::NewAccount(1)), - Event::pallet_balances(crate::Event::Endowed(1, 100)), - Event::pallet_balances(crate::Event::BalanceSet(1, 100, 0)), + Event::System(system::Event::NewAccount(1)), + Event::Balances(crate::Event::Endowed(1, 100)), + Event::Balances(crate::Event::BalanceSet(1, 100, 0)), ] ); @@ -721,8 +721,8 @@ macro_rules! decl_tests { assert_eq!( events(), [ - Event::frame_system(system::Event::KilledAccount(1)), - Event::pallet_balances(crate::Event::DustLost(1, 99)), + Event::System(system::Event::KilledAccount(1)), + Event::Balances(crate::Event::DustLost(1, 99)), ] ); }); @@ -739,9 +739,9 @@ macro_rules! decl_tests { assert_eq!( events(), [ - Event::frame_system(system::Event::NewAccount(1)), - Event::pallet_balances(crate::Event::Endowed(1, 100)), - Event::pallet_balances(crate::Event::BalanceSet(1, 100, 0)), + Event::System(system::Event::NewAccount(1)), + Event::Balances(crate::Event::Endowed(1, 100)), + Event::Balances(crate::Event::BalanceSet(1, 100, 0)), ] ); @@ -751,7 +751,7 @@ macro_rules! decl_tests { assert_eq!( events(), [ - Event::frame_system(system::Event::KilledAccount(1)) + Event::System(system::Event::KilledAccount(1)) ] ); }); diff --git a/frame/balances/src/tests_local.rs b/frame/balances/src/tests_local.rs index afa68764573e0..e6de7e64b16a2 100644 --- a/frame/balances/src/tests_local.rs +++ b/frame/balances/src/tests_local.rs @@ -172,9 +172,9 @@ fn emit_events_with_no_existential_deposit_suicide_with_dust() { assert_eq!( events(), [ - Event::frame_system(system::Event::NewAccount(1)), - Event::pallet_balances(crate::Event::Endowed(1, 100)), - Event::pallet_balances(crate::Event::BalanceSet(1, 100, 0)), + Event::System(system::Event::NewAccount(1)), + Event::Balances(crate::Event::Endowed(1, 100)), + Event::Balances(crate::Event::BalanceSet(1, 100, 0)), ] ); @@ -190,8 +190,8 @@ fn emit_events_with_no_existential_deposit_suicide_with_dust() { assert_eq!( events(), [ - Event::frame_system(system::Event::KilledAccount(1)), - Event::pallet_balances(crate::Event::DustLost(1, 1)), + Event::System(system::Event::KilledAccount(1)), + Event::Balances(crate::Event::DustLost(1, 1)), ] ); }); diff --git a/frame/balances/src/tests_reentrancy.rs b/frame/balances/src/tests_reentrancy.rs index a12da8f001d80..caca7d78d0ff5 100644 --- a/frame/balances/src/tests_reentrancy.rs +++ b/frame/balances/src/tests_reentrancy.rs @@ -188,8 +188,8 @@ fn transfer_dust_removal_tst1_should_work() { // Number of events expected is 8 assert_eq!(System::events().len(), 11); - System::assert_has_event(Event::pallet_balances(crate::Event::Transfer(2, 3, 450))); - System::assert_has_event(Event::pallet_balances(crate::Event::DustLost(2, 50))); + System::assert_has_event(Event::Balances(crate::Event::Transfer(2, 3, 450))); + System::assert_has_event(Event::Balances(crate::Event::DustLost(2, 50))); } ); } @@ -220,8 +220,8 @@ fn transfer_dust_removal_tst2_should_work() { // Number of events expected is 8 assert_eq!(System::events().len(), 9); - System::assert_has_event(Event::pallet_balances(crate::Event::Transfer(2, 1, 450))); - System::assert_has_event(Event::pallet_balances(crate::Event::DustLost(2, 50))); + System::assert_has_event(Event::Balances(crate::Event::Transfer(2, 1, 450))); + System::assert_has_event(Event::Balances(crate::Event::DustLost(2, 50))); } ); } @@ -261,11 +261,11 @@ fn repatriating_reserved_balance_dust_removal_should_work() { // Number of events expected is 10 assert_eq!(System::events().len(), 10); - System::assert_has_event(Event::pallet_balances( + System::assert_has_event(Event::Balances( crate::Event::ReserveRepatriated(2, 1, 450, Status::Free), )); - System::assert_last_event(Event::pallet_balances(crate::Event::DustLost(2, 50))); + System::assert_last_event(Event::Balances(crate::Event::DustLost(2, 50))); } ); } diff --git a/frame/bounties/src/tests.rs b/frame/bounties/src/tests.rs index 04cc06ef64b8d..3a53ffd56ac1a 100644 --- a/frame/bounties/src/tests.rs +++ b/frame/bounties/src/tests.rs @@ -161,7 +161,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { fn last_event() -> RawEvent { System::events().into_iter().map(|r| r.event) .filter_map(|e| { - if let Event::pallet_bounties(inner) = e { Some(inner) } else { None } + if let Event::Bounties(inner) = e { Some(inner) } else { None } }) .last() .unwrap() diff --git a/frame/collective/src/lib.rs b/frame/collective/src/lib.rs index 76e4106978233..a7039887db606 100644 --- a/frame/collective/src/lib.rs +++ b/frame/collective/src/lib.rs @@ -1059,15 +1059,15 @@ mod tests { pub fn new_test_ext() -> sp_io::TestExternalities { let mut ext: sp_io::TestExternalities = GenesisConfig { - collective_Instance1: collective::GenesisConfig { + collective: collective::GenesisConfig { members: vec![1, 2, 3], phantom: Default::default(), }, - collective_Instance2: collective::GenesisConfig { + collective_majority: collective::GenesisConfig { members: vec![1, 2, 3, 4, 5], phantom: Default::default(), }, - collective: Default::default(), + default_collective: Default::default(), }.build_storage().unwrap().into(); ext.execute_with(|| System::set_block_number(1)); ext @@ -1107,10 +1107,10 @@ mod tests { let record = |event| EventRecord { phase: Phase::Initialization, event, topics: vec![] }; assert_eq!(System::events(), vec![ - record(Event::collective_Instance1(RawEvent::Proposed(1, 0, hash.clone(), 3))), - record(Event::collective_Instance1(RawEvent::Voted(2, hash.clone(), true, 2, 0))), - record(Event::collective_Instance1(RawEvent::Closed(hash.clone(), 2, 1))), - record(Event::collective_Instance1(RawEvent::Disapproved(hash.clone()))) + record(Event::Collective(RawEvent::Proposed(1, 0, hash.clone(), 3))), + record(Event::Collective(RawEvent::Voted(2, hash.clone(), true, 2, 0))), + record(Event::Collective(RawEvent::Closed(hash.clone(), 2, 1))), + record(Event::Collective(RawEvent::Disapproved(hash.clone()))) ]); }); } @@ -1169,10 +1169,10 @@ mod tests { let record = |event| EventRecord { phase: Phase::Initialization, event, topics: vec![] }; assert_eq!(System::events(), vec![ - record(Event::collective_Instance1(RawEvent::Proposed(1, 0, hash.clone(), 3))), - record(Event::collective_Instance1(RawEvent::Voted(2, hash.clone(), true, 2, 0))), - record(Event::collective_Instance1(RawEvent::Closed(hash.clone(), 2, 1))), - record(Event::collective_Instance1(RawEvent::Disapproved(hash.clone()))) + record(Event::Collective(RawEvent::Proposed(1, 0, hash.clone(), 3))), + record(Event::Collective(RawEvent::Voted(2, hash.clone(), true, 2, 0))), + record(Event::Collective(RawEvent::Closed(hash.clone(), 2, 1))), + record(Event::Collective(RawEvent::Disapproved(hash.clone()))) ]); }); } @@ -1194,11 +1194,11 @@ mod tests { let record = |event| EventRecord { phase: Phase::Initialization, event, topics: vec![] }; assert_eq!(System::events(), vec![ - record(Event::collective_Instance1(RawEvent::Proposed(1, 0, hash.clone(), 3))), - record(Event::collective_Instance1(RawEvent::Voted(2, hash.clone(), true, 2, 0))), - record(Event::collective_Instance1(RawEvent::Closed(hash.clone(), 3, 0))), - record(Event::collective_Instance1(RawEvent::Approved(hash.clone()))), - record(Event::collective_Instance1(RawEvent::Executed(hash.clone(), Err(DispatchError::BadOrigin)))) + record(Event::Collective(RawEvent::Proposed(1, 0, hash.clone(), 3))), + record(Event::Collective(RawEvent::Voted(2, hash.clone(), true, 2, 0))), + record(Event::Collective(RawEvent::Closed(hash.clone(), 3, 0))), + record(Event::Collective(RawEvent::Approved(hash.clone()))), + record(Event::Collective(RawEvent::Executed(hash.clone(), Err(DispatchError::BadOrigin)))) ]); }); } @@ -1221,12 +1221,12 @@ mod tests { let record = |event| EventRecord { phase: Phase::Initialization, event, topics: vec![] }; assert_eq!(System::events(), vec![ - record(Event::collective_Instance2(RawEvent::Proposed(1, 0, hash.clone(), 5))), - record(Event::collective_Instance2(RawEvent::Voted(2, hash.clone(), true, 2, 0))), - record(Event::collective_Instance2(RawEvent::Voted(3, hash.clone(), true, 3, 0))), - record(Event::collective_Instance2(RawEvent::Closed(hash.clone(), 5, 0))), - record(Event::collective_Instance2(RawEvent::Approved(hash.clone()))), - record(Event::collective_Instance2(RawEvent::Executed(hash.clone(), Err(DispatchError::BadOrigin)))) + record(Event::CollectiveMajority(RawEvent::Proposed(1, 0, hash.clone(), 5))), + record(Event::CollectiveMajority(RawEvent::Voted(2, hash.clone(), true, 2, 0))), + record(Event::CollectiveMajority(RawEvent::Voted(3, hash.clone(), true, 3, 0))), + record(Event::CollectiveMajority(RawEvent::Closed(hash.clone(), 5, 0))), + record(Event::CollectiveMajority(RawEvent::Approved(hash.clone()))), + record(Event::CollectiveMajority(RawEvent::Executed(hash.clone(), Err(DispatchError::BadOrigin)))) ]); }); } @@ -1321,7 +1321,7 @@ mod tests { assert_eq!(System::events(), vec![ EventRecord { phase: Phase::Initialization, - event: Event::collective_Instance1(RawEvent::Proposed( + event: Event::Collective(RawEvent::Proposed( 1, 0, hex!["68eea8f20b542ec656c6ac2d10435ae3bd1729efc34d1354ab85af840aad2d35"].into(), @@ -1449,7 +1449,7 @@ mod tests { assert_eq!(System::events(), vec![ EventRecord { phase: Phase::Initialization, - event: Event::collective_Instance1(RawEvent::Proposed( + event: Event::Collective(RawEvent::Proposed( 1, 0, hex!["68eea8f20b542ec656c6ac2d10435ae3bd1729efc34d1354ab85af840aad2d35"].into(), @@ -1459,7 +1459,7 @@ mod tests { }, EventRecord { phase: Phase::Initialization, - event: Event::collective_Instance1(RawEvent::Voted( + event: Event::Collective(RawEvent::Voted( 1, hex!["68eea8f20b542ec656c6ac2d10435ae3bd1729efc34d1354ab85af840aad2d35"].into(), false, @@ -1592,7 +1592,7 @@ mod tests { assert_eq!(System::events(), vec![ EventRecord { phase: Phase::Initialization, - event: Event::collective_Instance1( + event: Event::Collective( RawEvent::Proposed( 1, 0, @@ -1603,7 +1603,7 @@ mod tests { }, EventRecord { phase: Phase::Initialization, - event: Event::collective_Instance1(RawEvent::Voted( + event: Event::Collective(RawEvent::Voted( 2, hex!["68eea8f20b542ec656c6ac2d10435ae3bd1729efc34d1354ab85af840aad2d35"].into(), false, @@ -1614,14 +1614,14 @@ mod tests { }, EventRecord { phase: Phase::Initialization, - event: Event::collective_Instance1(RawEvent::Closed( + event: Event::Collective(RawEvent::Closed( hex!["68eea8f20b542ec656c6ac2d10435ae3bd1729efc34d1354ab85af840aad2d35"].into(), 1, 1, )), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::collective_Instance1(RawEvent::Disapproved( + event: Event::Collective(RawEvent::Disapproved( hex!["68eea8f20b542ec656c6ac2d10435ae3bd1729efc34d1354ab85af840aad2d35"].into(), )), topics: vec![], @@ -1644,7 +1644,7 @@ mod tests { assert_eq!(System::events(), vec![ EventRecord { phase: Phase::Initialization, - event: Event::collective_Instance1(RawEvent::Proposed( + event: Event::Collective(RawEvent::Proposed( 1, 0, hex!["68eea8f20b542ec656c6ac2d10435ae3bd1729efc34d1354ab85af840aad2d35"].into(), @@ -1654,7 +1654,7 @@ mod tests { }, EventRecord { phase: Phase::Initialization, - event: Event::collective_Instance1(RawEvent::Voted( + event: Event::Collective(RawEvent::Voted( 2, hex!["68eea8f20b542ec656c6ac2d10435ae3bd1729efc34d1354ab85af840aad2d35"].into(), true, @@ -1665,21 +1665,21 @@ mod tests { }, EventRecord { phase: Phase::Initialization, - event: Event::collective_Instance1(RawEvent::Closed( + event: Event::Collective(RawEvent::Closed( hex!["68eea8f20b542ec656c6ac2d10435ae3bd1729efc34d1354ab85af840aad2d35"].into(), 2, 0, )), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::collective_Instance1(RawEvent::Approved( + event: Event::Collective(RawEvent::Approved( hex!["68eea8f20b542ec656c6ac2d10435ae3bd1729efc34d1354ab85af840aad2d35"].into(), )), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::collective_Instance1(RawEvent::Executed( + event: Event::Collective(RawEvent::Executed( hex!["68eea8f20b542ec656c6ac2d10435ae3bd1729efc34d1354ab85af840aad2d35"].into(), Err(DispatchError::BadOrigin), )), @@ -1731,9 +1731,9 @@ mod tests { assert_ok!(Collective::disapprove_proposal(Origin::root(), hash.clone())); let record = |event| EventRecord { phase: Phase::Initialization, event, topics: vec![] }; assert_eq!(System::events(), vec![ - record(Event::collective_Instance1(RawEvent::Proposed(1, 0, hash.clone(), 2))), - record(Event::collective_Instance1(RawEvent::Voted(2, hash.clone(), true, 2, 0))), - record(Event::collective_Instance1(RawEvent::Disapproved(hash.clone()))), + record(Event::Collective(RawEvent::Proposed(1, 0, hash.clone(), 2))), + record(Event::Collective(RawEvent::Voted(2, hash.clone(), true, 2, 0))), + record(Event::Collective(RawEvent::Disapproved(hash.clone()))), ]); }) } diff --git a/frame/contracts/src/exec.rs b/frame/contracts/src/exec.rs index f3a981347c981..3739ab77e2b6c 100644 --- a/frame/contracts/src/exec.rs +++ b/frame/contracts/src/exec.rs @@ -1357,7 +1357,7 @@ mod tests { >::events() .into_iter() .filter_map(|meta| match meta.event { - MetaEvent::pallet_contracts(contract_event) => Some(contract_event), + MetaEvent::Contracts(contract_event) => Some(contract_event), _ => None, }) .collect() diff --git a/frame/contracts/src/tests.rs b/frame/contracts/src/tests.rs index 75ea8d9bd89b6..e066a369af0be 100644 --- a/frame/contracts/src/tests.rs +++ b/frame/contracts/src/tests.rs @@ -481,50 +481,50 @@ fn instantiate_and_call_and_deposit_event() { assert_eq!(System::events(), vec![ EventRecord { phase: Phase::Initialization, - event: Event::frame_system(frame_system::Event::NewAccount(ALICE.clone())), + event: Event::System(frame_system::Event::NewAccount(ALICE.clone())), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::pallet_balances( + event: Event::Balances( pallet_balances::Event::Endowed(ALICE, 1_000_000) ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::frame_system(frame_system::Event::NewAccount(addr.clone())), + event: Event::System(frame_system::Event::NewAccount(addr.clone())), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::pallet_balances( + event: Event::Balances( pallet_balances::Event::Endowed(addr.clone(), subsistence * 100) ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::pallet_balances( + event: Event::Balances( pallet_balances::Event::Transfer(ALICE, addr.clone(), subsistence * 100) ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::pallet_contracts(crate::Event::CodeStored(code_hash.into())), + event: Event::Contracts(crate::Event::CodeStored(code_hash.into())), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::pallet_contracts( + event: Event::Contracts( crate::Event::ContractEmitted(addr.clone(), vec![1, 2, 3, 4]) ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::pallet_contracts(crate::Event::Instantiated(ALICE, addr.clone())), + event: Event::Contracts(crate::Event::Instantiated(ALICE, addr.clone())), topics: vec![], }, ]); @@ -1210,45 +1210,45 @@ fn restoration( let mut events = vec![ EventRecord { phase: Phase::Initialization, - event: Event::frame_system(frame_system::Event::NewAccount(ALICE)), + event: Event::System(frame_system::Event::NewAccount(ALICE)), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::pallet_balances( + event: Event::Balances( pallet_balances::Event::Endowed(ALICE, 1_000_000) ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::frame_system(frame_system::Event::NewAccount(addr_bob.clone())), + event: Event::System(frame_system::Event::NewAccount(addr_bob.clone())), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::pallet_balances( + event: Event::Balances( pallet_balances::Event::Endowed(addr_bob.clone(), 30_000) ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::pallet_balances( + event: Event::Balances( pallet_balances::Event::Transfer(ALICE, addr_bob.clone(), 30_000) ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::pallet_contracts( + event: Event::Contracts( crate::Event::CodeStored(set_rent_code_hash.into()) ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::pallet_contracts( + event: Event::Contracts( crate::Event::Instantiated(ALICE, addr_bob.clone()) ), topics: vec![], @@ -1271,26 +1271,26 @@ fn restoration( events.extend([ EventRecord { phase: Phase::Initialization, - event: Event::frame_system(frame_system::Event::NewAccount(addr_dummy.clone())), + event: Event::System(frame_system::Event::NewAccount(addr_dummy.clone())), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::pallet_balances( + event: Event::Balances( pallet_balances::Event::Endowed(addr_dummy.clone(), 20_000) ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::pallet_balances( + event: Event::Balances( pallet_balances::Event::Transfer(ALICE, addr_dummy.clone(), 20_000) ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::pallet_contracts( + event: Event::Contracts( crate::Event::Instantiated(ALICE, addr_dummy.clone()) ), topics: vec![], @@ -1418,46 +1418,46 @@ fn restoration( assert_eq!(System::events(), vec![ EventRecord { phase: Phase::Initialization, - event: Event::pallet_contracts(crate::Event::Evicted(addr_bob)), + event: Event::Contracts(crate::Event::Evicted(addr_bob)), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::frame_system(frame_system::Event::NewAccount(CHARLIE)), + event: Event::System(frame_system::Event::NewAccount(CHARLIE)), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::pallet_balances(pallet_balances::Event::Endowed(CHARLIE, 1_000_000)), + event: Event::Balances(pallet_balances::Event::Endowed(CHARLIE, 1_000_000)), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::frame_system(frame_system::Event::NewAccount(addr_django.clone())), + event: Event::System(frame_system::Event::NewAccount(addr_django.clone())), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::pallet_balances(pallet_balances::Event::Endowed(addr_django.clone(), 30_000)), + event: Event::Balances(pallet_balances::Event::Endowed(addr_django.clone(), 30_000)), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::pallet_balances( + event: Event::Balances( pallet_balances::Event::Transfer(CHARLIE, addr_django.clone(), 30_000) ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::pallet_contracts( + event: Event::Contracts( crate::Event::CodeStored(restoration_code_hash) ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::pallet_contracts( + event: Event::Contracts( crate::Event::Instantiated(CHARLIE, addr_django.clone()) ), topics: vec![], @@ -1491,17 +1491,17 @@ fn restoration( assert_eq!(System::events(), vec![ EventRecord { phase: Phase::Initialization, - event: Event::pallet_contracts(crate::Event::CodeRemoved(restoration_code_hash)), + event: Event::Contracts(crate::Event::CodeRemoved(restoration_code_hash)), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::frame_system(system::Event::KilledAccount(addr_django.clone())), + event: Event::System(system::Event::KilledAccount(addr_django.clone())), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::pallet_contracts( + event: Event::Contracts( crate::Event::Restored( addr_django, addr_bob, bob_contract.code_hash, 50 ) @@ -1729,26 +1729,26 @@ fn self_destruct_works() { pretty_assertions::assert_eq!(System::events(), vec![ EventRecord { phase: Phase::Initialization, - event: Event::frame_system( + event: Event::System( frame_system::Event::KilledAccount(addr.clone()) ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::pallet_balances( + event: Event::Balances( pallet_balances::Event::Transfer(addr.clone(), DJANGO, 93_086) ), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::pallet_contracts(crate::Event::CodeRemoved(code_hash)), + event: Event::Contracts(crate::Event::CodeRemoved(code_hash)), topics: vec![], }, EventRecord { phase: Phase::Initialization, - event: Event::pallet_contracts( + event: Event::Contracts( crate::Event::Terminated(addr.clone(), DJANGO) ), topics: vec![], diff --git a/frame/election-provider-multi-phase/src/mock.rs b/frame/election-provider-multi-phase/src/mock.rs index 830df099b5d08..bd035aaf82969 100644 --- a/frame/election-provider-multi-phase/src/mock.rs +++ b/frame/election-provider-multi-phase/src/mock.rs @@ -75,7 +75,7 @@ pub(crate) fn multi_phase_events() -> Vec> { System::events() .into_iter() .map(|r| r.event) - .filter_map(|e| if let Event::multi_phase(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 ab2edfaac6c29..556c57eea5a10 100644 --- a/frame/elections-phragmen/src/lib.rs +++ b/frame/elections-phragmen/src/lib.rs @@ -1308,7 +1308,7 @@ mod tests { pub fn build_and_execute(self, test: impl FnOnce() -> ()) { MEMBERS.with(|m| *m.borrow_mut() = self.genesis_members.iter().map(|(m, _)| m.clone()).collect::>()); let mut ext: sp_io::TestExternalities = GenesisConfig { - pallet_balances: pallet_balances::GenesisConfig::{ + balances: pallet_balances::GenesisConfig::{ balances: vec![ (1, 10 * self.balance_factor), (2, 20 * self.balance_factor), @@ -1318,7 +1318,7 @@ mod tests { (6, 60 * self.balance_factor) ], }, - elections_phragmen: elections_phragmen::GenesisConfig:: { + elections: elections_phragmen::GenesisConfig:: { members: self.genesis_members }, }.build_storage().unwrap().into(); @@ -2134,7 +2134,7 @@ mod tests { System::set_block_number(5); Elections::on_initialize(System::block_number()); - System::assert_last_event(Event::elections_phragmen(super::Event::EmptyTerm)); + System::assert_last_event(Event::Elections(super::Event::EmptyTerm)); }) } @@ -2150,7 +2150,7 @@ mod tests { System::set_block_number(5); Elections::on_initialize(System::block_number()); - System::assert_last_event(Event::elections_phragmen(super::Event::NewTerm(vec![(4, 40), (5, 50)]))); + System::assert_last_event(Event::Elections(super::Event::NewTerm(vec![(4, 40), (5, 50)]))); assert_eq!(members_and_stake(), vec![(4, 40), (5, 50)]); assert_eq!(runners_up_and_stake(), vec![]); @@ -2161,7 +2161,7 @@ mod tests { System::set_block_number(10); Elections::on_initialize(System::block_number()); - System::assert_last_event(Event::elections_phragmen(super::Event::NewTerm(vec![]))); + System::assert_last_event(Event::Elections(super::Event::NewTerm(vec![]))); // outgoing have lost their bond. assert_eq!(balances(&4), (37, 0)); @@ -2231,7 +2231,7 @@ mod tests { assert_eq!(Elections::election_rounds(), 1); assert!(members_ids().is_empty()); - System::assert_last_event(Event::elections_phragmen(super::Event::NewTerm(vec![]))); + System::assert_last_event(Event::Elections(super::Event::NewTerm(vec![]))); }); } @@ -2589,7 +2589,7 @@ mod tests { // 5 is an outgoing loser. will also get slashed. assert_eq!(balances(&5), (45, 2)); - System::assert_has_event(Event::elections_phragmen(super::Event::NewTerm(vec![(4, 40), (5, 50)]))); + System::assert_has_event(Event::Elections(super::Event::NewTerm(vec![(4, 40), (5, 50)]))); }) } diff --git a/frame/elections/src/mock.rs b/frame/elections/src/mock.rs index b5dd15ce8119b..bb67622eb7ea1 100644 --- a/frame/elections/src/mock.rs +++ b/frame/elections/src/mock.rs @@ -197,7 +197,7 @@ impl ExtBuilder { PRESENT_SLASH_PER_VOTER.with(|v| *v.borrow_mut() = self.bad_presentation_punishment); DECAY_RATIO.with(|v| *v.borrow_mut() = self.decay_ratio); let mut ext: sp_io::TestExternalities = GenesisConfig { - pallet_balances: pallet_balances::GenesisConfig::{ + balances: pallet_balances::GenesisConfig::{ balances: vec![ (1, 10 * self.balance_factor), (2, 20 * self.balance_factor), diff --git a/frame/example/src/tests.rs b/frame/example/src/tests.rs index f4658c2807647..a290ea0f6576f 100644 --- a/frame/example/src/tests.rs +++ b/frame/example/src/tests.rs @@ -107,9 +107,9 @@ impl Config for Test { pub fn new_test_ext() -> sp_io::TestExternalities { let t = GenesisConfig { // We use default for brevity, but you can configure as desired if needed. - frame_system: Default::default(), - pallet_balances: Default::default(), - pallet_example: pallet_example::GenesisConfig { + system: Default::default(), + balances: Default::default(), + example: pallet_example::GenesisConfig { dummy: 42, // we configure the map with (key, value) pairs. bar: vec![(1, 2), (2, 3)], diff --git a/frame/offences/src/tests.rs b/frame/offences/src/tests.rs index f7bd90fe93e62..edc22cb239c44 100644 --- a/frame/offences/src/tests.rs +++ b/frame/offences/src/tests.rs @@ -131,7 +131,7 @@ fn should_deposit_event() { System::events(), vec![EventRecord { phase: Phase::Initialization, - event: Event::offences(crate::Event::Offence(KIND, time_slot.encode())), + event: Event::Offences(crate::Event::Offence(KIND, time_slot.encode())), topics: vec![], }] ); @@ -166,7 +166,7 @@ fn doesnt_deposit_event_for_dups() { System::events(), vec![EventRecord { phase: Phase::Initialization, - event: Event::offences(crate::Event::Offence(KIND, time_slot.encode())), + event: Event::Offences(crate::Event::Offence(KIND, time_slot.encode())), topics: vec![], }] ); diff --git a/frame/staking/src/mock.rs b/frame/staking/src/mock.rs index 8930a6bfd61c8..b4ff35d0d6f90 100644 --- a/frame/staking/src/mock.rs +++ b/frame/staking/src/mock.rs @@ -794,7 +794,7 @@ macro_rules! assert_session_era { pub(crate) fn staking_events() -> Vec> { System::events().into_iter().map(|r| r.event).filter_map(|e| { - if let Event::staking(inner) = e { + if let Event::Staking(inner) = e { Some(inner) } else { None diff --git a/frame/sudo/src/tests.rs b/frame/sudo/src/tests.rs index 2f824ae6a3946..aa859c547c039 100644 --- a/frame/sudo/src/tests.rs +++ b/frame/sudo/src/tests.rs @@ -58,7 +58,7 @@ fn sudo_emits_events_correctly() { // Should emit event to indicate success when called with the root `key` and `call` is `Ok`. let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log(42, 1))); assert_ok!(Sudo::sudo(Origin::signed(1), call)); - System::assert_has_event(TestEvent::sudo(Event::Sudid(Ok(())))); + System::assert_has_event(TestEvent::Sudo(Event::Sudid(Ok(())))); }) } @@ -96,7 +96,7 @@ fn sudo_unchecked_weight_emits_events_correctly() { // Should emit event to indicate success when called with the root `key` and `call` is `Ok`. let call = Box::new(Call::Logger(LoggerCall::privileged_i32_log(42, 1))); assert_ok!(Sudo::sudo_unchecked_weight(Origin::signed(1), call, 1_000)); - System::assert_has_event(TestEvent::sudo(Event::Sudid(Ok(())))); + System::assert_has_event(TestEvent::Sudo(Event::Sudid(Ok(())))); }) } @@ -122,10 +122,10 @@ fn set_key_emits_events_correctly() { // A root `key` can change the root `key`. assert_ok!(Sudo::set_key(Origin::signed(1), 2)); - System::assert_has_event(TestEvent::sudo(Event::KeyChanged(1))); + System::assert_has_event(TestEvent::Sudo(Event::KeyChanged(1))); // Double check. assert_ok!(Sudo::set_key(Origin::signed(2), 4)); - System::assert_has_event(TestEvent::sudo(Event::KeyChanged(2))); + System::assert_has_event(TestEvent::Sudo(Event::KeyChanged(2))); }); } @@ -160,6 +160,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(42, 1))); assert_ok!(Sudo::sudo_as(Origin::signed(1), 2, call)); - System::assert_has_event(TestEvent::sudo(Event::SudoAsDone(Ok(())))); + System::assert_has_event(TestEvent::Sudo(Event::SudoAsDone(Ok(())))); }); } diff --git a/frame/support/procedural/src/construct_runtime/expand/config.rs b/frame/support/procedural/src/construct_runtime/expand/config.rs index 93d4a868b7847..0400bd52f433a 100644 --- a/frame/support/procedural/src/construct_runtime/expand/config.rs +++ b/frame/support/procedural/src/construct_runtime/expand/config.rs @@ -16,6 +16,7 @@ // limitations under the License use crate::construct_runtime::Pallet; +use inflector::Inflector; use proc_macro2::TokenStream; use quote::{format_ident, quote}; use syn::Ident; @@ -32,12 +33,8 @@ pub fn expand_outer_config( for decl in pallet_decls { if let Some(pallet_entry) = decl.find_part("Config") { let config = format_ident!("{}Config", decl.name); - let mod_name = decl.pallet.mod_name(); - let field_name = if let Some(inst) = decl.instance.as_ref() { - format_ident!("{}_{}", mod_name, inst) - } else { - mod_name - }; + let pallet_name = &decl.name.to_string().to_snake_case(); + let field_name = &Ident::new(pallet_name, decl.name.span()); let part_is_generic = !pallet_entry.generics.params.is_empty(); types.extend(expand_config_types(runtime, decl, &config, part_is_generic)); @@ -56,7 +53,6 @@ pub fn expand_outer_config( #[serde(rename_all = "camelCase")] #[serde(deny_unknown_fields)] #[serde(crate = "__genesis_config_serde_import__")] - #[allow(non_snake_case)] pub struct GenesisConfig { #fields } @@ -85,7 +81,7 @@ fn expand_config_types( config: &Ident, part_is_generic: bool, ) -> TokenStream { - let path = &decl.pallet; + let path = &decl.path; match (decl.instance.as_ref(), part_is_generic) { (Some(inst), true) => quote!{ @@ -109,7 +105,7 @@ fn expand_config_build_storage_call( decl: &Pallet, field_name: &Ident, ) -> TokenStream { - let path = &decl.pallet; + let path = &decl.path; let instance = if let Some(inst) = decl.instance.as_ref() { quote!(#path::#inst) } else { diff --git a/frame/support/procedural/src/construct_runtime/expand/event.rs b/frame/support/procedural/src/construct_runtime/expand/event.rs index c2c905e50ff8d..afedb3ed92508 100644 --- a/frame/support/procedural/src/construct_runtime/expand/event.rs +++ b/frame/support/procedural/src/construct_runtime/expand/event.rs @@ -15,9 +15,9 @@ // See the License for the specific language governing permissions and // limitations under the License -use crate::construct_runtime::{Pallet, parse::PalletPath}; +use crate::construct_runtime::Pallet; use proc_macro2::TokenStream; -use quote::{format_ident, quote}; +use quote::quote; use syn::{Generics, Ident}; pub fn expand_outer_event( @@ -27,11 +27,10 @@ pub fn expand_outer_event( ) -> syn::Result { let mut event_variants = TokenStream::new(); let mut event_conversions = TokenStream::new(); - let mut events_metadata = TokenStream::new(); for pallet_decl in pallet_decls { if let Some(pallet_entry) = pallet_decl.find_part("Event") { - let path = &pallet_decl.pallet; + let path = &pallet_decl.path; let index = pallet_decl.index; let instance = pallet_decl.instance.as_ref(); let generics = &pallet_entry.generics; @@ -53,9 +52,8 @@ pub fn expand_outer_event( (None, false) => quote!(#path::Event), }; - event_variants.extend(expand_event_variant(runtime, path, index, instance, generics)); - event_conversions.extend(expand_event_conversion(scrate, path, instance, &pallet_event)); - events_metadata.extend(expand_event_metadata(scrate, path, &pallet_event)); + event_variants.extend(expand_event_variant(runtime, pallet_decl, index, instance, generics)); + event_conversions.extend(expand_event_conversion(scrate, pallet_decl, &pallet_event)); } } @@ -77,49 +75,42 @@ pub fn expand_outer_event( fn expand_event_variant( runtime: &Ident, - path: &PalletPath, + pallet: &Pallet, index: u8, instance: Option<&Ident>, generics: &Generics, ) -> TokenStream { + let path = &pallet.path; + let variant_name = &pallet.name; let part_is_generic = !generics.params.is_empty(); - let mod_name = &path.mod_name(); - match (instance, part_is_generic) { - (Some(inst), true) => { - let variant = format_ident!("{}_{}", mod_name, inst); - quote!(#[codec(index = #index)] #variant(#path::Event<#runtime, #path::#inst>),) + match instance { + Some(inst) if part_is_generic => { + quote!(#[codec(index = #index)] #variant_name(#path::Event<#runtime, #path::#inst>),) } - (Some(inst), false) => { - let variant = format_ident!("{}_{}", mod_name, inst); - quote!(#[codec(index = #index)] #variant(#path::Event<#path::#inst>),) + Some(inst) => { + quote!(#[codec(index = #index)] #variant_name(#path::Event<#path::#inst>),) } - (None, true) => { - quote!(#[codec(index = #index)] #mod_name(#path::Event<#runtime>),) + None if part_is_generic => { + quote!(#[codec(index = #index)] #variant_name(#path::Event<#runtime>),) } - (None, false) => { - quote!(#[codec(index = #index)] #mod_name(#path::Event),) + None => { + quote!(#[codec(index = #index)] #variant_name(#path::Event),) } } } fn expand_event_conversion( scrate: &TokenStream, - path: &PalletPath, - instance: Option<&Ident>, + pallet: &Pallet, pallet_event: &TokenStream, ) -> TokenStream { - let mod_name = path.mod_name(); - let variant = if let Some(inst) = instance { - format_ident!("{}_{}", mod_name, inst) - } else { - mod_name - }; + let variant_name = &pallet.name; quote!{ impl From<#pallet_event> for Event { fn from(x: #pallet_event) -> Self { - Event::#variant(x) + Event::#variant_name(x) } } impl #scrate::sp_std::convert::TryInto<#pallet_event> for Event { @@ -127,20 +118,10 @@ fn expand_event_conversion( fn try_into(self) -> #scrate::sp_std::result::Result<#pallet_event, Self::Error> { match self { - Self::#variant(evt) => Ok(evt), + Self::#variant_name(evt) => Ok(evt), _ => Err(()), } } } } } - -fn expand_event_metadata( - scrate: &TokenStream, - path: &PalletPath, - pallet_event: &TokenStream, -) -> TokenStream { - let mod_name = path.mod_name(); - - quote!{(stringify!(#mod_name), #scrate::event::FnEncode(#pallet_event::metadata)),} -} diff --git a/frame/support/procedural/src/construct_runtime/expand/metadata.rs b/frame/support/procedural/src/construct_runtime/expand/metadata.rs index cbabec73d3a6f..5854d0edccabb 100644 --- a/frame/support/procedural/src/construct_runtime/expand/metadata.rs +++ b/frame/support/procedural/src/construct_runtime/expand/metadata.rs @@ -92,7 +92,7 @@ fn expand_pallet_metadata_storage( ) -> TokenStream { if filtered_names.contains(&"Storage") { let instance = decl.instance.as_ref().into_iter(); - let path = &decl.pallet; + let path = &decl.path; quote!{ Some(#scrate::metadata::DecodeDifferent::Encode( @@ -114,7 +114,7 @@ fn expand_pallet_metadata_calls( ) -> TokenStream { if filtered_names.contains(&"Call") { let instance = decl.instance.as_ref().into_iter(); - let path = &decl.pallet; + let path = &decl.path; quote!{ Some(#scrate::metadata::DecodeDifferent::Encode( @@ -135,7 +135,7 @@ fn expand_pallet_metadata_events( decl: &Pallet, ) -> TokenStream { if filtered_names.contains(&"Event") { - let path = &decl.pallet; + let path = &decl.path; let part_is_generic = !decl.find_part("Event").expect("Event part exists; qed").generics.params.is_empty(); let pallet_event = match (decl.instance.as_ref(), part_is_generic) { @@ -160,7 +160,7 @@ fn expand_pallet_metadata_constants( scrate: &TokenStream, decl: &Pallet, ) -> TokenStream { - let path = &decl.pallet; + let path = &decl.path; let instance = decl.instance.as_ref().into_iter(); quote!{ @@ -177,7 +177,7 @@ fn expand_pallet_metadata_errors( scrate: &TokenStream, decl: &Pallet, ) -> TokenStream { - let path = &decl.pallet; + let path = &decl.path; let instance = decl.instance.as_ref().into_iter(); quote!{ diff --git a/frame/support/procedural/src/construct_runtime/expand/origin.rs b/frame/support/procedural/src/construct_runtime/expand/origin.rs index 021396e64caa8..2d0cc8300cb76 100644 --- a/frame/support/procedural/src/construct_runtime/expand/origin.rs +++ b/frame/support/procedural/src/construct_runtime/expand/origin.rs @@ -15,9 +15,9 @@ // See the License for the specific language governing permissions and // limitations under the License -use crate::construct_runtime::{parse::PalletPath, Pallet, SYSTEM_PALLET_NAME}; +use crate::construct_runtime::{Pallet, SYSTEM_PALLET_NAME}; use proc_macro2::TokenStream; -use quote::{format_ident, quote}; +use quote::quote; use syn::{token, Ident, Generics}; pub fn expand_outer_origin( @@ -39,7 +39,6 @@ pub fn expand_outer_origin( for pallet_decl in pallets.iter().filter(|pallet| pallet.name != SYSTEM_PALLET_NAME) { if let Some(pallet_entry) = pallet_decl.find_part("Origin") { - let path = &pallet_decl.pallet; let instance = pallet_decl.instance.as_ref(); let index = pallet_decl.index; let generics = &pallet_entry.generics; @@ -54,15 +53,15 @@ pub fn expand_outer_origin( } caller_variants.extend( - expand_origin_caller_variant(runtime, path, index, instance, generics), + expand_origin_caller_variant(runtime, pallet_decl, index, instance, generics), ); pallet_conversions.extend( - expand_origin_pallet_conversions(scrate, runtime, path, instance, generics), + expand_origin_pallet_conversions(scrate, runtime, pallet_decl, instance, generics), ); } } - let system_path = &system_pallet.pallet; + let system_path = &system_pallet.path; let system_index = system_pallet.index; Ok(quote!{ @@ -251,28 +250,27 @@ pub fn expand_outer_origin( fn expand_origin_caller_variant( runtime: &Ident, - path: &PalletPath, + pallet: &Pallet, index: u8, instance: Option<&Ident>, generics: &Generics, ) -> TokenStream { let part_is_generic = !generics.params.is_empty(); - let mod_name = &path.mod_name(); + let variant_name = &pallet.name; + let path = &pallet.path; - match (instance, part_is_generic) { - (Some(inst), true) => { - let variant = format_ident!("{}_{}", mod_name, inst); - quote!(#[codec(index = #index)] #variant(#path::Origin<#runtime, #path::#inst>),) + match instance { + Some(inst) if part_is_generic => { + quote!(#[codec(index = #index)] #variant_name(#path::Origin<#runtime, #path::#inst>),) } - (Some(inst), false) => { - let variant = format_ident!("{}_{}", mod_name, inst); - quote!(#[codec(index = #index)] #variant(#path::Origin<#path::#inst>),) + Some(inst) => { + quote!(#[codec(index = #index)] #variant_name(#path::Origin<#path::#inst>),) } - (None, true) => { - quote!(#[codec(index = #index)] #mod_name(#path::Origin<#runtime>),) + None if part_is_generic => { + quote!(#[codec(index = #index)] #variant_name(#path::Origin<#runtime>),) } - (None, false) => { - quote!(#[codec(index = #index)] #mod_name(#path::Origin),) + None => { + quote!(#[codec(index = #index)] #variant_name(#path::Origin),) } } } @@ -280,29 +278,25 @@ fn expand_origin_caller_variant( fn expand_origin_pallet_conversions( scrate: &TokenStream, runtime: &Ident, - path: &PalletPath, + pallet: &Pallet, instance: Option<&Ident>, generics: &Generics, ) -> TokenStream { - let mod_name = path.mod_name(); - let variant = if let Some(inst) = instance { - format_ident!("{}_{}", mod_name, inst) - } else { - mod_name - }; + let path = &pallet.path; + let variant_name = &pallet.name; let part_is_generic = !generics.params.is_empty(); - let pallet_origin = match (instance, part_is_generic) { - (Some(inst), true) => quote!(#path::Origin<#runtime, #path::#inst>), - (Some(inst), false) => quote!(#path::Origin<#path::#inst>), - (None, true) => quote!(#path::Origin<#runtime>), - (None, false) => quote!(#path::Origin), + let pallet_origin = match instance { + Some(inst) if part_is_generic => quote!(#path::Origin<#runtime, #path::#inst>), + Some(inst) => quote!(#path::Origin<#path::#inst>), + None if part_is_generic => quote!(#path::Origin<#runtime>), + None => quote!(#path::Origin), }; quote!{ impl From<#pallet_origin> for OriginCaller { fn from(x: #pallet_origin) -> Self { - OriginCaller::#variant(x) + OriginCaller::#variant_name(x) } } @@ -317,7 +311,7 @@ fn expand_origin_pallet_conversions( impl From for #scrate::sp_std::result::Result<#pallet_origin, Origin> { /// NOTE: converting to pallet origin loses the origin filter information. fn from(val: Origin) -> Self { - if let OriginCaller::#variant(l) = val.caller { + if let OriginCaller::#variant_name(l) = val.caller { Ok(l) } else { Err(val) @@ -330,7 +324,7 @@ fn expand_origin_pallet_conversions( fn try_from( x: OriginCaller, ) -> #scrate::sp_std::result::Result<#pallet_origin, OriginCaller> { - if let OriginCaller::#variant(l) = x { + if let OriginCaller::#variant_name(l) = x { Ok(l) } else { Err(x) diff --git a/frame/support/procedural/src/construct_runtime/mod.rs b/frame/support/procedural/src/construct_runtime/mod.rs index a24168c463aa7..eb3550355aa40 100644 --- a/frame/support/procedural/src/construct_runtime/mod.rs +++ b/frame/support/procedural/src/construct_runtime/mod.rs @@ -35,7 +35,7 @@ const SYSTEM_PALLET_NAME: &str = "System"; pub struct Pallet { pub name: Ident, pub index: u8, - pub pallet: PalletPath, + pub path: PalletPath, pub instance: Option, pub pallet_parts: Vec, } @@ -101,7 +101,7 @@ fn complete_pallets(decl: impl Iterator) -> syn::Resul Ok(Pallet { name: pallet.name, index: final_index, - pallet: pallet.pallet, + path: pallet.path, instance: pallet.instance, pallet_parts: pallet.pallet_parts, }) @@ -252,7 +252,7 @@ fn decl_outer_dispatch<'a>( let pallets_tokens = pallet_declarations .filter(|pallet_declaration| pallet_declaration.exists_part("Call")) .map(|pallet_declaration| { - let pallet = &pallet_declaration.pallet.inner.segments.last().unwrap(); + let pallet = &pallet_declaration.path.inner.segments.last().unwrap(); let name = &pallet_declaration.name; let index = pallet_declaration.index; quote!(#[codec(index = #index)] #pallet::#name) @@ -275,7 +275,7 @@ fn decl_all_pallets<'a>( let mut names = Vec::new(); for pallet_declaration in pallet_declarations { let type_name = &pallet_declaration.name; - let pallet = &pallet_declaration.pallet; + let pallet = &pallet_declaration.path; let mut generics = vec![quote!(#runtime)]; generics.extend( pallet_declaration diff --git a/frame/support/procedural/src/construct_runtime/parse.rs b/frame/support/procedural/src/construct_runtime/parse.rs index 390729865e98d..2d242749cfe01 100644 --- a/frame/support/procedural/src/construct_runtime/parse.rs +++ b/frame/support/procedural/src/construct_runtime/parse.rs @@ -156,7 +156,7 @@ pub struct PalletDeclaration { pub name: Ident, /// Optional fixed index (e.g. `MyPallet ... = 3,`) pub index: Option, - pub pallet: PalletPath, + pub path: PalletPath, pub instance: Option, pub pallet_parts: Vec, } @@ -165,7 +165,7 @@ impl Parse for PalletDeclaration { fn parse(input: ParseStream) -> Result { let name = input.parse()?; let _: Token![:] = input.parse()?; - let pallet = input.parse()?; + let path = input.parse()?; let instance = if input.peek(Token![<]) { let _: Token![<] = input.parse()?; let res = Some(input.parse()?); @@ -189,7 +189,7 @@ impl Parse for PalletDeclaration { let parsed = Self { name, - pallet, + path, instance, pallet_parts, index, @@ -247,30 +247,6 @@ impl Parse for PalletPath { } } -impl PalletPath { - /// Return the snake-cased module name for this path. - pub fn mod_name(&self) -> Ident { - let mut iter = self.inner.segments.iter(); - let mut mod_name = match &iter.next().expect("Path should always have 1 segment; qed").ident { - ident if ident == "self" || ident == "super" || ident == "crate" => { - // Skip `crate`, `self` and `super` quasi-keywords when creating the module name - iter.next() - .expect("There must be a path segment pointing to a pallet following \ - `crate`, `self` or `super`; qed") - .ident - .clone() - } - ident => ident.clone(), - }; - - for segment in iter { - mod_name = quote::format_ident!("{}_{}", mod_name, segment.ident); - } - - mod_name - } -} - impl quote::ToTokens for PalletPath { fn to_tokens(&self, tokens: &mut TokenStream) { self.inner.to_tokens(tokens); diff --git a/frame/support/test/tests/construct_runtime.rs b/frame/support/test/tests/construct_runtime.rs index 6b0a7091edff9..7858595108b0e 100644 --- a/frame/support/test/tests/construct_runtime.rs +++ b/frame/support/test/tests/construct_runtime.rs @@ -383,31 +383,31 @@ fn origin_codec() { let origin = OriginCaller::system(system::RawOrigin::None); assert_eq!(origin.encode()[0], 30); - let origin = OriginCaller::module1_Instance1(module1::Origin(Default::default())); + let origin = OriginCaller::Module1_1(module1::Origin(Default::default())); assert_eq!(origin.encode()[0], 31); - let origin = OriginCaller::module2(module2::Origin); + let origin = OriginCaller::Module2(module2::Origin); assert_eq!(origin.encode()[0], 32); - let origin = OriginCaller::module1_Instance2(module1::Origin(Default::default())); + let origin = OriginCaller::Module1_2(module1::Origin(Default::default())); assert_eq!(origin.encode()[0], 33); - let origin = OriginCaller::nested_module3(nested::module3::Origin); + let origin = OriginCaller::NestedModule3(nested::module3::Origin); assert_eq!(origin.encode()[0], 34); - let origin = OriginCaller::module3(module3::Origin(Default::default())); + let origin = OriginCaller::Module3(module3::Origin(Default::default())); assert_eq!(origin.encode()[0], 35); - let origin = OriginCaller::module1_Instance6(module1::Origin(Default::default())); + let origin = OriginCaller::Module1_6(module1::Origin(Default::default())); assert_eq!(origin.encode()[0], 1); - let origin = OriginCaller::module1_Instance7(module1::Origin(Default::default())); + let origin = OriginCaller::Module1_7(module1::Origin(Default::default())); assert_eq!(origin.encode()[0], 2); - let origin = OriginCaller::module1_Instance8(module1::Origin(Default::default())); + let origin = OriginCaller::Module1_8(module1::Origin(Default::default())); assert_eq!(origin.encode()[0], 12); - let origin = OriginCaller::module1_Instance9(module1::Origin(Default::default())); + let origin = OriginCaller::Module1_9(module1::Origin(Default::default())); assert_eq!(origin.encode()[0], 13); } diff --git a/frame/support/test/tests/instance.rs b/frame/support/test/tests/instance.rs index 077763ac9128d..d952fd82eb0df 100644 --- a/frame/support/test/tests/instance.rs +++ b/frame/support/test/tests/instance.rs @@ -299,26 +299,26 @@ pub type UncheckedExtrinsic = generic::UncheckedExtrinsic sp_io::TestExternalities { GenesisConfig{ - module1_Instance1: module1::GenesisConfig { + module_1_1: module1::GenesisConfig { value: 3, test: 2, }, - module1_Instance2: module1::GenesisConfig { + module_1_2: module1::GenesisConfig { value: 4, test: 5, }, - module2: module2::GenesisConfig { + module_2: module2::GenesisConfig { value: 4, map: vec![(0, 0)], double_map: vec![(0, 0, 0)], }, - module2_Instance1: module2::GenesisConfig { + module_2_1: module2::GenesisConfig { value: 4, map: vec![(0, 0)], double_map: vec![(0, 0, 0)], }, - module2_Instance2: Default::default(), - module2_Instance3: Default::default(), + module_2_2: Default::default(), + module_2_3: Default::default(), }.build_storage().unwrap().into() } diff --git a/frame/support/test/tests/pallet.rs b/frame/support/test/tests/pallet.rs index 7478da189df07..f7e04e9226874 100644 --- a/frame/support/test/tests/pallet.rs +++ b/frame/support/test/tests/pallet.rs @@ -485,7 +485,7 @@ fn transactional_works() { pallet::Call::::foo_transactional(1).dispatch_bypass_filter(None.into()).unwrap(); assert_eq!( frame_system::Pallet::::events().iter().map(|e| &e.event).collect::>(), - vec![&Event::pallet(pallet::Event::Something(0))], + vec![&Event::Example(pallet::Event::Something(0))], ); }) } @@ -550,7 +550,7 @@ fn pallet_expand_deposit_event() { pallet::Call::::foo(3, 0).dispatch_bypass_filter(None.into()).unwrap(); assert_eq!( frame_system::Pallet::::events()[0].event, - Event::pallet(pallet::Event::Something(3)), + Event::Example(pallet::Event::Something(3)), ); }) } @@ -643,15 +643,15 @@ fn pallet_hooks_expand() { assert_eq!( frame_system::Pallet::::events()[0].event, - Event::pallet(pallet::Event::Something(10)), + Event::Example(pallet::Event::Something(10)), ); assert_eq!( frame_system::Pallet::::events()[1].event, - Event::pallet(pallet::Event::Something(20)), + Event::Example(pallet::Event::Something(20)), ); assert_eq!( frame_system::Pallet::::events()[2].event, - Event::pallet(pallet::Event::Something(30)), + 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 846a96a237c95..48ff166c5b226 100644 --- a/frame/support/test/tests/pallet_instance.rs +++ b/frame/support/test/tests/pallet_instance.rs @@ -394,7 +394,7 @@ fn pallet_expand_deposit_event() { pallet::Call::::foo(3).dispatch_bypass_filter(None.into()).unwrap(); assert_eq!( frame_system::Pallet::::events()[0].event, - Event::pallet(pallet::Event::Something(3)), + Event::Example(pallet::Event::Something(3)), ); }); @@ -403,7 +403,7 @@ fn pallet_expand_deposit_event() { pallet::Call::::foo(3).dispatch_bypass_filter(None.into()).unwrap(); assert_eq!( frame_system::Pallet::::events()[0].event, - Event::pallet_Instance1(pallet::Event::Something(3)), + Event::Instance1Example(pallet::Event::Something(3)), ); }); } @@ -539,27 +539,27 @@ fn pallet_hooks_expand() { // The order is indeed reversed due to https://github.com/paritytech/substrate/issues/6280 assert_eq!( frame_system::Pallet::::events()[0].event, - Event::pallet_Instance1(pallet::Event::Something(11)), + Event::Instance1Example(pallet::Event::Something(11)), ); assert_eq!( frame_system::Pallet::::events()[1].event, - Event::pallet(pallet::Event::Something(10)), + Event::Example(pallet::Event::Something(10)), ); assert_eq!( frame_system::Pallet::::events()[2].event, - Event::pallet_Instance1(pallet::Event::Something(21)), + Event::Instance1Example(pallet::Event::Something(21)), ); assert_eq!( frame_system::Pallet::::events()[3].event, - Event::pallet(pallet::Event::Something(20)), + Event::Example(pallet::Event::Something(20)), ); assert_eq!( frame_system::Pallet::::events()[4].event, - Event::pallet_Instance1(pallet::Event::Something(31)), + Event::Instance1Example(pallet::Event::Something(31)), ); assert_eq!( frame_system::Pallet::::events()[5].event, - Event::pallet(pallet::Event::Something(30)), + Event::Example(pallet::Event::Something(30)), ); }) } diff --git a/frame/tips/src/tests.rs b/frame/tips/src/tests.rs index 6b144273ca828..6063f0954bd8a 100644 --- a/frame/tips/src/tests.rs +++ b/frame/tips/src/tests.rs @@ -176,7 +176,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { fn last_event() -> RawEvent { System::events().into_iter().map(|r| r.event) .filter_map(|e| { - if let Event::tips(inner) = e { Some(inner) } else { None } + if let Event::TipsModTestInst(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 2b1ad2db9ae09..1ce3f75d5a016 100644 --- a/frame/transaction-payment/src/lib.rs +++ b/frame/transaction-payment/src/lib.rs @@ -1177,9 +1177,9 @@ mod tests { ); assert_eq!(Balances::free_balance(2), 0); // Transfer Event - System::assert_has_event(Event::pallet_balances(pallet_balances::Event::Transfer(2, 3, 80))); + System::assert_has_event(Event::Balances(pallet_balances::Event::Transfer(2, 3, 80))); // Killed Event - System::assert_has_event(Event::system(system::Event::KilledAccount(2))); + System::assert_has_event(Event::System(system::Event::KilledAccount(2))); }); } diff --git a/frame/transaction-storage/src/mock.rs b/frame/transaction-storage/src/mock.rs index 351893c08a33b..03dacf8a98e89 100644 --- a/frame/transaction-storage/src/mock.rs +++ b/frame/transaction-storage/src/mock.rs @@ -102,11 +102,11 @@ impl pallet_transaction_storage::Config for Test { pub fn new_test_ext() -> sp_io::TestExternalities { let t = GenesisConfig { - frame_system: Default::default(), - pallet_balances: pallet_balances::GenesisConfig:: { + system: Default::default(), + balances: pallet_balances::GenesisConfig:: { balances: vec![(1, 1000000000), (2, 100), (3, 100), (4, 100)] }, - pallet_transaction_storage: pallet_transaction_storage::GenesisConfig:: { + transaction_storage: pallet_transaction_storage::GenesisConfig:: { storage_period: 10, byte_fee: 2, entry_fee: 200,