async def test_get_credentials_for_request(mock_agent_controller: AcaPyClient): cred_precis = IndyCredPrecis(cred_info=IndyCredInfo( cred_def_id="WgWxqztrNooG92RXvxSTWv:3:CL:20:tag")) # V1 when(VerifierV1).get_credentials_for_request( controller=mock_agent_controller, proof_id="v1-abcd").thenReturn(get([cred_precis])) result = await test_module.get_credentials_for_request( proof_id="v1-abcd", aries_controller=mock_agent_controller, ) assert result == [cred_precis] verify(VerifierV1).get_credentials_for_request( controller=mock_agent_controller, proof_id="v1-abcd") # V2 when(VerifierV2).get_credentials_for_request( controller=mock_agent_controller, proof_id="v2-abcd").thenReturn(get([cred_precis])) result = await test_module.get_credentials_for_request( proof_id="v2-abcd", aries_controller=mock_agent_controller, ) assert result == [cred_precis] verify(VerifierV2).get_credentials_for_request( controller=mock_agent_controller, proof_id="v2-abcd")
async def test_send_proof_request_v2(mock_agent_controller: AcaPyClient): # V2 when(VerifierV2).send_proof_request(...).thenReturn( get(presentation_exchange_record_2)) when(mock_agent_controller.connection).get_connection( conn_id="abcde").thenReturn(get(conn_record)) when(verifier_utils).get_actor( did="did:key:z6MkvVT4kkAmhTb9srDHScsL1q7pVKt9cpUJUah2pKuYh4As" ).thenReturn(get(actor)) send_proof_request = test_module.SendProofRequest( connection_id="abcde", proof_request=indy_proof_request, protocol_version="v2", ) result = await test_module.send_proof_request( proof_request=send_proof_request, aries_controller=mock_agent_controller, ) assert result is presentation_exchange_record_2 verify(VerifierV2).send_proof_request(controller=mock_agent_controller, proof_request=send_proof_request)
async def test_get_proof_record(mock_agent_controller: AcaPyClient): # V1 when(VerifierV1).get_proof_record(controller=mock_agent_controller, proof_id="v1-abcd").thenReturn( get(presentation_exchange_record_1)) result = await test_module.get_proof_record( proof_id="v1-abcd", aries_controller=mock_agent_controller, ) assert result == presentation_exchange_record_1 verify(VerifierV1).get_proof_record(controller=mock_agent_controller, proof_id="v1-abcd") # V2 when(VerifierV2).get_proof_record(controller=mock_agent_controller, proof_id="v2-abcd").thenReturn( get(presentation_exchange_record_2)) result = await test_module.get_proof_record( proof_id="v2-abcd", aries_controller=mock_agent_controller, ) assert result == presentation_exchange_record_2 verify(VerifierV2).get_proof_record(controller=mock_agent_controller, proof_id="v2-abcd")
async def test_onboard_issuer_no_public_did( mock_agent_controller: AcaPyClient, ): endorser_controller = get_mock_agent_controller() when(acapy_wallet).get_public_did(controller=mock_agent_controller).thenRaise( CloudApiException(detail="Error") ) when(acapy_wallet).create_did(mock_agent_controller).thenReturn( get( Did( did="WgWxqztrNooG92RXvxSTWv", verkey="WgWxqztrNooG92RXvxSTWvWgWxqztrNooG92RXvxSTWv", ) ) ) when(acapy_ledger).register_nym_on_ledger(...).thenReturn(get()) when(acapy_ledger).accept_taa_if_required(...).thenReturn(get()) when(acapy_wallet).set_public_did(...).thenReturn(get()) when(acapy_wallet).get_public_did(controller=endorser_controller).thenReturn( get(Did(did="EndorserController", verkey="EndorserVerkey")) ) when(endorser_controller.out_of_band).create_invitation(...).thenReturn( get(InvitationRecord(invitation=InvitationMessage())) ) when(mock_agent_controller.out_of_band).receive_invitation(...).thenReturn( get(ConnRecord()) ) when(mock_agent_controller.endorse_transaction).set_endorser_role(...).thenReturn( get() ) when(mock_agent_controller.endorse_transaction).set_endorser_info(...).thenReturn( get() ) # Mock event listener when(onboarding).start_listener(...).thenReturn(get(mock_start_listener)) onboard_result = await onboarding.onboard_issuer( name="issuer_name", endorser_controller=endorser_controller, issuer_controller=mock_agent_controller, issuer_wallet_id="issuer_wallet_id", ) assert_that(onboard_result).has_did("did:sov:WgWxqztrNooG92RXvxSTWv") verify(acapy_wallet).create_did(mock_agent_controller) verify(acapy_ledger).register_nym_on_ledger( endorser_controller, did="WgWxqztrNooG92RXvxSTWv", verkey="WgWxqztrNooG92RXvxSTWvWgWxqztrNooG92RXvxSTWv", alias="issuer_name", ) verify(acapy_ledger).accept_taa_if_required(mock_agent_controller) verify(acapy_wallet).set_public_did(mock_agent_controller, "WgWxqztrNooG92RXvxSTWv")
async def test_onboard_verifier_no_public_did(mock_agent_controller: AcaPyClient): when(acapy_wallet).get_public_did(controller=mock_agent_controller).thenRaise( CloudApiException(detail="No public did found") ) did_key = "did:key:123" invitation_url = "https://invitation.com" when(mock_agent_controller.out_of_band).create_invitation(...).thenReturn( get( InvitationRecord( invitation_url=invitation_url, invitation=InvitationMessage(services=[{"recipientKeys": [did_key]}]), ) ) ) onboard_result = await onboarding.onboard_verifier( name="verifier_name", verifier_controller=mock_agent_controller ) assert_that(onboard_result).has_did(did_key) assert_that(onboard_result).has_didcomm_invitation(invitation_url) verify(mock_agent_controller.out_of_band).create_invitation( auto_accept=True, multi_use=True, body=InvitationCreateRequest( use_public_did=False, alias="Trust Registry verifier_name", handshake_protocols=["https://didcomm.org/didexchange/1.0"], ), )
async def test_reject_proof_request(mock_agent_controller: AcaPyClient): proof_request_v1 = test_module.RejectProofRequest(proof_id="v1-1234") # V1 when(VerifierV1).reject_proof_request( controller=mock_agent_controller, proof_request=proof_request_v1).thenReturn(get(None)) presentation_exchange_record_1.state = "request-received" when(VerifierV1).get_proof_record( controller=mock_agent_controller, proof_id=proof_request_v1.proof_id).thenReturn( get(presentation_exchange_record_1)) result = await test_module.reject_proof_request( proof_request=test_module.RejectProofRequest(proof_id="v1-1234"), aries_controller=mock_agent_controller, ) assert result is None verify(VerifierV1).reject_proof_request(controller=mock_agent_controller, proof_request=proof_request_v1) verify(VerifierV1).get_proof_record(controller=mock_agent_controller, proof_id=proof_request_v1.proof_id) proof_request_v2 = test_module.RejectProofRequest(proof_id="v2-1234") # V2 when(VerifierV2).reject_proof_request( controller=mock_agent_controller, proof_request=proof_request_v2).thenReturn(get(None)) presentation_exchange_record_2.state = "request-received" when(VerifierV2).get_proof_record( controller=mock_agent_controller, proof_id=proof_request_v2.proof_id).thenReturn( get(presentation_exchange_record_2)) result = await test_module.reject_proof_request( proof_request=test_module.RejectProofRequest(proof_id="v2-1234"), aries_controller=mock_agent_controller, ) assert result is None verify(VerifierV2).reject_proof_request(controller=mock_agent_controller, proof_request=proof_request_v2) verify(VerifierV2).get_proof_record(controller=mock_agent_controller, proof_id=proof_request_v2.proof_id)
async def test_get_proof_records(mock_agent_controller: AcaPyClient): # V1 and V2 with when(VerifierV1).get_proof_records( controller=mock_agent_controller).thenReturn( get([presentation_exchange_record_1 ])), when(VerifierV2).get_proof_records( controller=mock_agent_controller).thenReturn( get([presentation_exchange_record_2])): result = await test_module.get_proof_records( aries_controller=mock_agent_controller) assert result == [ presentation_exchange_record_1, presentation_exchange_record_2, ] verify(VerifierV1).get_proof_records(controller=mock_agent_controller) verify(VerifierV2).get_proof_records(controller=mock_agent_controller)
async def test_onboard_issuer_public_did_exists( mock_agent_controller: AcaPyClient, ): when(acapy_wallet).get_public_did(controller=mock_agent_controller).thenReturn( get( Did( did="WgWxqztrNooG92RXvxSTWv", verkey="WgWxqztrNooG92RXvxSTWvWgWxqztrNooG92RXvxSTWv", ) ) ) endorser_controller = get_mock_agent_controller() when(endorser_controller.out_of_band).create_invitation(...).thenReturn( get(InvitationRecord(invitation=InvitationMessage())) ) when(mock_agent_controller.out_of_band).receive_invitation(...).thenReturn( get(ConnRecord()) ) when(acapy_wallet).get_public_did(controller=endorser_controller).thenReturn( get(Did(did="EndorserController", verkey="EndorserVerkey")) ) when(mock_agent_controller.endorse_transaction).set_endorser_role(...).thenReturn( get() ) when(mock_agent_controller.endorse_transaction).set_endorser_info(...).thenReturn( get() ) # Mock event listener when(onboarding).start_listener(...).thenReturn(get(mock_start_listener)) onboard_result = await onboarding.onboard_issuer( name="issuer_name", endorser_controller=endorser_controller, issuer_controller=mock_agent_controller, issuer_wallet_id="issuer_wallet_id", ) assert_that(onboard_result).has_did("did:sov:WgWxqztrNooG92RXvxSTWv") verify(acapy_wallet, times=0).create_did(...) verify(endorser_controller.out_of_band).create_invitation( auto_accept=True, body=InvitationCreateRequest( handshake_protocols=["https://didcomm.org/didexchange/1.0"], use_public_did=True, ), ) verify(mock_agent_controller.out_of_band).receive_invitation( auto_accept=True, use_existing_connection=True, body=InvitationMessage(), alias="endorser", )
async def test_accept_proof_request_v2(mock_agent_controller: AcaPyClient): # V2 when(VerifierV2).accept_proof_request(...).thenReturn( get(presentation_exchange_record_2)) presentation = test_module.AcceptProofRequest( proof_id="v2-1234", presentation_spec=indy_pres_spec) when(test_module).assert_valid_prover( aries_controller=mock_agent_controller, prover=VerifierV2, presentation=presentation, ).thenReturn(get()) result = await test_module.accept_proof_request( presentation=presentation, aries_controller=mock_agent_controller, ) assert result is presentation_exchange_record_2 verify(VerifierV2).accept_proof_request(...)
async def test_delete_proof(mock_agent_controller: AcaPyClient): # V1 when(VerifierV1).delete_proof(controller=mock_agent_controller, proof_id="v1-1234").thenReturn(get(None)) result = await test_module.delete_proof( proof_id="v1-1234", aries_controller=mock_agent_controller) assert result is None verify(VerifierV1).delete_proof(controller=mock_agent_controller, proof_id="v1-1234") # V2 when(VerifierV2).delete_proof(controller=mock_agent_controller, proof_id="v2-1234").thenReturn(get(None)) result = await test_module.delete_proof( proof_id="v2-1234", aries_controller=mock_agent_controller) assert result is None verify(VerifierV2).delete_proof(controller=mock_agent_controller, proof_id="v2-1234")
async def test_onboard_verifier_no_recipient_keys(mock_agent_controller: AcaPyClient): when(acapy_wallet).get_public_did(controller=mock_agent_controller).thenRaise( CloudApiException(detail="No public did found") ) when(mock_agent_controller.out_of_band).create_invitation(...).thenReturn( get( InvitationRecord( invitation=InvitationMessage(services=[{"recipientKeys": []}]), ) ) ) with pytest.raises(CloudApiException, match="Error creating invitation:"): await onboarding.onboard_verifier( name="verifier_name", verifier_controller=mock_agent_controller )
async def test_onboard_verifier_public_did_exists(mock_agent_controller: AcaPyClient): when(acapy_wallet).get_public_did(controller=mock_agent_controller).thenReturn( get( Did( did="WgWxqztrNooG92RXvxSTWv", verkey="WgWxqztrNooG92RXvxSTWvWgWxqztrNooG92RXvxSTWv", ) ) ) onboard_result = await onboarding.onboard_verifier( name="verifier_name", verifier_controller=mock_agent_controller ) assert_that(onboard_result).has_did("did:sov:WgWxqztrNooG92RXvxSTWv") verify(acapy_wallet).get_public_did(controller=mock_agent_controller)