forked from Monadical-SAS/rpc-cache-server
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtest-client.js
47 lines (44 loc) · 1.37 KB
/
test-client.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
const {JSONRPCClient} = require("json-rpc-2.0");
const axios = require("axios");
// JSONRPCClient needs to know how to send a JSON-RPC request.
// Tell it by passing a function to its constructor. The function must take a JSON-RPC request and send it.
const client = new JSONRPCClient((jsonRPCRequest) =>
axios({
method: "post",
url: "http://rpc-c-Reade-XI5DWSROAOTQ-1591340619.us-east-2.elb.amazonaws.com",
//url: "http://localhost:3001/json-rpc",
headers: {
"content-type": "application/json",
},
data: jsonRPCRequest,
}).then((response) => {
if (response.status === 200) {
// Use client.receive when you received a JSON-RPC response.
return client.receive(response.data);
} else if (jsonRPCRequest.id !== undefined) {
return Promise.reject(new Error(response.statusText));
}
})
);
const filters = [
{
dataSize: 34,
},
];
const params = {
commitment: 'recent',
encoding: 'base64',
filters,
};
(async ()=> {
const cacheStart = new Date();
let res = null;
for (let i =0; i<100; i++) {
res = await client.request("getProgramAccounts", ["WormT3McKhFJ2RkiGpdw9GKvNCrB2aB54gb2uV9MfQC", params])
}
const cacheEnd = new Date();
console.log(
// @ts-ignore
`Cache's elapsed time: ${cacheEnd - cacheStart}, results: ${res.length}`
);
})();