From 3527ffde22d3878224b7cf0e490e406ee2e9cd3a Mon Sep 17 00:00:00 2001 From: Madhur Shrimal Date: Mon, 1 Jul 2024 20:57:18 -0700 Subject: [PATCH] fix mocks and subscribers --- chainio/clients/avsregistry/builder.go | 12 ++++++++---- chainio/clients/avsregistry/subscriber.go | 9 +++++++-- chainio/clients/builder.go | 1 + chainio/gen.go | 4 ++-- chainio/mocks/elContractsReader.go | 6 +++--- chainio/mocks/elContractsWriter.go | 6 +++--- 6 files changed, 24 insertions(+), 14 deletions(-) diff --git a/chainio/clients/avsregistry/builder.go b/chainio/clients/avsregistry/builder.go index 6faf9589..81787f1f 100644 --- a/chainio/clients/avsregistry/builder.go +++ b/chainio/clients/avsregistry/builder.go @@ -10,6 +10,7 @@ import ( func BuildClients( config Config, client eth.Client, + wsClient eth.Client, txMgr txmgr.TxManager, logger logging.Logger, ) (*ChainReader, *ChainSubscriber, *ChainWriter, *ContractBindings, error) { @@ -33,13 +34,16 @@ func BuildClients( client, ) - chainSubscriber := NewChainSubscriber( - avsBindings.RegistryCoordinator, - avsBindings.BlsApkRegistry, + chainSubscriber, err := NewSubscriberFromConfig( + config, + wsClient, logger, ) + if err != nil { + return nil, nil, nil, nil, err + } - // This is ugly but we need elReader to be able to create the AVS writer + // This is ugly, but we need elReader to be able to create the AVS writer elChainReader, err := elcontracts.NewReaderFromConfig( elcontracts.Config{ DelegationManagerAddress: avsBindings.DelegationManagerAddr, diff --git a/chainio/clients/avsregistry/subscriber.go b/chainio/clients/avsregistry/subscriber.go index 24ffb73e..3d86924b 100644 --- a/chainio/clients/avsregistry/subscriber.go +++ b/chainio/clients/avsregistry/subscriber.go @@ -26,6 +26,8 @@ type ChainSubscriber struct { // forces EthSubscriber to implement the chainio.Subscriber interface var _ Subscriber = (*ChainSubscriber)(nil) +// NewChainSubscriber creates a new instance of ChainSubscriber +// The bindings must be created using websocket ETH Client func NewChainSubscriber( regCoord regcoord.ContractRegistryCoordinatorFilters, blsApkRegistry blsapkreg.ContractBLSApkRegistryFilters, @@ -40,6 +42,8 @@ func NewChainSubscriber( } } +// BuildAvsRegistryChainSubscriber creates a new instance of ChainSubscriber +// Deprecated: Use NewSubscriberFromConfig instead func BuildAvsRegistryChainSubscriber( regCoordAddr common.Address, ethWsClient eth.Client, @@ -60,12 +64,13 @@ func BuildAvsRegistryChainSubscriber( return NewChainSubscriber(regCoord, blsApkReg, logger), nil } +// NewSubscriberFromConfig creates a new instance of ChainSubscriber func NewSubscriberFromConfig( cfg Config, - ethClient eth.Client, + wsClient eth.Client, logger logging.Logger, ) (*ChainSubscriber, error) { - bindings, err := NewBindingsFromConfig(cfg, ethClient, logger) + bindings, err := NewBindingsFromConfig(cfg, wsClient, logger) if err != nil { return nil, err } diff --git a/chainio/clients/builder.go b/chainio/clients/builder.go index c5836f7a..c3f4b320 100644 --- a/chainio/clients/builder.go +++ b/chainio/clients/builder.go @@ -95,6 +95,7 @@ func BuildAll( OperatorStateRetrieverAddress: gethcommon.HexToAddress(config.OperatorStateRetrieverAddr), }, ethHttpClient, + ethWsClient, txMgr, logger, ) diff --git a/chainio/gen.go b/chainio/gen.go index a34ae1e6..e80ef40b 100644 --- a/chainio/gen.go +++ b/chainio/gen.go @@ -3,8 +3,8 @@ package chainio //go:generate mockgen -destination=./mocks/avsRegistryContractsReader.go -package=mocks -mock_names=Reader=MockAVSReader github.com/Layr-Labs/eigensdk-go/chainio/clients/avsregistry Reader //go:generate mockgen -destination=./mocks/avsRegistryContractsSubscriber.go -package=mocks -mock_names=Subscriber=MockAVSSubscriber github.com/Layr-Labs/eigensdk-go/chainio/clients/avsregistry Subscriber //go:generate mockgen -destination=./mocks/avsRegistryContractsWriter.go -package=mocks -mock_names=Writer=MockAVSWriter github.com/Layr-Labs/eigensdk-go/chainio/clients/avsregistry Writer -//go:generate mockgen -destination=./mocks/elContractsReader.go -package=mocks github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts ELReader -//go:generate mockgen -destination=./mocks/elContractsWriter.go -package=mocks github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts ELWriter +//go:generate mockgen -destination=./mocks/elContractsReader.go -package=mocks -mock_names=Reader=MockELReader github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts Reader +//go:generate mockgen -destination=./mocks/elContractsWriter.go -package=mocks -mock_names=Writer=MockELWriter github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts Writer //go:generate mockgen -destination=./mocks/ethclient.go -package=mocks -mock_names=Client=MockEthClient github.com/Layr-Labs/eigensdk-go/chainio/clients/eth Client //go:generate mockgen -destination=./mocks/eventSubscription.go -package=mocks github.com/ethereum/go-ethereum/event Subscription //go:generate mockgen -destination=./clients/mocks/fireblocks.go -package=mocks -mock_names=Client=MockFireblocksClient github.com/Layr-Labs/eigensdk-go/chainio/clients/fireblocks Client diff --git a/chainio/mocks/elContractsReader.go b/chainio/mocks/elContractsReader.go index 1ba7173e..1c5af900 100644 --- a/chainio/mocks/elContractsReader.go +++ b/chainio/mocks/elContractsReader.go @@ -1,9 +1,9 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts (interfaces: ELReader) +// Source: github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts (interfaces: Reader) // // Generated by this command: // -// mockgen -destination=./mocks/elContractsReader.go -package=mocks github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts ELReader +// mockgen -destination=./mocks/elContractsReader.go -package=mocks -mock_names=Reader=MockELReader github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts Reader // // Package mocks is a generated GoMock package. @@ -21,7 +21,7 @@ import ( gomock "go.uber.org/mock/gomock" ) -// MockELReader is a mock of ELReader interface. +// MockELReader is a mock of Reader interface. type MockELReader struct { ctrl *gomock.Controller recorder *MockELReaderMockRecorder diff --git a/chainio/mocks/elContractsWriter.go b/chainio/mocks/elContractsWriter.go index f497184f..4bc01909 100644 --- a/chainio/mocks/elContractsWriter.go +++ b/chainio/mocks/elContractsWriter.go @@ -1,9 +1,9 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts (interfaces: ELWriter) +// Source: github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts (interfaces: Writer) // // Generated by this command: // -// mockgen -destination=./mocks/elContractsWriter.go -package=mocks github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts ELWriter +// mockgen -destination=./mocks/elContractsWriter.go -package=mocks -mock_names=Writer=MockELWriter github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts Writer // // Package mocks is a generated GoMock package. @@ -20,7 +20,7 @@ import ( gomock "go.uber.org/mock/gomock" ) -// MockELWriter is a mock of ELWriter interface. +// MockELWriter is a mock of Writer interface. type MockELWriter struct { ctrl *gomock.Controller recorder *MockELWriterMockRecorder