Skip to content

Commit 06768e2

Browse files
author
Valentin Rodygin
authored
Add ContractCall mode (#10778)
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
1 parent 70f600b commit 06768e2

File tree

2 files changed

+148
-92
lines changed

2 files changed

+148
-92
lines changed

packages/celotool/src/cmds/geth/simulate_client.ts

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
/* tslint:disable no-console */
2-
import { AccountType, generateAddress } from 'src/lib/generate_utils'
3-
import { getIndexForLoadTestThread, simulateClient, TestMode } from 'src/lib/geth'
2+
import BigNumber from 'bignumber.js'
3+
import { AccountType, generateAddress, generatePrivateKey } from 'src/lib/generate_utils'
4+
import {
5+
getIndexForLoadTestThread,
6+
MAX_LOADTEST_THREAD_COUNT,
7+
simulateClient,
8+
TestMode,
9+
} from 'src/lib/geth'
410
import * as yargs from 'yargs'
511
export const command = 'simulate-client'
612

@@ -13,8 +19,12 @@ interface SimulateClientArgv extends yargs.Argv {
1319
index: number
1420
mnemonic: string
1521
recipientIndex: number
22+
contractAddress: string
23+
contractData: string
1624
clientCount: number
1725
reuseClient: boolean
26+
maxGasPrice: number
27+
totalTxGas: number
1828
testMode: string
1929
}
2030

@@ -47,26 +57,53 @@ export const builder = () => {
4757
'Index of the load test account to send transactions to. Used to generate account address',
4858
default: 0,
4959
})
60+
.options('contract-address', {
61+
type: 'string',
62+
description: `Contract Address to send to when using test mode: ${TestMode.ContractCall}`,
63+
default: '',
64+
})
65+
.options('contract-data', {
66+
type: 'string',
67+
description: `Data to send to when using test mode: ${TestMode.ContractCall}`,
68+
default: '',
69+
})
5070
.options('mnemonic', {
5171
type: 'string',
5272
description: 'Mnemonic used to generate account addresses',
5373
demand: 'A mnemonic must be provided',
5474
})
5575
.options('client-count', {
5676
type: 'number',
57-
description: 'Number of clients to simulate',
77+
description: `Number of clients to simulate, must not exceed ${MAX_LOADTEST_THREAD_COUNT}`,
5878
default: 1,
5979
})
80+
.check((argv) => argv['client-count'] <= MAX_LOADTEST_THREAD_COUNT)
6081
.options('reuse-client', {
6182
type: 'boolean',
6283
description: 'Use the same client for all the threads/accounts',
6384
default: false,
6485
})
86+
.options('max-gas-price', {
87+
type: 'number',
88+
description: 'Max gasPrice to use for transactions',
89+
default: 0,
90+
})
91+
.options('total-tx-gas', {
92+
type: 'number',
93+
description: 'Gas Target when using data transfers',
94+
default: 500000,
95+
})
6596
.options('test-mode', {
6697
type: 'string',
6798
description:
68-
'Load test mode: mixed transaction types, big calldatas, simple transfers paid in CELO or transfers paid in cUSD',
69-
choices: [TestMode.Mixed, TestMode.Data, TestMode.Transfer, TestMode.StableTransfer],
99+
'Load test mode: mixed transaction types, big calldatas, simple transfers paid in CELO, transfers paid in cUSD, or contract calls',
100+
choices: [
101+
TestMode.Mixed,
102+
TestMode.Data,
103+
TestMode.Transfer,
104+
TestMode.StableTransfer,
105+
TestMode.ContractCall,
106+
],
70107
default: TestMode.Mixed,
71108
})
72109
}
@@ -75,7 +112,7 @@ export const handler = async (argv: SimulateClientArgv) => {
75112
for (let thread = 0; thread < argv.clientCount; thread++) {
76113
const senderIndex = getIndexForLoadTestThread(argv.index, thread)
77114
const recipientIndex = getIndexForLoadTestThread(argv.recipientIndex, thread)
78-
const senderAddress = generateAddress(
115+
const senderPK = generatePrivateKey(
79116
argv.mnemonic,
80117
AccountType.LOAD_TESTING_ACCOUNT,
81118
senderIndex
@@ -89,7 +126,7 @@ export const handler = async (argv: SimulateClientArgv) => {
89126
const web3ProviderPort = argv.reuseClient ? 8545 : 8545 + thread
90127

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

99136
// tslint:disable-next-line: no-floating-promises
100137
simulateClient(
101-
senderAddress,
138+
senderPK,
102139
recipientAddress,
140+
argv.contractAddress,
141+
argv.contractData,
103142
argv.delay,
104143
argv.blockscoutUrl,
105144
argv.blockscoutMeasurePercent,
106145
argv.index,
107146
argv.testMode as TestMode,
108147
thread,
109-
`http://localhost:${web3ProviderPort}`
148+
new BigNumber(argv.maxGasPrice),
149+
argv.totalTxGas,
150+
`http://127.0.0.1:${web3ProviderPort}`
110151
)
111152
}
112153
}

0 commit comments

Comments
 (0)