/
keeper_helpers.go
603 lines (539 loc) · 25 KB
/
keeper_helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
package actions
import (
"fmt"
"math"
"math/big"
"strconv"
"testing"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
"github.com/smartcontractkit/chainlink-testing-framework/blockchain"
"github.com/smartcontractkit/chainlink-testing-framework/logging"
"github.com/smartcontractkit/chainlink/integration-tests/client"
"github.com/smartcontractkit/chainlink/integration-tests/contracts"
"github.com/smartcontractkit/chainlink/integration-tests/contracts/ethereum"
)
var ZeroAddress = common.Address{}
func CreateKeeperJobs(
t *testing.T,
chainlinkNodes []*client.ChainlinkK8sClient,
keeperRegistry contracts.KeeperRegistry,
ocrConfig contracts.OCRv2Config,
evmChainID string,
) {
// Send keeper jobs to registry and chainlink nodes
primaryNode := chainlinkNodes[0]
primaryNodeAddress, err := primaryNode.PrimaryEthAddress()
require.NoError(t, err, "Reading ETH Keys from Chainlink Client shouldn't fail")
nodeAddresses, err := ChainlinkNodeAddresses(chainlinkNodes)
require.NoError(t, err, "Retrieving on-chain wallet addresses for chainlink nodes shouldn't fail")
nodeAddressesStr, payees := make([]string, 0), make([]string, 0)
for _, cla := range nodeAddresses {
nodeAddressesStr = append(nodeAddressesStr, cla.Hex())
payees = append(payees, primaryNodeAddress)
}
err = keeperRegistry.SetKeepers(nodeAddressesStr, payees, ocrConfig)
require.NoError(t, err, "Setting keepers in the registry shouldn't fail")
for _, chainlinkNode := range chainlinkNodes {
chainlinkNodeAddress, err := chainlinkNode.PrimaryEthAddress()
require.NoError(t, err, "Error retrieving chainlink node address")
_, err = chainlinkNode.MustCreateJob(&client.KeeperJobSpec{
Name: fmt.Sprintf("keeper-test-%s", keeperRegistry.Address()),
ContractAddress: keeperRegistry.Address(),
FromAddress: chainlinkNodeAddress,
EVMChainID: evmChainID,
MinIncomingConfirmations: 1,
})
require.NoError(t, err, "Creating KeeperV2 Job shouldn't fail")
}
}
func CreateKeeperJobsWithKeyIndex(
t *testing.T,
chainlinkNodes []*client.ChainlinkK8sClient,
keeperRegistry contracts.KeeperRegistry,
keyIndex int,
ocrConfig contracts.OCRv2Config,
evmChainID string,
) {
// Send keeper jobs to registry and chainlink nodes
primaryNode := chainlinkNodes[0]
primaryNodeAddresses, err := primaryNode.EthAddresses()
require.NoError(t, err, "Reading ETH Keys from Chainlink Client shouldn't fail")
nodeAddresses, err := ChainlinkNodeAddressesAtIndex(chainlinkNodes, keyIndex)
require.NoError(t, err, "Retrieving on-chain wallet addresses for chainlink nodes shouldn't fail")
nodeAddressesStr, payees := make([]string, 0), make([]string, 0)
for _, cla := range nodeAddresses {
nodeAddressesStr = append(nodeAddressesStr, cla.Hex())
payees = append(payees, primaryNodeAddresses[keyIndex])
}
err = keeperRegistry.SetKeepers(nodeAddressesStr, payees, ocrConfig)
require.NoError(t, err, "Setting keepers in the registry shouldn't fail")
for _, chainlinkNode := range chainlinkNodes {
chainlinkNodeAddress, err := chainlinkNode.EthAddresses()
require.NoError(t, err, "Error retrieving chainlink node address")
_, err = chainlinkNode.MustCreateJob(&client.KeeperJobSpec{
Name: fmt.Sprintf("keeper-test-%s", keeperRegistry.Address()),
ContractAddress: keeperRegistry.Address(),
FromAddress: chainlinkNodeAddress[keyIndex],
EVMChainID: evmChainID,
MinIncomingConfirmations: 1,
})
require.NoError(t, err, "Creating KeeperV2 Job shouldn't fail")
}
}
func DeleteKeeperJobsWithId(t *testing.T, chainlinkNodes []*client.ChainlinkK8sClient, id int) {
for _, chainlinkNode := range chainlinkNodes {
err := chainlinkNode.MustDeleteJob(strconv.Itoa(id))
require.NoError(t, err, "Deleting KeeperV2 Job shouldn't fail")
}
}
// DeployKeeperContracts deploys keeper registry and a number of basic upkeep contracts with an update interval of 5.
// It returns the freshly deployed registry, registrar, consumers and the IDs of the upkeeps.
func DeployKeeperContracts(
t *testing.T,
registryVersion ethereum.KeeperRegistryVersion,
registrySettings contracts.KeeperRegistrySettings,
numberOfUpkeeps int,
upkeepGasLimit uint32,
linkToken contracts.LinkToken,
contractDeployer contracts.ContractDeployer,
client blockchain.EVMClient,
linkFundsForEachUpkeep *big.Int,
) (contracts.KeeperRegistry, contracts.KeeperRegistrar, []contracts.KeeperConsumer, []*big.Int) {
ef, err := contractDeployer.DeployMockETHLINKFeed(big.NewInt(2e18))
require.NoError(t, err, "Deploying mock ETH-Link feed shouldn't fail")
gf, err := contractDeployer.DeployMockGasFeed(big.NewInt(2e11))
require.NoError(t, err, "Deploying mock gas feed shouldn't fail")
err = client.WaitForEvents()
require.NoError(t, err, "Failed waiting for mock feeds to deploy")
// Deploy the transcoder here, and then set it to the registry
transcoder := DeployUpkeepTranscoder(t, contractDeployer, client)
registry := DeployKeeperRegistry(t, contractDeployer, client,
&contracts.KeeperRegistryOpts{
RegistryVersion: registryVersion,
LinkAddr: linkToken.Address(),
ETHFeedAddr: ef.Address(),
GasFeedAddr: gf.Address(),
TranscoderAddr: transcoder.Address(),
RegistrarAddr: ZeroAddress.Hex(),
Settings: registrySettings,
},
)
// Fund the registry with 1 LINK * amount of KeeperConsumerPerformance contracts
err = linkToken.Transfer(registry.Address(), big.NewInt(0).Mul(big.NewInt(1e18), big.NewInt(int64(numberOfUpkeeps))))
require.NoError(t, err, "Funding keeper registry contract shouldn't fail")
registrarSettings := contracts.KeeperRegistrarSettings{
AutoApproveConfigType: 2,
AutoApproveMaxAllowed: math.MaxUint16,
RegistryAddr: registry.Address(),
MinLinkJuels: big.NewInt(0),
}
registrar := DeployKeeperRegistrar(t, registryVersion, linkToken, registrarSettings, contractDeployer, client, registry)
upkeeps := DeployKeeperConsumers(t, contractDeployer, client, numberOfUpkeeps, false, false)
var upkeepsAddresses []string
for _, upkeep := range upkeeps {
upkeepsAddresses = append(upkeepsAddresses, upkeep.Address())
}
upkeepIds := RegisterUpkeepContracts(t, linkToken, linkFundsForEachUpkeep, client, upkeepGasLimit, registry, registrar, numberOfUpkeeps, upkeepsAddresses, false, false)
err = client.WaitForEvents()
require.NoError(t, err, "Error waiting for events")
return registry, registrar, upkeeps, upkeepIds
}
// DeployPerformanceKeeperContracts deploys a set amount of keeper performance contracts registered to a single registry
func DeployPerformanceKeeperContracts(
t *testing.T,
registryVersion ethereum.KeeperRegistryVersion,
numberOfContracts int,
upkeepGasLimit uint32,
linkToken contracts.LinkToken,
contractDeployer contracts.ContractDeployer,
client blockchain.EVMClient,
registrySettings *contracts.KeeperRegistrySettings,
linkFundsForEachUpkeep *big.Int,
blockRange, // How many blocks to run the test for
blockInterval, // Interval of blocks that upkeeps are expected to be performed
checkGasToBurn, // How much gas should be burned on checkUpkeep() calls
performGasToBurn int64, // How much gas should be burned on performUpkeep() calls
) (contracts.KeeperRegistry, contracts.KeeperRegistrar, []contracts.KeeperConsumerPerformance, []*big.Int) {
ef, err := contractDeployer.DeployMockETHLINKFeed(big.NewInt(2e18))
require.NoError(t, err, "Deploying mock ETH-Link feed shouldn't fail")
gf, err := contractDeployer.DeployMockGasFeed(big.NewInt(2e11))
require.NoError(t, err, "Deploying mock gas feed shouldn't fail")
err = client.WaitForEvents()
require.NoError(t, err, "Failed waiting for mock feeds to deploy")
registry := DeployKeeperRegistry(t, contractDeployer, client,
&contracts.KeeperRegistryOpts{
RegistryVersion: registryVersion,
LinkAddr: linkToken.Address(),
ETHFeedAddr: ef.Address(),
GasFeedAddr: gf.Address(),
TranscoderAddr: ZeroAddress.Hex(),
RegistrarAddr: ZeroAddress.Hex(),
Settings: *registrySettings,
},
)
// Fund the registry with 1 LINK * amount of KeeperConsumerPerformance contracts
err = linkToken.Transfer(registry.Address(), big.NewInt(0).Mul(big.NewInt(1e18), big.NewInt(int64(numberOfContracts))))
require.NoError(t, err, "Funding keeper registry contract shouldn't fail")
registrarSettings := contracts.KeeperRegistrarSettings{
AutoApproveConfigType: 2,
AutoApproveMaxAllowed: math.MaxUint16,
RegistryAddr: registry.Address(),
MinLinkJuels: big.NewInt(0),
}
registrar := DeployKeeperRegistrar(t, registryVersion, linkToken, registrarSettings, contractDeployer, client, registry)
upkeeps := DeployKeeperConsumersPerformance(
t, contractDeployer, client, numberOfContracts, blockRange, blockInterval, checkGasToBurn, performGasToBurn,
)
var upkeepsAddresses []string
for _, upkeep := range upkeeps {
upkeepsAddresses = append(upkeepsAddresses, upkeep.Address())
}
upkeepIds := RegisterUpkeepContracts(t, linkToken, linkFundsForEachUpkeep, client, upkeepGasLimit, registry, registrar, numberOfContracts, upkeepsAddresses, false, false)
return registry, registrar, upkeeps, upkeepIds
}
// DeployPerformDataCheckerContracts deploys a set amount of keeper perform data checker contracts registered to a single registry
func DeployPerformDataCheckerContracts(
t *testing.T,
registryVersion ethereum.KeeperRegistryVersion,
numberOfContracts int,
upkeepGasLimit uint32,
linkToken contracts.LinkToken,
contractDeployer contracts.ContractDeployer,
client blockchain.EVMClient,
registrySettings *contracts.KeeperRegistrySettings,
linkFundsForEachUpkeep *big.Int,
expectedData []byte,
) (contracts.KeeperRegistry, contracts.KeeperRegistrar, []contracts.KeeperPerformDataChecker, []*big.Int) {
ef, err := contractDeployer.DeployMockETHLINKFeed(big.NewInt(2e18))
require.NoError(t, err, "Deploying mock ETH-Link feed shouldn't fail")
gf, err := contractDeployer.DeployMockGasFeed(big.NewInt(2e11))
require.NoError(t, err, "Deploying mock gas feed shouldn't fail")
err = client.WaitForEvents()
require.NoError(t, err, "Failed waiting for mock feeds to deploy")
registry := DeployKeeperRegistry(t, contractDeployer, client,
&contracts.KeeperRegistryOpts{
RegistryVersion: registryVersion,
LinkAddr: linkToken.Address(),
ETHFeedAddr: ef.Address(),
GasFeedAddr: gf.Address(),
TranscoderAddr: ZeroAddress.Hex(),
RegistrarAddr: ZeroAddress.Hex(),
Settings: *registrySettings,
},
)
// Fund the registry with 1 LINK * amount of KeeperConsumerPerformance contracts
err = linkToken.Transfer(registry.Address(), big.NewInt(0).Mul(big.NewInt(1e18), big.NewInt(int64(numberOfContracts))))
require.NoError(t, err, "Funding keeper registry contract shouldn't fail")
registrarSettings := contracts.KeeperRegistrarSettings{
AutoApproveConfigType: 2,
AutoApproveMaxAllowed: math.MaxUint16,
RegistryAddr: registry.Address(),
MinLinkJuels: big.NewInt(0),
}
registrar := DeployKeeperRegistrar(t, registryVersion, linkToken, registrarSettings, contractDeployer, client, registry)
upkeeps := DeployPerformDataChecker(t, contractDeployer, client, numberOfContracts, expectedData)
var upkeepsAddresses []string
for _, upkeep := range upkeeps {
upkeepsAddresses = append(upkeepsAddresses, upkeep.Address())
}
upkeepIds := RegisterUpkeepContracts(t, linkToken, linkFundsForEachUpkeep, client, upkeepGasLimit, registry, registrar, numberOfContracts, upkeepsAddresses, false, false)
return registry, registrar, upkeeps, upkeepIds
}
func DeployKeeperRegistry(
t *testing.T,
contractDeployer contracts.ContractDeployer,
client blockchain.EVMClient,
registryOpts *contracts.KeeperRegistryOpts,
) contracts.KeeperRegistry {
registry, err := contractDeployer.DeployKeeperRegistry(
registryOpts,
)
require.NoError(t, err, "Deploying keeper registry shouldn't fail")
err = client.WaitForEvents()
require.NoError(t, err, "Failed waiting for keeper registry to deploy")
return registry
}
func DeployKeeperRegistrar(
t *testing.T,
registryVersion ethereum.KeeperRegistryVersion,
linkToken contracts.LinkToken,
registrarSettings contracts.KeeperRegistrarSettings,
contractDeployer contracts.ContractDeployer,
client blockchain.EVMClient,
registry contracts.KeeperRegistry,
) contracts.KeeperRegistrar {
registrar, err := contractDeployer.DeployKeeperRegistrar(registryVersion, linkToken.Address(), registrarSettings)
require.NoError(t, err, "Deploying KeeperRegistrar contract shouldn't fail")
err = client.WaitForEvents()
require.NoError(t, err, "Failed waiting for registrar to deploy")
if registryVersion != ethereum.RegistryVersion_2_0 {
err = registry.SetRegistrar(registrar.Address())
require.NoError(t, err, "Registering the registrar address on the registry shouldn't fail")
err = client.WaitForEvents()
require.NoError(t, err, "Failed waiting for registry to set registrar")
}
return registrar
}
func DeployUpkeepTranscoder(
t *testing.T,
contractDeployer contracts.ContractDeployer,
client blockchain.EVMClient,
) contracts.UpkeepTranscoder {
transcoder, err := contractDeployer.DeployUpkeepTranscoder()
require.NoError(t, err, "Deploying UpkeepTranscoder contract shouldn't fail")
err = client.WaitForEvents()
require.NoError(t, err, "Failed waiting for transcoder to deploy")
return transcoder
}
func RegisterUpkeepContracts(t *testing.T, linkToken contracts.LinkToken, linkFunds *big.Int, client blockchain.EVMClient, upkeepGasLimit uint32, registry contracts.KeeperRegistry, registrar contracts.KeeperRegistrar, numberOfContracts int, upkeepAddresses []string, isLogTrigger bool, isMercury bool) []*big.Int {
checkData := make([][]byte, 0)
for i := 0; i < numberOfContracts; i++ {
checkData = append(checkData, []byte("0"))
}
return RegisterUpkeepContractsWithCheckData(
t, linkToken, linkFunds, client, upkeepGasLimit, registry, registrar,
numberOfContracts, upkeepAddresses, checkData, isLogTrigger, isMercury)
}
func RegisterUpkeepContractsWithCheckData(t *testing.T, linkToken contracts.LinkToken, linkFunds *big.Int, client blockchain.EVMClient, upkeepGasLimit uint32, registry contracts.KeeperRegistry, registrar contracts.KeeperRegistrar, numberOfContracts int, upkeepAddresses []string, checkData [][]byte, isLogTrigger bool, isMercury bool) []*big.Int {
l := logging.GetTestLogger(t)
registrationTxHashes := make([]common.Hash, 0)
upkeepIds := make([]*big.Int, 0)
for contractCount, upkeepAddress := range upkeepAddresses {
req, err := registrar.EncodeRegisterRequest(
fmt.Sprintf("upkeep_%d", contractCount+1),
[]byte("test@mail.com"),
upkeepAddress,
upkeepGasLimit,
client.GetDefaultWallet().Address(), // upkeep Admin
checkData[contractCount],
linkFunds,
0,
client.GetDefaultWallet().Address(),
isLogTrigger,
isMercury,
)
require.NoError(t, err, "Encoding the register request shouldn't fail")
tx, err := linkToken.TransferAndCall(registrar.Address(), linkFunds, req)
require.NoError(t, err, "Error registering the upkeep consumer to the registrar")
l.Debug().
Str("Contract Address", upkeepAddress).
Int("Number", contractCount+1).
Int("Out Of", numberOfContracts).
Str("TxHash", tx.Hash().String()).
Str("Check Data", hexutil.Encode(checkData[contractCount])).
Msg("Registered Keeper Consumer Contract")
registrationTxHashes = append(registrationTxHashes, tx.Hash())
if (contractCount+1)%ContractDeploymentInterval == 0 { // For large amounts of contract deployments, space things out some
err = client.WaitForEvents()
require.NoError(t, err, "Failed to wait after registering upkeep consumers")
}
}
err := client.WaitForEvents()
require.NoError(t, err, "Failed while waiting for all consumer contracts to be registered to registrar")
// Fetch the upkeep IDs
for _, txHash := range registrationTxHashes {
receipt, err := client.GetTxReceipt(txHash)
require.NoError(t, err, "Registration tx should be completed")
var upkeepId *big.Int
for _, rawLog := range receipt.Logs {
parsedUpkeepId, err := registry.ParseUpkeepIdFromRegisteredLog(rawLog)
if err == nil {
upkeepId = parsedUpkeepId
break
}
}
require.NotNil(t, upkeepId, "Upkeep ID should be found after registration")
l.Debug().
Str("TxHash", txHash.String()).
Str("Upkeep ID", upkeepId.String()).
Msg("Found upkeepId in tx hash")
upkeepIds = append(upkeepIds, upkeepId)
}
l.Info().Msg("Successfully registered all Keeper Consumer Contracts")
return upkeepIds
}
func DeployKeeperConsumers(t *testing.T, contractDeployer contracts.ContractDeployer, client blockchain.EVMClient, numberOfContracts int, isLogTrigger bool, isMercury bool) []contracts.KeeperConsumer {
l := logging.GetTestLogger(t)
keeperConsumerContracts := make([]contracts.KeeperConsumer, 0)
for contractCount := 0; contractCount < numberOfContracts; contractCount++ {
// Deploy consumer
var keeperConsumerInstance contracts.KeeperConsumer
var err error
if isMercury && isLogTrigger {
// v2.1 only: Log triggered based contract with Mercury enabled
keeperConsumerInstance, err = contractDeployer.DeployAutomationLogTriggeredStreamsLookupUpkeepConsumer()
} else if isMercury {
// v2.1 only: Conditional based contract with Mercury enabled
keeperConsumerInstance, err = contractDeployer.DeployAutomationStreamsLookupUpkeepConsumer(big.NewInt(1000), big.NewInt(5), false, true, false) // 1000 block test range
} else if isLogTrigger {
// v2.1 only: Log triggered based contract without Mercury
keeperConsumerInstance, err = contractDeployer.DeployAutomationLogTriggerConsumer(big.NewInt(1000)) // 1000 block test range
} else {
// v2.0 and v2.1: Conditional based contract without Mercury
keeperConsumerInstance, err = contractDeployer.DeployUpkeepCounter(big.NewInt(999999), big.NewInt(5))
}
require.NoError(t, err, "Deploying Consumer instance %d shouldn't fail", contractCount+1)
keeperConsumerContracts = append(keeperConsumerContracts, keeperConsumerInstance)
l.Debug().
Str("Contract Address", keeperConsumerInstance.Address()).
Int("Number", contractCount+1).
Int("Out Of", numberOfContracts).
Msg("Deployed Keeper Consumer Contract")
if (contractCount+1)%ContractDeploymentInterval == 0 { // For large amounts of contract deployments, space things out some
err := client.WaitForEvents()
require.NoError(t, err, "Failed to wait for KeeperConsumer deployments")
}
}
err := client.WaitForEvents()
require.NoError(t, err, "Failed waiting for to deploy all keeper consumer contracts")
l.Info().Msg("Successfully deployed all Keeper Consumer Contracts")
return keeperConsumerContracts
}
func DeployKeeperConsumersPerformance(
t *testing.T,
contractDeployer contracts.ContractDeployer,
client blockchain.EVMClient,
numberOfContracts int,
blockRange, // How many blocks to run the test for
blockInterval, // Interval of blocks that upkeeps are expected to be performed
checkGasToBurn, // How much gas should be burned on checkUpkeep() calls
performGasToBurn int64, // How much gas should be burned on performUpkeep() calls
) []contracts.KeeperConsumerPerformance {
l := logging.GetTestLogger(t)
upkeeps := make([]contracts.KeeperConsumerPerformance, 0)
for contractCount := 0; contractCount < numberOfContracts; contractCount++ {
// Deploy consumer
keeperConsumerInstance, err := contractDeployer.DeployKeeperConsumerPerformance(
big.NewInt(blockRange),
big.NewInt(blockInterval),
big.NewInt(checkGasToBurn),
big.NewInt(performGasToBurn),
)
require.NoError(t, err, "Deploying KeeperConsumerPerformance instance %d shouldn't fail", contractCount+1)
upkeeps = append(upkeeps, keeperConsumerInstance)
l.Debug().
Str("Contract Address", keeperConsumerInstance.Address()).
Int("Number", contractCount+1).
Int("Out Of", numberOfContracts).
Msg("Deployed Keeper Performance Contract")
if (contractCount+1)%ContractDeploymentInterval == 0 { // For large amounts of contract deployments, space things out some
err = client.WaitForEvents()
require.NoError(t, err, "Failed to wait for KeeperConsumerPerformance deployments")
}
}
err := client.WaitForEvents()
require.NoError(t, err, "Failed waiting for to deploy all keeper consumer contracts")
l.Info().Msg("Successfully deployed all Keeper Consumer Contracts")
return upkeeps
}
func DeployPerformDataChecker(
t *testing.T,
contractDeployer contracts.ContractDeployer,
client blockchain.EVMClient,
numberOfContracts int,
expectedData []byte,
) []contracts.KeeperPerformDataChecker {
l := logging.GetTestLogger(t)
upkeeps := make([]contracts.KeeperPerformDataChecker, 0)
for contractCount := 0; contractCount < numberOfContracts; contractCount++ {
performDataCheckerInstance, err := contractDeployer.DeployKeeperPerformDataChecker(expectedData)
require.NoError(t, err, "Deploying KeeperPerformDataChecker instance %d shouldn't fail", contractCount+1)
upkeeps = append(upkeeps, performDataCheckerInstance)
l.Debug().
Str("Contract Address", performDataCheckerInstance.Address()).
Int("Number", contractCount+1).
Int("Out Of", numberOfContracts).
Msg("Deployed PerformDataChecker Contract")
if (contractCount+1)%ContractDeploymentInterval == 0 {
err = client.WaitForEvents()
require.NoError(t, err, "Failed to wait for PerformDataChecker deployments")
}
}
err := client.WaitForEvents()
require.NoError(t, err, "Failed waiting for to deploy all keeper perform data checker contracts")
l.Info().Msg("Successfully deployed all PerformDataChecker Contracts")
return upkeeps
}
func DeployUpkeepCounters(
t *testing.T,
contractDeployer contracts.ContractDeployer,
client blockchain.EVMClient,
numberOfContracts int,
testRange *big.Int,
interval *big.Int,
) []contracts.UpkeepCounter {
l := logging.GetTestLogger(t)
upkeepCounters := make([]contracts.UpkeepCounter, 0)
for contractCount := 0; contractCount < numberOfContracts; contractCount++ {
// Deploy consumer
upkeepCounter, err := contractDeployer.DeployUpkeepCounter(testRange, interval)
require.NoError(t, err, "Deploying KeeperConsumer instance %d shouldn't fail", contractCount+1)
upkeepCounters = append(upkeepCounters, upkeepCounter)
l.Debug().
Str("Contract Address", upkeepCounter.Address()).
Int("Number", contractCount+1).
Int("Out Of", numberOfContracts).
Msg("Deployed Keeper Consumer Contract")
if (contractCount+1)%ContractDeploymentInterval == 0 { // For large amounts of contract deployments, space things out some
err = client.WaitForEvents()
require.NoError(t, err, "Failed to wait for KeeperConsumer deployments")
}
}
err := client.WaitForEvents()
require.NoError(t, err, "Failed waiting for to deploy all keeper consumer contracts")
l.Info().Msg("Successfully deployed all Keeper Consumer Contracts")
return upkeepCounters
}
func DeployUpkeepPerformCounterRestrictive(
t *testing.T,
contractDeployer contracts.ContractDeployer,
client blockchain.EVMClient,
numberOfContracts int,
testRange *big.Int,
averageEligibilityCadence *big.Int,
) []contracts.UpkeepPerformCounterRestrictive {
l := logging.GetTestLogger(t)
upkeepCounters := make([]contracts.UpkeepPerformCounterRestrictive, 0)
for contractCount := 0; contractCount < numberOfContracts; contractCount++ {
// Deploy consumer
upkeepCounter, err := contractDeployer.DeployUpkeepPerformCounterRestrictive(testRange, averageEligibilityCadence)
require.NoError(t, err, "Deploying KeeperConsumer instance %d shouldn't fail", contractCount+1)
upkeepCounters = append(upkeepCounters, upkeepCounter)
l.Debug().
Str("Contract Address", upkeepCounter.Address()).
Int("Number", contractCount+1).
Int("Out Of", numberOfContracts).
Msg("Deployed Keeper Consumer Contract")
if (contractCount+1)%ContractDeploymentInterval == 0 { // For large amounts of contract deployments, space things out some
err = client.WaitForEvents()
require.NoError(t, err, "Failed to wait for KeeperConsumer deployments")
}
}
err := client.WaitForEvents()
require.NoError(t, err, "Failed waiting for to deploy all keeper consumer contracts")
l.Info().Msg("Successfully deployed all Keeper Consumer Contracts")
return upkeepCounters
}
// RegisterNewUpkeeps registers the given amount of new upkeeps, using the registry and registrar
// which are passed as parameters.
// It returns the newly deployed contracts (consumers), as well as their upkeep IDs.
func RegisterNewUpkeeps(
t *testing.T,
contractDeployer contracts.ContractDeployer,
client blockchain.EVMClient,
linkToken contracts.LinkToken,
registry contracts.KeeperRegistry,
registrar contracts.KeeperRegistrar,
upkeepGasLimit uint32,
numberOfNewUpkeeps int,
) ([]contracts.KeeperConsumer, []*big.Int) {
newlyDeployedUpkeeps := DeployKeeperConsumers(t, contractDeployer, client, numberOfNewUpkeeps, false, false)
var addressesOfNewUpkeeps []string
for _, upkeep := range newlyDeployedUpkeeps {
addressesOfNewUpkeeps = append(addressesOfNewUpkeeps, upkeep.Address())
}
newUpkeepIDs := RegisterUpkeepContracts(t, linkToken, big.NewInt(9e18), client, upkeepGasLimit, registry, registrar, numberOfNewUpkeeps, addressesOfNewUpkeeps, false, false)
return newlyDeployedUpkeeps, newUpkeepIDs
}