Skip to content

Commit e0a03ff

Browse files
Merge pull request #102 from Fidelis900/feat/commit-ip-event
Feat/commit ip event
2 parents 3e436c7 + f13c387 commit e0a03ff

1 file changed

Lines changed: 29 additions & 5 deletions

File tree

  • contracts/ip_registry/src

contracts/ip_registry/src/lib.rs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![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};
33

44
// ── Storage Keys ────────────────────────────────────────────────────────────
55

@@ -62,10 +62,13 @@ impl IpRegistry {
6262
ids.push_back(id);
6363
env.storage().persistent().set(&DataKey::OwnerIps(owner), &ids);
6464

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+
6972
id
7073
}
7174

@@ -155,6 +158,27 @@ mod tests {
155158
use super::*;
156159
use soroban_sdk::{testutils::Address as _, Env};
157160

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+
158182
#[test]
159183
fn unknown_owner_returns_none() {
160184
let env = Env::default();

0 commit comments

Comments
 (0)