I'm writing a test case for the on_initalize hook!
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(_now: T::BlockNumber) -> Weight {
let time: u64 = T::TimeProvider::now().as_secs() - 180 ;
<RootOracleEvent<T>>::mutate(|event_list| {
if let Some(index) = event_list.iter().position(|member| member.time_stamp <= time) {
event_list.remove(index);
}
});
T::DbWeight::get().writes(1)
}
}
And, when I write a test case, its throws an error: ---- tests::valid_weights stdout ----
thread 'tests::valid_weights' panicked at 'attempt to subtract with overflow', pallets/pallet_oracle_feed/src/lib.rs:86:29
note: run with the RUST_BACKTRACE=1
environment variable to display a backtrace
#[test]
fn valid_weights() {
use frame_support::pallet_prelude::*;
use frame_support::weights::RuntimeDbWeight;
new_test_ext().execute_with(|| {
let db_weights: RuntimeDbWeight = <Test as frame_system::Config>::DbWeight::get();
assert_eq!(
ClubPalletTesting::on_initialize(1),
db_weights.writes(2));
})
}
now
? I have an assumption what could be the cause, but it would help if you could share the code of theon_initialize
or the whole pallet, if possible.