Skip to content

Commit

Permalink
feat: fix more tests in wasm land
Browse files Browse the repository at this point in the history
  • Loading branch information
sstelfox committed Feb 11, 2024
1 parent 5576cfb commit a89a687
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/codec/crypto/authentication_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ mod tests {

use super::*;

#[test]
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::wasm_bindgen_test;

#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), test)]
fn test_authentication_tag_parsing() {
let mut rng = rand::thread_rng();
let input: [u8; TAG_LENGTH + 4] = rng.gen();
Expand All @@ -80,7 +84,8 @@ mod tests {
assert_eq!(tag.as_bytes(), &input[..TAG_LENGTH]);
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), test)]
fn test_authentication_tag_parsing_stream_too_short() {
let input = [0u8; TAG_LENGTH - 1];
let result = AuthenticationTag::parse(&input);
Expand Down
9 changes: 7 additions & 2 deletions src/codec/crypto/fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ impl From<&VerifyingKey> for Fingerprint {
pub mod tests {
use super::*;

#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::wasm_bindgen_test;

const REFERENCE_FINGERPRINT_BYTES: &[u8; 32] = b"UUUUUUUUaaaaaaaaUUUUUUUUaaaaaaaa";

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), test)]
fn test_fingerprint_debug_fmt() {
let fingerprint = Fingerprint::from(*REFERENCE_FINGERPRINT_BYTES);
let fmt_str = format!("{:?}", fingerprint);
Expand All @@ -53,7 +57,8 @@ pub mod tests {
);
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), test)]
fn test_key_id_from_fingerprint() {
let fingerprint = Fingerprint::from(*REFERENCE_FINGERPRINT_BYTES);
let key_id = fingerprint.key_id();
Expand Down
9 changes: 7 additions & 2 deletions src/codec/crypto/nonce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ impl Deref for Nonce {
mod tests {
use super::*;

#[test]
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::wasm_bindgen_test;

#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), test)]
fn test_nonce_parsing() {
let mut rng = rand::thread_rng();
let input: [u8; NONCE_LENGTH + 4] = rng.gen();
Expand All @@ -81,7 +85,8 @@ mod tests {
assert!(Nonce::parse_complete(&input[..NONCE_LENGTH]).is_ok());
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), test)]
fn test_nonce_parsing_stream_too_short() {
let input = [0u8; NONCE_LENGTH - 1];
let result = Nonce::parse(&input);
Expand Down

0 comments on commit a89a687

Please sign in to comment.