1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#[cfg(not(test))]
use ic_cdk::api::time;

use crate::types::TimestampNs;

#[macro_export]
macro_rules! custom_print {
    ($($arg:tt)*) => {
        #[cfg(not(test))]
        {
            ic_cdk::print(format!("[IC-WEBSOCKET-CDK]: {}", format!($($arg)*)));
        }
        #[cfg(test)]
        {
            println!("[IC-WEBSOCKET-CDK]: {}", format!($($arg)*));
        }
    }
}

#[macro_export]
macro_rules! custom_trap {
    ($($arg:tt)*) => {
        #[cfg(not(test))]
        {
            ic_cdk::trap($($arg)*);
        }
        #[cfg(test)]
        {
            panic!($($arg)*);
        }
    }
}

pub(crate) fn get_current_time() -> TimestampNs {
    #[cfg(test)]
    {
        use std::time::SystemTime;
        let duration_since_epoch = SystemTime::now()
            .duration_since(SystemTime::UNIX_EPOCH)
            .unwrap();
        let timestamp_nanos = duration_since_epoch.as_nanos();
        timestamp_nanos as TimestampNs
    }
    #[cfg(not(test))]
    {
        time()
    }
}