EpochInfo so tests can assert that the runtime actually reached the requested
time.
| Helper | Target | Returns |
|---|---|---|
time_travel_to_slot / timeTravelToSlot | Absolute slot number | EpochInfo with the new absolute_slot |
time_travel_to_epoch / timeTravelToEpoch | Absolute epoch number | EpochInfo with the new epoch |
time_travel_to_timestamp / timeTravelToTimestamp | Unix timestamp in milliseconds | EpochInfo reflecting the implied slot |
Forward onlyTime travel can only move the clock forward. A target in the past is
rejected rather than ignored — the Rust helpers return an
Err and the JS
helpers throw. The JS error is a generic
cheatcode failed: surfnet_timeTravel: ... Internal error without the unit or
target. The detail is only in the runtime log.Jump To A Slot
Jump To An Epoch
Jump To A Unix Timestamp
Pass the timestamp in milliseconds since the Unix epoch — the same unit as JavaScript’sDate.now() — not seconds. The runtime computes the closest slot
at that timestamp.
The clock reports seconds, not millisecondsEvery timestamp you read back from the runtime is in seconds — the
onchain
Clock sysvar’s unix_timestamp, and the
ClockValue carried by
the systemClockUpdated event. Feeding one of those values straight back into
a time-travel helper resolves to a moment in early 1970, so the call is
rejected as a past target. Multiply by 1000 first.Pause And Resume The Clock
Time travel jumps to a target; pausing stops the clock from advancing at all.surfnet_pauseClock halts slot production and time progression until
surfnet_resumeClock runs — reach for it when a test needs the slot and
timestamp to hold still across several assertions.
Neither the Rust SDK nor the Surfnet class in @solana/surfpool wraps these
two cheatcodes. Call them through the
Kit plugin, or directly over JSON-RPC.
EpochInfo — the clock state at the moment of the
pause, and after resuming. Note the two things that shape does not carry:
- No timestamp.
EpochInfohas no time field. Read the simulated Unix time from theClocksysvar instead:getAccountInfoonSysvarC1ock11111111111111111111111111111111withjsonParsedencoding — again, in seconds. - No paused flag. No RPC method reports whether the clock is currently
paused. From the SDKs, watch the
clockUpdateevent, which fires with aclockCommandwhenever a pause, resume, or interval change runs. Otherwise, track the state in your test.
Common Patterns
Test A Lockup Or Vesting Window
The example below is a sketch —assertWithdrawFails and
assertWithdrawSucceeds are placeholders for whatever client-side helpers your
test suite uses to assert on RPC behavior.
Drive A Multi-Epoch Scenario
Intermediate slots are skippedTime travel jumps directly to the target — moving from epoch 1 to epoch 5
skips the slots in between. If your program needs each intermediate epoch
boundary to fire (for example, to credit per-epoch rewards), call
time_travel_to_epoch once per epoch with any required transactions in
between.EpochInfo Shape
Both SDKs return anEpochInfo-shaped object with these fields:
| Field | Rust | JS |
|---|---|---|
| Absolute slot | absolute_slot: u64 | absoluteSlot: number |
| Slot within epoch | slot_index: u64 | slotIndex: number |
| Slots per epoch | slots_in_epoch: u64 | slotsInEpoch: number |
| Epoch number | epoch: u64 | epoch: number |
| Block height | block_height: u64 | blockHeight: number |
| Transaction count | transaction_count: Option<u64> | transactionCount?: number |