Skip to content
This repository has been archived by the owner on Sep 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #110 from PeterStrob/feat/pres_integration_test
Browse files Browse the repository at this point in the history
feat:added presentation exchange flow integration test
  • Loading branch information
dbluhm committed Nov 5, 2021
2 parents 534da74 + efd00b9 commit fd15350
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Fields:
def __init__(self, record: PresExRecord, **kwargs):
super().__init__(**kwargs)
self.raw_repr = record
self.presentation_request = record.presentation_request
self.presentation_request = record.presentation_request.serialize()
self.presentation_exchange_id = record.presentation_exchange_id
self.matching_credentials = []
self.page = None
Expand Down
2 changes: 1 addition & 1 deletion int/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ services:
ACAPY_TOOLBOX_LOG_LEVEL: DEBUG
ports:
- "3001:3001"
command: start -it http 0.0.0.0 3000 -ot http -e http://acapy_plugin_agent:3000 --admin 0.0.0.0 3001 --admin-insecure-mode --plugin acapy_plugin_toolbox --genesis-url https://raw.githubusercontent.com/Indicio-tech/indicio-network/master/genesis_files/pool_transactions_testnet_genesis --wallet-type indy --wallet-name default --wallet-key "insecure, for use in testing only" --auto-provision --auto-ping-connection --monitor-ping
command: start -it http 0.0.0.0 3000 -ot http -e http://acapy_plugin_agent:3000 --admin 0.0.0.0 3001 --admin-insecure-mode --plugin acapy_plugin_toolbox --genesis-url https://raw.githubusercontent.com/Indicio-tech/indicio-network/master/genesis_files/pool_transactions_testnet_genesis --wallet-type indy --wallet-name default --wallet-key "insecure, for use in testing only" --auto-provision --auto-ping-connection --monitor-ping --auto-store-credential --preserve-exchange-records

echo:
image: echo-agent
Expand Down
14 changes: 3 additions & 11 deletions int/tests/test_holder.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,28 +166,20 @@ async def test_holder_credential_exchange(
async def test_credentials_get_list(
backchannel: Client,
connection,
issuer_holder_connection,
endorser_did,
create_schema,
create_cred_def,
issue_credential,
):
cred1 = issue_credential
cred2 = issue_credential
cred = issue_credential
credentials_get_list = await connection.send_and_await_reply_async(
{
"@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/admin-holder/0.1/credentials-get-list"
}
)
cred1_set = set([result.credential_exchange_id for result in cred1.results])
cred2_set = set([result.credential_exchange_id for result in cred2.results])
cred_set = set([result.credential_exchange_id for result in cred.results])
cred_get_list_set = set(
[cred["credential_exchange_id"] for cred in credentials_get_list["results"]]
)

assert (
credentials_get_list["@type"]
== "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/admin-holder/0.1/credentials-list"
)
assert cred1_set.issubset(cred_get_list_set)
assert cred2_set.issubset(cred_get_list_set)
assert cred_set.issubset(cred_get_list_set)
77 changes: 77 additions & 0 deletions int/tests/test_presentation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from acapy_client.models.indy_proof_request import IndyProofRequest
from acapy_client.models.indy_proof_request_requested_attributes import (
IndyProofRequestRequestedAttributes,
)
from acapy_client.models.indy_proof_request_requested_predicates import (
IndyProofRequestRequestedPredicates,
)
from acapy_client.models.v10_presentation_send_request_request import (
V10PresentationSendRequestRequest,
)
from acapy_client.types import Unset
import pytest
from typing import cast
from acapy_client import Client
from acapy_client.models.conn_record import ConnRecord
from acapy_client.api.present_proof_v10 import send_proof_request

from tests.test_holder import issue_credential, issuer_holder_connection
from tests.conftest import connection


@pytest.mark.asyncio
async def test_presentation(
backchannel: Client,
issue_credential,
issuer_holder_connection,
wait_for_message,
connection,
):
"""Test the presentation message and notification flows."""
verifier, prover = issuer_holder_connection
verifier = cast(ConnRecord, verifier)
prover = cast(ConnRecord, prover)
assert not isinstance(verifier.connection_id, Unset)
assert not isinstance(prover.connection_id, Unset)
proof_req = await send_proof_request.asyncio(
client=backchannel,
json_body=V10PresentationSendRequestRequest(
connection_id=prover.connection_id,
proof_request=IndyProofRequest(
name="test-proof",
requested_attributes=IndyProofRequestRequestedAttributes.from_dict(
{"attr_1_0": {"name": "attr_1_0"}}
),
requested_predicates=IndyProofRequestRequestedPredicates(),
version="0.1",
),
),
)
presentation_request_received = await wait_for_message(
msg_type="did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/admin-holder/0.1/presentation-request-received"
)
assert presentation_request_received["matching_credentials"]
await connection.send_async(
{
"@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/admin-holder/0.1/presentation-request-approve",
"@id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"presentation_exchange_id": presentation_request_received[
"presentation_exchange_id"
],
"self_attested_attributes": {},
"requested_attributes": {
"attr_1_0": {
"cred_id": presentation_request_received["matching_credentials"][0][
"cred_info"
]["referent"],
"revealed": True,
}
},
"requested_predicates": {},
"comment": "It's dangerous to go alone. Take this!",
}
)
pres_sent = await wait_for_message(
msg_type="did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/admin-holder/0.1/presentation-sent"
)
assert pres_sent["presentation_exchange_id"]
4 changes: 3 additions & 1 deletion tests/holder/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ async def test_pres_req_received_sent_on_state(profile, mock_send_to_admins):
handler = test_module.present_proof_event_handler
state = V10PresentationExchange.STATE_REQUEST_RECEIVED
message = test_module.PresRequestReceived
event = Event("anything", {"state": state})
event = Event(
"anything", {"state": state, "presentation_request": {"pres_request": "test"}}
)
with mock.patch.object(
message, "retrieve_matching_credentials", mock.CoroutineMock()
):
Expand Down

0 comments on commit fd15350

Please sign in to comment.