Repository navigation
Expand file tree
/
Copy pathbenchmark.js
More file actions
executable file
·115 lines (97 loc) · 2.89 KB
/
Copy pathbenchmark.js
File metadata and controls
executable file
·115 lines (97 loc) · 2.89 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable no-undef */
import http from 'k6/http';
import { check } from 'k6';
import { uuidv4 } from 'https://jslib.k6.io/k6-utils/1.4.0/index.js';
import { sleep } from 'k6';
export const options = {
scenarios: {
contacts: {
executor: 'ramping-vus',
startVUs: 0,
stages: [
{ duration: '15s', target: 500 },
{ duration: '15s', target: 500 },
{ duration: '15s', target: 0 }
]
}
}
};
const ADMIN_API_URL = 'http://localhost:3001';
const RECEIVER_PATH_NAME = 'receiver';
const SENDER_PATH_NAME = 'sender';
function request(url, data) {
return http.post(url, JSON.stringify(data), {
headers: {
'Content-Type': 'application/json'
}
});
}
export function setup() {
const assetRes = request(`${ADMIN_API_URL}/assets`, {
code: 'USD',
scale: 2
});
// 409 already exists OK for reruns
check(assetRes, {
'asset created or exists': (r) => r.status === 201 || r.status === 409
});
const receiverRes = request(`${ADMIN_API_URL}/wallet-addresses`, {
pathName: RECEIVER_PATH_NAME,
publicName: 'Receiver',
assetCode: 'USD'
});
check(receiverRes, {
'receiver wallet created or exists': (r) =>
r.status === 201 || r.status === 409
});
const receiver = JSON.parse(receiverRes.body);
const senderRes = request(`${ADMIN_API_URL}/wallet-addresses`, {
pathName: SENDER_PATH_NAME,
publicName: 'Sender',
assetCode: 'USD'
});
check(senderRes, {
'sender wallet created or exists': (r) =>
r.status === 201 || r.status === 409
});
const sender = JSON.parse(senderRes.body);
return {
receiverWalletAddress: receiver.address,
senderWalletAddress: sender.address
};
}
export default function (data) {
const paymentIntentId = uuidv4();
const paymentIntentRes = request(`${ADMIN_API_URL}/payment-intents`, {
id: paymentIntentId,
walletAddress: data.receiverWalletAddress
});
console.log(`payment intent response: ${paymentIntentRes.body}`);
check(paymentIntentRes, {
'payment intent created': (r) => r.status === 201,
'payment intent id matches': (r) =>
JSON.parse(r.body).id === paymentIntentId
});
const quoteRes = request(`${ADMIN_API_URL}/quotes`, {
walletAddress: data.senderWalletAddress,
paymentIntentId,
debitAmount: '100'
});
console.log(`quote response: ${quoteRes.body}`);
check(quoteRes, {
'quote created': (r) => r.status === 201
});
const quoteBody = JSON.parse(quoteRes.body);
const quoteId = quoteBody.id;
const quotePaymentIntentId = quoteBody.paymentIntentId;
const paymentRes = request(`${ADMIN_API_URL}/payments`, {
walletAddress: data.senderWalletAddress,
paymentIntentId: quotePaymentIntentId,
quoteId
});
console.log(`payment response: ${paymentRes.body}`);
check(paymentRes, {
'payment created': (r) => r.status === 201
});
}