From d16cb44c0f805185a55b2cc3fa39fcfe52cacf61 Mon Sep 17 00:00:00 2001 From: jamshale Date: Thu, 8 Feb 2024 17:36:27 +0000 Subject: [PATCH] add unit tests for registering revocation definition Signed-off-by: jamshale --- .../legacy_indy/tests/test_registry.py | 213 ++++++++++++++++++ 1 file changed, 213 insertions(+) diff --git a/aries_cloudagent/anoncreds/default/legacy_indy/tests/test_registry.py b/aries_cloudagent/anoncreds/default/legacy_indy/tests/test_registry.py index 2460b2079b..c661a69751 100644 --- a/aries_cloudagent/anoncreds/default/legacy_indy/tests/test_registry.py +++ b/aries_cloudagent/anoncreds/default/legacy_indy/tests/test_registry.py @@ -37,6 +37,7 @@ CredDefValue, CredDefValuePrimary, ) +from ....models.anoncreds_revocation import RevRegDef, RevRegDefResult, RevRegDefValue from .. import registry as test_module B58 = alphabet if isinstance(alphabet, str) else alphabet.decode("ascii") @@ -512,6 +513,218 @@ async def test_register_credential_definition_with_transaction_and_auto_request( BaseResponder )._instance.send.called + async def test_register_revocation_registry_definition_no_endorsement(self): + self.profile.context.injector.bind_instance( + BaseLedger, + mock.MagicMock(send_revoc_reg_def=mock.CoroutineMock(return_value=1)), + ) + result = await self.registry.register_revocation_registry_definition( + self.profile, + RevRegDef( + tag="tag", + cred_def_id="CsQY9MGeD3CQP4EyuVFo5m:3:CL:14951:MYCO_Biomarker", + value=RevRegDefValue( + max_cred_num=100, + public_keys={ + "accum_key": {"z": "1 0BB...386"}, + }, + tails_hash="not-correct-hash", + tails_location="http://tails-server.com", + ), + issuer_id="CsQY9MGeD3CQP4EyuVFo5m", + type="CL_ACCUM", + ), + {}, + ) + + assert isinstance(result, RevRegDefResult) + assert self.profile.context.injector.get_provider( + BaseLedger + )._instance.send_revoc_reg_def.called + + @mock.patch.object( + ConnRecord, + "retrieve_by_id", + return_value=mock.CoroutineMock( + metadata_get=mock.CoroutineMock(return_value={"endorser_did": "test_did"}) + ), + ) + @mock.patch.object( + TransactionManager, + "create_record", + return_value=TransactionRecord(), + ) + @mock.patch.object( + TransactionManager, + "create_request", + return_value=(TransactionRecord(), "transaction_request"), + ) + async def test_register_revocation_registry_definition_with_author_role( + self, mock_create_request, mock_create_record, mock_endorser_connection + ): + self.profile.context.injector.bind_instance( + BaseLedger, + mock.MagicMock(send_revoc_reg_def=mock.CoroutineMock(return_value=1)), + ) + self.profile.settings.set_value("endorser.author", True) + self.profile.context.injector.bind_instance( + BaseLedger, + mock.MagicMock( + send_revoc_reg_def=mock.CoroutineMock( + return_value=("id", {"signed_txn": "txn"}) + ) + ), + ) + self.profile.context.injector.bind_instance( + BaseResponder, + mock.MagicMock(send=mock.CoroutineMock(return_value=None)), + ) + + self.profile.settings.set_value("endorser.auto_request", True) + + result = await self.registry.register_revocation_registry_definition( + self.profile, + RevRegDef( + tag="tag", + cred_def_id="CsQY9MGeD3CQP4EyuVFo5m:3:CL:14951:MYCO_Biomarker", + value=RevRegDefValue( + max_cred_num=100, + public_keys={ + "accum_key": {"z": "1 0BB...386"}, + }, + tails_hash="not-correct-hash", + tails_location="http://tails-server.com", + ), + issuer_id="CsQY9MGeD3CQP4EyuVFo5m", + type="CL_ACCUM", + ), + { + "endorser_connection_id": "test_connection_id", + }, + ) + + assert isinstance(result, RevRegDefResult) + assert self.profile.context.injector.get_provider( + BaseLedger + )._instance.send_revoc_reg_def.called + assert mock_create_record.called + assert mock_create_request.called + assert self.profile.context.injector.get_provider( + BaseResponder + )._instance.send.called + + @mock.patch.object( + ConnRecord, + "retrieve_by_id", + return_value=mock.CoroutineMock( + metadata_get=mock.CoroutineMock(return_value={"endorser_did": "test_did"}) + ), + ) + @mock.patch.object( + TransactionManager, + "create_record", + return_value=TransactionRecord(), + ) + async def test_register_revocation_registry_definition_with_create_transaction_option( + self, mock_create_record, mock_endorser_connection + ): + self.profile.context.injector.bind_instance( + BaseLedger, + mock.MagicMock(send_revoc_reg_def=mock.CoroutineMock(return_value=1)), + ) + self.profile.context.injector.bind_instance( + BaseLedger, + mock.MagicMock( + send_revoc_reg_def=mock.CoroutineMock( + return_value=("id", {"signed_txn": "txn"}) + ) + ), + ) + + result = await self.registry.register_revocation_registry_definition( + self.profile, + RevRegDef( + tag="tag", + cred_def_id="CsQY9MGeD3CQP4EyuVFo5m:3:CL:14951:MYCO_Biomarker", + value=RevRegDefValue( + max_cred_num=100, + public_keys={ + "accum_key": {"z": "1 0BB...386"}, + }, + tails_hash="not-correct-hash", + tails_location="http://tails-server.com", + ), + issuer_id="CsQY9MGeD3CQP4EyuVFo5m", + type="CL_ACCUM", + ), + { + "endorser_connection_id": "test_connection_id", + "create_transaction_for_endorser": True, + }, + ) + + assert isinstance(result, RevRegDefResult) + assert self.profile.context.injector.get_provider( + BaseLedger + )._instance.send_revoc_reg_def.called + assert mock_create_record.called + + @mock.patch.object( + ConnRecord, + "retrieve_by_id", + return_value=mock.CoroutineMock( + metadata_get=mock.CoroutineMock(return_value={"endorser_did": "test_did"}) + ), + ) + @mock.patch.object( + TransactionManager, + "create_record", + return_value=TransactionRecord(), + ) + async def test_register_revocation_registry_definition_with_create_transaction_and_auto_request( + self, mock_create_record, mock_endorser_connection + ): + self.profile.context.injector.bind_instance( + BaseLedger, + mock.MagicMock(send_revoc_reg_def=mock.CoroutineMock(return_value=1)), + ) + self.profile.context.injector.bind_instance( + BaseLedger, + mock.MagicMock( + send_revoc_reg_def=mock.CoroutineMock( + return_value=("id", {"signed_txn": "txn"}) + ) + ), + ) + + result = await self.registry.register_revocation_registry_definition( + self.profile, + RevRegDef( + tag="tag", + cred_def_id="CsQY9MGeD3CQP4EyuVFo5m:3:CL:14951:MYCO_Biomarker", + value=RevRegDefValue( + max_cred_num=100, + public_keys={ + "accum_key": {"z": "1 0BB...386"}, + }, + tails_hash="not-correct-hash", + tails_location="http://tails-server.com", + ), + issuer_id="CsQY9MGeD3CQP4EyuVFo5m", + type="CL_ACCUM", + ), + { + "endorser_connection_id": "test_connection_id", + "create_transaction_for_endorser": True, + }, + ) + + assert isinstance(result, RevRegDefResult) + assert self.profile.context.injector.get_provider( + BaseLedger + )._instance.send_revoc_reg_def.called + assert mock_create_record.called + async def test_txn_submit(self): self.profile.inject = mock.MagicMock( side_effect=[