Skip to content
Merged
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
6 changes: 6 additions & 0 deletions contracts/identity-registry-contract/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,9 @@ pub fn ban_expert(env: &Env, expert: &Address) -> Result<(), RegistryError> {
pub fn get_expert_status(env: &Env, expert: &Address) -> ExpertStatus {
storage::get_expert_status(env, expert)
}

/// Check if an expert is verified
/// Returns true only if the expert's status is Verified
pub fn is_verified(env: &Env, expert: &Address) -> bool {
storage::get_expert_status(env, expert) == ExpertStatus::Verified
}
6 changes: 6 additions & 0 deletions contracts/identity-registry-contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@ impl IdentityRegistryContract {
pub fn get_status(env: Env, expert: Address) -> ExpertStatus {
contract::get_expert_status(&env, &expert)
}

/// Check if an expert is verified
/// Returns true only if the expert's status is Verified
pub fn is_verified(env: Env, expert: Address) -> bool {
contract::is_verified(&env, &expert)
}
}
28 changes: 28 additions & 0 deletions contracts/identity-registry-contract/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,31 @@ fn test_complete_expert_lifecycle() {
client.ban_expert(&expert);
assert_eq!(client.get_status(&expert), ExpertStatus::Banned);
}

#[test]
fn test_getters() {
let env = Env::default();
env.mock_all_auths();

let contract_id = env.register(IdentityRegistryContract, ());
let client = IdentityRegistryContractClient::new(&env, &contract_id);

let admin = Address::generate(&env);
client.init(&admin);

// Test 1: Check is_verified on a random address (should be false)
let random_address = Address::generate(&env);
assert_eq!(client.is_verified(&random_address), false);
assert_eq!(client.get_status(&random_address), ExpertStatus::Unverified);

// Test 2: Verify an expert and check is_verified (should be true)
let expert = Address::generate(&env);
client.add_expert(&expert);
assert_eq!(client.is_verified(&expert), true);
assert_eq!(client.get_status(&expert), ExpertStatus::Verified);

// Test 3: Ban the expert and check is_verified (should be false)
client.ban_expert(&expert);
assert_eq!(client.is_verified(&expert), false);
assert_eq!(client.get_status(&expert), ExpertStatus::Banned);
Comment on lines +334 to +359
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟑 Minor

Verify unauthenticated access explicitly in test_getters.

env.mock_all_auths() at the top can mask accidental auth requirements. To assert the β€œno signature required” behavior, run the getter checks before mocking auth, then mock only for admin calls.

πŸ”§ Suggested test tweak
 fn test_getters() {
     let env = Env::default();
-    env.mock_all_auths();
 
     let contract_id = env.register(IdentityRegistryContract, ());
     let client = IdentityRegistryContractClient::new(&env, &contract_id);
 
     let admin = Address::generate(&env);
     client.init(&admin);
 
     // Test 1: Check is_verified on a random address (should be false)
     let random_address = Address::generate(&env);
     assert_eq!(client.is_verified(&random_address), false);
     assert_eq!(client.get_status(&random_address), ExpertStatus::Unverified);
 
     // Test 2: Verify an expert and check is_verified (should be true)
     let expert = Address::generate(&env);
+    env.mock_all_auths();
     client.add_expert(&expert);
     assert_eq!(client.is_verified(&expert), true);
     assert_eq!(client.get_status(&expert), ExpertStatus::Verified);
 
     // Test 3: Ban the expert and check is_verified (should be false)
     client.ban_expert(&expert);
     assert_eq!(client.is_verified(&expert), false);
     assert_eq!(client.get_status(&expert), ExpertStatus::Banned);
 }
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#[test]
fn test_getters() {
let env = Env::default();
env.mock_all_auths();
let contract_id = env.register(IdentityRegistryContract, ());
let client = IdentityRegistryContractClient::new(&env, &contract_id);
let admin = Address::generate(&env);
client.init(&admin);
// Test 1: Check is_verified on a random address (should be false)
let random_address = Address::generate(&env);
assert_eq!(client.is_verified(&random_address), false);
assert_eq!(client.get_status(&random_address), ExpertStatus::Unverified);
// Test 2: Verify an expert and check is_verified (should be true)
let expert = Address::generate(&env);
client.add_expert(&expert);
assert_eq!(client.is_verified(&expert), true);
assert_eq!(client.get_status(&expert), ExpertStatus::Verified);
// Test 3: Ban the expert and check is_verified (should be false)
client.ban_expert(&expert);
assert_eq!(client.is_verified(&expert), false);
assert_eq!(client.get_status(&expert), ExpertStatus::Banned);
#[test]
fn test_getters() {
let env = Env::default();
let contract_id = env.register(IdentityRegistryContract, ());
let client = IdentityRegistryContractClient::new(&env, &contract_id);
let admin = Address::generate(&env);
env.mock_all_auths();
client.init(&admin);
env.unmock_all_auths();
// Test 1: Check is_verified on a random address (should be false)
let random_address = Address::generate(&env);
assert_eq!(client.is_verified(&random_address), false);
assert_eq!(client.get_status(&random_address), ExpertStatus::Unverified);
// Test 2: Verify an expert and check is_verified (should be true)
let expert = Address::generate(&env);
env.mock_all_auths();
client.add_expert(&expert);
env.unmock_all_auths();
assert_eq!(client.is_verified(&expert), true);
assert_eq!(client.get_status(&expert), ExpertStatus::Verified);
// Test 3: Ban the expert and check is_verified (should be false)
env.mock_all_auths();
client.ban_expert(&expert);
env.unmock_all_auths();
assert_eq!(client.is_verified(&expert), false);
assert_eq!(client.get_status(&expert), ExpertStatus::Banned);
}
πŸ€– Prompt for AI Agents
In `@contracts/identity-registry-contract/src/test.rs` around lines 334 - 359, The
test currently calls env.mock_all_auths() up front which hides whether getters
require auth; update test_getters to perform the unauthenticated checks first
(call client.is_verified and client.get_status for random_address and for expert
before any mocking), then call env.mock_all_auths() only when performing admin
actions (wrap/mock only around client.add_expert(&expert) and
client.ban_expert(&expert) or call it immediately before those calls), keeping
admin initialization (client.init(&admin)) as needed; ensure references to
IdentityRegistryContractClient methods client.is_verified, client.get_status,
client.add_expert, and client.ban_expert are used in that order so the test
asserts no signature is required for getters.

}