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

refactor: reduce redundancy in avsRegistry writer test #462

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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
}
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
4 changes: 1 addition & 3 deletions testutils/testclients/testclients.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading