use crate::{Runtime, Sandbox};
type MomentOf<R> = <R as pallet_timestamp::Config>::Moment;
impl<R> Sandbox<R>
where
R: Runtime,
R::Config: pallet_timestamp::Config,
{
pub fn get_timestamp(&mut self) -> MomentOf<R::Config> {
self.execute_with(pallet_timestamp::Pallet::<R::Config>::get)
}
pub fn set_timestamp(&mut self, timestamp: MomentOf<R::Config>) {
self.execute_with(|| pallet_timestamp::Pallet::<R::Config>::set_timestamp(timestamp))
}
}
#[cfg(test)]
mod tests {
use crate::{runtime::MinimalRuntime, Sandbox};
#[test]
fn getting_and_setting_timestamp_works() {
let mut sandbox = Sandbox::<MinimalRuntime>::new().expect("Failed to create sandbox");
for timestamp in 0..10 {
assert_ne!(sandbox.get_timestamp(), timestamp);
sandbox.set_timestamp(timestamp);
assert_eq!(sandbox.get_timestamp(), timestamp);
sandbox.build_block().expect("Failed to build block");
}
}
}