Skip to content
Merged
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
13 changes: 7 additions & 6 deletions crates/revive-strategy/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,20 +174,21 @@ impl TestEnv {

pub fn set_timestamp(&mut self, new_timestamp: U256) -> U256 {
// Set timestamp in pallet-revive runtime (milliseconds).
// We clamp to u64::MAX / 1000 to prevent overflow when converting to milliseconds.
self.0.lock().unwrap().externalities.execute_with(|| {
let u64_max = U256::from(u64::MAX);
let clamped_timestamp = if new_timestamp > u64_max {
let max_timestamp_seconds = U256::from(u64::MAX / 1000);
let clamped_timestamp = if new_timestamp > max_timestamp_seconds {
tracing::warn!(
timestamp = ?new_timestamp,
max = ?u64_max,
"Timestamp exceeds u64::MAX. Clamping to u64::MAX."
max = ?max_timestamp_seconds,
"Timestamp exceeds maximum. Clamping to u64::MAX / 1000."
);
u64_max
max_timestamp_seconds
} else {
new_timestamp
};

let timestamp_ms = clamped_timestamp.saturating_to::<u64>().saturating_mul(1000);
let timestamp_ms = clamped_timestamp.saturating_to::<u64>() * 1000;
Timestamp::set_timestamp(timestamp_ms);
clamped_timestamp
})
Expand Down
Loading