Skip to content

Commit 7920f7f

Browse files
authored
Merge pull request #30 from 100monkeys-ai/add-tests-integrity-checksum-12806015087958317194
🧪 Add unit tests for BLAKE3 integrity verification
2 parents 9706ff4 + 94cdc45 commit 7920f7f

1 file changed

Lines changed: 31 additions & 9 deletions

File tree

foundry/server/src/integrity/checksum.rs

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,38 @@ mod tests {
4242
}
4343

4444
#[test]
45-
fn test_verify() {
46-
let empty_hash = "blake3:af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262";
47-
let hello_hash = "blake3:d74981efa70a0c880b8d8c1985d075dbcbf679b99a5f9914e5aaf96b831a9e24";
45+
fn test_verify_happy_path() {
46+
let data = b"hello world";
47+
let expected = "blake3:d74981efa70a0c880b8d8c1985d075dbcbf679b99a5f9914e5aaf96b831a9e24";
48+
assert!(verify(data, expected));
49+
}
50+
51+
#[test]
52+
fn test_verify_modified_data() {
53+
let data = b"hello world!"; // extra char
54+
let expected = "blake3:d74981efa70a0c880b8d8c1985d075dbcbf679b99a5f9914e5aaf96b831a9e24"; // hash of "hello world"
55+
assert!(!verify(data, expected));
56+
}
57+
58+
#[test]
59+
fn test_verify_invalid_prefix() {
60+
let data = b"hello world";
61+
// same hash value, different prefix
62+
let expected = "sha256:d74981efa70a0c880b8d8c1985d075dbcbf679b99a5f9914e5aaf96b831a9e24";
63+
assert!(!verify(data, expected));
64+
}
4865

49-
assert!(verify(b"", empty_hash));
50-
assert!(verify(b"hello world", hello_hash));
66+
#[test]
67+
fn test_verify_wrong_length_hash() {
68+
let data = b"hello world";
69+
let expected = "blake3:d74981efa70a0c880b8d8c1985d075dbcbf679b99a5f9914e5aaf96b831a9e"; // truncated
70+
assert!(!verify(data, expected));
71+
}
5172

52-
// Negative test cases
53-
assert!(!verify(b"hello world", empty_hash));
54-
assert!(!verify(b"", hello_hash));
55-
assert!(!verify(b"hello world", "blake3:invalid"));
73+
#[test]
74+
fn test_verify_empty_string() {
75+
let data = b"";
76+
let expected = "blake3:af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262";
77+
assert!(verify(data, expected));
5678
}
5779
}

0 commit comments

Comments
 (0)