-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: added general util functions with unit tests #3
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor docstring suggestions.
We need to properly test convert_nsec_to_secret_key
.
backend/src/util.rs
Outdated
#[test] | ||
fn test_convert_days_to_blocks() { | ||
assert_eq!(convert_days_to_blocks(1), 144); | ||
assert_eq!(convert_days_to_blocks(2), 288); | ||
assert_eq!(convert_days_to_blocks(3), 432); | ||
} | ||
|
||
#[test] | ||
fn test_check_npub() { | ||
let npub = "npub1tv7hxxwtw4gcz4n6fpduads7lsmynh5pjedgfhvdctnulrz9rsksjx28xe"; | ||
assert!(check_npub(npub.to_string())); | ||
} | ||
|
||
#[test] | ||
fn test_nsec_to_hex() { | ||
let nsec = "nsec1ezmlpxvhhjnqt9wf60tmshkye7xlwsf37dl0qlmrjuxeq7p3zahs2tukgx"; | ||
let expected_hex = "c8b7f09997bca60595c9d3d7b85ec4cf8df74131f37ef07f63970d907831176f"; | ||
|
||
let hex = convert_nsec_to_hex(nsec.to_string()); | ||
assert_eq!(expected_hex, hex); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are missing a test of the convert_nsec_to_secret_key
. This is important to check if the conversion is successful and also should test if the SecretKey
generated is valid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function already uses the conversion before converting to hex, so the '''SecretKey::from_slice(&data)''' already does the check for a valid secret key.
Implemented these basic functions for a Nostr and Segwit usage on interface
External:
convert_npub_to_public_key(npub: String) -> String (Uses bitcoin::key::PublicKey)
check_npub(npub: String) -> bool
Internal:
convert_nsec_to_secret_key (nsec: String) -> SecretKey (Uses bitcoin::key::SecretKey)