Skip to content

Add ContractCall mode #10778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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