From 5f13764ceae81a0eaf311a12874507c37382b932 Mon Sep 17 00:00:00 2001 From: lumtis Date: Fri, 22 Nov 2024 14:50:18 +0100 Subject: [PATCH] consolidate function call --- e2e/e2etests/test_erc20_deposit_refund.go | 45 ++--------------------- e2e/runner/liquidity.go | 8 +++- 2 files changed, 9 insertions(+), 44 deletions(-) diff --git a/e2e/e2etests/test_erc20_deposit_refund.go b/e2e/e2etests/test_erc20_deposit_refund.go index 816cf702a8..6823799c38 100644 --- a/e2e/e2etests/test_erc20_deposit_refund.go +++ b/e2e/e2etests/test_erc20_deposit_refund.go @@ -2,13 +2,10 @@ package e2etests import ( "errors" - "fmt" - "math/big" - "time" - "github.com/ethereum/go-ethereum/accounts/abi/bind" ethcommon "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" + "math/big" "github.com/zeta-chain/node/e2e/runner" "github.com/zeta-chain/node/e2e/utils" @@ -64,7 +61,8 @@ func TestERC20DepositAndCallRefund(r *runner.E2ERunner, _ []string) { r.Logger.Info("Sending a deposit that should revert with a liquidity pool") r.Logger.Info("Creating the liquidity pool USTD/ZETA") - err = createZetaERC20LiquidityPool(r) + fifty := big.NewInt(0).Mul(big.NewInt(1e18), big.NewInt(50)) + r.AddLiquidityERC20(fifty, fifty) require.NoError(r, err) r.Logger.Info("Liquidity pool created") @@ -120,43 +118,6 @@ func TestERC20DepositAndCallRefund(r *runner.E2ERunner, _ []string) { r.Logger.Info("\tbalance after refund: %s", erc20BalanceAfterRefund.String()) } -func createZetaERC20LiquidityPool(r *runner.E2ERunner) error { - amount := big.NewInt(1e10) - txHash := r.DepositERC20WithAmountAndMessage(r.EVMAddress(), amount, []byte{}) - utils.WaitCctxMinedByInboundHash(r.Ctx, txHash.Hex(), r.CctxClient, r.Logger, r.CctxTimeout) - - tx, err := r.ERC20ZRC20.Approve(r.ZEVMAuth, r.UniswapV2RouterAddr, big.NewInt(1e10)) - if err != nil { - return err - } - receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) - if receipt.Status == 0 { - return errors.New("approve failed") - } - - previousValue := r.ZEVMAuth.Value - r.ZEVMAuth.Value = big.NewInt(1e10) - tx, err = r.UniswapV2Router.AddLiquidityETH( - r.ZEVMAuth, - r.ERC20ZRC20Addr, - amount, - big.NewInt(0), - big.NewInt(0), - r.EVMAddress(), - big.NewInt(time.Now().Add(10*time.Minute).Unix()), - ) - r.ZEVMAuth.Value = previousValue - if err != nil { - return err - } - receipt = utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) - if receipt.Status == 0 { - return fmt.Errorf("add liquidity failed") - } - - return nil -} - func sendInvalidERC20Deposit(r *runner.E2ERunner, amount *big.Int) (string, error) { tx, err := r.ERC20.Approve(r.EVMAuth, r.ERC20CustodyAddr, amount) if err != nil { diff --git a/e2e/runner/liquidity.go b/e2e/runner/liquidity.go index 4679afbd1a..5f51a9fa3c 100644 --- a/e2e/runner/liquidity.go +++ b/e2e/runner/liquidity.go @@ -37,7 +37,9 @@ func (r *E2ERunner) AddLiquidityETH(amountZETA, amountETH *big.Int) { require.NoError(r, err) receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) - require.EqualValues(r, types.ReceiptStatusSuccessful, receipt.Status, "add liquidity failed") + if receipt.Status == types.ReceiptStatusFailed { + r.Logger.Error("Add liquidity failed: %s", receipt.Logs) + } // get the pair address pairAddress, err := r.UniswapV2Factory.GetPair(&bind.CallOpts{}, r.WZetaAddr, r.ETHZRC20Addr) @@ -72,7 +74,9 @@ func (r *E2ERunner) AddLiquidityERC20(amountZETA, amountERC20 *big.Int) { require.NoError(r, err) receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) - require.EqualValues(r, types.ReceiptStatusSuccessful, receipt.Status, "add liquidity failed") + if receipt.Status == types.ReceiptStatusFailed { + r.Logger.Error("Add liquidity failed: %s", receipt.Logs) + } // get the pair address pairAddress, err := r.UniswapV2Factory.GetPair(&bind.CallOpts{}, r.WZetaAddr, r.ERC20ZRC20Addr)