-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: support for credential and present-proof flows with thid (#609)
- Loading branch information
Anton Baliasnikov
authored
Aug 3, 2023
1 parent
4fb1ca7
commit 9cef8c0
Showing
11 changed files
with
278 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
MERCURY_MEDIATOR_VERSION=0.3.0 | ||
IRIS_SERVICE_VERSION=0.1.0 | ||
PRISM_AGENT_VERSION=1.6.0 | ||
PRISM_NODE_VERSION=v2.1.3 | ||
PRISM_AGENT_VERSION=1.9.2 | ||
PRISM_NODE_VERSION=2.2.1 | ||
PORT=80 | ||
NETWORK=prism | ||
VAULT_DEV_ROOT_TOKEN_ID=root |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { sleep } from "k6"; | ||
import { HttpService } from "./HttpService"; | ||
import { WAITING_LOOP_MAX_ITERATIONS, WAITING_LOOP_PAUSE_INTERVAL } from "./Config"; | ||
import { IssueCredentialRecord, Connection } from "@input-output-hk/prism-typescript-client"; | ||
import vu from "k6/execution"; | ||
import { ISSUER_AGENT_URL, WAITING_LOOP_MAX_ITERATIONS, WAITING_LOOP_PAUSE_INTERVAL } from "./Config"; | ||
import { IssueCredentialRecord, Connection, CredentialSchemaResponse } from "@input-output-hk/prism-typescript-client"; | ||
import {v4 as uuidv4} from 'uuid'; | ||
|
||
/** | ||
* A service class for managing credentials in the application. | ||
|
@@ -16,9 +16,16 @@ export class CredentialsService extends HttpService { | |
* @param {Connection} connection - The connection object. | ||
* @returns {IssueCredentialRecord} The created credential offer record. | ||
*/ | ||
createCredentialOffer(issuingDid: string, connection: Connection): IssueCredentialRecord { | ||
createCredentialOffer(issuingDid: string, connection: Connection, schema: CredentialSchemaResponse): IssueCredentialRecord { | ||
const payload = `{ | ||
"claims": { "offerId": "${vu.vu.idInInstance}-${vu.vu.idInTest}-${vu.vu.iterationInScenario}" }, | ||
"claims": { | ||
"emailAddress": "${uuidv4()}[email protected]", | ||
"familyName": "Test", | ||
"dateOfIssuance": "${new Date()}", | ||
"drivingLicenseID": "Test", | ||
"drivingClass": 1 | ||
}, | ||
"schemaId": "${ISSUER_AGENT_URL.replace("localhost", "host.docker.internal")}/schema-registry/schemas/${schema.guid}", | ||
"issuingDID": "${issuingDid}", | ||
"connectionId": "${connection.connectionId}", | ||
"automaticIssuance": false | ||
|
@@ -27,6 +34,60 @@ export class CredentialsService extends HttpService { | |
return res.json() as unknown as IssueCredentialRecord; | ||
} | ||
|
||
createCredentialSchema(issuingDid: string): CredentialSchemaResponse { | ||
const payload = ` | ||
{ | ||
"name": "${uuidv4()}}", | ||
"version": "1.0.0", | ||
"description": "Simple credential schema for the driving licence verifiable credential.", | ||
"type": "https://w3c-ccg.github.io/vc-json-schemas/schema/2.0/schema.json", | ||
"schema": { | ||
"$id": "https://example.com/driving-license-1.0", | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"description": "Driving License", | ||
"type": "object", | ||
"properties": { | ||
"emailAddress": { | ||
"type": "string", | ||
"format": "email" | ||
}, | ||
"givenName": { | ||
"type": "string" | ||
}, | ||
"familyName": { | ||
"type": "string" | ||
}, | ||
"dateOfIssuance": { | ||
"type": "string" | ||
}, | ||
"drivingLicenseID": { | ||
"type": "string" | ||
}, | ||
"drivingClass": { | ||
"type": "integer" | ||
} | ||
}, | ||
"required": [ | ||
"emailAddress", | ||
"familyName", | ||
"dateOfIssuance", | ||
"drivingLicenseID", | ||
"drivingClass" | ||
], | ||
"additionalProperties": false | ||
}, | ||
"tags": [ | ||
"driving", | ||
"licence", | ||
"id" | ||
], | ||
"author": "${issuingDid}" | ||
} | ||
` | ||
const res = this.post("schema-registry/schemas", payload); | ||
return res.json() as unknown as CredentialSchemaResponse; | ||
} | ||
|
||
/** | ||
* Retrieves a specific credential record by ID. | ||
* @param {IssueCredentialRecord} record - The credential record. | ||
|
@@ -41,8 +102,8 @@ export class CredentialsService extends HttpService { | |
* Retrieves all credential records. | ||
* @returns {IssueCredentialRecord[]} An array of credential records. | ||
*/ | ||
getCredentialRecords(): IssueCredentialRecord[] { | ||
const res = this.get("issue-credentials/records"); | ||
getCredentialRecords(thid: string): IssueCredentialRecord[] { | ||
const res = this.get(`issue-credentials/records?thid=${thid}`); | ||
return res.json("contents") as unknown as IssueCredentialRecord[]; | ||
} | ||
|
||
|
@@ -73,21 +134,21 @@ export class CredentialsService extends HttpService { | |
* @returns {IssueCredentialRecord} The received credential offer record. | ||
* @throws {Error} If the credential offer is not received within the maximum iterations. | ||
*/ | ||
waitForCredentialOffer(): IssueCredentialRecord { | ||
waitForCredentialOffer(thid: string): IssueCredentialRecord { | ||
let iterations = 0; | ||
let record: IssueCredentialRecord | undefined; | ||
do { | ||
console.log(`${vu.vu.idInInstance}-${vu.vu.idInTest}-${vu.vu.iterationInScenario}`) | ||
record = this.getCredentialRecords().find( | ||
r => r.claims["offerId"] === `${vu.vu.idInInstance}-${vu.vu.idInTest}-${vu.vu.iterationInScenario}` | ||
&& r.protocolState === "OfferReceived"); | ||
// console.log(`Waiting for credential offer with thid=${thid}`) | ||
record = this.getCredentialRecords(thid).find( | ||
r => r.thid === thid && r.protocolState === "OfferReceived" | ||
); | ||
if (record) { | ||
return record; | ||
} | ||
sleep(WAITING_LOOP_PAUSE_INTERVAL); | ||
iterations++; | ||
} while (iterations < WAITING_LOOP_MAX_ITERATIONS); | ||
throw new Error(`Record with offerId=${vu.vu.idInTest} not achieved during the waiting loop`); | ||
throw new Error(`Record with thid=${thid} not achieved during the waiting loop`); | ||
} | ||
|
||
/** | ||
|
@@ -102,14 +163,12 @@ export class CredentialsService extends HttpService { | |
do { | ||
const response = this.getCredentialRecord(credentialRecord); | ||
currentState = response.protocolState; | ||
console.log(`Credential state: ${currentState}`) | ||
sleep(WAITING_LOOP_PAUSE_INTERVAL); | ||
iterations++; | ||
} while (currentState !== state && iterations < WAITING_LOOP_MAX_ITERATIONS); | ||
if (currentState !== state) { | ||
throw new Error(`Credential is not ${state} after the waiting loop`); | ||
} | ||
if (__ENV.DEBUG) console.log(`Credential state achieved: ${currentState}`); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...formance-tests/atala-performance-tests-k6/src/tests/credentials/credential-schema-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { group } from 'k6'; | ||
import { Options } from 'k6/options'; | ||
import { Issuer } from '../../actors'; | ||
|
||
export let options: Options = { | ||
scenarios: { | ||
smoke: { | ||
executor: 'constant-vus', | ||
vus: 3, | ||
duration: "1s", | ||
}, | ||
}, | ||
thresholds: { | ||
'http_req_duration{group:::Issuer creates credential schema}': ['max >= 0'], | ||
'http_reqs{group:::Issuer creates credential schema}': ['count >= 0'], | ||
'group_duration{group:::Issuer creates credential schema}': ['max >= 0'], | ||
checks: ['rate==1'], | ||
http_req_duration: ['p(95)<=100'], | ||
}, | ||
}; | ||
|
||
export const issuer = new Issuer(); | ||
|
||
export function setup() { | ||
group('Issuer publishes DID', function () { | ||
issuer.createUnpublishedDid(); | ||
issuer.publishDid(); | ||
}); | ||
|
||
return { | ||
issuerDid: issuer.did, | ||
}; | ||
} | ||
|
||
export default (data: { issuerDid: string; }) => { | ||
|
||
// This is the only way to pass data from setup to default | ||
issuer.did = data.issuerDid; | ||
|
||
group('Issuer creates credential schema', function () { | ||
issuer.createCredentialSchema(); | ||
}); | ||
}; |
Oops, something went wrong.