Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions contracts/attestation-registry/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@ fn configuration_getters_before_initialize_fail() {
);
}

#[test]
fn get_admin_before_initialize_fails() {
let env = Env::default();
let contract_id = env.register(AttestationRegistry, ());
let client = AttestationRegistryClient::new(&env, &contract_id);

let result = client.try_get_admin();
assert_eq!(result, Err(Ok(Error::NotInitialized)));
}

#[test]
fn get_attester_registry_before_initialize_fails() {
let env = Env::default();
let contract_id = env.register(AttestationRegistry, ());
let client = AttestationRegistryClient::new(&env, &contract_id);

let result = client.try_get_attester_registry();
assert_eq!(result, Err(Ok(Error::NotInitialized)));
}

#[test]
fn attest_by_allowlisted_attester_succeeds() {
let (env, client, attester_registry, _admin) = setup();
Expand Down
3 changes: 3 additions & 0 deletions crates/lafiya-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ clap = { version = "4.5", features = ["derive"] }
serde = { version = "1.0", features = ["derive"] }
toml = "1.1"
anyhow = "1.0"

[dev-dependencies]
tempfile = "3.10"
76 changes: 75 additions & 1 deletion crates/lafiya-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ fn main() -> anyhow::Result<()> {
Ok(())
}

// Tiny which implementation to avoid extra dep if not available, but we add which crate feature? We'll implement simple check
mod which {
use std::path::Path;

Expand Down Expand Up @@ -386,3 +385,78 @@ mod which {
Err(())
}
}

#[cfg(test)]
mod tests {
use super::*;
use std::io::Write;
use tempfile::NamedTempFile;

#[test]
fn parse_config_list_succeeds() {
let args = vec!["lafiya-cli", "config", "list"];
let result = Cli::try_parse_from(args);

assert!(result.is_ok());
let cli = result.unwrap();
assert_eq!(cli.network, "testnet");
assert!(cli.config.is_none());
match cli.command {
Commands::Config { sub: ConfigSub::List } => {}
_ => panic!("Expected Config List command"),
}
}

#[test]
fn parse_config_list_with_explicit_network_succeeds() {
let args = vec!["lafiya-cli", "--network", "mainnet", "config", "list"];
let result = Cli::try_parse_from(args);

assert!(result.is_ok());
let cli = result.unwrap();
assert_eq!(cli.network, "mainnet");
match cli.command {
Commands::Config { sub: ConfigSub::List } => {}
_ => panic!("Expected Config List command"),
}
}

#[test]
fn parse_missing_subcommand_fails() {
let args = vec!["lafiya-cli"];
let result = Cli::try_parse_from(args);

assert!(result.is_err());
}

#[test]
fn load_networks_from_missing_file_returns_handled_error() {
let nonexistent_path = std::path::PathBuf::from("/nonexistent/path/networks.toml");
let result = load_networks(Some(&nonexistent_path));

assert!(result.is_err());
match result {
Err(lafiya_config::ConfigError::NotFound(path)) => {
assert_eq!(path, nonexistent_path);
}
other => panic!("Expected ConfigError::NotFound, got: {:?}", other),
}
}

#[test]
fn load_networks_from_malformed_toml_returns_handled_error() {
let mut file = NamedTempFile::new().unwrap();
file.write_all(b"[invalid\nthis is not valid toml").unwrap();
file.flush().unwrap();

let result = load_networks(Some(file.path()));

assert!(result.is_err());
match result {
Err(lafiya_config::ConfigError::ParseError { path, .. }) => {
assert_eq!(path, file.path());
}
other => panic!("Expected ConfigError::ParseError, got: {:?}", other),
}
}
}