Skip to content

Commit

Permalink
Add a beacon offset test
Browse files Browse the repository at this point in the history
  • Loading branch information
madninja committed Sep 6, 2023
1 parent fad11da commit 5f07aac
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/beaconer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,31 @@ mod test {
assert_eq!(phy_payload_a, phy_payload_b);
}

#[test]
fn test_beacon_offset() {
use super::mk_beacon_offset;
use std::str::FromStr;

const PUBKEY_1: &str = "13WvV82S7QN3VMzMSieiGxvuaPKknMtf213E5JwPnboDkUfesKw";
const PUBKEY_2: &str = "14HZVR4bdF9QMowYxWrumcFBNfWnhDdD5XXA5za1fWwUhHxxFS1";
let pubkey_1 = helium_crypto::PublicKey::from_str(PUBKEY_1).expect("public key");
let offset_1 = mk_beacon_offset(&pubkey_1, time::Duration::hours(6));
// Same key and interval should always end up at the same offset
assert_eq!(
offset_1,
mk_beacon_offset(&pubkey_1, time::Duration::hours(6))
);
let pubkey_2 = helium_crypto::PublicKey::from_str(PUBKEY_2).expect("public key 2");
let offset_2 = mk_beacon_offset(&pubkey_2, time::Duration::hours(6));
assert_eq!(
offset_2,
mk_beacon_offset(&pubkey_2, time::Duration::hours(6))
);
// And two offsets based on different keys should not land at the same
// offset
assert_ne!(offset_1, offset_2);
}

#[test]
fn test_beacon_first_time() {
use super::mk_first_beacon_delay;
Expand Down

0 comments on commit 5f07aac

Please sign in to comment.