-
Notifications
You must be signed in to change notification settings - Fork 0
/
k6.test.js
92 lines (86 loc) · 2.91 KB
/
k6.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import http from "k6/http";
import {
describe,
expect,
} from "https://jslib.k6.io/k6chaijs/4.3.4.3/index.js";
import { sleep } from "k6";
export const options = {
vus: 1000,
duration: "10s",
};
export default function () {
describe("Transfers", () => {
const randomUserACreateResponse = http.post(
"http://localhost:5001/accounts/create"
);
const randomUserBCreateResponse = http.post(
"http://localhost:5001/accounts/create"
);
const randomUserA = JSON.parse(randomUserACreateResponse.body);
const randomUserB = JSON.parse(randomUserBCreateResponse.body);
if (
typeof randomUserA === "object" &&
randomUserA !== null &&
typeof randomUserB === "object" &&
randomUserB !== null
) {
const { accountId } = randomUserA;
if (accountId) {
const senderAccountId = accountId;
const noncePayload = JSON.stringify({ accountId: senderAccountId });
const nonceResponse = http.post(
"http://localhost:5001/accounts/get-nonce",
noncePayload,
{
headers: { "Content-Type": "application/json" },
}
);
const nonceDetails = JSON.parse(nonceResponse.body);
if (typeof nonceDetails === "object" && nonceDetails !== null) {
const { nonce } = nonceDetails;
if (nonce) {
const getSignedTransactionPayload = JSON.stringify({
senderPublicKey: randomUserA.publicKey,
recipientPublicKey: randomUserB.publicKey,
senderPrivateKey: randomUserA.privateKey,
amount: "10.37",
nonce,
});
const signedTransactionResponse = http.post(
"http://localhost:5001/accounts/get-signed-transaction",
getSignedTransactionPayload,
{
headers: { "Content-Type": "application/json" },
}
);
const transactionPayload = signedTransactionResponse.body;
const createTransferResponse = http.post(
"http://localhost:5001/accounts/create-transfer",
transactionPayload,
{
headers: { "Content-Type": "application/json" },
}
);
const transferDetails = JSON.parse(createTransferResponse.body);
if (
typeof transferDetails === "object" &&
transferDetails !== null
) {
const { transactionId } = transferDetails;
if (transactionId) {
sleep(5);
const transferCompletionResponse = http.get(
`http://localhost:5001/accounts/getTransfer/${transactionId}`
);
expect(
transferCompletionResponse.status,
"response status"
).to.equal(200);
}
}
}
}
}
}
});
}