1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#[cfg(test)]
pub mod tests {
use std::{fs, path::{Path, PathBuf}};
use tempfile::tempdir;
// use tempfile::tempdir;
// use super::*; // Import parent module's structs and functions
use verifier::aqua_verifier::{AquaVerifier, VerificationOptions};
use aqua_verifier_rs_types::models::page_data::PageData;
use crate::{aqua::verify::cli_verify_chain, models::CliArgs};
#[test]
fn test_verify_chain() {
// Create a temporary directory for our test files
let temp_dir = tempdir().expect("Failed to create temp directory");
// Create a test aqua data file
// let verify_path = create_test_aqua_data_file(temp_dir.path());
let path = Path::new("src/test/data/logo.chain.json").to_path_buf();
print!("Path is {}", path.display());
// let res: Result<PageData, String> = read_aqua_data(&path.to_path_buf());
// if res.is_err(){
// panic!("Cannot read json");
// }
// Prepare CLI arguments for testing
let cli_args = CliArgs {
authenticate: None,
sign: None,
witness: None,
file: Some(path),
remove: None,
remove_count: 0,
verbose: true, // Set to true to see detailed logs during test
output: Some(temp_dir.path().join("test_output_logs.txt")),
level: Some("2".to_string()), // Adjust as needed
keys_file: None,
};
let option = VerificationOptions {
version: 1.2,
strict: false,
allow_null: false,
verification_platform: "none".to_string(),
chain: "sepolia".to_string(),
api_key: "".to_string(),
};
let aqua_verifier = AquaVerifier::new(Some(option));
// Call the function being tested
// This is a no-panic test to ensure the function runs without crashing
cli_verify_chain(
cli_args.clone(),
aqua_verifier,
cli_args.file.unwrap()
);
// Optional: Add assertions to verify expected behavior
// 1. Check if output file was created
assert!(cli_args.output.as_ref().unwrap().exists(),
"Output log file should have been created");
// 2. Read and optionally check the contents of the output log
let log_contents = fs::read_to_string(cli_args.output.unwrap())
.expect("Should be able to read the log file");
// Add more specific assertions based on your expected verification results
// For example:
assert!(!log_contents.is_empty(), "Log file should not be empty");
// You might want to add more specific checks based on your verification logic
}
#[test]
fn test_verify_chain_with_invalid_file() {
let temp_dir = tempdir().expect("Failed to create temp directory");
// Create an intentionally invalid file path
// let invalid_path = temp_dir.path().join("non_existent_file.json");
let path = Path::new("src/test/data/non_existent_file.json").to_path_buf();
print!("Path is {}", path.display());
// Prepare CLI arguments for testing
let cli_args = CliArgs {
authenticate: None,
sign: None,
witness: None,
file: Some(path),
remove: None,
remove_count: 0,
verbose: true, // Set to true to see detailed logs during test
output: Some(temp_dir.path().join("test_output_logs.txt")),
level: Some("2".to_string()), // Adjust as needed
keys_file: None,
};
let option = VerificationOptions {
version: 1.2,
strict: false,
allow_null: false,
verification_platform: "none".to_string(),
chain: "sepolia".to_string(),
api_key: "".to_string(),
};
let aqua_verifier = AquaVerifier::new(Some(option));
// This test ensures graceful handling of non-existent files
cli_verify_chain(
cli_args.clone(),
aqua_verifier,
cli_args.file.unwrap()
);
// Verify error handling
let log_contents = fs::read_to_string(cli_args.output.unwrap())
.expect("Should be able to read the log file");
assert!(log_contents.contains("Error"),
"Log should contain an error message for invalid file");
}
}