Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(e2e): fix add liquidity occasional error (tentative) #3199

Merged
merged 5 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/zetae2e/local/erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func erc20TestRoutine(
startTime := time.Now()

// funding the account
txERC20Send := deployerRunner.SendERC20OnEvm(account.EVMAddress(), 10)
txERC20Send := deployerRunner.SendERC20OnEvm(account.EVMAddress(), 10000)
erc20Runner.WaitForTxReceiptOnEvm(txERC20Send)

// depositing the necessary tokens on ZetaChain
Expand Down
43 changes: 3 additions & 40 deletions e2e/e2etests/test_erc20_deposit_refund.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package e2etests

import (
"errors"
"fmt"
"math/big"
"time"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
ethcommon "github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -64,7 +62,9 @@ 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.AddLiquidityETH(fifty, fifty)
r.AddLiquidityERC20(fifty, fifty)
lumtis marked this conversation as resolved.
Show resolved Hide resolved
require.NoError(r, err)

r.Logger.Info("Liquidity pool created")
Expand Down Expand Up @@ -120,43 +120,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 {
Expand Down
3 changes: 2 additions & 1 deletion e2e/runner/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ func (r *E2ERunner) SendERC20OnEvm(address ethcommon.Address, amountERC20 int64)
func (r *E2ERunner) DepositERC20() ethcommon.Hash {
r.Logger.Print("⏳ depositing ERC20 into ZEVM")

return r.DepositERC20WithAmountAndMessage(r.EVMAddress(), big.NewInt(1e18), []byte{})
oneHundred := big.NewInt(0).Mul(big.NewInt(1e18), big.NewInt(100))
return r.DepositERC20WithAmountAndMessage(r.EVMAddress(), oneHundred, []byte{})
}

func (r *E2ERunner) DepositERC20WithAmountAndMessage(to ethcommon.Address, amount *big.Int, msg []byte) ethcommon.Hash {
Expand Down
8 changes: 6 additions & 2 deletions e2e/runner/liquidity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 for ZETA/ETH")
}
lumtis marked this conversation as resolved.
Show resolved Hide resolved

// get the pair address
pairAddress, err := r.UniswapV2Factory.GetPair(&bind.CallOpts{}, r.WZetaAddr, r.ETHZRC20Addr)
Expand Down Expand Up @@ -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 for ZETA/ERC20")
}
lumtis marked this conversation as resolved.
Show resolved Hide resolved

// get the pair address
pairAddress, err := r.UniswapV2Factory.GetPair(&bind.CallOpts{}, r.WZetaAddr, r.ERC20ZRC20Addr)
Expand Down
8 changes: 7 additions & 1 deletion e2e/utils/require.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ func RequireCCTXStatus(
expected crosschaintypes.CctxStatus,
msgAndArgs ...any,
) {
msg := fmt.Sprintf("cctx status is not %q cctx index %s", expected.String(), cctx.Index)
msg := fmt.Sprintf(
"cctx status is not %q cctx index %s, status: %s, error: %s",
expected.String(),
cctx.Index,
cctx.CctxStatus.StatusMessage,
cctx.CctxStatus.ErrorMessage,
)

require.NotNil(t, cctx.CctxStatus)
require.Equal(t, expected, cctx.CctxStatus.Status, msg+errSuffix(msgAndArgs...))
Expand Down
Loading