Last active
September 13, 2019 23:12
-
-
Save vgrichina/2f039ddffbc6eda844d1a75d6c17455e to your computer and use it in GitHub Desktop.
load testing nearcore payments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const nearlib = require('nearlib'); | |
const { signTransaction, transfer } = nearlib.transactions; | |
const { base_decode } = nearlib.utils.serialize; | |
const sleep = (ms) => new Promise((resolved) => setTimeout(resolved, ms)); | |
(async () => { | |
const [,, accountId, txCount] = process.argv; | |
const near = await nearlib.connect({...require('near-shell/get-config')(), deps: { keyStore: new nearlib.keyStores.UnencryptedFileSystemKeyStore('./neardev') } }); | |
const account = await near.account(accountId); | |
const status = await account.connection.provider.status(); | |
let nonce = account._accessKey.nonce; | |
let transactions = []; | |
for (let i = 0; i < parseInt(txCount); i++) { | |
nonce++; | |
const actions = [transfer(1)]; | |
const [txHash, signedTx] = await signTransaction( | |
accountId, nonce, actions, base_decode(status.sync_info.latest_block_hash), account.connection.signer, account.accountId, account.connection.networkId | |
); | |
transactions.push(signedTx); | |
} | |
console.log('txs', await Promise.all(transactions.map(async (signedTx, i) => { | |
try { | |
await sleep(i); | |
return await account.connection.provider.sendTransaction(signedTx) | |
} catch (e) { | |
console.log('Error: ', e); | |
return null; | |
} | |
}))); | |
})().then(console.log); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"near-shell": "^0.10.5", | |
"nearlib": "^0.13.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use like: