44from asynctest import TestCase as AsyncTestCase
55from more_itertools import side_effect
66
7+ from aries_cloudagent .revocation .models .issuer_cred_rev_record import (
8+ IssuerCredRevRecord ,
9+ )
10+
711from ...core .in_memory import InMemoryProfile
812from ...indy .issuer import IndyIssuer
913from ...protocols .issue_credential .v1_0 .models .credential_exchange import (
@@ -38,7 +42,25 @@ async def test_revoke_credential_publish(self):
3842 tails_local_path = TAILS_LOCAL ,
3943 send_entry = async_mock .CoroutineMock (),
4044 clear_pending = async_mock .CoroutineMock (),
45+ pending_pub = ["2" ],
4146 )
47+ issuer = async_mock .MagicMock (IndyIssuer , autospec = True )
48+ issuer .revoke_credentials = async_mock .CoroutineMock (
49+ return_value = (
50+ json .dumps (
51+ {
52+ "ver" : "1.0" ,
53+ "value" : {
54+ "prevAccum" : "1 ..." ,
55+ "accum" : "21 ..." ,
56+ "issued" : [1 ],
57+ },
58+ }
59+ ),
60+ [],
61+ )
62+ )
63+ self .profile .context .injector .bind_instance (IndyIssuer , issuer )
4264
4365 with async_mock .patch .object (
4466 test_module .IssuerCredRevRecord ,
@@ -64,26 +86,14 @@ async def test_revoke_credential_publish(self):
6486 return_value = mock_rev_reg
6587 )
6688
67- issuer = async_mock .MagicMock (IndyIssuer , autospec = True )
68- issuer .revoke_credentials = async_mock .CoroutineMock (
69- return_value = (
70- json .dumps (
71- {
72- "ver" : "1.0" ,
73- "value" : {
74- "prevAccum" : "1 ..." ,
75- "accum" : "21 ..." ,
76- "issued" : [1 ],
77- },
78- }
79- ),
80- [],
81- )
82- )
83- self .profile .context .injector .bind_instance (IndyIssuer , issuer )
84-
8589 await self .manager .revoke_credential_by_cred_ex_id (CRED_EX_ID , publish = True )
8690
91+ issuer .revoke_credentials .assert_awaited_once_with (
92+ mock_issuer_rev_reg_record .revoc_reg_id ,
93+ mock_issuer_rev_reg_record .tails_local_path ,
94+ ["2" , "1" ],
95+ )
96+
8797 async def test_revoke_cred_by_cxid_not_found (self ):
8898 CRED_EX_ID = "dummy-cxid"
8999
@@ -128,6 +138,8 @@ async def test_revoke_credential_pend(self):
128138 mock_issuer_rev_reg_record = async_mock .MagicMock (
129139 mark_pending = async_mock .CoroutineMock ()
130140 )
141+ issuer = async_mock .MagicMock (IndyIssuer , autospec = True )
142+ self .profile .context .injector .bind_instance (IndyIssuer , issuer )
131143
132144 with async_mock .patch .object (
133145 test_module , "IndyRevocation" , autospec = True
@@ -148,14 +160,13 @@ async def test_revoke_credential_pend(self):
148160 return_value = mock_issuer_rev_reg_record
149161 )
150162
151- issuer = async_mock .MagicMock (IndyIssuer , autospec = True )
152- self .profile .context .injector .bind_instance (IndyIssuer , issuer )
153-
154163 await self .manager .revoke_credential (REV_REG_ID , CRED_REV_ID , False )
155164 mock_issuer_rev_reg_record .mark_pending .assert_called_once_with (
156165 session .return_value , CRED_REV_ID
157166 )
158167
168+ issuer .revoke_credentials .assert_not_awaited ()
169+
159170 async def test_publish_pending_revocations_basic (self ):
160171 deltas = [
161172 {
@@ -415,3 +426,43 @@ async def test_retrieve_records(self):
415426 )
416427 assert ret_ex .connection_id == str (index )
417428 assert ret_ex .thread_id == str (1000 + index )
429+
430+ async def test_set_revoked_state (self ):
431+ CRED_REV_ID = "1"
432+
433+ async with self .profile .session () as session :
434+ exchange_record = V10CredentialExchange (
435+ connection_id = "mark-revoked-cid" ,
436+ thread_id = "mark-revoked-tid" ,
437+ initiator = V10CredentialExchange .INITIATOR_SELF ,
438+ revoc_reg_id = REV_REG_ID ,
439+ revocation_id = CRED_REV_ID ,
440+ role = V10CredentialExchange .ROLE_ISSUER ,
441+ state = V10CredentialExchange .STATE_ISSUED ,
442+ )
443+ await exchange_record .save (session )
444+
445+ crev_record = IssuerCredRevRecord (
446+ cred_ex_id = exchange_record .credential_exchange_id ,
447+ cred_def_id = CRED_DEF_ID ,
448+ rev_reg_id = REV_REG_ID ,
449+ cred_rev_id = CRED_REV_ID ,
450+ state = IssuerCredRevRecord .STATE_ISSUED ,
451+ )
452+ await crev_record .save (session )
453+
454+ await self .manager .set_cred_revoked_state (REV_REG_ID , [CRED_REV_ID ])
455+
456+ async with self .profile .session () as session :
457+ check_exchange_record = await V10CredentialExchange .retrieve_by_id (
458+ session , exchange_record .credential_exchange_id
459+ )
460+ assert (
461+ check_exchange_record .state
462+ == V10CredentialExchange .STATE_CREDENTIAL_REVOKED
463+ )
464+
465+ check_crev_record = await IssuerCredRevRecord .retrieve_by_id (
466+ session , crev_record .record_id
467+ )
468+ assert check_crev_record .state == IssuerCredRevRecord .STATE_REVOKED
0 commit comments