mirror of
https://github.com/Blah-IM/blahrs.git
synced 2025-07-07 06:35:34 +00:00
feat(types,blahd): allow using mock clock for testing
This commit is contained in:
parent
1a4980ebba
commit
31dc3e33c6
8 changed files with 61 additions and 13 deletions
|
@ -3,6 +3,10 @@ name = "blah-types"
|
|||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
unsafe_use_mock_instant_for_testing = ["dep:mock_instant"]
|
||||
|
||||
[[bench]]
|
||||
name = "crypto_ops"
|
||||
harness = false
|
||||
|
@ -13,6 +17,7 @@ bitflags_serde_shim = "0.2"
|
|||
ed25519-dalek = "2"
|
||||
hex = { version = "0.4", features = ["serde"] }
|
||||
html-escape = "0.2"
|
||||
mock_instant = { version = "0.5", optional = true }
|
||||
rand = "0.8"
|
||||
rusqlite = { version = "0.32", optional = true }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
use std::fmt;
|
||||
use std::str::FromStr;
|
||||
use std::time::SystemTime;
|
||||
|
||||
use ed25519_dalek::{
|
||||
Signature, SignatureError, Signer, SigningKey, VerifyingKey, PUBLIC_KEY_LENGTH,
|
||||
|
@ -104,6 +103,12 @@ impl<T: Serialize> SignExt for T {
|
|||
}
|
||||
|
||||
pub fn get_timestamp() -> u64 {
|
||||
#[cfg(not(feature = "unsafe_use_mock_instant_for_testing"))]
|
||||
use std::time::SystemTime;
|
||||
|
||||
#[cfg(feature = "unsafe_use_mock_instant_for_testing")]
|
||||
use mock_instant::thread_local::SystemTime;
|
||||
|
||||
SystemTime::now()
|
||||
.duration_since(SystemTime::UNIX_EPOCH)
|
||||
.expect("after UNIX epoch")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue