Skip to content

Commit 77fd4fb

Browse files
committed
moved tests into the separate directory
1 parent c8d4207 commit 77fd4fb

File tree

8 files changed

+157
-180
lines changed

8 files changed

+157
-180
lines changed

rust/cryptonote/src/components/breadcrumb.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,10 @@ pub struct BreadcrumbProps {
1010
pub fn Breadcrumb(props: BreadcrumbProps) -> Element {
1111
let language = use_context::<Signal<Language>>();
1212
let t = get_translations(language());
13-
let nav = navigator();
1413

1514
rsx! {
1615
card { font_size: "larger",
17-
a {
18-
href: "#",
19-
onclick: move |_| {
20-
nav.push("/");
21-
},
16+
Link { to: crate::Route::Home {},
2217
"{t.home}"
2318
}
2419
" ❭ {props.title}"

rust/cryptonote/src/components/layout.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,13 @@ pub fn Layout() -> Element {
5656
" "
5757
{crate::i18n::get_translations(language()).by_continuing}
5858
" "
59-
a {
60-
href: "/license",
61-
onclick: move |evt| {
62-
evt.prevent_default();
63-
nav.push(Route::License {});
64-
},
59+
Link { to: Route::License {},
6560
"{crate::i18n::get_translations(language()).terms_of_service}"
6661
}
6762
" "
6863
{crate::i18n::get_translations(language()).you_agree}
6964
" "
70-
a {
71-
href: "/privacy",
72-
onclick: move |evt| {
73-
evt.prevent_default();
74-
nav.push(Route::Privacy {});
75-
},
65+
Link { to: Route::Privacy {},
7666
"{crate::i18n::get_translations(language()).privacy_policy_and}"
7767
}
7868
". "

rust/cryptonote/src/crypto.rs

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -130,70 +130,3 @@ pub fn decrypt_symmetric(
130130
}
131131
}
132132
}
133-
134-
#[cfg(test)]
135-
mod tests {
136-
use super::*;
137-
138-
#[test]
139-
fn test_symmetric_chacha20_roundtrip() {
140-
let plaintext = b"Hello, Cryptonote!";
141-
let password = "test_password_123";
142-
let encrypted = encrypt_symmetric(
143-
plaintext,
144-
password,
145-
CipherType::ChaCha20Poly1305,
146-
)
147-
.expect("Encryption failed");
148-
let decrypted =
149-
decrypt_symmetric(&encrypted, password)
150-
.expect("Decryption failed");
151-
assert_eq!(plaintext.to_vec(), decrypted);
152-
}
153-
154-
#[test]
155-
fn test_symmetric_aes_roundtrip() {
156-
let plaintext = b"Secret message with AES";
157-
let password = "strong_password";
158-
let encrypted = encrypt_symmetric(
159-
plaintext,
160-
password,
161-
CipherType::Aes256Gcm,
162-
)
163-
.expect("Encryption failed");
164-
let decrypted =
165-
decrypt_symmetric(&encrypted, password)
166-
.expect("Decryption failed");
167-
assert_eq!(plaintext.to_vec(), decrypted);
168-
}
169-
170-
#[test]
171-
fn test_symmetric_wrong_password() {
172-
let plaintext = b"Test data";
173-
let encrypted = encrypt_symmetric(
174-
plaintext,
175-
"correct",
176-
CipherType::ChaCha20Poly1305,
177-
)
178-
.expect("Encryption failed");
179-
let result = decrypt_symmetric(&encrypted, "wrong");
180-
assert!(result.is_err());
181-
}
182-
183-
#[test]
184-
fn test_key_derivation_consistency() {
185-
let password = "test";
186-
let salt = vec![1u8; SALT_SIZE];
187-
let key1 = derive_key(
188-
password,
189-
&salt,
190-
CipherType::ChaCha20Poly1305,
191-
);
192-
let key2 = derive_key(
193-
password,
194-
&salt,
195-
CipherType::ChaCha20Poly1305,
196-
);
197-
assert_eq!(key1, key2);
198-
}
199-
}

rust/cryptonote/src/encoding.rs

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -53,101 +53,6 @@ pub fn generate_qr_code(
5353
})?)
5454
}
5555

56-
#[cfg(test)]
57-
mod tests {
58-
use super::*;
59-
use crate::crypto::{CipherType, encrypt_symmetric};
60-
61-
#[test]
62-
fn test_encode_decode_plaintext() {
63-
let note = NoteData::PlainText(
64-
"Hello, World!".to_string(),
65-
);
66-
let encoded =
67-
encode_note(&note).expect("Encoding failed");
68-
let decoded =
69-
decode_note(&encoded).expect("Decoding failed");
70-
match decoded {
71-
NoteData::PlainText(text) => {
72-
assert_eq!(text, "Hello, World!")
73-
}
74-
_ => panic!("Expected PlainText"),
75-
}
76-
}
77-
78-
#[test]
79-
fn test_encode_decode_encrypted() {
80-
let plaintext = b"Secret message";
81-
let encrypted = encrypt_symmetric(
82-
plaintext,
83-
"password",
84-
CipherType::ChaCha20Poly1305,
85-
)
86-
.expect("Encryption failed");
87-
let note = NoteData::CipherText(encrypted);
88-
let encoded =
89-
encode_note(&note).expect("Encoding failed");
90-
let decoded =
91-
decode_note(&encoded).expect("Decoding failed");
92-
93-
match decoded {
94-
NoteData::CipherText(enc_data) => {
95-
assert_eq!(
96-
note.as_ciphertext()
97-
.unwrap()
98-
.ciphertext,
99-
enc_data.ciphertext
100-
);
101-
}
102-
_ => panic!("Expected CipherText"),
103-
}
104-
}
105-
106-
#[test]
107-
fn test_build_parse_url() {
108-
let note =
109-
NoteData::PlainText("Test note".to_string());
110-
let url =
111-
build_url("https://example.com/view", &note)
112-
.expect("URL build failed");
113-
assert!(
114-
url.starts_with(
115-
"https://example.com/view#note="
116-
)
117-
);
118-
let parsed =
119-
parse_url(&url).expect("URL parse failed");
120-
match parsed {
121-
NoteData::PlainText(text) => {
122-
assert_eq!(text, "Test note")
123-
}
124-
_ => panic!("Expected PlainText"),
125-
}
126-
}
127-
128-
#[test]
129-
fn test_qr_code_generation() {
130-
let url = "https://example.com/test";
131-
let svg = generate_qr_code(url)
132-
.expect("QR generation failed");
133-
assert!(svg.contains("<svg"));
134-
assert!(svg.contains("</svg>"));
135-
}
136-
137-
#[test]
138-
fn test_invalid_base64() {
139-
let result = decode_note("not-valid-base64!!!");
140-
assert!(result.is_err());
141-
}
142-
143-
#[test]
144-
fn test_invalid_url_format() {
145-
let result =
146-
parse_url("https://example.com/no-note-param");
147-
assert!(result.is_err());
148-
}
149-
}
150-
15156
impl NoteData {
15257
pub fn as_ciphertext(&self) -> Option<&EncryptedData> {
15358
match self {

rust/cryptonote/src/error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ impl AppError {
4444

4545
impl std::error::Error for AppError {}
4646

47+
4748
impl From<digest::InvalidLength> for AppError {
4849
fn from(e: digest::InvalidLength) -> Self {
4950
AppError::Cipher(e)

rust/cryptonote/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub mod crypto;
2+
pub mod encoding;
3+
pub mod error;
4+
pub mod i18n;
5+
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
use cryptonote::crypto::{
2+
CipherType, decrypt_symmetric, derive_key,
3+
encrypt_symmetric,
4+
};
5+
6+
const SALT_SIZE: usize = 32;
7+
8+
#[test]
9+
fn test_symmetric_chacha20_roundtrip() {
10+
let plaintext = b"Hello, Cryptonote!";
11+
let password = "test_password_123";
12+
let encrypted = encrypt_symmetric(
13+
plaintext,
14+
password,
15+
CipherType::ChaCha20Poly1305,
16+
)
17+
.expect("Encryption failed");
18+
let decrypted = decrypt_symmetric(&encrypted, password)
19+
.expect("Decryption failed");
20+
assert_eq!(plaintext.to_vec(), decrypted);
21+
}
22+
23+
#[test]
24+
fn test_symmetric_aes_roundtrip() {
25+
let plaintext = b"Secret message with AES";
26+
let password = "strong_password";
27+
let encrypted = encrypt_symmetric(
28+
plaintext,
29+
password,
30+
CipherType::Aes256Gcm,
31+
)
32+
.expect("Encryption failed");
33+
let decrypted = decrypt_symmetric(&encrypted, password)
34+
.expect("Decryption failed");
35+
assert_eq!(plaintext.to_vec(), decrypted);
36+
}
37+
38+
#[test]
39+
fn test_symmetric_wrong_password() {
40+
let plaintext = b"Test data";
41+
let encrypted = encrypt_symmetric(
42+
plaintext,
43+
"correct",
44+
CipherType::ChaCha20Poly1305,
45+
)
46+
.expect("Encryption failed");
47+
let result = decrypt_symmetric(&encrypted, "wrong");
48+
assert!(result.is_err());
49+
}
50+
51+
#[test]
52+
fn test_key_derivation_consistency() {
53+
let password = "test";
54+
let salt = vec![1u8; SALT_SIZE];
55+
let key1 = derive_key(
56+
password,
57+
&salt,
58+
CipherType::ChaCha20Poly1305,
59+
);
60+
let key2 = derive_key(
61+
password,
62+
&salt,
63+
CipherType::ChaCha20Poly1305,
64+
);
65+
assert_eq!(key1, key2);
66+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
use cryptonote::crypto::{CipherType, encrypt_symmetric};
2+
use cryptonote::encoding::{
3+
build_url, decode_note, encode_note, generate_qr_code,
4+
parse_url, NoteData,
5+
};
6+
7+
#[test]
8+
fn test_encode_decode_plaintext() {
9+
let note =
10+
NoteData::PlainText("Hello, World!".to_string());
11+
let encoded = encode_note(&note).expect("Encoding failed");
12+
let decoded =
13+
decode_note(&encoded).expect("Decoding failed");
14+
match decoded {
15+
NoteData::PlainText(text) => {
16+
assert_eq!(text, "Hello, World!")
17+
}
18+
_ => panic!("Expected PlainText"),
19+
}
20+
}
21+
22+
#[test]
23+
fn test_encode_decode_encrypted() {
24+
let plaintext = b"Secret message";
25+
let encrypted = encrypt_symmetric(
26+
plaintext,
27+
"password",
28+
CipherType::ChaCha20Poly1305,
29+
)
30+
.expect("Encryption failed");
31+
let note = NoteData::CipherText(encrypted);
32+
let encoded = encode_note(&note).expect("Encoding failed");
33+
let decoded =
34+
decode_note(&encoded).expect("Decoding failed");
35+
36+
match decoded {
37+
NoteData::CipherText(enc_data) => {
38+
assert_eq!(
39+
note.as_ciphertext().unwrap().ciphertext,
40+
enc_data.ciphertext
41+
);
42+
}
43+
_ => panic!("Expected CipherText"),
44+
}
45+
}
46+
47+
#[test]
48+
fn test_build_parse_url() {
49+
let note = NoteData::PlainText("Test note".to_string());
50+
let url = build_url("https://example.com/view", &note)
51+
.expect("URL build failed");
52+
assert!(url.starts_with("https://example.com/view#note="));
53+
let parsed = parse_url(&url).expect("URL parse failed");
54+
match parsed {
55+
NoteData::PlainText(text) => {
56+
assert_eq!(text, "Test note")
57+
}
58+
_ => panic!("Expected PlainText"),
59+
}
60+
}
61+
62+
#[test]
63+
fn test_qr_code_generation() {
64+
let url = "https://example.com/test";
65+
let svg = generate_qr_code(url)
66+
.expect("QR generation failed");
67+
assert!(svg.contains("<svg"));
68+
assert!(svg.contains("</svg>"));
69+
}
70+
71+
#[test]
72+
fn test_invalid_base64() {
73+
let result = decode_note("not-valid-base64!!!");
74+
assert!(result.is_err());
75+
}
76+
77+
#[test]
78+
fn test_invalid_url_format() {
79+
let result =
80+
parse_url("https://example.com/no-note-param");
81+
assert!(result.is_err());
82+
}

0 commit comments

Comments
 (0)