|
1 | 1 | #![no_std] |
2 | | -use soroban_sdk::{contract, contractimpl, contracttype, Address, Bytes, BytesN, Env, Vec}; |
| 2 | +use soroban_sdk::{contract, contractimpl, contracttype, symbol_short, Address, Bytes, BytesN, Env, Vec}; |
3 | 3 |
|
4 | 4 | // ── Storage Keys ──────────────────────────────────────────────────────────── |
5 | 5 |
|
@@ -62,10 +62,13 @@ impl IpRegistry { |
62 | 62 | ids.push_back(id); |
63 | 63 | env.storage().persistent().set(&DataKey::OwnerIps(owner), &ids); |
64 | 64 |
|
65 | | - env.storage().persistent().set(&DataKey::NextId, &(id + 1)); |
66 | | - env.storage() |
67 | | - .persistent() |
68 | | - .extend_ttl(&DataKey::NextId, TTL_THRESHOLD, TTL_BUMP); |
| 65 | + env.storage().instance().set(&DataKey::NextId, &(id + 1)); |
| 66 | + |
| 67 | + env.events().publish( |
| 68 | + (symbol_short!("ip_commit"), owner), |
| 69 | + (id, record.timestamp), |
| 70 | + ); |
| 71 | + |
69 | 72 | id |
70 | 73 | } |
71 | 74 |
|
@@ -155,6 +158,27 @@ mod tests { |
155 | 158 | use super::*; |
156 | 159 | use soroban_sdk::{testutils::Address as _, Env}; |
157 | 160 |
|
| 161 | + #[test] |
| 162 | + fn commit_ip_emits_event() { |
| 163 | + let env = Env::default(); |
| 164 | + env.mock_all_auths(); |
| 165 | + let contract_id = env.register(IpRegistry, ()); |
| 166 | + let client = IpRegistryClient::new(&env, &contract_id); |
| 167 | + |
| 168 | + let owner = Address::generate(&env); |
| 169 | + let hash = BytesN::from_array(&env, &[0xabu8; 32]); |
| 170 | + let id = client.commit_ip(&owner, &hash); |
| 171 | + |
| 172 | + let events = env.events().all(); |
| 173 | + assert_eq!(events.len(), 1); |
| 174 | + let (_, topics, data): (_, soroban_sdk::Vec<soroban_sdk::Val>, soroban_sdk::Val) = |
| 175 | + events.get(0).unwrap(); |
| 176 | + // topic[1] is the owner address; data is (ip_id, timestamp) |
| 177 | + let (emitted_id, _timestamp): (u64, u64) = |
| 178 | + soroban_sdk::FromVal::from_val(&env, &data); |
| 179 | + assert_eq!(emitted_id, id); |
| 180 | + } |
| 181 | + |
158 | 182 | #[test] |
159 | 183 | fn unknown_owner_returns_none() { |
160 | 184 | let env = Env::default(); |
|
0 commit comments