df-hyperliquid-core 0.0.9-beta

Hyperliquid SDK for Rust: markets, account, trading, transfers, earn and deploy, with exact decimals and signing. Native and wasm.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//! Nonces that follow the clock and never repeat, one count an account.

use super::*;

#[test]
fn a_nonce_follows_the_clock_never_repeats_and_is_kept_an_account_each() {
    let mut clock = NonceClock::new();
    for (now, nonce) in [(10, 10), (10, 11), (10, 12), (5, 13), (100, 100)] {
        assert_eq!(clock.next(now), nonce, "at {now}: a clock that steps back does not take the nonce with it");
    }
    assert_eq!(clock.last(), 100);

    let mut one = NonceClock::new();
    let mut two = NonceClock::after(1_790_000_000_000);
    assert_eq!(one.next(1_790_000_000_000), 1_790_000_000_000);
    assert_eq!(two.next(1_790_000_000_000), 1_790_000_000_001);
    assert_eq!(one.last(), 1_790_000_000_000);
}