1
1
/* 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'
4
10
import * as yargs from 'yargs'
5
11
export const command = 'simulate-client'
6
12
@@ -13,8 +19,12 @@ interface SimulateClientArgv extends yargs.Argv {
13
19
index : number
14
20
mnemonic : string
15
21
recipientIndex : number
22
+ contractAddress : string
23
+ contractData : string
16
24
clientCount : number
17
25
reuseClient : boolean
26
+ maxGasPrice : number
27
+ totalTxGas : number
18
28
testMode : string
19
29
}
20
30
@@ -47,26 +57,53 @@ export const builder = () => {
47
57
'Index of the load test account to send transactions to. Used to generate account address' ,
48
58
default : 0 ,
49
59
} )
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
+ } )
50
70
. options ( 'mnemonic' , {
51
71
type : 'string' ,
52
72
description : 'Mnemonic used to generate account addresses' ,
53
73
demand : 'A mnemonic must be provided' ,
54
74
} )
55
75
. options ( 'client-count' , {
56
76
type : 'number' ,
57
- description : ' Number of clients to simulate' ,
77
+ description : ` Number of clients to simulate, must not exceed ${ MAX_LOADTEST_THREAD_COUNT } ` ,
58
78
default : 1 ,
59
79
} )
80
+ . check ( ( argv ) => argv [ 'client-count' ] <= MAX_LOADTEST_THREAD_COUNT )
60
81
. options ( 'reuse-client' , {
61
82
type : 'boolean' ,
62
83
description : 'Use the same client for all the threads/accounts' ,
63
84
default : false ,
64
85
} )
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
+ } )
65
96
. options ( 'test-mode' , {
66
97
type : 'string' ,
67
98
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
+ ] ,
70
107
default : TestMode . Mixed ,
71
108
} )
72
109
}
@@ -75,7 +112,7 @@ export const handler = async (argv: SimulateClientArgv) => {
75
112
for ( let thread = 0 ; thread < argv . clientCount ; thread ++ ) {
76
113
const senderIndex = getIndexForLoadTestThread ( argv . index , thread )
77
114
const recipientIndex = getIndexForLoadTestThread ( argv . recipientIndex , thread )
78
- const senderAddress = generateAddress (
115
+ const senderPK = generatePrivateKey (
79
116
argv . mnemonic ,
80
117
AccountType . LOAD_TESTING_ACCOUNT ,
81
118
senderIndex
@@ -89,7 +126,7 @@ export const handler = async (argv: SimulateClientArgv) => {
89
126
const web3ProviderPort = argv . reuseClient ? 8545 : 8545 + thread
90
127
91
128
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 } `
93
130
)
94
131
console . log (
95
132
`Account for recipient index ${ argv . recipientIndex } thread ${ thread } , final index ${ recipientIndex } : ${ recipientAddress } `
@@ -98,15 +135,19 @@ export const handler = async (argv: SimulateClientArgv) => {
98
135
99
136
// tslint:disable-next-line: no-floating-promises
100
137
simulateClient (
101
- senderAddress ,
138
+ senderPK ,
102
139
recipientAddress ,
140
+ argv . contractAddress ,
141
+ argv . contractData ,
103
142
argv . delay ,
104
143
argv . blockscoutUrl ,
105
144
argv . blockscoutMeasurePercent ,
106
145
argv . index ,
107
146
argv . testMode as TestMode ,
108
147
thread ,
109
- `http://localhost:${ web3ProviderPort } `
148
+ new BigNumber ( argv . maxGasPrice ) ,
149
+ argv . totalTxGas ,
150
+ `http://127.0.0.1:${ web3ProviderPort } `
110
151
)
111
152
}
112
153
}
0 commit comments