Skip to content
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

feat: add set ejection cooldown function #545

Merged
24 changes: 24 additions & 0 deletions chainio/clients/avsregistry/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,3 +598,27 @@ func (w *ChainWriter) SetAccountIdentifier(
}
return receipt, nil
}

// Sets the ejection cooldown with the value received by parameter. The ejection cooldown is the time an operator has to
// wait to join any quorum after being rejected. Returns the receipt of the transaction in case of success.
func (w *ChainWriter) SetEjectionCooldown(
ctx context.Context,
ejectionCooldown *big.Int,
waitForReceipt bool,
) (*gethtypes.Receipt, error) {
w.logger.Info("setting ejection cooldown with value ", ejectionCooldown)

noSendTxOpts, err := w.txMgr.GetNoSendTxOpts()
if err != nil {
return nil, err
}
tx, err := w.registryCoordinator.SetEjectionCooldown(noSendTxOpts, ejectionCooldown)
if err != nil {
return nil, err
}
receipt, err := w.txMgr.Send(ctx, tx, waitForReceipt)
if err != nil {
return nil, utils.WrapError("failed to send SetEjectionCooldown tx with err", err.Error())
}
return receipt, nil
}
34 changes: 34 additions & 0 deletions chainio/clients/avsregistry/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,3 +603,37 @@ func TestSetAccountIdentifier(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, newAccountIdentifier.String(), testutils.ANVIL_SECOND_ADDRESS)
}

func TestSetEjectionCooldown(t *testing.T) {
// Test set up
clients, anvilHttpEndpoint := testclients.BuildTestClients(t)

contractAddrs := testutils.GetContractAddressesFromContractRegistry(anvilHttpEndpoint)

chainWriter := clients.AvsRegistryChainWriter

ejectionCooldown := big.NewInt(2873)

ethHttpClient := clients.EthHttpClient

registryCoordinatorContract, err := regcoord.NewContractRegistryCoordinator(
contractAddrs.RegistryCoordinator,
ethHttpClient,
)
require.NoError(t, err)

// At first, ejectionCooldown is zero
cooldown, err := registryCoordinatorContract.EjectionCooldown(&bind.CallOpts{})
require.NoError(t, err)
assert.Equal(t, cooldown.Int64(), int64(0))

// Set a new ejectionCooldown
receipt, err := chainWriter.SetEjectionCooldown(context.Background(), ejectionCooldown, true)
require.NoError(t, err)
require.Equal(t, receipt.Status, gethtypes.ReceiptStatusSuccessful)

// After change, ejectionCooldown is the setted value
MegaRedHand marked this conversation as resolved.
Show resolved Hide resolved
newCooldown, err := registryCoordinatorContract.EjectionCooldown(&bind.CallOpts{})
require.NoError(t, err)
assert.Equal(t, newCooldown, ejectionCooldown)
}