-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoken_holding.ts
52 lines (45 loc) · 1.67 KB
/
token_holding.ts
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
/**
* Sample request generator usage.
* Contributed by jjohnsonvng:
* https://github.com/alexfernandez/loadtest/issues/86#issuecomment-211579639
*/
import "dotenv/config";
import loadtest from "loadtest";
import { addresses } from "./address";
const RPS = Number(process.env.RPS) || 10;
const DURATION = Number(process.env.DURATION) || 120;
const getRandomAddress = () =>
addresses[Math.floor(Math.random() * addresses.length)];
const options: loadtest.LoadTestOptions = {
url: "https://api.getnimbus.io/v2/address/0x692853c81afc8f847147c8a8b4368dc894697fc12b929ef3071482d27339815e/holding?chain=SUI&force_refresh=false&includePnl=false",
concurrency: Math.min(10, RPS / 20),
method: "GET",
agentKeepAlive: true,
requestsPerSecond: RPS,
maxSeconds: DURATION,
requestGenerator: (params, options, client, callback) => {
const address = getRandomAddress();
options.href = `${options.url}${address}/holding?includePnl=false&chain=SUI`;
options.search = `?chain=SUI&includePnl=false`;
options.query = `chain=SUI&includePnl=false`;
options.path = `/v2/address/${address}/holding?includePnl=false&chain=SUI`;
options.headers["x-api-key"] = process.env.API_KEY;
options.headers["Content-Type"] = "application/json";
// const cb = (a) => {
// if (a.statusCode !== 200) {
// console.log(address)
// }
// callback(a)
// }
const request = client(options, callback);
return request;
},
};
loadtest.loadTest(options, (error, result) => {
if (error) {
return console.error(`Got an error: ${error}`);
}
// const { histogramMs, ...rest } = result
// console.log("Tests run successfully", {rest})
result.show();
});