Skip to content

Commit

Permalink
refactor: reduce redundancy in avsRegistry writer test (#462)
Browse files Browse the repository at this point in the history
  • Loading branch information
maximopalopoli authored Feb 3, 2025
1 parent 870f687 commit fae0cf3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
16 changes: 8 additions & 8 deletions chainio/clients/avsregistry/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"crypto/ecdsa"
"crypto/rand"
"errors"
"math/big"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand All @@ -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 {
Expand Down Expand Up @@ -206,7 +206,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",
Expand Down Expand Up @@ -328,7 +328,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",
Expand Down Expand Up @@ -370,7 +370,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",
Expand Down Expand Up @@ -401,7 +401,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",
Expand Down Expand Up @@ -432,7 +432,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",
Expand Down Expand Up @@ -464,7 +464,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",
Expand All @@ -491,7 +491,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
}
14 changes: 3 additions & 11 deletions chainio/clients/avsregistry/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
Expand All @@ -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},
Expand All @@ -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}},
Expand All @@ -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,
Expand All @@ -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(""),
Expand Down
2 changes: 1 addition & 1 deletion testutils/testclients/testclients.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func NewTestTxManager(httpEndpoint string, privateKeyHex string) (*txmgr.SimpleT
return txManager, nil
}

// Creates a testing ChainWriter from an httpEndpoint, private key and config.
// Creates an avsRegistry 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.
func NewTestAvsRegistryWriterFromConfig(
Expand Down

0 comments on commit fae0cf3

Please sign in to comment.