From e9e320be9e8b98ce327c3fe03362226a5363c63c Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Fri, 17 Jan 2025 14:48:27 -0300 Subject: [PATCH 01/10] Add error returning in contract tests cases --- chainio/clients/elcontracts/reader_test.go | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/chainio/clients/elcontracts/reader_test.go b/chainio/clients/elcontracts/reader_test.go index 13d8b9e3..fb5f0d7f 100644 --- a/chainio/clients/elcontracts/reader_test.go +++ b/chainio/clients/elcontracts/reader_test.go @@ -734,3 +734,41 @@ func TestAppointeesFunctions(t *testing.T) { assert.NotEmpty(t, appointeesPermission) }) } + +func TestContractErrorCases(t *testing.T) { + ctx := context.Background() + + testConfig := testutils.GetDefaultTestConfig() + anvilC, err := testutils.StartAnvilContainer(testConfig.AnvilStateFileName) + require.NoError(t, err) + + anvilHttpEndpoint, err := anvilC.Endpoint(context.Background(), "http") + require.NoError(t, err) + contractAddrs := testutils.GetContractAddressesFromContractRegistry(anvilHttpEndpoint) + + config := elcontracts.Config{ + DelegationManagerAddress: contractAddrs.DelegationManager, + } + + chainReader, err := testclients.NewTestChainReaderFromConfig(anvilHttpEndpoint, config) + require.NoError(t, err) + + strategyAddr := common.HexToAddress("34634374736473673643") + + t.Run("GetStrategyAndUnderlyingToken", func(t *testing.T) { + strategy, undToken, err := chainReader.GetStrategyAndUnderlyingToken(ctx, strategyAddr) + assert.Zero(t, strategy) + assert.Zero(t, undToken) + assert.Error(t, err) + assert.Equal(t, err.Error(), "Failed to fetch token contract: no contract code at given address") + }) + + t.Run("GetStrategyAndUnderlyingERC20Token", func(t *testing.T) { + strategy, methods, undToken, err := chainReader.GetStrategyAndUnderlyingERC20Token(ctx, strategyAddr) + assert.Zero(t, strategy) + assert.Zero(t, methods) + assert.Zero(t, undToken) + assert.Error(t, err) + assert.Equal(t, err.Error(), "Failed to fetch token contract: no contract code at given address") + }) +} From 0bb669c77844c8089951a6b230637a15b0c56643 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Mon, 20 Jan 2025 11:44:34 -0300 Subject: [PATCH 02/10] Add comments in reader's non-failing binding calls --- chainio/clients/elcontracts/reader.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index 972b627d..1872967c 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -103,6 +103,7 @@ func (r *ChainReader) IsOperatorRegistered( &bind.CallOpts{Context: ctx}, gethcommon.HexToAddress(operator.Address), ) + // This call should not fail since it's a getter if err != nil { return false, err } @@ -140,6 +141,7 @@ func (r *ChainReader) GetOperatorDetails( &bind.CallOpts{Context: ctx}, gethcommon.HexToAddress(operator.Address), ) + // This call should not fail since it's a getter if err != nil { return types.Operator{}, err } @@ -150,6 +152,7 @@ func (r *ChainReader) GetOperatorDetails( }, gethcommon.HexToAddress(operator.Address), ) + // This call should not fail if err != nil { return types.Operator{}, err } @@ -174,6 +177,7 @@ func (r *ChainReader) GetStrategyAndUnderlyingToken( strategyAddr gethcommon.Address, ) (*strategy.ContractIStrategy, gethcommon.Address, error) { contractStrategy, err := strategy.NewContractIStrategy(strategyAddr, r.ethClient) + // This call should not fail since it's an init if err != nil { return nil, gethcommon.Address{}, utils.WrapError("Failed to fetch strategy contract", err) } @@ -191,6 +195,7 @@ func (r *ChainReader) GetStrategyAndUnderlyingERC20Token( strategyAddr gethcommon.Address, ) (*strategy.ContractIStrategy, erc20.ContractIERC20Methods, gethcommon.Address, error) { contractStrategy, err := strategy.NewContractIStrategy(strategyAddr, r.ethClient) + // This call should not fail since it's an init if err != nil { return nil, nil, gethcommon.Address{}, utils.WrapError("Failed to fetch strategy contract", err) } @@ -199,6 +204,7 @@ func (r *ChainReader) GetStrategyAndUnderlyingERC20Token( return nil, nil, gethcommon.Address{}, utils.WrapError("Failed to fetch token contract", err) } contractUnderlyingToken, err := erc20.NewContractIERC20(underlyingTokenAddr, r.ethClient) + // This call should not fail, if strategy has no underlying token then enters the if above if err != nil { return nil, nil, gethcommon.Address{}, utils.WrapError("Failed to fetch token contract", err) } @@ -336,6 +342,7 @@ func (r *ChainReader) GetOperatorAVSSplit( split, err := r.rewardsCoordinator.GetOperatorAVSSplit(&bind.CallOpts{Context: ctx}, operator, avs) + // This call should not fail since it's a getter if err != nil { return 0, err } @@ -353,6 +360,7 @@ func (r *ChainReader) GetOperatorPISplit( split, err := r.rewardsCoordinator.GetOperatorPISplit(&bind.CallOpts{Context: ctx}, operator) + // This call should not fail since it's a getter if err != nil { return 0, err } @@ -398,6 +406,7 @@ func (r *ChainReader) GetAllocationInfo( operatorAddress, strategyAddress, ) + // This call should not fail since it's a getter if err != nil { return nil, err } @@ -474,6 +483,7 @@ func (r *ChainReader) IsOperatorRegisteredWithOperatorSet( if operatorSet.Id == 0 { // this is an M2 AVS status, err := r.avsDirectory.AvsOperatorStatus(&bind.CallOpts{Context: ctx}, operatorSet.Avs, operatorAddress) + // This call should not fail since it's a getter if err != nil { return false, err } @@ -481,6 +491,7 @@ func (r *ChainReader) IsOperatorRegisteredWithOperatorSet( return status == 1, nil } else { registeredOperatorSets, err := r.allocationManager.GetRegisteredSets(&bind.CallOpts{Context: ctx}, operatorAddress) + // This call should not fail since it's a getter if err != nil { return false, err } @@ -543,6 +554,7 @@ func (r *ChainReader) GetSlashableShares( } currentBlock, err := r.ethClient.BlockNumber(ctx) + // This call should not fail since it's a getter if err != nil { return nil, err } @@ -554,6 +566,7 @@ func (r *ChainReader) GetSlashableShares( strategies, uint32(currentBlock), ) + // This call should not fail since it's a getter if err != nil { return nil, err } @@ -578,6 +591,7 @@ func (r *ChainReader) GetSlashableSharesForOperatorSets( operatorSets []allocationmanager.OperatorSet, ) ([]OperatorSetStakes, error) { currentBlock, err := r.ethClient.BlockNumber(ctx) + // This call should not fail since it's a getter if err != nil { return nil, err } @@ -602,6 +616,7 @@ func (r *ChainReader) GetSlashableSharesForOperatorSetsBefore( } strategies, err := r.GetStrategiesForOperatorSet(ctx, operatorSet) + // If operator setId is 0 will fail on if above if err != nil { return nil, err } @@ -616,6 +631,7 @@ func (r *ChainReader) GetSlashableSharesForOperatorSetsBefore( strategies, futureBlock, ) + // This call should not fail since it's a getter if err != nil { return nil, err } @@ -639,6 +655,7 @@ func (r *ChainReader) GetAllocationDelay( return 0, errors.New("AllocationManager contract not provided") } isSet, delay, err := r.allocationManager.GetAllocationDelay(&bind.CallOpts{Context: ctx}, operatorAddress) + // This call should not fail since it's a getter if err != nil { return 0, err } @@ -672,6 +689,7 @@ func (r *ChainReader) CanCall( target, selector, ) + // This call should not fail since it's a getter if err != nil { return false, errors.New("call to permission controller failed: " + err.Error()) } @@ -690,6 +708,7 @@ func (r *ChainReader) ListAppointees( target, selector, ) + // This call should not fail since it's a getter if err != nil { return nil, errors.New("call to permission controller failed: " + err.Error()) } @@ -706,6 +725,7 @@ func (r *ChainReader) ListAppointeePermissions( accountAddress, appointeeAddress, ) + // This call should not fail since it's a getter if err != nil { return nil, nil, errors.New("call to permission controller failed: " + err.Error()) } @@ -717,6 +737,7 @@ func (r *ChainReader) ListPendingAdmins( accountAddress gethcommon.Address, ) ([]gethcommon.Address, error) { pendingAdmins, err := r.permissionController.GetPendingAdmins(&bind.CallOpts{Context: ctx}, accountAddress) + // This call should not fail since it's a getter if err != nil { return nil, errors.New("call to permission controller failed: " + err.Error()) } @@ -728,6 +749,7 @@ func (r *ChainReader) ListAdmins( accountAddress gethcommon.Address, ) ([]gethcommon.Address, error) { pendingAdmins, err := r.permissionController.GetAdmins(&bind.CallOpts{Context: ctx}, accountAddress) + // This call should not fail since it's a getter if err != nil { return nil, errors.New("call to permission controller failed: " + err.Error()) } @@ -744,6 +766,7 @@ func (r *ChainReader) IsPendingAdmin( accountAddress, pendingAdminAddress, ) + // This call should not fail since it's a getter if err != nil { return isPendingAdmin, errors.New("call to permission controller failed: " + err.Error()) } @@ -756,6 +779,7 @@ func (r *ChainReader) IsAdmin( adminAddress gethcommon.Address, ) (bool, error) { isAdmin, err := r.permissionController.IsAdmin(&bind.CallOpts{Context: ctx}, accountAddress, adminAddress) + // This call should not fail since it's a getter if err != nil { return isAdmin, errors.New("call to permission controller failed: " + err.Error()) } From 159ba1cc0151bfed2baad43a8e1bbfad2c53f318 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Mon, 20 Jan 2025 13:06:15 -0300 Subject: [PATCH 03/10] Nit in admin functions (remove verifications) --- chainio/clients/elcontracts/reader.go | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index 1872967c..eae5ef21 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -736,24 +736,14 @@ func (r *ChainReader) ListPendingAdmins( ctx context.Context, accountAddress gethcommon.Address, ) ([]gethcommon.Address, error) { - pendingAdmins, err := r.permissionController.GetPendingAdmins(&bind.CallOpts{Context: ctx}, accountAddress) - // This call should not fail since it's a getter - if err != nil { - return nil, errors.New("call to permission controller failed: " + err.Error()) - } - return pendingAdmins, nil + return r.permissionController.GetPendingAdmins(&bind.CallOpts{Context: ctx}, accountAddress) } func (r *ChainReader) ListAdmins( ctx context.Context, accountAddress gethcommon.Address, ) ([]gethcommon.Address, error) { - pendingAdmins, err := r.permissionController.GetAdmins(&bind.CallOpts{Context: ctx}, accountAddress) - // This call should not fail since it's a getter - if err != nil { - return nil, errors.New("call to permission controller failed: " + err.Error()) - } - return pendingAdmins, nil + return r.permissionController.GetAdmins(&bind.CallOpts{Context: ctx}, accountAddress) } func (r *ChainReader) IsPendingAdmin( @@ -778,10 +768,5 @@ func (r *ChainReader) IsAdmin( accountAddress gethcommon.Address, adminAddress gethcommon.Address, ) (bool, error) { - isAdmin, err := r.permissionController.IsAdmin(&bind.CallOpts{Context: ctx}, accountAddress, adminAddress) - // This call should not fail since it's a getter - if err != nil { - return isAdmin, errors.New("call to permission controller failed: " + err.Error()) - } - return isAdmin, nil + return r.permissionController.IsAdmin(&bind.CallOpts{Context: ctx}, accountAddress, adminAddress) } From 663751a2c6e16a8030fd9e991781738d58c3eb71 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Mon, 20 Jan 2025 13:06:49 -0300 Subject: [PATCH 04/10] Remove verifications in GetOperatorSplit functions --- chainio/clients/elcontracts/reader.go | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index eae5ef21..d8d2a398 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -340,14 +340,7 @@ func (r *ChainReader) GetOperatorAVSSplit( return 0, errors.New("RewardsCoordinator contract not provided") } - split, err := r.rewardsCoordinator.GetOperatorAVSSplit(&bind.CallOpts{Context: ctx}, operator, avs) - - // This call should not fail since it's a getter - if err != nil { - return 0, err - } - - return split, nil + return r.rewardsCoordinator.GetOperatorAVSSplit(&bind.CallOpts{Context: ctx}, operator, avs) } func (r *ChainReader) GetOperatorPISplit( @@ -358,14 +351,7 @@ func (r *ChainReader) GetOperatorPISplit( return 0, errors.New("RewardsCoordinator contract not provided") } - split, err := r.rewardsCoordinator.GetOperatorPISplit(&bind.CallOpts{Context: ctx}, operator) - - // This call should not fail since it's a getter - if err != nil { - return 0, err - } - - return split, nil + return r.rewardsCoordinator.GetOperatorPISplit(&bind.CallOpts{Context: ctx}, operator) } func (r *ChainReader) GetAllocatableMagnitude( From e10bea1fc22108dc1ab635bd748b7fc45916021c Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Mon, 20 Jan 2025 13:07:22 -0300 Subject: [PATCH 05/10] Remove binding result verification in IsOperatorRegistered --- chainio/clients/elcontracts/reader.go | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index d8d2a398..f04d44ec 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -99,16 +99,7 @@ func (r *ChainReader) IsOperatorRegistered( return false, errors.New("DelegationManager contract not provided") } - isOperator, err := r.delegationManager.IsOperator( - &bind.CallOpts{Context: ctx}, - gethcommon.HexToAddress(operator.Address), - ) - // This call should not fail since it's a getter - if err != nil { - return false, err - } - - return isOperator, nil + return r.delegationManager.IsOperator(&bind.CallOpts{Context: ctx}, gethcommon.HexToAddress(operator.Address)) } // GetStakerShares returns the amount of shares that a staker has in all of the strategies in which they have nonzero From 481d9f7af04b1fb2bea86aec872165d304cb4049 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Mon, 20 Jan 2025 13:14:12 -0300 Subject: [PATCH 06/10] Remove more binding result validations in admin funcs --- chainio/clients/elcontracts/reader.go | 37 +++------------------------ 1 file changed, 4 insertions(+), 33 deletions(-) diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index f04d44ec..63fab851 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -659,18 +659,13 @@ func (r *ChainReader) CanCall( target gethcommon.Address, selector [4]byte, ) (bool, error) { - canCall, err := r.permissionController.CanCall( + return r.permissionController.CanCall( &bind.CallOpts{Context: ctx}, accountAddress, appointeeAddress, target, selector, ) - // This call should not fail since it's a getter - if err != nil { - return false, errors.New("call to permission controller failed: " + err.Error()) - } - return canCall, nil } func (r *ChainReader) ListAppointees( @@ -679,17 +674,7 @@ func (r *ChainReader) ListAppointees( target gethcommon.Address, selector [4]byte, ) ([]gethcommon.Address, error) { - appointees, err := r.permissionController.GetAppointees( - &bind.CallOpts{Context: ctx}, - accountAddress, - target, - selector, - ) - // This call should not fail since it's a getter - if err != nil { - return nil, errors.New("call to permission controller failed: " + err.Error()) - } - return appointees, nil + return r.permissionController.GetAppointees(&bind.CallOpts{Context: ctx}, accountAddress, target, selector) } func (r *ChainReader) ListAppointeePermissions( @@ -697,16 +682,11 @@ func (r *ChainReader) ListAppointeePermissions( accountAddress gethcommon.Address, appointeeAddress gethcommon.Address, ) ([]gethcommon.Address, [][4]byte, error) { - targets, selectors, err := r.permissionController.GetAppointeePermissions( + return r.permissionController.GetAppointeePermissions( &bind.CallOpts{Context: ctx}, accountAddress, appointeeAddress, ) - // This call should not fail since it's a getter - if err != nil { - return nil, nil, errors.New("call to permission controller failed: " + err.Error()) - } - return targets, selectors, nil } func (r *ChainReader) ListPendingAdmins( @@ -728,16 +708,7 @@ func (r *ChainReader) IsPendingAdmin( accountAddress gethcommon.Address, pendingAdminAddress gethcommon.Address, ) (bool, error) { - isPendingAdmin, err := r.permissionController.IsPendingAdmin( - &bind.CallOpts{Context: ctx}, - accountAddress, - pendingAdminAddress, - ) - // This call should not fail since it's a getter - if err != nil { - return isPendingAdmin, errors.New("call to permission controller failed: " + err.Error()) - } - return isPendingAdmin, nil + return r.permissionController.IsPendingAdmin(&bind.CallOpts{Context: ctx}, accountAddress, pendingAdminAddress) } func (r *ChainReader) IsAdmin( From 6c27738927170533baadfa570ce1b45f8a9f66e4 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Mon, 20 Jan 2025 15:18:49 -0300 Subject: [PATCH 07/10] Restore validation on admin functions to clarify returned error --- chainio/clients/elcontracts/reader.go | 58 +++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 7 deletions(-) diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index 63fab851..74ba2fa8 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -659,13 +659,18 @@ func (r *ChainReader) CanCall( target gethcommon.Address, selector [4]byte, ) (bool, error) { - return r.permissionController.CanCall( + canCall, err := r.permissionController.CanCall( &bind.CallOpts{Context: ctx}, accountAddress, appointeeAddress, target, selector, ) + // This call should not fail since it's a getter + if err != nil { + return false, errors.New("call to permission controller failed: " + err.Error()) + } + return canCall, nil } func (r *ChainReader) ListAppointees( @@ -674,7 +679,17 @@ func (r *ChainReader) ListAppointees( target gethcommon.Address, selector [4]byte, ) ([]gethcommon.Address, error) { - return r.permissionController.GetAppointees(&bind.CallOpts{Context: ctx}, accountAddress, target, selector) + appointees, err := r.permissionController.GetAppointees( + &bind.CallOpts{Context: ctx}, + accountAddress, + target, + selector, + ) + // This call should not fail since it's a getter + if err != nil { + return nil, errors.New("call to permission controller failed: " + err.Error()) + } + return appointees, nil } func (r *ChainReader) ListAppointeePermissions( @@ -682,25 +697,40 @@ func (r *ChainReader) ListAppointeePermissions( accountAddress gethcommon.Address, appointeeAddress gethcommon.Address, ) ([]gethcommon.Address, [][4]byte, error) { - return r.permissionController.GetAppointeePermissions( + targets, selectors, err := r.permissionController.GetAppointeePermissions( &bind.CallOpts{Context: ctx}, accountAddress, appointeeAddress, ) + // This call should not fail since it's a getter + if err != nil { + return nil, nil, errors.New("call to permission controller failed: " + err.Error()) + } + return targets, selectors, nil } func (r *ChainReader) ListPendingAdmins( ctx context.Context, accountAddress gethcommon.Address, ) ([]gethcommon.Address, error) { - return r.permissionController.GetPendingAdmins(&bind.CallOpts{Context: ctx}, accountAddress) + pendingAdmins, err := r.permissionController.GetPendingAdmins(&bind.CallOpts{Context: ctx}, accountAddress) + // This call should not fail since it's a getter + if err != nil { + return nil, errors.New("call to permission controller failed: " + err.Error()) + } + return pendingAdmins, nil } func (r *ChainReader) ListAdmins( ctx context.Context, accountAddress gethcommon.Address, ) ([]gethcommon.Address, error) { - return r.permissionController.GetAdmins(&bind.CallOpts{Context: ctx}, accountAddress) + pendingAdmins, err := r.permissionController.GetAdmins(&bind.CallOpts{Context: ctx}, accountAddress) + // This call should not fail since it's a getter + if err != nil { + return nil, errors.New("call to permission controller failed: " + err.Error()) + } + return pendingAdmins, nil } func (r *ChainReader) IsPendingAdmin( @@ -708,7 +738,16 @@ func (r *ChainReader) IsPendingAdmin( accountAddress gethcommon.Address, pendingAdminAddress gethcommon.Address, ) (bool, error) { - return r.permissionController.IsPendingAdmin(&bind.CallOpts{Context: ctx}, accountAddress, pendingAdminAddress) + isPendingAdmin, err := r.permissionController.IsPendingAdmin( + &bind.CallOpts{Context: ctx}, + accountAddress, + pendingAdminAddress, + ) + // This call should not fail since it's a getter + if err != nil { + return isPendingAdmin, errors.New("call to permission controller failed: " + err.Error()) + } + return isPendingAdmin, nil } func (r *ChainReader) IsAdmin( @@ -716,5 +755,10 @@ func (r *ChainReader) IsAdmin( accountAddress gethcommon.Address, adminAddress gethcommon.Address, ) (bool, error) { - return r.permissionController.IsAdmin(&bind.CallOpts{Context: ctx}, accountAddress, adminAddress) + isAdmin, err := r.permissionController.IsAdmin(&bind.CallOpts{Context: ctx}, accountAddress, adminAddress) + // This call should not fail since it's a getter + if err != nil { + return isAdmin, errors.New("call to permission controller failed: " + err.Error()) + } + return isAdmin, nil } From 5aa26755c6ec239cb5d84881b82c8f08dd5853fc Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Mon, 20 Jan 2025 15:24:50 -0300 Subject: [PATCH 08/10] Use utils.WrapError instead of creating a new one --- chainio/clients/elcontracts/reader.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index 74ba2fa8..e9597936 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -668,7 +668,7 @@ func (r *ChainReader) CanCall( ) // This call should not fail since it's a getter if err != nil { - return false, errors.New("call to permission controller failed: " + err.Error()) + return false, utils.WrapError("call to permission controller failed", err) } return canCall, nil } @@ -687,7 +687,7 @@ func (r *ChainReader) ListAppointees( ) // This call should not fail since it's a getter if err != nil { - return nil, errors.New("call to permission controller failed: " + err.Error()) + return nil, utils.WrapError("call to permission controller failed", err) } return appointees, nil } @@ -704,7 +704,7 @@ func (r *ChainReader) ListAppointeePermissions( ) // This call should not fail since it's a getter if err != nil { - return nil, nil, errors.New("call to permission controller failed: " + err.Error()) + return nil, nil, utils.WrapError("call to permission controller failed", err) } return targets, selectors, nil } @@ -716,7 +716,7 @@ func (r *ChainReader) ListPendingAdmins( pendingAdmins, err := r.permissionController.GetPendingAdmins(&bind.CallOpts{Context: ctx}, accountAddress) // This call should not fail since it's a getter if err != nil { - return nil, errors.New("call to permission controller failed: " + err.Error()) + return nil, utils.WrapError("call to permission controller failed", err) } return pendingAdmins, nil } @@ -728,7 +728,7 @@ func (r *ChainReader) ListAdmins( pendingAdmins, err := r.permissionController.GetAdmins(&bind.CallOpts{Context: ctx}, accountAddress) // This call should not fail since it's a getter if err != nil { - return nil, errors.New("call to permission controller failed: " + err.Error()) + return nil, utils.WrapError("call to permission controller failed", err) } return pendingAdmins, nil } @@ -745,7 +745,7 @@ func (r *ChainReader) IsPendingAdmin( ) // This call should not fail since it's a getter if err != nil { - return isPendingAdmin, errors.New("call to permission controller failed: " + err.Error()) + return isPendingAdmin, utils.WrapError("call to permission controller failed", err) } return isPendingAdmin, nil } @@ -758,7 +758,7 @@ func (r *ChainReader) IsAdmin( isAdmin, err := r.permissionController.IsAdmin(&bind.CallOpts{Context: ctx}, accountAddress, adminAddress) // This call should not fail since it's a getter if err != nil { - return isAdmin, errors.New("call to permission controller failed: " + err.Error()) + return isAdmin, utils.WrapError("call to permission controller failed", err) } return isAdmin, nil } From 6b302bd800bb2ff267c23913cfac1e2273956898 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Mon, 20 Jan 2025 15:25:53 -0300 Subject: [PATCH 09/10] Change the boolean returned value on error --- chainio/clients/elcontracts/reader.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index e9597936..939cf64d 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -745,7 +745,7 @@ func (r *ChainReader) IsPendingAdmin( ) // This call should not fail since it's a getter if err != nil { - return isPendingAdmin, utils.WrapError("call to permission controller failed", err) + return false, utils.WrapError("call to permission controller failed", err) } return isPendingAdmin, nil } @@ -758,7 +758,7 @@ func (r *ChainReader) IsAdmin( isAdmin, err := r.permissionController.IsAdmin(&bind.CallOpts{Context: ctx}, accountAddress, adminAddress) // This call should not fail since it's a getter if err != nil { - return isAdmin, utils.WrapError("call to permission controller failed", err) + return false, utils.WrapError("call to permission controller failed", err) } return isAdmin, nil } From 69a37114805cef48f3c113da0780d06ff5174b72 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Mon, 20 Jan 2025 15:39:17 -0300 Subject: [PATCH 10/10] Improve comment on GetStrategyAndUnderlyingERC20Token --- chainio/clients/elcontracts/reader.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index 939cf64d..128f7db0 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -195,7 +195,7 @@ func (r *ChainReader) GetStrategyAndUnderlyingERC20Token( return nil, nil, gethcommon.Address{}, utils.WrapError("Failed to fetch token contract", err) } contractUnderlyingToken, err := erc20.NewContractIERC20(underlyingTokenAddr, r.ethClient) - // This call should not fail, if strategy has no underlying token then enters the if above + // This call should not fail, if the strategy does not have an underlying token then it would enter the if above if err != nil { return nil, nil, gethcommon.Address{}, utils.WrapError("Failed to fetch token contract", err) }