Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions pallets/asset-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,22 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(pub(crate) fn deposit_event)]
pub enum Event<T: Config> {
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.
Expand Down Expand Up @@ -178,7 +191,11 @@ pub mod pallet {
AssetIdType::<T>::insert(&asset_id, &asset);
AssetTypeId::<T>::insert(&asset, &asset_id);

Self::deposit_event(Event::AssetRegistered(asset_id, asset, metadata));
Self::deposit_event(Event::AssetRegistered {
asset_id,
asset,
metadata,
});
Ok(())
}

Expand All @@ -198,7 +215,10 @@ pub mod pallet {

AssetTypeUnitsPerSecond::<T>::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(())
}

Expand Down Expand Up @@ -229,7 +249,10 @@ pub mod pallet {
AssetTypeUnitsPerSecond::<T>::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(())
}
}
Expand Down
37 changes: 27 additions & 10 deletions pallets/asset-manager/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}])
});
}

Expand Down Expand Up @@ -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,
},
])
});
}
Expand Down Expand Up @@ -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),
},
])
});
}
Expand Down
29 changes: 22 additions & 7 deletions pallets/author-mapping/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,23 @@ pub mod pallet {
#[pallet::generate_deposit(pub(crate) fn deposit_event)]
pub enum Event<T: Config> {
/// 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]
Expand All @@ -120,7 +129,10 @@ pub mod pallet {

Self::enact_registration(&author_id, &account_id)?;

<Pallet<T>>::deposit_event(Event::AuthorRegistered(author_id, account_id));
<Pallet<T>>::deposit_event(Event::AuthorRegistered {
author_id,
account_id,
});

Ok(())
}
Expand Down Expand Up @@ -152,7 +164,10 @@ pub mod pallet {
MappingWithDeposit::<T>::remove(&old_author_id);
MappingWithDeposit::<T>::insert(&new_author_id, &stored_info);

<Pallet<T>>::deposit_event(Event::AuthorRotated(new_author_id, stored_info.account));
<Pallet<T>>::deposit_event(Event::AuthorRotated {
new_author_id: new_author_id,
account_id: stored_info.account,
});

Ok(())
}
Expand Down Expand Up @@ -180,7 +195,7 @@ pub mod pallet {

T::DepositCurrency::unreserve(&account_id, stored_info.deposit);

<Pallet<T>>::deposit_event(Event::AuthorDeRegistered(author_id));
<Pallet<T>>::deposit_event(Event::AuthorDeRegistered { author_id });

Ok(().into())
}
Expand Down
19 changes: 15 additions & 4 deletions pallets/author-mapping/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
);
})
}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
})
);
})
}
Expand Down
27 changes: 18 additions & 9 deletions pallets/migrations/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,17 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(pub(crate) fn deposit_event)]
pub enum Event<T: Config> {
/// Runtime upgrade started
RuntimeUpgradeStarted(),
RuntimeUpgradeCompleted(Weight),
MigrationStarted(Vec<u8>),
MigrationCompleted(Vec<u8>, Weight),
/// Runtime upgrade completed
RuntimeUpgradeCompleted { weight: Weight },
/// Migration started
MigrationStarted { migration_name: Vec<u8> },
/// Migration completed
MigrationCompleted {
migration_name: Vec<u8>,
consumed_weight: Weight,
},
}

#[pallet::hooks]
Expand Down Expand Up @@ -264,7 +271,9 @@ pub mod pallet {
let migration_done = <MigrationState<T>>::get(migration_name_as_bytes);

if !migration_done {
<Pallet<T>>::deposit_event(Event::MigrationStarted(migration_name_as_bytes.into()));
<Pallet<T>>::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.
Expand All @@ -287,10 +296,10 @@ pub mod pallet {
);

let consumed_weight = migration.migrate(available_for_step);
<Pallet<T>>::deposit_event(Event::MigrationCompleted(
migration_name_as_bytes.into(),
consumed_weight,
));
<Pallet<T>>::deposit_event(Event::MigrationCompleted {
migration_name: migration_name_as_bytes.into(),
consumed_weight: consumed_weight,
});
<MigrationState<T>>::insert(migration_name_as_bytes, true);

weight = weight.saturating_add(consumed_weight);
Expand All @@ -307,7 +316,7 @@ pub mod pallet {

<FullyUpgraded<T>>::put(true);
weight += T::DbWeight::get().writes(1);
<Pallet<T>>::deposit_event(Event::RuntimeUpgradeCompleted(weight));
<Pallet<T>>::deposit_event(Event::RuntimeUpgradeCompleted { weight });

weight
}
Expand Down
21 changes: 16 additions & 5 deletions pallets/migrations/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down Expand Up @@ -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);

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

Expand Down
Loading