mod trap;
use candid::Principal;
pub use self::trap::trap;
pub fn caller() -> Principal {
#[cfg(target_family = "wasm")]
{
ic_cdk::api::msg_caller()
}
#[cfg(not(target_family = "wasm"))]
{
Principal::from_text("ghsi2-tqaaa-aaaan-aaaca-cai").expect("it should be valid")
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_should_return_caller_principal() {
let principal = caller();
let expected = Principal::from_text("ghsi2-tqaaa-aaaan-aaaca-cai").unwrap();
assert_eq!(principal, expected);
}
#[test]
fn test_caller_returns_consistent_principal() {
let principal1 = caller();
let principal2 = caller();
assert_eq!(principal1, principal2);
}
}