diff --git a/pallets/asset-manager/src/lib.rs b/pallets/asset-manager/src/lib.rs index 1ae62971314..9e3f59604ac 100644 --- a/pallets/asset-manager/src/lib.rs +++ b/pallets/asset-manager/src/lib.rs @@ -126,9 +126,22 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { - AssetRegistered(T::AssetId, T::AssetType, T::AssetRegistrarMetadata), - UnitsPerSecondChanged(T::AssetType, u128), - AssetTypeChanged(T::AssetId, T::AssetType), + /// New asset with the asset manager is registered + AssetRegistered { + asset_id: T::AssetId, + asset: T::AssetType, + metadata: T::AssetRegistrarMetadata, + }, + /// Changed the amount of units we are charging per execution second for a given asset + UnitsPerSecondChanged { + asset_type: T::AssetType, + units_per_second: u128, + }, + /// Changed the xcm type mapping for a given asset id + AssetTypeChanged { + asset_id: T::AssetId, + new_asset_type: T::AssetType, + }, } /// Mapping from an asset id to asset type. @@ -178,7 +191,11 @@ pub mod pallet { AssetIdType::::insert(&asset_id, &asset); AssetTypeId::::insert(&asset, &asset_id); - Self::deposit_event(Event::AssetRegistered(asset_id, asset, metadata)); + Self::deposit_event(Event::AssetRegistered { + asset_id, + asset, + metadata, + }); Ok(()) } @@ -198,7 +215,10 @@ pub mod pallet { AssetTypeUnitsPerSecond::::insert(&asset_type, &units_per_second); - Self::deposit_event(Event::UnitsPerSecondChanged(asset_type, units_per_second)); + Self::deposit_event(Event::UnitsPerSecondChanged { + asset_type, + units_per_second, + }); Ok(()) } @@ -229,7 +249,10 @@ pub mod pallet { AssetTypeUnitsPerSecond::::insert(&new_asset_type, units); } - Self::deposit_event(Event::AssetTypeChanged(asset_id, new_asset_type)); + Self::deposit_event(Event::AssetTypeChanged { + asset_id, + new_asset_type, + }); Ok(()) } } diff --git a/pallets/asset-manager/src/tests.rs b/pallets/asset-manager/src/tests.rs index 2a9dcef9e2d..76a54f878d4 100644 --- a/pallets/asset-manager/src/tests.rs +++ b/pallets/asset-manager/src/tests.rs @@ -44,11 +44,11 @@ fn registering_works() { AssetManager::asset_type_id(MockAssetType::MockAsset(1)).unwrap(), 1 ); - expect_events(vec![crate::Event::AssetRegistered( - 1, - MockAssetType::MockAsset(1), - 0u32, - )]) + expect_events(vec![crate::Event::AssetRegistered { + asset_id: 1, + asset: MockAssetType::MockAsset(1), + metadata: 0u32, + }]) }); } @@ -103,8 +103,15 @@ fn test_root_can_change_units_per_second() { ); expect_events(vec![ - crate::Event::AssetRegistered(1, MockAssetType::MockAsset(1), 0), - crate::Event::UnitsPerSecondChanged(MockAssetType::MockAsset(1), 200), + crate::Event::AssetRegistered { + asset_id: 1, + asset: MockAssetType::MockAsset(1), + metadata: 0, + }, + crate::Event::UnitsPerSecondChanged { + asset_type: MockAssetType::MockAsset(1), + units_per_second: 200, + }, ]) }); } @@ -189,9 +196,19 @@ fn test_root_can_change_asset_id_type() { assert!(AssetManager::asset_type_id(MockAssetType::MockAsset(1)).is_none()); expect_events(vec![ - crate::Event::AssetRegistered(1, MockAssetType::MockAsset(1), 0), - crate::Event::UnitsPerSecondChanged(MockAssetType::MockAsset(1), 200), - crate::Event::AssetTypeChanged(1, MockAssetType::MockAsset(2)), + crate::Event::AssetRegistered { + asset_id: 1, + asset: MockAssetType::MockAsset(1), + metadata: 0, + }, + crate::Event::UnitsPerSecondChanged { + asset_type: MockAssetType::MockAsset(1), + units_per_second: 200, + }, + crate::Event::AssetTypeChanged { + asset_id: 1, + new_asset_type: MockAssetType::MockAsset(2), + }, ]) }); } diff --git a/pallets/author-mapping/src/lib.rs b/pallets/author-mapping/src/lib.rs index 5ea00b7f719..8fffef2581e 100644 --- a/pallets/author-mapping/src/lib.rs +++ b/pallets/author-mapping/src/lib.rs @@ -93,14 +93,23 @@ pub mod pallet { #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { /// A NimbusId has been registered and mapped to an AccountId. - AuthorRegistered(NimbusId, T::AccountId), + AuthorRegistered { + author_id: NimbusId, + account_id: T::AccountId, + }, /// An NimbusId has been de-registered, and its AccountId mapping removed. - AuthorDeRegistered(NimbusId), + AuthorDeRegistered { author_id: NimbusId }, /// An NimbusId has been registered, replacing a previous registration and its mapping. - AuthorRotated(NimbusId, T::AccountId), + AuthorRotated { + new_author_id: NimbusId, + account_id: T::AccountId, + }, /// An NimbusId has been forcibly deregistered after not being rotated or cleaned up. /// The reporteing account has been rewarded accordingly. - DefunctAuthorBusted(NimbusId, T::AccountId), + DefunctAuthorBusted { + author_id: NimbusId, + account_id: T::AccountId, + }, } #[pallet::call] @@ -120,7 +129,10 @@ pub mod pallet { Self::enact_registration(&author_id, &account_id)?; - >::deposit_event(Event::AuthorRegistered(author_id, account_id)); + >::deposit_event(Event::AuthorRegistered { + author_id, + account_id, + }); Ok(()) } @@ -152,7 +164,10 @@ pub mod pallet { MappingWithDeposit::::remove(&old_author_id); MappingWithDeposit::::insert(&new_author_id, &stored_info); - >::deposit_event(Event::AuthorRotated(new_author_id, stored_info.account)); + >::deposit_event(Event::AuthorRotated { + new_author_id: new_author_id, + account_id: stored_info.account, + }); Ok(()) } @@ -180,7 +195,7 @@ pub mod pallet { T::DepositCurrency::unreserve(&account_id, stored_info.deposit); - >::deposit_event(Event::AuthorDeRegistered(author_id)); + >::deposit_event(Event::AuthorDeRegistered { author_id }); Ok(().into()) } diff --git a/pallets/author-mapping/src/tests.rs b/pallets/author-mapping/src/tests.rs index 932788d4f33..2a3ecaea5d6 100644 --- a/pallets/author-mapping/src/tests.rs +++ b/pallets/author-mapping/src/tests.rs @@ -60,7 +60,10 @@ fn eligible_account_can_register() { assert_eq!( last_event(), - MetaEvent::AuthorMapping(Event::AuthorRegistered(TestAuthor::Bob.into(), 2)) + MetaEvent::AuthorMapping(Event::AuthorRegistered { + author_id: TestAuthor::Bob.into(), + account_id: 2 + }) ); }) } @@ -105,7 +108,10 @@ fn double_registration_costs_twice_as_much() { assert_eq!( last_event(), - MetaEvent::AuthorMapping(Event::AuthorRegistered(TestAuthor::Bob.into(), 2)) + MetaEvent::AuthorMapping(Event::AuthorRegistered { + author_id: TestAuthor::Bob.into(), + account_id: 2 + }) ); // Register again as Alice @@ -123,7 +129,10 @@ fn double_registration_costs_twice_as_much() { assert_eq!( last_event(), - MetaEvent::AuthorMapping(Event::AuthorRegistered(TestAuthor::Alice.into(), 2)) + MetaEvent::AuthorMapping(Event::AuthorRegistered { + author_id: TestAuthor::Alice.into(), + account_id: 2 + }) ); // Should still be registered as Bob as well @@ -155,7 +164,9 @@ fn registered_account_can_clear() { assert_eq!( last_event(), - MetaEvent::AuthorMapping(Event::AuthorDeRegistered(TestAuthor::Alice.into())) + MetaEvent::AuthorMapping(Event::AuthorDeRegistered { + author_id: TestAuthor::Alice.into() + }) ); }) } diff --git a/pallets/migrations/src/lib.rs b/pallets/migrations/src/lib.rs index 66ef5941027..48655311eb3 100644 --- a/pallets/migrations/src/lib.rs +++ b/pallets/migrations/src/lib.rs @@ -100,10 +100,17 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { + /// Runtime upgrade started RuntimeUpgradeStarted(), - RuntimeUpgradeCompleted(Weight), - MigrationStarted(Vec), - MigrationCompleted(Vec, Weight), + /// Runtime upgrade completed + RuntimeUpgradeCompleted { weight: Weight }, + /// Migration started + MigrationStarted { migration_name: Vec }, + /// Migration completed + MigrationCompleted { + migration_name: Vec, + consumed_weight: Weight, + }, } #[pallet::hooks] @@ -264,7 +271,9 @@ pub mod pallet { let migration_done = >::get(migration_name_as_bytes); if !migration_done { - >::deposit_event(Event::MigrationStarted(migration_name_as_bytes.into())); + >::deposit_event(Event::MigrationStarted { + migration_name: migration_name_as_bytes.into(), + }); // when we go overweight, leave a warning... there's nothing we can really do about // this scenario other than hope that the block is actually accepted. @@ -287,10 +296,10 @@ pub mod pallet { ); let consumed_weight = migration.migrate(available_for_step); - >::deposit_event(Event::MigrationCompleted( - migration_name_as_bytes.into(), - consumed_weight, - )); + >::deposit_event(Event::MigrationCompleted { + migration_name: migration_name_as_bytes.into(), + consumed_weight: consumed_weight, + }); >::insert(migration_name_as_bytes, true); weight = weight.saturating_add(consumed_weight); @@ -307,7 +316,7 @@ pub mod pallet { >::put(true); weight += T::DbWeight::get().writes(1); - >::deposit_event(Event::RuntimeUpgradeCompleted(weight)); + >::deposit_event(Event::RuntimeUpgradeCompleted { weight }); weight } diff --git a/pallets/migrations/src/tests.rs b/pallets/migrations/src/tests.rs index f76ce78a622..952fc2b0073 100644 --- a/pallets/migrations/src/tests.rs +++ b/pallets/migrations/src/tests.rs @@ -106,7 +106,9 @@ fn on_runtime_upgrade_emits_events() { let expected = vec![ Event::RuntimeUpgradeStarted(), - Event::RuntimeUpgradeCompleted(100000000u64.into()), + Event::RuntimeUpgradeCompleted { + weight: 100000000u64.into(), + }, ]; assert_eq!(events(), expected); }); @@ -157,9 +159,16 @@ fn migration_should_only_be_invoked_once() { ); let mut expected = vec![ Event::RuntimeUpgradeStarted(), - Event::MigrationStarted("migration1".into()), - Event::MigrationCompleted("migration1".into(), 1u32.into()), - Event::RuntimeUpgradeCompleted(100000001u32.into()), // includes reads/writes + Event::MigrationStarted { + migration_name: "migration1".into(), + }, + Event::MigrationCompleted { + migration_name: "migration1".into(), + consumed_weight: 1u32.into(), + }, + Event::RuntimeUpgradeCompleted { + weight: 100000001u32.into(), + }, // includes reads/writes ]; assert_eq!(events(), expected); @@ -181,7 +190,9 @@ fn migration_should_only_be_invoked_once() { ); expected.append(&mut vec![ Event::RuntimeUpgradeStarted(), - Event::RuntimeUpgradeCompleted(100000000u32.into()), + Event::RuntimeUpgradeCompleted { + weight: 100000000u32.into(), + }, ]); assert_eq!(events(), expected); diff --git a/pallets/parachain-staking/src/lib.rs b/pallets/parachain-staking/src/lib.rs index 8fa88406ce7..f89bbc8fda6 100644 --- a/pallets/parachain-staking/src/lib.rs +++ b/pallets/parachain-staking/src/lib.rs @@ -439,11 +439,11 @@ pub mod pallet { >::put(new_total); self.bond += more; self.total_counted += more; - >::deposit_event(Event::CandidateBondedMore( - who.clone(), - more.into(), - self.bond.into(), - )); + >::deposit_event(Event::CandidateBondedMore { + candidate: who.clone(), + amount: more.into(), + new_total_bond: self.bond.into(), + }); Ok(()) } /// Schedule executable decrease of collator candidate self bond @@ -493,11 +493,11 @@ pub mod pallet { // (assumptions enforced by `schedule_bond_less`; if storage corrupts, must re-verify) self.bond -= request.amount; self.total_counted -= request.amount; - let event = Event::CandidateBondedLess( - who.clone().into(), - request.amount.into(), - self.bond.into(), - ); + let event = Event::CandidateBondedLess { + candidate: who.clone().into(), + amount: request.amount.into(), + new_bond: self.bond.into(), + }; // reset s.t. no pending request self.request = None; // update candidate pool value because it must change if self bond changes @@ -515,11 +515,11 @@ pub mod pallet { let request = self .request .ok_or(Error::::PendingCandidateRequestsDNE)?; - let event = Event::CancelledCandidateBondLess( - who.clone().into(), - request.amount.into(), - request.when_executable, - ); + let event = Event::CancelledCandidateBondLess { + candidate: who.clone().into(), + amount: request.amount.into(), + execute_round: request.when_executable, + }; self.request = None; Pallet::::deposit_event(event); Ok(()) @@ -683,17 +683,17 @@ pub mod pallet { .expect("Delegation existence => DelegatorState existence"); let leaving = delegator_state.delegations.0.len() == 1usize; delegator_state.rm_delegation(candidate); - Pallet::::deposit_event(Event::DelegationKicked( - lowest_bottom_to_be_kicked.owner.clone(), - candidate.clone(), - lowest_bottom_to_be_kicked.amount, - )); + Pallet::::deposit_event(Event::DelegationKicked { + delegator: lowest_bottom_to_be_kicked.owner.clone(), + candidate: candidate.clone(), + unstaked_amount: lowest_bottom_to_be_kicked.amount, + }); if leaving { >::remove(&lowest_bottom_to_be_kicked.owner); - Pallet::::deposit_event(Event::DelegatorLeft( - lowest_bottom_to_be_kicked.owner, - lowest_bottom_to_be_kicked.amount, - )); + Pallet::::deposit_event(Event::DelegatorLeft { + delegator: lowest_bottom_to_be_kicked.owner, + unstaked_amount: lowest_bottom_to_be_kicked.amount, + }); } else { >::insert(&lowest_bottom_to_be_kicked.owner, delegator_state); } @@ -1415,12 +1415,12 @@ pub mod pallet { >::put(new_total_staked); let nom_st: Delegator> = self.clone().into(); >::insert(&delegator_id, nom_st); - Pallet::::deposit_event(Event::DelegationIncreased( - delegator_id, - candidate_id, - balance_amt, - in_top, - )); + Pallet::::deposit_event(Event::DelegationIncreased { + delegator: delegator_id, + candidate: candidate_id, + amount: balance_amt, + in_top: in_top, + }); return Ok(()); } } @@ -1548,14 +1548,17 @@ pub mod pallet { delegator_id.clone(), balance_amt, )?; - Pallet::::deposit_event(Event::DelegationRevoked( - delegator_id.clone(), - candidate_id, - balance_amt, - )); + Pallet::::deposit_event(Event::DelegationRevoked { + delegator: delegator_id.clone(), + candidate: candidate_id, + unstaked_amount: balance_amt, + }); if leaving { >::remove(&delegator_id); - Pallet::::deposit_event(Event::DelegatorLeft(delegator_id, balance_amt)); + Pallet::::deposit_event(Event::DelegatorLeft { + delegator: delegator_id, + unstaked_amount: balance_amt, + }); } else { let nom_st: Delegator> = self.clone().into(); >::insert(&delegator_id, nom_st); @@ -1598,12 +1601,12 @@ pub mod pallet { let nom_st: Delegator> = self.clone().into(); >::insert(&delegator_id, nom_st); - Pallet::::deposit_event(Event::DelegationDecreased( - delegator_id, - candidate_id, - balance_amt, - in_top, - )); + Pallet::::deposit_event(Event::DelegationDecreased { + delegator: delegator_id, + candidate: candidate_id, + amount: balance_amt, + in_top: in_top, + }); return Ok(()); } else { // must rm entire delegation if x.amount <= less or cancel request @@ -1962,85 +1965,185 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { - /// Starting Block, Round, Number of Collators Selected, Total Balance - NewRound(T::BlockNumber, RoundIndex, u32, BalanceOf), - /// Account, Amount Locked, New Total Amt Locked - JoinedCollatorCandidates(T::AccountId, BalanceOf, BalanceOf), - /// Round, Collator Account, Total Exposed Amount (includes all delegations) - CollatorChosen(RoundIndex, T::AccountId, BalanceOf), - /// Candidate, Amount To Decrease, Round at which request can be executed by caller - CandidateBondLessRequested(T::AccountId, BalanceOf, RoundIndex), - /// Candidate, Amount, New Bond Total - CandidateBondedMore(T::AccountId, BalanceOf, BalanceOf), - /// Candidate, Amount, New Bond - CandidateBondedLess(T::AccountId, BalanceOf, BalanceOf), - /// Candidate - CandidateWentOffline(T::AccountId), - /// Candidate - CandidateBackOnline(T::AccountId), - /// Round At Which Exit Is Allowed, Candidate, Scheduled Exit - CandidateScheduledExit(RoundIndex, T::AccountId, RoundIndex), - /// Candidate - CancelledCandidateExit(T::AccountId), - /// Candidate, Amount, Round at which could be executed - CancelledCandidateBondLess(T::AccountId, BalanceOf, RoundIndex), - /// Ex-Candidate, Amount Unlocked, New Total Amt Locked - CandidateLeft(T::AccountId, BalanceOf, BalanceOf), - /// Delegator, Candidate, Amount to be decreased, Round at which can be executed - DelegationDecreaseScheduled(T::AccountId, T::AccountId, BalanceOf, RoundIndex), - // Delegator, Candidate, Amount, If in top delegations for candidate after increase - DelegationIncreased(T::AccountId, T::AccountId, BalanceOf, bool), - // Delegator, Candidate, Amount, If in top delegations for candidate after decrease - DelegationDecreased(T::AccountId, T::AccountId, BalanceOf, bool), - /// Round, Delegator, Scheduled Exit - DelegatorExitScheduled(RoundIndex, T::AccountId, RoundIndex), - /// Round, Delegator, Candidate, Scheduled Exit - DelegationRevocationScheduled(RoundIndex, T::AccountId, T::AccountId, RoundIndex), - /// Delegator, Amount Unstaked - DelegatorLeft(T::AccountId, BalanceOf), - /// Delegator, Candidate, Amount Unstaked - DelegationRevoked(T::AccountId, T::AccountId, BalanceOf), - /// Delegator, Candidate, Amount Unstaked - DelegationKicked(T::AccountId, T::AccountId, BalanceOf), - /// Delegator - DelegatorExitCancelled(T::AccountId), - /// Delegator, Cancelled Request - CancelledDelegationRequest(T::AccountId, DelegationRequest>), - /// Delegator, Amount Locked, Candidate, Delegator Position with New Total Counted if in Top - Delegation( - T::AccountId, - BalanceOf, - T::AccountId, - DelegatorAdded>, - ), - /// Delegator, Candidate, Amount Unstaked, New Total Amt Staked for Candidate - DelegatorLeftCandidate(T::AccountId, T::AccountId, BalanceOf, BalanceOf), - /// Paid the account (delegator or collator) the balance as liquid rewards - Rewarded(T::AccountId, BalanceOf), - /// Transferred to account which holds funds reserved for parachain bond - ReservedForParachainBond(T::AccountId, BalanceOf), - /// Account (re)set for parachain bond treasury [old, new] - ParachainBondAccountSet(T::AccountId, T::AccountId), - /// Percent of inflation reserved for parachain bond (re)set [old, new] - ParachainBondReservePercentSet(Percent, Percent), + /// Started new round. + NewRound { + starting_block: T::BlockNumber, + round: RoundIndex, + selected_collators_number: u32, + total_balance: BalanceOf, + }, + /// Account joined the set of collator candidates. + JoinedCollatorCandidates { + account: T::AccountId, + amount_locked: BalanceOf, + new_total_amt_locked: BalanceOf, + }, + /// Candidate selected for collators. Total Exposed Amount includes all delegations. + CollatorChosen { + round: RoundIndex, + collator_account: T::AccountId, + total_exposed_amount: BalanceOf, + }, + /// Сandidate requested to decrease a self bond. + CandidateBondLessRequested { + candidate: T::AccountId, + amount_to_decrease: BalanceOf, + execute_round: RoundIndex, + }, + /// Сandidate has increased a self bond. + CandidateBondedMore { + candidate: T::AccountId, + amount: BalanceOf, + new_total_bond: BalanceOf, + }, + /// Сandidate has decreased a self bond. + CandidateBondedLess { + candidate: T::AccountId, + amount: BalanceOf, + new_bond: BalanceOf, + }, + /// Candidate temporarily leave the set of collator candidates without unbonding. + CandidateWentOffline { candidate: T::AccountId }, + /// Candidate rejoins the set of collator candidates. + CandidateBackOnline { candidate: T::AccountId }, + /// Сandidate has requested to leave the set of candidates. + CandidateScheduledExit { + exit_allowed_round: RoundIndex, + candidate: T::AccountId, + scheduled_exit: RoundIndex, + }, + /// Cancelled request to leave the set of candidates. + CancelledCandidateExit { candidate: T::AccountId }, + /// Cancelled request to decrease candidate's bond. + CancelledCandidateBondLess { + candidate: T::AccountId, + amount: BalanceOf, + execute_round: RoundIndex, + }, + /// Candidate has left the set of candidates. + CandidateLeft { + ex_candidate: T::AccountId, + unlocked_amount: BalanceOf, + new_total_amt_locked: BalanceOf, + }, + /// Delegator requested to decrease a bond for the collator candidate. + DelegationDecreaseScheduled { + delegator: T::AccountId, + candidate: T::AccountId, + amount_to_decrease: BalanceOf, + execute_round: RoundIndex, + }, + // Delegation increased. + DelegationIncreased { + delegator: T::AccountId, + candidate: T::AccountId, + amount: BalanceOf, + in_top: bool, + }, + // Delegation decreased. + DelegationDecreased { + delegator: T::AccountId, + candidate: T::AccountId, + amount: BalanceOf, + in_top: bool, + }, + /// Delegator requested to leave the set of delegators. + DelegatorExitScheduled { + round: RoundIndex, + delegator: T::AccountId, + scheduled_exit: RoundIndex, + }, + /// Delegator requested to revoke delegation. + DelegationRevocationScheduled { + round: RoundIndex, + delegator: T::AccountId, + candidate: T::AccountId, + scheduled_exit: RoundIndex, + }, + /// Delegator has left the set of delegators. + DelegatorLeft { + delegator: T::AccountId, + unstaked_amount: BalanceOf, + }, + /// Delegation revoked. + DelegationRevoked { + delegator: T::AccountId, + candidate: T::AccountId, + unstaked_amount: BalanceOf, + }, + /// Delegation kicked. + DelegationKicked { + delegator: T::AccountId, + candidate: T::AccountId, + unstaked_amount: BalanceOf, + }, + /// Cancelled a pending request to exit the set of delegators. + DelegatorExitCancelled { delegator: T::AccountId }, + /// Cancelled request to change an existing delegation. + CancelledDelegationRequest { + delegator: T::AccountId, + cancelled_request: DelegationRequest>, + }, + /// New delegation (increase of the existing one). + Delegation { + delegator: T::AccountId, + locked_amount: BalanceOf, + candidate: T::AccountId, + delegator_position: DelegatorAdded>, + }, + /// Delegation from candidate state has been remove. + DelegatorLeftCandidate { + delegator: T::AccountId, + candidate: T::AccountId, + unstaked_amount: BalanceOf, + total_candidate_staked: BalanceOf, + }, + /// Paid the account (delegator or collator) the balance as liquid rewards. + Rewarded { + account: T::AccountId, + rewards: BalanceOf, + }, + /// Transferred to account which holds funds reserved for parachain bond. + ReservedForParachainBond { + account: T::AccountId, + value: BalanceOf, + }, + /// Account (re)set for parachain bond treasury. + ParachainBondAccountSet { + old: T::AccountId, + new: T::AccountId, + }, + /// Percent of inflation reserved for parachain bond (re)set. + ParachainBondReservePercentSet { old: Percent, new: Percent }, /// Annual inflation input (first 3) was used to derive new per-round inflation (last 3) - InflationSet(Perbill, Perbill, Perbill, Perbill, Perbill, Perbill), - /// Staking expectations set - StakeExpectationsSet(BalanceOf, BalanceOf, BalanceOf), - /// Set total selected candidates to this value [old, new] - TotalSelectedSet(u32, u32), - /// Set collator commission to this value [old, new] - CollatorCommissionSet(Perbill, Perbill), - /// Set blocks per round [current_round, first_block, old, new, new_per_round_inflation] - BlocksPerRoundSet( - RoundIndex, - T::BlockNumber, - u32, - u32, - Perbill, - Perbill, - Perbill, - ), + InflationSet { + annual_min: Perbill, + annual_ideal: Perbill, + annual_max: Perbill, + round_min: Perbill, + round_ideal: Perbill, + round_max: Perbill, + }, + /// Staking expectations set. + StakeExpectationsSet { + expect_min: BalanceOf, + expect_ideal: BalanceOf, + expect_max: BalanceOf, + }, + /// Set total selected candidates to this value. + TotalSelectedSet { old: u32, new: u32 }, + /// Set collator commission to this value. + CollatorCommissionSet { old: Perbill, new: Perbill }, + /// Set blocks per round + BlocksPerRoundSet { + current_round: RoundIndex, + first_block: T::BlockNumber, + old: u32, + new: u32, + new_per_round_inflation_min: Perbill, + new_per_round_inflation_ideal: Perbill, + new_per_round_inflation_max: Perbill, + }, } #[pallet::hooks] @@ -2061,12 +2164,12 @@ pub mod pallet { >::put(round); // snapshot total stake >::insert(round.current, >::get()); - Self::deposit_event(Event::NewRound( - round.first, - round.current, - collator_count, - total_staked, - )); + Self::deposit_event(Event::NewRound { + starting_block: round.first, + round: round.current, + selected_collators_number: collator_count, + total_balance: total_staked, + }); weight += T::WeightInfo::round_transition_on_initialize(collator_count, delegation_count); } @@ -2335,12 +2438,12 @@ pub mod pallet { >::put(round); // Snapshot total stake >::insert(1u32, >::get()); - >::deposit_event(Event::NewRound( - T::BlockNumber::zero(), - 1u32, - v_count, - total_staked, - )); + >::deposit_event(Event::NewRound { + starting_block: T::BlockNumber::zero(), + round: 1u32, + selected_collators_number: v_count, + total_balance: total_staked, + }); } } @@ -2411,11 +2514,11 @@ pub mod pallet { Error::::NoWritingSameValue ); config.set_expectations(expectations); - Self::deposit_event(Event::StakeExpectationsSet( - config.expect.min, - config.expect.ideal, - config.expect.max, - )); + Self::deposit_event(Event::StakeExpectationsSet { + expect_min: config.expect.min, + expect_ideal: config.expect.ideal, + expect_max: config.expect.max, + }); >::put(config); Ok(().into()) } @@ -2431,14 +2534,14 @@ pub mod pallet { ensure!(config.annual != schedule, Error::::NoWritingSameValue); config.annual = schedule; config.set_round_from_annual::(schedule); - Self::deposit_event(Event::InflationSet( - config.annual.min, - config.annual.ideal, - config.annual.max, - config.round.min, - config.round.ideal, - config.round.max, - )); + Self::deposit_event(Event::InflationSet { + annual_min: config.annual.min, + annual_ideal: config.annual.ideal, + annual_max: config.annual.max, + round_min: config.round.min, + round_ideal: config.round.ideal, + round_max: config.round.max, + }); >::put(config); Ok(().into()) } @@ -2458,7 +2561,7 @@ pub mod pallet { account: new.clone(), percent, }); - Self::deposit_event(Event::ParachainBondAccountSet(old, new)); + Self::deposit_event(Event::ParachainBondAccountSet { old, new }); Ok(().into()) } #[pallet::weight(::WeightInfo::set_parachain_bond_reserve_percent())] @@ -2477,7 +2580,7 @@ pub mod pallet { account, percent: new, }); - Self::deposit_event(Event::ParachainBondReservePercentSet(old, new)); + Self::deposit_event(Event::ParachainBondReservePercentSet { old, new }); Ok(().into()) } #[pallet::weight(::WeightInfo::set_total_selected())] @@ -2496,7 +2599,7 @@ pub mod pallet { Error::::RoundLengthMustBeAtLeastTotalSelectedCollators, ); >::put(new); - Self::deposit_event(Event::TotalSelectedSet(old, new)); + Self::deposit_event(Event::TotalSelectedSet { old, new }); Ok(().into()) } #[pallet::weight(::WeightInfo::set_collator_commission())] @@ -2509,7 +2612,7 @@ pub mod pallet { let old = >::get(); ensure!(old != new, Error::::NoWritingSameValue); >::put(new); - Self::deposit_event(Event::CollatorCommissionSet(old, new)); + Self::deposit_event(Event::CollatorCommissionSet { old, new }); Ok(().into()) } #[pallet::weight(::WeightInfo::set_blocks_per_round())] @@ -2535,15 +2638,15 @@ pub mod pallet { let mut inflation_config = >::get(); inflation_config.reset_round(new); >::put(round); - Self::deposit_event(Event::BlocksPerRoundSet( - now, - first, - old, - new, - inflation_config.round.min, - inflation_config.round.ideal, - inflation_config.round.max, - )); + Self::deposit_event(Event::BlocksPerRoundSet { + current_round: now, + first_block: first, + old: old, + new: new, + new_per_round_inflation_min: inflation_config.round.min, + new_per_round_inflation_ideal: inflation_config.round.ideal, + new_per_round_inflation_max: inflation_config.round.max, + }); >::put(inflation_config); Ok(().into()) } @@ -2585,7 +2688,11 @@ pub mod pallet { >::put(candidates); let new_total = >::get().saturating_add(bond); >::put(new_total); - Self::deposit_event(Event::JoinedCollatorCandidates(acc, bond, new_total)); + Self::deposit_event(Event::JoinedCollatorCandidates { + account: acc, + amount_locked: bond, + new_total_amt_locked: new_total, + }); Ok(().into()) } #[pallet::weight(::WeightInfo::schedule_leave_candidates(*candidate_count))] @@ -2607,7 +2714,11 @@ pub mod pallet { >::put(candidates); } >::insert(&collator, state); - Self::deposit_event(Event::CandidateScheduledExit(now, collator, when)); + Self::deposit_event(Event::CandidateScheduledExit { + exit_allowed_round: now, + candidate: collator, + scheduled_exit: when, + }); Ok(().into()) } #[pallet::weight( @@ -2672,11 +2783,11 @@ pub mod pallet { >::remove(&candidate); let new_total_staked = >::get().saturating_sub(total_backing); >::put(new_total_staked); - Self::deposit_event(Event::CandidateLeft( - candidate, - total_backing, - new_total_staked, - )); + Self::deposit_event(Event::CandidateLeft { + ex_candidate: candidate, + unlocked_amount: total_backing, + new_total_amt_locked: new_total_staked, + }); Ok(().into()) } #[pallet::weight(::WeightInfo::cancel_leave_candidates(*candidate_count))] @@ -2705,7 +2816,9 @@ pub mod pallet { ); >::put(candidates); >::insert(&collator, state); - Self::deposit_event(Event::CancelledCandidateExit(collator)); + Self::deposit_event(Event::CancelledCandidateExit { + candidate: collator, + }); Ok(().into()) } #[pallet::weight(::WeightInfo::go_offline())] @@ -2720,7 +2833,9 @@ pub mod pallet { >::put(candidates); } >::insert(&collator, state); - Self::deposit_event(Event::CandidateWentOffline(collator)); + Self::deposit_event(Event::CandidateWentOffline { + candidate: collator, + }); Ok(().into()) } #[pallet::weight(::WeightInfo::go_online())] @@ -2741,7 +2856,9 @@ pub mod pallet { ); >::put(candidates); >::insert(&collator, state); - Self::deposit_event(Event::CandidateBackOnline(collator)); + Self::deposit_event(Event::CandidateBackOnline { + candidate: collator, + }); Ok(().into()) } #[pallet::weight(::WeightInfo::candidate_bond_more())] @@ -2770,7 +2887,11 @@ pub mod pallet { let mut state = >::get(&collator).ok_or(Error::::CandidateDNE)?; let when = state.schedule_bond_less::(less)?; >::insert(&collator, state); - Self::deposit_event(Event::CandidateBondLessRequested(collator, less, when)); + Self::deposit_event(Event::CandidateBondLessRequested { + candidate: collator, + amount_to_decrease: less, + execute_round: when, + }); Ok(().into()) } #[pallet::weight(::WeightInfo::execute_candidate_bond_less())] @@ -2873,12 +2994,12 @@ pub mod pallet { >::put(new_total_locked); >::insert(&candidate, state); >::insert(&delegator, delegator_state); - Self::deposit_event(Event::Delegation( - delegator, - amount, - candidate, - delegator_position, - )); + Self::deposit_event(Event::Delegation { + delegator: delegator, + locked_amount: amount, + candidate: candidate, + delegator_position: delegator_position, + }); Ok(().into()) } #[pallet::weight(::WeightInfo::schedule_leave_delegators())] @@ -2891,7 +3012,11 @@ pub mod pallet { ensure!(!state.is_leaving(), Error::::DelegatorAlreadyLeaving); let (now, when) = state.schedule_leave::(); >::insert(&acc, state); - Self::deposit_event(Event::DelegatorExitScheduled(now, acc, when)); + Self::deposit_event(Event::DelegatorExitScheduled { + round: now, + delegator: acc, + scheduled_exit: when, + }); Ok(().into()) } #[pallet::weight(::WeightInfo::execute_leave_delegators(*delegation_count))] @@ -2917,7 +3042,10 @@ pub mod pallet { } } >::remove(&delegator); - Self::deposit_event(Event::DelegatorLeft(delegator, state.total)); + Self::deposit_event(Event::DelegatorLeft { + delegator: delegator, + unstaked_amount: state.total, + }); Ok(().into()) } #[pallet::weight(::WeightInfo::cancel_leave_delegators())] @@ -2932,7 +3060,7 @@ pub mod pallet { // cancel exit request state.cancel_leave(); >::insert(&delegator, state); - Self::deposit_event(Event::DelegatorExitCancelled(delegator)); + Self::deposit_event(Event::DelegatorExitCancelled { delegator }); Ok(().into()) } #[pallet::weight(::WeightInfo::schedule_revoke_delegation())] @@ -2946,9 +3074,12 @@ pub mod pallet { let mut state = >::get(&delegator).ok_or(Error::::DelegatorDNE)?; let (now, when) = state.schedule_revoke::(collator.clone())?; >::insert(&delegator, state); - Self::deposit_event(Event::DelegationRevocationScheduled( - now, delegator, collator, when, - )); + Self::deposit_event(Event::DelegationRevocationScheduled { + round: now, + delegator: delegator, + candidate: collator, + scheduled_exit: when, + }); Ok(().into()) } #[pallet::weight(::WeightInfo::delegator_bond_more())] @@ -2974,9 +3105,12 @@ pub mod pallet { let mut state = >::get(&caller).ok_or(Error::::DelegatorDNE)?; let when = state.schedule_decrease_delegation::(candidate.clone(), less)?; >::insert(&caller, state); - Self::deposit_event(Event::DelegationDecreaseScheduled( - caller, candidate, less, when, - )); + Self::deposit_event(Event::DelegationDecreaseScheduled { + delegator: caller, + candidate: candidate, + amount_to_decrease: less, + execute_round: when, + }); Ok(().into()) } #[pallet::weight(::WeightInfo::execute_delegator_bond_less())] @@ -3001,7 +3135,10 @@ pub mod pallet { let mut state = >::get(&delegator).ok_or(Error::::DelegatorDNE)?; let request = state.cancel_pending_request::(candidate)?; >::insert(&delegator, state); - Self::deposit_event(Event::CancelledDelegationRequest(delegator, request)); + Self::deposit_event(Event::CancelledDelegationRequest { + delegator: delegator, + cancelled_request: request, + }); Ok(().into()) } } @@ -3053,9 +3190,12 @@ pub mod pallet { >::put(new_total_locked); let new_total = state.total_counted; >::insert(&candidate, state); - Self::deposit_event(Event::DelegatorLeftCandidate( - delegator, candidate, amount, new_total, - )); + Self::deposit_event(Event::DelegatorLeftCandidate { + delegator: delegator, + candidate: candidate, + unstaked_amount: amount, + total_candidate_staked: new_total, + }); Ok(()) } fn prepare_staking_payouts(now: RoundIndex) { @@ -3080,10 +3220,10 @@ pub mod pallet { { // update round issuance iff transfer succeeds left_issuance -= imb.peek(); - Self::deposit_event(Event::ReservedForParachainBond( - bond_config.account, - imb.peek(), - )); + Self::deposit_event(Event::ReservedForParachainBond { + account: bond_config.account, + value: imb.peek(), + }); } let payout = DelayedPayout { @@ -3146,7 +3286,10 @@ pub mod pallet { let mint = |amt: BalanceOf, to: T::AccountId| { if let Ok(amount_transferred) = T::Currency::deposit_into_existing(&to, amt) { - Self::deposit_event(Event::Rewarded(to.clone(), amount_transferred.peek())); + Self::deposit_event(Event::Rewarded { + account: to.clone(), + rewards: amount_transferred.peek(), + }); } }; @@ -3232,7 +3375,11 @@ pub mod pallet { total: state.total_counted, }; >::insert(now, account, snapshot); - Self::deposit_event(Event::CollatorChosen(now, account.clone(), snapshot_total)); + Self::deposit_event(Event::CollatorChosen { + round: now, + collator_account: account.clone(), + total_exposed_amount: snapshot_total, + }); } // insert canonical collator set >::put(collators); diff --git a/pallets/parachain-staking/src/migrations.rs b/pallets/parachain-staking/src/migrations.rs index 51bdac9910d..f428b39ebae 100644 --- a/pallets/parachain-staking/src/migrations.rs +++ b/pallets/parachain-staking/src/migrations.rs @@ -199,17 +199,17 @@ impl OnRuntimeUpgrade for SplitCandidateStateToDecreasePoV { .expect("Delegation existence => DelegatorState existence"); let leaving = delegator_state.delegations.0.len() == 1usize; delegator_state.rm_delegation(&account); - Pallet::::deposit_event(Event::DelegationKicked( - owner.clone(), - account.clone(), - *amount, - )); + Pallet::::deposit_event(Event::DelegationKicked { + delegator: owner.clone(), + candidate: account.clone(), + unstaked_amount: *amount, + }); if leaving { >::remove(&owner); - Pallet::::deposit_event(Event::DelegatorLeft( - owner.clone(), - *amount, - )); + Pallet::::deposit_event(Event::DelegatorLeft { + delegator: owner.clone(), + unstaked_amount: *amount, + }); } else { >::insert(&owner, delegator_state); } diff --git a/pallets/parachain-staking/src/tests.rs b/pallets/parachain-staking/src/tests.rs index 4be54b1e787..6c7090bee70 100644 --- a/pallets/parachain-staking/src/tests.rs +++ b/pallets/parachain-staking/src/tests.rs @@ -65,9 +65,10 @@ fn set_total_selected_event_emits_correctly() { // before we can bump total_selected we must bump the blocks per round assert_ok!(ParachainStaking::set_blocks_per_round(Origin::root(), 6u32)); assert_ok!(ParachainStaking::set_total_selected(Origin::root(), 6u32)); - assert_last_event!(MetaEvent::ParachainStaking(Event::TotalSelectedSet( - 5u32, 6u32 - ))); + assert_last_event!(MetaEvent::ParachainStaking(Event::TotalSelectedSet { + old: 5u32, + new: 6u32 + })); }); } @@ -183,10 +184,10 @@ fn set_collator_commission_event_emits_correctly() { Origin::root(), Perbill::from_percent(5) )); - assert_last_event!(MetaEvent::ParachainStaking(Event::CollatorCommissionSet( - Perbill::from_percent(20), - Perbill::from_percent(5), - ))); + assert_last_event!(MetaEvent::ParachainStaking(Event::CollatorCommissionSet { + old: Perbill::from_percent(20), + new: Perbill::from_percent(5), + })); }); } @@ -224,15 +225,15 @@ fn cannot_set_collator_commission_to_current_collator_commission() { fn set_blocks_per_round_event_emits_correctly() { ExtBuilder::default().build().execute_with(|| { assert_ok!(ParachainStaking::set_blocks_per_round(Origin::root(), 6u32)); - assert_last_event!(MetaEvent::ParachainStaking(Event::BlocksPerRoundSet( - 1, - 0, - 5, - 6, - Perbill::from_parts(926), - Perbill::from_parts(926), - Perbill::from_parts(926), - ))); + assert_last_event!(MetaEvent::ParachainStaking(Event::BlocksPerRoundSet { + current_round: 1, + first_block: 0, + old: 5, + new: 6, + new_per_round_inflation_min: Perbill::from_parts(926), + new_per_round_inflation_ideal: Perbill::from_parts(926), + new_per_round_inflation_max: Perbill::from_parts(926), + })); }); } @@ -281,10 +282,20 @@ fn round_immediately_jumps_if_current_duration_exceeds_new_blocks_per_round() { )); roll_to(17); - assert_last_event!(MetaEvent::ParachainStaking(Event::NewRound(10, 2, 1, 20))); + assert_last_event!(MetaEvent::ParachainStaking(Event::NewRound { + starting_block: 10, + round: 2, + selected_collators_number: 1, + total_balance: 20 + })); assert_ok!(ParachainStaking::set_blocks_per_round(Origin::root(), 5u32)); roll_to(18); - assert_last_event!(MetaEvent::ParachainStaking(Event::NewRound(18, 3, 1, 20))); + assert_last_event!(MetaEvent::ParachainStaking(Event::NewRound { + starting_block: 18, + round: 3, + selected_collators_number: 1, + total_balance: 20 + })); }); } @@ -354,9 +365,11 @@ fn set_staking_event_emits_event_correctly() { max: 5u128, } )); - assert_last_event!(MetaEvent::ParachainStaking(Event::StakeExpectationsSet( - 3u128, 4u128, 5u128, - ))); + assert_last_event!(MetaEvent::ParachainStaking(Event::StakeExpectationsSet { + expect_min: 3u128, + expect_ideal: 4u128, + expect_max: 5u128, + })); }); } @@ -447,14 +460,14 @@ fn set_inflation_event_emits_correctly() { Origin::root(), Range { min, ideal, max } )); - assert_last_event!(MetaEvent::ParachainStaking(Event::InflationSet( - min, - ideal, - max, - Perbill::from_parts(57), - Perbill::from_parts(75), - Perbill::from_parts(93), - ))); + assert_last_event!(MetaEvent::ParachainStaking(Event::InflationSet { + annual_min: min, + annual_ideal: ideal, + annual_max: max, + round_min: Perbill::from_parts(57), + round_ideal: Perbill::from_parts(75), + round_max: Perbill::from_parts(93), + })); }); } @@ -546,9 +559,9 @@ fn set_parachain_bond_account_event_emits_correctly() { Origin::root(), 11 )); - assert_last_event!(MetaEvent::ParachainStaking(Event::ParachainBondAccountSet( - 0, 11 - ))); + assert_last_event!(MetaEvent::ParachainStaking( + Event::ParachainBondAccountSet { old: 0, new: 11 } + )); }); } @@ -574,10 +587,10 @@ fn set_parachain_bond_reserve_percent_event_emits_correctly() { Percent::from_percent(50) )); assert_last_event!(MetaEvent::ParachainStaking( - Event::ParachainBondReservePercentSet( - Percent::from_percent(30), - Percent::from_percent(50), - ) + Event::ParachainBondReservePercentSet { + old: Percent::from_percent(30), + new: Percent::from_percent(50), + } )); }); } @@ -629,7 +642,11 @@ fn join_candidates_event_emits_correctly() { 0u32 )); assert_last_event!(MetaEvent::ParachainStaking( - Event::JoinedCollatorCandidates(1, 10u128, 10u128,) + Event::JoinedCollatorCandidates { + account: 1, + amount_locked: 10u128, + new_total_amt_locked: 10u128, + } )); }); } @@ -821,9 +838,11 @@ fn leave_candidates_event_emits_correctly() { Origin::signed(1), 1u32 )); - assert_last_event!(MetaEvent::ParachainStaking(Event::CandidateScheduledExit( - 1, 1, 3 - ))); + assert_last_event!(MetaEvent::ParachainStaking(Event::CandidateScheduledExit { + exit_allowed_round: 1, + candidate: 1, + scheduled_exit: 3 + })); }); } @@ -924,7 +943,11 @@ fn execute_leave_candidates_emits_event() { 1, 0 )); - assert_last_event!(MetaEvent::ParachainStaking(Event::CandidateLeft(1, 10, 0))); + assert_last_event!(MetaEvent::ParachainStaking(Event::CandidateLeft { + ex_candidate: 1, + unlocked_amount: 10, + new_total_amt_locked: 0 + })); }); } @@ -1092,9 +1115,9 @@ fn cancel_leave_candidates_emits_event() { Origin::signed(1), 1 )); - assert_last_event!(MetaEvent::ParachainStaking(Event::CancelledCandidateExit( - 1 - ))); + assert_last_event!(MetaEvent::ParachainStaking(Event::CancelledCandidateExit { + candidate: 1 + })); }); } @@ -1149,7 +1172,9 @@ fn go_offline_event_emits_correctly() { .build() .execute_with(|| { assert_ok!(ParachainStaking::go_offline(Origin::signed(1))); - assert_last_event!(MetaEvent::ParachainStaking(Event::CandidateWentOffline(1))); + assert_last_event!(MetaEvent::ParachainStaking(Event::CandidateWentOffline { + candidate: 1 + })); }); } @@ -1218,7 +1243,9 @@ fn go_online_event_emits_correctly() { .execute_with(|| { assert_ok!(ParachainStaking::go_offline(Origin::signed(1))); assert_ok!(ParachainStaking::go_online(Origin::signed(1))); - assert_last_event!(MetaEvent::ParachainStaking(Event::CandidateBackOnline(1))); + assert_last_event!(MetaEvent::ParachainStaking(Event::CandidateBackOnline { + candidate: 1 + })); }); } @@ -1306,9 +1333,11 @@ fn candidate_bond_more_emits_correct_event() { .build() .execute_with(|| { assert_ok!(ParachainStaking::candidate_bond_more(Origin::signed(1), 30)); - assert_last_event!(MetaEvent::ParachainStaking(Event::CandidateBondedMore( - 1, 30, 50 - ))); + assert_last_event!(MetaEvent::ParachainStaking(Event::CandidateBondedMore { + candidate: 1, + amount: 30, + new_total_bond: 50 + })); }); } @@ -1385,7 +1414,11 @@ fn schedule_candidate_bond_less_event_emits_correctly() { 10 )); assert_last_event!(MetaEvent::ParachainStaking( - Event::CandidateBondLessRequested(1, 10, 3,) + Event::CandidateBondLessRequested { + candidate: 1, + amount_to_decrease: 10, + execute_round: 3, + } )); }); } @@ -1492,9 +1525,11 @@ fn execute_candidate_bond_less_emits_correct_event() { Origin::signed(1), 1 )); - assert_last_event!(MetaEvent::ParachainStaking(Event::CandidateBondedLess( - 1, 30, 20 - ))); + assert_last_event!(MetaEvent::ParachainStaking(Event::CandidateBondedLess { + candidate: 1, + amount: 30, + new_bond: 20 + })); }); } @@ -1606,7 +1641,11 @@ fn cancel_candidate_bond_less_emits_event() { Origin::signed(1) )); assert_last_event!(MetaEvent::ParachainStaking( - Event::CancelledCandidateBondLess(1, 10, 3,) + Event::CancelledCandidateBondLess { + candidate: 1, + amount: 10, + execute_round: 3, + } )); }); } @@ -1660,12 +1699,12 @@ fn delegate_event_emits_correctly() { .build() .execute_with(|| { assert_ok!(ParachainStaking::delegate(Origin::signed(2), 1, 10, 0, 0)); - assert_last_event!(MetaEvent::ParachainStaking(Event::Delegation( - 2, - 10, - 1, - DelegatorAdded::AddedToTop { new_total: 40 }, - ))); + assert_last_event!(MetaEvent::ParachainStaking(Event::Delegation { + delegator: 2, + locked_amount: 10, + candidate: 1, + delegator_position: DelegatorAdded::AddedToTop { new_total: 40 }, + })); }); } @@ -1922,9 +1961,11 @@ fn schedule_leave_delegators_event_emits_correctly() { assert_ok!(ParachainStaking::schedule_leave_delegators(Origin::signed( 2 ))); - assert_last_event!(MetaEvent::ParachainStaking(Event::DelegatorExitScheduled( - 1, 2, 3 - ))); + assert_last_event!(MetaEvent::ParachainStaking(Event::DelegatorExitScheduled { + round: 1, + delegator: 2, + scheduled_exit: 3 + })); }); } @@ -1979,7 +2020,10 @@ fn execute_leave_delegators_event_emits_correctly() { 2, 1 )); - assert_event_emitted!(Event::DelegatorLeft(2, 10)); + assert_event_emitted!(Event::DelegatorLeft { + delegator: 2, + unstaked_amount: 10 + }); }); } @@ -2183,9 +2227,9 @@ fn cancel_leave_delegators_emits_correct_event() { 2 ))); assert_ok!(ParachainStaking::cancel_leave_delegators(Origin::signed(2))); - assert_last_event!(MetaEvent::ParachainStaking(Event::DelegatorExitCancelled( - 2 - ))); + assert_last_event!(MetaEvent::ParachainStaking(Event::DelegatorExitCancelled { + delegator: 2 + })); }); } @@ -2222,7 +2266,12 @@ fn revoke_delegation_event_emits_correctly() { 1 )); assert_last_event!(MetaEvent::ParachainStaking( - Event::DelegationRevocationScheduled(1, 2, 1, 3,) + Event::DelegationRevocationScheduled { + round: 1, + delegator: 2, + candidate: 1, + scheduled_exit: 3, + } )); roll_to(10); assert_ok!(ParachainStaking::execute_delegation_request( @@ -2230,7 +2279,12 @@ fn revoke_delegation_event_emits_correctly() { 2, 1 )); - assert_event_emitted!(Event::DelegatorLeftCandidate(2, 1, 10, 30)); + assert_event_emitted!(Event::DelegatorLeftCandidate { + delegator: 2, + candidate: 1, + unstaked_amount: 10, + total_candidate_staked: 30 + }); }); } @@ -2446,9 +2500,12 @@ fn delegator_bond_more_updates_candidate_state_bottom_delegations() { 1, 5 )); - assert_last_event!(MetaEvent::ParachainStaking(Event::DelegationIncreased( - 2, 1, 5, false - ))); + assert_last_event!(MetaEvent::ParachainStaking(Event::DelegationIncreased { + delegator: 2, + candidate: 1, + amount: 5, + in_top: false + })); assert_eq!( ParachainStaking::bottom_delegations(1) .expect("exists") @@ -2521,7 +2578,12 @@ fn delegator_bond_less_event_emits_correctly() { 5 )); assert_last_event!(MetaEvent::ParachainStaking( - Event::DelegationDecreaseScheduled(2, 1, 5, 3,) + Event::DelegationDecreaseScheduled { + delegator: 2, + candidate: 1, + amount_to_decrease: 5, + execute_round: 3, + } )); }); } @@ -2699,8 +2761,16 @@ fn execute_revoke_delegation_emits_exit_event_if_exit_happens() { 2, 1 )); - assert_event_emitted!(Event::DelegatorLeftCandidate(2, 1, 10, 30)); - assert_event_emitted!(Event::DelegatorLeft(2, 10)); + assert_event_emitted!(Event::DelegatorLeftCandidate { + delegator: 2, + candidate: 1, + unstaked_amount: 10, + total_candidate_staked: 30 + }); + assert_event_emitted!(Event::DelegatorLeft { + delegator: 2, + unstaked_amount: 10 + }); }); } @@ -2757,8 +2827,16 @@ fn revoke_delegation_executes_exit_if_last_delegation() { 2, 1 )); - assert_event_emitted!(Event::DelegatorLeftCandidate(2, 1, 10, 30)); - assert_event_emitted!(Event::DelegatorLeft(2, 10)); + assert_event_emitted!(Event::DelegatorLeftCandidate { + delegator: 2, + candidate: 1, + unstaked_amount: 10, + total_candidate_staked: 30 + }); + assert_event_emitted!(Event::DelegatorLeft { + delegator: 2, + unstaked_amount: 10 + }); }); } @@ -2780,7 +2858,12 @@ fn execute_revoke_delegation_emits_correct_event() { 2, 1 )); - assert_event_emitted!(Event::DelegatorLeftCandidate(2, 1, 10, 30)); + assert_event_emitted!(Event::DelegatorLeftCandidate { + delegator: 2, + candidate: 1, + unstaked_amount: 10, + total_candidate_staked: 30 + }); }); } @@ -3039,7 +3122,12 @@ fn delegator_bond_less_after_revoke_delegation_does_not_effect_exit() { 1 )); assert_last_event!(MetaEvent::ParachainStaking( - Event::DelegationRevocationScheduled(1, 2, 1, 3,) + Event::DelegationRevocationScheduled { + round: 1, + delegator: 2, + candidate: 1, + scheduled_exit: 3, + } )); assert_noop!( ParachainStaking::schedule_delegator_bond_less(Origin::signed(2), 1, 2), @@ -3061,9 +3149,12 @@ fn delegator_bond_less_after_revoke_delegation_does_not_effect_exit() { 2, 3 )); - assert_last_event!(MetaEvent::ParachainStaking(Event::DelegationDecreased( - 2, 3, 2, true - ))); + assert_last_event!(MetaEvent::ParachainStaking(Event::DelegationDecreased { + delegator: 2, + candidate: 3, + amount: 2, + in_top: true + })); assert!(ParachainStaking::is_delegator(&2)); assert_eq!(Balances::reserved_balance(&2), 8); assert_eq!(Balances::free_balance(&2), 22); @@ -3413,15 +3504,15 @@ fn cancel_revoke_delegation_emits_correct_event() { 1 )); assert_last_event!(MetaEvent::ParachainStaking( - Event::CancelledDelegationRequest( - 2, - DelegationRequest { + Event::CancelledDelegationRequest { + delegator: 2, + cancelled_request: DelegationRequest { collator: 1, amount: 10, when_executable: 3, action: DelegationChange::Revoke, }, - ) + } )); }); } @@ -3479,15 +3570,15 @@ fn cancel_delegator_bond_less_correct_event() { 1 )); assert_last_event!(MetaEvent::ParachainStaking( - Event::CancelledDelegationRequest( - 2, - DelegationRequest { + Event::CancelledDelegationRequest { + delegator: 2, + cancelled_request: DelegationRequest { collator: 1, amount: 5, when_executable: 3, action: DelegationChange::Decrease, }, - ) + } )); }); } @@ -3640,13 +3731,38 @@ fn parachain_bond_inflation_reserve_matches_config() { roll_to(8); // chooses top TotalSelectedCandidates (5), in order let mut expected = vec![ - Event::ParachainBondAccountSet(0, 11), - Event::CollatorChosen(2, 1, 50), - Event::CollatorChosen(2, 2, 40), - Event::CollatorChosen(2, 3, 20), - Event::CollatorChosen(2, 4, 20), - Event::CollatorChosen(2, 5, 10), - Event::NewRound(5, 2, 5, 140), + Event::ParachainBondAccountSet { old: 0, new: 11 }, + Event::CollatorChosen { + round: 2, + collator_account: 1, + total_exposed_amount: 50, + }, + Event::CollatorChosen { + round: 2, + collator_account: 2, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 2, + collator_account: 3, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 2, + collator_account: 4, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 2, + collator_account: 5, + total_exposed_amount: 10, + }, + Event::NewRound { + starting_block: 5, + round: 2, + selected_collators_number: 5, + total_balance: 140, + }, ]; assert_eq_events!(expected.clone()); assert_eq!(Balances::free_balance(&11), 1); @@ -3655,23 +3771,88 @@ fn parachain_bond_inflation_reserve_matches_config() { roll_to(16); // distribute total issuance to collator 1 and its delegators 6, 7, 19 let mut new = vec![ - Event::CollatorChosen(3, 1, 50), - Event::CollatorChosen(3, 2, 40), - Event::CollatorChosen(3, 3, 20), - Event::CollatorChosen(3, 4, 20), - Event::CollatorChosen(3, 5, 10), - Event::NewRound(10, 3, 5, 140), - Event::ReservedForParachainBond(11, 15), - Event::CollatorChosen(4, 1, 50), - Event::CollatorChosen(4, 2, 40), - Event::CollatorChosen(4, 3, 20), - Event::CollatorChosen(4, 4, 20), - Event::CollatorChosen(4, 5, 10), - Event::NewRound(15, 4, 5, 140), - Event::Rewarded(1, 20), - Event::Rewarded(6, 5), - Event::Rewarded(7, 5), - Event::Rewarded(10, 5), + Event::CollatorChosen { + round: 3, + collator_account: 1, + total_exposed_amount: 50, + }, + Event::CollatorChosen { + round: 3, + collator_account: 2, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 3, + collator_account: 3, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 3, + collator_account: 4, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 3, + collator_account: 5, + total_exposed_amount: 10, + }, + Event::NewRound { + starting_block: 10, + round: 3, + selected_collators_number: 5, + total_balance: 140, + }, + Event::ReservedForParachainBond { + account: 11, + value: 15, + }, + Event::CollatorChosen { + round: 4, + collator_account: 1, + total_exposed_amount: 50, + }, + Event::CollatorChosen { + round: 4, + collator_account: 2, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 4, + collator_account: 3, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 4, + collator_account: 4, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 4, + collator_account: 5, + total_exposed_amount: 10, + }, + Event::NewRound { + starting_block: 15, + round: 4, + selected_collators_number: 5, + total_balance: 140, + }, + Event::Rewarded { + account: 1, + rewards: 20, + }, + Event::Rewarded { + account: 6, + rewards: 5, + }, + Event::Rewarded { + account: 7, + rewards: 5, + }, + Event::Rewarded { + account: 10, + rewards: 5, + }, ]; expected.append(&mut new); assert_eq_events!(expected.clone()); @@ -3697,42 +3878,174 @@ fn parachain_bond_inflation_reserve_matches_config() { )); roll_to(30); let mut new2 = vec![ - Event::DelegatorExitScheduled(4, 6, 6), - Event::ReservedForParachainBond(11, 16), - Event::CollatorChosen(5, 1, 50), - Event::CollatorChosen(5, 2, 40), - Event::CollatorChosen(5, 3, 20), - Event::CollatorChosen(5, 4, 20), - Event::CollatorChosen(5, 5, 10), - Event::NewRound(20, 5, 5, 140), - Event::Rewarded(1, 21), - Event::Rewarded(6, 5), - Event::Rewarded(7, 5), - Event::Rewarded(10, 5), - Event::ReservedForParachainBond(11, 16), - Event::CollatorChosen(6, 1, 50), - Event::CollatorChosen(6, 2, 40), - Event::CollatorChosen(6, 3, 20), - Event::CollatorChosen(6, 4, 20), - Event::CollatorChosen(6, 5, 10), - Event::NewRound(25, 6, 5, 140), - Event::Rewarded(1, 22), - Event::Rewarded(6, 6), - Event::Rewarded(7, 6), - Event::Rewarded(10, 6), - Event::DelegatorLeftCandidate(6, 1, 10, 40), - Event::DelegatorLeft(6, 10), - Event::ReservedForParachainBond(11, 17), - Event::CollatorChosen(7, 1, 40), - Event::CollatorChosen(7, 2, 40), - Event::CollatorChosen(7, 3, 20), - Event::CollatorChosen(7, 4, 20), - Event::CollatorChosen(7, 5, 10), - Event::NewRound(30, 7, 5, 130), - Event::Rewarded(1, 24), - Event::Rewarded(6, 6), - Event::Rewarded(7, 6), - Event::Rewarded(10, 6), + Event::DelegatorExitScheduled { + round: 4, + delegator: 6, + scheduled_exit: 6, + }, + Event::ReservedForParachainBond { + account: 11, + value: 16, + }, + Event::CollatorChosen { + round: 5, + collator_account: 1, + total_exposed_amount: 50, + }, + Event::CollatorChosen { + round: 5, + collator_account: 2, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 5, + collator_account: 3, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 5, + collator_account: 4, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 5, + collator_account: 5, + total_exposed_amount: 10, + }, + Event::NewRound { + starting_block: 20, + round: 5, + selected_collators_number: 5, + total_balance: 140, + }, + Event::Rewarded { + account: 1, + rewards: 21, + }, + Event::Rewarded { + account: 6, + rewards: 5, + }, + Event::Rewarded { + account: 7, + rewards: 5, + }, + Event::Rewarded { + account: 10, + rewards: 5, + }, + Event::ReservedForParachainBond { + account: 11, + value: 16, + }, + Event::CollatorChosen { + round: 6, + collator_account: 1, + total_exposed_amount: 50, + }, + Event::CollatorChosen { + round: 6, + collator_account: 2, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 6, + collator_account: 3, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 6, + collator_account: 4, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 6, + collator_account: 5, + total_exposed_amount: 10, + }, + Event::NewRound { + starting_block: 25, + round: 6, + selected_collators_number: 5, + total_balance: 140, + }, + Event::Rewarded { + account: 1, + rewards: 22, + }, + Event::Rewarded { + account: 6, + rewards: 6, + }, + Event::Rewarded { + account: 7, + rewards: 6, + }, + Event::Rewarded { + account: 10, + rewards: 6, + }, + Event::DelegatorLeftCandidate { + delegator: 6, + candidate: 1, + unstaked_amount: 10, + total_candidate_staked: 40, + }, + Event::DelegatorLeft { + delegator: 6, + unstaked_amount: 10, + }, + Event::ReservedForParachainBond { + account: 11, + value: 17, + }, + Event::CollatorChosen { + round: 7, + collator_account: 1, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 7, + collator_account: 2, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 7, + collator_account: 3, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 7, + collator_account: 4, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 7, + collator_account: 5, + total_exposed_amount: 10, + }, + Event::NewRound { + starting_block: 30, + round: 7, + selected_collators_number: 5, + total_balance: 130, + }, + Event::Rewarded { + account: 1, + rewards: 24, + }, + Event::Rewarded { + account: 6, + rewards: 6, + }, + Event::Rewarded { + account: 7, + rewards: 6, + }, + Event::Rewarded { + account: 10, + rewards: 6, + }, ]; expected.append(&mut new2); assert_eq_events!(expected.clone()); @@ -3746,21 +4059,61 @@ fn parachain_bond_inflation_reserve_matches_config() { roll_to(35); // keep paying 6 let mut new3 = vec![ - Event::ParachainBondReservePercentSet( - Percent::from_percent(30), - Percent::from_percent(50), - ), - Event::ReservedForParachainBond(11, 30), - Event::CollatorChosen(8, 1, 40), - Event::CollatorChosen(8, 2, 40), - Event::CollatorChosen(8, 3, 20), - Event::CollatorChosen(8, 4, 20), - Event::CollatorChosen(8, 5, 10), - Event::NewRound(35, 8, 5, 130), - Event::Rewarded(1, 20), - Event::Rewarded(6, 4), - Event::Rewarded(7, 4), - Event::Rewarded(10, 4), + Event::ParachainBondReservePercentSet { + old: Percent::from_percent(30), + new: Percent::from_percent(50), + }, + Event::ReservedForParachainBond { + account: 11, + value: 30, + }, + Event::CollatorChosen { + round: 8, + collator_account: 1, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 8, + collator_account: 2, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 8, + collator_account: 3, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 8, + collator_account: 4, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 8, + collator_account: 5, + total_exposed_amount: 10, + }, + Event::NewRound { + starting_block: 35, + round: 8, + selected_collators_number: 5, + total_balance: 130, + }, + Event::Rewarded { + account: 1, + rewards: 20, + }, + Event::Rewarded { + account: 6, + rewards: 4, + }, + Event::Rewarded { + account: 7, + rewards: 4, + }, + Event::Rewarded { + account: 10, + rewards: 4, + }, ]; expected.append(&mut new3); assert_eq_events!(expected.clone()); @@ -3769,16 +4122,53 @@ fn parachain_bond_inflation_reserve_matches_config() { roll_to(40); // no more paying 6 let mut new4 = vec![ - Event::ReservedForParachainBond(11, 32), - Event::CollatorChosen(9, 1, 40), - Event::CollatorChosen(9, 2, 40), - Event::CollatorChosen(9, 3, 20), - Event::CollatorChosen(9, 4, 20), - Event::CollatorChosen(9, 5, 10), - Event::NewRound(40, 9, 5, 130), - Event::Rewarded(1, 22), - Event::Rewarded(7, 5), - Event::Rewarded(10, 5), + Event::ReservedForParachainBond { + account: 11, + value: 32, + }, + Event::CollatorChosen { + round: 9, + collator_account: 1, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 9, + collator_account: 2, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 9, + collator_account: 3, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 9, + collator_account: 4, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 9, + collator_account: 5, + total_exposed_amount: 10, + }, + Event::NewRound { + starting_block: 40, + round: 9, + selected_collators_number: 5, + total_balance: 130, + }, + Event::Rewarded { + account: 1, + rewards: 22, + }, + Event::Rewarded { + account: 7, + rewards: 5, + }, + Event::Rewarded { + account: 10, + rewards: 5, + }, ]; expected.append(&mut new4); assert_eq_events!(expected.clone()); @@ -3788,17 +4178,59 @@ fn parachain_bond_inflation_reserve_matches_config() { roll_to(45); // new delegation is not rewarded yet let mut new5 = vec![ - Event::Delegation(8, 10, 1, DelegatorAdded::AddedToTop { new_total: 50 }), - Event::ReservedForParachainBond(11, 33), - Event::CollatorChosen(10, 1, 50), - Event::CollatorChosen(10, 2, 40), - Event::CollatorChosen(10, 3, 20), - Event::CollatorChosen(10, 4, 20), - Event::CollatorChosen(10, 5, 10), - Event::NewRound(45, 10, 5, 140), - Event::Rewarded(1, 23), - Event::Rewarded(7, 5), - Event::Rewarded(10, 5), + Event::Delegation { + delegator: 8, + locked_amount: 10, + candidate: 1, + delegator_position: DelegatorAdded::AddedToTop { new_total: 50 }, + }, + Event::ReservedForParachainBond { + account: 11, + value: 33, + }, + Event::CollatorChosen { + round: 10, + collator_account: 1, + total_exposed_amount: 50, + }, + Event::CollatorChosen { + round: 10, + collator_account: 2, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 10, + collator_account: 3, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 10, + collator_account: 4, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 10, + collator_account: 5, + total_exposed_amount: 10, + }, + Event::NewRound { + starting_block: 45, + round: 10, + selected_collators_number: 5, + total_balance: 140, + }, + Event::Rewarded { + account: 1, + rewards: 23, + }, + Event::Rewarded { + account: 7, + rewards: 5, + }, + Event::Rewarded { + account: 10, + rewards: 5, + }, ]; expected.append(&mut new5); assert_eq_events!(expected.clone()); @@ -3808,16 +4240,53 @@ fn parachain_bond_inflation_reserve_matches_config() { roll_to(50); // new delegation is still not rewarded yet let mut new6 = vec![ - Event::ReservedForParachainBond(11, 35), - Event::CollatorChosen(11, 1, 50), - Event::CollatorChosen(11, 2, 40), - Event::CollatorChosen(11, 3, 20), - Event::CollatorChosen(11, 4, 20), - Event::CollatorChosen(11, 5, 10), - Event::NewRound(50, 11, 5, 140), - Event::Rewarded(1, 24), - Event::Rewarded(7, 5), - Event::Rewarded(10, 5), + Event::ReservedForParachainBond { + account: 11, + value: 35, + }, + Event::CollatorChosen { + round: 11, + collator_account: 1, + total_exposed_amount: 50, + }, + Event::CollatorChosen { + round: 11, + collator_account: 2, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 11, + collator_account: 3, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 11, + collator_account: 4, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 11, + collator_account: 5, + total_exposed_amount: 10, + }, + Event::NewRound { + starting_block: 50, + round: 11, + selected_collators_number: 5, + total_balance: 140, + }, + Event::Rewarded { + account: 1, + rewards: 24, + }, + Event::Rewarded { + account: 7, + rewards: 5, + }, + Event::Rewarded { + account: 10, + rewards: 5, + }, ]; expected.append(&mut new6); assert_eq_events!(expected.clone()); @@ -3825,17 +4294,57 @@ fn parachain_bond_inflation_reserve_matches_config() { roll_to(55); // new delegation is rewarded, 2 rounds after joining (`RewardPaymentDelay` is 2) let mut new7 = vec![ - Event::ReservedForParachainBond(11, 37), - Event::CollatorChosen(12, 1, 50), - Event::CollatorChosen(12, 2, 40), - Event::CollatorChosen(12, 3, 20), - Event::CollatorChosen(12, 4, 20), - Event::CollatorChosen(12, 5, 10), - Event::NewRound(55, 12, 5, 140), - Event::Rewarded(1, 24), - Event::Rewarded(7, 4), - Event::Rewarded(10, 4), - Event::Rewarded(8, 4), + Event::ReservedForParachainBond { + account: 11, + value: 37, + }, + Event::CollatorChosen { + round: 12, + collator_account: 1, + total_exposed_amount: 50, + }, + Event::CollatorChosen { + round: 12, + collator_account: 2, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 12, + collator_account: 3, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 12, + collator_account: 4, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 12, + collator_account: 5, + total_exposed_amount: 10, + }, + Event::NewRound { + starting_block: 55, + round: 12, + selected_collators_number: 5, + total_balance: 140, + }, + Event::Rewarded { + account: 1, + rewards: 24, + }, + Event::Rewarded { + account: 7, + rewards: 4, + }, + Event::Rewarded { + account: 10, + rewards: 4, + }, + Event::Rewarded { + account: 8, + rewards: 4, + }, ]; expected.append(&mut new7); assert_eq_events!(expected); @@ -3861,8 +4370,17 @@ fn paid_collator_commission_matches_config() { roll_to(8); // chooses top TotalSelectedCandidates (5), in order let mut expected = vec![ - Event::CollatorChosen(2, 1, 40), - Event::NewRound(5, 2, 1, 40), + Event::CollatorChosen { + round: 2, + collator_account: 1, + total_exposed_amount: 40, + }, + Event::NewRound { + starting_block: 5, + round: 2, + selected_collators_number: 1, + total_balance: 40, + }, ]; assert_eq_events!(expected.clone()); assert_ok!(ParachainStaking::join_candidates( @@ -3871,19 +4389,50 @@ fn paid_collator_commission_matches_config() { 100u32 )); assert_last_event!(MetaEvent::ParachainStaking( - Event::JoinedCollatorCandidates(4, 20u128, 60u128,) + Event::JoinedCollatorCandidates { + account: 4, + amount_locked: 20u128, + new_total_amt_locked: 60u128, + } )); roll_to(9); assert_ok!(ParachainStaking::delegate(Origin::signed(5), 4, 10, 10, 10)); assert_ok!(ParachainStaking::delegate(Origin::signed(6), 4, 10, 10, 10)); roll_to(11); let mut new = vec![ - Event::JoinedCollatorCandidates(4, 20, 60), - Event::Delegation(5, 10, 4, DelegatorAdded::AddedToTop { new_total: 30 }), - Event::Delegation(6, 10, 4, DelegatorAdded::AddedToTop { new_total: 40 }), - Event::CollatorChosen(3, 1, 40), - Event::CollatorChosen(3, 4, 40), - Event::NewRound(10, 3, 2, 80), + Event::JoinedCollatorCandidates { + account: 4, + amount_locked: 20, + new_total_amt_locked: 60, + }, + Event::Delegation { + delegator: 5, + locked_amount: 10, + candidate: 4, + delegator_position: DelegatorAdded::AddedToTop { new_total: 30 }, + }, + Event::Delegation { + delegator: 6, + locked_amount: 10, + candidate: 4, + delegator_position: DelegatorAdded::AddedToTop { new_total: 40 }, + }, + Event::CollatorChosen { + round: 3, + collator_account: 1, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 3, + collator_account: 4, + total_exposed_amount: 40, + }, + Event::NewRound { + starting_block: 10, + round: 3, + selected_collators_number: 2, + total_balance: 80, + }, ]; expected.append(&mut new); assert_eq_events!(expected.clone()); @@ -3893,15 +4442,50 @@ fn paid_collator_commission_matches_config() { // 20% of 10 is commission + due_portion (0) = 2 + 4 = 6 // all delegator payouts are 10-2 = 8 * stake_pct let mut new2 = vec![ - Event::CollatorChosen(4, 1, 40), - Event::CollatorChosen(4, 4, 40), - Event::NewRound(15, 4, 2, 80), - Event::CollatorChosen(5, 1, 40), - Event::CollatorChosen(5, 4, 40), - Event::NewRound(20, 5, 2, 80), - Event::Rewarded(4, 18), - Event::Rewarded(5, 6), - Event::Rewarded(6, 6), + Event::CollatorChosen { + round: 4, + collator_account: 1, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 4, + collator_account: 4, + total_exposed_amount: 40, + }, + Event::NewRound { + starting_block: 15, + round: 4, + selected_collators_number: 2, + total_balance: 80, + }, + Event::CollatorChosen { + round: 5, + collator_account: 1, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 5, + collator_account: 4, + total_exposed_amount: 40, + }, + Event::NewRound { + starting_block: 20, + round: 5, + selected_collators_number: 2, + total_balance: 80, + }, + Event::Rewarded { + account: 4, + rewards: 18, + }, + Event::Rewarded { + account: 5, + rewards: 6, + }, + Event::Rewarded { + account: 6, + rewards: 6, + }, ]; expected.append(&mut new2); assert_eq_events!(expected); @@ -3943,18 +4527,70 @@ fn collator_exit_executes_after_delay() { // holding them retroactively accountable for previous faults // (within the last T::SlashingWindow blocks) let expected = vec![ - Event::CollatorChosen(2, 1, 700), - Event::CollatorChosen(2, 2, 400), - Event::NewRound(5, 2, 2, 1100), - Event::CollatorChosen(3, 1, 700), - Event::CollatorChosen(3, 2, 400), - Event::NewRound(10, 3, 2, 1100), - Event::CandidateScheduledExit(3, 2, 5), - Event::CollatorChosen(4, 1, 700), - Event::NewRound(15, 4, 1, 700), - Event::CollatorChosen(5, 1, 700), - Event::NewRound(20, 5, 1, 700), - Event::CandidateLeft(2, 400, 700), + Event::CollatorChosen { + round: 2, + collator_account: 1, + total_exposed_amount: 700, + }, + Event::CollatorChosen { + round: 2, + collator_account: 2, + total_exposed_amount: 400, + }, + Event::NewRound { + starting_block: 5, + round: 2, + selected_collators_number: 2, + total_balance: 1100, + }, + Event::CollatorChosen { + round: 3, + collator_account: 1, + total_exposed_amount: 700, + }, + Event::CollatorChosen { + round: 3, + collator_account: 2, + total_exposed_amount: 400, + }, + Event::NewRound { + starting_block: 10, + round: 3, + selected_collators_number: 2, + total_balance: 1100, + }, + Event::CandidateScheduledExit { + exit_allowed_round: 3, + candidate: 2, + scheduled_exit: 5, + }, + Event::CollatorChosen { + round: 4, + collator_account: 1, + total_exposed_amount: 700, + }, + Event::NewRound { + starting_block: 15, + round: 4, + selected_collators_number: 1, + total_balance: 700, + }, + Event::CollatorChosen { + round: 5, + collator_account: 1, + total_exposed_amount: 700, + }, + Event::NewRound { + starting_block: 20, + round: 5, + selected_collators_number: 1, + total_balance: 700, + }, + Event::CandidateLeft { + ex_candidate: 2, + unlocked_amount: 400, + new_total_amt_locked: 700, + }, ]; assert_eq_events!(expected); }); @@ -3980,21 +4616,48 @@ fn collator_selection_chooses_top_candidates() { roll_to(8); // should choose top TotalSelectedCandidates (5), in order let expected = vec![ - Event::CollatorChosen(2, 1, 100), - Event::CollatorChosen(2, 2, 90), - Event::CollatorChosen(2, 3, 80), - Event::CollatorChosen(2, 4, 70), - Event::CollatorChosen(2, 5, 60), - Event::NewRound(5, 2, 5, 400), + Event::CollatorChosen { + round: 2, + collator_account: 1, + total_exposed_amount: 100, + }, + Event::CollatorChosen { + round: 2, + collator_account: 2, + total_exposed_amount: 90, + }, + Event::CollatorChosen { + round: 2, + collator_account: 3, + total_exposed_amount: 80, + }, + Event::CollatorChosen { + round: 2, + collator_account: 4, + total_exposed_amount: 70, + }, + Event::CollatorChosen { + round: 2, + collator_account: 5, + total_exposed_amount: 60, + }, + Event::NewRound { + starting_block: 5, + round: 2, + selected_collators_number: 5, + total_balance: 400, + }, ]; assert_eq_events!(expected.clone()); assert_ok!(ParachainStaking::schedule_leave_candidates( Origin::signed(6), 6 )); - assert_last_event!(MetaEvent::ParachainStaking(Event::CandidateScheduledExit( - 2, 6, 4 - ))); + assert_last_event!(MetaEvent::ParachainStaking(Event::CandidateScheduledExit { + exit_allowed_round: 2, + candidate: 6, + scheduled_exit: 4 + })); roll_to(21); assert_ok!(ParachainStaking::execute_leave_candidates( Origin::signed(6), @@ -4007,44 +4670,185 @@ fn collator_selection_chooses_top_candidates() { 100u32 )); assert_last_event!(MetaEvent::ParachainStaking( - Event::JoinedCollatorCandidates(6, 69u128, 469u128,) + Event::JoinedCollatorCandidates { + account: 6, + amount_locked: 69u128, + new_total_amt_locked: 469u128, + } )); roll_to(27); // should choose top TotalSelectedCandidates (5), in order let expected = vec![ - Event::CollatorChosen(2, 1, 100), - Event::CollatorChosen(2, 2, 90), - Event::CollatorChosen(2, 3, 80), - Event::CollatorChosen(2, 4, 70), - Event::CollatorChosen(2, 5, 60), - Event::NewRound(5, 2, 5, 400), - Event::CandidateScheduledExit(2, 6, 4), - Event::CollatorChosen(3, 1, 100), - Event::CollatorChosen(3, 2, 90), - Event::CollatorChosen(3, 3, 80), - Event::CollatorChosen(3, 4, 70), - Event::CollatorChosen(3, 5, 60), - Event::NewRound(10, 3, 5, 400), - Event::CollatorChosen(4, 1, 100), - Event::CollatorChosen(4, 2, 90), - Event::CollatorChosen(4, 3, 80), - Event::CollatorChosen(4, 4, 70), - Event::CollatorChosen(4, 5, 60), - Event::NewRound(15, 4, 5, 400), - Event::CollatorChosen(5, 1, 100), - Event::CollatorChosen(5, 2, 90), - Event::CollatorChosen(5, 3, 80), - Event::CollatorChosen(5, 4, 70), - Event::CollatorChosen(5, 5, 60), - Event::NewRound(20, 5, 5, 400), - Event::CandidateLeft(6, 50, 400), - Event::JoinedCollatorCandidates(6, 69, 469), - Event::CollatorChosen(6, 1, 100), - Event::CollatorChosen(6, 2, 90), - Event::CollatorChosen(6, 3, 80), - Event::CollatorChosen(6, 4, 70), - Event::CollatorChosen(6, 6, 69), - Event::NewRound(25, 6, 5, 409), + Event::CollatorChosen { + round: 2, + collator_account: 1, + total_exposed_amount: 100, + }, + Event::CollatorChosen { + round: 2, + collator_account: 2, + total_exposed_amount: 90, + }, + Event::CollatorChosen { + round: 2, + collator_account: 3, + total_exposed_amount: 80, + }, + Event::CollatorChosen { + round: 2, + collator_account: 4, + total_exposed_amount: 70, + }, + Event::CollatorChosen { + round: 2, + collator_account: 5, + total_exposed_amount: 60, + }, + Event::NewRound { + starting_block: 5, + round: 2, + selected_collators_number: 5, + total_balance: 400, + }, + Event::CandidateScheduledExit { + exit_allowed_round: 2, + candidate: 6, + scheduled_exit: 4, + }, + Event::CollatorChosen { + round: 3, + collator_account: 1, + total_exposed_amount: 100, + }, + Event::CollatorChosen { + round: 3, + collator_account: 2, + total_exposed_amount: 90, + }, + Event::CollatorChosen { + round: 3, + collator_account: 3, + total_exposed_amount: 80, + }, + Event::CollatorChosen { + round: 3, + collator_account: 4, + total_exposed_amount: 70, + }, + Event::CollatorChosen { + round: 3, + collator_account: 5, + total_exposed_amount: 60, + }, + Event::NewRound { + starting_block: 10, + round: 3, + selected_collators_number: 5, + total_balance: 400, + }, + Event::CollatorChosen { + round: 4, + collator_account: 1, + total_exposed_amount: 100, + }, + Event::CollatorChosen { + round: 4, + collator_account: 2, + total_exposed_amount: 90, + }, + Event::CollatorChosen { + round: 4, + collator_account: 3, + total_exposed_amount: 80, + }, + Event::CollatorChosen { + round: 4, + collator_account: 4, + total_exposed_amount: 70, + }, + Event::CollatorChosen { + round: 4, + collator_account: 5, + total_exposed_amount: 60, + }, + Event::NewRound { + starting_block: 15, + round: 4, + selected_collators_number: 5, + total_balance: 400, + }, + Event::CollatorChosen { + round: 5, + collator_account: 1, + total_exposed_amount: 100, + }, + Event::CollatorChosen { + round: 5, + collator_account: 2, + total_exposed_amount: 90, + }, + Event::CollatorChosen { + round: 5, + collator_account: 3, + total_exposed_amount: 80, + }, + Event::CollatorChosen { + round: 5, + collator_account: 4, + total_exposed_amount: 70, + }, + Event::CollatorChosen { + round: 5, + collator_account: 5, + total_exposed_amount: 60, + }, + Event::NewRound { + starting_block: 20, + round: 5, + selected_collators_number: 5, + total_balance: 400, + }, + Event::CandidateLeft { + ex_candidate: 6, + unlocked_amount: 50, + new_total_amt_locked: 400, + }, + Event::JoinedCollatorCandidates { + account: 6, + amount_locked: 69, + new_total_amt_locked: 469, + }, + Event::CollatorChosen { + round: 6, + collator_account: 1, + total_exposed_amount: 100, + }, + Event::CollatorChosen { + round: 6, + collator_account: 2, + total_exposed_amount: 90, + }, + Event::CollatorChosen { + round: 6, + collator_account: 3, + total_exposed_amount: 80, + }, + Event::CollatorChosen { + round: 6, + collator_account: 4, + total_exposed_amount: 70, + }, + Event::CollatorChosen { + round: 6, + collator_account: 6, + total_exposed_amount: 69, + }, + Event::NewRound { + starting_block: 25, + round: 6, + selected_collators_number: 5, + total_balance: 409, + }, ]; assert_eq_events!(expected); }); @@ -4070,12 +4874,37 @@ fn payout_distribution_to_solo_collators() { roll_to(8); // should choose top TotalCandidatesSelected (5), in order let mut expected = vec![ - Event::CollatorChosen(2, 1, 100), - Event::CollatorChosen(2, 2, 90), - Event::CollatorChosen(2, 3, 80), - Event::CollatorChosen(2, 4, 70), - Event::CollatorChosen(2, 5, 60), - Event::NewRound(5, 2, 5, 400), + Event::CollatorChosen { + round: 2, + collator_account: 1, + total_exposed_amount: 100, + }, + Event::CollatorChosen { + round: 2, + collator_account: 2, + total_exposed_amount: 90, + }, + Event::CollatorChosen { + round: 2, + collator_account: 3, + total_exposed_amount: 80, + }, + Event::CollatorChosen { + round: 2, + collator_account: 4, + total_exposed_amount: 70, + }, + Event::CollatorChosen { + round: 2, + collator_account: 5, + total_exposed_amount: 60, + }, + Event::NewRound { + starting_block: 5, + round: 2, + selected_collators_number: 5, + total_balance: 400, + }, ]; assert_eq_events!(expected.clone()); // ~ set block author as 1 for all blocks this round @@ -4083,19 +4912,72 @@ fn payout_distribution_to_solo_collators() { roll_to(16); // pay total issuance to 1 let mut new = vec![ - Event::CollatorChosen(3, 1, 100), - Event::CollatorChosen(3, 2, 90), - Event::CollatorChosen(3, 3, 80), - Event::CollatorChosen(3, 4, 70), - Event::CollatorChosen(3, 5, 60), - Event::NewRound(10, 3, 5, 400), - Event::CollatorChosen(4, 1, 100), - Event::CollatorChosen(4, 2, 90), - Event::CollatorChosen(4, 3, 80), - Event::CollatorChosen(4, 4, 70), - Event::CollatorChosen(4, 5, 60), - Event::NewRound(15, 4, 5, 400), - Event::Rewarded(1, 305), + Event::CollatorChosen { + round: 3, + collator_account: 1, + total_exposed_amount: 100, + }, + Event::CollatorChosen { + round: 3, + collator_account: 2, + total_exposed_amount: 90, + }, + Event::CollatorChosen { + round: 3, + collator_account: 3, + total_exposed_amount: 80, + }, + Event::CollatorChosen { + round: 3, + collator_account: 4, + total_exposed_amount: 70, + }, + Event::CollatorChosen { + round: 3, + collator_account: 5, + total_exposed_amount: 60, + }, + Event::NewRound { + starting_block: 10, + round: 3, + selected_collators_number: 5, + total_balance: 400, + }, + Event::CollatorChosen { + round: 4, + collator_account: 1, + total_exposed_amount: 100, + }, + Event::CollatorChosen { + round: 4, + collator_account: 2, + total_exposed_amount: 90, + }, + Event::CollatorChosen { + round: 4, + collator_account: 3, + total_exposed_amount: 80, + }, + Event::CollatorChosen { + round: 4, + collator_account: 4, + total_exposed_amount: 70, + }, + Event::CollatorChosen { + round: 4, + collator_account: 5, + total_exposed_amount: 60, + }, + Event::NewRound { + starting_block: 15, + round: 4, + selected_collators_number: 5, + total_balance: 400, + }, + Event::Rewarded { + account: 1, + rewards: 305, + }, ]; expected.append(&mut new); assert_eq_events!(expected.clone()); @@ -4106,20 +4988,76 @@ fn payout_distribution_to_solo_collators() { roll_to(26); // pay 60% total issuance to 1 and 40% total issuance to 2 let mut new1 = vec![ - Event::CollatorChosen(5, 1, 100), - Event::CollatorChosen(5, 2, 90), - Event::CollatorChosen(5, 3, 80), - Event::CollatorChosen(5, 4, 70), - Event::CollatorChosen(5, 5, 60), - Event::NewRound(20, 5, 5, 400), - Event::CollatorChosen(6, 1, 100), - Event::CollatorChosen(6, 2, 90), - Event::CollatorChosen(6, 3, 80), - Event::CollatorChosen(6, 4, 70), - Event::CollatorChosen(6, 5, 60), - Event::NewRound(25, 6, 5, 400), - Event::Rewarded(1, 192), - Event::Rewarded(2, 128), + Event::CollatorChosen { + round: 5, + collator_account: 1, + total_exposed_amount: 100, + }, + Event::CollatorChosen { + round: 5, + collator_account: 2, + total_exposed_amount: 90, + }, + Event::CollatorChosen { + round: 5, + collator_account: 3, + total_exposed_amount: 80, + }, + Event::CollatorChosen { + round: 5, + collator_account: 4, + total_exposed_amount: 70, + }, + Event::CollatorChosen { + round: 5, + collator_account: 5, + total_exposed_amount: 60, + }, + Event::NewRound { + starting_block: 20, + round: 5, + selected_collators_number: 5, + total_balance: 400, + }, + Event::CollatorChosen { + round: 6, + collator_account: 1, + total_exposed_amount: 100, + }, + Event::CollatorChosen { + round: 6, + collator_account: 2, + total_exposed_amount: 90, + }, + Event::CollatorChosen { + round: 6, + collator_account: 3, + total_exposed_amount: 80, + }, + Event::CollatorChosen { + round: 6, + collator_account: 4, + total_exposed_amount: 70, + }, + Event::CollatorChosen { + round: 6, + collator_account: 5, + total_exposed_amount: 60, + }, + Event::NewRound { + starting_block: 25, + round: 6, + selected_collators_number: 5, + total_balance: 400, + }, + Event::Rewarded { + account: 1, + rewards: 192, + }, + Event::Rewarded { + account: 2, + rewards: 128, + }, ]; expected.append(&mut new1); assert_eq_events!(expected.clone()); @@ -4132,23 +5070,88 @@ fn payout_distribution_to_solo_collators() { roll_to(39); // pay 20% issuance for all collators let mut new2 = vec![ - Event::CollatorChosen(7, 1, 100), - Event::CollatorChosen(7, 2, 90), - Event::CollatorChosen(7, 3, 80), - Event::CollatorChosen(7, 4, 70), - Event::CollatorChosen(7, 5, 60), - Event::NewRound(30, 7, 5, 400), - Event::CollatorChosen(8, 1, 100), - Event::CollatorChosen(8, 2, 90), - Event::CollatorChosen(8, 3, 80), - Event::CollatorChosen(8, 4, 70), - Event::CollatorChosen(8, 5, 60), - Event::NewRound(35, 8, 5, 400), - Event::Rewarded(5, 67), - Event::Rewarded(3, 67), - Event::Rewarded(4, 67), - Event::Rewarded(1, 67), - Event::Rewarded(2, 67), + Event::CollatorChosen { + round: 7, + collator_account: 1, + total_exposed_amount: 100, + }, + Event::CollatorChosen { + round: 7, + collator_account: 2, + total_exposed_amount: 90, + }, + Event::CollatorChosen { + round: 7, + collator_account: 3, + total_exposed_amount: 80, + }, + Event::CollatorChosen { + round: 7, + collator_account: 4, + total_exposed_amount: 70, + }, + Event::CollatorChosen { + round: 7, + collator_account: 5, + total_exposed_amount: 60, + }, + Event::NewRound { + starting_block: 30, + round: 7, + selected_collators_number: 5, + total_balance: 400, + }, + Event::CollatorChosen { + round: 8, + collator_account: 1, + total_exposed_amount: 100, + }, + Event::CollatorChosen { + round: 8, + collator_account: 2, + total_exposed_amount: 90, + }, + Event::CollatorChosen { + round: 8, + collator_account: 3, + total_exposed_amount: 80, + }, + Event::CollatorChosen { + round: 8, + collator_account: 4, + total_exposed_amount: 70, + }, + Event::CollatorChosen { + round: 8, + collator_account: 5, + total_exposed_amount: 60, + }, + Event::NewRound { + starting_block: 35, + round: 8, + selected_collators_number: 5, + total_balance: 400, + }, + Event::Rewarded { + account: 5, + rewards: 67, + }, + Event::Rewarded { + account: 3, + rewards: 67, + }, + Event::Rewarded { + account: 4, + rewards: 67, + }, + Event::Rewarded { + account: 1, + rewards: 67, + }, + Event::Rewarded { + account: 2, + rewards: 67, + }, ]; expected.append(&mut new2); assert_eq_events!(expected); @@ -4192,12 +5195,37 @@ fn multiple_delegations() { roll_to(8); // chooses top TotalSelectedCandidates (5), in order let mut expected = vec![ - Event::CollatorChosen(2, 1, 50), - Event::CollatorChosen(2, 2, 40), - Event::CollatorChosen(2, 3, 20), - Event::CollatorChosen(2, 4, 20), - Event::CollatorChosen(2, 5, 10), - Event::NewRound(5, 2, 5, 140), + Event::CollatorChosen { + round: 2, + collator_account: 1, + total_exposed_amount: 50, + }, + Event::CollatorChosen { + round: 2, + collator_account: 2, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 2, + collator_account: 3, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 2, + collator_account: 4, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 2, + collator_account: 5, + total_exposed_amount: 10, + }, + Event::NewRound { + starting_block: 5, + round: 2, + selected_collators_number: 5, + total_balance: 140, + }, ]; assert_eq_events!(expected.clone()); assert_ok!(ParachainStaking::delegate(Origin::signed(6), 2, 10, 10, 10)); @@ -4205,21 +5233,86 @@ fn multiple_delegations() { assert_ok!(ParachainStaking::delegate(Origin::signed(6), 4, 10, 10, 10)); roll_to(16); let mut new = vec![ - Event::Delegation(6, 10, 2, DelegatorAdded::AddedToTop { new_total: 50 }), - Event::Delegation(6, 10, 3, DelegatorAdded::AddedToTop { new_total: 30 }), - Event::Delegation(6, 10, 4, DelegatorAdded::AddedToTop { new_total: 30 }), - Event::CollatorChosen(3, 1, 50), - Event::CollatorChosen(3, 2, 50), - Event::CollatorChosen(3, 3, 30), - Event::CollatorChosen(3, 4, 30), - Event::CollatorChosen(3, 5, 10), - Event::NewRound(10, 3, 5, 170), - Event::CollatorChosen(4, 1, 50), - Event::CollatorChosen(4, 2, 50), - Event::CollatorChosen(4, 3, 30), - Event::CollatorChosen(4, 4, 30), - Event::CollatorChosen(4, 5, 10), - Event::NewRound(15, 4, 5, 170), + Event::Delegation { + delegator: 6, + locked_amount: 10, + candidate: 2, + delegator_position: DelegatorAdded::AddedToTop { new_total: 50 }, + }, + Event::Delegation { + delegator: 6, + locked_amount: 10, + candidate: 3, + delegator_position: DelegatorAdded::AddedToTop { new_total: 30 }, + }, + Event::Delegation { + delegator: 6, + locked_amount: 10, + candidate: 4, + delegator_position: DelegatorAdded::AddedToTop { new_total: 30 }, + }, + Event::CollatorChosen { + round: 3, + collator_account: 1, + total_exposed_amount: 50, + }, + Event::CollatorChosen { + round: 3, + collator_account: 2, + total_exposed_amount: 50, + }, + Event::CollatorChosen { + round: 3, + collator_account: 3, + total_exposed_amount: 30, + }, + Event::CollatorChosen { + round: 3, + collator_account: 4, + total_exposed_amount: 30, + }, + Event::CollatorChosen { + round: 3, + collator_account: 5, + total_exposed_amount: 10, + }, + Event::NewRound { + starting_block: 10, + round: 3, + selected_collators_number: 5, + total_balance: 170, + }, + Event::CollatorChosen { + round: 4, + collator_account: 1, + total_exposed_amount: 50, + }, + Event::CollatorChosen { + round: 4, + collator_account: 2, + total_exposed_amount: 50, + }, + Event::CollatorChosen { + round: 4, + collator_account: 3, + total_exposed_amount: 30, + }, + Event::CollatorChosen { + round: 4, + collator_account: 4, + total_exposed_amount: 30, + }, + Event::CollatorChosen { + round: 4, + collator_account: 5, + total_exposed_amount: 10, + }, + Event::NewRound { + starting_block: 15, + round: 4, + selected_collators_number: 5, + total_balance: 170, + }, ]; expected.append(&mut new); assert_eq_events!(expected.clone()); @@ -4234,20 +5327,80 @@ fn multiple_delegations() { ),); roll_to(26); let mut new2 = vec![ - Event::CollatorChosen(5, 1, 50), - Event::CollatorChosen(5, 2, 50), - Event::CollatorChosen(5, 3, 30), - Event::CollatorChosen(5, 4, 30), - Event::CollatorChosen(5, 5, 10), - Event::NewRound(20, 5, 5, 170), - Event::Delegation(7, 80, 2, DelegatorAdded::AddedToTop { new_total: 130 }), - Event::Delegation(10, 10, 2, DelegatorAdded::AddedToBottom), - Event::CollatorChosen(6, 1, 50), - Event::CollatorChosen(6, 2, 130), - Event::CollatorChosen(6, 3, 30), - Event::CollatorChosen(6, 4, 30), - Event::CollatorChosen(6, 5, 10), - Event::NewRound(25, 6, 5, 250), + Event::CollatorChosen { + round: 5, + collator_account: 1, + total_exposed_amount: 50, + }, + Event::CollatorChosen { + round: 5, + collator_account: 2, + total_exposed_amount: 50, + }, + Event::CollatorChosen { + round: 5, + collator_account: 3, + total_exposed_amount: 30, + }, + Event::CollatorChosen { + round: 5, + collator_account: 4, + total_exposed_amount: 30, + }, + Event::CollatorChosen { + round: 5, + collator_account: 5, + total_exposed_amount: 10, + }, + Event::NewRound { + starting_block: 20, + round: 5, + selected_collators_number: 5, + total_balance: 170, + }, + Event::Delegation { + delegator: 7, + locked_amount: 80, + candidate: 2, + delegator_position: DelegatorAdded::AddedToTop { new_total: 130 }, + }, + Event::Delegation { + delegator: 10, + locked_amount: 10, + candidate: 2, + delegator_position: DelegatorAdded::AddedToBottom, + }, + Event::CollatorChosen { + round: 6, + collator_account: 1, + total_exposed_amount: 50, + }, + Event::CollatorChosen { + round: 6, + collator_account: 2, + total_exposed_amount: 130, + }, + Event::CollatorChosen { + round: 6, + collator_account: 3, + total_exposed_amount: 30, + }, + Event::CollatorChosen { + round: 6, + collator_account: 4, + total_exposed_amount: 30, + }, + Event::CollatorChosen { + round: 6, + collator_account: 5, + total_exposed_amount: 10, + }, + Event::NewRound { + starting_block: 25, + round: 6, + selected_collators_number: 5, + total_balance: 250, + }, ]; expected.append(&mut new2); assert_eq_events!(expected.clone()); @@ -4255,17 +5408,44 @@ fn multiple_delegations() { Origin::signed(2), 5 )); - assert_last_event!(MetaEvent::ParachainStaking(Event::CandidateScheduledExit( - 6, 2, 8 - ))); + assert_last_event!(MetaEvent::ParachainStaking(Event::CandidateScheduledExit { + exit_allowed_round: 6, + candidate: 2, + scheduled_exit: 8 + })); roll_to(31); let mut new3 = vec![ - Event::CandidateScheduledExit(6, 2, 8), - Event::CollatorChosen(7, 1, 50), - Event::CollatorChosen(7, 3, 30), - Event::CollatorChosen(7, 4, 30), - Event::CollatorChosen(7, 5, 10), - Event::NewRound(30, 7, 4, 120), + Event::CandidateScheduledExit { + exit_allowed_round: 6, + candidate: 2, + scheduled_exit: 8, + }, + Event::CollatorChosen { + round: 7, + collator_account: 1, + total_exposed_amount: 50, + }, + Event::CollatorChosen { + round: 7, + collator_account: 3, + total_exposed_amount: 30, + }, + Event::CollatorChosen { + round: 7, + collator_account: 4, + total_exposed_amount: 30, + }, + Event::CollatorChosen { + round: 7, + collator_account: 5, + total_exposed_amount: 10, + }, + Event::NewRound { + starting_block: 30, + round: 7, + selected_collators_number: 4, + total_balance: 120, + }, ]; expected.append(&mut new3); assert_eq_events!(expected); @@ -4404,12 +5584,37 @@ fn payouts_follow_delegation_changes() { roll_to(8); // chooses top TotalSelectedCandidates (5), in order let mut expected = vec![ - Event::CollatorChosen(2, 1, 50), - Event::CollatorChosen(2, 2, 40), - Event::CollatorChosen(2, 3, 20), - Event::CollatorChosen(2, 4, 20), - Event::CollatorChosen(2, 5, 10), - Event::NewRound(5, 2, 5, 140), + Event::CollatorChosen { + round: 2, + collator_account: 1, + total_exposed_amount: 50, + }, + Event::CollatorChosen { + round: 2, + collator_account: 2, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 2, + collator_account: 3, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 2, + collator_account: 4, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 2, + collator_account: 5, + total_exposed_amount: 10, + }, + Event::NewRound { + starting_block: 5, + round: 2, + selected_collators_number: 5, + total_balance: 140, + }, ]; assert_eq_events!(expected.clone()); // ~ set block author as 1 for all blocks this round @@ -4417,22 +5622,84 @@ fn payouts_follow_delegation_changes() { roll_to(16); // distribute total issuance to collator 1 and its delegators 6, 7, 19 let mut new = vec![ - Event::CollatorChosen(3, 1, 50), - Event::CollatorChosen(3, 2, 40), - Event::CollatorChosen(3, 3, 20), - Event::CollatorChosen(3, 4, 20), - Event::CollatorChosen(3, 5, 10), - Event::NewRound(10, 3, 5, 140), - Event::CollatorChosen(4, 1, 50), - Event::CollatorChosen(4, 2, 40), - Event::CollatorChosen(4, 3, 20), - Event::CollatorChosen(4, 4, 20), - Event::CollatorChosen(4, 5, 10), - Event::NewRound(15, 4, 5, 140), - Event::Rewarded(1, 26), - Event::Rewarded(6, 8), - Event::Rewarded(7, 8), - Event::Rewarded(10, 8), + Event::CollatorChosen { + round: 3, + collator_account: 1, + total_exposed_amount: 50, + }, + Event::CollatorChosen { + round: 3, + collator_account: 2, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 3, + collator_account: 3, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 3, + collator_account: 4, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 3, + collator_account: 5, + total_exposed_amount: 10, + }, + Event::NewRound { + starting_block: 10, + round: 3, + selected_collators_number: 5, + total_balance: 140, + }, + Event::CollatorChosen { + round: 4, + collator_account: 1, + total_exposed_amount: 50, + }, + Event::CollatorChosen { + round: 4, + collator_account: 2, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 4, + collator_account: 3, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 4, + collator_account: 4, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 4, + collator_account: 5, + total_exposed_amount: 10, + }, + Event::NewRound { + starting_block: 15, + round: 4, + selected_collators_number: 5, + total_balance: 140, + }, + Event::Rewarded { + account: 1, + rewards: 26, + }, + Event::Rewarded { + account: 6, + rewards: 8, + }, + Event::Rewarded { + account: 7, + rewards: 8, + }, + Event::Rewarded { + account: 10, + rewards: 8, + }, ]; expected.append(&mut new); assert_eq_events!(expected.clone()); @@ -4458,29 +5725,115 @@ fn payouts_follow_delegation_changes() { )); // keep paying 6 (note: inflation is in terms of total issuance so that's why 1 is 21) let mut new2 = vec![ - Event::DelegatorExitScheduled(4, 6, 6), - Event::CollatorChosen(5, 1, 50), - Event::CollatorChosen(5, 2, 40), - Event::CollatorChosen(5, 3, 20), - Event::CollatorChosen(5, 4, 20), - Event::CollatorChosen(5, 5, 10), - Event::NewRound(20, 5, 5, 140), - Event::Rewarded(1, 27), - Event::Rewarded(6, 8), - Event::Rewarded(7, 8), - Event::Rewarded(10, 8), - Event::CollatorChosen(6, 1, 50), - Event::CollatorChosen(6, 2, 40), - Event::CollatorChosen(6, 3, 20), - Event::CollatorChosen(6, 4, 20), - Event::CollatorChosen(6, 5, 10), - Event::NewRound(25, 6, 5, 140), - Event::Rewarded(1, 29), - Event::Rewarded(6, 9), - Event::Rewarded(7, 9), - Event::Rewarded(10, 9), - Event::DelegatorLeftCandidate(6, 1, 10, 40), - Event::DelegatorLeft(6, 10), + Event::DelegatorExitScheduled { + round: 4, + delegator: 6, + scheduled_exit: 6, + }, + Event::CollatorChosen { + round: 5, + collator_account: 1, + total_exposed_amount: 50, + }, + Event::CollatorChosen { + round: 5, + collator_account: 2, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 5, + collator_account: 3, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 5, + collator_account: 4, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 5, + collator_account: 5, + total_exposed_amount: 10, + }, + Event::NewRound { + starting_block: 20, + round: 5, + selected_collators_number: 5, + total_balance: 140, + }, + Event::Rewarded { + account: 1, + rewards: 27, + }, + Event::Rewarded { + account: 6, + rewards: 8, + }, + Event::Rewarded { + account: 7, + rewards: 8, + }, + Event::Rewarded { + account: 10, + rewards: 8, + }, + Event::CollatorChosen { + round: 6, + collator_account: 1, + total_exposed_amount: 50, + }, + Event::CollatorChosen { + round: 6, + collator_account: 2, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 6, + collator_account: 3, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 6, + collator_account: 4, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 6, + collator_account: 5, + total_exposed_amount: 10, + }, + Event::NewRound { + starting_block: 25, + round: 6, + selected_collators_number: 5, + total_balance: 140, + }, + Event::Rewarded { + account: 1, + rewards: 29, + }, + Event::Rewarded { + account: 6, + rewards: 9, + }, + Event::Rewarded { + account: 7, + rewards: 9, + }, + Event::Rewarded { + account: 10, + rewards: 9, + }, + Event::DelegatorLeftCandidate { + delegator: 6, + candidate: 1, + unstaked_amount: 10, + total_candidate_staked: 40, + }, + Event::DelegatorLeft { + delegator: 6, + unstaked_amount: 10, + }, ]; expected.append(&mut new2); assert_eq_events!(expected.clone()); @@ -4489,26 +5842,100 @@ fn payouts_follow_delegation_changes() { roll_to(35); // keep paying 6 let mut new3 = vec![ - Event::CollatorChosen(7, 1, 40), - Event::CollatorChosen(7, 2, 40), - Event::CollatorChosen(7, 3, 20), - Event::CollatorChosen(7, 4, 20), - Event::CollatorChosen(7, 5, 10), - Event::NewRound(30, 7, 5, 130), - Event::Rewarded(1, 30), - Event::Rewarded(6, 9), - Event::Rewarded(7, 9), - Event::Rewarded(10, 9), - Event::CollatorChosen(8, 1, 40), - Event::CollatorChosen(8, 2, 40), - Event::CollatorChosen(8, 3, 20), - Event::CollatorChosen(8, 4, 20), - Event::CollatorChosen(8, 5, 10), - Event::NewRound(35, 8, 5, 130), - Event::Rewarded(1, 32), - Event::Rewarded(6, 10), - Event::Rewarded(7, 10), - Event::Rewarded(10, 10), + Event::CollatorChosen { + round: 7, + collator_account: 1, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 7, + collator_account: 2, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 7, + collator_account: 3, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 7, + collator_account: 4, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 7, + collator_account: 5, + total_exposed_amount: 10, + }, + Event::NewRound { + starting_block: 30, + round: 7, + selected_collators_number: 5, + total_balance: 130, + }, + Event::Rewarded { + account: 1, + rewards: 30, + }, + Event::Rewarded { + account: 6, + rewards: 9, + }, + Event::Rewarded { + account: 7, + rewards: 9, + }, + Event::Rewarded { + account: 10, + rewards: 9, + }, + Event::CollatorChosen { + round: 8, + collator_account: 1, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 8, + collator_account: 2, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 8, + collator_account: 3, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 8, + collator_account: 4, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 8, + collator_account: 5, + total_exposed_amount: 10, + }, + Event::NewRound { + starting_block: 35, + round: 8, + selected_collators_number: 5, + total_balance: 130, + }, + Event::Rewarded { + account: 1, + rewards: 32, + }, + Event::Rewarded { + account: 6, + rewards: 10, + }, + Event::Rewarded { + account: 7, + rewards: 10, + }, + Event::Rewarded { + account: 10, + rewards: 10, + }, ]; expected.append(&mut new3); assert_eq_events!(expected.clone()); @@ -4516,15 +5943,49 @@ fn payouts_follow_delegation_changes() { roll_to(40); // no more paying 6 let mut new4 = vec![ - Event::CollatorChosen(9, 1, 40), - Event::CollatorChosen(9, 2, 40), - Event::CollatorChosen(9, 3, 20), - Event::CollatorChosen(9, 4, 20), - Event::CollatorChosen(9, 5, 10), - Event::NewRound(40, 9, 5, 130), - Event::Rewarded(1, 38), - Event::Rewarded(7, 13), - Event::Rewarded(10, 13), + Event::CollatorChosen { + round: 9, + collator_account: 1, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 9, + collator_account: 2, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 9, + collator_account: 3, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 9, + collator_account: 4, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 9, + collator_account: 5, + total_exposed_amount: 10, + }, + Event::NewRound { + starting_block: 40, + round: 9, + selected_collators_number: 5, + total_balance: 130, + }, + Event::Rewarded { + account: 1, + rewards: 38, + }, + Event::Rewarded { + account: 7, + rewards: 13, + }, + Event::Rewarded { + account: 10, + rewards: 13, + }, ]; expected.append(&mut new4); assert_eq_events!(expected.clone()); @@ -4533,16 +5994,55 @@ fn payouts_follow_delegation_changes() { roll_to(45); // new delegation is not rewarded yet let mut new5 = vec![ - Event::Delegation(8, 10, 1, DelegatorAdded::AddedToTop { new_total: 50 }), - Event::CollatorChosen(10, 1, 50), - Event::CollatorChosen(10, 2, 40), - Event::CollatorChosen(10, 3, 20), - Event::CollatorChosen(10, 4, 20), - Event::CollatorChosen(10, 5, 10), - Event::NewRound(45, 10, 5, 140), - Event::Rewarded(1, 40), - Event::Rewarded(7, 13), - Event::Rewarded(10, 13), + Event::Delegation { + delegator: 8, + locked_amount: 10, + candidate: 1, + delegator_position: DelegatorAdded::AddedToTop { new_total: 50 }, + }, + Event::CollatorChosen { + round: 10, + collator_account: 1, + total_exposed_amount: 50, + }, + Event::CollatorChosen { + round: 10, + collator_account: 2, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 10, + collator_account: 3, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 10, + collator_account: 4, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 10, + collator_account: 5, + total_exposed_amount: 10, + }, + Event::NewRound { + starting_block: 45, + round: 10, + selected_collators_number: 5, + total_balance: 140, + }, + Event::Rewarded { + account: 1, + rewards: 40, + }, + Event::Rewarded { + account: 7, + rewards: 13, + }, + Event::Rewarded { + account: 10, + rewards: 13, + }, ]; expected.append(&mut new5); assert_eq_events!(expected.clone()); @@ -4550,15 +6050,49 @@ fn payouts_follow_delegation_changes() { roll_to(50); // new delegation not rewarded yet let mut new6 = vec![ - Event::CollatorChosen(11, 1, 50), - Event::CollatorChosen(11, 2, 40), - Event::CollatorChosen(11, 3, 20), - Event::CollatorChosen(11, 4, 20), - Event::CollatorChosen(11, 5, 10), - Event::NewRound(50, 11, 5, 140), - Event::Rewarded(1, 42), - Event::Rewarded(7, 14), - Event::Rewarded(10, 14), + Event::CollatorChosen { + round: 11, + collator_account: 1, + total_exposed_amount: 50, + }, + Event::CollatorChosen { + round: 11, + collator_account: 2, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 11, + collator_account: 3, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 11, + collator_account: 4, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 11, + collator_account: 5, + total_exposed_amount: 10, + }, + Event::NewRound { + starting_block: 50, + round: 11, + selected_collators_number: 5, + total_balance: 140, + }, + Event::Rewarded { + account: 1, + rewards: 42, + }, + Event::Rewarded { + account: 7, + rewards: 14, + }, + Event::Rewarded { + account: 10, + rewards: 14, + }, ]; expected.append(&mut new6); assert_eq_events!(expected.clone()); @@ -4566,16 +6100,53 @@ fn payouts_follow_delegation_changes() { // new delegation is rewarded for first time // 2 rounds after joining (`RewardPaymentDelay` = 2) let mut new7 = vec![ - Event::CollatorChosen(12, 1, 50), - Event::CollatorChosen(12, 2, 40), - Event::CollatorChosen(12, 3, 20), - Event::CollatorChosen(12, 4, 20), - Event::CollatorChosen(12, 5, 10), - Event::NewRound(55, 12, 5, 140), - Event::Rewarded(1, 39), - Event::Rewarded(7, 12), - Event::Rewarded(10, 12), - Event::Rewarded(8, 12), + Event::CollatorChosen { + round: 12, + collator_account: 1, + total_exposed_amount: 50, + }, + Event::CollatorChosen { + round: 12, + collator_account: 2, + total_exposed_amount: 40, + }, + Event::CollatorChosen { + round: 12, + collator_account: 3, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 12, + collator_account: 4, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 12, + collator_account: 5, + total_exposed_amount: 10, + }, + Event::NewRound { + starting_block: 55, + round: 12, + selected_collators_number: 5, + total_balance: 140, + }, + Event::Rewarded { + account: 1, + rewards: 39, + }, + Event::Rewarded { + account: 7, + rewards: 12, + }, + Event::Rewarded { + account: 10, + rewards: 12, + }, + Event::Rewarded { + account: 8, + rewards: 12, + }, ]; expected.append(&mut new7); assert_eq_events!(expected); @@ -4748,7 +6319,12 @@ fn only_top_collators_are_counted() { 1, 8 )); - assert_event_emitted!(Event::DelegationIncreased(3, 1, 8, true)); + assert_event_emitted!(Event::DelegationIncreased { + delegator: 3, + candidate: 1, + amount: 8, + in_top: true, + }); let collator_state = ParachainStaking::candidate_info(1).unwrap(); // 16 + 17 + 18 + 19 + 20 = 90 (top 4 + self bond) assert_eq!(collator_state.total_counted, 90); @@ -4758,7 +6334,12 @@ fn only_top_collators_are_counted() { 1, 8 )); - assert_event_emitted!(Event::DelegationIncreased(4, 1, 8, true)); + assert_event_emitted!(Event::DelegationIncreased { + delegator: 4, + candidate: 1, + amount: 8, + in_top: true, + }); let collator_state = ParachainStaking::candidate_info(1).unwrap(); // 17 + 18 + 19 + 20 + 20 = 94 (top 4 + self bond) assert_eq!(collator_state.total_counted, 94); @@ -4768,7 +6349,12 @@ fn only_top_collators_are_counted() { 1, 8 )); - assert_event_emitted!(Event::DelegationIncreased(5, 1, 8, true)); + assert_event_emitted!(Event::DelegationIncreased { + delegator: 5, + candidate: 1, + amount: 8, + in_top: true, + }); let collator_state = ParachainStaking::candidate_info(1).unwrap(); // 18 + 19 + 20 + 21 + 20 = 98 (top 4 + self bond) assert_eq!(collator_state.total_counted, 98); @@ -4778,7 +6364,12 @@ fn only_top_collators_are_counted() { 1, 8 )); - assert_event_emitted!(Event::DelegationIncreased(6, 1, 8, true)); + assert_event_emitted!(Event::DelegationIncreased { + delegator: 6, + candidate: 1, + amount: 8, + in_top: true, + }); let collator_state = ParachainStaking::candidate_info(1).unwrap(); // 19 + 20 + 21 + 22 + 20 = 102 (top 4 + self bond) assert_eq!(collator_state.total_counted, 102); @@ -4809,18 +6400,23 @@ fn delegation_events_convey_correct_position() { assert_eq!(collator1_state.total_counted, 70); // Top delegations are full, new highest delegation is made assert_ok!(ParachainStaking::delegate(Origin::signed(7), 1, 15, 10, 10)); - assert_event_emitted!(Event::Delegation( - 7, - 15, - 1, - DelegatorAdded::AddedToTop { new_total: 74 }, - )); + assert_event_emitted!(Event::Delegation { + delegator: 7, + locked_amount: 15, + candidate: 1, + delegator_position: DelegatorAdded::AddedToTop { new_total: 74 }, + }); let collator1_state = ParachainStaking::candidate_info(1).unwrap(); // 12 + 13 + 14 + 15 + 20 = 70 (top 4 + self bond) assert_eq!(collator1_state.total_counted, 74); // New delegation is added to the bottom assert_ok!(ParachainStaking::delegate(Origin::signed(8), 1, 10, 10, 10)); - assert_event_emitted!(Event::Delegation(8, 10, 1, DelegatorAdded::AddedToBottom)); + assert_event_emitted!(Event::Delegation { + delegator: 8, + locked_amount: 10, + candidate: 1, + delegator_position: DelegatorAdded::AddedToBottom, + }); let collator1_state = ParachainStaking::candidate_info(1).unwrap(); // 12 + 13 + 14 + 15 + 20 = 70 (top 4 + self bond) assert_eq!(collator1_state.total_counted, 74); @@ -4830,7 +6426,12 @@ fn delegation_events_convey_correct_position() { 1, 3 )); - assert_event_emitted!(Event::DelegationIncreased(8, 1, 3, true)); + assert_event_emitted!(Event::DelegationIncreased { + delegator: 8, + candidate: 1, + amount: 3, + in_top: true, + }); let collator1_state = ParachainStaking::candidate_info(1).unwrap(); // 13 + 13 + 14 + 15 + 20 = 75 (top 4 + self bond) assert_eq!(collator1_state.total_counted, 75); @@ -4840,7 +6441,12 @@ fn delegation_events_convey_correct_position() { 1, 1 )); - assert_event_emitted!(Event::DelegationIncreased(3, 1, 1, false)); + assert_event_emitted!(Event::DelegationIncreased { + delegator: 3, + candidate: 1, + amount: 1, + in_top: false, + }); let collator1_state = ParachainStaking::candidate_info(1).unwrap(); // 13 + 13 + 14 + 15 + 20 = 75 (top 4 + self bond) assert_eq!(collator1_state.total_counted, 75); @@ -4850,14 +6456,24 @@ fn delegation_events_convey_correct_position() { 1, 2 )); - assert_event_emitted!(Event::DelegationDecreaseScheduled(6, 1, 2, 3)); + assert_event_emitted!(Event::DelegationDecreaseScheduled { + delegator: 6, + candidate: 1, + amount_to_decrease: 2, + execute_round: 3, + }); roll_to(30); assert_ok!(ParachainStaking::execute_delegation_request( Origin::signed(6), 6, 1 )); - assert_event_emitted!(Event::DelegationDecreased(6, 1, 2, true)); + assert_event_emitted!(Event::DelegationDecreased { + delegator: 6, + candidate: 1, + amount: 2, + in_top: true, + }); let collator1_state = ParachainStaking::candidate_info(1).unwrap(); // 12 + 13 + 13 + 15 + 20 = 73 (top 4 + self bond)ƒ assert_eq!(collator1_state.total_counted, 73); @@ -4867,14 +6483,24 @@ fn delegation_events_convey_correct_position() { 1, 1 )); - assert_event_emitted!(Event::DelegationDecreaseScheduled(6, 1, 1, 9)); + assert_event_emitted!(Event::DelegationDecreaseScheduled { + delegator: 6, + candidate: 1, + amount_to_decrease: 1, + execute_round: 9, + }); roll_to(40); assert_ok!(ParachainStaking::execute_delegation_request( Origin::signed(6), 6, 1 )); - assert_event_emitted!(Event::DelegationDecreased(6, 1, 1, false)); + assert_event_emitted!(Event::DelegationDecreased { + delegator: 6, + candidate: 1, + amount: 1, + in_top: false, + }); let collator1_state = ParachainStaking::candidate_info(1).unwrap(); // 12 + 13 + 13 + 15 + 20 = 73 (top 4 + self bond) assert_eq!(collator1_state.total_counted, 73); @@ -4896,38 +6522,92 @@ fn no_rewards_paid_until_after_reward_payment_delay() { set_author(1, 4, 1); set_author(1, 4, 1); let mut expected = vec![ - Event::CollatorChosen(2, 1, 20), - Event::CollatorChosen(2, 2, 20), - Event::CollatorChosen(2, 3, 20), - Event::CollatorChosen(2, 4, 20), - Event::NewRound(5, 2, 4, 80), + Event::CollatorChosen { + round: 2, + collator_account: 1, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 2, + collator_account: 2, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 2, + collator_account: 3, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 2, + collator_account: 4, + total_exposed_amount: 20, + }, + Event::NewRound { + starting_block: 5, + round: 2, + selected_collators_number: 4, + total_balance: 80, + }, ]; assert_eq_events!(expected); roll_to_round_begin(3); expected.append(&mut vec![ - Event::CollatorChosen(3, 1, 20), - Event::CollatorChosen(3, 2, 20), - Event::CollatorChosen(3, 3, 20), - Event::CollatorChosen(3, 4, 20), - Event::NewRound(10, 3, 4, 80), + Event::CollatorChosen { + round: 3, + collator_account: 1, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 3, + collator_account: 2, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 3, + collator_account: 3, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: 3, + collator_account: 4, + total_exposed_amount: 20, + }, + Event::NewRound { + starting_block: 10, + round: 3, + selected_collators_number: 4, + total_balance: 80, + }, // rewards will begin immediately following a NewRound - Event::Rewarded(3, 1), + Event::Rewarded { + account: 3, + rewards: 1, + }, ]); assert_eq_events!(expected); // roll to the next block where we start round 3; we should have round change and first // payout made. roll_one_block(); - expected.push(Event::Rewarded(4, 2)); + expected.push(Event::Rewarded { + account: 4, + rewards: 2, + }); assert_eq_events!(expected); roll_one_block(); - expected.push(Event::Rewarded(1, 1)); + expected.push(Event::Rewarded { + account: 1, + rewards: 1, + }); assert_eq_events!(expected); roll_one_block(); - expected.push(Event::Rewarded(2, 1)); + expected.push(Event::Rewarded { + account: 2, + rewards: 1, + }); assert_eq_events!(expected); // there should be no more payments in this round... @@ -4960,9 +6640,22 @@ fn deferred_payment_storage_items_are_cleaned_up() { round = 2; roll_to_round_begin(round.into()); let mut expected = vec![ - Event::CollatorChosen(round, 1, 20), - Event::CollatorChosen(round, 2, 20), - Event::NewRound(5, round, 2, 40), + Event::CollatorChosen { + round: round, + collator_account: 1, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: round, + collator_account: 2, + total_exposed_amount: 20, + }, + Event::NewRound { + starting_block: 5, + round: round, + selected_collators_number: 2, + total_balance: 40, + }, ]; assert_eq_events!(expected); @@ -4999,10 +6692,26 @@ fn deferred_payment_storage_items_are_cleaned_up() { round = 3; roll_to_round_begin(round.into()); expected.append(&mut vec![ - Event::CollatorChosen(round, 1, 20), - Event::CollatorChosen(round, 2, 20), - Event::NewRound(10, round, 2, 40), - Event::Rewarded(1, 1), + Event::CollatorChosen { + round: round, + collator_account: 1, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: round, + collator_account: 2, + total_exposed_amount: 20, + }, + Event::NewRound { + starting_block: 10, + round: round, + selected_collators_number: 2, + total_balance: 40, + }, + Event::Rewarded { + account: 1, + rewards: 1, + }, ]); assert_eq_events!(expected); @@ -5047,10 +6756,26 @@ fn deferred_payment_storage_items_are_cleaned_up() { round = 4; roll_to_round_begin(round.into()); expected.append(&mut vec![ - Event::Rewarded(2, 1), // from previous round - Event::CollatorChosen(round, 1, 20), - Event::CollatorChosen(round, 2, 20), - Event::NewRound(15, round, 2, 40), + Event::Rewarded { + account: 2, + rewards: 1, + }, // from previous round + Event::CollatorChosen { + round: round, + collator_account: 1, + total_exposed_amount: 20, + }, + Event::CollatorChosen { + round: round, + collator_account: 2, + total_exposed_amount: 20, + }, + Event::NewRound { + starting_block: 15, + round: round, + selected_collators_number: 2, + total_balance: 40, + }, ]); assert_eq_events!(expected); @@ -5156,15 +6881,45 @@ fn deferred_payment_steady_state_event_flow() { ); let expected = vec![ - Event::CollatorChosen(round as u32, 1, 400), - Event::CollatorChosen(round as u32, 2, 400), - Event::CollatorChosen(round as u32, 3, 400), - Event::CollatorChosen(round as u32, 4, 400), - Event::NewRound((round - 1) * 5, round as u32, 4, 1600), + Event::CollatorChosen { + round: round as u32, + collator_account: 1, + total_exposed_amount: 400, + }, + Event::CollatorChosen { + round: round as u32, + collator_account: 2, + total_exposed_amount: 400, + }, + Event::CollatorChosen { + round: round as u32, + collator_account: 3, + total_exposed_amount: 400, + }, + Event::CollatorChosen { + round: round as u32, + collator_account: 4, + total_exposed_amount: 400, + }, + Event::NewRound { + starting_block: (round - 1) * 5, + round: round as u32, + selected_collators_number: 4, + total_balance: 1600, + }, // first payout should occur on round change - Event::Rewarded(3, 19), - Event::Rewarded(22, 6), - Event::Rewarded(33, 6), + Event::Rewarded { + account: 3, + rewards: 19, + }, + Event::Rewarded { + account: 22, + rewards: 6, + }, + Event::Rewarded { + account: 33, + rewards: 6, + }, ]; assert_eq_last_events!(expected); @@ -5172,32 +6927,62 @@ fn deferred_payment_steady_state_event_flow() { roll_one_block(); let expected = vec![ - Event::Rewarded(4, 19), - Event::Rewarded(33, 6), - Event::Rewarded(44, 6), + Event::Rewarded { + account: 4, + rewards: 19, + }, + Event::Rewarded { + account: 33, + rewards: 6, + }, + Event::Rewarded { + account: 44, + rewards: 6, + }, ]; assert_eq_last_events!(expected); roll_one_block(); let expected = vec![ - Event::Rewarded(1, 19), - Event::Rewarded(11, 6), - Event::Rewarded(44, 6), + Event::Rewarded { + account: 1, + rewards: 19, + }, + Event::Rewarded { + account: 11, + rewards: 6, + }, + Event::Rewarded { + account: 44, + rewards: 6, + }, ]; assert_eq_last_events!(expected); roll_one_block(); let expected = vec![ - Event::Rewarded(2, 19), - Event::Rewarded(11, 6), - Event::Rewarded(22, 6), + Event::Rewarded { + account: 2, + rewards: 19, + }, + Event::Rewarded { + account: 11, + rewards: 6, + }, + Event::Rewarded { + account: 22, + rewards: 6, + }, ]; assert_eq_last_events!(expected); roll_one_block(); let expected = vec![ // we paid everyone out by now, should repeat last event - Event::Rewarded(22, 6), + Event::Rewarded { + account: 22, + rewards: 6, + }, ]; assert_eq_last_events!(expected); @@ -5501,12 +7286,34 @@ fn split_candidate_state_kicks_extra_bottom_delegators_to_exit() { assert!(ParachainStaking::is_delegator(&11)); assert!(ParachainStaking::is_delegator(&12)); crate::migrations::SplitCandidateStateToDecreasePoV::::on_runtime_upgrade(); - assert_event_emitted!(Event::DelegationKicked(11, 1, 11)); - assert_event_emitted!(Event::DelegationKicked(11, 2, 11)); - assert_event_emitted!(Event::DelegationKicked(12, 1, 10)); - assert_event_emitted!(Event::DelegationKicked(12, 2, 10)); - assert_event_emitted!(Event::DelegatorLeft(12, 10)); - assert_event_emitted!(Event::DelegatorLeft(11, 11)); + assert_event_emitted!(Event::DelegationKicked { + delegator: 11, + candidate: 1, + unstaked_amount: 11 + }); + assert_event_emitted!(Event::DelegationKicked { + delegator: 11, + candidate: 2, + unstaked_amount: 11 + }); + assert_event_emitted!(Event::DelegationKicked { + delegator: 12, + candidate: 1, + unstaked_amount: 10 + }); + assert_event_emitted!(Event::DelegationKicked { + delegator: 12, + candidate: 2, + unstaked_amount: 10 + }); + assert_event_emitted!(Event::DelegatorLeft { + delegator: 12, + unstaked_amount: 10 + }); + assert_event_emitted!(Event::DelegatorLeft { + delegator: 11, + unstaked_amount: 11 + }); // kicked 11 and 12 and revoked them assert_eq!(Balances::free_balance(&11), 22); assert_eq!(Balances::free_balance(&12), 20); @@ -5664,12 +7471,34 @@ fn split_candidate_state_kicks_extra_bottom_delegations_without_exit() { assert!(ParachainStaking::is_delegator(&11)); assert!(ParachainStaking::is_delegator(&12)); crate::migrations::SplitCandidateStateToDecreasePoV::::on_runtime_upgrade(); - assert_event_emitted!(Event::DelegationKicked(11, 1, 11)); - assert_event_emitted!(Event::DelegationKicked(11, 2, 11)); - assert_event_emitted!(Event::DelegationKicked(12, 1, 10)); - assert_event_emitted!(Event::DelegationKicked(12, 2, 10)); - assert_event_not_emitted!(Event::DelegatorLeft(12, 10)); - assert_event_not_emitted!(Event::DelegatorLeft(11, 10)); + assert_event_emitted!(Event::DelegationKicked { + delegator: 11, + candidate: 1, + unstaked_amount: 11, + }); + assert_event_emitted!(Event::DelegationKicked { + delegator: 11, + candidate: 2, + unstaked_amount: 11, + }); + assert_event_emitted!(Event::DelegationKicked { + delegator: 12, + candidate: 1, + unstaked_amount: 10, + }); + assert_event_emitted!(Event::DelegationKicked { + delegator: 12, + candidate: 2, + unstaked_amount: 10, + }); + assert_event_not_emitted!(Event::DelegatorLeft { + delegator: 12, + unstaked_amount: 10, + }); + assert_event_not_emitted!(Event::DelegatorLeft { + delegator: 11, + unstaked_amount: 10, + }); // kicked 11 and 12 and revoked them assert_eq!(Balances::free_balance(&11), 22); assert_eq!(Balances::free_balance(&12), 20); diff --git a/pallets/xcm-transactor/src/lib.rs b/pallets/xcm-transactor/src/lib.rs index af24a4f8fdf..b114b5c78b2 100644 --- a/pallets/xcm-transactor/src/lib.rs +++ b/pallets/xcm-transactor/src/lib.rs @@ -190,11 +190,31 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { - TransactedDerivative(T::AccountId, MultiLocation, Vec, u16), - TransactedSovereign(T::AccountId, MultiLocation, Vec), - RegisterdDerivative(T::AccountId, u16), - TransactFailed(XcmError), - TransactInfoChanged(MultiLocation, RemoteTransactInfoWithMaxWeight), + /// Transacted the inner call through a derivative account in a destination chain. + TransactedDerivative { + account_id: T::AccountId, + dest: MultiLocation, + call: Vec, + index: u16, + }, + /// Transacted the call through the sovereign account in a destination chain. + TransactedSovereign { + fee_payer: T::AccountId, + dest: MultiLocation, + call: Vec, + }, + /// Registered a derivative index for an account id. + RegisterdDerivative { + account_id: T::AccountId, + index: u16, + }, + /// Transact failed + TransactFailed { error: XcmError }, + /// Changed the transact info of a location + TransactInfoChanged { + location: MultiLocation, + remote_info: RemoteTransactInfoWithMaxWeight, + }, } #[pallet::call] @@ -219,7 +239,10 @@ pub mod pallet { IndexToAccount::::insert(&index, who.clone()); // Deposit event - Self::deposit_event(Event::::RegisterdDerivative(who, index)); + Self::deposit_event(Event::::RegisterdDerivative { + account_id: who, + index: index, + }); Ok(()) } @@ -273,9 +296,12 @@ pub mod pallet { )?; // Deposit event - Self::deposit_event(Event::::TransactedDerivative( - who, dest, call_bytes, index, - )); + Self::deposit_event(Event::::TransactedDerivative { + account_id: who, + dest: dest, + call: call_bytes, + index: index, + }); Ok(()) } @@ -329,9 +355,12 @@ pub mod pallet { call_bytes.clone(), )?; // Deposit event - Self::deposit_event(Event::::TransactedDerivative( - who, dest, call_bytes, index, - )); + Self::deposit_event(Event::::TransactedDerivative { + account_id: who, + dest: dest, + call: call_bytes, + index: index, + }); Ok(()) } @@ -372,7 +401,11 @@ pub mod pallet { )?; // Deposit event - Self::deposit_event(Event::::TransactedSovereign(fee_payer, dest, call)); + Self::deposit_event(Event::::TransactedSovereign { + fee_payer, + dest, + call, + }); Ok(()) } @@ -397,7 +430,10 @@ pub mod pallet { TransactInfoWithWeightLimit::::insert(&location, &remote_info); - Self::deposit_event(Event::TransactInfoChanged(location, remote_info)); + Self::deposit_event(Event::TransactInfoChanged { + location, + remote_info, + }); Ok(()) } } diff --git a/pallets/xcm-transactor/src/tests.rs b/pallets/xcm-transactor/src/tests.rs index a3b421273fe..0b1ca3d1eb6 100644 --- a/pallets/xcm-transactor/src/tests.rs +++ b/pallets/xcm-transactor/src/tests.rs @@ -41,7 +41,10 @@ fn test_register_address() { assert_eq!(XcmTransactor::index_to_account(&1).unwrap(), 1u64); - let expected = vec![crate::Event::RegisterdDerivative(1u64, 1)]; + let expected = vec![crate::Event::RegisterdDerivative { + account_id: 1u64, + index: 1, + }]; assert_eq!(events(), expected); }) } @@ -164,22 +167,25 @@ fn test_transact_through_derivative_multilocation_success() { vec![1u8] )); let expected = vec![ - crate::Event::RegisterdDerivative(1u64, 1), - crate::Event::TransactInfoChanged( - MultiLocation::parent(), - RemoteTransactInfoWithMaxWeight { + crate::Event::RegisterdDerivative { + account_id: 1u64, + index: 1, + }, + crate::Event::TransactInfoChanged { + location: MultiLocation::parent(), + remote_info: RemoteTransactInfoWithMaxWeight { transact_extra_weight: 0, fee_per_second: 1, max_weight: 10000, }, - ), - crate::Event::TransactedDerivative( - 1u64, - MultiLocation::parent(), - Transactors::Relay + }, + crate::Event::TransactedDerivative { + account_id: 1u64, + dest: MultiLocation::parent(), + call: Transactors::Relay .encode_call(UtilityAvailableCalls::AsDerivative(1, vec![1u8])), - 1, - ), + index: 1, + }, ]; assert_eq!(events(), expected); }) @@ -213,22 +219,25 @@ fn test_transact_through_derivative_success() { vec![1u8] )); let expected = vec![ - crate::Event::RegisterdDerivative(1u64, 1), - crate::Event::TransactInfoChanged( - MultiLocation::parent(), - RemoteTransactInfoWithMaxWeight { + crate::Event::RegisterdDerivative { + account_id: 1u64, + index: 1, + }, + crate::Event::TransactInfoChanged { + location: MultiLocation::parent(), + remote_info: RemoteTransactInfoWithMaxWeight { transact_extra_weight: 0, fee_per_second: 1, max_weight: 10000, }, - ), - crate::Event::TransactedDerivative( - 1u64, - MultiLocation::parent(), - Transactors::Relay + }, + crate::Event::TransactedDerivative { + account_id: 1u64, + dest: MultiLocation::parent(), + call: Transactors::Relay .encode_call(UtilityAvailableCalls::AsDerivative(1, vec![1u8])), - 1, - ), + index: 1, + }, ]; assert_eq!(events(), expected); }) @@ -273,15 +282,19 @@ fn test_root_can_transact_through_sovereign() { )); let expected = vec![ - crate::Event::TransactInfoChanged( - MultiLocation::parent(), - RemoteTransactInfoWithMaxWeight { + crate::Event::TransactInfoChanged { + location: MultiLocation::parent(), + remote_info: RemoteTransactInfoWithMaxWeight { transact_extra_weight: 0, fee_per_second: 1, max_weight: 10000, }, - ), - crate::Event::TransactedSovereign(1u64, MultiLocation::parent(), vec![1u8]), + }, + crate::Event::TransactedSovereign { + fee_payer: 1u64, + dest: MultiLocation::parent(), + call: vec![1u8], + }, ]; assert_eq!(events(), expected); }) diff --git a/precompiles/author-mapping/src/tests.rs b/precompiles/author-mapping/src/tests.rs index 37e73da5d05..5059e1c85dc 100644 --- a/precompiles/author-mapping/src/tests.rs +++ b/precompiles/author-mapping/src/tests.rs @@ -121,7 +121,11 @@ fn add_association_works() { amount: 10 } .into(), - AuthorMappingEvent::AuthorRegistered(expected_nimbus_id, Alice).into(), + AuthorMappingEvent::AuthorRegistered { + author_id: expected_nimbus_id, + account_id: Alice + } + .into(), EvmEvent::Executed(Precompile.into()).into(), ] ); @@ -161,8 +165,16 @@ fn update_association_works() { amount: 10 } .into(), - AuthorMappingEvent::AuthorRegistered(first_nimbus_id, Alice).into(), - AuthorMappingEvent::AuthorRotated(second_nimbus_id, Alice).into(), + AuthorMappingEvent::AuthorRegistered { + author_id: first_nimbus_id, + account_id: Alice + } + .into(), + AuthorMappingEvent::AuthorRotated { + new_author_id: second_nimbus_id, + account_id: Alice + } + .into(), EvmEvent::Executed(Precompile.into()).into(), ] ); @@ -198,13 +210,20 @@ fn clear_association_works() { amount: 10 } .into(), - AuthorMappingEvent::AuthorRegistered(nimbus_id.clone(), Alice).into(), + AuthorMappingEvent::AuthorRegistered { + author_id: nimbus_id.clone(), + account_id: Alice + } + .into(), BalancesEvent::Unreserved { who: Alice, amount: 10 } .into(), - AuthorMappingEvent::AuthorDeRegistered(nimbus_id).into(), + AuthorMappingEvent::AuthorDeRegistered { + author_id: nimbus_id + } + .into(), EvmEvent::Executed(Precompile.into()).into(), ] ); diff --git a/precompiles/parachain-staking/src/tests.rs b/precompiles/parachain-staking/src/tests.rs index c86a0431793..119a9eb4e6a 100644 --- a/precompiles/parachain-staking/src/tests.rs +++ b/precompiles/parachain-staking/src/tests.rs @@ -745,8 +745,12 @@ fn join_candidates_works() { // Make sure the call goes through successfully assert_ok!(Call::Evm(evm_call(TestAccount::Alice, input_data)).dispatch(Origin::root())); - let expected: crate::mock::Event = - StakingEvent::JoinedCollatorCandidates(TestAccount::Alice, 1000, 1000).into(); + let expected: crate::mock::Event = StakingEvent::JoinedCollatorCandidates { + account: TestAccount::Alice, + amount_locked: 1000, + new_total_amt_locked: 1000, + } + .into(); // Assert that the events vector contains the one expected println!("{:?}", events()); assert!(events().contains(&expected)); @@ -772,8 +776,12 @@ fn leave_candidates_works() { // Make sure the call goes through successfully assert_ok!(Call::Evm(evm_call(TestAccount::Alice, input_data)).dispatch(Origin::root())); - let expected: crate::mock::Event = - StakingEvent::CandidateScheduledExit(1, TestAccount::Alice, 3).into(); + let expected: crate::mock::Event = StakingEvent::CandidateScheduledExit { + exit_allowed_round: 1, + candidate: TestAccount::Alice, + scheduled_exit: 3, + } + .into(); // Assert that the events vector contains the one expected assert!(events().contains(&expected)); }); @@ -797,8 +805,12 @@ fn schedule_leave_candidates_works() { // Make sure the call goes through successfully assert_ok!(Call::Evm(evm_call(TestAccount::Alice, input_data)).dispatch(Origin::root())); - let expected: crate::mock::Event = - StakingEvent::CandidateScheduledExit(1, TestAccount::Alice, 3).into(); + let expected: crate::mock::Event = StakingEvent::CandidateScheduledExit { + exit_allowed_round: 1, + candidate: TestAccount::Alice, + scheduled_exit: 3, + } + .into(); // Assert that the events vector contains the one expected assert!(events().contains(&expected)); }); @@ -828,8 +840,12 @@ fn execute_leave_candidates_works() { // Make sure the call goes through successfully assert_ok!(Call::Evm(evm_call(TestAccount::Alice, input_data)).dispatch(Origin::root())); - let expected: crate::mock::Event = - StakingEvent::CandidateLeft(TestAccount::Alice, 1_000, 0).into(); + let expected: crate::mock::Event = StakingEvent::CandidateLeft { + ex_candidate: TestAccount::Alice, + unlocked_amount: 1_000, + new_total_amt_locked: 0, + } + .into(); // Assert that the events vector contains the one expected assert!(events().contains(&expected)); }); @@ -857,8 +873,10 @@ fn cancel_leave_candidates_works() { // Make sure the call goes through successfully assert_ok!(Call::Evm(evm_call(TestAccount::Alice, input_data)).dispatch(Origin::root())); - let expected: crate::mock::Event = - StakingEvent::CancelledCandidateExit(TestAccount::Alice).into(); + let expected: crate::mock::Event = StakingEvent::CancelledCandidateExit { + candidate: TestAccount::Alice, + } + .into(); // Assert that the events vector contains the one expected assert!(events().contains(&expected)); }); @@ -883,8 +901,10 @@ fn go_online_works() { // Make sure the call goes through successfully assert_ok!(Call::Evm(evm_call(TestAccount::Alice, input_data)).dispatch(Origin::root())); - let expected: crate::mock::Event = - StakingEvent::CandidateBackOnline(TestAccount::Alice).into(); + let expected: crate::mock::Event = StakingEvent::CandidateBackOnline { + candidate: TestAccount::Alice, + } + .into(); // Assert that the events vector contains the one expected assert!(events().contains(&expected)); }); @@ -906,8 +926,10 @@ fn go_offline_works() { // Make sure the call goes through successfully assert_ok!(Call::Evm(evm_call(TestAccount::Alice, input_data)).dispatch(Origin::root())); - let expected: crate::mock::Event = - StakingEvent::CandidateWentOffline(TestAccount::Alice).into(); + let expected: crate::mock::Event = StakingEvent::CandidateWentOffline { + candidate: TestAccount::Alice, + } + .into(); // Assert that the events vector contains the one expected assert!(events().contains(&expected)); }); @@ -931,8 +953,12 @@ fn candidate_bond_more_works() { // Make sure the call goes through successfully assert_ok!(Call::Evm(evm_call(TestAccount::Alice, input_data)).dispatch(Origin::root())); - let expected: crate::mock::Event = - StakingEvent::CandidateBondedMore(TestAccount::Alice, 500, 1500).into(); + let expected: crate::mock::Event = StakingEvent::CandidateBondedMore { + candidate: TestAccount::Alice, + amount: 500, + new_total_bond: 1500, + } + .into(); // Assert that the events vector contains the one expected assert!(events().contains(&expected)); }); @@ -957,8 +983,12 @@ fn candidate_bond_less_works() { // Make sure the call goes through successfully assert_ok!(Call::Evm(evm_call(TestAccount::Alice, input_data)).dispatch(Origin::root())); - let expected: crate::mock::Event = - StakingEvent::CandidateBondLessRequested(TestAccount::Alice, 500, 3).into(); + let expected: crate::mock::Event = StakingEvent::CandidateBondLessRequested { + candidate: TestAccount::Alice, + amount_to_decrease: 500, + execute_round: 3, + } + .into(); // Assert that the events vector contains the one expected assert!(events().contains(&expected)); }); @@ -982,8 +1012,12 @@ fn schedule_candidate_bond_less_works() { // Make sure the call goes through successfully assert_ok!(Call::Evm(evm_call(TestAccount::Alice, input_data)).dispatch(Origin::root())); - let expected: crate::mock::Event = - StakingEvent::CandidateBondLessRequested(TestAccount::Alice, 500, 3).into(); + let expected: crate::mock::Event = StakingEvent::CandidateBondLessRequested { + candidate: TestAccount::Alice, + amount_to_decrease: 500, + execute_round: 3, + } + .into(); // Assert that the events vector contains the one expected assert!(events().contains(&expected)); }); @@ -1012,8 +1046,12 @@ fn execute_candidate_bond_less_works() { // Make sure the call goes through successfully assert_ok!(Call::Evm(evm_call(TestAccount::Alice, input_data)).dispatch(Origin::root())); - let expected: crate::mock::Event = - StakingEvent::CandidateBondedLess(TestAccount::Alice, 500, 1000).into(); + let expected: crate::mock::Event = StakingEvent::CandidateBondedLess { + candidate: TestAccount::Alice, + amount: 500, + new_bond: 1000, + } + .into(); // Assert that the events vector contains the one expected assert!(events().contains(&expected)); }); @@ -1040,8 +1078,12 @@ fn cancel_candidate_bond_less_works() { // Make sure the call goes through successfully assert_ok!(Call::Evm(evm_call(TestAccount::Alice, input_data)).dispatch(Origin::root())); - let expected: crate::mock::Event = - StakingEvent::CancelledCandidateBondLess(TestAccount::Alice, 200, 3).into(); + let expected: crate::mock::Event = StakingEvent::CancelledCandidateBondLess { + candidate: TestAccount::Alice, + amount: 200, + execute_round: 3, + } + .into(); // Assert that the events vector contains the one expected assert!(events().contains(&expected)); }); @@ -1073,12 +1115,14 @@ fn nominate_works() { assert!(ParachainStaking::is_delegator(&TestAccount::Bob)); - let expected: crate::mock::Event = StakingEvent::Delegation( - TestAccount::Bob, - 1_000, - TestAccount::Alice, - parachain_staking::DelegatorAdded::AddedToTop { new_total: 2_000 }, - ) + let expected: crate::mock::Event = StakingEvent::Delegation { + delegator: TestAccount::Bob, + locked_amount: 1_000, + candidate: TestAccount::Alice, + delegator_position: parachain_staking::DelegatorAdded::AddedToTop { + new_total: 2_000, + }, + } .into(); // Assert that the events vector contains the one expected assert!(events().contains(&expected)); @@ -1110,12 +1154,14 @@ fn delegate_works() { assert!(ParachainStaking::is_delegator(&TestAccount::Bob)); - let expected: crate::mock::Event = StakingEvent::Delegation( - TestAccount::Bob, - 1_000, - TestAccount::Alice, - parachain_staking::DelegatorAdded::AddedToTop { new_total: 2_000 }, - ) + let expected: crate::mock::Event = StakingEvent::Delegation { + delegator: TestAccount::Bob, + locked_amount: 1_000, + candidate: TestAccount::Alice, + delegator_position: parachain_staking::DelegatorAdded::AddedToTop { + new_total: 2_000, + }, + } .into(); // Assert that the events vector contains the one expected assert!(events().contains(&expected)); @@ -1142,8 +1188,12 @@ fn leave_nominators_works() { // Make sure the call goes through successfully assert_ok!(Call::Evm(evm_call(TestAccount::Bob, input_data)).dispatch(Origin::root())); - let expected: crate::mock::Event = - StakingEvent::DelegatorExitScheduled(1, TestAccount::Bob, 3).into(); + let expected: crate::mock::Event = StakingEvent::DelegatorExitScheduled { + round: 1, + delegator: TestAccount::Bob, + scheduled_exit: 3, + } + .into(); // Assert that the events vector contains the one expected assert!(events().contains(&expected)); }); @@ -1166,8 +1216,12 @@ fn schedule_leave_delegators_works() { // Make sure the call goes through successfully assert_ok!(Call::Evm(evm_call(TestAccount::Bob, input_data)).dispatch(Origin::root())); - let expected: crate::mock::Event = - StakingEvent::DelegatorExitScheduled(1, TestAccount::Bob, 3).into(); + let expected: crate::mock::Event = StakingEvent::DelegatorExitScheduled { + round: 1, + delegator: TestAccount::Bob, + scheduled_exit: 3, + } + .into(); // Assert that the events vector contains the one expected assert!(events().contains(&expected)); }); @@ -1197,8 +1251,11 @@ fn execute_leave_delegators_works() { // Make sure the call goes through successfully assert_ok!(Call::Evm(evm_call(TestAccount::Alice, input_data)).dispatch(Origin::root())); - let expected: crate::mock::Event = - StakingEvent::DelegatorLeft(TestAccount::Bob, 500).into(); + let expected: crate::mock::Event = StakingEvent::DelegatorLeft { + delegator: TestAccount::Bob, + unstaked_amount: 500, + } + .into(); // Assert that the events vector contains the one expected assert!(events().contains(&expected)); }); @@ -1224,8 +1281,10 @@ fn cancel_leave_delegators_works() { // Make sure the call goes through successfully assert_ok!(Call::Evm(evm_call(TestAccount::Bob, input_data)).dispatch(Origin::root())); - let expected: crate::mock::Event = - StakingEvent::DelegatorExitCancelled(TestAccount::Bob).into(); + let expected: crate::mock::Event = StakingEvent::DelegatorExitCancelled { + delegator: TestAccount::Bob, + } + .into(); // Assert that the events vector contains the one expected assert!(events().contains(&expected)); }); @@ -1250,12 +1309,12 @@ fn revoke_nomination_works() { // Make sure the call goes through successfully assert_ok!(Call::Evm(evm_call(TestAccount::Bob, input_data)).dispatch(Origin::root())); - let expected: crate::mock::Event = StakingEvent::DelegationRevocationScheduled( - 1, - TestAccount::Bob, - TestAccount::Alice, - 3, - ) + let expected: crate::mock::Event = StakingEvent::DelegationRevocationScheduled { + round: 1, + delegator: TestAccount::Bob, + candidate: TestAccount::Alice, + scheduled_exit: 3, + } .into(); // Assert that the events vector contains the one expected assert!(events().contains(&expected)); @@ -1280,12 +1339,12 @@ fn schedule_revoke_delegation_works() { // Make sure the call goes through successfully assert_ok!(Call::Evm(evm_call(TestAccount::Bob, input_data)).dispatch(Origin::root())); - let expected: crate::mock::Event = StakingEvent::DelegationRevocationScheduled( - 1, - TestAccount::Bob, - TestAccount::Alice, - 3, - ) + let expected: crate::mock::Event = StakingEvent::DelegationRevocationScheduled { + round: 1, + delegator: TestAccount::Bob, + candidate: TestAccount::Alice, + scheduled_exit: 3, + } .into(); // Assert that the events vector contains the one expected assert!(events().contains(&expected)); @@ -1311,9 +1370,13 @@ fn nominator_bond_more_works() { assert_ok!(Call::Evm(evm_call(TestAccount::Bob, input_data)).dispatch(Origin::root())); - let expected: crate::mock::Event = - StakingEvent::DelegationIncreased(TestAccount::Bob, TestAccount::Alice, 500, true) - .into(); + let expected: crate::mock::Event = StakingEvent::DelegationIncreased { + delegator: TestAccount::Bob, + candidate: TestAccount::Alice, + amount: 500, + in_top: true, + } + .into(); // Assert that the events vector contains the one expected assert!(events().contains(&expected)); }); @@ -1337,9 +1400,13 @@ fn delegator_bond_more_works() { assert_ok!(Call::Evm(evm_call(TestAccount::Bob, input_data)).dispatch(Origin::root())); - let expected: crate::mock::Event = - StakingEvent::DelegationIncreased(TestAccount::Bob, TestAccount::Alice, 500, true) - .into(); + let expected: crate::mock::Event = StakingEvent::DelegationIncreased { + delegator: TestAccount::Bob, + candidate: TestAccount::Alice, + amount: 500, + in_top: true, + } + .into(); // Assert that the events vector contains the one expected assert!(events().contains(&expected)); }); @@ -1365,12 +1432,12 @@ fn nominator_bond_less_works() { assert_ok!(Call::Evm(evm_call(TestAccount::Bob, input_data)).dispatch(Origin::root())); // Check for the right events. - let expected_event: crate::mock::Event = StakingEvent::DelegationDecreaseScheduled( - TestAccount::Bob, - TestAccount::Alice, - 500, - 3, - ) + let expected_event: crate::mock::Event = StakingEvent::DelegationDecreaseScheduled { + delegator: TestAccount::Bob, + candidate: TestAccount::Alice, + amount_to_decrease: 500, + execute_round: 3, + } .into(); assert!(events().contains(&expected_event)); @@ -1397,12 +1464,12 @@ fn schedule_delegator_bond_less_works() { assert_ok!(Call::Evm(evm_call(TestAccount::Bob, input_data)).dispatch(Origin::root())); // Check for the right events. - let expected_event: crate::mock::Event = StakingEvent::DelegationDecreaseScheduled( - TestAccount::Bob, - TestAccount::Alice, - 500, - 3, - ) + let expected_event: crate::mock::Event = StakingEvent::DelegationDecreaseScheduled { + delegator: TestAccount::Bob, + candidate: TestAccount::Alice, + amount_to_decrease: 500, + execute_round: 3, + } .into(); assert!(events().contains(&expected_event)); @@ -1433,8 +1500,12 @@ fn execute_revoke_delegation_works() { // Make sure the call goes through successfully assert_ok!(Call::Evm(evm_call(TestAccount::Alice, input_data)).dispatch(Origin::root())); - let expected: crate::mock::Event = - StakingEvent::DelegationRevoked(TestAccount::Bob, TestAccount::Alice, 1_000).into(); + let expected: crate::mock::Event = StakingEvent::DelegationRevoked { + delegator: TestAccount::Bob, + candidate: TestAccount::Alice, + unstaked_amount: 1_000, + } + .into(); // Assert that the events vector contains the one expected assert!(events().contains(&expected)); }); @@ -1465,9 +1536,13 @@ fn execute_delegator_bond_less_works() { // Make sure the call goes through successfully assert_ok!(Call::Evm(evm_call(TestAccount::Alice, input_data)).dispatch(Origin::root())); - let expected: crate::mock::Event = - StakingEvent::DelegationDecreased(TestAccount::Bob, TestAccount::Alice, 500, true) - .into(); + let expected: crate::mock::Event = StakingEvent::DelegationDecreased { + delegator: TestAccount::Bob, + candidate: TestAccount::Alice, + amount: 500, + in_top: true, + } + .into(); // Assert that the events vector contains the one expected assert!(events().contains(&expected)); }); @@ -1495,15 +1570,15 @@ fn cancel_revoke_delegation_works() { // Make sure the call goes through successfully assert_ok!(Call::Evm(evm_call(TestAccount::Bob, input_data)).dispatch(Origin::root())); - let expected: crate::mock::Event = StakingEvent::CancelledDelegationRequest( - TestAccount::Bob, - parachain_staking::DelegationRequest { + let expected: crate::mock::Event = StakingEvent::CancelledDelegationRequest { + delegator: TestAccount::Bob, + cancelled_request: parachain_staking::DelegationRequest { collator: TestAccount::Alice, amount: 1_000, when_executable: 3, action: parachain_staking::DelegationChange::Revoke, }, - ) + } .into(); // Assert that the events vector contains the one expected assert!(events().contains(&expected)); @@ -1533,15 +1608,15 @@ fn cancel_delegator_bonded_less_works() { // Make sure the call goes through successfully assert_ok!(Call::Evm(evm_call(TestAccount::Bob, input_data)).dispatch(Origin::root())); - let expected: crate::mock::Event = StakingEvent::CancelledDelegationRequest( - TestAccount::Bob, - parachain_staking::DelegationRequest { + let expected: crate::mock::Event = StakingEvent::CancelledDelegationRequest { + delegator: TestAccount::Bob, + cancelled_request: parachain_staking::DelegationRequest { collator: TestAccount::Alice, amount: 500, when_executable: 3, action: parachain_staking::DelegationChange::Decrease, }, - ) + } .into(); // Assert that the events vector contains the one expected assert!(events().contains(&expected)); diff --git a/precompiles/xcm_transactor/src/tests.rs b/precompiles/xcm_transactor/src/tests.rs index 579af708834..5c859bd6a82 100644 --- a/precompiles/xcm_transactor/src/tests.rs +++ b/precompiles/xcm_transactor/src/tests.rs @@ -166,7 +166,7 @@ fn take_transact_info() { Box::new(xcm::VersionedMultiLocation::V1(MultiLocation::parent())), 0, 1, - 10000 + 10000, )); // Expected result is zero diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index 8693150a9c6..d9e64066fc4 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -953,18 +953,12 @@ impl InstanceFilter for ProxyType { c, Call::ParachainStaking(..) | Call::Utility(..) | Call::AuthorMapping(..) ), - ProxyType::CancelProxy => { - matches!( - c, - Call::Proxy(pallet_proxy::Call::reject_announcement { .. }) - ) - } - ProxyType::Balances => { - matches!(c, Call::Balances(..) | Call::Utility(..)) - } - ProxyType::AuthorMapping => { - matches!(c, Call::AuthorMapping(..)) - } + ProxyType::CancelProxy => matches!( + c, + Call::Proxy(pallet_proxy::Call::reject_announcement { .. }) + ), + ProxyType::Balances => matches!(c, Call::Balances(..) | Call::Utility(..)), + ProxyType::AuthorMapping => matches!(c, Call::AuthorMapping(..)), } } diff --git a/runtime/moonbase/tests/integration_test.rs b/runtime/moonbase/tests/integration_test.rs index 1d8e8fe50cd..d6cbf33c6fe 100644 --- a/runtime/moonbase/tests/integration_test.rs +++ b/runtime/moonbase/tests/integration_test.rs @@ -301,11 +301,11 @@ fn join_collator_candidates() { )); assert_eq!( last_event(), - Event::ParachainStaking(parachain_staking::Event::JoinedCollatorCandidates( - AccountId::from(DAVE), - 1_000 * UNIT, - 3_100 * UNIT - )) + Event::ParachainStaking(parachain_staking::Event::JoinedCollatorCandidates { + account: AccountId::from(DAVE), + amount_locked: 1_000 * UNIT, + new_total_amt_locked: 3_100 * UNIT + }) ); let candidates = ParachainStaking::candidate_pool(); assert_eq!(candidates.0[0].owner, AccountId::from(ALICE)); @@ -1769,10 +1769,10 @@ fn author_mapping_precompile_associate_update_and_clear() { ); let expected_associate_event = - Event::AuthorMapping(pallet_author_mapping::Event::AuthorRegistered( - first_nimbus_id.clone(), - AccountId::from(ALICE), - )); + Event::AuthorMapping(pallet_author_mapping::Event::AuthorRegistered { + author_id: first_nimbus_id.clone(), + account_id: AccountId::from(ALICE), + }); assert_eq!(last_event(), expected_associate_event); let update_expected_result = Some(Ok(PrecompileOutput { @@ -1802,10 +1802,10 @@ fn author_mapping_precompile_associate_update_and_clear() { ); let expected_update_event = - Event::AuthorMapping(pallet_author_mapping::Event::AuthorRotated( - second_nimbus_id.clone(), - AccountId::from(ALICE), - )); + Event::AuthorMapping(pallet_author_mapping::Event::AuthorRotated { + new_author_id: second_nimbus_id.clone(), + account_id: AccountId::from(ALICE), + }); assert_eq!(last_event(), expected_update_event); let clear_expected_result = Some(Ok(PrecompileOutput { @@ -1833,9 +1833,10 @@ fn author_mapping_precompile_associate_update_and_clear() { clear_expected_result ); - let expected_clear_event = Event::AuthorMapping( - pallet_author_mapping::Event::AuthorDeRegistered(second_nimbus_id.clone()), - ); + let expected_clear_event = + Event::AuthorMapping(pallet_author_mapping::Event::AuthorDeRegistered { + author_id: second_nimbus_id.clone(), + }); assert_eq!(last_event(), expected_clear_event); }); } diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index fff92d09452..dbd964e4a5c 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -887,18 +887,12 @@ impl InstanceFilter for ProxyType { c, Call::ParachainStaking(..) | Call::Utility(..) | Call::AuthorMapping(..) ), - ProxyType::CancelProxy => { - matches!( - c, - Call::Proxy(pallet_proxy::Call::reject_announcement { .. }) - ) - } - ProxyType::Balances => { - matches!(c, Call::Balances(..) | Call::Utility(..)) - } - ProxyType::AuthorMapping => { - matches!(c, Call::AuthorMapping(..)) - } + ProxyType::CancelProxy => matches!( + c, + Call::Proxy(pallet_proxy::Call::reject_announcement { .. }) + ), + ProxyType::Balances => matches!(c, Call::Balances(..) | Call::Utility(..)), + ProxyType::AuthorMapping => matches!(c, Call::AuthorMapping(..)), } } diff --git a/runtime/moonbeam/tests/integration_test.rs b/runtime/moonbeam/tests/integration_test.rs index 79938a6c35a..876d78229f0 100644 --- a/runtime/moonbeam/tests/integration_test.rs +++ b/runtime/moonbeam/tests/integration_test.rs @@ -303,11 +303,11 @@ fn join_collator_candidates() { )); assert_eq!( last_event(), - Event::ParachainStaking(parachain_staking::Event::JoinedCollatorCandidates( - AccountId::from(DAVE), - 100_000 * GLMR, - 310_000 * GLMR - )) + Event::ParachainStaking(parachain_staking::Event::JoinedCollatorCandidates { + account: AccountId::from(DAVE), + amount_locked: 100_000 * GLMR, + new_total_amt_locked: 310_000 * GLMR + }) ); let candidates = ParachainStaking::candidate_pool(); assert_eq!(candidates.0[0].owner, AccountId::from(ALICE)); diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index b8734619633..901c6a5c721 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -886,18 +886,12 @@ impl InstanceFilter for ProxyType { c, Call::ParachainStaking(..) | Call::Utility(..) | Call::AuthorMapping(..) ), - ProxyType::CancelProxy => { - matches!( - c, - Call::Proxy(pallet_proxy::Call::reject_announcement { .. }) - ) - } - ProxyType::Balances => { - matches!(c, Call::Balances(..) | Call::Utility(..)) - } - ProxyType::AuthorMapping => { - matches!(c, Call::AuthorMapping(..)) - } + ProxyType::CancelProxy => matches!( + c, + Call::Proxy(pallet_proxy::Call::reject_announcement { .. }) + ), + ProxyType::Balances => matches!(c, Call::Balances(..) | Call::Utility(..)), + ProxyType::AuthorMapping => matches!(c, Call::AuthorMapping(..)), } } diff --git a/runtime/moonriver/tests/integration_test.rs b/runtime/moonriver/tests/integration_test.rs index 4a93d7d2314..52a833fc0f0 100644 --- a/runtime/moonriver/tests/integration_test.rs +++ b/runtime/moonriver/tests/integration_test.rs @@ -298,11 +298,11 @@ fn join_collator_candidates() { )); assert_eq!( last_event(), - Event::ParachainStaking(parachain_staking::Event::JoinedCollatorCandidates( - AccountId::from(DAVE), - 1_000 * MOVR, - 3_100 * MOVR - )) + Event::ParachainStaking(parachain_staking::Event::JoinedCollatorCandidates { + account: AccountId::from(DAVE), + amount_locked: 1_000 * MOVR, + new_total_amt_locked: 3_100 * MOVR + }) ); let candidates = ParachainStaking::candidate_pool(); assert_eq!(candidates.0[0].owner, AccountId::from(ALICE));