def test_init(): present_proof = PresentProof(for_relationship, thread_id, name, proof_attrs, proof_predicates) assert present_proof.for_relationship == for_relationship assert present_proof.thread_id == thread_id assert present_proof.name == name assert present_proof.proof_attrs == proof_attrs assert present_proof.proof_predicates == proof_predicates
async def test_accept_proposal(): present_proof = PresentProof(for_relationship, thread_id) msg = present_proof.accept_proposal_msg() assert msg['@type'] == '{};spec/{}/{}/{}'.format( COMMUNITY_MSG_QUALIFIER, PresentProof.MSG_FAMILY, PresentProof.MSG_FAMILY_VERSION, PresentProof.ACCEPT_PROPOSAL) assert msg['@id'] is not None assert msg['~for_relationship'] == for_relationship assert msg['~thread'] is not None assert msg['~thread']['thid'] == thread_id
async def test_status(): present_proof = PresentProof(for_relationship, thread_id) msg = present_proof.status_msg() assert msg['@type'] == '{};spec/{}/{}/{}'.format( COMMUNITY_MSG_QUALIFIER, PresentProof.MSG_FAMILY, PresentProof.MSG_FAMILY_VERSION, PresentProof.STATUS) assert msg['@id'] is not None assert msg['~for_relationship'] == for_relationship assert msg['~thread'] is not None assert msg['~thread']['thid'] == thread_id
async def test_reject(): present_proof = PresentProof(for_relationship, thread_id) msg = present_proof.reject_msg(reject_reason) assert msg['@type'] == '{};spec/{}/{}/{}'.format( COMMUNITY_MSG_QUALIFIER, PresentProof.MSG_FAMILY, PresentProof.MSG_FAMILY_VERSION, PresentProof.REJECT) assert msg['@id'] is not None assert msg['~for_relationship'] == for_relationship assert msg['~thread'] is not None assert msg['~thread']['thid'] == thread_id assert msg['reason'] == reject_reason
async def test_request(): present_proof = PresentProof(for_relationship, None, name, proof_attrs, proof_predicates) msg = present_proof.request_msg() assert msg['@type'] == '{};spec/{}/{}/{}'.format( COMMUNITY_MSG_QUALIFIER, PresentProof.MSG_FAMILY, PresentProof.MSG_FAMILY_VERSION, PresentProof.PROOF_REQUEST) assert msg['@id'] is not None assert msg['~for_relationship'] == for_relationship assert msg['~thread'] is not None assert msg['~thread']['thid'] is not None assert msg['name'] == name assert msg['proof_attrs'] == proof_attrs assert msg['proof_predicates'] == proof_predicates
async def request_proof(loop, for_did): global issuer_did # input parameters for request proof proof_name = 'Proof of Degree' proof_attrs = [{ 'name': 'name', 'restrictions': [{ 'issuer_did': issuer_did }] }, { 'name': 'degree', 'restrictions': [{ 'issuer_did': issuer_did }] }] # constructor for the Present Proof protocol proof = PresentProof(for_did, None, proof_name, proof_attrs) spinner = make_spinner( 'Waiting for proof presentation from Connect.me') # Console spinner first_step = loop.create_future() # handler for the result of the proof presentation async def proof_handler(msg_name, message): spinner.stop_and_persist('Done') print_message(msg_name, message) if msg_name == PresentProof.PRESENTATION_RESULT: first_step.set_result( None) # proof data contained inside `message` else: non_handled(f'Message name is not handled - {msg_name}', message) # adds handler to the set of handlers handlers.add_handler(PresentProof.MSG_FAMILY, PresentProof.MSG_FAMILY_VERSION, proof_handler) spinner.start() # request proof await proof.request(context) await first_step # wait for connect.me user to present the requested proof