From 4a6a2a7165b31e71451e36686f75fd49554a4c56 Mon Sep 17 00:00:00 2001 From: Berend Sliedrecht Date: Wed, 10 Jan 2024 11:37:42 +0100 Subject: [PATCH] fix(present-proof): isolated tests Signed-off-by: Berend Sliedrecht --- ...entation-exchange-presentation.e2e.test.ts | 214 ++++++++++-------- 1 file changed, 115 insertions(+), 99 deletions(-) diff --git a/packages/core/src/modules/proofs/protocol/v2/__tests__/v2-presentation-exchange-presentation.e2e.test.ts b/packages/core/src/modules/proofs/protocol/v2/__tests__/v2-presentation-exchange-presentation.e2e.test.ts index 264dd8d660..38f44fcd72 100644 --- a/packages/core/src/modules/proofs/protocol/v2/__tests__/v2-presentation-exchange-presentation.e2e.test.ts +++ b/packages/core/src/modules/proofs/protocol/v2/__tests__/v2-presentation-exchange-presentation.e2e.test.ts @@ -43,11 +43,6 @@ describe('Present Proof', () => { let issuerProverConnectionId: string let proverVerifierConnectionId: string - let verifierProofExchangeRecord: ProofExchangeRecord - let proverProofExchangeRecord: ProofExchangeRecord - - let didCommMessageRepository: DidCommMessageRepository - beforeAll(async () => { testLogger.test('Initializing the agents') ;({ @@ -98,7 +93,7 @@ describe('Present Proof', () => { state: ProofState.ProposalReceived, }) - proverProofExchangeRecord = await proverAgent.proofs.proposeProof({ + await proverAgent.proofs.proposeProof({ connectionId: proverVerifierConnectionId, protocolVersion: 'v2', proofFormats: { @@ -113,9 +108,10 @@ describe('Present Proof', () => { }) testLogger.test('Verifier waits for presentation from the Prover') - verifierProofExchangeRecord = await verifierPresentationRecordPromise + const verifierProofExchangeRecord = await verifierPresentationRecordPromise - didCommMessageRepository = proverAgent.dependencyManager.resolve(DidCommMessageRepository) + const didCommMessageRepository = + proverAgent.dependencyManager.resolve(DidCommMessageRepository) const proposal = await didCommMessageRepository.findAgentMessage(verifierAgent.context, { associatedRecordId: verifierProofExchangeRecord.id, @@ -153,12 +149,33 @@ describe('Present Proof', () => { }) test(`Verifier accepts the Proposal send by the Prover`, async () => { + testLogger.test('Prover sends proof proposal to a Verifier') + + let proverProofExchangeRecord = await proverAgent.proofs.proposeProof({ + connectionId: proverVerifierConnectionId, + protocolVersion: 'v2', + proofFormats: { + presentationExchange: { + presentationDefinition: { + id: 'e950bfe5-d7ec-4303-ad61-6983fb976ac9', + input_descriptors: [TEST_INPUT_DESCRIPTORS_CITIZENSHIP], + }, + }, + }, + comment: 'V2 Presentation Exchange propose proof test', + }) + + const verifierPresentationRecordPromise = waitForProofExchangeRecord(verifierAgent, { + state: ProofState.ProposalReceived, + }) + const proverPresentationRecordPromise = waitForProofExchangeRecord(proverAgent, { - threadId: verifierProofExchangeRecord.threadId, + threadId: proverProofExchangeRecord.threadId, state: ProofState.RequestReceived, }) testLogger.test('Verifier accepts presentation proposal from the Prover') + let verifierProofExchangeRecord = await verifierPresentationRecordPromise verifierProofExchangeRecord = await verifierAgent.proofs.acceptProposal({ proofRecordId: verifierProofExchangeRecord.id, }) @@ -166,7 +183,8 @@ describe('Present Proof', () => { testLogger.test('Prover waits for proof request from the Verifier') proverProofExchangeRecord = await proverPresentationRecordPromise - didCommMessageRepository = proverAgent.dependencyManager.resolve(DidCommMessageRepository) + const didCommMessageRepository = + proverAgent.dependencyManager.resolve(DidCommMessageRepository) const request = await didCommMessageRepository.findAgentMessage(proverAgent.context, { associatedRecordId: proverProofExchangeRecord.id, @@ -214,6 +232,40 @@ describe('Present Proof', () => { }) test(`Prover accepts presentation request from the Verifier`, async () => { + testLogger.test('Prover sends proof proposal to a Verifier') + + let proverProofExchangeRecord = await proverAgent.proofs.proposeProof({ + connectionId: proverVerifierConnectionId, + protocolVersion: 'v2', + proofFormats: { + presentationExchange: { + presentationDefinition: { + id: 'e950bfe5-d7ec-4303-ad61-6983fb976ac9', + input_descriptors: [TEST_INPUT_DESCRIPTORS_CITIZENSHIP], + }, + }, + }, + comment: 'V2 Presentation Exchange propose proof test', + }) + + const verifierProposalReceivedPresentationRecordPromise = waitForProofExchangeRecord(verifierAgent, { + state: ProofState.ProposalReceived, + }) + + const proverPresentationRecordPromise = waitForProofExchangeRecord(proverAgent, { + threadId: proverProofExchangeRecord.threadId, + state: ProofState.RequestReceived, + }) + + testLogger.test('Verifier accepts presentation proposal from the Prover') + let verifierProofExchangeRecord = await verifierProposalReceivedPresentationRecordPromise + verifierProofExchangeRecord = await verifierAgent.proofs.acceptProposal({ + proofRecordId: verifierProofExchangeRecord.id, + }) + + testLogger.test('Prover waits for proof request from the Verifier') + proverProofExchangeRecord = await proverPresentationRecordPromise + // Prover retrieves the requested credentials and accepts the presentation request testLogger.test('Prover accepts presentation request from Verifier') @@ -230,100 +282,14 @@ describe('Present Proof', () => { testLogger.test('Verifier waits for presentation from the Prover') verifierProofExchangeRecord = await verifierPresentationRecordPromise + const didCommMessageRepository = + verifierAgent.dependencyManager.resolve(DidCommMessageRepository) + const presentation = await didCommMessageRepository.findAgentMessage(verifierAgent.context, { associatedRecordId: verifierProofExchangeRecord.id, messageClass: V2PresentationMessage, }) - // { - // "@type":"https://didcomm.org/present-proof/2.0/presentation", - // "last_presentation":true, - // "formats":[ - // { - // "attach_id":"97cf1dbf-2ce0-4641-9083-00f4aec99478", - // "format":"dif/presentation-exchange/submission@v1.0" - // } - // ], - // "presentations~attach":[ - // { - // "@id":"97cf1dbf-2ce0-4641-9083-00f4aec99478", - // "mime-type":"application/json", - // "data":{ - // "json":{ - // "presentation_submission":{ - // "id":"dHOs_n7UF7QAbJvEovHeW", - // "definition_id":"e950bfe5-d7ec-4303-ad61-6983fb976ac9", - // "descriptor_map":[ - // { - // "id":"citizenship_input_1", - // "format":"ldp_vp", - // "path":"$", - // "path_nested":{ - // "id":"citizenship_input_1", - // "format":"ldp_vc ", - // "path":"$.verifiableCredential[0]" - // } - // } - // ] - // }, - // "context":[ - // "https://www.w3.org/2018/credentials/v1" - // ], - // "type":[ - // "VerifiableP resentation" - // ], - // "holder":"did:key:z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL", - // "verifiableCredential":[ - // { - // "@context":[ - // "https://www.w3.org/2018/credentials/v1", - // "https://www.w3.org/2018/credentials/examples/v1" - // ], - // "type":[ - // "Verifiab leCredential", - // "UniversityDegreeCredential" - // ], - // "issuer":"did:key:z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL", - // "issuanceDate":"2017-10-22T12:23:48Z", - // "credentialSubject":{ - // "id":"did:key:z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38Eef XmgDL", - // "degree":{ - // "type":"BachelorDegree", - // "name":"Bachelor of Science and Arts" - // } - // }, - // "proof":{ - // "verificationMethod":"di d:key:z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL#z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL", - // "type":"E d25519Signature2018", - // "created":"2023-12-19T12:38:36Z", - // "proofPurpose":"assertionMethod", - // "jws":"eyJhbGciOiJFZERTQSIs ImI2NCI6ZmFsc2UsImNyaXQiOlsiYjY0Il19..U3oPjRgz-fTd_kkUtNgWKh-FRWWkKdy0iSgOiGA1d7IyImuL1URQwJjd3UlJAkFf1kl7NeakiCtZ cFfxkPpECQ" - // } - // } - // ], - // "proof":{ - // "verificationMethod":"did:key:z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL#z6Mkgg342Yc puk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL", - // "type":"Ed25519Signature2018", - // "created":"2023-12-19T12:38:37Z", - // "proofPurpos e":"authentication", - // "challenge":"273899451763000636595367", - // "jws":"eyJhbGciOiJFZERTQSIsImI2NCI6ZmFsc2UsImNyaXQiOlsi YjY0Il19..X_pR5Evhj-byuMkhJfXfoj9HO03iLKtltq64A4cueuLAH-Ix5D-G9g7r4xec9ysyga8GS2tZQl0OK4W9LJcOAQ" - // } - // } - // } - // } - // ], - // "@id":"2cdf aa16-d132-4778-9d6f-622fc0e0fa84", - // "~thread":{ - // "thid":"e03cfab3-7ab1-477f-9df7-dc7ede70b952" - // }, - // "~please_ack":{ - // "on":[ - // " RECEIPT" - // ] - // } - // } - expect(presentation).toMatchObject({ type: 'https://didcomm.org/present-proof/2.0/presentation', formats: [ @@ -403,6 +369,56 @@ describe('Present Proof', () => { }) test(`Verifier accepts the presentation provided by the Prover`, async () => { + testLogger.test('Prover sends proof proposal to a Verifier') + + let proverProofExchangeRecord = await proverAgent.proofs.proposeProof({ + connectionId: proverVerifierConnectionId, + protocolVersion: 'v2', + proofFormats: { + presentationExchange: { + presentationDefinition: { + id: 'e950bfe5-d7ec-4303-ad61-6983fb976ac9', + input_descriptors: [TEST_INPUT_DESCRIPTORS_CITIZENSHIP], + }, + }, + }, + comment: 'V2 Presentation Exchange propose proof test', + }) + + const verifierProposalReceivedPresentationRecordPromise = waitForProofExchangeRecord(verifierAgent, { + state: ProofState.ProposalReceived, + }) + + const proverPresentationRecordPromise = waitForProofExchangeRecord(proverAgent, { + threadId: proverProofExchangeRecord.threadId, + state: ProofState.RequestReceived, + }) + + testLogger.test('Verifier accepts presentation proposal from the Prover') + let verifierProofExchangeRecord = await verifierProposalReceivedPresentationRecordPromise + verifierProofExchangeRecord = await verifierAgent.proofs.acceptProposal({ + proofRecordId: verifierProofExchangeRecord.id, + }) + + testLogger.test('Prover waits for proof request from the Verifier') + proverProofExchangeRecord = await proverPresentationRecordPromise + + // Prover retrieves the requested credentials and accepts the presentation request + testLogger.test('Prover accepts presentation request from Verifier') + + const verifierPresentationRecordPromise = waitForProofExchangeRecord(verifierAgent, { + threadId: verifierProofExchangeRecord.threadId, + state: ProofState.PresentationReceived, + }) + + await proverAgent.proofs.acceptRequest({ + proofRecordId: proverProofExchangeRecord.id, + }) + + // Verifier waits for the presentation from the Prover + testLogger.test('Verifier waits for presentation from the Prover') + verifierProofExchangeRecord = await verifierPresentationRecordPromise + const proverProofExchangeRecordPromise = waitForProofExchangeRecord(proverAgent, { threadId: proverProofExchangeRecord.threadId, state: ProofState.Done,