Skip to content

Commit

Permalink
Create security_tests.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Dec 8, 2024
1 parent 72f0945 commit 105c0e4
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/security/security_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#[cfg(test)]
mod tests {
use super::*;
use ed25519_dalek::{Keypair, Signature, Signer};
use std::collections::HashMap;

#[test]
fn test_multi_sig_wallet() {
let mut wallet = MultiSigWallet::new(2, vec![
Keypair::generate(&mut rand::thread_rng()).public,
Keypair::generate(&mut rand::thread_rng()).public,
]);

let message = b"Hello, world!";
let keypair = Keypair::generate(&mut rand::thread_rng());
let signature: Signature = keypair.sign(message);

wallet.add_signature(keypair.public, signature);
assert!(!wallet.verify(message));

let keypair2 = Keypair::generate(&mut rand::thread_rng());
let signature2: Signature = keypair2.sign(message);

wallet.add_signature(keypair2.public, signature2);
assert!(wallet.verify(message));
}

#[test]
fn test_encryption() {
let key = rand::thread_rng().gen::<[u8; 32]>();
let data = b"Hello, world!";
let encrypted_data = encrypt(data, &key);
let decrypted_data = decrypt(&encrypted_data, &key);
assert_eq!(data, &decrypted_data[..]);
}
}

0 comments on commit 105c0e4

Please sign in to comment.