From 39c7b987653e218a2c89fe75ce68a7a3d978bed0 Mon Sep 17 00:00:00 2001 From: Mourits de Beer <31511766+ff137@users.noreply.github.com> Date: Thu, 10 Oct 2024 14:30:18 +0200 Subject: [PATCH 1/3] Revert ":art: resolve remaining repo code scanning warnings (#1113)" This reverts commit 6a0091d0defe94adbb43279877efd625574eeccc. --- scripts/k6/main.js | 2 +- scripts/k6/scenarios/create-invitations.js | 2 +- scripts/k6/scenarios/create-issuers.js | 6 ++--- scripts/k6/scenarios/create-schemas.js | 31 ++++++++++------------ scripts/k6/scenarios/delete-holders.js | 2 +- 5 files changed, 20 insertions(+), 23 deletions(-) diff --git a/scripts/k6/main.js b/scripts/k6/main.js index c148d51ed..5804a73f1 100644 --- a/scripts/k6/main.js +++ b/scripts/k6/main.js @@ -151,7 +151,7 @@ export function setup() { } } - return bearerToken, issuers; + return { bearerToken, issuers }; } // Helper function to calculate the wallet index based on VU and iteration diff --git a/scripts/k6/scenarios/create-invitations.js b/scripts/k6/scenarios/create-invitations.js index df913d347..4d764254c 100644 --- a/scripts/k6/scenarios/create-invitations.js +++ b/scripts/k6/scenarios/create-invitations.js @@ -76,7 +76,7 @@ export function setup() { console.error("Failed to bootstrap issuers."); } - return bearerToken, issuers, holders; + return { bearerToken, issuers, holders }; } function getIssuerIndex(vu, iter) { diff --git a/scripts/k6/scenarios/create-issuers.js b/scripts/k6/scenarios/create-issuers.js index cd705d9f6..c31f969f5 100644 --- a/scripts/k6/scenarios/create-issuers.js +++ b/scripts/k6/scenarios/create-issuers.js @@ -23,8 +23,8 @@ export const options = { scenarios: { default: { executor: "per-vu-iterations", - vus, - iterations, + vus: vus, + iterations: iterations, maxDuration: "24h", }, }, @@ -66,7 +66,7 @@ const wallets = new SharedArray("wallets", () => { export function setup() { const bearerToken = getBearerToken(); file.writeString(outputFilepath, ""); - return bearerToken; + return { bearerToken }; } const iterationsPerVU = options.scenarios.default.iterations; diff --git a/scripts/k6/scenarios/create-schemas.js b/scripts/k6/scenarios/create-schemas.js index f998dfe8c..493df888d 100644 --- a/scripts/k6/scenarios/create-schemas.js +++ b/scripts/k6/scenarios/create-schemas.js @@ -56,7 +56,7 @@ const schemas = new SharedArray("schemas", () => { export function setup() { file.writeString(outputFilepath, ""); const governanceBearerToken = getGovernanceBearerToken(); - return governanceBearerToken; // eslint-disable-line no-eval + return { governanceBearerToken }; // eslint-disable-line no-eval } const iterationsPerVU = options.scenarios.default.iterations; @@ -95,23 +95,20 @@ export default function (data) { schema.schemaName, schema.schemaVersion ); - - function isSchemaValid(response) { - if (response.status !== 200 || response.body === "[]") { - return false; - } - - try { - const schemaData = JSON.parse(response.body); - return schemaData.length > 0 && schemaData[0].id != null; - } catch (e) { - console.error("Failed to parse schema data:", e); - return false; - } - } - check(getSchemaResponse, { - "getSchema check passes": (r) => isSchemaValid(r), + "getSchema check passes": (r) => { + if (r.status !== 200 || r.body === "[]") { + return false; + } + + try { + const schemaData = JSON.parse(r.body); + return schemaData.length > 0 && schemaData[0].id != null; + } catch (e) { + console.error("Failed to parse schema data:", e); + return false; + } + }, }); const { id: schemaId } = JSON.parse(getSchemaResponse.body)[0]; diff --git a/scripts/k6/scenarios/delete-holders.js b/scripts/k6/scenarios/delete-holders.js index 4660ff755..12c08176f 100644 --- a/scripts/k6/scenarios/delete-holders.js +++ b/scripts/k6/scenarios/delete-holders.js @@ -60,7 +60,7 @@ const filepath = "output/create-holders.json"; export function setup() { const bearerToken = getBearerToken(); - return bearerToken; + return { bearerToken }; } const iterationsPerVU = options.scenarios.default.iterations; From 468b3c54bbcfbddbad99683e7bc903d805600665 Mon Sep 17 00:00:00 2001 From: ff137 Date: Thu, 10 Oct 2024 14:55:19 +0300 Subject: [PATCH 2/3] :art: reduce arrow function complexity --- scripts/k6/scenarios/create-schemas.js | 29 ++++++++++++++------------ 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/scripts/k6/scenarios/create-schemas.js b/scripts/k6/scenarios/create-schemas.js index 493df888d..770c56a6a 100644 --- a/scripts/k6/scenarios/create-schemas.js +++ b/scripts/k6/scenarios/create-schemas.js @@ -95,20 +95,23 @@ export default function (data) { schema.schemaName, schema.schemaVersion ); - check(getSchemaResponse, { - "getSchema check passes": (r) => { - if (r.status !== 200 || r.body === "[]") { - return false; - } - try { - const schemaData = JSON.parse(r.body); - return schemaData.length > 0 && schemaData[0].id != null; - } catch (e) { - console.error("Failed to parse schema data:", e); - return false; - } - }, + function isSchemaValid(response) { + if (response.status !== 200 || response.body === "[]") { + return false; + } + + try { + const schemaData = JSON.parse(response.body); + return schemaData.length > 0 && schemaData[0].id != null; + } catch (e) { + console.error("Failed to parse schema data:", e); + return false; + } + } + + check(getSchemaResponse, { + "getSchema check passes": (r) => isSchemaValid(r), }); const { id: schemaId } = JSON.parse(getSchemaResponse.body)[0]; From 198e1f2df6d4dc19b43a641d1bd680c002fdad2f Mon Sep 17 00:00:00 2001 From: ff137 Date: Thu, 10 Oct 2024 14:54:57 +0300 Subject: [PATCH 3/3] :art: use property shorthand --- scripts/k6/scenarios/create-issuers.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/k6/scenarios/create-issuers.js b/scripts/k6/scenarios/create-issuers.js index c31f969f5..991bde5bc 100644 --- a/scripts/k6/scenarios/create-issuers.js +++ b/scripts/k6/scenarios/create-issuers.js @@ -23,8 +23,8 @@ export const options = { scenarios: { default: { executor: "per-vu-iterations", - vus: vus, - iterations: iterations, + vus, + iterations, maxDuration: "24h", }, },