optimized create_n_users bench and ignore out.json
This commit is contained in:
parent
7b13439ea0
commit
1cb747f3ee
|
@ -3,5 +3,6 @@ node_modules
|
|||
bench/metrics.csv
|
||||
*.pem*
|
||||
*.pks*
|
||||
*out.json*
|
||||
.env
|
||||
test-ledger
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Connection, Keypair, LAMPORTS_PER_SOL, PublicKey } from '@solana/web3.js';
|
||||
import * as fs from 'fs';
|
||||
import { Connection, Keypair } from '@solana/web3.js';
|
||||
import * as splToken from "@solana/spl-token";
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
|
||||
// number of users
|
||||
|
@ -9,45 +9,42 @@ const nbUsers = +process.argv[2];
|
|||
const url = process.argv.length > 3 ? process.argv[3] : "http://0.0.0.0:8899";
|
||||
// outfile
|
||||
const outFile = process.argv.length > 4 ? process.argv[4] : "out.json";
|
||||
|
||||
console.log("creating " + nbUsers + " Users on " + url + " out file " + outFile);
|
||||
function delay(ms: number) {
|
||||
return new Promise( resolve => setTimeout(resolve, ms) );
|
||||
}
|
||||
export async function main() {
|
||||
const connection = new Connection(url, 'confirmed');
|
||||
let authority = Keypair.fromSecretKey(
|
||||
Uint8Array.from(
|
||||
JSON.parse(
|
||||
process.env.KEYPAIR ||
|
||||
fs.readFileSync(os.homedir() + '/.config/solana/id.json', 'utf-8'),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
let userKps = [...Array(nbUsers)].map(_x => Keypair.generate())
|
||||
let mint = await splToken.createMint(
|
||||
(async function main() {
|
||||
console.log("Creating " + nbUsers + " Users on " + url + " out file " + outFile);
|
||||
console.time('Time taken');
|
||||
|
||||
const connection = new Connection(url, 'confirmed');
|
||||
|
||||
const authority = Keypair.fromSecretKey(
|
||||
Uint8Array.from(
|
||||
JSON.parse(
|
||||
process.env.KEYPAIR ||
|
||||
fs.readFileSync(os.homedir() + '/.config/solana/id.json', 'utf-8'),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
const userKps = Array(nbUsers).fill(0).map(() => Keypair.generate());
|
||||
|
||||
const mint = await splToken.createMint(
|
||||
connection,
|
||||
authority,
|
||||
authority.publicKey,
|
||||
null,
|
||||
6,
|
||||
);
|
||||
let accounts : PublicKey[] = [];
|
||||
for (const user of userKps) {
|
||||
console.log("account created");
|
||||
let account = await splToken.createAccount(
|
||||
|
||||
const accounts = await Promise.all(userKps.map(async user => {
|
||||
const account = await splToken.createAccount(
|
||||
connection,
|
||||
authority,
|
||||
mint,
|
||||
user.publicKey,
|
||||
)
|
||||
accounts.push(account)
|
||||
await delay(100)
|
||||
};
|
||||
);
|
||||
|
||||
console.log("Account created");
|
||||
|
||||
for (const account of accounts) {
|
||||
console.log("account minted");
|
||||
await splToken.mintTo(
|
||||
connection,
|
||||
authority,
|
||||
|
@ -56,30 +53,27 @@ export async function main() {
|
|||
authority,
|
||||
1_000_000_000_000,
|
||||
)
|
||||
await delay(100)
|
||||
};
|
||||
|
||||
const users = userKps.map(x => {
|
||||
const info = {
|
||||
'publicKey' : x.publicKey.toBase58(),
|
||||
'secretKey' : Array.from(x.secretKey)
|
||||
};
|
||||
return info;
|
||||
});
|
||||
console.log("Account minted");
|
||||
|
||||
return account;
|
||||
}));
|
||||
|
||||
console.timeLog('Time taken');
|
||||
|
||||
const users = userKps.map(x => ({
|
||||
'publicKey': x.publicKey.toBase58(),
|
||||
'secretKey': Array.from(x.secretKey)
|
||||
}));
|
||||
|
||||
const data = {
|
||||
'users' : users,
|
||||
'tokenAccounts' : accounts,
|
||||
'mint' : mint,
|
||||
'minted_amount' : 1_000_000_000_000
|
||||
'users': users,
|
||||
'tokenAccounts': accounts,
|
||||
'mint': mint,
|
||||
'minted_amount': 1_000_000_000_000
|
||||
};
|
||||
|
||||
console.log('created ' + nbUsers + ' Users and minted 10^12 tokens for mint ' + mint);
|
||||
fs.writeFileSync(outFile, JSON.stringify(data));
|
||||
}
|
||||
|
||||
main().then(x => {
|
||||
console.log('finished sucessfully')
|
||||
}).catch(e => {
|
||||
console.log('caught an error : ' + e)
|
||||
})
|
||||
fs.writeFileSync(outFile, JSON.stringify(data));
|
||||
})()
|
||||
|
|
Loading…
Reference in New Issue