Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

Commit

Permalink
Use pallet names to name enum variants (paritytech#8990)
Browse files Browse the repository at this point in the history
* Remove unused event_metadata variable

* Eliminate mod_name and use pallet names to name enum variants

* Rename field name `pallet` to `path`

* Use only the pallet name to generate variant names

* Use new naming scheme for Event enum in sudo pallet tests

* Use new naming scheme for Event enum in offences pallet tests

* Use new naming scheme for Event enum in contracts pallet tests

* Use new naming scheme for Event enum in collective pallet tests

* Use new naming scheme for Event enum in bounties pallet tests

* Use new naming scheme for Event enum in balances pallet tests

* Use new naming scheme for Event enum in assets pallet tests

* Use new naming scheme for Event enum in frame support tests

* Use new naming scheme for Event enum in tips pallet tests

* Use new naming scheme for Event enum in transaction payment pallet tests

* Use new naming scheme for GenesisConfig fields in example pallet tests

* Use new naming scheme for GenesisConfig fields in elections pallet tests

* Use new naming scheme for Event enum in election provider multi-phase pallet tests

* Use new naming scheme for Event enum in elections phragmen pallet tests

* Use new naming scheme for GenesisConfig fields in chain spec

* Use new naming scheme for Event enum in staking pallet mock

* Use new naming scheme for GenesisConfig fields in node-template chain spec

* Use new naming scheme for GenesisConfig fields in node-testing chain spec

* Use new naming scheme for Event enum in node executor tests

* Use new naming scheme for GenesisConfig fields in transaction storage pallet mock

* Refactor match conditions
  • Loading branch information
KiChjang authored and Andrei Navoichyk committed Sep 9, 2022
1 parent c3ea13c commit a9c4d39
Show file tree
Hide file tree
Showing 31 changed files with 269 additions and 322 deletions.
40 changes: 20 additions & 20 deletions bin/node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -283,59 +283,59 @@ pub fn testnet_genesis(
))
}).collect::<Vec<_>>(),
},
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(),
slash_reward_fraction: Perbill::from_percent(10),
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()
.collect(),
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(),
}
}

Expand Down
22 changes: 11 additions & 11 deletions bin/node/executor/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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![],
Expand Down Expand Up @@ -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(),
Expand All @@ -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(),
Expand All @@ -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![],
Expand Down
40 changes: 20 additions & 20 deletions bin/node/testing/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand All @@ -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(),
}
}
2 changes: 1 addition & 1 deletion frame/assets/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
});
}

Expand Down
26 changes: 13 additions & 13 deletions frame/balances/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)));
});
}

Expand All @@ -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)),
]
);

Expand All @@ -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)),
]
);
});
Expand All @@ -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)),
]
);

Expand All @@ -751,7 +751,7 @@ macro_rules! decl_tests {
assert_eq!(
events(),
[
Event::frame_system(system::Event::KilledAccount(1))
Event::System(system::Event::KilledAccount(1))
]
);
});
Expand Down
10 changes: 5 additions & 5 deletions frame/balances/src/tests_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
]
);

Expand All @@ -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)),
]
);
});
Expand Down
Loading

0 comments on commit a9c4d39

Please sign in to comment.