From 86df4130ee9c939883cd79efeb7b20c354373070 Mon Sep 17 00:00:00 2001 From: Robbie Blaine <4052340+rblaine95@users.noreply.github.com> Date: Thu, 1 Aug 2024 14:45:18 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20=F0=9F=91=B7=E2=80=8D=E2=99=82?= =?UTF-8?q?=EF=B8=8F=20K6=20run=20Biome=20Lint=20and=20Format=20(#921)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Biome Format * Run `npm run format` * Set Biome Formatter Indent Style to spaces * Set Biome Formatter Indent Width to `2` * Set Biome Formatter Line Width to `120` * Use `biome check` instead of `format` or `lint` * Allows Organize Imports to run * Make `npm run lint:fix` not run the unsafe lint fixes * Add an `npm run lint:fix:unsafe` to enable the `unsafe` flag * Biome Lint Fix * Applied Biome Lint Fix * Walked through the unsafe fixes and identified the one that was causing the k6 syntax error * Disable `useOptionalChain` rule * Manually disable ESLint rules on a per-file basis because Codacy * Use of Console and Undefined is 100% valid for k6 * I believe the use of snake case is to maintain consistency with calls made to CloudAPI --- scripts/k6/biome.json | 28 +- scripts/k6/libs/auth.js | 41 +- scripts/k6/libs/functions.js | 538 +++++++++++---------- scripts/k6/libs/issuerUtils.js | 2 +- scripts/k6/libs/schemaUtils.js | 39 +- scripts/k6/main.js | 89 ++-- scripts/k6/package.json | 19 +- scripts/k6/scenarios/create-credentials.js | 98 ++-- scripts/k6/scenarios/create-holders.js | 86 ++-- scripts/k6/scenarios/create-invitation.js | 93 ++-- scripts/k6/scenarios/create-issuers.js | 80 +-- scripts/k6/scenarios/create-proof.js | 89 ++-- scripts/k6/scenarios/delete-holders.js | 42 +- 13 files changed, 641 insertions(+), 603 deletions(-) diff --git a/scripts/k6/biome.json b/scripts/k6/biome.json index 635034232..9fb136680 100644 --- a/scripts/k6/biome.json +++ b/scripts/k6/biome.json @@ -1,16 +1,24 @@ { - "$schema": "https://biomejs.dev/schemas/1.8.3/schema.json", - "organizeImports": { - "enabled": true - }, + "$schema": "https://biomejs.dev/schemas/1.8.3/schema.json", + "organizeImports": { + "enabled": true + }, "files": { "ignore": ["node_modules", "output"] }, - "linter": { - "enabled": true, - "rules": { - "recommended": true - }, + "formatter": { + "indentStyle": "space", + "indentWidth": 2, + "lineWidth": 120 + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true, + "complexity": { + "useOptionalChain": "off" + } + }, "ignore": ["node_modules", "output"] - } + } } diff --git a/scripts/k6/libs/auth.js b/scripts/k6/libs/auth.js index 63bae8205..167e0c24a 100644 --- a/scripts/k6/libs/auth.js +++ b/scripts/k6/libs/auth.js @@ -1,6 +1,5 @@ /* global __ENV, __ITER, __VU */ -/* eslint no-undef: "error" */ -/* eslint no-console: ["error", { allow: ["warn", "error"] }] */ +/* eslint-disable no-undefined, no-console, camelcase */ import http from "k6/http"; @@ -10,22 +9,21 @@ export function getBearerToken() { const clientSecret = __ENV.CLIENT_SECRET; const requestBody = `grant_type=client_credentials&client_id=${clientId}&client_secret=${clientSecret}`; - let response = http.post(url, requestBody, { + const response = http.post(url, requestBody, { headers: { - "Content-Type": "application/x-www-form-urlencoded" - } + "Content-Type": "application/x-www-form-urlencoded", + }, }); if (response.status === 200) { - let responseData = JSON.parse(response.body); - let bearerToken = responseData.access_token; + const responseData = JSON.parse(response.body); + const bearerToken = responseData.access_token; return bearerToken; - } else { - console.error("Error:", response.status_text); - console.error("Response body:", response.body); - console.error("Error description:", response.json().error_description); - throw new Error("Failed to obtain bearer token"); } + console.error("Error:", response.status_text); + console.error("Response body:", response.body); + console.error("Error description:", response.json().error_description); + throw new Error("Failed to obtain bearer token"); } export function getGovernanceBearerToken() { @@ -34,20 +32,19 @@ export function getGovernanceBearerToken() { const clientSecret = __ENV.GOVERNANCE_CLIENT_SECRET; const requestBody = `grant_type=client_credentials&client_id=${clientId}&client_secret=${clientSecret}`; - let response = http.post(url, requestBody, { + const response = http.post(url, requestBody, { headers: { - "Content-Type": "application/x-www-form-urlencoded" - } + "Content-Type": "application/x-www-form-urlencoded", + }, }); if (response.status === 200) { - let responseData = JSON.parse(response.body); - let bearerToken = responseData.access_token; + const responseData = JSON.parse(response.body); + const bearerToken = responseData.access_token; return bearerToken; - } else { - console.error("Error:", response.status_text); - console.error("Response body:", response.body); - console.error("Error description:", response.json().error_description); - throw new Error("Failed to obtain bearer token"); } + console.error("Error:", response.status_text); + console.error("Response body:", response.body); + console.error("Error description:", response.json().error_description); + throw new Error("Failed to obtain bearer token"); } diff --git a/scripts/k6/libs/functions.js b/scripts/k6/libs/functions.js index ed1c62bff..5cf4cfca8 100644 --- a/scripts/k6/libs/functions.js +++ b/scripts/k6/libs/functions.js @@ -1,11 +1,10 @@ /* global __ENV, __ITER, __VU, console */ -/* eslint no-undef: "error" */ -/* eslint no-console: ["error", { allow: ["warn", "error", "log"] }] */ +/* eslint-disable no-undefined, no-console, camelcase */ +import { check, sleep } from "k6"; import http from "k6/http"; +import { Counter, Trend } from "k6/metrics"; import sse from "k6/x/sse"; -import { check, sleep } from "k6"; -import { Trend, Counter } from "k6/metrics"; // import { sleep } from 'k6'; // let customDuration = new Trend('custom_duration', true); @@ -24,17 +23,17 @@ export function createTenant(bearerToken, wallet) { wallet_label: wallet.wallet_label, wallet_name: wallet.wallet_name, group_id: "Some Group Id", - image_url: "https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png" + image_url: "https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png", }); const params = { headers: { - "Authorization": `Bearer ${bearerToken}`, - "Content-Type": "application/json" - } + Authorization: `Bearer ${bearerToken}`, + "Content-Type": "application/json", + }, }; - let response = http.post(url, payload, params); - if (response.status === 200 ) { + const response = http.post(url, payload, params); + if (response.status === 200) { // Request was successful // const { wallet_id: walletId, access_token: accessToken } = JSON.parse(response.body); // // Store walletId and accessToken for the current VU and iteration @@ -48,24 +47,23 @@ export function createTenant(bearerToken, wallet) { // accessToken: accessToken // }; return response; - } else { - // Request failed - console.warn(`Request failed for VU: ${__VU}, ITER: ${__ITER}`); - logError(response, payload); - throw new Error("Failed to create tenant"); } + // Request failed + console.warn(`Request failed for VU: ${__VU}, ITER: ${__ITER}`); + logError(response, payload); + throw new Error("Failed to create tenant"); } export function getWalletIdByWalletName(bearerToken, walletName) { const url = `${__ENV.CLOUDAPI_URL}/tenant-admin/v1/tenants?wallet_name=${walletName}`; const params = { headers: { - "Authorization": `Bearer ${bearerToken}`, - "Content-Type": "application/json" - } + Authorization: `Bearer ${bearerToken}`, + "Content-Type": "application/json", + }, }; - let response = http.get(url, params); + const response = http.get(url, params); if (response.status >= 200 && response.status < 300) { // Request was successful const responseData = JSON.parse(response.body); @@ -80,74 +78,71 @@ export function getWalletIdByWalletName(bearerToken, walletName) { console.warn(`Wallet not found for wallet_name ${walletName}`); console.warn(`Response body: ${response.body}`); return null; - } else { - logError(response); - console.warn(`Request failed for wallet_name ${walletName}`); - return null; } + logError(response); + console.warn(`Request failed for wallet_name ${walletName}`); + return null; } export function getTrustRegistryActor(walletName) { const url = `${__ENV.CLOUDAPI_URL}/public/v1/trust-registry/actors?actor_name=${walletName}`; const params = { headers: { - "Content-Type": "application/json" - } + "Content-Type": "application/json", + }, }; - let response = http.get(url); + const response = http.get(url); // console.log(`Respone: ${response}`) if (response.status === 200) { // Request was successful // console.log(`Issuer found for actor_name ${walletName}`); return response; - } else { - logError(response); - console.warn(`Issuer not on Trust Registry: actor_name ${walletName}`); - return null; } + logError(response); + console.warn(`Issuer not on Trust Registry: actor_name ${walletName}`); + return null; } export function getAccessTokenByWalletId(bearerToken, walletId) { - let start = new Date(); + const start = new Date(); const url = `${__ENV.CLOUDAPI_URL}/tenant-admin/v1/tenants/${walletId}/access-token`; const params = { headers: { - "Authorization": `Bearer ${bearerToken}`, + Authorization: `Bearer ${bearerToken}`, }, }; - let response = http.get(url, params); + const response = http.get(url, params); if (response.status >= 200 && response.status < 300) { // Request was successful const responseData = JSON.parse(response.body); const accessToken = responseData.access_token; - let end = new Date(); + const end = new Date(); // customDuration.add(end - start, { step: 'getAccessTokenByWalletId' }); return accessToken; - } else { - // Request failed - console.error(`Request failed with status ${response.status}`); - console.error(`Response body: ${response.body}`); - // throw new Error(`Failed to get access token: ${response.body}`); - let end = new Date(); - // customDuration.add(end - start, { step: 'getAccessTokenByWalletId' }); - return null; } + // Request failed + console.error(`Request failed with status ${response.status}`); + console.error(`Response body: ${response.body}`); + // throw new Error(`Failed to get access token: ${response.body}`); + const end = new Date(); + // customDuration.add(end - start, { step: 'getAccessTokenByWalletId' }); + return null; } export function deleteTenant(bearerToken, walletId) { const url = `${__ENV.CLOUDAPI_URL}/tenant-admin/v1/tenants/${walletId}`; const params = { headers: { - "Authorization": `Bearer ${bearerToken}`, + Authorization: `Bearer ${bearerToken}`, }, }; try { - let response = http.del(url, null, params); + const response = http.del(url, null, params); const responseBody = response.body; if (response.status === 200) { @@ -178,24 +173,23 @@ export function createIssuerTenant(bearerToken, walletName) { wallet_name: walletName, roles: ["issuer", "verifier"], group_id: "Group A", - image_url: "https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png" + image_url: "https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png", }); const params = { headers: { - "Authorization": `Bearer ${bearerToken}`, - "Content-Type": "application/json" - } + Authorization: `Bearer ${bearerToken}`, + "Content-Type": "application/json", + }, }; try { - let response = http.post(url, payload, params); + const response = http.post(url, payload, params); if (response.status >= 200 && response.status < 300) { return response; - } else { - logError(response); - console.warn(`Request failed for wallet_name ${walletName}`); - return null; } + logError(response); + console.warn(`Request failed for wallet_name ${walletName}`); + return null; } catch (error) { console.error(`Error creating issuer tenant: ${error.message}`); throw error; @@ -206,13 +200,13 @@ export function createInvitation(bearerToken, issuerAccessToken) { const url = `${__ENV.CLOUDAPI_URL}/tenant/v1/connections/create-invitation`; const params = { headers: { - "Authorization": `Bearer ${bearerToken}`, - "x-api-key": issuerAccessToken - } + Authorization: `Bearer ${bearerToken}`, + "x-api-key": issuerAccessToken, + }, }; try { - let response = http.post(url, null, params); + const response = http.post(url, null, params); return response; } catch (error) { console.error(`Error creating invitation: ${error.message}`); @@ -225,18 +219,18 @@ export function acceptInvitation(holderAccessToken, invitationObj) { const params = { headers: { "x-api-key": holderAccessToken, - "Content-Type": "application/json" - } + "Content-Type": "application/json", + }, }; try { // Construct the request body including the invitation object const requestBody = { - "alias": "holder <> issuer", - "invitation": invitationObj + alias: "holder <> issuer", + invitation: invitationObj, }; - let response = http.post(url, JSON.stringify(requestBody), params); + const response = http.post(url, JSON.stringify(requestBody), params); return response; } catch (error) { console.error(`Error accepting invitation: ${error.message}`); @@ -248,47 +242,46 @@ export function createCredential(bearerToken, issuerAccessToken, credentialDefin const url = `${__ENV.CLOUDAPI_URL}/tenant/v1/issuer/credentials`; const params = { headers: { - "Authorization": `Bearer ${bearerToken}`, - "x-api-key": issuerAccessToken - } + Authorization: `Bearer ${bearerToken}`, + "x-api-key": issuerAccessToken, + }, }; try { // Construct the request body including the invitation object const requestBody = JSON.stringify({ - "type": "indy", - "indy_credential_detail": { - "credential_definition_id": credentialDefinitionId, - "attributes": { - "date_of_birth": "1986-09-29", - "id_number": "8698989898989", - "country_of_birth": "South Africa", - "citizen_status": "Citizen", - "date_of_issue": "2021-09-29", - "gender": "MALE", - "surname": "Doe", - "nationality": "South African", - "country_of_birth_iso_code": "ZA", - "names": "John James", - } + type: "indy", + indy_credential_detail: { + credential_definition_id: credentialDefinitionId, + attributes: { + date_of_birth: "1986-09-29", + id_number: "8698989898989", + country_of_birth: "South Africa", + citizen_status: "Citizen", + date_of_issue: "2021-09-29", + gender: "MALE", + surname: "Doe", + nationality: "South African", + country_of_birth_iso_code: "ZA", + names: "John James", + }, }, - "save_exchange_record": false, - "connection_id": issuerConnectionId, - "protocol_version": "v2" + save_exchange_record: false, + connection_id: issuerConnectionId, + protocol_version: "v2", }); // console.log(`credentialDefinitionId: ${credentialDefinitionId}`) // console.log(`issuerConnectionId: ${issuerConnectionId}`) - let response = http.post(url, requestBody, params); + const response = http.post(url, requestBody, params); if (response.status >= 200 && response.status < 300) { // Request was successful return response; - } else { - console.error(`Request failed with status ${response.status}`); - console.error(`Response body: ${response.body}`); - return response.body; } + console.error(`Request failed with status ${response.status}`); + console.error(`Response body: ${response.body}`); + return response.body; } catch (error) { console.error(`Error accepting invitation: ${error.message}`); throw error; @@ -300,12 +293,12 @@ export function acceptCredential(holderAccessToken, credentialId) { const params = { headers: { "x-api-key": holderAccessToken, - "Content-Type": "application/json" - } + "Content-Type": "application/json", + }, }; try { - let response = http.post(url, null, params); + const response = http.post(url, null, params); return response; } catch (error) { console.error(`Error accepting credential: ${error.message}`); @@ -317,22 +310,22 @@ export function createCredentialDefinition(bearerToken, issuerAccessToken, credD const url = `${__ENV.CLOUDAPI_URL}/tenant/v1/definitions/credentials`; const params = { headers: { - "Authorization": `Bearer ${bearerToken}`, - "x-api-key": issuerAccessToken + Authorization: `Bearer ${bearerToken}`, + "x-api-key": issuerAccessToken, }, - timeout: "120s" + timeout: "120s", }; try { // Construct the request body including the invitation object const requestBody = JSON.stringify({ - "tag": credDefTag, - "schema_id": schemaId, - "support_revocation": true, - "revocation_registry_size": 100 + tag: credDefTag, + schema_id: schemaId, + support_revocation: true, + revocation_registry_size: 100, }); - let response = http.post(url, requestBody, params); + const response = http.post(url, requestBody, params); console.log(`Response body: ${response.body}`); console.log(`Request body: ${requestBody}`); return response; @@ -347,18 +340,18 @@ export function getCredentialIdByThreadId(holderAccessToken, threadId) { const params = { headers: { "x-api-key": holderAccessToken, - "Content-Type": "application/json" - } + "Content-Type": "application/json", + }, }; // console.log(`holderAccessToken: ${holderAccessToken}`); try { - let response = http.get(url, params); + const response = http.get(url, params); // console.log(`Request headers: ${JSON.stringify(response.request.headers)}`); // Parse the response body - let responseData = JSON.parse(response.body); + const responseData = JSON.parse(response.body); // Iterate over the responseData array for (let i = 0; i < responseData.length; i++) { - let obj = responseData[i]; + const obj = responseData[i]; // Check if the current object has a matching thread_id if (obj.thread_id === threadId) { // Return the credential_id if a match is found @@ -366,7 +359,9 @@ export function getCredentialIdByThreadId(holderAccessToken, threadId) { } } // Throw an error if no match is found - throw new Error(`No match found for threadId: ${threadId}\nResponse body: ${JSON.stringify(responseData, null, 2)}`); + throw new Error( + `No match found for threadId: ${threadId}\nResponse body: ${JSON.stringify(responseData, null, 2)}`, + ); } catch (error) { console.error("Error in getCredentialIdByThreadId:", error); throw error; // Re-throw the error to propagate it to the caller @@ -381,30 +376,36 @@ export function waitForSSEEvent(holderAccessToken, holderWalletId, threadId) { let eventReceived = false; - const response = sse.open(sseUrl, { - headers, - tags: { "k6_sse_tag": "credential_offer_received" }, - }, function (client) { - client.on("event", function (event) { - // console.log(`event data=${event.data}`); - const eventData = JSON.parse(event.data); - if (eventData.topic === "credentials" && eventData.payload.state === "offer-received") { - check(eventData, { - "Event received": (e) => e.payload.state === "offer-received", - }); - eventReceived = true; + const response = sse.open( + sseUrl, + { + headers, + tags: { k6_sse_tag: "credential_offer_received" }, + }, + (client) => { + client.on("event", (event) => { + // console.log(`event data=${event.data}`); + const eventData = JSON.parse(event.data); + if (eventData.topic === "credentials" && eventData.payload.state === "offer-received") { + check(eventData, { + "Event received": (e) => e.payload.state === "offer-received", + }); + eventReceived = true; + client.close(); + } + }); + + client.on("error", (e) => { + console.log("An unexpected error occurred: ", e.error()); client.close(); - } - }); + }); + }, + ); - client.on("error", function (e) { - console.log("An unexpected error occurred: ", e.error()); - client.close(); - }); + check(response, { + "SSE connection established": (r) => r && r.status === 200, }); - check(response, { "SSE connection established": (r) => r && r.status === 200 }); - // Wait for the event to be received or a maximum duration const maxDuration = 10; // 10 seconds const checkInterval = 1; // 1 second @@ -427,30 +428,36 @@ export function waitForSSEEventConnection(holderAccessToken, holderWalletId, inv let eventReceived = false; - const response = sse.open(sseUrl, { - headers, - tags: { "k6_sse_tag": "connection_ready" }, - }, function (client) { - client.on("event", function (event) { - // console.log(`event data=${event.data}`); - const eventData = JSON.parse(event.data); - if (eventData.topic === "connections" && eventData.payload.state === "completed") { - check(eventData, { - "Event received": (e) => e.payload.state === "completed", - }); - eventReceived = true; + const response = sse.open( + sseUrl, + { + headers, + tags: { k6_sse_tag: "connection_ready" }, + }, + (client) => { + client.on("event", (event) => { + // console.log(`event data=${event.data}`); + const eventData = JSON.parse(event.data); + if (eventData.topic === "connections" && eventData.payload.state === "completed") { + check(eventData, { + "Event received": (e) => e.payload.state === "completed", + }); + eventReceived = true; + client.close(); + } + }); + + client.on("error", (e) => { + console.log("An unexpected error occurred: ", e.error()); client.close(); - } - }); + }); + }, + ); - client.on("error", function (e) { - console.log("An unexpected error occurred: ", e.error()); - client.close(); - }); + check(response, { + "SSE connection established": (r) => r && r.status === 200, }); - check(response, { "SSE connection established": (r) => r && r.status === 200 }); - // Create random number between 1 and 3 // const random = Math.floor(Math.random() * 3) + 1; @@ -476,12 +483,12 @@ export function getCredentialDefinitionId(bearerToken, issuerAccessToken, credDe const url = `${__ENV.CLOUDAPI_URL}/tenant/v1/definitions/credentials?schema_version=0.1.0`; const params = { headers: { - "Authorization": `Bearer ${bearerToken}`, - "x-api-key": issuerAccessToken - } + Authorization: `Bearer ${bearerToken}`, + "x-api-key": issuerAccessToken, + }, }; - let response = http.get(url, params); + const response = http.get(url, params); if (response.status >= 200 && response.status < 300) { const responseData = JSON.parse(response.body); const matchingItem = responseData.find((item) => item.tag === credDefTag); @@ -489,15 +496,13 @@ export function getCredentialDefinitionId(bearerToken, issuerAccessToken, credDe if (matchingItem) { console.log(`Credential definition found for tag ${credDefTag}: ${matchingItem.id}`); return matchingItem.id; - } else { - console.warn(`Credential definition not found for tag ${credDefTag}`); - // logError(response); - return false; } - } else { - logError(response); - throw new Error("Failed to check credential definition existence"); + console.warn(`Credential definition not found for tag ${credDefTag}`); + // logError(response); + return false; } + logError(response); + throw new Error("Failed to check credential definition existence"); } export function sendProofRequest(issuerAccessToken, issuerConnectionId) { @@ -505,27 +510,27 @@ export function sendProofRequest(issuerAccessToken, issuerConnectionId) { const params = { headers: { "x-api-key": issuerAccessToken, - "Content-Type": 'application/json' - } + "Content-Type": "application/json", + }, }; try { // Construct the request body including the invitation object const requestBody = { - "type": "indy", - "indy_proof_request": { - "requested_attributes": { - "get_id_number": {"name": "id_number"} - }, - "requested_predicates": {} + type: "indy", + indy_proof_request: { + requested_attributes: { + get_id_number: { name: "id_number" }, + }, + requested_predicates: {}, }, - "save_exchange_record": true, - "comment": "string", - "protocol_version": "v2", - "connection_id": issuerConnectionId + save_exchange_record: true, + comment: "string", + protocol_version: "v2", + connection_id: issuerConnectionId, }; - let response = http.post(url, JSON.stringify(requestBody), params); + const response = http.post(url, JSON.stringify(requestBody), params); return response; } catch (error) { console.error(`Error accepting invitation: ${error.message}`); @@ -541,30 +546,36 @@ export function waitForSSEEventReceived(holderAccessToken, holderWalletId, threa let eventReceived = false; - const response = sse.open(sseUrl, { - headers, - // tags: { 'k6_sse_tag': 'proof_request_received' }, - }, function (client) { - client.on("event", function (event) { - // console.log(`event data=${event.data}`); - const eventData = JSON.parse(event.data); - if (eventData.topic === "proofs" && eventData.payload.state === "request-received") { - check(eventData, { - "Request received": (e) => e.payload.state === "request-received", - }); - eventReceived = true; + const response = sse.open( + sseUrl, + { + headers, + // tags: { 'k6_sse_tag': 'proof_request_received' }, + }, + (client) => { + client.on("event", (event) => { + // console.log(`event data=${event.data}`); + const eventData = JSON.parse(event.data); + if (eventData.topic === "proofs" && eventData.payload.state === "request-received") { + check(eventData, { + "Request received": (e) => e.payload.state === "request-received", + }); + eventReceived = true; + client.close(); + } + }); + + client.on("error", (e) => { + console.log("An unexpected error occurred: ", e.error()); client.close(); - } - }); + }); + }, + ); - client.on("error", function (e) { - console.log("An unexpected error occurred: ", e.error()); - client.close(); - }); + check(response, { + "SSE connection established": (r) => r && r.status === 200, }); - check(response, { "SSE connection established": (r) => r && r.status === 200 }); - // Wait for the event to be received or a maximum duration const maxDuration = 10; // 10 seconds const checkInterval = 1; // 1 second @@ -584,18 +595,18 @@ export function getProofIdByThreadId(holderAccessToken, threadId) { const params = { headers: { "x-api-key": holderAccessToken, - "Content-Type": 'application/json' - } + "Content-Type": "application/json", + }, }; // console.log(`holderAccessToken: ${holderAccessToken}`); try { - let response = http.get(url, params); + const response = http.get(url, params); // console.log(`Request headers: ${JSON.stringify(response.request.headers)}`); // Parse the response body - let responseData = JSON.parse(response.body); + const responseData = JSON.parse(response.body); // Iterate over the responseData array for (let i = 0; i < responseData.length; i++) { - let obj = responseData[i]; + const obj = responseData[i]; // Check if the current object has a matching thread_id if (obj.thread_id === threadId) { // Return the credential_id if a match is found @@ -603,7 +614,9 @@ export function getProofIdByThreadId(holderAccessToken, threadId) { } } // Throw an error if no match is found - throw new Error(`No match found for threadId: ${threadId}\nResponse body: ${JSON.stringify(responseData, null, 2)}`); + throw new Error( + `No match found for threadId: ${threadId}\nResponse body: ${JSON.stringify(responseData, null, 2)}`, + ); } catch (error) { console.error("Error in getProofId:", error); throw error; // Re-throw the error to propagate it to the caller @@ -615,20 +628,20 @@ export function getProofIdCredentials(holderAccessToken, proofId) { const params = { headers: { "x-api-key": holderAccessToken, - "Content-Type": 'application/json' - } + "Content-Type": "application/json", + }, }; // console.log(`holderAccessToken: ${holderAccessToken}`); try { - let response = http.get(url, params); + const response = http.get(url, params); // console.log(`Request headers: ${JSON.stringify(response.request.headers)}`); // Parse the response body - let responseData = JSON.parse(response.body); + const responseData = JSON.parse(response.body); // Iterate over the responseData array for (let i = 0; i < responseData.length; i++) { - let obj = responseData[i]; + const obj = responseData[i]; // Check if the current object has a matching thread_id - let referent = obj.cred_info.referent; + const referent = obj.cred_info.referent; return referent; } // Throw an error if no match is found @@ -645,28 +658,28 @@ export function acceptProofRequest(holderAccessToken, proofId, referent) { const params = { headers: { "x-api-key": holderAccessToken, - "Content-Type": 'application/json' - } + "Content-Type": "application/json", + }, }; try { // Construct the request body including the invitation object const requestBody = { - "type": "indy", - "proof_id": proofId, - "indy_presentation_spec": { - "requested_attributes": { - "get_id_number": { - "cred_id": referent, - "revealed": true - } + type: "indy", + proof_id: proofId, + indy_presentation_spec: { + requested_attributes: { + get_id_number: { + cred_id: referent, + revealed: true, }, - "requested_predicates": {}, - "self_attested_attributes": {} + }, + requested_predicates: {}, + self_attested_attributes: {}, }, - "diff_presentation_spec": {} + diff_presentation_spec: {}, }; - let response = http.post(url, JSON.stringify(requestBody), params); + const response = http.post(url, JSON.stringify(requestBody), params); // console.log(`holderAccessToken: ${holderAccessToken}`); // console.log(`Response body: ${response.body}`); // console.log(`Referent: ${referent}`); @@ -686,26 +699,36 @@ export function waitForSSEProofDone(issuerAccessToken, issuerWalletId, proofThre let eventReceived = false; - const response = sse.open(sseUrl, { - headers, - tags: { "k6_sse_tag": "proof_done" }, - }, function (client) { - client.on("event", function (event) { - // console.log(`event data=${event.data}`); - const eventData = JSON.parse(event.data); - if (eventData.topic === "proofs" && eventData.payload.state === "done") { - check(eventData, { - "Request received": (e) => e.payload.state === "done", }); eventReceived = true; + const response = sse.open( + sseUrl, + { + headers, + tags: { k6_sse_tag: "proof_done" }, + }, + (client) => { + client.on("event", (event) => { + // console.log(`event data=${event.data}`); + const eventData = JSON.parse(event.data); + if (eventData.topic === "proofs" && eventData.payload.state === "done") { + check(eventData, { + "Request received": (e) => e.payload.state === "done", + }); + eventReceived = true; + client.close(); + } + }); + + client.on("error", (e) => { + console.log("An unexpected error occurred: ", e.error()); client.close(); - } - }); + }); + }, + ); - client.on("error", function (e) { console.log("An unexpected error occurred: ", e.error()); client.close(); - }); + check(response, { + "SSE connection established": (r) => r && r.status === 200, }); - check(response, { "SSE connection established": (r) => r && r.status === 200 }); - // Wait for the event to be received or a maximum duration const maxDuration = 10; // 10 seconds const checkInterval = 1; // 1 second @@ -725,25 +748,25 @@ export function getProof(issuerAccessToken, issuerConnectionId, proofThreadId) { const params = { headers: { "x-api-key": issuerAccessToken, - "Content-Type": 'application/json' - } + "Content-Type": "application/json", + }, }; try { // Construct the request body including the invitation object const requestBody = { - "type": "indy", - "indy_proof_request": { - "requested_attributes": { - "get_id_number": {"name": "id_number"} - }, - "requested_predicates": {} + type: "indy", + indy_proof_request: { + requested_attributes: { + get_id_number: { name: "id_number" }, + }, + requested_predicates: {}, }, - "save_exchange_record": true, - "comment": "string", - "protocol_version": "v2", - "connection_id": issuerConnectionId + save_exchange_record: true, + comment: "string", + protocol_version: "v2", + connection_id: issuerConnectionId, }; - let response = http.get(url, params); + const response = http.get(url, params); // console.log(`Response body: ${response.body}`); // console.log(`IssuerAccessToken: ${issuerAccessToken}`); // console.log(`IssuerConnectionId: ${issuerConnectionId}`); @@ -759,16 +782,17 @@ export function createSchema(bearerToken, schemaName, schemaVersion) { const url = `${__ENV.CLOUDAPI_URL}/governance/v1/definitions/schemas`; const params = { headers: { - "Authorization": `Bearer ${bearerToken}`, + Authorization: `Bearer ${bearerToken}`, }, - timeout: "120s" }; + timeout: "120s", + }; try { // Construct the request body including the invitation object const requestBody = JSON.stringify({ - "name": schemaName, - "version": schemaVersion, - "attribute_names": [ + name: schemaName, + version: schemaVersion, + attribute_names: [ "date_of_birth", "id_number", "country_of_birth", @@ -778,11 +802,11 @@ export function createSchema(bearerToken, schemaName, schemaVersion) { "surname", "nationality", "country_of_birth_iso_code", - "names" - ] + "names", + ], }); - let response = http.post(url, requestBody, params); + const response = http.post(url, requestBody, params); // console.log(`Response body: ${response.body}`); return response; } catch (error) { @@ -795,24 +819,20 @@ export function getSchema(bearerToken, schemaName, schemaVersion) { const url = `${__ENV.CLOUDAPI_URL}/governance/v1/definitions/schemas?schema_name=${schemaName}&schema_version=${schemaVersion}`; const params = { headers: { - "Authorization": `Bearer ${bearerToken}`, + Authorization: `Bearer ${bearerToken}`, }, }; try { - let response = http.get(url, params); + const response = http.get(url, params); // console.log(`Response XXX body: ${response.body}`); return response; - } - catch (error) { + } catch (error) { console.error(`Error getting schema: ${error.message}`); throw error; } } - - - // { // "name": "load_pop", // "version": "0.1.0", diff --git a/scripts/k6/libs/issuerUtils.js b/scripts/k6/libs/issuerUtils.js index bc534050f..5805c809c 100644 --- a/scripts/k6/libs/issuerUtils.js +++ b/scripts/k6/libs/issuerUtils.js @@ -1,5 +1,5 @@ // issuerUtils.js -import { getWalletIdByWalletName, getAccessTokenByWalletId, createIssuerTenant } from './functions.js'; +import { createIssuerTenant, getAccessTokenByWalletId, getWalletIdByWalletName } from "./functions.js"; export function createIssuerIfNotExists(bearerToken, walletName) { let issuerWalletId = getWalletIdByWalletName(bearerToken, walletName); diff --git a/scripts/k6/libs/schemaUtils.js b/scripts/k6/libs/schemaUtils.js index 478eb70a1..1bb931631 100644 --- a/scripts/k6/libs/schemaUtils.js +++ b/scripts/k6/libs/schemaUtils.js @@ -1,25 +1,23 @@ // schemaUtils.js -import { getSchema, createSchema } from './functions.js'; +import { createSchema, getSchema } from "./functions.js"; export function createSchemaIfNotExists(bearerToken, schemaName, schemaVersion) { const schemaExists = checkSchemaExists(bearerToken, schemaName, schemaVersion); if (schemaExists) { console.log(`Schema: ${schemaName} version: ${schemaVersion} already exists`); return getSchemaId(bearerToken, schemaName, schemaVersion); - } else { - console.log(`Schema: ${schemaName} version: ${schemaVersion} does not exist - creating...`); - const createSchemaResponse = createSchema(bearerToken, schemaName, schemaVersion); - if (createSchemaResponse.status === 200) { - // Schema created successfully - const schemaData = JSON.parse(createSchemaResponse.body); - return schemaData.id; - } else { - // Schema creation failed - console.error(`Failed to create schema ${schemaName} v${schemaVersion}`); - throw new Error(`Failed to create schema ${schemaName} v${schemaVersion}`); - } } + console.log(`Schema: ${schemaName} version: ${schemaVersion} does not exist - creating...`); + const createSchemaResponse = createSchema(bearerToken, schemaName, schemaVersion); + if (createSchemaResponse.status === 200) { + // Schema created successfully + const schemaData = JSON.parse(createSchemaResponse.body); + return schemaData.id; + } + // Schema creation failed + console.error(`Failed to create schema ${schemaName} v${schemaVersion}`); + throw new Error(`Failed to create schema ${schemaName} v${schemaVersion}`); } function checkSchemaExists(bearerToken, schemaName, schemaVersion) { @@ -27,10 +25,9 @@ function checkSchemaExists(bearerToken, schemaName, schemaVersion) { if (getSchemaResponse.status === 200 && getSchemaResponse.body !== "[]") { // Schema exists return true; - } else { - // Schema does not exist - return false; } + // Schema does not exist + return false; } function getSchemaId(bearerToken, schemaName, schemaVersion) { @@ -41,13 +38,11 @@ function getSchemaId(bearerToken, schemaName, schemaVersion) { if (schemaData.length > 0) { const schemaId = schemaData[0].id; return schemaId; - } else { - console.error("Schema data array is empty"); - return null; } - } else { - // Schema does not exist - console.error("Schema does not exist or request failed"); + console.error("Schema data array is empty"); return null; } + // Schema does not exist + console.error("Schema does not exist or request failed"); + return null; } diff --git a/scripts/k6/main.js b/scripts/k6/main.js index 420a838fd..daa716c73 100644 --- a/scripts/k6/main.js +++ b/scripts/k6/main.js @@ -1,33 +1,33 @@ /* global __ENV, __ITER, __VU */ -/* eslint no-undef: "error" */ -/* eslint no-console: ["error", { allow: ["warn", "error", "log"] }] */ +/* eslint-disable no-undefined, no-console, camelcase */ import { check } from "k6"; import { SharedArray } from "k6/data"; +import { Counter, Trend } from "k6/metrics"; import { getBearerToken } from "./auth.js"; -import { Trend, Counter } from "k6/metrics"; import { - createTenant, - getWalletIdByWalletName, - getAccessTokenByWalletId, - deleteTenant, - createIssuerTenant, - createInvitation, + acceptCredential, acceptInvitation, createCredential, - acceptCredential, createCredentialDefinition, + createInvitation, + createIssuerTenant, + createTenant, + deleteTenant, + getAccessTokenByWalletId, + getCredentialDefinitionId, getCredentialIdByThreadId, + getWalletIdByWalletName, waitForSSEEvent, waitForSSEEventConnection, - getCredentialDefinitionId } from "./tenant.js"; -export let options = { +export const options = { vus: 2, // number of VUs to run iterations: 2, // total number of iterations (global) maxRedirects: 4, - thresholds: { //https://community.grafana.com/t/ignore-http-calls-made-in-setup-or-teardown-in-results/97260/2 + thresholds: { + // https://community.grafana.com/t/ignore-http-calls-made-in-setup-or-teardown-in-results/97260/2 "http_req_duration{scenario:default}": ["max>=0"], "http_reqs{scenario:default}": ["count >= 0"], "iteration_duration{scenario:default}": ["max>=0"], @@ -43,19 +43,19 @@ const specificFunctionReqs = new Counter("specific_function_reqs"); const mainIterationDuration = new Trend("main_iteration_duration"); // Seed data: Generating a list of options.iterations unique wallet names -const wallets = new SharedArray("wallets", function() { +const wallets = new SharedArray("wallets", () => { const walletsArray = []; for (let i = 0; i < options.iterations; i++) { walletsArray.push({ wallet_label: `xk6 holder ${i}`, - wallet_name: `xk6_wallet_${i}` + wallet_name: `xk6_wallet_${i}`, }); } return walletsArray; }); const numIssuers = 1; -let issuers = []; +const issuers = []; export function setup() { const bearerToken = getBearerToken(); @@ -84,7 +84,7 @@ export function setup() { try { const createIssuerTenantResponse = createIssuerTenant(bearerToken, walletName); check(createIssuerTenantResponse, { - "Issuer tenant created successfully": (r) => r.status === 200 + "Issuer tenant created successfully": (r) => r.status === 200, }); const tenantData = JSON.parse(createIssuerTenantResponse.body); issuerWalletId = tenantData.wallet_id; @@ -101,17 +101,16 @@ export function setup() { issuers.push({ walletId: issuerWalletId, accessToken: issuerAccessToken, - credentialDefinitionId + credentialDefinitionId, }); continue; - } else { - console.warn(`Failed to get credential definition ID for issuer ${walletName}`); - // console.error(`Response body: ${credentialDefinitionId.body}`); } + console.warn(`Failed to get credential definition ID for issuer ${walletName}`); + // console.error(`Response body: ${credentialDefinitionId.body}`); const createCredentialDefinitionResponse = createCredentialDefinition(bearerToken, issuerAccessToken, credDefTag); check(createCredentialDefinitionResponse, { - "Credential definition created successfully": (r) => r.status === 200 + "Credential definition created successfully": (r) => r.status === 200, }); if (createCredentialDefinitionResponse.status === 200) { @@ -120,7 +119,7 @@ export function setup() { issuers.push({ walletId: issuerWalletId, accessToken: issuerAccessToken, - credentialDefinitionId + credentialDefinitionId, }); } else { console.error(`Failed to create credential definition for issuer ${walletName}`); @@ -137,7 +136,7 @@ function getWalletIndex(vu, iter) { return startIndex + (iter % iterationsPerVU); } -export default function(data) { +export default function (data) { const start = Date.now(); const bearerToken = data.bearerToken; const issuers = data.issuers; @@ -153,11 +152,10 @@ export default function(data) { throw new Error(`Unexpected response status: ${r.status}`); } return true; - } + }, }); const { wallet_id: walletId, access_token: holderAccessToken } = JSON.parse(createTenantResponse.body); - const createInvitationResponse = createInvitation(bearerToken, issuer.accessToken); check(createInvitationResponse, { "Invitation created successfully": (r) => { @@ -165,7 +163,7 @@ export default function(data) { throw new Error(`Unexpected response status while create invitation: ${r.status}`); } return true; - } + }, }); const { invitation: invitationObj, connection_id: issuerConnectionId } = JSON.parse(createInvitationResponse.body); @@ -176,12 +174,16 @@ export default function(data) { throw new Error(`Unexpected response while accepting invitation: ${r.response}`); } return true; - } + }, }); const { connection_id: holderInvitationConnectionId } = JSON.parse(acceptInvitationResponse.body); - const waitForSSEEventConnectionResponse = waitForSSEEventConnection(holderAccessToken, walletId, holderInvitationConnectionId); + const waitForSSEEventConnectionResponse = waitForSSEEventConnection( + holderAccessToken, + walletId, + holderInvitationConnectionId, + ); check(waitForSSEEventConnectionResponse, { "SSE Event received successfully: connection-ready": (r) => { if (!r) { @@ -191,14 +193,19 @@ export default function(data) { }, }); - const createCredentialResponse = createCredential(bearerToken, issuer.accessToken, issuer.credentialDefinitionId, issuerConnectionId); + const createCredentialResponse = createCredential( + bearerToken, + issuer.accessToken, + issuer.credentialDefinitionId, + issuerConnectionId, + ); check(createCredentialResponse, { "Credential created successfully": (r) => { if (r.status !== 200) { throw new Error(`Unexpected response while creating credential: ${r.response}`); } return true; - } + }, }); const { thread_id: threadId } = JSON.parse(createCredentialResponse.body); @@ -222,7 +229,7 @@ export default function(data) { throw new Error(`Unexpected response while accepting credential: ${r.response}`); } return true; - } + }, }); specificFunctionReqs.add(1, { my_custom_tag: "specific_function" }); @@ -245,11 +252,10 @@ export function teardown(data) { if (r.status !== 200) { console.error(`Unexpected response status while deleting issuer tenant ${issuer.walletId}: ${r.status}`); return false; - } else { - console.log(`Deleted issuer tenant ${issuer.walletId} successfully.`); - return true; } - } + console.log(`Deleted issuer tenant ${issuer.walletId} successfully.`); + return true; + }, }); } } else { @@ -257,18 +263,17 @@ export function teardown(data) { } // // Delete holder tenants for (const wallet of wallets) { - const walletId = getWalletIdByWalletName(bearerToken, wallet.wallet_name); + const walletId = getWalletIdByWalletName(bearerToken, wallet.wallet_name); const deleteHolderResponse = deleteTenant(bearerToken, walletId); - check (deleteHolderResponse, { + check(deleteHolderResponse, { "Delete Holder Tenant Response status code is 200": (r) => { if (r.status !== 200) { console.error(`Unexpected response status while deleting holder tenant ${walletId}: ${r.status}`); return false; - } else { - console.log(`Deleted holder tenant ${walletId} successfully.`); - return true; } - } + console.log(`Deleted holder tenant ${walletId} successfully.`); + return true; + }, }); } } diff --git a/scripts/k6/package.json b/scripts/k6/package.json index f74d932ef..d1650a82e 100644 --- a/scripts/k6/package.json +++ b/scripts/k6/package.json @@ -1,11 +1,12 @@ { - "scripts": { - "format:check": "biome format .", - "format": "biome format --write .", - "lint:fix": "biome lint --write --unsafe .", - "lint": "biome lint ." - }, - "devDependencies": { - "@biomejs/biome": "^1.8.3" - } + "scripts": { + "format:check": "biome check --linter-enabled=false .", + "format": "biome check --linter-enabled=false --write .", + "lint:fix": "biome check --formatter-enabled=false --write .", + "lint:fix:unsafe": "biome check --formatter-enabled=false --write --unsafe .", + "lint": "biome check --formatter-enabled=false ." + }, + "devDependencies": { + "@biomejs/biome": "^1.8.3" + } } diff --git a/scripts/k6/scenarios/create-credentials.js b/scripts/k6/scenarios/create-credentials.js index 31c9e7b15..1aa0a3cf0 100644 --- a/scripts/k6/scenarios/create-credentials.js +++ b/scripts/k6/scenarios/create-credentials.js @@ -1,30 +1,28 @@ /* global __ENV, __ITER, __VU */ -/* eslint no-undef: "error" */ -/* eslint no-console: ["error", { allow: ["warn", "error", "log"] }] */ +/* eslint-disable no-undefined, no-console, camelcase */ import { check, sleep } from "k6"; import { SharedArray } from "k6/data"; +import { Counter, Trend } from "k6/metrics"; import { getBearerToken } from "../libs/auth.js"; -import { Trend, Counter } from "k6/metrics"; -import { createSchemaIfNotExists } from "../libs/schemaUtils.js"; -import { createIssuerIfNotExists } from '../libs/issuerUtils.js'; import { - getWalletIdByWalletName, - deleteTenant, - createCredential, acceptCredential, + createCredential, createCredentialDefinition, + deleteTenant, + getCredentialDefinitionId, getCredentialIdByThreadId, + getWalletIdByWalletName, waitForSSEEvent, - getCredentialDefinitionId } from "../libs/functions.js"; +import { createIssuerIfNotExists } from "../libs/issuerUtils.js"; +import { createSchemaIfNotExists } from "../libs/schemaUtils.js"; -const vus = parseInt(__ENV.VUS, 10); -const iterations = parseInt(__ENV.ITERATIONS, 10); +const vus = Number.parseInt(__ENV.VUS, 10); +const iterations = Number.parseInt(__ENV.ITERATIONS, 10); const issuerPrefix = __ENV.ISSUER_PREFIX; - -export let options = { +export const options = { scenarios: { default: { executor: "per-vu-iterations", @@ -36,11 +34,12 @@ export let options = { setupTimeout: "180s", // Increase the setup timeout to 120 seconds teardownTimeout: "180s", // Increase the teardown timeout to 120 seconds maxRedirects: 4, - thresholds: { //https://community.grafana.com/t/ignore-http-calls-made-in-setup-or-teardown-in-results/97260/2 + thresholds: { + // https://community.grafana.com/t/ignore-http-calls-made-in-setup-or-teardown-in-results/97260/2 "http_req_duration{scenario:default}": ["max>=0"], "http_reqs{scenario:default}": ["count >= 0"], "iteration_duration{scenario:default}": ["max>=0"], - "checks": ["rate==1"], + checks: ["rate==1"], // 'specific_function_reqs{my_custom_tag:specific_function}': ['count>=0'], // 'specific_function_reqs{scenario:default}': ['count>=0'], }, @@ -70,7 +69,7 @@ const testFunctionReqs = new Counter("test_function_reqs"); // }); const numIssuers = 1; -let issuers = []; +const issuers = []; export function setup() { const bearerToken = getBearerToken(); @@ -90,7 +89,7 @@ export function setup() { const issuerData = createIssuerIfNotExists(bearerToken, walletName); check(issuerData, { - "Issuer data retrieved successfully": (data) => data !== null && data !== undefined + "Issuer data retrieved successfully": (data) => data !== null && data !== undefined, }); if (!issuerData) { console.error(`Failed to create or retrieve issuer for ${walletName}`); @@ -104,22 +103,26 @@ export function setup() { issuers.push({ walletId: issuerWalletId, accessToken: issuerAccessToken, - credentialDefinitionId + credentialDefinitionId, }); continue; - } else { - console.warn(`Failed to get credential definition ID for issuer ${walletName}`); - // console.error(`Response body: ${credentialDefinitionId.body}`); } + console.warn(`Failed to get credential definition ID for issuer ${walletName}`); + // console.error(`Response body: ${credentialDefinitionId.body}`); const schemaId = createSchemaIfNotExists(governanceBearerToken, schemaName, schemaVersion); check(schemaId, { - "Schema ID is not null": (id) => id !== null && id !== undefined + "Schema ID is not null": (id) => id !== null && id !== undefined, }); - const createCredentialDefinitionResponse = createCredentialDefinition(bearerToken, issuerAccessToken, credDefTag, schemaId); + const createCredentialDefinitionResponse = createCredentialDefinition( + bearerToken, + issuerAccessToken, + credDefTag, + schemaId, + ); check(createCredentialDefinitionResponse, { - "Credential definition created successfully": (r) => r.status === 200 + "Credential definition created successfully": (r) => r.status === 200, }); if (createCredentialDefinitionResponse.status === 200) { @@ -128,7 +131,7 @@ export function setup() { issuers.push({ walletId: issuerWalletId, accessToken: issuerAccessToken, - credentialDefinitionId + credentialDefinitionId, }); } else { console.error(`Failed to create credential definition for issuer ${walletName}`); @@ -150,7 +153,7 @@ function getRandomInt() { return Math.floor(Math.random() * 101); } -export default function(data) { +export default function (data) { // const start = Date.now(); const bearerToken = data.bearerToken; const issuers = data.issuers; @@ -177,20 +180,25 @@ export default function(data) { let createCredentialResponse; try { - createCredentialResponse = createCredential(bearerToken, issuer.accessToken, issuer.credentialDefinitionId, wallet.issuer_connection_id); + createCredentialResponse = createCredential( + bearerToken, + issuer.accessToken, + issuer.credentialDefinitionId, + wallet.issuer_connection_id, + ); } catch (error) { - // console.error(`Error creating credential: ${error.message}`); - createCredentialResponse = { status: 500, response: error.message }; + // console.error(`Error creating credential: ${error.message}`); + createCredentialResponse = { status: 500, response: error.message }; } check(createCredentialResponse, { - "Credential created successfully": (r) => { - if (r.status !== 200) { - console.error(`Unexpected response while creating credential: ${r.response}`); - return false; - } - return true; + "Credential created successfully": (r) => { + if (r.status !== 200) { + console.error(`Unexpected response while creating credential: ${r.response}`); + return false; } + return true; + }, }); const { thread_id: threadId } = JSON.parse(createCredentialResponse.body); @@ -218,7 +226,7 @@ export default function(data) { throw new Error(`Unexpected response while accepting credential: ${r.response}`); } return true; - } + }, }); // specificFunctionReqs.add(1, { my_custom_tag: 'specific_function' }); @@ -246,11 +254,10 @@ export function teardown(data) { if (r.status !== 200) { console.error(`Unexpected response status while deleting issuer tenant ${issuer.walletId}: ${r.status}`); return false; - } else { - console.log(`Deleted issuer tenant ${issuer.walletId} successfully.`); - return true; } - } + console.log(`Deleted issuer tenant ${issuer.walletId} successfully.`); + return true; + }, }); } } else { @@ -259,18 +266,17 @@ export function teardown(data) { // // Delete holder tenants if (__ENV.SKIP_DELETE_HOLDERS !== "true") { for (const wallet of wallets) { - const walletId = getWalletIdByWalletName(bearerToken, wallet.wallet_name); + const walletId = getWalletIdByWalletName(bearerToken, wallet.wallet_name); const deleteHolderResponse = deleteTenant(bearerToken, walletId); - check (deleteHolderResponse, { + check(deleteHolderResponse, { "Delete Holder Tenant Response status code is 200": (r) => { if (r.status !== 200) { console.error(`Unexpected response status while deleting holder tenant ${walletId}: ${r.status}`); return false; - } else { - console.log(`Deleted holder tenant ${walletId} successfully.`); - return true; } - } + console.log(`Deleted holder tenant ${walletId} successfully.`); + return true; + }, }); } } else { diff --git a/scripts/k6/scenarios/create-holders.js b/scripts/k6/scenarios/create-holders.js index 332c2db2d..84058c4c3 100644 --- a/scripts/k6/scenarios/create-holders.js +++ b/scripts/k6/scenarios/create-holders.js @@ -1,30 +1,29 @@ /* global __ENV, __ITER, __VU */ -/* eslint no-undef: "error" */ -/* eslint no-console: ["error", { allow: ["warn", "error", "log"] }] */ +/* eslint-disable no-undefined, no-console, camelcase */ -import { sleep, check } from "k6"; +import { check, sleep } from "k6"; import { SharedArray } from "k6/data"; -import { getBearerToken, getGovernanceBearerToken } from "../libs/auth.js"; -import { Trend, Counter } from "k6/metrics"; +import { Counter, Trend } from "k6/metrics"; import file from "k6/x/file"; -import { createSchemaIfNotExists } from "../libs/schemaUtils.js"; -import { createIssuerIfNotExists } from '../libs/issuerUtils.js'; +import { getBearerToken, getGovernanceBearerToken } from "../libs/auth.js"; import { + createCredentialDefinition, createTenant, - getWalletIdByWalletName, deleteTenant, - createCredentialDefinition, getCredentialDefinitionId, + getWalletIdByWalletName, } from "../libs/functions.js"; +import { createIssuerIfNotExists } from "../libs/issuerUtils.js"; +import { createSchemaIfNotExists } from "../libs/schemaUtils.js"; -const vus = parseInt(__ENV.VUS, 10); -const iterations = parseInt(__ENV.ITERATIONS, 10); +const vus = Number.parseInt(__ENV.VUS, 10); +const iterations = Number.parseInt(__ENV.ITERATIONS, 10); const issuerPrefix = __ENV.ISSUER_PREFIX; const holderPrefix = __ENV.HOLDER_PREFIX; const schemaName = __ENV.SCHEMA_NAME; const schemaVersion = __ENV.SCHEMA_VERSION; -export let options = { +export const options = { scenarios: { default: { executor: "per-vu-iterations", @@ -36,11 +35,12 @@ export let options = { setupTimeout: "300s", // Increase the setup timeout to 120 seconds teardownTimeout: "120s", // Increase the teardown timeout to 120 seconds maxRedirects: 4, - thresholds: { //https://community.grafana.com/t/ignore-http-calls-made-in-setup-or-teardown-in-results/97260/2 + thresholds: { + // https://community.grafana.com/t/ignore-http-calls-made-in-setup-or-teardown-in-results/97260/2 "http_req_duration{scenario:default}": ["max>=0"], "http_reqs{scenario:default}": ["count >= 0"], "iteration_duration{scenario:default}": ["max>=0"], - "checks": ["rate==1"], + checks: ["rate==1"], // 'specific_function_reqs{my_custom_tag:specific_function}': ['count>=0'], // 'specific_function_reqs{scenario:default}': ['count>=0'], }, @@ -55,19 +55,19 @@ const testFunctionReqs = new Counter("test_function_reqs"); const mainIterationDuration = new Trend("main_iteration_duration"); // Seed data: Generating a list of options.iterations unique wallet names -const wallets = new SharedArray("wallets", function() { +const wallets = new SharedArray("wallets", () => { const walletsArray = []; for (let i = 0; i < options.scenarios.default.iterations * options.scenarios.default.vus; i++) { walletsArray.push({ wallet_label: `${holderPrefix} ${i}`, - wallet_name: `${holderPrefix}_${i}` + wallet_name: `${holderPrefix}_${i}`, }); } return walletsArray; }); const numIssuers = 1; -let issuers = []; +const issuers = []; const filepath = "output/create-holders.json"; export function setup() { @@ -83,7 +83,7 @@ export function setup() { const issuerData = createIssuerIfNotExists(bearerToken, walletName); check(issuerData, { - "Issuer data retrieved successfully": (data) => data !== null && data !== undefined + "Issuer data retrieved successfully": (data) => data !== null && data !== undefined, }); if (!issuerData) { console.error(`Failed to create or retrieve issuer for ${walletName}`); @@ -97,22 +97,26 @@ export function setup() { issuers.push({ walletId: issuerWalletId, accessToken: issuerAccessToken, - credentialDefinitionId + credentialDefinitionId, }); continue; - } else { - console.warn(`Failed to get credential definition ID for issuer ${walletName}`); - // console.error(`Response body: ${credentialDefinitionId.body}`); } + console.warn(`Failed to get credential definition ID for issuer ${walletName}`); + // console.error(`Response body: ${credentialDefinitionId.body}`); const schemaId = createSchemaIfNotExists(governanceBearerToken, schemaName, schemaVersion); check(schemaId, { - "Schema ID is not null": (id) => id !== null && id !== undefined + "Schema ID is not null": (id) => id !== null && id !== undefined, }); - const createCredentialDefinitionResponse = createCredentialDefinition(bearerToken, issuerAccessToken, credDefTag, schemaId); + const createCredentialDefinitionResponse = createCredentialDefinition( + bearerToken, + issuerAccessToken, + credDefTag, + schemaId, + ); check(createCredentialDefinitionResponse, { - "Credential definition created successfully": (r) => r.status === 200 + "Credential definition created successfully": (r) => r.status === 200, }); if (createCredentialDefinitionResponse.status === 200) { @@ -121,7 +125,7 @@ export function setup() { issuers.push({ walletId: issuerWalletId, accessToken: issuerAccessToken, - credentialDefinitionId + credentialDefinitionId, }); } else { console.error(`Failed to create credential definition for issuer ${walletName}`); @@ -138,7 +142,7 @@ function getWalletIndex(vu, iter) { return walletIndex; } -export default function(data) { +export default function (data) { const start = Date.now(); const bearerToken = data.bearerToken; const issuers = data.issuers; @@ -152,7 +156,7 @@ export default function(data) { throw new Error(`Unexpected response status: ${r.status}`); } return true; - } + }, }); const { wallet_id: walletId, access_token: holderAccessToken } = JSON.parse(createTenantResponse.body); @@ -164,7 +168,7 @@ export default function(data) { wallet_id: walletId, access_token: holderAccessToken, }); - file.appendString(filepath, holderData + "\n"); + file.appendString(filepath, `${holderData}\n`); const end = Date.now(); const duration = end - start; @@ -180,18 +184,18 @@ export function teardown(data) { console.log(__ENV.SKIP_DELETE_ISSUERS); - if (__ENV.SKIP_DELETE_ISSUERS !== "true") { for (const issuer of issuers) { + if (__ENV.SKIP_DELETE_ISSUERS !== "true") { + for (const issuer of issuers) { const deleteIssuerResponse = deleteTenant(bearerToken, issuer.walletId); check(deleteIssuerResponse, { "Delete Issuer Tenant Response status code is 200": (r) => { if (r.status !== 200) { console.error(`Unexpected response status while deleting issuer tenant ${issuer.walletId}: ${r.status}`); return false; - } else { - console.log(`Deleted issuer tenant ${issuer.walletId} successfully.`); - return true; } - } + console.log(`Deleted issuer tenant ${issuer.walletId} successfully.`); + return true; + }, }); } } else { @@ -199,19 +203,19 @@ export function teardown(data) { } // // Delete holder tenants - if (__ENV.SKIP_DELETE_HOLDERS !== "true") { for (const wallet of wallets) { - const walletId = getWalletIdByWalletName(bearerToken, wallet.wallet_name); + if (__ENV.SKIP_DELETE_HOLDERS !== "true") { + for (const wallet of wallets) { + const walletId = getWalletIdByWalletName(bearerToken, wallet.wallet_name); const deleteHolderResponse = deleteTenant(bearerToken, walletId); - check (deleteHolderResponse, { + check(deleteHolderResponse, { "Delete Holder Tenant Response status code is 200": (r) => { if (r.status !== 200) { console.error(`Unexpected response status while deleting holder tenant ${walletId}: ${r.status}`); return false; - } else { - console.log(`Deleted holder tenant ${walletId} successfully.`); - return true; } - } + console.log(`Deleted holder tenant ${walletId} successfully.`); + return true; + }, }); } } diff --git a/scripts/k6/scenarios/create-invitation.js b/scripts/k6/scenarios/create-invitation.js index ff0f34926..4a1f78034 100644 --- a/scripts/k6/scenarios/create-invitation.js +++ b/scripts/k6/scenarios/create-invitation.js @@ -1,29 +1,28 @@ /* global __ENV, __ITER, __VU */ -/* eslint no-undef: "error" */ -/* eslint no-console: ["error", { allow: ["warn", "error", "log"] }] */ +/* eslint-disable no-undefined, no-console, camelcase */ import { check } from "k6"; import { SharedArray } from "k6/data"; -import { getBearerToken } from "../libs/auth.js"; -import { Trend, Counter } from "k6/metrics"; +import { Counter, Trend } from "k6/metrics"; import file from "k6/x/file"; -import { createSchemaIfNotExists } from "../libs/schemaUtils.js"; -import { createIssuerIfNotExists } from '../libs/issuerUtils.js'; +import { getBearerToken } from "../libs/auth.js"; import { - getWalletIdByWalletName, - deleteTenant, - createInvitation, acceptInvitation, createCredentialDefinition, + createInvitation, + deleteTenant, + getCredentialDefinitionId, + getWalletIdByWalletName, waitForSSEEventConnection, - getCredentialDefinitionId } from "../libs/functions.js"; +import { createIssuerIfNotExists } from "../libs/issuerUtils.js"; +import { createSchemaIfNotExists } from "../libs/schemaUtils.js"; -const vus = parseInt(__ENV.VUS, 10); -const iterations = parseInt(__ENV.ITERATIONS, 10); +const vus = Number.parseInt(__ENV.VUS, 10); +const iterations = Number.parseInt(__ENV.ITERATIONS, 10); const issuerPrefix = __ENV.ISSUER_PREFIX; -export let options = { +export const options = { scenarios: { default: { executor: "per-vu-iterations", @@ -35,12 +34,13 @@ export let options = { setupTimeout: "120s", // Increase the setup timeout to 120 seconds teardownTimeout: "120s", // Increase the teardown timeout to 120 seconds maxRedirects: 4, - thresholds: { //https://community.grafana.com/t/ignore-http-calls-made-in-setup-or-teardown-in-results/97260/2 + thresholds: { + // https://community.grafana.com/t/ignore-http-calls-made-in-setup-or-teardown-in-results/97260/2 "http_req_duration{scenario:default}": ["max>=0"], "http_reqs{scenario:default}": ["count >= 0"], "http_reqs{my_custom_tag:specific_function}": ["count>=0"], "iteration_duration{scenario:default}": ["max>=0"], - "checks": ["rate==1"], + checks: ["rate==1"], // 'test_function_reqs{my_custom_tag:specific_function}': ['count>=0'], // 'test_function_reqs{scenario:default}': ['count>=0'], // 'custom_duration{step:getAccessTokenByWalletId}': ['avg>=0'], @@ -59,19 +59,19 @@ const data = open(inputFilepath, "r"); const outputFilepath = "output/create-invitation.json"; // Seed data: Generating a list of options.iterations unique wallet names -const wallets = new SharedArray("wallets", function() { +const wallets = new SharedArray("wallets", () => { const walletsArray = []; for (let i = 0; i < options.iterations; i++) { walletsArray.push({ wallet_label: `xxkk6 holder ${i}`, - wallet_name: `xxkk6_wallet_${i}` + wallet_name: `xxkk6_wallet_${i}`, }); } return walletsArray; }); const numIssuers = 1; -let issuers = []; +const issuers = []; export function setup() { const bearerToken = getBearerToken(); @@ -93,7 +93,7 @@ export function setup() { const issuerData = createIssuerIfNotExists(bearerToken, walletName); check(issuerData, { - "Issuer data retrieved successfully": (data) => data !== null && data !== undefined + "Issuer data retrieved successfully": (data) => data !== null && data !== undefined, }); if (!issuerData) { console.error(`Failed to create or retrieve issuer for ${walletName}`); @@ -107,22 +107,26 @@ export function setup() { issuers.push({ walletId: issuerWalletId, accessToken: issuerAccessToken, - credentialDefinitionId + credentialDefinitionId, }); continue; - } else { - console.warn(`Failed to get credential definition ID for issuer ${walletName}`); - // console.error(`Response body: ${credentialDefinitionId.body}`); } + console.warn(`Failed to get credential definition ID for issuer ${walletName}`); + // console.error(`Response body: ${credentialDefinitionId.body}`); const schemaId = createSchemaIfNotExists(governanceBearerToken, schemaName, schemaVersion); check(schemaId, { - "Schema ID is not null": (id) => id !== null && id !== undefined + "Schema ID is not null": (id) => id !== null && id !== undefined, }); - const createCredentialDefinitionResponse = createCredentialDefinition(bearerToken, issuerAccessToken, credDefTag, schemaId); + const createCredentialDefinitionResponse = createCredentialDefinition( + bearerToken, + issuerAccessToken, + credDefTag, + schemaId, + ); check(createCredentialDefinitionResponse, { - "Credential definition created successfully": (r) => r.status === 200 + "Credential definition created successfully": (r) => r.status === 200, }); if (createCredentialDefinitionResponse.status === 200) { @@ -131,7 +135,7 @@ export function setup() { issuers.push({ walletId: issuerWalletId, accessToken: issuerAccessToken, - credentialDefinitionId + credentialDefinitionId, }); } else { console.error(`Failed to create credential definition for issuer ${walletName}`); @@ -151,7 +155,7 @@ function getWalletIndex(vu, iter) { const vuStartTimes = {}; const vuEndTimes = {}; -export default function(data) { +export default function (data) { if (__ITER === 0) { vuStartTimes[__VU] = Date.now(); } @@ -163,7 +167,6 @@ export default function(data) { const holders = data.holders; const wallet = holders[walletIndex]; - const issuerIndex = __ITER % numIssuers; const issuer = issuers[issuerIndex]; @@ -184,7 +187,7 @@ export default function(data) { throw new Error(`Unexpected response status while create invitation: ${r.status}`); } return true; - } + }, }); const { invitation: invitationObj, connection_id: issuerConnectionId } = JSON.parse(createInvitationResponse.body); @@ -195,12 +198,16 @@ export default function(data) { throw new Error(`Unexpected response while accepting invitation: ${r.response}`); } return true; - } + }, }); const { connection_id: holderInvitationConnectionId } = JSON.parse(acceptInvitationResponse.body); - const waitForSSEEventConnectionResponse = waitForSSEEventConnection(wallet.access_token, wallet.wallet_id, holderInvitationConnectionId); + const waitForSSEEventConnectionResponse = waitForSSEEventConnection( + wallet.access_token, + wallet.wallet_id, + holderInvitationConnectionId, + ); check(waitForSSEEventConnectionResponse, { "SSE Event received successfully: connection-ready": (r) => { if (!r) { @@ -222,7 +229,7 @@ export default function(data) { connection_id: holderInvitationConnectionId, issuer_connection_id: issuerConnectionId, }); - file.appendString(outputFilepath, holderData + "\n"); + file.appendString(outputFilepath, `${holderData}\n`); const end = Date.now(); const duration = end - start; @@ -230,8 +237,6 @@ export default function(data) { mainIterationDuration.add(duration); } - - export function teardown(data) { vuEndTimes[__VU] = Date.now(); const bearerToken = data.bearerToken; @@ -246,11 +251,10 @@ export function teardown(data) { if (r.status !== 200) { console.error(`Unexpected response status while deleting issuer tenant ${issuer.walletId}: ${r.status}`); return false; - } else { - console.log(`Deleted issuer tenant ${issuer.walletId} successfully.`); - return true; } - } + console.log(`Deleted issuer tenant ${issuer.walletId} successfully.`); + return true; + }, }); } } else { @@ -259,18 +263,17 @@ export function teardown(data) { // // Delete holder tenants if (__ENV.SKIP_DELETE_HOLDERS !== "true") { for (const wallet of holders) { - const walletId = getWalletIdByWalletName(bearerToken, wallet.wallet_name); + const walletId = getWalletIdByWalletName(bearerToken, wallet.wallet_name); const deleteHolderResponse = deleteTenant(bearerToken, walletId); - check (deleteHolderResponse, { + check(deleteHolderResponse, { "Delete Holder Tenant Response status code is 200": (r) => { if (r.status !== 200) { console.error(`Unexpected response status while deleting holder tenant ${walletId}: ${r.status}`); return false; - } else { - console.log(`Deleted holder tenant ${walletId} successfully.`); - return true; } - } + console.log(`Deleted holder tenant ${walletId} successfully.`); + return true; + }, }); } } else { diff --git a/scripts/k6/scenarios/create-issuers.js b/scripts/k6/scenarios/create-issuers.js index a937af42e..9a663d47b 100644 --- a/scripts/k6/scenarios/create-issuers.js +++ b/scripts/k6/scenarios/create-issuers.js @@ -1,56 +1,58 @@ /* global __ENV, __ITER, __VU */ // Solve Codacy '__ENV' is not defined. error +/* eslint-disable no-undefined, no-console, camelcase */ -import { check } from 'k6'; -import { SharedArray } from 'k6/data'; -import { getBearerToken } from '../libs/auth.js'; -import { Trend, Counter } from 'k6/metrics'; +import { check } from "k6"; +import { SharedArray } from "k6/data"; +import { Counter, Trend } from "k6/metrics"; +import { getBearerToken } from "../libs/auth.js"; import { - getWalletIdByWalletName, - deleteTenant, + createCredentialDefinition, createIssuerTenant, + deleteTenant, getTrustRegistryActor, - createCredentialDefinition, -} from '../libs/functions.js'; + getWalletIdByWalletName, +} from "../libs/functions.js"; -const vus = parseInt(__ENV.VUS, 10); -const iterations = parseInt(__ENV.ITERATIONS, 10); +const vus = Number.parseInt(__ENV.VUS, 10); +const iterations = Number.parseInt(__ENV.ITERATIONS, 10); const issuerPrefix = __ENV.ISSUER_PREFIX; // const holderPrefix = __ENV.HOLDER_PREFIX; -export let options = { +export const options = { scenarios: { default: { - executor: 'per-vu-iterations', + executor: "per-vu-iterations", vus: vus, iterations: iterations, - maxDuration: '24h', + maxDuration: "24h", }, }, - setupTimeout: '300s', // Increase the setup timeout to 120 seconds - teardownTimeout: '120s', // Increase the teardown timeout to 120 seconds + setupTimeout: "300s", // Increase the setup timeout to 120 seconds + teardownTimeout: "120s", // Increase the teardown timeout to 120 seconds maxRedirects: 4, - thresholds: { //https://community.grafana.com/t/ignore-http-calls-made-in-setup-or-teardown-in-results/97260/2 - 'http_req_duration{scenario:default}': [`max>=0`], - 'http_reqs{scenario:default}': ['count >= 0'], - 'iteration_duration{scenario:default}': ['max>=0'], + thresholds: { + // https://community.grafana.com/t/ignore-http-calls-made-in-setup-or-teardown-in-results/97260/2 + "http_req_duration{scenario:default}": ["max>=0"], + "http_reqs{scenario:default}": ["count >= 0"], + "iteration_duration{scenario:default}": ["max>=0"], }, tags: { - test_run_id: 'phased-issuance', - test_phase: 'create-issuers', + test_run_id: "phased-issuance", + test_phase: "create-issuers", }, }; -const testFunctionReqs = new Counter('test_function_reqs'); -const mainIterationDuration = new Trend('main_iteration_duration'); +const testFunctionReqs = new Counter("test_function_reqs"); +const mainIterationDuration = new Trend("main_iteration_duration"); // Seed data: Generating a list of options.iterations unique wallet names -const wallets = new SharedArray('wallets', function() { +const wallets = new SharedArray("wallets", () => { const walletsArray = []; for (let i = 0; i < options.scenarios.default.iterations * options.scenarios.default.vus; i++) { walletsArray.push({ walletLabel: `${issuerPrefix} ${i}`, - walletName: `${issuerPrefix}_${i}` + walletName: `${issuerPrefix}_${i}`, }); } return walletsArray; @@ -68,7 +70,7 @@ function getWalletIndex(vu, iter) { return walletIndex; } -export default function(data) { +export default function (data) { const start = Date.now(); const bearerToken = data.bearerToken; const walletIndex = getWalletIndex(__VU, __ITER + 1); // __ITER starts from 0, adding 1 to align with the logic @@ -77,7 +79,7 @@ export default function(data) { const createIssuerTenantResponse = createIssuerTenant(bearerToken, wallet.walletName); check(createIssuerTenantResponse, { - "Issuer tenant created successfully": (r) => r.status === 200 + "Issuer tenant created successfully": (r) => r.status === 200, }); const issuerAccessToken = createIssuerTenantResponse.json().access_token; @@ -85,13 +87,14 @@ export default function(data) { check(getTrustRegistryActorResponse, { "Trust Registry Actor Response status code is 200": (r) => { if (r.status !== 200) { - console.error(`Unexpected response status while getting trust registry actor for issuer tenant ${wallet.walletName}: ${r.status}`); + console.error( + `Unexpected response status while getting trust registry actor for issuer tenant ${wallet.walletName}: ${r.status}`, + ); return false; - } else { - console.log(`Got trust registry actor for issuer tenant ${wallet.walletName} successfully.`); - return true; } - } + console.log(`Got trust registry actor for issuer tenant ${wallet.walletName} successfully.`); + return true; + }, }); // const createCredentialDefinitionResponse = createCredentialDefinition(bearerToken, issuerAccessToken, credDefTag); @@ -110,20 +113,19 @@ export function teardown(data) { const bearerToken = data.bearerToken; // // Delete issuer tenants - if (__ENV.SKIP_DELETE_ISSUERS !== 'true') { + if (__ENV.SKIP_DELETE_ISSUERS !== "true") { for (const wallet of wallets) { - const walletId = getWalletIdByWalletName(bearerToken, wallet.walletName); + const walletId = getWalletIdByWalletName(bearerToken, wallet.walletName); const deleteIssuerResponse = deleteTenant(bearerToken, walletId); - check (deleteIssuerResponse, { + check(deleteIssuerResponse, { "Delete Issuer Tenant Response status code is 200": (r) => { if (r.status !== 200) { console.error(`Unexpected response status while deleting issuer tenant ${walletId}: ${r.status}`); return false; - } else { - console.log(`Deleted issuer tenant ${walletId} successfully.`); - return true; } - } + console.log(`Deleted issuer tenant ${walletId} successfully.`); + return true; + }, }); } } diff --git a/scripts/k6/scenarios/create-proof.js b/scripts/k6/scenarios/create-proof.js index f8d236836..2cbe00441 100644 --- a/scripts/k6/scenarios/create-proof.js +++ b/scripts/k6/scenarios/create-proof.js @@ -1,33 +1,31 @@ /* global __ENV, __ITER, __VU */ -/* eslint no-undef: "error" */ -/* eslint no-console: ["error", { allow: ["warn", "error", "log"] }] */ +/* eslint-disable no-undefined, no-console, camelcase */ import { check, sleep } from "k6"; import { SharedArray } from "k6/data"; +import { Counter, Trend } from "k6/metrics"; import { getBearerToken } from "../libs/auth.js"; -import { Trend, Counter } from "k6/metrics"; -import { createSchemaIfNotExists } from "../libs/schemaUtils.js"; -import { createIssuerIfNotExists } from '../libs/issuerUtils.js'; import { - getWalletIdByWalletName, - deleteTenant, + acceptProofRequest, createCredentialDefinition, + deleteTenant, getCredentialDefinitionId, + getProof, + getProofIdByThreadId, getProofIdCredentials, + getWalletIdByWalletName, sendProofRequest, waitForSSEEventReceived, - getProofIdByThreadId, - acceptProofRequest, waitForSSEProofDone, - getProof, } from "../libs/functions.js"; +import { createIssuerIfNotExists } from "../libs/issuerUtils.js"; +import { createSchemaIfNotExists } from "../libs/schemaUtils.js"; -const vus = parseInt(__ENV.VUS, 10); -const iterations = parseInt(__ENV.ITERATIONS, 10); +const vus = Number.parseInt(__ENV.VUS, 10); +const iterations = Number.parseInt(__ENV.ITERATIONS, 10); const issuerPrefix = __ENV.ISSUER_PREFIX; - -export let options = { +export const options = { scenarios: { default: { executor: "per-vu-iterations", @@ -39,11 +37,12 @@ export let options = { setupTimeout: "180s", // Increase the setup timeout to 120 seconds teardownTimeout: "180s", // Increase the teardown timeout to 120 seconds maxRedirects: 4, - thresholds: { //https://community.grafana.com/t/ignore-http-calls-made-in-setup-or-teardown-in-results/97260/2 + thresholds: { + // https://community.grafana.com/t/ignore-http-calls-made-in-setup-or-teardown-in-results/97260/2 "http_req_duration{scenario:default}": ["max>=0"], "http_reqs{scenario:default}": ["count >= 0"], "iteration_duration{scenario:default}": ["max>=0"], - "checks": ["rate==1"], + checks: ["rate==1"], // 'specific_function_reqs{my_custom_tag:specific_function}': ['count>=0'], // 'specific_function_reqs{scenario:default}': ['count>=0'], }, @@ -73,7 +72,7 @@ const testFunctionReqs = new Counter("test_function_reqs"); // }); const numIssuers = 1; -let issuers = []; +const issuers = []; export function setup() { const bearerToken = getBearerToken(); @@ -93,7 +92,7 @@ export function setup() { const issuerData = createIssuerIfNotExists(bearerToken, walletName); check(issuerData, { - "Issuer data retrieved successfully": (data) => data !== null && data !== undefined + "Issuer data retrieved successfully": (data) => data !== null && data !== undefined, }); if (!issuerData) { console.error(`Failed to create or retrieve issuer for ${walletName}`); @@ -107,22 +106,26 @@ export function setup() { issuers.push({ walletId: issuerWalletId, accessToken: issuerAccessToken, - credentialDefinitionId + credentialDefinitionId, }); continue; - } else { - console.warn(`Failed to get credential definition ID for issuer ${walletName}`); - // console.error(`Response body: ${credentialDefinitionId.body}`); } + console.warn(`Failed to get credential definition ID for issuer ${walletName}`); + // console.error(`Response body: ${credentialDefinitionId.body}`); const schemaId = createSchemaIfNotExists(governanceBearerToken, schemaName, schemaVersion); check(schemaId, { - "Schema ID is not null": (id) => id !== null && id !== undefined + "Schema ID is not null": (id) => id !== null && id !== undefined, }); - const createCredentialDefinitionResponse = createCredentialDefinition(bearerToken, issuerAccessToken, credDefTag, schemaId); + const createCredentialDefinitionResponse = createCredentialDefinition( + bearerToken, + issuerAccessToken, + credDefTag, + schemaId, + ); check(createCredentialDefinitionResponse, { - "Credential definition created successfully": (r) => r.status === 200 + "Credential definition created successfully": (r) => r.status === 200, }); if (createCredentialDefinitionResponse.status === 200) { @@ -131,7 +134,7 @@ export function setup() { issuers.push({ walletId: issuerWalletId, accessToken: issuerAccessToken, - credentialDefinitionId + credentialDefinitionId, }); } else { console.error(`Failed to create credential definition for issuer ${walletName}`); @@ -153,7 +156,7 @@ function getRandomInt() { return Math.floor(Math.random() * 101); } -export default function(data) { +export default function (data) { // const start = Date.now(); const bearerToken = data.bearerToken; const issuers = data.issuers; @@ -172,8 +175,8 @@ export default function(data) { try { sendProofRequestResponse = sendProofRequest(issuer.accessToken, wallet.issuer_connection_id); } catch (error) { - // console.error(`Error creating credential: ${error.message}`); - sendProofRequestResponse = { status: 500, response: error.message }; + // console.error(`Error creating credential: ${error.message}`); + sendProofRequestResponse = { status: 500, response: error.message }; } check(sendProofRequestResponse, { "Proof request sent successfully": (r) => { @@ -181,7 +184,7 @@ export default function(data) { throw new Error(`Unexpected response while sending proof request: ${r.response}`); } return true; - } + }, }); const { thread_id: threadId } = JSON.parse(sendProofRequestResponse.body); @@ -207,7 +210,7 @@ export default function(data) { throw new Error(`Unexpected response while accepting proof: ${r.response}`); } return true; - } + }, }); const waitForSSEProofDoneRequest = waitForSSEProofDone(issuer.accessToken, issuer.walletId, threadId); @@ -223,10 +226,10 @@ export default function(data) { // const getProofResponse = getProof(issuer.accessToken, wallet.issuer_connection_id, threadId ); let getProofResponse; try { - getProofResponse = getProof(issuer.accessToken, wallet.issuer_connection_id, threadId ); + getProofResponse = getProof(issuer.accessToken, wallet.issuer_connection_id, threadId); } catch (error) { - // console.error(`Error creating credential: ${error.message}`); - getProofResponse = { status: 500, response: error.message }; + // console.error(`Error creating credential: ${error.message}`); + getProofResponse = { status: 500, response: error.message }; } check(getProofResponse, { "Proof received successfully": (r) => { @@ -255,11 +258,10 @@ export function teardown(data) { if (r.status !== 200) { console.error(`Unexpected response status while deleting issuer tenant ${issuer.walletId}: ${r.status}`); return false; - } else { - console.log(`Deleted issuer tenant ${issuer.walletId} successfully.`); - return true; } - } + console.log(`Deleted issuer tenant ${issuer.walletId} successfully.`); + return true; + }, }); } } else { @@ -268,18 +270,17 @@ export function teardown(data) { // // Delete holder tenants if (__ENV.SKIP_DELETE_HOLDERS !== "true") { for (const wallet of wallets) { - const walletId = getWalletIdByWalletName(bearerToken, wallet.wallet_name); + const walletId = getWalletIdByWalletName(bearerToken, wallet.wallet_name); const deleteHolderResponse = deleteTenant(bearerToken, walletId); - check (deleteHolderResponse, { + check(deleteHolderResponse, { "Delete Holder Tenant Response status code is 200": (r) => { if (r.status !== 200) { console.error(`Unexpected response status while deleting holder tenant ${walletId}: ${r.status}`); return false; - } else { - console.log(`Deleted holder tenant ${walletId} successfully.`); - return true; } - } + console.log(`Deleted holder tenant ${walletId} successfully.`); + return true; + }, }); } } else { diff --git a/scripts/k6/scenarios/delete-holders.js b/scripts/k6/scenarios/delete-holders.js index 014aefc08..f9178ee02 100644 --- a/scripts/k6/scenarios/delete-holders.js +++ b/scripts/k6/scenarios/delete-holders.js @@ -1,21 +1,17 @@ /* global __ENV, __ITER, __VU */ -/* eslint no-undef: "error" */ -/* eslint no-console: ["error", { allow: ["warn", "error", "log"] }] */ +/* eslint-disable no-undefined, no-console, camelcase */ -import { sleep, check } from "k6"; +import { check, sleep } from "k6"; import { SharedArray } from "k6/data"; +import { Counter, Trend } from "k6/metrics"; import { getBearerToken } from "../libs/auth.js"; -import { Trend, Counter } from "k6/metrics"; -import { - getWalletIdByWalletName, - deleteTenant, -} from "../libs/functions.js"; +import { deleteTenant, getWalletIdByWalletName } from "../libs/functions.js"; -const vus = parseInt(__ENV.VUS, 10); -const iterations = parseInt(__ENV.ITERATIONS, 10); +const vus = Number.parseInt(__ENV.VUS, 10); +const iterations = Number.parseInt(__ENV.ITERATIONS, 10); const holderPrefix = __ENV.HOLDER_PREFIX; -export let options = { +export const options = { scenarios: { default: { executor: "per-vu-iterations", @@ -27,11 +23,12 @@ export let options = { setupTimeout: "180s", // Increase the setup timeout to 120 seconds teardownTimeout: "120s", // Increase the teardown timeout to 120 seconds maxRedirects: 4, - thresholds: { //https://community.grafana.com/t/ignore-http-calls-made-in-setup-or-teardown-in-results/97260/2 + thresholds: { + // https://community.grafana.com/t/ignore-http-calls-made-in-setup-or-teardown-in-results/97260/2 "http_req_duration{scenario:default}": ["max>=0"], "http_reqs{scenario:default}": ["count >= 0"], "iteration_duration{scenario:default}": ["max>=0"], - "checks": ["rate==1"] + checks: ["rate==1"], }, tags: { test_run_id: "phased-issuance", @@ -42,19 +39,19 @@ export let options = { const testFunctionReqs = new Counter("test_function_reqs"); // Seed data: Generating a list of options.iterations unique wallet names -const wallets = new SharedArray("wallets", function() { +const wallets = new SharedArray("wallets", () => { const walletsArray = []; for (let i = 0; i < options.scenarios.default.iterations * options.scenarios.default.vus; i++) { walletsArray.push({ wallet_label: `${holderPrefix} ${i}`, - wallet_name: `${holderPrefix}_${i}` + wallet_name: `${holderPrefix}_${i}`, }); } return walletsArray; }); const numIssuers = 1; -let issuers = []; +const issuers = []; const filepath = "output/create-holders.json"; export function setup() { @@ -69,23 +66,22 @@ function getWalletIndex(vu, iter) { return walletIndex; } -export default function(data) { +export default function (data) { const bearerToken = data.bearerToken; const walletIndex = getWalletIndex(__VU, __ITER + 1); // __ITER starts from 0, adding 1 to align with the logic const wallet = wallets[walletIndex]; - const walletId = getWalletIdByWalletName(bearerToken, wallet.wallet_name); + const walletId = getWalletIdByWalletName(bearerToken, wallet.wallet_name); const deleteHolderResponse = deleteTenant(bearerToken, walletId); - check (deleteHolderResponse, { + check(deleteHolderResponse, { "Delete Holder Tenant Response status code is 200": (r) => { if (r.status !== 200) { console.error(`Unexpected response status while deleting holder tenant ${walletId}: ${r.status}`); return false; - } else { - // console.log(`Deleted holder tenant ${walletId} successfully.`); - return true; } - } + // console.log(`Deleted holder tenant ${walletId} successfully.`); + return true; + }, }); testFunctionReqs.add(1); }