From 664adf390b891c99a1aba442bb8585e92d452371 Mon Sep 17 00:00:00 2001 From: Allain Magyar Date: Fri, 18 Aug 2023 10:17:04 -0300 Subject: [PATCH] chore: rollback test file --- .../tests/sdk/src/SdkAgentWorkflow.ts | 174 ++++++++---------- 1 file changed, 75 insertions(+), 99 deletions(-) diff --git a/integration-tests/e2e-tests/tests/sdk/src/SdkAgentWorkflow.ts b/integration-tests/e2e-tests/tests/sdk/src/SdkAgentWorkflow.ts index 10582cb41..05b93a93a 100644 --- a/integration-tests/e2e-tests/tests/sdk/src/SdkAgentWorkflow.ts +++ b/integration-tests/e2e-tests/tests/sdk/src/SdkAgentWorkflow.ts @@ -14,52 +14,52 @@ import { Pluto, PublicMediatorStore, RequestPresentation, -} from "@input-output-hk/atala-prism-wallet-sdk"; -import axios from "axios"; -import { EnvironmentVariables } from "../environment.variables"; -import { Actor, Duration, Notepad, Wait } from "@serenity-js/core"; -import { Questions } from "../../Questions"; -import { equals } from "@serenity-js/assertions"; +} from '@input-output-hk/atala-prism-wallet-sdk' +import axios from 'axios' +import { EnvironmentVariables } from '../environment.variables' +import { Actor, Duration, Notepad, Wait } from '@serenity-js/core' +import { Questions } from '../../Questions' +import { equals } from '@serenity-js/assertions' export class SdkAgentWorkflow { - private static edgeAgent: Agent; - private static connectionsManager: ConnectionsManager; + private static edgeAgent: Agent + private static connectionsManager: ConnectionsManager - private static credentialOfferStack: Domain.Message[] = []; - private static proofRequestStack: Domain.Message[] = []; - private static issuedCredentialStack: Domain.Message[] = []; + private static credentialOfferStack: Domain.Message[] = [] + private static proofRequestStack: Domain.Message[] = [] + private static issuedCredentialStack: Domain.Message[] = [] static async createAgent() { - this.credentialOfferStack = []; - this.proofRequestStack = []; - this.issuedCredentialStack = []; + this.credentialOfferStack = [] + this.proofRequestStack = [] + this.issuedCredentialStack = [] - let apollo = new Apollo(); - let castor = new Castor(apollo); + let apollo = new Apollo() + let castor = new Castor(apollo) let pluto = new Pluto({ - type: "sqljs", - }); + type: 'sqljs' + }) - let api = new ApiImpl(); - let didcomm = new DIDCommWrapper(apollo, castor, pluto); - let mercury = new Mercury(castor, didcomm, api); + let api = new ApiImpl() + let didcomm = new DIDCommWrapper(apollo, castor, pluto) + let mercury = new Mercury(castor, didcomm, api) - let mediatorDID = Domain.DID.fromString(await this.mediatorDid()); - let mediatorStore = new PublicMediatorStore(pluto); + let mediatorDID = Domain.DID.fromString(await this.mediatorDid()) + let mediatorStore = new PublicMediatorStore(pluto) let mediatorHandler = new BasicMediatorHandler( mediatorDID, mercury, mediatorStore - ); + ) this.connectionsManager = new ConnectionsManager( castor, mercury, pluto, mediatorHandler - ); + ) - let seed = apollo.createRandomSeed().seed; + let seed = apollo.createRandomSeed().seed this.edgeAgent = new Agent( apollo, castor, @@ -68,119 +68,95 @@ export class SdkAgentWorkflow { mediatorHandler, this.connectionsManager, seed - ); - - this.edgeAgent.addListener( - ListenerKey.MESSAGE, - async (messages: Domain.Message[]) => { - for (let message of messages) { - if (message.piuri.includes("/offer-credential")) { - this.credentialOfferStack.push(message); - } else if (message.piuri.includes("/present-proof")) { - this.proofRequestStack.push(message); - } else if (message.piuri.includes("/issue-credential")) { - this.issuedCredentialStack.push(message); - } + ) + + this.edgeAgent.addListener(ListenerKey.MESSAGE, async (messages: Domain.Message[]) => { + for (let message of messages) { + if (message.piuri.includes('/offer-credential')) { + this.credentialOfferStack.push(message) + } else if (message.piuri.includes('/present-proof')) { + this.proofRequestStack.push(message) + } else if (message.piuri.includes('/issue-credential')) { + this.issuedCredentialStack.push(message) } } - ); + }) - await this.edgeAgent.start(); + await this.edgeAgent.start() } static async mediatorDid(): Promise { - let response = await axios.get(EnvironmentVariables.oobUrl); - let encodedData = response.data.split("?_oob=")[1]; - let oobData = JSON.parse(Buffer.from(encodedData, "base64").toString()); - return oobData.from; + let response = await axios.get(EnvironmentVariables.oobUrl) + let encodedData = response.data.split('?_oob=')[1] + let oobData = JSON.parse(Buffer.from(encodedData, 'base64').toString()) + return oobData.from } static async connect(edgeAgent: Actor) { - let url = await edgeAgent.answer(Notepad.notes().get("invitation")); - let oobInvitation = await this.edgeAgent.parseOOBInvitation(new URL(url)); - await this.edgeAgent.acceptDIDCommInvitation(oobInvitation); + let url = await edgeAgent.answer(Notepad.notes().get('invitation')) + let oobInvitation = await this.edgeAgent.parseOOBInvitation(new URL(url)) + await this.edgeAgent.acceptDIDCommInvitation(oobInvitation) } static async verifyNewCredential(edgeAgent: Actor) { await edgeAgent.attemptsTo( - Wait.upTo(Duration.ofSeconds(30)).until( - Questions.getArraySize( - "credential offer stack", - this.credentialOfferStack - ), - equals(1) - ) - ); + Wait.upTo(Duration.ofSeconds(30)) + .until( + Questions.getArraySize('credential offer stack',this.credentialOfferStack), + equals(1) + ) + ) } static async waitToReceiveIssuedCredential(edgeAgent: Actor) { await edgeAgent.attemptsTo( - Wait.upTo(Duration.ofSeconds(30)).until( - Questions.getArraySize( - "issued credential stack", - this.issuedCredentialStack - ), - equals(1) - ) - ); + Wait.upTo(Duration.ofSeconds(30)) + .until( + Questions.getArraySize('issued credential stack',this.issuedCredentialStack), + equals(1) + ) + ) } static async processIssuedCredential(edgeAgent: Actor) { - let issuedCredential = this.issuedCredentialStack.pop()!; + let issuedCredential = this.issuedCredentialStack.pop()! const issueCredential = IssueCredential.fromMessage(issuedCredential); await this.edgeAgent.processIssuedCredentialMessage(issueCredential); } static async acceptCredential(edgeAgent: Actor) { - let message = OfferCredential.fromMessage(this.credentialOfferStack.pop()!); - let requestCredential = - await this.edgeAgent.prepareRequestCredentialWithIssuer(message); + let message = OfferCredential.fromMessage(this.credentialOfferStack.pop()!) + let requestCredential = await this.edgeAgent.prepareRequestCredentialWithIssuer(message) try { - await this.edgeAgent.sendMessage(requestCredential.makeMessage()); + await this.edgeAgent.sendMessage(requestCredential.makeMessage()) } catch (e) { - console.error( - "This should not appear", - new Error().stack?.split("\n")[1] - ); + console.error('This should not appear', new Error().stack?.split('\n')[1]) } } static async waitForProofRequest(edgeAgent: Actor) { await edgeAgent.attemptsTo( - Wait.upTo(Duration.ofSeconds(30)).until( - Questions.getArraySize( - "proof of request stack", - this.proofRequestStack - ), - equals(1) - ) - ); + Wait.upTo(Duration.ofSeconds(30)) + .until( + Questions.getArraySize('proof of request stack', this.proofRequestStack), + equals(1) + ) + ) } static async presentProof(edgeAgent: Actor) { - let credentials = await this.edgeAgent.verifiableCredentials(); - let credential = credentials[0]; - - const requestPresentationMessage = RequestPresentation.fromMessage( - this.proofRequestStack.pop()! - ); - - let presentation = await this.edgeAgent.createPresentationForRequestProof( - requestPresentationMessage, - credential - ); - + let credentials = await this.edgeAgent.verifiableCredentials() + let credential = credentials[0] + const requestPresentationMessage = RequestPresentation.fromMessage(this.proofRequestStack.pop()!) + let presentation = await this.edgeAgent.createPresentationForRequestProof(requestPresentationMessage, credential) try { - await this.edgeAgent.sendMessage(presentation.makeMessage()); + await this.edgeAgent.sendMessage(presentation.makeMessage()) } catch (e) { - console.error( - "This should not appear", - new Error().stack?.split("\n")[1] - ); + console.error('This should not appear', new Error().stack?.split('\n')[1]) } } static async stop() { - await this.edgeAgent.stop(); + await this.edgeAgent.stop() } }