Skip to content

Commit

Permalink
add unit tests for registering revocation definition
Browse files Browse the repository at this point in the history
Signed-off-by: jamshale <[email protected]>
  • Loading branch information
jamshale committed Feb 8, 2024
1 parent 6b040e5 commit d16cb44
Showing 1 changed file with 213 additions and 0 deletions.
213 changes: 213 additions & 0 deletions aries_cloudagent/anoncreds/default/legacy_indy/tests/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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=[
Expand Down

0 comments on commit d16cb44

Please sign in to comment.