@@ -6,10 +6,13 @@ mod tests {
66 use soroban_sdk:: testutils:: Events ;
77 use soroban_sdk:: { symbol_short, Address , BytesN , Env , IntoVal , TryFromVal , Vec } ;
88
9+ use crate :: types:: REVOKE_TOPIC ;
10+
911 #[ contractclient( name = "IpRegistryClient" ) ]
1012 #[ allow( dead_code) ]
1113 pub trait IpRegistry {
1214 fn commit_ip ( env : Env , owner : Address , commitment_hash : BytesN < 32 > ) -> u64 ;
15+ fn batch_commit_ip ( env : Env , owner : Address , commitment_hashes : Vec < BytesN < 32 > > ) -> Vec < u64 > ;
1316 fn get_ip ( env : Env , ip_id : u64 ) -> IpRecord ;
1417 fn verify_commitment (
1518 env : Env ,
@@ -28,6 +31,8 @@ mod tests {
2831 blinding_factor : BytesN < 32 > ,
2932 ) -> bool ;
3033 fn get_partial_disclosure ( env : Env , ip_id : u64 ) -> Option < BytesN < 32 > > ;
34+ fn validate_upgrade ( env : Env , new_wasm_hash : BytesN < 32 > ) ;
35+ fn upgrade ( env : Env , new_wasm_hash : BytesN < 32 > ) ;
3136 }
3237
3338 #[ test]
@@ -245,6 +250,33 @@ mod tests {
245250 assert ! ( client. get_ip( & ip_id) . revoked) ;
246251 }
247252
253+ #[ test]
254+ fn test_revoke_ip_emits_event ( ) {
255+ let env = Env :: default ( ) ;
256+ let contract_id = env. register ( crate :: IpRegistry , ( ) ) ;
257+ let client = IpRegistryClient :: new ( & env, & contract_id) ;
258+
259+ let owner = <Address as TestAddress >:: generate ( & env) ;
260+ let commitment = BytesN :: from_array ( & env, & [ 9u8 ; 32 ] ) ;
261+
262+ env. mock_all_auths ( ) ;
263+ let ip_id = client. commit_ip ( & owner, & commitment) ;
264+
265+ // Clear previous events (from commit_ip)
266+ env. events ( ) . clear ( ) ;
267+
268+ client. revoke_ip ( & ip_id) ;
269+
270+ let all_events = env. events ( ) . all ( ) ;
271+ assert_eq ! ( all_events. len( ) , 1 ) ;
272+ let event = all_events. get ( 0 ) . unwrap ( ) ;
273+ let expected_topics = ( REVOKE_TOPIC , owner. clone ( ) ) . into_val ( & env) ;
274+ assert_eq ! ( event. 1 , expected_topics) ;
275+ let observed_data: ( u64 , u64 ) = TryFromVal :: try_from_val ( & env, & event. 2 ) . unwrap ( ) ;
276+ assert_eq ! ( observed_data. 0 , ip_id) ;
277+ assert_eq ! ( observed_data. 1 , env. ledger( ) . timestamp( ) ) ;
278+ }
279+
248280 #[ test]
249281 #[ should_panic]
250282 fn test_revoke_ip_twice_panics ( ) {
@@ -486,4 +518,114 @@ mod tests {
486518
487519 assert_eq ! ( client. get_partial_disclosure( & ip_id) , None ) ;
488520 }
521+
522+ #[ test]
523+ fn test_batch_commit_ip_single ( ) {
524+ let env = Env :: default ( ) ;
525+ env. mock_all_auths ( ) ;
526+ let contract_id = env. register ( crate :: IpRegistry , ( ) ) ;
527+ let client = IpRegistryClient :: new ( & env, & contract_id) ;
528+
529+ let owner = <Address as TestAddress >:: generate ( & env) ;
530+ let commitments = Vec :: from_array ( & env, [ BytesN :: from_array ( & env, & [ 1u8 ; 32 ] ) ] ) ;
531+
532+ let ids = client. batch_commit_ip ( & owner, & commitments) ;
533+ assert_eq ! ( ids. len( ) , 1 ) ;
534+ assert_eq ! ( ids. get( 0 ) . unwrap( ) , 1 ) ;
535+ }
536+
537+ #[ test]
538+ fn test_batch_commit_ip_five ( ) {
539+ let env = Env :: default ( ) ;
540+ env. mock_all_auths ( ) ;
541+ let contract_id = env. register ( crate :: IpRegistry , ( ) ) ;
542+ let client = IpRegistryClient :: new ( & env, & contract_id) ;
543+
544+ let owner = <Address as TestAddress >:: generate ( & env) ;
545+ let commitments = Vec :: from_array ( & env, [
546+ BytesN :: from_array ( & env, & [ 1u8 ; 32 ] ) ,
547+ BytesN :: from_array ( & env, & [ 2u8 ; 32 ] ) ,
548+ BytesN :: from_array ( & env, & [ 3u8 ; 32 ] ) ,
549+ BytesN :: from_array ( & env, & [ 4u8 ; 32 ] ) ,
550+ BytesN :: from_array ( & env, & [ 5u8 ; 32 ] ) ,
551+ ] ) ;
552+
553+ let ids = client. batch_commit_ip ( & owner, & commitments) ;
554+ assert_eq ! ( ids. len( ) , 5 ) ;
555+ for i in 0 ..5 {
556+ assert_eq ! ( ids. get( i) . unwrap( ) , ( i + 1 ) as u64 ) ;
557+ }
558+ }
559+
560+ #[ test]
561+ fn test_batch_commit_ip_hundred ( ) {
562+ let env = Env :: default ( ) ;
563+ env. mock_all_auths ( ) ;
564+ let contract_id = env. register ( crate :: IpRegistry , ( ) ) ;
565+ let client = IpRegistryClient :: new ( & env, & contract_id) ;
566+
567+ let owner = <Address as TestAddress >:: generate ( & env) ;
568+ let mut commitments = Vec :: new ( & env) ;
569+ for i in 0 ..100 {
570+ commitments. push_back ( BytesN :: from_array ( & env, & [ i as u8 ; 32 ] ) ) ;
571+ }
572+
573+ let ids = client. batch_commit_ip ( & owner, & commitments) ;
574+ assert_eq ! ( ids. len( ) , 100 ) ;
575+ for i in 0 ..100 {
576+ assert_eq ! ( ids. get( i) . unwrap( ) , ( i + 1 ) as u64 ) ;
577+ }
578+ }
579+
580+ #[ test]
581+ fn test_batch_commit_ip_sequential_with_single ( ) {
582+ let env = Env :: default ( ) ;
583+ env. mock_all_auths ( ) ;
584+ let contract_id = env. register ( crate :: IpRegistry , ( ) ) ;
585+ let client = IpRegistryClient :: new ( & env, & contract_id) ;
586+
587+ let owner = <Address as TestAddress >:: generate ( & env) ;
588+
589+ // Single commit
590+ let id1 = client. commit_ip ( & owner, & BytesN :: from_array ( & env, & [ 10u8 ; 32 ] ) ) ;
591+ assert_eq ! ( id1, 1 ) ;
592+
593+ // Batch commit 3
594+ let commitments = Vec :: from_array ( & env, [
595+ BytesN :: from_array ( & env, & [ 11u8 ; 32 ] ) ,
596+ BytesN :: from_array ( & env, & [ 12u8 ; 32 ] ) ,
597+ BytesN :: from_array ( & env, & [ 13u8 ; 32 ] ) ,
598+ ] ) ;
599+ let ids = client. batch_commit_ip ( & owner, & commitments) ;
600+ assert_eq ! ( ids. len( ) , 3 ) ;
601+ assert_eq ! ( ids. get( 0 ) . unwrap( ) , 2 ) ;
602+ assert_eq ! ( ids. get( 1 ) . unwrap( ) , 3 ) ;
603+ assert_eq ! ( ids. get( 2 ) . unwrap( ) , 4 ) ;
604+
605+ // Another single
606+ let id5 = client. commit_ip ( & owner, & BytesN :: from_array ( & env, & [ 14u8 ; 32 ] ) ) ;
607+ assert_eq ! ( id5, 5 ) ;
608+ }
609+
610+ #[ test]
611+ fn test_validate_upgrade_accepts_non_zero_hash ( ) {
612+ let env = Env :: default ( ) ;
613+ let contract_id = env. register ( crate :: IpRegistry , ( ) ) ;
614+ let client = IpRegistryClient :: new ( & env, & contract_id) ;
615+
616+ let valid_hash = BytesN :: from_array ( & env, & [ 1u8 ; 32 ] ) ;
617+ // Should not panic
618+ client. validate_upgrade ( & valid_hash) ;
619+ }
620+
621+ #[ test]
622+ #[ should_panic]
623+ fn test_validate_upgrade_rejects_zero_hash ( ) {
624+ let env = Env :: default ( ) ;
625+ let contract_id = env. register ( crate :: IpRegistry , ( ) ) ;
626+ let client = IpRegistryClient :: new ( & env, & contract_id) ;
627+
628+ let zero_hash = BytesN :: from_array ( & env, & [ 0u8 ; 32 ] ) ;
629+ client. validate_upgrade ( & zero_hash) ;
630+ }
489631}
0 commit comments