diff --git a/chainio/clients/avsregistry/bindings.go b/chainio/clients/avsregistry/bindings.go index 98ce0891..776dca36 100644 --- a/chainio/clients/avsregistry/bindings.go +++ b/chainio/clients/avsregistry/bindings.go @@ -41,7 +41,7 @@ type ContractBindings struct { func NewAVSRegistryContractBindings( registryCoordinatorAddr gethcommon.Address, operatorStateRetrieverAddr gethcommon.Address, - ethclient eth.Client, + ethclient eth.HttpBackend, logger logging.Logger, ) (*ContractBindings, error) { contractBlsRegistryCoordinator, err := regcoordinator.NewContractRegistryCoordinator( @@ -124,7 +124,7 @@ func NewAVSRegistryContractBindings( // NewBindingsFromConfig creates a new instance of ContractBindings func NewBindingsFromConfig( cfg Config, - client eth.Client, + client eth.HttpBackend, logger logging.Logger, ) (*ContractBindings, error) { var ( diff --git a/chainio/clients/avsregistry/builder.go b/chainio/clients/avsregistry/builder.go index 81787f1f..c46b96bd 100644 --- a/chainio/clients/avsregistry/builder.go +++ b/chainio/clients/avsregistry/builder.go @@ -9,8 +9,8 @@ import ( func BuildClients( config Config, - client eth.Client, - wsClient eth.Client, + client eth.HttpBackend, + wsClient eth.WsBackend, txMgr txmgr.TxManager, logger logging.Logger, ) (*ChainReader, *ChainSubscriber, *ChainWriter, *ContractBindings, error) { diff --git a/chainio/clients/avsregistry/reader.go b/chainio/clients/avsregistry/reader.go index 84a8dcc7..dac569c7 100644 --- a/chainio/clients/avsregistry/reader.go +++ b/chainio/clients/avsregistry/reader.go @@ -37,7 +37,7 @@ type ChainReader struct { registryCoordinator *regcoord.ContractRegistryCoordinator operatorStateRetriever *opstateretriever.ContractOperatorStateRetriever stakeRegistry *stakeregistry.ContractStakeRegistry - ethClient eth.Client + ethClient eth.HttpBackend } func NewChainReader( @@ -47,7 +47,7 @@ func NewChainReader( operatorStateRetriever *opstateretriever.ContractOperatorStateRetriever, stakeRegistry *stakeregistry.ContractStakeRegistry, logger logging.Logger, - ethClient eth.Client, + ethClient eth.HttpBackend, ) *ChainReader { logger = logger.With(logging.ComponentKey, "avsregistry/ChainReader") @@ -65,7 +65,7 @@ func NewChainReader( // NewReaderFromConfig creates a new ChainReader func NewReaderFromConfig( cfg Config, - client eth.Client, + client eth.HttpBackend, logger logging.Logger, ) (*ChainReader, error) { bindings, err := NewBindingsFromConfig(cfg, client, logger) @@ -89,7 +89,7 @@ func NewReaderFromConfig( func BuildAvsRegistryChainReader( registryCoordinatorAddr common.Address, operatorStateRetrieverAddr common.Address, - ethClient eth.Client, + ethClient eth.HttpBackend, logger logging.Logger, ) (*ChainReader, error) { contractRegistryCoordinator, err := regcoord.NewContractRegistryCoordinator(registryCoordinatorAddr, ethClient) diff --git a/chainio/clients/avsregistry/subscriber.go b/chainio/clients/avsregistry/subscriber.go index b18ddd80..70d188b7 100644 --- a/chainio/clients/avsregistry/subscriber.go +++ b/chainio/clients/avsregistry/subscriber.go @@ -38,7 +38,7 @@ func NewChainSubscriber( // Deprecated: Use NewSubscriberFromConfig instead func BuildAvsRegistryChainSubscriber( regCoordAddr common.Address, - ethWsClient eth.Client, + ethWsClient eth.WsBackend, logger logging.Logger, ) (*ChainSubscriber, error) { regCoord, err := regcoord.NewContractRegistryCoordinator(regCoordAddr, ethWsClient) @@ -60,7 +60,7 @@ func BuildAvsRegistryChainSubscriber( // A websocket ETH Client must be provided func NewSubscriberFromConfig( cfg Config, - wsClient eth.Client, + wsClient eth.WsBackend, logger logging.Logger, ) (*ChainSubscriber, error) { bindings, err := NewBindingsFromConfig(cfg, wsClient, logger) diff --git a/chainio/clients/avsregistry/writer.go b/chainio/clients/avsregistry/writer.go index dbd397ef..9609d4b4 100644 --- a/chainio/clients/avsregistry/writer.go +++ b/chainio/clients/avsregistry/writer.go @@ -45,7 +45,7 @@ type ChainWriter struct { blsApkRegistry *blsapkregistry.ContractBLSApkRegistry elReader eLReader logger logging.Logger - ethClient eth.Client + ethClient eth.HttpBackend txMgr txmgr.TxManager } @@ -57,7 +57,7 @@ func NewChainWriter( blsApkRegistry *blsapkregistry.ContractBLSApkRegistry, elReader eLReader, logger logging.Logger, - ethClient eth.Client, + ethClient eth.HttpBackend, txMgr txmgr.TxManager, ) *ChainWriter { logger = logger.With(logging.ComponentKey, "avsregistry/ChainWriter") @@ -81,7 +81,7 @@ func BuildAvsRegistryChainWriter( registryCoordinatorAddr gethcommon.Address, operatorStateRetrieverAddr gethcommon.Address, logger logging.Logger, - ethClient eth.Client, + ethClient eth.HttpBackend, txMgr txmgr.TxManager, ) (*ChainWriter, error) { registryCoordinator, err := regcoord.NewContractRegistryCoordinator(registryCoordinatorAddr, ethClient) @@ -147,7 +147,7 @@ func BuildAvsRegistryChainWriter( // NewWriterFromConfig creates a new ChainWriter from the provided config func NewWriterFromConfig( cfg Config, - client eth.Client, + client eth.HttpBackend, txMgr txmgr.TxManager, logger logging.Logger, ) (*ChainWriter, error) { diff --git a/chainio/clients/builder.go b/chainio/clients/builder.go index c3f4b320..31d9559f 100644 --- a/chainio/clients/builder.go +++ b/chainio/clients/builder.go @@ -5,6 +5,8 @@ import ( "crypto/ecdsa" "time" + "github.com/ethereum/go-ethereum/ethclient" + "github.com/Layr-Labs/eigensdk-go/chainio/clients/avsregistry" "github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts" "github.com/Layr-Labs/eigensdk-go/chainio/clients/eth" @@ -39,8 +41,8 @@ type Clients struct { AvsRegistryChainWriter *avsregistry.ChainWriter ElChainReader *elcontracts.ChainReader ElChainWriter *elcontracts.ChainWriter - EthHttpClient eth.Client - EthWsClient eth.Client + EthHttpClient eth.HttpBackend + EthWsClient eth.WsBackend Wallet wallet.Wallet TxManager txmgr.TxManager AvsRegistryContractBindings *avsregistry.ContractBindings @@ -61,12 +63,12 @@ func BuildAll( eigenMetrics := metrics.NewEigenMetrics(config.AvsName, config.PromMetricsIpPortAddress, promReg, logger) // creating two types of Eth clients: HTTP and WS - ethHttpClient, err := eth.NewClient(config.EthHttpUrl) + ethHttpClient, err := ethclient.Dial(config.EthHttpUrl) if err != nil { return nil, utils.WrapError("Failed to create Eth Http client", err) } - ethWsClient, err := eth.NewClient(config.EthWsUrl) + ethWsClient, err := ethclient.Dial(config.EthWsUrl) if err != nil { return nil, utils.WrapError("Failed to create Eth WS client", err) } diff --git a/chainio/clients/elcontracts/bindings.go b/chainio/clients/elcontracts/bindings.go index 2eaad8bb..487ec2c3 100644 --- a/chainio/clients/elcontracts/bindings.go +++ b/chainio/clients/elcontracts/bindings.go @@ -35,7 +35,7 @@ type ContractBindings struct { func NewBindingsFromConfig( cfg Config, - client eth.Client, + client eth.HttpBackend, logger logging.Logger, ) (*ContractBindings, error) { var ( @@ -117,7 +117,7 @@ func isZeroAddress(address gethcommon.Address) bool { func NewEigenlayerContractBindings( delegationManagerAddr gethcommon.Address, avsDirectoryAddr gethcommon.Address, - ethclient eth.Client, + ethclient eth.HttpBackend, logger logging.Logger, ) (*ContractBindings, error) { contractDelegationManager, err := delegationmanager.NewContractDelegationManager(delegationManagerAddr, ethclient) diff --git a/chainio/clients/elcontracts/builder.go b/chainio/clients/elcontracts/builder.go index ba966d6c..2c568517 100644 --- a/chainio/clients/elcontracts/builder.go +++ b/chainio/clients/elcontracts/builder.go @@ -9,7 +9,7 @@ import ( func BuildClients( config Config, - client eth.Client, + client eth.HttpBackend, txMgr txmgr.TxManager, logger logging.Logger, eigenMetrics *metrics.EigenMetrics, diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index 6591e894..97aafa54 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -35,7 +35,7 @@ type ChainReader struct { strategyManager *strategymanager.ContractStrategyManager avsDirectory *avsdirectory.ContractAVSDirectory rewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator - ethClient eth.Client + ethClient eth.HttpBackend } func NewChainReader( @@ -45,7 +45,7 @@ func NewChainReader( avsDirectory *avsdirectory.ContractAVSDirectory, rewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator, logger logging.Logger, - ethClient eth.Client, + ethClient eth.HttpBackend, ) *ChainReader { logger = logger.With(logging.ComponentKey, "elcontracts/reader") @@ -65,7 +65,7 @@ func NewChainReader( func BuildELChainReader( delegationManagerAddr gethcommon.Address, avsDirectoryAddr gethcommon.Address, - ethClient eth.Client, + ethClient eth.HttpBackend, logger logging.Logger, ) (*ChainReader, error) { elContractBindings, err := NewEigenlayerContractBindings( @@ -90,7 +90,7 @@ func BuildELChainReader( func NewReaderFromConfig( cfg Config, - ethClient eth.Client, + ethClient eth.HttpBackend, logger logging.Logger, ) (*ChainReader, error) { elContractBindings, err := NewBindingsFromConfig( diff --git a/chainio/clients/elcontracts/writer.go b/chainio/clients/elcontracts/writer.go index cc1e5d1a..f0578b41 100644 --- a/chainio/clients/elcontracts/writer.go +++ b/chainio/clients/elcontracts/writer.go @@ -38,7 +38,7 @@ type ChainWriter struct { rewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator strategyManagerAddr gethcommon.Address elChainReader Reader - ethClient eth.Client + ethClient eth.HttpBackend logger logging.Logger txMgr txmgr.TxManager } @@ -50,7 +50,7 @@ func NewChainWriter( rewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator, strategyManagerAddr gethcommon.Address, elChainReader Reader, - ethClient eth.Client, + ethClient eth.HttpBackend, logger logging.Logger, eigenMetrics metrics.Metrics, txMgr txmgr.TxManager, @@ -75,7 +75,7 @@ func NewChainWriter( func BuildELChainWriter( delegationManagerAddr gethcommon.Address, avsDirectoryAddr gethcommon.Address, - ethClient eth.Client, + ethClient eth.HttpBackend, logger logging.Logger, eigenMetrics metrics.Metrics, txMgr txmgr.TxManager, @@ -114,7 +114,7 @@ func BuildELChainWriter( func NewWriterFromConfig( cfg Config, - ethClient eth.Client, + ethClient eth.HttpBackend, logger logging.Logger, eigenMetrics metrics.Metrics, txMgr txmgr.TxManager, diff --git a/chainio/clients/eth/client.go b/chainio/clients/eth/client.go index 16ee4e14..709851b7 100644 --- a/chainio/clients/eth/client.go +++ b/chainio/clients/eth/client.go @@ -4,54 +4,29 @@ import ( "context" "math/big" - "github.com/ethereum/go-ethereum" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/ethclient" + + "github.com/ethereum/go-ethereum/accounts/abi/bind" ) -type Client interface { - ChainID(ctx context.Context) (*big.Int, error) - BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error) - BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) - BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) +// HttpBackend is the HTTP ETH Client interface +// It is exactly the same as the WsBackend and there is no difference between them to the compiler, +// but we keep them separate as a signal to the programmer that an eth.Client with an underlying http/ws connection is +// expected +type HttpBackend interface { + bind.ContractBackend + BlockNumber(ctx context.Context) (uint64, error) - CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) - CallContractAtHash(ctx context.Context, msg ethereum.CallMsg, blockHash common.Hash) ([]byte, error) - CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) - EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error) - FeeHistory( - ctx context.Context, - blockCount uint64, - lastBlock *big.Int, - rewardPercentiles []float64, - ) (*ethereum.FeeHistory, error) - FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error) - HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) - HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) - NetworkID(ctx context.Context) (*big.Int, error) - NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error) - PeerCount(ctx context.Context) (uint64, error) - PendingBalanceAt(ctx context.Context, account common.Address) (*big.Int, error) - PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error) - PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error) - PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) - PendingStorageAt(ctx context.Context, account common.Address, key common.Hash) ([]byte, error) - PendingTransactionCount(ctx context.Context) (uint, error) - SendTransaction(ctx context.Context, tx *types.Transaction) error - StorageAt(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error) - SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error) - SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error) - SuggestGasPrice(ctx context.Context) (*big.Int, error) - SuggestGasTipCap(ctx context.Context) (*big.Int, error) - SyncProgress(ctx context.Context) (*ethereum.SyncProgress, error) - TransactionByHash(ctx context.Context, hash common.Hash) (tx *types.Transaction, isPending bool, err error) - TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error) - TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error) - TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) - TransactionSender(ctx context.Context, tx *types.Transaction, block common.Hash, index uint) (common.Address, error) + BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) } -func NewClient(rpcAddress string) (Client, error) { - return ethclient.Dial(rpcAddress) +// WsBackend is the Websocket ETH Client interface +// It is exactly the same as the HttpBackend and there is no difference between them to the compiler, +// but we keep them separate as a signal to the programmer that an eth.Client with an underlying http/ws connection is +// expected +type WsBackend interface { + bind.ContractBackend + + BlockNumber(ctx context.Context) (uint64, error) + BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) } diff --git a/chainio/clients/eth/instrumented_client.go b/chainio/clients/eth/instrumented_client.go index cf2d3877..1e90a8c1 100644 --- a/chainio/clients/eth/instrumented_client.go +++ b/chainio/clients/eth/instrumented_client.go @@ -27,7 +27,8 @@ type InstrumentedClient struct { clientAndVersion string } -var _ Client = (*InstrumentedClient)(nil) +var _ HttpBackend = (*InstrumentedClient)(nil) +var _ WsBackend = (*InstrumentedClient)(nil) func NewInstrumentedClient(rpcAddress string, rpcCallsCollector *rpccalls.Collector) (*InstrumentedClient, error) { client, err := ethclient.Dial(rpcAddress) @@ -115,19 +116,6 @@ func (iec *InstrumentedClient) CallContract( return bytes, nil } -func (iec *InstrumentedClient) CallContractAtHash( - ctx context.Context, - msg ethereum.CallMsg, - blockHash common.Hash, -) ([]byte, error) { - callContractAtHash := func() ([]byte, error) { return iec.client.CallContractAtHash(ctx, msg, blockHash) } - bytes, err := instrumentFunction[[]byte](callContractAtHash, "eth_call", iec) - if err != nil { - return nil, err - } - return bytes, nil -} - func (iec *InstrumentedClient) CodeAt( ctx context.Context, contract common.Address, @@ -205,15 +193,6 @@ func (iec *InstrumentedClient) HeaderByNumber(ctx context.Context, number *big.I return header, nil } -func (iec *InstrumentedClient) NetworkID(ctx context.Context) (*big.Int, error) { - networkID := func() (*big.Int, error) { return iec.client.NetworkID(ctx) } - id, err := instrumentFunction[*big.Int](networkID, "net_version", iec) - if err != nil { - return nil, err - } - return id, nil -} - func (iec *InstrumentedClient) NonceAt( ctx context.Context, account common.Address, @@ -227,15 +206,6 @@ func (iec *InstrumentedClient) NonceAt( return nonce, nil } -func (iec *InstrumentedClient) PeerCount(ctx context.Context) (uint64, error) { - peerCount := func() (uint64, error) { return iec.client.PeerCount(ctx) } - count, err := instrumentFunction[uint64](peerCount, "net_peerCount", iec) - if err != nil { - return 0, err - } - return count, nil -} - func (iec *InstrumentedClient) PendingBalanceAt(ctx context.Context, account common.Address) (*big.Int, error) { pendingBalanceAt := func() (*big.Int, error) { return iec.client.PendingBalanceAt(ctx, account) } balance, err := instrumentFunction[*big.Int](pendingBalanceAt, "eth_getBalance", iec) @@ -460,42 +430,6 @@ func (iec *InstrumentedClient) TransactionReceipt(ctx context.Context, txHash co return receipt, nil } -func (iec *InstrumentedClient) TransactionSender( - ctx context.Context, - tx *types.Transaction, - block common.Hash, - index uint, -) (common.Address, error) { - transactionSender := func() (common.Address, error) { return iec.client.TransactionSender(ctx, tx, block, index) } - address, err := instrumentFunction[common.Address]( - transactionSender, - "eth_getSender", - iec, - ) - if err != nil { - return common.Address{}, err - } - return address, nil -} - -// Extra methods - -// TODO(samlaf): feels weird that we have to write this function ourselves -// -// perhaps the gethClient interface should be the instrumented client, -// and then ethclient can take an instrumentedGethClient? -func (iec *InstrumentedClient) WaitForTransactionReceipt(ctx context.Context, txHash common.Hash) *types.Receipt { - for { - // verifying transaction receipt - receipt, err := iec.TransactionReceipt(ctx, txHash) - if err != nil { - time.Sleep(2 * time.Second) - } else { - return receipt - } - } -} - // Not sure why this method is not exposed in the ethclient itself... // but it is needed to comply with the rpc metrics defined in avs-node spec // https://docs.eigenlayer.xyz/eigenlayer/avs-guides/spec/metrics/metrics-prom-spec diff --git a/chainio/clients/wallet/fireblocks_wallet.go b/chainio/clients/wallet/fireblocks_wallet.go index e550a35e..4f077c3f 100644 --- a/chainio/clients/wallet/fireblocks_wallet.go +++ b/chainio/clients/wallet/fireblocks_wallet.go @@ -8,9 +8,11 @@ import ( "strconv" "sync" - "github.com/Layr-Labs/eigensdk-go/chainio/clients/eth" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/Layr-Labs/eigensdk-go/chainio/clients/fireblocks" "github.com/Layr-Labs/eigensdk-go/logging" + "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" @@ -31,13 +33,20 @@ var ( ErrTransactionFailed = errors.New("transaction failed") ) +type ethClient interface { + ChainID(ctx context.Context) (*big.Int, error) + TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) + + bind.ContractBackend +} + type fireblocksWallet struct { // mu protects access to nonceToTxID and txIDToNonce which can be // accessed concurrently by SendTransaction and GetTransactionReceipt mu sync.Mutex fireblocksClient fireblocks.Client - ethClient eth.Client + ethClient ethClient vaultAccountName string logger logging.Logger chainID *big.Int @@ -56,7 +65,7 @@ type fireblocksWallet struct { func NewFireblocksWallet( fireblocksClient fireblocks.Client, - ethClient eth.Client, + ethClient ethClient, vaultAccountName string, logger logging.Logger, ) (Wallet, error) { diff --git a/chainio/clients/wallet/fireblocks_wallet_test.go b/chainio/clients/wallet/fireblocks_wallet_test.go index f07ecba5..234ad121 100644 --- a/chainio/clients/wallet/fireblocks_wallet_test.go +++ b/chainio/clients/wallet/fireblocks_wallet_test.go @@ -5,12 +5,12 @@ import ( "math/big" "testing" + "github.com/Layr-Labs/eigensdk-go/internal/fakes" + "github.com/Layr-Labs/eigensdk-go/chainio/clients/fireblocks" cmocks "github.com/Layr-Labs/eigensdk-go/chainio/clients/mocks" "github.com/Layr-Labs/eigensdk-go/chainio/clients/wallet" - "github.com/Layr-Labs/eigensdk-go/chainio/mocks" "github.com/Layr-Labs/eigensdk-go/logging" - "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/stretchr/testify/assert" @@ -27,10 +27,9 @@ func TestSendTransaction(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() fireblocksClient := cmocks.NewMockFireblocksClient(ctrl) - ethClient := mocks.NewMockEthClient(ctrl) + ethClient := fakes.NewEthClient() logger, err := logging.NewZapLogger(logging.Development) assert.NoError(t, err) - ethClient.EXPECT().ChainID(gomock.Any()).Return(big.NewInt(5), nil) sender, err := wallet.NewFireblocksWallet(fireblocksClient, ethClient, vaultAccountName, logger) assert.NoError(t, err) @@ -87,10 +86,9 @@ func TestTransfer(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() fireblocksClient := cmocks.NewMockFireblocksClient(ctrl) - ethClient := mocks.NewMockEthClient(ctrl) + ethClient := fakes.NewEthClient() logger, err := logging.NewZapLogger(logging.Development) assert.NoError(t, err) - ethClient.EXPECT().ChainID(gomock.Any()).Return(big.NewInt(5), nil) sender, err := wallet.NewFireblocksWallet(fireblocksClient, ethClient, vaultAccountName, logger) assert.NoError(t, err) @@ -175,10 +173,9 @@ func TestSendTransactionNoValidContract(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() fireblocksClient := cmocks.NewMockFireblocksClient(ctrl) - ethClient := mocks.NewMockEthClient(ctrl) + ethClient := fakes.NewEthClient() logger, err := logging.NewZapLogger(logging.Development) assert.NoError(t, err) - ethClient.EXPECT().ChainID(gomock.Any()).Return(big.NewInt(5), nil) sender, err := wallet.NewFireblocksWallet(fireblocksClient, ethClient, vaultAccountName, logger) assert.NoError(t, err) @@ -231,10 +228,9 @@ func TestSendTransactionNoValidExternalAccount(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() fireblocksClient := cmocks.NewMockFireblocksClient(ctrl) - ethClient := mocks.NewMockEthClient(ctrl) + ethClient := fakes.NewEthClient() logger, err := logging.NewZapLogger(logging.Development) assert.NoError(t, err) - ethClient.EXPECT().ChainID(gomock.Any()).Return(big.NewInt(5), nil) sender, err := wallet.NewFireblocksWallet(fireblocksClient, ethClient, vaultAccountName, logger) assert.NoError(t, err) @@ -291,10 +287,9 @@ func TestSendTransactionInvalidVault(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() fireblocksClient := cmocks.NewMockFireblocksClient(ctrl) - ethClient := mocks.NewMockEthClient(ctrl) + ethClient := fakes.NewEthClient() logger, err := logging.NewZapLogger(logging.Development) assert.NoError(t, err) - ethClient.EXPECT().ChainID(gomock.Any()).Return(big.NewInt(5), nil) sender, err := wallet.NewFireblocksWallet(fireblocksClient, ethClient, vaultAccountName, logger) assert.NoError(t, err) @@ -329,10 +324,9 @@ func TestSendTransactionReplaceTx(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() fireblocksClient := cmocks.NewMockFireblocksClient(ctrl) - ethClient := mocks.NewMockEthClient(ctrl) + ethClient := fakes.NewEthClient() logger, err := logging.NewZapLogger(logging.Development) assert.NoError(t, err) - ethClient.EXPECT().ChainID(gomock.Any()).Return(big.NewInt(5), nil) sender, err := wallet.NewFireblocksWallet(fireblocksClient, ethClient, vaultAccountName, logger) assert.NoError(t, err) @@ -429,27 +423,21 @@ func TestWaitForTransactionReceipt(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() fireblocksClient := cmocks.NewMockFireblocksClient(ctrl) - ethClient := mocks.NewMockEthClient(ctrl) + ethClient := fakes.NewEthClient() logger, err := logging.NewZapLogger(logging.Development) assert.NoError(t, err) - ethClient.EXPECT().ChainID(gomock.Any()).Return(big.NewInt(5), nil) sender, err := wallet.NewFireblocksWallet(fireblocksClient, ethClient, vaultAccountName, logger) assert.NoError(t, err) - expectedTxHash := "0x0000000000000000000000000000000000000000000000000000000000001234" - fireblocksClient.EXPECT().GetTransaction(gomock.Any(), expectedTxHash).Return(&fireblocks.Transaction{ - ID: expectedTxHash, + fireblocksClient.EXPECT().GetTransaction(gomock.Any(), fakes.TransactionHash).Return(&fireblocks.Transaction{ + ID: fakes.TransactionHash, Status: fireblocks.Completed, - TxHash: expectedTxHash, - }, nil) - ethClient.EXPECT().TransactionReceipt(gomock.Any(), common.HexToHash(expectedTxHash)).Return(&types.Receipt{ - TxHash: common.HexToHash(expectedTxHash), - BlockNumber: big.NewInt(1234), + TxHash: fakes.TransactionHash, }, nil) - receipt, err := sender.GetTransactionReceipt(context.Background(), expectedTxHash) + receipt, err := sender.GetTransactionReceipt(context.Background(), fakes.TransactionHash) assert.NoError(t, err) - assert.Equal(t, expectedTxHash, receipt.TxHash.String()) + assert.Equal(t, fakes.TransactionHash, receipt.TxHash.String()) assert.Equal(t, big.NewInt(1234), receipt.BlockNumber) } @@ -457,21 +445,19 @@ func TestWaitForTransactionReceiptFailFromFireblocks(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() fireblocksClient := cmocks.NewMockFireblocksClient(ctrl) - ethClient := mocks.NewMockEthClient(ctrl) + ethClient := fakes.NewEthClient() logger, err := logging.NewZapLogger(logging.Development) assert.NoError(t, err) - ethClient.EXPECT().ChainID(gomock.Any()).Return(big.NewInt(5), nil) sender, err := wallet.NewFireblocksWallet(fireblocksClient, ethClient, vaultAccountName, logger) assert.NoError(t, err) - expectedTxHash := "0x0000000000000000000000000000000000000000000000000000000000001234" - fireblocksClient.EXPECT().GetTransaction(gomock.Any(), expectedTxHash).Return(&fireblocks.Transaction{ - ID: expectedTxHash, + fireblocksClient.EXPECT().GetTransaction(gomock.Any(), fakes.TransactionHash).Return(&fireblocks.Transaction{ + ID: fakes.TransactionHash, Status: fireblocks.Confirming, // not completed - TxHash: expectedTxHash, + TxHash: fakes.TransactionHash, }, nil) - receipt, err := sender.GetTransactionReceipt(context.Background(), expectedTxHash) + receipt, err := sender.GetTransactionReceipt(context.Background(), fakes.TransactionHash) assert.ErrorAs(t, err, &wallet.ErrReceiptNotYetAvailable) assert.Nil(t, receipt) } @@ -480,21 +466,19 @@ func TestWaitForTransactionReceiptStuckAtFireblocks(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() fireblocksClient := cmocks.NewMockFireblocksClient(ctrl) - ethClient := mocks.NewMockEthClient(ctrl) + ethClient := fakes.NewEthClient() logger, err := logging.NewZapLogger(logging.Development) assert.NoError(t, err) - ethClient.EXPECT().ChainID(gomock.Any()).Return(big.NewInt(5), nil) sender, err := wallet.NewFireblocksWallet(fireblocksClient, ethClient, vaultAccountName, logger) assert.NoError(t, err) - expectedTxHash := "0x0000000000000000000000000000000000000000000000000000000000001234" - fireblocksClient.EXPECT().GetTransaction(gomock.Any(), expectedTxHash).Return(&fireblocks.Transaction{ - ID: expectedTxHash, + fireblocksClient.EXPECT().GetTransaction(gomock.Any(), fakes.TransactionHash).Return(&fireblocks.Transaction{ + ID: fakes.TransactionHash, Status: fireblocks.PendingSignature, // not completed - TxHash: expectedTxHash, + TxHash: fakes.TransactionHash, }, nil) - receipt, err := sender.GetTransactionReceipt(context.Background(), expectedTxHash) + receipt, err := sender.GetTransactionReceipt(context.Background(), fakes.TransactionHash) assert.ErrorAs(t, err, &wallet.ErrNotYetBroadcasted) assert.Nil(t, receipt) } @@ -503,22 +487,21 @@ func TestWaitForTransactionReceiptFailFromChain(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() fireblocksClient := cmocks.NewMockFireblocksClient(ctrl) - ethClient := mocks.NewMockEthClient(ctrl) + ethClient := fakes.NewEthClient() logger, err := logging.NewZapLogger(logging.Development) assert.NoError(t, err) - ethClient.EXPECT().ChainID(gomock.Any()).Return(big.NewInt(5), nil) sender, err := wallet.NewFireblocksWallet(fireblocksClient, ethClient, vaultAccountName, logger) assert.NoError(t, err) - expectedTxHash := "0x0000000000000000000000000000000000000000000000000000000000001234" - fireblocksClient.EXPECT().GetTransaction(gomock.Any(), expectedTxHash).Return(&fireblocks.Transaction{ - ID: expectedTxHash, - Status: fireblocks.Completed, - TxHash: expectedTxHash, - }, nil) - ethClient.EXPECT().TransactionReceipt(gomock.Any(), common.HexToHash(expectedTxHash)).Return(nil, ethereum.NotFound) + fireblocksClient.EXPECT(). + GetTransaction(gomock.Any(), fakes.TransactionNashNotInFake). + Return(&fireblocks.Transaction{ + ID: fakes.TransactionNashNotInFake, + Status: fireblocks.Completed, + TxHash: fakes.TransactionNashNotInFake, + }, nil) - receipt, err := sender.GetTransactionReceipt(context.Background(), expectedTxHash) + receipt, err := sender.GetTransactionReceipt(context.Background(), fakes.TransactionNashNotInFake) assert.Error(t, err) assert.Nil(t, receipt) } @@ -527,10 +510,9 @@ func TestSenderAddress(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() fireblocksClient := cmocks.NewMockFireblocksClient(ctrl) - ethClient := mocks.NewMockEthClient(ctrl) + ethClient := fakes.NewEthClient() logger, err := logging.NewZapLogger(logging.Development) assert.NoError(t, err) - ethClient.EXPECT().ChainID(gomock.Any()).Return(big.NewInt(5), nil) w, err := wallet.NewFireblocksWallet(fireblocksClient, ethClient, vaultAccountName, logger) assert.NoError(t, err) assetID := fireblocks.AssetIDByChain[5] diff --git a/chainio/clients/wallet/privatekey_wallet.go b/chainio/clients/wallet/privatekey_wallet.go index 33ae3728..acec1ee8 100644 --- a/chainio/clients/wallet/privatekey_wallet.go +++ b/chainio/clients/wallet/privatekey_wallet.go @@ -5,7 +5,6 @@ import ( "fmt" "math/big" - "github.com/Layr-Labs/eigensdk-go/chainio/clients/eth" "github.com/Layr-Labs/eigensdk-go/logging" "github.com/Layr-Labs/eigensdk-go/signerv2" "github.com/Layr-Labs/eigensdk-go/utils" @@ -18,7 +17,7 @@ import ( var _ Wallet = (*privateKeyWallet)(nil) type privateKeyWallet struct { - ethClient eth.Client + ethClient ethClient address common.Address signerFn signerv2.SignerFn logger logging.Logger @@ -28,7 +27,7 @@ type privateKeyWallet struct { } func NewPrivateKeyWallet( - ethClient eth.Client, + ethClient ethClient, signer signerv2.SignerFn, signerAddress common.Address, logger logging.Logger, diff --git a/chainio/gen.go b/chainio/gen.go index 8fdfcb5c..8535bf47 100644 --- a/chainio/gen.go +++ b/chainio/gen.go @@ -1,5 +1,4 @@ package chainio -//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=./clients/mocks/fireblocks.go -package=mocks -mock_names=Client=MockFireblocksClient github.com/Layr-Labs/eigensdk-go/chainio/clients/fireblocks Client //go:generate mockgen -destination=./clients/mocks/wallet.go -package=mocks github.com/Layr-Labs/eigensdk-go/chainio/clients/wallet Wallet diff --git a/chainio/mocks/erc20ContractClient.go b/chainio/mocks/erc20ContractClient.go deleted file mode 100644 index c95e0632..00000000 --- a/chainio/mocks/erc20ContractClient.go +++ /dev/null @@ -1,57 +0,0 @@ -// Code generated by MockGen. DO NOT EDIT. -// Source: github.com/Layr-Labs/eigensdk-go/chainio/clients (interfaces: ERC20ContractClient) -// -// Generated by this command: -// -// mockgen -destination=./mocks/erc20ContractClient.go -package=mocks github.com/Layr-Labs/eigensdk-go/chainio/clients ERC20ContractClient -// -// Package mocks is a generated GoMock package. -package mocks - -import ( - big "math/big" - reflect "reflect" - - bind "github.com/ethereum/go-ethereum/accounts/abi/bind" - common "github.com/ethereum/go-ethereum/common" - types "github.com/ethereum/go-ethereum/core/types" - gomock "go.uber.org/mock/gomock" -) - -// MockERC20ContractClient is a mock of ERC20ContractClient interface. -type MockERC20ContractClient struct { - ctrl *gomock.Controller - recorder *MockERC20ContractClientMockRecorder -} - -// MockERC20ContractClientMockRecorder is the mock recorder for MockERC20ContractClient. -type MockERC20ContractClientMockRecorder struct { - mock *MockERC20ContractClient -} - -// NewMockERC20ContractClient creates a new mock instance. -func NewMockERC20ContractClient(ctrl *gomock.Controller) *MockERC20ContractClient { - mock := &MockERC20ContractClient{ctrl: ctrl} - mock.recorder = &MockERC20ContractClientMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockERC20ContractClient) EXPECT() *MockERC20ContractClientMockRecorder { - return m.recorder -} - -// Approve mocks base method. -func (m *MockERC20ContractClient) Approve(arg0 *bind.TransactOpts, arg1 common.Address, arg2 *big.Int) (*types.Transaction, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Approve", arg0, arg1, arg2) - ret0, _ := ret[0].(*types.Transaction) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Approve indicates an expected call of Approve. -func (mr *MockERC20ContractClientMockRecorder) Approve(arg0, arg1, arg2 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Approve", reflect.TypeOf((*MockERC20ContractClient)(nil).Approve), arg0, arg1, arg2) -} diff --git a/chainio/mocks/ethclient.go b/chainio/mocks/ethclient.go deleted file mode 100644 index e54fba51..00000000 --- a/chainio/mocks/ethclient.go +++ /dev/null @@ -1,554 +0,0 @@ -// Code generated by MockGen. DO NOT EDIT. -// Source: github.com/Layr-Labs/eigensdk-go/chainio/clients/eth (interfaces: Client) -// -// Generated by this command: -// -// mockgen -destination=./mocks/ethclient.go -package=mocks -mock_names=Client=MockEthClient github.com/Layr-Labs/eigensdk-go/chainio/clients/eth Client -// - -// Package mocks is a generated GoMock package. -package mocks - -import ( - context "context" - big "math/big" - reflect "reflect" - - ethereum "github.com/ethereum/go-ethereum" - common "github.com/ethereum/go-ethereum/common" - types "github.com/ethereum/go-ethereum/core/types" - gomock "go.uber.org/mock/gomock" -) - -// MockEthClient is a mock of Client interface. -type MockEthClient struct { - ctrl *gomock.Controller - recorder *MockEthClientMockRecorder -} - -// MockEthClientMockRecorder is the mock recorder for MockEthClient. -type MockEthClientMockRecorder struct { - mock *MockEthClient -} - -// NewMockEthClient creates a new mock instance. -func NewMockEthClient(ctrl *gomock.Controller) *MockEthClient { - mock := &MockEthClient{ctrl: ctrl} - mock.recorder = &MockEthClientMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockEthClient) EXPECT() *MockEthClientMockRecorder { - return m.recorder -} - -// BalanceAt mocks base method. -func (m *MockEthClient) BalanceAt(arg0 context.Context, arg1 common.Address, arg2 *big.Int) (*big.Int, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "BalanceAt", arg0, arg1, arg2) - ret0, _ := ret[0].(*big.Int) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// BalanceAt indicates an expected call of BalanceAt. -func (mr *MockEthClientMockRecorder) BalanceAt(arg0, arg1, arg2 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BalanceAt", reflect.TypeOf((*MockEthClient)(nil).BalanceAt), arg0, arg1, arg2) -} - -// BlockByHash mocks base method. -func (m *MockEthClient) BlockByHash(arg0 context.Context, arg1 common.Hash) (*types.Block, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "BlockByHash", arg0, arg1) - ret0, _ := ret[0].(*types.Block) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// BlockByHash indicates an expected call of BlockByHash. -func (mr *MockEthClientMockRecorder) BlockByHash(arg0, arg1 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockByHash", reflect.TypeOf((*MockEthClient)(nil).BlockByHash), arg0, arg1) -} - -// BlockByNumber mocks base method. -func (m *MockEthClient) BlockByNumber(arg0 context.Context, arg1 *big.Int) (*types.Block, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "BlockByNumber", arg0, arg1) - ret0, _ := ret[0].(*types.Block) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// BlockByNumber indicates an expected call of BlockByNumber. -func (mr *MockEthClientMockRecorder) BlockByNumber(arg0, arg1 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockByNumber", reflect.TypeOf((*MockEthClient)(nil).BlockByNumber), arg0, arg1) -} - -// BlockNumber mocks base method. -func (m *MockEthClient) BlockNumber(arg0 context.Context) (uint64, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "BlockNumber", arg0) - ret0, _ := ret[0].(uint64) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// BlockNumber indicates an expected call of BlockNumber. -func (mr *MockEthClientMockRecorder) BlockNumber(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockNumber", reflect.TypeOf((*MockEthClient)(nil).BlockNumber), arg0) -} - -// CallContract mocks base method. -func (m *MockEthClient) CallContract(arg0 context.Context, arg1 ethereum.CallMsg, arg2 *big.Int) ([]byte, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CallContract", arg0, arg1, arg2) - ret0, _ := ret[0].([]byte) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// CallContract indicates an expected call of CallContract. -func (mr *MockEthClientMockRecorder) CallContract(arg0, arg1, arg2 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CallContract", reflect.TypeOf((*MockEthClient)(nil).CallContract), arg0, arg1, arg2) -} - -// CallContractAtHash mocks base method. -func (m *MockEthClient) CallContractAtHash(arg0 context.Context, arg1 ethereum.CallMsg, arg2 common.Hash) ([]byte, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CallContractAtHash", arg0, arg1, arg2) - ret0, _ := ret[0].([]byte) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// CallContractAtHash indicates an expected call of CallContractAtHash. -func (mr *MockEthClientMockRecorder) CallContractAtHash(arg0, arg1, arg2 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CallContractAtHash", reflect.TypeOf((*MockEthClient)(nil).CallContractAtHash), arg0, arg1, arg2) -} - -// ChainID mocks base method. -func (m *MockEthClient) ChainID(arg0 context.Context) (*big.Int, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ChainID", arg0) - ret0, _ := ret[0].(*big.Int) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ChainID indicates an expected call of ChainID. -func (mr *MockEthClientMockRecorder) ChainID(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChainID", reflect.TypeOf((*MockEthClient)(nil).ChainID), arg0) -} - -// CodeAt mocks base method. -func (m *MockEthClient) CodeAt(arg0 context.Context, arg1 common.Address, arg2 *big.Int) ([]byte, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CodeAt", arg0, arg1, arg2) - ret0, _ := ret[0].([]byte) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// CodeAt indicates an expected call of CodeAt. -func (mr *MockEthClientMockRecorder) CodeAt(arg0, arg1, arg2 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CodeAt", reflect.TypeOf((*MockEthClient)(nil).CodeAt), arg0, arg1, arg2) -} - -// EstimateGas mocks base method. -func (m *MockEthClient) EstimateGas(arg0 context.Context, arg1 ethereum.CallMsg) (uint64, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "EstimateGas", arg0, arg1) - ret0, _ := ret[0].(uint64) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// EstimateGas indicates an expected call of EstimateGas. -func (mr *MockEthClientMockRecorder) EstimateGas(arg0, arg1 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EstimateGas", reflect.TypeOf((*MockEthClient)(nil).EstimateGas), arg0, arg1) -} - -// FeeHistory mocks base method. -func (m *MockEthClient) FeeHistory(arg0 context.Context, arg1 uint64, arg2 *big.Int, arg3 []float64) (*ethereum.FeeHistory, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "FeeHistory", arg0, arg1, arg2, arg3) - ret0, _ := ret[0].(*ethereum.FeeHistory) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// FeeHistory indicates an expected call of FeeHistory. -func (mr *MockEthClientMockRecorder) FeeHistory(arg0, arg1, arg2, arg3 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FeeHistory", reflect.TypeOf((*MockEthClient)(nil).FeeHistory), arg0, arg1, arg2, arg3) -} - -// FilterLogs mocks base method. -func (m *MockEthClient) FilterLogs(arg0 context.Context, arg1 ethereum.FilterQuery) ([]types.Log, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "FilterLogs", arg0, arg1) - ret0, _ := ret[0].([]types.Log) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// FilterLogs indicates an expected call of FilterLogs. -func (mr *MockEthClientMockRecorder) FilterLogs(arg0, arg1 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FilterLogs", reflect.TypeOf((*MockEthClient)(nil).FilterLogs), arg0, arg1) -} - -// HeaderByHash mocks base method. -func (m *MockEthClient) HeaderByHash(arg0 context.Context, arg1 common.Hash) (*types.Header, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "HeaderByHash", arg0, arg1) - ret0, _ := ret[0].(*types.Header) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// HeaderByHash indicates an expected call of HeaderByHash. -func (mr *MockEthClientMockRecorder) HeaderByHash(arg0, arg1 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HeaderByHash", reflect.TypeOf((*MockEthClient)(nil).HeaderByHash), arg0, arg1) -} - -// HeaderByNumber mocks base method. -func (m *MockEthClient) HeaderByNumber(arg0 context.Context, arg1 *big.Int) (*types.Header, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "HeaderByNumber", arg0, arg1) - ret0, _ := ret[0].(*types.Header) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// HeaderByNumber indicates an expected call of HeaderByNumber. -func (mr *MockEthClientMockRecorder) HeaderByNumber(arg0, arg1 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HeaderByNumber", reflect.TypeOf((*MockEthClient)(nil).HeaderByNumber), arg0, arg1) -} - -// NetworkID mocks base method. -func (m *MockEthClient) NetworkID(arg0 context.Context) (*big.Int, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "NetworkID", arg0) - ret0, _ := ret[0].(*big.Int) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// NetworkID indicates an expected call of NetworkID. -func (mr *MockEthClientMockRecorder) NetworkID(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NetworkID", reflect.TypeOf((*MockEthClient)(nil).NetworkID), arg0) -} - -// NonceAt mocks base method. -func (m *MockEthClient) NonceAt(arg0 context.Context, arg1 common.Address, arg2 *big.Int) (uint64, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "NonceAt", arg0, arg1, arg2) - ret0, _ := ret[0].(uint64) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// NonceAt indicates an expected call of NonceAt. -func (mr *MockEthClientMockRecorder) NonceAt(arg0, arg1, arg2 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NonceAt", reflect.TypeOf((*MockEthClient)(nil).NonceAt), arg0, arg1, arg2) -} - -// PeerCount mocks base method. -func (m *MockEthClient) PeerCount(arg0 context.Context) (uint64, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PeerCount", arg0) - ret0, _ := ret[0].(uint64) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// PeerCount indicates an expected call of PeerCount. -func (mr *MockEthClientMockRecorder) PeerCount(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PeerCount", reflect.TypeOf((*MockEthClient)(nil).PeerCount), arg0) -} - -// PendingBalanceAt mocks base method. -func (m *MockEthClient) PendingBalanceAt(arg0 context.Context, arg1 common.Address) (*big.Int, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PendingBalanceAt", arg0, arg1) - ret0, _ := ret[0].(*big.Int) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// PendingBalanceAt indicates an expected call of PendingBalanceAt. -func (mr *MockEthClientMockRecorder) PendingBalanceAt(arg0, arg1 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PendingBalanceAt", reflect.TypeOf((*MockEthClient)(nil).PendingBalanceAt), arg0, arg1) -} - -// PendingCallContract mocks base method. -func (m *MockEthClient) PendingCallContract(arg0 context.Context, arg1 ethereum.CallMsg) ([]byte, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PendingCallContract", arg0, arg1) - ret0, _ := ret[0].([]byte) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// PendingCallContract indicates an expected call of PendingCallContract. -func (mr *MockEthClientMockRecorder) PendingCallContract(arg0, arg1 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PendingCallContract", reflect.TypeOf((*MockEthClient)(nil).PendingCallContract), arg0, arg1) -} - -// PendingCodeAt mocks base method. -func (m *MockEthClient) PendingCodeAt(arg0 context.Context, arg1 common.Address) ([]byte, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PendingCodeAt", arg0, arg1) - ret0, _ := ret[0].([]byte) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// PendingCodeAt indicates an expected call of PendingCodeAt. -func (mr *MockEthClientMockRecorder) PendingCodeAt(arg0, arg1 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PendingCodeAt", reflect.TypeOf((*MockEthClient)(nil).PendingCodeAt), arg0, arg1) -} - -// PendingNonceAt mocks base method. -func (m *MockEthClient) PendingNonceAt(arg0 context.Context, arg1 common.Address) (uint64, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PendingNonceAt", arg0, arg1) - ret0, _ := ret[0].(uint64) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// PendingNonceAt indicates an expected call of PendingNonceAt. -func (mr *MockEthClientMockRecorder) PendingNonceAt(arg0, arg1 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PendingNonceAt", reflect.TypeOf((*MockEthClient)(nil).PendingNonceAt), arg0, arg1) -} - -// PendingStorageAt mocks base method. -func (m *MockEthClient) PendingStorageAt(arg0 context.Context, arg1 common.Address, arg2 common.Hash) ([]byte, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PendingStorageAt", arg0, arg1, arg2) - ret0, _ := ret[0].([]byte) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// PendingStorageAt indicates an expected call of PendingStorageAt. -func (mr *MockEthClientMockRecorder) PendingStorageAt(arg0, arg1, arg2 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PendingStorageAt", reflect.TypeOf((*MockEthClient)(nil).PendingStorageAt), arg0, arg1, arg2) -} - -// PendingTransactionCount mocks base method. -func (m *MockEthClient) PendingTransactionCount(arg0 context.Context) (uint, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PendingTransactionCount", arg0) - ret0, _ := ret[0].(uint) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// PendingTransactionCount indicates an expected call of PendingTransactionCount. -func (mr *MockEthClientMockRecorder) PendingTransactionCount(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PendingTransactionCount", reflect.TypeOf((*MockEthClient)(nil).PendingTransactionCount), arg0) -} - -// SendTransaction mocks base method. -func (m *MockEthClient) SendTransaction(arg0 context.Context, arg1 *types.Transaction) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SendTransaction", arg0, arg1) - ret0, _ := ret[0].(error) - return ret0 -} - -// SendTransaction indicates an expected call of SendTransaction. -func (mr *MockEthClientMockRecorder) SendTransaction(arg0, arg1 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendTransaction", reflect.TypeOf((*MockEthClient)(nil).SendTransaction), arg0, arg1) -} - -// StorageAt mocks base method. -func (m *MockEthClient) StorageAt(arg0 context.Context, arg1 common.Address, arg2 common.Hash, arg3 *big.Int) ([]byte, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "StorageAt", arg0, arg1, arg2, arg3) - ret0, _ := ret[0].([]byte) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// StorageAt indicates an expected call of StorageAt. -func (mr *MockEthClientMockRecorder) StorageAt(arg0, arg1, arg2, arg3 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StorageAt", reflect.TypeOf((*MockEthClient)(nil).StorageAt), arg0, arg1, arg2, arg3) -} - -// SubscribeFilterLogs mocks base method. -func (m *MockEthClient) SubscribeFilterLogs(arg0 context.Context, arg1 ethereum.FilterQuery, arg2 chan<- types.Log) (ethereum.Subscription, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SubscribeFilterLogs", arg0, arg1, arg2) - ret0, _ := ret[0].(ethereum.Subscription) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// SubscribeFilterLogs indicates an expected call of SubscribeFilterLogs. -func (mr *MockEthClientMockRecorder) SubscribeFilterLogs(arg0, arg1, arg2 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubscribeFilterLogs", reflect.TypeOf((*MockEthClient)(nil).SubscribeFilterLogs), arg0, arg1, arg2) -} - -// SubscribeNewHead mocks base method. -func (m *MockEthClient) SubscribeNewHead(arg0 context.Context, arg1 chan<- *types.Header) (ethereum.Subscription, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SubscribeNewHead", arg0, arg1) - ret0, _ := ret[0].(ethereum.Subscription) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// SubscribeNewHead indicates an expected call of SubscribeNewHead. -func (mr *MockEthClientMockRecorder) SubscribeNewHead(arg0, arg1 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubscribeNewHead", reflect.TypeOf((*MockEthClient)(nil).SubscribeNewHead), arg0, arg1) -} - -// SuggestGasPrice mocks base method. -func (m *MockEthClient) SuggestGasPrice(arg0 context.Context) (*big.Int, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SuggestGasPrice", arg0) - ret0, _ := ret[0].(*big.Int) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// SuggestGasPrice indicates an expected call of SuggestGasPrice. -func (mr *MockEthClientMockRecorder) SuggestGasPrice(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SuggestGasPrice", reflect.TypeOf((*MockEthClient)(nil).SuggestGasPrice), arg0) -} - -// SuggestGasTipCap mocks base method. -func (m *MockEthClient) SuggestGasTipCap(arg0 context.Context) (*big.Int, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SuggestGasTipCap", arg0) - ret0, _ := ret[0].(*big.Int) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// SuggestGasTipCap indicates an expected call of SuggestGasTipCap. -func (mr *MockEthClientMockRecorder) SuggestGasTipCap(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SuggestGasTipCap", reflect.TypeOf((*MockEthClient)(nil).SuggestGasTipCap), arg0) -} - -// SyncProgress mocks base method. -func (m *MockEthClient) SyncProgress(arg0 context.Context) (*ethereum.SyncProgress, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SyncProgress", arg0) - ret0, _ := ret[0].(*ethereum.SyncProgress) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// SyncProgress indicates an expected call of SyncProgress. -func (mr *MockEthClientMockRecorder) SyncProgress(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SyncProgress", reflect.TypeOf((*MockEthClient)(nil).SyncProgress), arg0) -} - -// TransactionByHash mocks base method. -func (m *MockEthClient) TransactionByHash(arg0 context.Context, arg1 common.Hash) (*types.Transaction, bool, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "TransactionByHash", arg0, arg1) - ret0, _ := ret[0].(*types.Transaction) - ret1, _ := ret[1].(bool) - ret2, _ := ret[2].(error) - return ret0, ret1, ret2 -} - -// TransactionByHash indicates an expected call of TransactionByHash. -func (mr *MockEthClientMockRecorder) TransactionByHash(arg0, arg1 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TransactionByHash", reflect.TypeOf((*MockEthClient)(nil).TransactionByHash), arg0, arg1) -} - -// TransactionCount mocks base method. -func (m *MockEthClient) TransactionCount(arg0 context.Context, arg1 common.Hash) (uint, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "TransactionCount", arg0, arg1) - ret0, _ := ret[0].(uint) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// TransactionCount indicates an expected call of TransactionCount. -func (mr *MockEthClientMockRecorder) TransactionCount(arg0, arg1 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TransactionCount", reflect.TypeOf((*MockEthClient)(nil).TransactionCount), arg0, arg1) -} - -// TransactionInBlock mocks base method. -func (m *MockEthClient) TransactionInBlock(arg0 context.Context, arg1 common.Hash, arg2 uint) (*types.Transaction, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "TransactionInBlock", arg0, arg1, arg2) - ret0, _ := ret[0].(*types.Transaction) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// TransactionInBlock indicates an expected call of TransactionInBlock. -func (mr *MockEthClientMockRecorder) TransactionInBlock(arg0, arg1, arg2 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TransactionInBlock", reflect.TypeOf((*MockEthClient)(nil).TransactionInBlock), arg0, arg1, arg2) -} - -// TransactionReceipt mocks base method. -func (m *MockEthClient) TransactionReceipt(arg0 context.Context, arg1 common.Hash) (*types.Receipt, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "TransactionReceipt", arg0, arg1) - ret0, _ := ret[0].(*types.Receipt) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// TransactionReceipt indicates an expected call of TransactionReceipt. -func (mr *MockEthClientMockRecorder) TransactionReceipt(arg0, arg1 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TransactionReceipt", reflect.TypeOf((*MockEthClient)(nil).TransactionReceipt), arg0, arg1) -} - -// TransactionSender mocks base method. -func (m *MockEthClient) TransactionSender(arg0 context.Context, arg1 *types.Transaction, arg2 common.Hash, arg3 uint) (common.Address, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "TransactionSender", arg0, arg1, arg2, arg3) - ret0, _ := ret[0].(common.Address) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// TransactionSender indicates an expected call of TransactionSender. -func (mr *MockEthClientMockRecorder) TransactionSender(arg0, arg1, arg2, arg3 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TransactionSender", reflect.TypeOf((*MockEthClient)(nil).TransactionSender), arg0, arg1, arg2, arg3) -} diff --git a/chainio/txmgr/txmgr.go b/chainio/txmgr/txmgr.go index 5df7da23..d237840d 100644 --- a/chainio/txmgr/txmgr.go +++ b/chainio/txmgr/txmgr.go @@ -6,7 +6,6 @@ import ( "math/big" "time" - "github.com/Layr-Labs/eigensdk-go/chainio/clients/eth" "github.com/Layr-Labs/eigensdk-go/chainio/clients/wallet" "github.com/Layr-Labs/eigensdk-go/logging" "github.com/ethereum/go-ethereum" @@ -38,9 +37,15 @@ type TxManager interface { GetNoSendTxOpts() (*bind.TransactOpts, error) } +type ethClient interface { + SuggestGasTipCap(ctx context.Context) (*big.Int, error) + HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) + EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error) +} + type SimpleTxManager struct { wallet wallet.Wallet - client eth.Client + client ethClient log logging.Logger sender common.Address gasLimitMultiplier float64 @@ -52,7 +57,7 @@ var _ TxManager = (*SimpleTxManager)(nil) // to send a transaction to smart contracts on the Ethereum node func NewSimpleTxManager( wallet wallet.Wallet, - client eth.Client, + client ethClient, log logging.Logger, sender common.Address, ) *SimpleTxManager { diff --git a/internal/fakes/eth_client.go b/internal/fakes/eth_client.go new file mode 100644 index 00000000..7c167443 --- /dev/null +++ b/internal/fakes/eth_client.go @@ -0,0 +1,95 @@ +package fakes + +import ( + "context" + "errors" + "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "math/big" +) + +const ( + TransactionHash = "0x0000000000000000000000000000000000000000000000000000000000001234" + TransactionNashNotInFake = "0xabcd" + BlockNumber = 1234 +) + +type EthClient struct { + chainId *big.Int + successfulTxs map[common.Hash]bool +} + +// NewEthClient returns a new instance of the EthClient +// Right now this client is hardcoded with some values to satisfy current +// testing requirements, but it can be extended to support more features and +// can be made more generic over time when we add more tests. +// Currently used in +// - chainio/clients/wallet/fireblocks_wallet_test.go +func NewEthClient() *EthClient { + return &EthClient{ + chainId: big.NewInt(5), + successfulTxs: map[common.Hash]bool{ + common.HexToHash(TransactionHash): true, + }, + } +} + +func (f *EthClient) ChainID(ctx context.Context) (*big.Int, error) { + return f.chainId, nil +} + +func (f *EthClient) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) { + if _, ok := f.successfulTxs[txHash]; !ok { + return nil, errors.New("tx not found") + } + + return &types.Receipt{ + TxHash: txHash, + BlockNumber: big.NewInt(BlockNumber), + }, nil +} + +func (f *EthClient) CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error) { + return []byte{}, nil +} + +func (f *EthClient) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) { + return []byte{}, nil +} + +func (f *EthClient) EstimateGas(ctx context.Context, call ethereum.CallMsg) (uint64, error) { + return 0, nil +} + +func (f *EthClient) SuggestGasPrice(ctx context.Context) (*big.Int, error) { + return big.NewInt(0), nil +} + +func (f *EthClient) SuggestGasTipCap(ctx context.Context) (*big.Int, error) { + return big.NewInt(0), nil +} + +func (f *EthClient) SendTransaction(ctx context.Context, tx *types.Transaction) error { + return nil +} + +func (f *EthClient) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) { + return &types.Header{}, nil +} + +func (f *EthClient) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error) { + return []byte{}, nil +} + +func (f *EthClient) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) { + return 0, nil +} + +func (f *EthClient) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error) { + return []types.Log{}, nil +} + +func (f *EthClient) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error) { + return nil, nil +} diff --git a/logging/noop_logger.go b/logging/noop_logger.go deleted file mode 100644 index 7af1db0b..00000000 --- a/logging/noop_logger.go +++ /dev/null @@ -1,43 +0,0 @@ -package logging - -type NoopLogger struct{} - -var _ Logger = (*NoopLogger)(nil) - -func NewNoopLogger() Logger { - return &NoopLogger{} -} - -func (l *NoopLogger) Debug(msg string, tags ...any) {} - -func (l *NoopLogger) Info(msg string, tags ...any) {} - -func (l *NoopLogger) Warn(msg string, tags ...any) {} - -func (l *NoopLogger) Error(msg string, tags ...any) {} - -func (l *NoopLogger) Fatal(msg string, tags ...any) {} - -func (l *NoopLogger) Debugm(msg string, tags map[string]any) {} - -func (l *NoopLogger) Infom(msg string, tags map[string]any) {} - -func (l *NoopLogger) Warnm(msg string, tags map[string]any) {} - -func (l *NoopLogger) Errorm(msg string, tags map[string]any) {} - -func (l *NoopLogger) Fatalm(msg string, tags map[string]any) {} - -func (l *NoopLogger) Debugf(template string, args ...interface{}) {} - -func (l *NoopLogger) Infof(template string, args ...interface{}) {} - -func (l *NoopLogger) Warnf(template string, args ...interface{}) {} - -func (l *NoopLogger) Errorf(template string, args ...interface{}) {} - -func (l *NoopLogger) Fatalf(template string, args ...interface{}) {} - -func (l *NoopLogger) With(tags ...any) Logger { - return l -} diff --git a/metrics/collectors/economic/economic_test.go b/metrics/collectors/economic/economic_test.go index 671fb489..4e1ed81b 100644 --- a/metrics/collectors/economic/economic_test.go +++ b/metrics/collectors/economic/economic_test.go @@ -11,7 +11,7 @@ import ( "github.com/stretchr/testify/assert" "go.uber.org/mock/gomock" - "github.com/Layr-Labs/eigensdk-go/logging" + "github.com/Layr-Labs/eigensdk-go/testutils" "github.com/Layr-Labs/eigensdk-go/types" ) @@ -74,7 +74,7 @@ func TestEconomicCollector(t *testing.T) { elReader := newFakeELReader() avsRegistryReader := newFakeAVSRegistryReader() - logger := logging.NewNoopLogger() + logger := testutils.GetTestLogger() economicCollector := NewCollector(elReader, avsRegistryReader, "testavs", logger, operatorAddr, quorumNames) count := testutil.CollectAndCount(economicCollector, "eigen_slashing_status", "eigen_registered_stakes") diff --git a/metrics/eigenmetrics_test.go b/metrics/eigenmetrics_test.go index cfd4d301..ab1acbfe 100644 --- a/metrics/eigenmetrics_test.go +++ b/metrics/eigenmetrics_test.go @@ -7,12 +7,13 @@ import ( "testing" "time" + "github.com/Layr-Labs/eigensdk-go/testutils" + "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/testutil" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" - - "github.com/Layr-Labs/eigensdk-go/logging" ) type MetricsTestSuite struct { @@ -23,7 +24,7 @@ type MetricsTestSuite struct { // this runs before all tests to initialize reg and metrics func (suite *MetricsTestSuite) SetupTest() { - logger := logging.NewNoopLogger() + logger := testutils.GetTestLogger() // create and start the metrics server suite.reg = prometheus.NewRegistry() suite.metrics = NewEigenMetrics("testavs", "localhost:9090", suite.reg, logger) diff --git a/nodeapi/nodeapi_test.go b/nodeapi/nodeapi_test.go index a3012c2f..dadb8176 100644 --- a/nodeapi/nodeapi_test.go +++ b/nodeapi/nodeapi_test.go @@ -7,13 +7,13 @@ import ( "testing" "time" - "github.com/stretchr/testify/assert" + "github.com/Layr-Labs/eigensdk-go/testutils" - "github.com/Layr-Labs/eigensdk-go/logging" + "github.com/stretchr/testify/assert" ) -var noopLogger = logging.NewNoopLogger() -var testNodeApi = NewNodeApi("testAvs", "v0.0.1", "localhost:8080", noopLogger) +var logger = testutils.GetTestLogger() +var testNodeApi = NewNodeApi("testAvs", "v0.0.1", "localhost:8080", logger) // just making sure that the nodeapi starts without any errors func TestStart(t *testing.T) { @@ -56,7 +56,7 @@ func TestHealthHandler(t *testing.T) { }, "partially healthy": { nodeApi: func() *NodeApi { - nodeApi := NewNodeApi("testAvs", "v0.0.1", "localhost:8080", noopLogger) + nodeApi := NewNodeApi("testAvs", "v0.0.1", "localhost:8080", logger) nodeApi.UpdateHealth(PartiallyHealthy) return nodeApi }(), @@ -65,7 +65,7 @@ func TestHealthHandler(t *testing.T) { }, "unhealthy": { nodeApi: func() *NodeApi { - nodeApi := NewNodeApi("testAvs", "v0.0.1", "localhost:8080", noopLogger) + nodeApi := NewNodeApi("testAvs", "v0.0.1", "localhost:8080", logger) nodeApi.UpdateHealth(Unhealthy) return nodeApi }(), @@ -106,7 +106,7 @@ func TestServicesHandler(t *testing.T) { }, "one service": { nodeApi: func() *NodeApi { - nodeApi := NewNodeApi("testAvs", "v0.0.1", "localhost:8080", noopLogger) + nodeApi := NewNodeApi("testAvs", "v0.0.1", "localhost:8080", logger) nodeApi.RegisterNewService("testServiceId", "testServiceName", "testServiceDescription", ServiceStatusUp) return nodeApi }(), @@ -115,7 +115,7 @@ func TestServicesHandler(t *testing.T) { }, "two services": { nodeApi: func() *NodeApi { - nodeApi := NewNodeApi("testAvs", "v0.0.1", "localhost:8080", noopLogger) + nodeApi := NewNodeApi("testAvs", "v0.0.1", "localhost:8080", logger) nodeApi.RegisterNewService("testServiceId", "testServiceName", "testServiceDescription", ServiceStatusUp) nodeApi.RegisterNewService("testServiceId2", "testServiceName2", "testServiceDescription2", ServiceStatusDown) return nodeApi diff --git a/services/avsregistry/avsregistry_chaincaller_test.go b/services/avsregistry/avsregistry_chaincaller_test.go index a334be73..5da31fd2 100644 --- a/services/avsregistry/avsregistry_chaincaller_test.go +++ b/services/avsregistry/avsregistry_chaincaller_test.go @@ -10,7 +10,7 @@ import ( "github.com/Layr-Labs/eigensdk-go/crypto/bls" "github.com/Layr-Labs/eigensdk-go/internal/fakes" - "github.com/Layr-Labs/eigensdk-go/logging" + "github.com/Layr-Labs/eigensdk-go/testutils" "github.com/Layr-Labs/eigensdk-go/types" "github.com/ethereum/go-ethereum/common" @@ -31,7 +31,7 @@ func (f *fakeOperatorInfoService) GetOperatorInfo(ctx context.Context, operator } func TestAvsRegistryServiceChainCaller_getOperatorPubkeys(t *testing.T) { - logger := logging.NewNoopLogger() + logger := testutils.GetTestLogger() testOperator1 := fakes.TestOperator{ OperatorAddr: common.HexToAddress("0x1"), OperatorId: types.OperatorId{1}, @@ -83,7 +83,7 @@ func TestAvsRegistryServiceChainCaller_getOperatorPubkeys(t *testing.T) { } func TestAvsRegistryServiceChainCaller_GetOperatorsAvsState(t *testing.T) { - logger := logging.NewNoopLogger() + logger := testutils.GetTestLogger() testOperator1 := fakes.TestOperator{ OperatorAddr: common.HexToAddress("0x1"), OperatorId: types.OperatorId{1}, @@ -143,7 +143,7 @@ func TestAvsRegistryServiceChainCaller_GetOperatorsAvsState(t *testing.T) { } func TestAvsRegistryServiceChainCaller_GetQuorumsAvsState(t *testing.T) { - logger := logging.NewNoopLogger() + logger := testutils.GetTestLogger() testOperator1 := fakes.TestOperator{ OperatorAddr: common.HexToAddress("0x1"), OperatorId: types.OperatorId{1}, diff --git a/services/bls_aggregation/blsagg_test.go b/services/bls_aggregation/blsagg_test.go index 47211b37..96bfa951 100644 --- a/services/bls_aggregation/blsagg_test.go +++ b/services/bls_aggregation/blsagg_test.go @@ -4,6 +4,7 @@ import ( "context" "crypto/sha256" "encoding/json" + "github.com/ethereum/go-ethereum/ethclient" "log/slog" "math/big" "os" @@ -11,7 +12,6 @@ import ( "time" "github.com/Layr-Labs/eigensdk-go/chainio/clients" - "github.com/Layr-Labs/eigensdk-go/chainio/clients/eth" "github.com/Layr-Labs/eigensdk-go/chainio/utils" "github.com/Layr-Labs/eigensdk-go/crypto/bls" "github.com/Layr-Labs/eigensdk-go/logging" @@ -77,8 +77,8 @@ func TestBlsAgg(t *testing.T) { blsSig := testOperator1.BlsKeypair.SignMessage(taskResponseDigest) fakeAvsRegistryService := avsregistry.NewFakeAvsRegistryService(blockNum, []types.TestOperator{testOperator1}) - noopLogger := logging.NewNoopLogger() - blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, noopLogger) + logger := testutils.GetTestLogger() + blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, logger) err = blsAggServ.InitializeNewTask(taskIndex, blockNum, quorumNumbers, quorumThresholdPercentages, tasksTimeToExpiry) require.Nil(t, err) @@ -125,8 +125,8 @@ func TestBlsAgg(t *testing.T) { require.Nil(t, err) fakeAvsRegistryService := avsregistry.NewFakeAvsRegistryService(blockNum, []types.TestOperator{testOperator1, testOperator2, testOperator3}) - noopLogger := logging.NewNoopLogger() - blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, noopLogger) + logger := testutils.GetTestLogger() + blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, logger) err = blsAggServ.InitializeNewTask(taskIndex, blockNum, quorumNumbers, quorumThresholdPercentages, tasksTimeToExpiry) require.Nil(t, err) @@ -182,8 +182,8 @@ func TestBlsAgg(t *testing.T) { require.Nil(t, err) fakeAvsRegistryService := avsregistry.NewFakeAvsRegistryService(blockNum, []types.TestOperator{testOperator1, testOperator2}) - noopLogger := logging.NewNoopLogger() - blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, noopLogger) + logger := testutils.GetTestLogger() + blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, logger) err = blsAggServ.InitializeNewTask(taskIndex, blockNum, quorumNumbers, quorumThresholdPercentages, tasksTimeToExpiry) require.Nil(t, err) @@ -227,8 +227,8 @@ func TestBlsAgg(t *testing.T) { blockNum := uint32(1) fakeAvsRegistryService := avsregistry.NewFakeAvsRegistryService(blockNum, []types.TestOperator{testOperator1, testOperator2}) - noopLogger := logging.NewNoopLogger() - blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, noopLogger) + logger := testutils.GetTestLogger() + blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, logger) // initialize 2 concurrent tasks task1Index := types.TaskIndex(1) @@ -309,8 +309,8 @@ func TestBlsAgg(t *testing.T) { blockNum := uint32(1) fakeAvsRegistryService := avsregistry.NewFakeAvsRegistryService(blockNum, []types.TestOperator{testOperator1}) - noopLogger := logging.NewNoopLogger() - blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, noopLogger) + logger := testutils.GetTestLogger() + blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, logger) err := blsAggServ.InitializeNewTask(taskIndex, blockNum, quorumNumbers, quorumThresholdPercentages, tasksTimeToExpiry) require.Nil(t, err) @@ -342,8 +342,8 @@ func TestBlsAgg(t *testing.T) { blockNum := uint32(1) fakeAvsRegistryService := avsregistry.NewFakeAvsRegistryService(blockNum, []types.TestOperator{testOperator1, testOperator2}) - noopLogger := logging.NewNoopLogger() - blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, noopLogger) + logger := testutils.GetTestLogger() + blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, logger) err = blsAggServ.InitializeNewTask(taskIndex, blockNum, quorumNumbers, quorumThresholdPercentages, tasksTimeToExpiry) require.Nil(t, err) @@ -384,8 +384,8 @@ func TestBlsAgg(t *testing.T) { blsSig := testOperator1.BlsKeypair.SignMessage(taskResponseDigest) fakeAvsRegistryService := avsregistry.NewFakeAvsRegistryService(blockNum, []types.TestOperator{testOperator1, testOperator2}) - noopLogger := logging.NewNoopLogger() - blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, noopLogger) + logger := testutils.GetTestLogger() + blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, logger) err = blsAggServ.InitializeNewTask(taskIndex, blockNum, quorumNumbers, quorumThresholdPercentages, tasksTimeToExpiry) require.Nil(t, err) @@ -420,8 +420,8 @@ func TestBlsAgg(t *testing.T) { blockNum := uint32(1) fakeAvsRegistryService := avsregistry.NewFakeAvsRegistryService(blockNum, []types.TestOperator{testOperator1, testOperator2}) - noopLogger := logging.NewNoopLogger() - blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, noopLogger) + logger := testutils.GetTestLogger() + blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, logger) err = blsAggServ.InitializeNewTask(taskIndex, blockNum, quorumNumbers, quorumThresholdPercentages, tasksTimeToExpiry) require.Nil(t, err) @@ -476,8 +476,8 @@ func TestBlsAgg(t *testing.T) { blockNum := uint32(1) fakeAvsRegistryService := avsregistry.NewFakeAvsRegistryService(blockNum, []types.TestOperator{testOperator1, testOperator2, testOperator3}) - noopLogger := logging.NewNoopLogger() - blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, noopLogger) + logger := testutils.GetTestLogger() + blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, logger) err = blsAggServ.InitializeNewTask(taskIndex, blockNum, quorumNumbers, quorumThresholdPercentages, tasksTimeToExpiry) require.Nil(t, err) @@ -534,8 +534,8 @@ func TestBlsAgg(t *testing.T) { blockNum := uint32(1) fakeAvsRegistryService := avsregistry.NewFakeAvsRegistryService(blockNum, []types.TestOperator{testOperator1, testOperator2, testOperator3}) - noopLogger := logging.NewNoopLogger() - blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, noopLogger) + logger := testutils.GetTestLogger() + blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, logger) err = blsAggServ.InitializeNewTask(taskIndex, blockNum, quorumNumbers, quorumThresholdPercentages, tasksTimeToExpiry) require.Nil(t, err) @@ -570,8 +570,8 @@ func TestBlsAgg(t *testing.T) { blockNum := uint32(1) fakeAvsRegistryService := avsregistry.NewFakeAvsRegistryService(blockNum, []types.TestOperator{testOperator1}) - noopLogger := logging.NewNoopLogger() - blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, noopLogger) + logger := testutils.GetTestLogger() + blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, logger) err = blsAggServ.InitializeNewTask(taskIndex, blockNum, quorumNumbers, quorumThresholdPercentages, tasksTimeToExpiry) require.Nil(t, err) @@ -608,8 +608,8 @@ func TestBlsAgg(t *testing.T) { blockNum := uint32(1) fakeAvsRegistryService := avsregistry.NewFakeAvsRegistryService(blockNum, []types.TestOperator{testOperator1, testOperator2}) - noopLogger := logging.NewNoopLogger() - blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, noopLogger) + logger := testutils.GetTestLogger() + blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, logger) err = blsAggServ.InitializeNewTask(taskIndex, blockNum, quorumNumbers, quorumThresholdPercentages, tasksTimeToExpiry) require.Nil(t, err) @@ -639,8 +639,8 @@ func TestBlsAgg(t *testing.T) { blsSig := testOperator1.BlsKeypair.SignMessage(taskResponseDigest) fakeAvsRegistryService := avsregistry.NewFakeAvsRegistryService(blockNum, []types.TestOperator{testOperator1}) - noopLogger := logging.NewNoopLogger() - blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, noopLogger) + logger := testutils.GetTestLogger() + blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, logger) err = blsAggServ.ProcessNewSignature(context.Background(), taskIndex, taskResponse, blsSig, testOperator1.OperatorId) require.Equal(t, TaskNotFoundErrorFn(taskIndex), err) @@ -665,8 +665,8 @@ func TestBlsAgg(t *testing.T) { quorumThresholdPercentages := []types.QuorumThresholdPercentage{100} fakeAvsRegistryService := avsregistry.NewFakeAvsRegistryService(blockNum, []types.TestOperator{testOperator1}) - noopLogger := logging.NewNoopLogger() - blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, noopLogger) + logger := testutils.GetTestLogger() + blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, logger) err := blsAggServ.InitializeNewTask(taskIndex, blockNum, quorumNumbers, quorumThresholdPercentages, tasksTimeToExpiry) require.Nil(t, err) @@ -719,8 +719,8 @@ func TestBlsAgg(t *testing.T) { quorumThresholdPercentages := []types.QuorumThresholdPercentage{100} fakeAvsRegistryService := avsregistry.NewFakeAvsRegistryService(blockNum, []types.TestOperator{testOperator1, testOperator2}) - noopLogger := logging.NewNoopLogger() - blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, noopLogger) + logger := testutils.GetTestLogger() + blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, logger) err := blsAggServ.InitializeNewTask(taskIndex, blockNum, quorumNumbers, quorumThresholdPercentages, tasksTimeToExpiry) require.Nil(t, err) @@ -762,8 +762,8 @@ func TestBlsAgg(t *testing.T) { blsSig := testOperator1.BlsKeypair.SignMessage(taskResponseDigest) fakeAvsRegistryService := avsregistry.NewFakeAvsRegistryService(blockNum, []types.TestOperator{testOperator1}) - noopLogger := logging.NewNoopLogger() - blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, noopLogger) + logger := testutils.GetTestLogger() + blsAggServ := NewBlsAggregatorService(fakeAvsRegistryService, hashFunction, logger) err = blsAggServ.InitializeNewTask(taskIndex, blockNum, quorumNumbers, quorumThresholdPercentages, tasksTimeToExpiry) require.Nil(t, err) @@ -805,7 +805,7 @@ func TestIntegrationBlsAgg(t *testing.T) { operatorId := types.OperatorIdFromG1Pubkey(blsKeyPair.GetPubKeyG1()) // create avs clients to interact with contracts deployed on anvil - ethHttpClient, err := eth.NewClient(anvilHttpEndpoint) + ethHttpClient, err := ethclient.Dial(anvilHttpEndpoint) require.NoError(t, err) logger := logging.NewTextSLogger(os.Stdout, &logging.SLoggerOptions{Level: slog.LevelDebug}) avsClients, err := clients.BuildAll(clients.BuildAllConfig{ diff --git a/signer/basic_signer.go b/signer/basic_signer.go index 59eecb5d..8ff440bb 100644 --- a/signer/basic_signer.go +++ b/signer/basic_signer.go @@ -6,7 +6,6 @@ import ( "fmt" "math/big" - sdkethclient "github.com/Layr-Labs/eigensdk-go/chainio/clients/eth" "github.com/Layr-Labs/eigensdk-go/logging" "github.com/Layr-Labs/eigensdk-go/utils" @@ -20,10 +19,17 @@ import ( // exported as the default so that users can call NewBasicSigner with it if they don't know any better var FallbackGasTipCap = big.NewInt(15000000000) +type ethClient interface { + bind.ContractBackend + + ChainID(ctx context.Context) (*big.Int, error) + TransactionReceipt(ctx context.Context, txHash gethcommon.Hash) (*gethtypes.Receipt, error) +} + // Deprecated: Use SignerV2 instead type BasicSigner struct { logger logging.Logger - ethClient sdkethclient.Client + ethClient ethClient privateKey *ecdsa.PrivateKey accountAddress gethcommon.Address contracts map[gethcommon.Address]*bind.BoundContract @@ -32,7 +38,7 @@ type BasicSigner struct { func NewBasicSigner( privateKey *ecdsa.PrivateKey, - ethClient sdkethclient.Client, + client ethClient, logger logging.Logger, fallbackGasTipCap *big.Int, ) (*BasicSigner, error) { @@ -44,7 +50,7 @@ func NewBasicSigner( return &BasicSigner{ logger: logger, - ethClient: ethClient, + ethClient: client, privateKey: privateKey, accountAddress: accountAddress, contracts: make(map[gethcommon.Address]*bind.BoundContract), diff --git a/signerv2/kms_signer_test.go b/signerv2/kms_signer_test.go index ec2cdde0..b08d6990 100644 --- a/signerv2/kms_signer_test.go +++ b/signerv2/kms_signer_test.go @@ -8,18 +8,21 @@ import ( "testing" eigenkms "github.com/Layr-Labs/eigensdk-go/aws/kms" - "github.com/Layr-Labs/eigensdk-go/chainio/clients/eth" "github.com/Layr-Labs/eigensdk-go/chainio/clients/wallet" "github.com/Layr-Labs/eigensdk-go/chainio/txmgr" - "github.com/Layr-Labs/eigensdk-go/logging" "github.com/Layr-Labs/eigensdk-go/signerv2" "github.com/Layr-Labs/eigensdk-go/testutils" + "github.com/aws/aws-sdk-go-v2/service/kms/types" + "github.com/ethereum/go-ethereum/common" gtypes "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/rpc" + "github.com/stretchr/testify/assert" + "github.com/testcontainers/testcontainers-go" ) @@ -94,8 +97,8 @@ func TestSendTransaction(t *testing.T) { err = rpcClient.CallContext(context.Background(), nil, "anvil_setBalance", keyAddr, 2_000_000_000_000_000_000) assert.Nil(t, err) - logger := &logging.NoopLogger{} - ethClient, err := eth.NewClient(anvilEndpoint) + logger := testutils.GetTestLogger() + ethClient, err := ethclient.Dial(anvilEndpoint) assert.Nil(t, err) chainID, err := ethClient.ChainID(context.Background()) assert.Nil(t, err) diff --git a/testutils/anvil.go b/testutils/anvil.go index f7fb6d20..c4da31ca 100644 --- a/testutils/anvil.go +++ b/testutils/anvil.go @@ -3,12 +3,12 @@ package testutils import ( "context" "fmt" + "github.com/ethereum/go-ethereum/ethclient" "log" "os/exec" "path/filepath" "runtime" - "github.com/Layr-Labs/eigensdk-go/chainio/clients/eth" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/testcontainers/testcontainers-go" @@ -64,7 +64,7 @@ type ContractAddresses struct { } func GetContractAddressesFromContractRegistry(ethHttpUrl string) (mockAvsContracts ContractAddresses) { - ethHttpClient, err := eth.NewClient(ethHttpUrl) + ethHttpClient, err := ethclient.Dial(ethHttpUrl) if err != nil { panic(err) } diff --git a/testutils/logger.go b/testutils/logger.go new file mode 100644 index 00000000..81df561e --- /dev/null +++ b/testutils/logger.go @@ -0,0 +1,17 @@ +package testutils + +import ( + "log/slog" + "os" + + "github.com/Layr-Labs/eigensdk-go/logging" +) + +func GetTestLogger() logging.Logger { + return logging.NewTextSLogger(os.Stdout, + &logging.SLoggerOptions{ + Level: slog.LevelDebug, + AddSource: true, + }, + ) +}