Skip to content

Commit

Permalink
Merge branch 'dev' into feat/add-set-ejection-cooldown-func
Browse files Browse the repository at this point in the history
  • Loading branch information
maximopalopoli committed Feb 7, 2025
2 parents a320767 + 946de36 commit 5ef5a5b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
24 changes: 24 additions & 0 deletions chainio/clients/avsregistry/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,30 @@ func (w *ChainWriter) SetEjector(
return receipt, nil
}

// Sets the accountIdentifier as the address received as parameter. Identifier should only be set once, since
// changing it could break existing operator sets. Returns the receipt of the transaction in case of success.
func (w *ChainWriter) SetAccountIdentifier(
ctx context.Context,
accountIdentifierAddress gethcommon.Address,
waitForReceipt bool,
) (*gethtypes.Receipt, error) {
w.logger.Info("setting account identifier with address ", accountIdentifierAddress)

noSendTxOpts, err := w.txMgr.GetNoSendTxOpts()
if err != nil {
return nil, err
}
tx, err := w.registryCoordinator.SetAccountIdentifier(noSendTxOpts, accountIdentifierAddress)
if err != nil {
return nil, err
}
receipt, err := w.txMgr.Send(ctx, tx, waitForReceipt)
if err != nil {
return nil, utils.WrapError("failed to send SetAccountIdentifier tx with err", err.Error())
}
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(
Expand Down
34 changes: 34 additions & 0 deletions chainio/clients/avsregistry/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,40 @@ func TestSetEjector(t *testing.T) {
assert.Equal(t, newEjector.String(), testutils.ANVIL_SECOND_ADDRESS)
}

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

contractAddrs := testutils.GetContractAddressesFromContractRegistry(anvilHttpEndpoint)

chainWriter := clients.AvsRegistryChainWriter

accountIdentifierAddress := gethcommon.HexToAddress(testutils.ANVIL_SECOND_ADDRESS)

ethHttpClient := clients.EthHttpClient

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

// At first, accountIdentifier is service manager address
accountIdentifier, err := registryCoordinatorContract.AccountIdentifier(&bind.CallOpts{})
require.NoError(t, err)
assert.Equal(t, accountIdentifier, contractAddrs.ServiceManager)

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

// After change, accountIdentifier is the value set
newAccountIdentifier, err := registryCoordinatorContract.AccountIdentifier(&bind.CallOpts{})
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)
Expand Down

0 comments on commit 5ef5a5b

Please sign in to comment.