Skip to content

Commit 4a3ba57

Browse files
committed
test(identity-registry): add test_unban_expert coverage
Tests the full ban -> unban lifecycle: verifies status transitions (Verified -> Banned -> Verified), data_uri preservation, that total expert count does not increment on unban, and that NotBanned is returned when unbanning a non-banned expert.
1 parent 4cd0c5f commit 4a3ba57

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

  • contracts/identity-registry-contract/src

contracts/identity-registry-contract/src/test.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,3 +746,44 @@ fn test_expert_pagination() {
746746
}
747747
}
748748

749+
#[test]
750+
fn test_unban_expert() {
751+
let env = Env::default();
752+
let contract_id = env.register(IdentityRegistryContract, ());
753+
let client = IdentityRegistryContractClient::new(&env, &contract_id);
754+
755+
let admin = Address::generate(&env);
756+
let expert = Address::generate(&env);
757+
758+
client.init(&admin);
759+
760+
env.mock_all_auths();
761+
let data_uri = String::from_str(&env, "ipfs://unban");
762+
client.add_expert(&expert, &data_uri);
763+
764+
// Initial status: Verified
765+
assert_eq!(client.get_status(&expert), ExpertStatus::Verified);
766+
let initial_total = client.get_total_experts();
767+
768+
// Ban the expert
769+
client.ban_expert(&expert);
770+
assert_eq!(client.get_status(&expert), ExpertStatus::Banned);
771+
772+
// Unban the expert
773+
client.unban_expert(&expert);
774+
assert_eq!(client.get_status(&expert), ExpertStatus::Verified);
775+
776+
// Data URI should be preserved
777+
env.as_contract(&contract_id, || {
778+
let rec = storage::get_expert_record(&env, &expert);
779+
assert_eq!(rec.data_uri, data_uri);
780+
});
781+
782+
// Total experts should NOT have increased
783+
assert_eq!(client.get_total_experts(), initial_total);
784+
785+
// Test: Try to unban a non-banned expert (should fail with NotBanned)
786+
let result = client.try_unban_expert(&expert);
787+
assert_eq!(result, Err(Ok(RegistryError::NotBanned)));
788+
}
789+

0 commit comments

Comments
 (0)