Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add initial k6 performance scenarios #532

Merged
merged 2 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tests/performance-tests/atala-performance-tests-k6/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"presets": ["@babel/env", "@babel/typescript"],
"plugins": [
"@babel/proposal-class-properties",

"@babel/proposal-object-rest-spread"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
yarn-error.log
dist
31 changes: 31 additions & 0 deletions tests/performance-tests/atala-performance-tests-k6/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## Prerequisites

- [k6](https://k6.io/docs/getting-started/installation)
- [NodeJS](https://nodejs.org/en/download/)
- [Yarn](https://yarnpkg.com/getting-started/install) (optional)

## Installation

**Install dependencies**

Clone the generated repository on your local machine, move to the project root folder and install the dependencies defined in [`package.json`](./package.json)

```bash
$ yarn install
```

## Running the test

To run a test written in TypeScript, we first have to transpile the TypeScript code into JavaScript and bundle the project

```bash
$ yarn webpack
```

This command creates the final test files to the `./dist` folder.

Once that is done, we can run our script the same way we usually do, for instance:

```bash
$ k6 run dist/connection-flow-test.js
```
30 changes: 30 additions & 0 deletions tests/performance-tests/atala-performance-tests-k6/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "typescript",
"version": "1.0.0",
"main": "index.js",
"repository": "ssh://[email protected]/k6io/example-typescript.git",
"author": "Simon Aronsson <[email protected]>",
"license": "MIT",
"devDependencies": {
"@babel/core": "7.13.16",
"@babel/plugin-proposal-class-properties": "7.13.0",
"@babel/plugin-proposal-object-rest-spread": "7.13.8",
"@babel/preset-env": "7.13.15",
"@babel/preset-typescript": "7.13.0",
"@types/k6": "~0.41.0",
"@types/webpack": "5.28.0",
"babel-loader": "8.2.2",
"clean-webpack-plugin": "4.0.0-alpha.0",
"copy-webpack-plugin": "^9.0.1",
"typescript": "4.2.4",
"webpack": "5.35.1",
"webpack-cli": "4.6.0",
"webpack-glob-entries": "^1.0.1"
},
"scripts": {
"start": "webpack"
},
"dependencies": {
"@input-output-hk/prism-typescript-client": "0.1.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { ConnectionService } from "../common/ConnectionService";
import { CredentialsService } from "../common/CredentialsService";
import { ProofsService } from "../common/ProofsService";
import { DidService } from "../common/DidService";

/**
* Base class for all SSI actors
*/
export class Actor {
connectionService: ConnectionService;
credentialsService: CredentialsService;
proofsService: ProofsService;
didService: DidService;
did: string | undefined;

/**
* Constructs a new instance of the Actor class.
* @param {string} url - The URL for the services.
* @param {string} apiKey - The API key for authentication.
*/
constructor(url: string, apiKey: string) {
this.connectionService = new ConnectionService(url, apiKey);
this.credentialsService = new CredentialsService(url, apiKey);
this.didService = new DidService(url, apiKey);
this.proofsService = new ProofsService(url, apiKey);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { Connection, ConnectionInvitation, IssueCredentialRecord } from "@input-output-hk/prism-typescript-client";
import { Actor } from "./Actor";
import { HOLDER_AGENT_API_KEY, HOLDER_AGENT_URL } from "../common/Config";

export class Holder extends Actor {
/**
* The connection with the Issuer.
*/
connectionWithIssuer: Connection | undefined;

/**
* The connection with the Verifier.
*/
connectionWithVerifier: Connection | undefined;

/**
* The credential issued by the issuer.
*/
credential: IssueCredentialRecord | undefined;

/**
* The DID template used to create an unpublished DID for Holder.
* Authentication is the only purpose for the public key required for Holder.
*/
holderDidTemplate: string = `{
"documentTemplate": {
"publicKeys": [
{
"id": "authKey",
"purpose": "authentication"
}
],
"services": []
}
}`;


/**
* Creates a new instance of Holder.
*/
constructor() {
super(HOLDER_AGENT_URL, HOLDER_AGENT_API_KEY);
}

/**
* Creates an unpublished DID.
*/
createUnpublishedDid() {
this.did = this.didService.createUnpublishedDid(this.holderDidTemplate).longFormDid;
}

/**
* Accepts a connection invitation from an issuer.
* @param {ConnectionInvitation} invitation - The connection invitation.
*/
acceptIssuerConnection(invitation: ConnectionInvitation) {
this.connectionWithIssuer = this.connectionService.acceptConnectionInvitation(invitation);
}

/**
* Accepts a connection invitation from a verifier.
* @param {ConnectionInvitation} invitation - The connection invitation.
*/
acceptVerifierConnection(invitation: ConnectionInvitation) {
this.connectionWithVerifier = this.connectionService.acceptConnectionInvitation(invitation);
}

/**
* Waits for the connection with the issuer to be finalized.
*/
finalizeConnectionWithIssuer() {
this.connectionService.waitForConnectionState(
this.connectionWithIssuer!,
"ConnectionResponseReceived"
);
}

/**
* Waits for the connection with the verifier to be finalized.
*/
finalizeConnectionWithVerifier() {
this.connectionService.waitForConnectionState(
this.connectionWithVerifier!,
"ConnectionResponseReceived"
);
}

/**
* Waits for a credential offer and accepts it.
*/
waitAndAcceptCredentialOffer() {
this.credential = this.credentialsService.waitForCredentialOffer();
this.credentialsService.acceptCredentialOffer(this.credential, this.did!);
this.credentialsService.waitForCredentialState(this.credential, "RequestSent");
}

/**
* Waits for the credential to be received.
*/
receiveCredential() {
this.credentialsService.waitForCredentialState(this.credential!, "CredentialReceived");
}

/**
* Waits for a proof request, accepts it, and waits for the presentation to be sent.
*/
waitAndAcceptProofRequest() {
const presentation = this.proofsService.waitForProof();
this.proofsService.acceptProofRequest(presentation, this.credential!.recordId);
this.proofsService.waitForPresentationState(presentation.presentationId, "PresentationSent");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { Connection, IssueCredentialRecord } from "@input-output-hk/prism-typescript-client";
import { Actor } from "./Actor";
import { ISSUER_AGENT_API_KEY, ISSUER_AGENT_URL } from "../common/Config";

export class Issuer extends Actor {

/**
* The connection with the holder.
*/
connectionWithHolder: Connection | undefined;

/**
* The connection with the verifier.
*/
connectionWithVerifier: Connection | undefined;

/**
* The credential to be issued.
*/
credential: IssueCredentialRecord | undefined;

/**
* The DID template used to create a DID for Issuer.
* assertionMethod is the only purpose for the public key required for Issuer.
*/
issuerDidTemplate: string = `{
"documentTemplate": {
"publicKeys": [
{
"id": "issuanceKey",
"purpose": "assertionMethod"
}
],
"services": []
}
}`;

/**
* Creates a new instance of Issuer.
*/
constructor() {
super(ISSUER_AGENT_URL, ISSUER_AGENT_API_KEY);
}

/**
* Creates a connection with the holder.
*/
createHolderConnection() {
this.connectionWithHolder = this.connectionService.createConnection();
}

/**
* Waits for the connection with the holder to be finalized.
*/
finalizeConnectionWithHolder() {
this.connectionService.waitForConnectionState(
this.connectionWithHolder!,
"ConnectionResponseSent"
);
}

/**
* Creates and publishes a DID.
*/
createAndPublishDid() {
const unpublishedDid = this.didService.createUnpublishedDid(this.issuerDidTemplate).longFormDid;
this.did = this.didService.publishDid(unpublishedDid).didRef;
this.didService.waitForDidState(unpublishedDid, "PUBLISHED");
}

/**
* Creates a credential offer for the holder.
*/
createCredentialOffer() {
this.credential = this.credentialsService.createCredentialOffer(this.did!, this.connectionWithHolder!);
this.credentialsService.waitForCredentialState(this.credential!, "OfferSent");
}

/**
* Receives credential request from the holder.
*/
receiveCredentialRequest() {
this.credentialsService.waitForCredentialState(this.credential!, "RequestReceived");
}

/**
* Issues the credential to the holder.
*/
issueCredential() {
this.credentialsService.issueCredential(this.credential!);
this.credentialsService.waitForCredentialState(this.credential!, "CredentialSent");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Connection } from "@input-output-hk/prism-typescript-client";
import { Actor } from "./Actor";
import { VERIFIER_AGENT_API_KEY, VERIFIER_AGENT_URL } from "../common/Config";

export class Verifier extends Actor {

/**
* The connection with the Holder.
*/
connectionWithHolder: Connection | undefined;

/**
* Presentation ID.
*/
presentationId: string | undefined;

/**
* Creates a new instance of Verifier.
*/
constructor() {
super(VERIFIER_AGENT_URL, VERIFIER_AGENT_API_KEY);
}

/**
* Creates a connection with the holder.
*/
createHolderConnection() {
this.connectionWithHolder = this.connectionService.createConnection();
}

/**
* Waits for the connection with the holder to be finalized.
*/
finalizeConnectionWithHolder() {
this.connectionService.waitForConnectionState(
this.connectionWithHolder!,
"ConnectionResponseSent"
);
}

/**
* Requests proof from the holder.
*/
requestProof() {
this.presentationId = this.proofsService.requestProof(this.connectionWithHolder!);
}

/**
* Acknowledges the proof received from the holder.
*/
acknowledgeProof() {
this.proofsService.waitForPresentationState(this.presentationId!, "PresentationVerified");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Actor } from "./Actor";
import { Holder } from "./Holder";
import { Issuer } from "./Issuer";
import { Verifier } from "./Verifier";
export { Actor, Holder, Issuer, Verifier };
Loading