Skip to content

Commit

Permalink
Add ContractCall mode (#10778)
Browse files Browse the repository at this point in the history
Based on @eelanagaraj's PR
https://github.com/celo-org/celo-monorepo/pull/10354/files

New mode that simulates contract calls.
Additionally:
- cleans up some obsolete code
- provides additional informational context for the --client-count parameter
- refactors the simulateClient method and extracts some shared parameters of
  the load test from the main loop
  • Loading branch information
Valentin Rodygin authored Nov 23, 2023
1 parent 70f600b commit 06768e2
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 92 deletions.
59 changes: 50 additions & 9 deletions packages/celotool/src/cmds/geth/simulate_client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
/* tslint:disable no-console */
import { AccountType, generateAddress } from 'src/lib/generate_utils'
import { getIndexForLoadTestThread, simulateClient, TestMode } from 'src/lib/geth'
import BigNumber from 'bignumber.js'
import { AccountType, generateAddress, generatePrivateKey } from 'src/lib/generate_utils'
import {
getIndexForLoadTestThread,
MAX_LOADTEST_THREAD_COUNT,
simulateClient,
TestMode,
} from 'src/lib/geth'
import * as yargs from 'yargs'
export const command = 'simulate-client'

Expand All @@ -13,8 +19,12 @@ interface SimulateClientArgv extends yargs.Argv {
index: number
mnemonic: string
recipientIndex: number
contractAddress: string
contractData: string
clientCount: number
reuseClient: boolean
maxGasPrice: number
totalTxGas: number
testMode: string
}

Expand Down Expand Up @@ -47,26 +57,53 @@ export const builder = () => {
'Index of the load test account to send transactions to. Used to generate account address',
default: 0,
})
.options('contract-address', {
type: 'string',
description: `Contract Address to send to when using test mode: ${TestMode.ContractCall}`,
default: '',
})
.options('contract-data', {
type: 'string',
description: `Data to send to when using test mode: ${TestMode.ContractCall}`,
default: '',
})
.options('mnemonic', {
type: 'string',
description: 'Mnemonic used to generate account addresses',
demand: 'A mnemonic must be provided',
})
.options('client-count', {
type: 'number',
description: 'Number of clients to simulate',
description: `Number of clients to simulate, must not exceed ${MAX_LOADTEST_THREAD_COUNT}`,
default: 1,
})
.check((argv) => argv['client-count'] <= MAX_LOADTEST_THREAD_COUNT)
.options('reuse-client', {
type: 'boolean',
description: 'Use the same client for all the threads/accounts',
default: false,
})
.options('max-gas-price', {
type: 'number',
description: 'Max gasPrice to use for transactions',
default: 0,
})
.options('total-tx-gas', {
type: 'number',
description: 'Gas Target when using data transfers',
default: 500000,
})
.options('test-mode', {
type: 'string',
description:
'Load test mode: mixed transaction types, big calldatas, simple transfers paid in CELO or transfers paid in cUSD',
choices: [TestMode.Mixed, TestMode.Data, TestMode.Transfer, TestMode.StableTransfer],
'Load test mode: mixed transaction types, big calldatas, simple transfers paid in CELO, transfers paid in cUSD, or contract calls',
choices: [
TestMode.Mixed,
TestMode.Data,
TestMode.Transfer,
TestMode.StableTransfer,
TestMode.ContractCall,
],
default: TestMode.Mixed,
})
}
Expand All @@ -75,7 +112,7 @@ export const handler = async (argv: SimulateClientArgv) => {
for (let thread = 0; thread < argv.clientCount; thread++) {
const senderIndex = getIndexForLoadTestThread(argv.index, thread)
const recipientIndex = getIndexForLoadTestThread(argv.recipientIndex, thread)
const senderAddress = generateAddress(
const senderPK = generatePrivateKey(
argv.mnemonic,
AccountType.LOAD_TESTING_ACCOUNT,
senderIndex
Expand All @@ -89,7 +126,7 @@ export const handler = async (argv: SimulateClientArgv) => {
const web3ProviderPort = argv.reuseClient ? 8545 : 8545 + thread

console.log(
`Account for sender index ${argv.index} thread ${thread}, final index ${senderIndex}: ${senderAddress}`
`PK for sender index ${argv.index} thread ${thread}, final index ${senderIndex}: ${senderPK}`
)
console.log(
`Account for recipient index ${argv.recipientIndex} thread ${thread}, final index ${recipientIndex}: ${recipientAddress}`
Expand All @@ -98,15 +135,19 @@ export const handler = async (argv: SimulateClientArgv) => {

// tslint:disable-next-line: no-floating-promises
simulateClient(
senderAddress,
senderPK,
recipientAddress,
argv.contractAddress,
argv.contractData,
argv.delay,
argv.blockscoutUrl,
argv.blockscoutMeasurePercent,
argv.index,
argv.testMode as TestMode,
thread,
`http://localhost:${web3ProviderPort}`
new BigNumber(argv.maxGasPrice),
argv.totalTxGas,
`http://127.0.0.1:${web3ProviderPort}`
)
}
}
Loading

0 comments on commit 06768e2

Please sign in to comment.