From d63e9faea71fe08e7400c2a688c44c286b1fbcd9 Mon Sep 17 00:00:00 2001 From: Adam Hamrick Date: Mon, 1 Jul 2024 13:12:29 -0400 Subject: [PATCH 1/2] Fixes Erroneous Approval Error --- integration-tests/ccip-tests/actions/ccip_helpers.go | 3 ++- integration-tests/ccip-tests/contracts/contract_models.go | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/integration-tests/ccip-tests/actions/ccip_helpers.go b/integration-tests/ccip-tests/actions/ccip_helpers.go index 88cd28876c..b7ed6b7c0f 100644 --- a/integration-tests/ccip-tests/actions/ccip_helpers.go +++ b/integration-tests/ccip-tests/actions/ccip_helpers.go @@ -402,7 +402,8 @@ func (ccipModule *CCIPCommon) ApproveTokens() error { return fmt.Errorf("failed to get allowance for token %s: %w", token.ContractAddress.Hex(), err) } if allowance.Cmp(ApprovedAmountToRouter) < 0 { - err := token.Approve(ccipModule.ChainClient.GetDefaultWallet(), ccipModule.Router.Address(), ApprovedAmountToRouter) + allowanceApprovalDelta := new(big.Int).Sub(ApprovedAmountToRouter, allowance) + err := token.Approve(ccipModule.ChainClient.GetDefaultWallet(), ccipModule.Router.Address(), allowanceApprovalDelta) if err != nil { return fmt.Errorf("failed to approve token %s: %w", token.ContractAddress.Hex(), err) } diff --git a/integration-tests/ccip-tests/contracts/contract_models.go b/integration-tests/ccip-tests/contracts/contract_models.go index 08a88be569..921ff320b3 100644 --- a/integration-tests/ccip-tests/contracts/contract_models.go +++ b/integration-tests/ccip-tests/contracts/contract_models.go @@ -272,6 +272,13 @@ func (token *ERC20Token) Approve(onBehalf *blockchain.EthereumWallet, spender st return fmt.Errorf("failed to get balance of onBehalf: %w", err) } if onBehalfBalance.Cmp(amount) < 0 { + token.logger.Warn(). + Str("Token", token.Address()). + Str("On Behalf", onBehalf.Address()). + Uint64("On Behalf's Balance", onBehalfBalance.Uint64()). + Uint64("Approve Amount", amount.Uint64()). + Str("Spender", spender). + Msg("Approving ERC20 transfer for more than balance") return fmt.Errorf("onBehalf '%s' does not have enough balance to approve", onBehalf.Address()) } currentAllowance, err := token.Allowance(onBehalf.Address(), spender) From fbe7393205696314d87046c694717e3cd46f1d6d Mon Sep 17 00:00:00 2001 From: Adam Hamrick Date: Mon, 1 Jul 2024 13:14:08 -0400 Subject: [PATCH 2/2] Remove warn --- .../ccip-tests/contracts/contract_models.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/integration-tests/ccip-tests/contracts/contract_models.go b/integration-tests/ccip-tests/contracts/contract_models.go index 921ff320b3..28dec6aedb 100644 --- a/integration-tests/ccip-tests/contracts/contract_models.go +++ b/integration-tests/ccip-tests/contracts/contract_models.go @@ -271,16 +271,6 @@ func (token *ERC20Token) Approve(onBehalf *blockchain.EthereumWallet, spender st if err != nil { return fmt.Errorf("failed to get balance of onBehalf: %w", err) } - if onBehalfBalance.Cmp(amount) < 0 { - token.logger.Warn(). - Str("Token", token.Address()). - Str("On Behalf", onBehalf.Address()). - Uint64("On Behalf's Balance", onBehalfBalance.Uint64()). - Uint64("Approve Amount", amount.Uint64()). - Str("Spender", spender). - Msg("Approving ERC20 transfer for more than balance") - return fmt.Errorf("onBehalf '%s' does not have enough balance to approve", onBehalf.Address()) - } currentAllowance, err := token.Allowance(onBehalf.Address(), spender) if err != nil { return fmt.Errorf("failed to get current allowance for '%s' on behalf of '%s': %w", spender, onBehalf.Address(), err)