Skip to content

Commit

Permalink
chore: rollback test file
Browse files Browse the repository at this point in the history
  • Loading branch information
amagyar-iohk committed Aug 18, 2023
1 parent 6c44708 commit 664adf3
Showing 1 changed file with 75 additions and 99 deletions.
174 changes: 75 additions & 99 deletions integration-tests/e2e-tests/tests/sdk/src/SdkAgentWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<string> {
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<string>(Notepad.notes().get("invitation"));
let oobInvitation = await this.edgeAgent.parseOOBInvitation(new URL(url));
await this.edgeAgent.acceptDIDCommInvitation(oobInvitation);
let url = await edgeAgent.answer<string>(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()
}
}

0 comments on commit 664adf3

Please sign in to comment.