Skip to content

Commit b60f697

Browse files
committed
pass in t to helpers
1 parent 6fbfcd4 commit b60f697

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

integration_test.go

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ type ContractAddresses struct {
5050
func TestIntegrationUpdateSingleOperatorPath(t *testing.T) {
5151

5252
/* Start the anvil chain */
53-
anvilC := startAnvilTestContainer()
53+
anvilC := startAnvilTestContainer(t)
5454
// Not sure why but deferring anvilC.Terminate() causes a panic when the test finishes...
5555
// so letting it terminate silently for now
5656
anvilHttpEndpoint, err := anvilC.Endpoint(context.Background(), "http")
5757
if err != nil {
5858
t.Fatal(err)
5959
}
6060

61-
contractAddresses := getContractAddressesFromContractRegistry(anvilHttpEndpoint)
61+
contractAddresses := getContractAddressesFromContractRegistry(t, anvilHttpEndpoint)
6262
operatorEcdsaPrivKeyHex := "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
6363
operatorEcdsaPrivKey, err := crypto.HexToECDSA(operatorEcdsaPrivKeyHex)
6464
if err != nil {
@@ -70,7 +70,7 @@ func TestIntegrationUpdateSingleOperatorPath(t *testing.T) {
7070
avsSync := c.avsSync
7171

7272
// first register operator into avs. at this point, the operator will have whatever stake it had registered in eigenlayer in the avs
73-
registerOperatorWithAvs(c.wallet, anvilHttpEndpoint, contractAddresses, operatorEcdsaPrivKeyHex, operatorBlsPrivKey, true)
73+
registerOperatorWithAvs(t, c.wallet, anvilHttpEndpoint, contractAddresses, operatorEcdsaPrivKeyHex, operatorBlsPrivKey, true)
7474

7575
// get stake of operator before sync
7676
operatorsPerQuorumBeforeSync, err := c.avsReader.GetOperatorsStakeInQuorumsAtCurrentBlock(&bind.CallOpts{}, []types.QuorumNum{0})
@@ -81,7 +81,7 @@ func TestIntegrationUpdateSingleOperatorPath(t *testing.T) {
8181

8282
// deposit into strategy to create a diff between eigenlayer and avs stakes
8383
depositAmount := big.NewInt(100)
84-
depositErc20IntoStrategyForOperator(c.wallet, anvilHttpEndpoint, contractAddresses.DelegationManager, contractAddresses.Erc20MockStrategy, operatorEcdsaPrivKeyHex, operatorAddr.Hex(), depositAmount, false)
84+
depositErc20IntoStrategyForOperator(t, c.wallet, anvilHttpEndpoint, contractAddresses.DelegationManager, contractAddresses.Erc20MockStrategy, operatorEcdsaPrivKeyHex, operatorAddr.Hex(), depositAmount, false)
8585

8686
// run avsSync
8787
go avsSync.Start(context.Background())
@@ -105,11 +105,11 @@ func TestIntegrationUpdateSingleOperatorPath(t *testing.T) {
105105
// Simulating an operator registered between the moment we read the operator set and the moment we try to update the operator set to ensure this behaves as expected
106106
func TestIntegrationFullOperatorSetWithRaceConditionFailsToUpdate(t *testing.T) {
107107
/* Start the anvil chain with no mining and FIFO transaction ordering to be able to force retries */
108-
anvilC := startAnvilTestContainer("--order", "fifo", "--no-mining")
108+
anvilC := startAnvilTestContainer(t, "--order", "fifo", "--no-mining")
109109
anvilHttpEndpoint, err := anvilC.Endpoint(context.Background(), "http")
110110
require.NoError(t, err)
111111

112-
contractAddresses := getContractAddressesFromContractRegistry(anvilHttpEndpoint)
112+
contractAddresses := getContractAddressesFromContractRegistry(t, anvilHttpEndpoint)
113113

114114
ethClient, err := ethclient.Dial(anvilHttpEndpoint)
115115
require.NoError(t, err)
@@ -127,10 +127,10 @@ func TestIntegrationFullOperatorSetWithRaceConditionFailsToUpdate(t *testing.T)
127127
operator2Wallet := createWalletForOperator(t, operator2EcdsaPrivKeyHex, ethClient)
128128

129129
// Register first operator
130-
registerOperatorWithAvs(c.wallet, anvilHttpEndpoint, contractAddresses, operator1EcdsaPrivKeyHex, operator1BlsPrivKey, false)
130+
registerOperatorWithAvs(t, c.wallet, anvilHttpEndpoint, contractAddresses, operator1EcdsaPrivKeyHex, operator1BlsPrivKey, false)
131131

132132
// mine block
133-
advanceChainByNBlocks(1, anvilC)
133+
advanceChainByNBlocks(t, 1, anvilC)
134134

135135
// get state pre sync
136136
operatorsPerQuorumBeforeSync, err := c.avsSync.AvsReader.GetOperatorsStakeInQuorumsAtCurrentBlock(&bind.CallOpts{}, []types.QuorumNum{0})
@@ -142,22 +142,22 @@ func TestIntegrationFullOperatorSetWithRaceConditionFailsToUpdate(t *testing.T)
142142

143143
// deposit into strategy to create a diff between eigenlayer and avs stakes
144144
depositAmount := big.NewInt(100)
145-
depositErc20IntoStrategyForOperator(c.wallet, anvilHttpEndpoint, contractAddresses.DelegationManager, contractAddresses.Erc20MockStrategy, operator1EcdsaPrivKeyHex, operator1Addr.Hex(), depositAmount, false)
145+
depositErc20IntoStrategyForOperator(t, c.wallet, anvilHttpEndpoint, contractAddresses.DelegationManager, contractAddresses.Erc20MockStrategy, operator1EcdsaPrivKeyHex, operator1Addr.Hex(), depositAmount, false)
146146

147147
// mine block
148-
advanceChainByNBlocks(1, anvilC)
148+
advanceChainByNBlocks(t, 1, anvilC)
149149

150150
// Register the second operator. Recall that because we are running anvil in FIFO mode
151151
// this transaction will be included before the call to UpdateStakesOfOperatorSubsetForAllQuorums
152-
registerOperatorWithAvs(operator2Wallet, anvilHttpEndpoint, contractAddresses, operator2EcdsaPrivKeyHex, operator2BlsPrivKey, false)
152+
registerOperatorWithAvs(t, operator2Wallet, anvilHttpEndpoint, contractAddresses, operator2EcdsaPrivKeyHex, operator2BlsPrivKey, false)
153153

154154
// Start the sync
155155
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
156156
defer cancel()
157157
go c.avsSync.Start(ctx)
158158

159159
// Mine another block to include operator2's registration
160-
advanceChainByNBlocks(1, anvilC)
160+
advanceChainByNBlocks(t, 1, anvilC)
161161

162162
// Wait for sync process to complete
163163
time.Sleep(2 * time.Second)
@@ -207,11 +207,11 @@ func TestIntegrationFullOperatorSetWithRaceConditionFailsToUpdate(t *testing.T)
207207
// since the contract makes sure we are updating the full operator set
208208
func TestIntegrationFullOperatorSetWithRetry(t *testing.T) {
209209
/* Start the anvil chain with no mining and FIFO transaction ordering to be able to force retries */
210-
anvilC := startAnvilTestContainer("--order", "fifo", "--no-mining")
210+
anvilC := startAnvilTestContainer(t, "--order", "fifo", "--no-mining")
211211
anvilHttpEndpoint, err := anvilC.Endpoint(context.Background(), "http")
212212
require.NoError(t, err)
213213

214-
contractAddresses := getContractAddressesFromContractRegistry(anvilHttpEndpoint)
214+
contractAddresses := getContractAddressesFromContractRegistry(t, anvilHttpEndpoint)
215215

216216
ethClient, err := ethclient.Dial(anvilHttpEndpoint)
217217
require.NoError(t, err)
@@ -229,10 +229,10 @@ func TestIntegrationFullOperatorSetWithRetry(t *testing.T) {
229229
operator2Wallet := createWalletForOperator(t, operator2EcdsaPrivKeyHex, ethClient)
230230

231231
// Register first operator
232-
registerOperatorWithAvs(c.wallet, anvilHttpEndpoint, contractAddresses, operator1EcdsaPrivKeyHex, operator1BlsPrivKey, false)
232+
registerOperatorWithAvs(t, c.wallet, anvilHttpEndpoint, contractAddresses, operator1EcdsaPrivKeyHex, operator1BlsPrivKey, false)
233233

234234
// mine block
235-
advanceChainByNBlocks(1, anvilC)
235+
advanceChainByNBlocks(t, 1, anvilC)
236236

237237
// get state pre sync
238238
operatorsPerQuorumBeforeSync, err := c.avsSync.AvsReader.GetOperatorsStakeInQuorumsAtCurrentBlock(&bind.CallOpts{}, []types.QuorumNum{0})
@@ -244,24 +244,24 @@ func TestIntegrationFullOperatorSetWithRetry(t *testing.T) {
244244

245245
// deposit into strategy to create a diff between eigenlayer and avs stakes
246246
depositAmount := big.NewInt(100)
247-
depositErc20IntoStrategyForOperator(c.wallet, anvilHttpEndpoint, contractAddresses.DelegationManager, contractAddresses.Erc20MockStrategy, operator1EcdsaPrivKeyHex, operator1Addr.Hex(), depositAmount, false)
248-
advanceChainByNBlocks(1, anvilC)
247+
depositErc20IntoStrategyForOperator(t, c.wallet, anvilHttpEndpoint, contractAddresses.DelegationManager, contractAddresses.Erc20MockStrategy, operator1EcdsaPrivKeyHex, operator1Addr.Hex(), depositAmount, false)
248+
advanceChainByNBlocks(t, 1, anvilC)
249249

250250
// Register the second operator. Recall that because we are running anvil in FIFO mode
251251
// this transaction will be included before the call to UpdateStakesOfOperatorSubsetForAllQuorums
252-
registerOperatorWithAvs(operator2Wallet, anvilHttpEndpoint, contractAddresses, operator2EcdsaPrivKeyHex, operator2BlsPrivKey, false)
252+
registerOperatorWithAvs(t, operator2Wallet, anvilHttpEndpoint, contractAddresses, operator2EcdsaPrivKeyHex, operator2BlsPrivKey, false)
253253

254254
// Start the sync
255255
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
256256
defer cancel()
257257
go c.avsSync.Start(ctx)
258258

259259
// Mine another block to include operator2's registration then wait for update
260-
advanceChainByNBlocks(1, anvilC)
260+
advanceChainByNBlocks(t, 1, anvilC)
261261
time.Sleep(1 * time.Second)
262262

263263
// Mine Block to include update
264-
advanceChainByNBlocks(1, anvilC)
264+
advanceChainByNBlocks(t, 1, anvilC)
265265

266266
// Wait for sync process to complete
267267
time.Sleep(10 * time.Second)
@@ -305,15 +305,15 @@ func TestIntegrationFullOperatorSetWithRetry(t *testing.T) {
305305

306306
func TestIntegrationFullOperatorSet(t *testing.T) {
307307
/* Start the anvil chain */
308-
anvilC := startAnvilTestContainer()
308+
anvilC := startAnvilTestContainer(t)
309309
// Not sure why but deferring anvilC.Terminate() causes a panic when the test finishes...
310310
// so letting it terminate silently for now
311311
anvilHttpEndpoint, err := anvilC.Endpoint(context.Background(), "http")
312312
if err != nil {
313313
t.Fatal(err)
314314
}
315315

316-
contractAddresses := getContractAddressesFromContractRegistry(anvilHttpEndpoint)
316+
contractAddresses := getContractAddressesFromContractRegistry(t, anvilHttpEndpoint)
317317
operatorEcdsaPrivKeyHex := "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
318318
operatorEcdsaPrivKey, err := crypto.HexToECDSA(operatorEcdsaPrivKeyHex)
319319
if err != nil {
@@ -326,7 +326,7 @@ func TestIntegrationFullOperatorSet(t *testing.T) {
326326
avsSync := c.avsSync
327327

328328
// first register operator into avs. at this point, the operator will have whatever stake it had registered in eigenlayer in the avs
329-
registerOperatorWithAvs(c.wallet, anvilHttpEndpoint, contractAddresses, operatorEcdsaPrivKeyHex, operatorBlsPrivKey, true)
329+
registerOperatorWithAvs(t, c.wallet, anvilHttpEndpoint, contractAddresses, operatorEcdsaPrivKeyHex, operatorBlsPrivKey, true)
330330

331331
// get stake of operator before sync
332332
operatorsPerQuorumBeforeSync, err := avsSync.AvsReader.GetOperatorsStakeInQuorumsAtCurrentBlock(&bind.CallOpts{}, []types.QuorumNum{0})
@@ -338,7 +338,7 @@ func TestIntegrationFullOperatorSet(t *testing.T) {
338338

339339
// deposit into strategy to create a diff between eigenlayer and avs stakes
340340
depositAmount := big.NewInt(100)
341-
depositErc20IntoStrategyForOperator(c.wallet, anvilHttpEndpoint, contractAddresses.DelegationManager, contractAddresses.Erc20MockStrategy, operatorEcdsaPrivKeyHex, operatorAddr.Hex(), depositAmount, true)
341+
depositErc20IntoStrategyForOperator(t, c.wallet, anvilHttpEndpoint, contractAddresses.DelegationManager, contractAddresses.Erc20MockStrategy, operatorEcdsaPrivKeyHex, operatorAddr.Hex(), depositAmount, true)
342342

343343
avsSync.Start(context.Background())
344344

@@ -432,7 +432,7 @@ func NewAvsSyncComponents(t *testing.T, anvilHttpEndpoint string, contractAddres
432432
}
433433
}
434434

435-
func startAnvilTestContainer(additionalFlags ...string) testcontainers.Container {
435+
func startAnvilTestContainer(t *testing.T, additionalFlags ...string) testcontainers.Container {
436436
integrationDir, err := os.Getwd()
437437
require.NoError(t, err)
438438

@@ -469,12 +469,12 @@ func startAnvilTestContainer(additionalFlags ...string) testcontainers.Container
469469
// see comment in start-anvil-chain-with-el-and-avs-deployed.sh
470470
// 25 is arbitrary, but I think it's enough (not sure at which block exactly deployment happened)
471471
// this is still needed as of the latest stable anvil
472-
advanceChainByNBlocks(25, anvilC)
472+
advanceChainByNBlocks(t, 25, anvilC)
473473

474474
return anvilC
475475
}
476476

477-
func advanceChainByNBlocks(n int, anvilC testcontainers.Container) {
477+
func advanceChainByNBlocks(t *testing.T, n int, anvilC testcontainers.Container) {
478478
anvilEndpoint, err := anvilC.Endpoint(context.Background(), "")
479479
require.NoError(t, err)
480480
rpcUrl := "http://" + anvilEndpoint
@@ -490,7 +490,7 @@ func advanceChainByNBlocks(n int, anvilC testcontainers.Container) {
490490
}
491491

492492
// TODO(samlaf): move this function to eigensdk
493-
func registerOperatorWithAvs(wallet walletsdk.Wallet, ethHttpUrl string, contractAddresses ContractAddresses, ecdsaPrivKeyHex string, blsPrivKeyHex string, waitForMine bool) {
493+
func registerOperatorWithAvs(t *testing.T, wallet walletsdk.Wallet, ethHttpUrl string, contractAddresses ContractAddresses, ecdsaPrivKeyHex string, blsPrivKeyHex string, waitForMine bool) {
494494
ethHttpClient, err := ethclient.Dial(ethHttpUrl)
495495
require.NoError(t, err)
496496
blsKeyPair, err := bls.NewKeyPairFromString(blsPrivKeyHex)
@@ -531,6 +531,7 @@ func registerOperatorWithAvs(wallet walletsdk.Wallet, ethHttpUrl string, contrac
531531

532532
// TODO(samlaf): move this function to eigensdk
533533
func depositErc20IntoStrategyForOperator(
534+
t *testing.T,
534535
wallet walletsdk.Wallet,
535536
ethHttpUrl string,
536537
delegationManagerAddr common.Address,
@@ -566,7 +567,7 @@ func depositErc20IntoStrategyForOperator(
566567

567568
}
568569

569-
func getContractAddressesFromContractRegistry(ethHttpUrl string) ContractAddresses {
570+
func getContractAddressesFromContractRegistry(t *testing.T, ethHttpUrl string) ContractAddresses {
570571
ethHttpClient, err := ethclient.Dial(ethHttpUrl)
571572
require.NoError(t, err)
572573
// The ContractsRegistry contract should always be deployed at this address on anvil

0 commit comments

Comments
 (0)