Skip to content

Commit

Permalink
chore: add unittests for tokenv3
Browse files Browse the repository at this point in the history
  • Loading branch information
ngutech21 committed Mar 23, 2024
1 parent 1ce57a7 commit e48060a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion moksha-core/src/dhke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ mod tests {
// # assert verify(a, C + C, secret_msg) == False # adding C twice shouldn't pass
// # assert verify(a, A, secret_msg) == False # A shouldn't pass

let dhke = Dhke::new();
let dhke = Dhke::default();

// Generate Alice's private key and public key
let a = pk_from_hex("0000000000000000000000000000000000000000000000000000000000000001");
Expand Down
15 changes: 14 additions & 1 deletion moksha-core/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ impl From<(Url, Proofs)> for TokenV3 {

#[cfg(test)]
mod tests {
use std::str::FromStr;

use serde_json::{json, Value};
use url::Url;

Expand Down Expand Up @@ -244,6 +246,9 @@ mod tests {
let token = serde_json::from_value::<super::Token>(js)?;
assert_eq!(token.mint, Some(Url::parse("https://8333.space:3338")?));
assert_eq!(token.proofs.len(), 2);

let v3 = TokenV3::new(token);
assert_eq!(v3.mint(), Some(Url::parse("https://8333.space:3338")?));
Ok(())
}

Expand Down Expand Up @@ -284,7 +289,7 @@ mod tests {
#[test]
fn test_tokens_deserialize() -> anyhow::Result<()> {
let input = read_fixture("token_nut_example.cashu")?;
let tokens = TokenV3::deserialize(input)?;
let tokens = TokenV3::from_str(&input)?;
assert_eq!(tokens.memo, Some("Thank you.".to_string()),);
assert_eq!(tokens.tokens.len(), 1);
Ok(())
Expand Down Expand Up @@ -314,4 +319,12 @@ mod tests {
assert!(tokens.is_err());
Ok(())
}

#[test]
fn test_empty_token() -> anyhow::Result<()> {
let tokens = TokenV3::empty();
assert!(tokens.tokens.is_empty());
assert!(tokens.memo.is_none());
Ok(())
}
}

0 comments on commit e48060a

Please sign in to comment.