Skip to content

Commit

Permalink
Fix getWalletIndex function (#1074)
Browse files Browse the repository at this point in the history
  • Loading branch information
wdbasson authored Sep 27, 2024
1 parent 3884838 commit 53e2155
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
6 changes: 4 additions & 2 deletions scripts/k6/libs/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import sse from "k6/x/sse";
// let customDuration = new Trend('custom_duration', true);

// Helper function to generate a unique, zero-based index for even distribution of operations
export function getWalletIndex(vu, iter) {
return (vu - 1) * (iter + 1) + iter;
export function getWalletIndex(vu, iter, iterationsPerVu) {
return (vu - 1) * iterationsPerVu + iter;
}

function logError(response, requestBody) {
Expand Down Expand Up @@ -458,6 +458,7 @@ export function getProofIdByThreadId(holderAccessToken, threadId) {
// Check if the current object has a matching thread_id
if (obj.thread_id === threadId) {
// Return the credential_id if a match is found
// console.log(`Log of the request made: ${JSON.stringify(response.request)}`);
return obj.proof_id;
}
}
Expand Down Expand Up @@ -494,6 +495,7 @@ export function getProofIdCredentials(holderAccessToken, proofId) {
return referent;
}
// Throw an error if no match is found
console.log(`Log of the request made: ${JSON.stringify(response.request)}`);
throw new Error(`No match found for proofId: ${proofId}\nResponse body: ${JSON.stringify(responseData, null, 2)}`);
} catch (error) {
console.error("Error in getProofIdCredentials:", error);
Expand Down
4 changes: 3 additions & 1 deletion scripts/k6/scenarios/create-credentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function setup() {
export default function (data) {
const bearerToken = data.bearerToken;
const holders = data.holders;
const walletIndex = getWalletIndex(__VU, __ITER);
const walletIndex = getWalletIndex(__VU, __ITER, iterations);
const wallet = holders[walletIndex];

// console.log(`VU: ${__VU}, Iteration: ${__ITER}, Wallet Index: ${walletIndex}, Issuer Wallet ID: ${wallet.issuer_wallet_id}`);
Expand Down Expand Up @@ -128,6 +128,8 @@ export default function (data) {
},
});

// sleep(1);

const credentialId = getCredentialIdByThreadId(wallet.access_token, threadId);

const acceptCredentialResponse = acceptCredential(wallet.access_token, credentialId);
Expand Down
4 changes: 3 additions & 1 deletion scripts/k6/scenarios/create-invitations.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ export default function (data) {
const start = Date.now();
const bearerToken = data.bearerToken;
const issuers = data.issuers;
const walletIndex = getWalletIndex(__VU, __ITER);
const walletIndex = getWalletIndex(__VU, __ITER, iterations);

// console.log(`VU: ${__VU}, Iteration: ${__ITER}, Wallet Index: ${walletIndex}`);

const holders = data.holders;
const wallet = holders[walletIndex];
Expand Down
5 changes: 3 additions & 2 deletions scripts/k6/scenarios/create-proof.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global __ENV, __ITER, __VU */
/* eslint-disable no-undefined, no-console, camelcase */

import { check } from "k6";
import { check, sleep } from "k6";
import { Counter } from "k6/metrics";
import { getBearerToken } from "../libs/auth.js";
import {
Expand Down Expand Up @@ -71,7 +71,7 @@ export function setup() {
export default function (data) {
const bearerToken = data.bearerToken;
const tenants = data.tenants;
const walletIndex = getWalletIndex(__VU, __ITER);
const walletIndex = getWalletIndex(__VU, __ITER, iterations);
const wallet = tenants[walletIndex];

// console.log(`wallet.issuer_connection_id: ${wallet.issuer_connection_id}`);
Expand Down Expand Up @@ -117,6 +117,7 @@ export default function (data) {

// TODO: return object and add check for the response
const proofId = getProofIdByThreadId(wallet.access_token, threadId);
// console.log(`Proof ID: ${proofId}`);
const referent = getProofIdCredentials(wallet.access_token, proofId);

const acceptProofResponse = acceptProofRequest(wallet.access_token, proofId, referent);
Expand Down
2 changes: 1 addition & 1 deletion scripts/k6/scenarios/revoke-credentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function setup() {

export default function (data) {
const tenants = data.tenants;
const walletIndex = getWalletIndex(__VU, __ITER);
const walletIndex = getWalletIndex(__VU, __ITER, iterations);
const wallet = tenants[walletIndex];

const revokeCredentialResponse = revokeCredentialAutoPublish(wallet.issuer_access_token, wallet.credential_exchange_id);
Expand Down

0 comments on commit 53e2155

Please sign in to comment.