Skip to content

Commit 54663ae

Browse files
authored
Merge pull request #97 from munyanezaarmel/test/protocol-admin-read-method
test: add unit tests for protocol admin read method (#72)
2 parents 3b02dbd + f28eedc commit 54663ae

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
use creator_keys::{CreatorKeysContract, CreatorKeysContractClient};
2+
use soroban_sdk::{testutils::Address as _, Address, Env};
3+
4+
#[test]
5+
fn test_get_protocol_admin_returns_none_initially() {
6+
let env = Env::default();
7+
let contract_id = env.register(CreatorKeysContract, ());
8+
let client = CreatorKeysContractClient::new(&env, &contract_id);
9+
10+
let result = client.get_protocol_admin();
11+
assert_eq!(result, None);
12+
}
13+
14+
#[test]
15+
fn test_get_protocol_admin_returns_set_address() {
16+
let env = Env::default();
17+
env.mock_all_auths();
18+
let contract_id = env.register(CreatorKeysContract, ());
19+
let client = CreatorKeysContractClient::new(&env, &contract_id);
20+
21+
let admin = Address::generate(&env);
22+
let new_admin = Address::generate(&env);
23+
client.set_protocol_admin(&admin, &new_admin);
24+
25+
let result = client.get_protocol_admin();
26+
assert_eq!(result, Some(new_admin));
27+
}
28+
29+
#[test]
30+
fn test_get_protocol_admin_persists_across_reads() {
31+
let env = Env::default();
32+
env.mock_all_auths();
33+
let contract_id = env.register(CreatorKeysContract, ());
34+
let client = CreatorKeysContractClient::new(&env, &contract_id);
35+
36+
let admin = Address::generate(&env);
37+
let new_admin = Address::generate(&env);
38+
client.set_protocol_admin(&admin, &new_admin);
39+
40+
let first_read = client.get_protocol_admin();
41+
let second_read = client.get_protocol_admin();
42+
assert_eq!(first_read, second_read);
43+
assert_eq!(first_read, Some(new_admin));
44+
}
45+
46+
#[test]
47+
fn test_get_protocol_admin_is_isolated_from_treasury() {
48+
// Ensures the admin read path does not bleed into treasury storage
49+
let env = Env::default();
50+
env.mock_all_auths();
51+
let contract_id = env.register(CreatorKeysContract, ());
52+
let client = CreatorKeysContractClient::new(&env, &contract_id);
53+
54+
let admin = Address::generate(&env);
55+
let treasury = Address::generate(&env);
56+
// Only set treasury, not protocol admin
57+
client.set_treasury_address(&admin, &treasury);
58+
59+
let result = client.get_protocol_admin();
60+
assert_eq!(result, None); // admin storage must be untouched
61+
}
62+
63+
#[test]
64+
fn test_get_protocol_admin_overwrite_returns_latest() {
65+
// Admin address can be updated and the read returns the most recent value
66+
let env = Env::default();
67+
env.mock_all_auths();
68+
let contract_id = env.register(CreatorKeysContract, ());
69+
let client = CreatorKeysContractClient::new(&env, &contract_id);
70+
71+
let admin = Address::generate(&env);
72+
let first_admin = Address::generate(&env);
73+
let second_admin = Address::generate(&env);
74+
75+
client.set_protocol_admin(&admin, &first_admin);
76+
assert_eq!(client.get_protocol_admin(), Some(first_admin));
77+
78+
client.set_protocol_admin(&admin, &second_admin);
79+
assert_eq!(client.get_protocol_admin(), Some(second_admin));
80+
}

0 commit comments

Comments
 (0)