Skip to content

Commit f5d9e3f

Browse files
authored
Merge pull request #562 from interlay/faucet-load-test
feat(scripts): faucet load test
2 parents 33b049b + d246232 commit f5d9e3f

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

scripts/load-test-faucet.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
import { Kintsugi } from '@interlay/monetary-js';
3+
import { Keyring } from '@polkadot/api';
4+
import { createSubstrateAPI, FaucetClient } from '../src';
5+
6+
const PARACHAIN_ENDPOINT = "wss://api-kusama.interlay.io/parachain";
7+
const FAUCET_URL = "http://localhost:3033";
8+
9+
// The script throws an error but does what it should
10+
main().catch((err) => {
11+
console.log("Error thrown by script:");
12+
console.log(err);
13+
});
14+
15+
/**
16+
* Flood the faucet with `users` requests to see if it breaks
17+
*/
18+
async function main() {
19+
const keyring = new Keyring({ type: "sr25519" });
20+
const api = await createSubstrateAPI(PARACHAIN_ENDPOINT);
21+
const faucet = new FaucetClient(api, FAUCET_URL);
22+
const salt = Math.random().toString();
23+
const users = 100;
24+
const promises = [];
25+
for (let i = 0; i < users; i++) {
26+
const account = keyring.addFromUri(`//${salt + i.toString()}`);
27+
console.log(account.address);
28+
const accountId = api.createType("AccountId", account.address);
29+
promises.push(
30+
faucet.fundAccount(accountId, Kintsugi)
31+
);
32+
}
33+
console.log(`Making ${users} simulatenous faucet requests...`);
34+
await Promise.all(promises);
35+
console.log("Finished");
36+
}

0 commit comments

Comments
 (0)