From c5a17b00ac698ec0fee7ab5124d1ed9825332722 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Thu, 23 Jan 2025 09:50:20 -0300 Subject: [PATCH 1/3] Use utils.WrapError instead or concat a new error --- chainio/clients/avsregistry/writer.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/chainio/clients/avsregistry/writer.go b/chainio/clients/avsregistry/writer.go index 99e5ec1a..1f24f4be 100644 --- a/chainio/clients/avsregistry/writer.go +++ b/chainio/clients/avsregistry/writer.go @@ -4,7 +4,6 @@ import ( "context" "crypto/ecdsa" "crypto/rand" - "errors" "math/big" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -23,6 +22,7 @@ import ( "github.com/Layr-Labs/eigensdk-go/crypto/bls" "github.com/Layr-Labs/eigensdk-go/logging" "github.com/Layr-Labs/eigensdk-go/types" + "github.com/Layr-Labs/eigensdk-go/utils" ) type eLReader interface { @@ -203,7 +203,7 @@ func (w *ChainWriter) RegisterOperatorInQuorumWithAVSRegistryCoordinator( } receipt, err := w.txMgr.Send(ctx, tx, waitForReceipt) if err != nil { - return nil, errors.New("failed to send tx with err: " + err.Error()) + return nil, utils.WrapError("failed to send tx with err", err.Error()) } w.logger.Info( "successfully registered operator with AVS registry coordinator", @@ -325,7 +325,7 @@ func (w *ChainWriter) RegisterOperator( } receipt, err := w.txMgr.Send(ctx, tx, waitForReceipt) if err != nil { - return nil, errors.New("failed to send tx with err: " + err.Error()) + return nil, utils.WrapError("failed to send tx with err", err.Error()) } w.logger.Info( "successfully registered operator with AVS registry coordinator", @@ -367,7 +367,7 @@ func (w *ChainWriter) UpdateStakesOfEntireOperatorSetForQuorums( } receipt, err := w.txMgr.Send(ctx, tx, waitForReceipt) if err != nil { - return nil, errors.New("failed to send tx with err: " + err.Error()) + return nil, utils.WrapError("failed to send tx with err: ", err.Error()) } w.logger.Info( "successfully updated stakes for entire operator set", @@ -396,7 +396,7 @@ func (w *ChainWriter) UpdateStakesOfOperatorSubsetForAllQuorums( } receipt, err := w.txMgr.Send(ctx, tx, waitForReceipt) if err != nil { - return nil, errors.New("failed to send tx with err: " + err.Error()) + return nil, utils.WrapError("failed to send tx with err", err.Error()) } w.logger.Info( "successfully updated stakes of operator subset for all quorums", @@ -425,7 +425,7 @@ func (w *ChainWriter) DeregisterOperator( } receipt, err := w.txMgr.Send(ctx, tx, waitForReceipt) if err != nil { - return nil, errors.New("failed to send tx with err: " + err.Error()) + return nil, utils.WrapError("failed to send tx with err", err.Error()) } w.logger.Info( "successfully deregistered operator with the AVS's registry coordinator", @@ -455,7 +455,7 @@ func (w *ChainWriter) DeregisterOperatorOperatorSets( } receipt, err := w.txMgr.Send(ctx, tx, waitForReceipt) if err != nil { - return nil, errors.New("failed to send tx with err: " + err.Error()) + return nil, utils.WrapError("failed to send tx with err", err.Error()) } w.logger.Info( "successfully deregistered operator with the AVS's registry coordinator", @@ -480,7 +480,7 @@ func (w *ChainWriter) UpdateSocket( } receipt, err := w.txMgr.Send(ctx, tx, waitForReceipt) if err != nil { - return nil, errors.New("failed to send UpdateSocket tx with err: " + err.Error()) + return nil, utils.WrapError("failed to send UpdateSocket tx with err", err.Error()) } return receipt, nil } From d2d505a5a82fe951f45083233caf499ff264a849 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Thu, 23 Jan 2025 09:53:06 -0300 Subject: [PATCH 2/3] Create cancelled context only once at TestWriterMethods --- chainio/clients/avsregistry/writer_test.go | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/chainio/clients/avsregistry/writer_test.go b/chainio/clients/avsregistry/writer_test.go index c95f9087..faf6d5b9 100644 --- a/chainio/clients/avsregistry/writer_test.go +++ b/chainio/clients/avsregistry/writer_test.go @@ -44,6 +44,9 @@ func TestWriterMethods(t *testing.T) { quorumNumbers := types.QuorumNums{0} + subCtx, cancelFn := context.WithCancel(context.Background()) + cancelFn() + t.Run("update socket without being registered", func(t *testing.T) { receipt, err := chainWriter.UpdateSocket( context.Background(), @@ -122,8 +125,6 @@ func TestWriterMethods(t *testing.T) { // Error cases t.Run("fail register operator cancelling context", func(t *testing.T) { - subCtx, cancelFn := context.WithCancel(context.Background()) - cancelFn() receipt, err := chainWriter.RegisterOperator( subCtx, ecdsaPrivateKey, @@ -137,8 +138,6 @@ func TestWriterMethods(t *testing.T) { }) t.Run("fail update stake of operator subset cancelling context", func(t *testing.T) { - subCtx, cancelFn := context.WithCancel(context.Background()) - cancelFn() receipt, err := chainWriter.UpdateStakesOfOperatorSubsetForAllQuorums( subCtx, []gethcommon.Address{addr}, @@ -149,8 +148,6 @@ func TestWriterMethods(t *testing.T) { }) t.Run("fail update stake of entire operator set cancelling context", func(t *testing.T) { - subCtx, cancelFn := context.WithCancel(context.Background()) - cancelFn() receipt, err := chainWriter.UpdateStakesOfEntireOperatorSetForQuorums( subCtx, [][]gethcommon.Address{{addr}}, @@ -174,8 +171,6 @@ func TestWriterMethods(t *testing.T) { }) t.Run("fail deregister operator cancelling context", func(t *testing.T) { - subCtx, cancelFn := context.WithCancel(context.Background()) - cancelFn() receipt, err := chainWriter.DeregisterOperator( subCtx, quorumNumbers, @@ -199,9 +194,6 @@ func TestWriterMethods(t *testing.T) { }) t.Run("fail update socket cancelling context", func(t *testing.T) { - subCtx, cancelFn := context.WithCancel(context.Background()) - - cancelFn() receipt, err := chainWriter.UpdateSocket( subCtx, types.Socket(""), From 35d03b199679221eef8d5148136515a266150d55 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Thu, 23 Jan 2025 09:55:12 -0300 Subject: [PATCH 3/3] Fix avsRegistry builder comment --- testutils/testclients/testclients.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/testutils/testclients/testclients.go b/testutils/testclients/testclients.go index 6798e451..3379ace0 100644 --- a/testutils/testclients/testclients.go +++ b/testutils/testclients/testclients.go @@ -195,9 +195,7 @@ func NewTestTxManager(httpEndpoint string, privateKeyHex string) (*txmgr.SimpleT return txManager, nil } -// Creates a testing ChainWriter from an httpEndpoint, private key and config. -// This is needed because the existing testclients.BuildTestClients returns a -// ChainWriter with a null rewardsCoordinator, which is required for some of the tests. +// Creates an avsRegistry testing ChainWriter from an httpEndpoint, private key and config. func NewTestAvsRegistryWriterFromConfig( httpEndpoint string, privateKeyHex string,