From de990faab7a8a8c530d018e057ea1db066f582be Mon Sep 17 00:00:00 2001 From: Francisco de Borja Aranda Castillejo Date: Wed, 25 Sep 2024 10:49:54 +0200 Subject: [PATCH] test: revert balance between tests --- e2e/e2etests/test_precompiles_bank.go | 23 ++++++++++++++----- .../test_precompiles_bank_through_contract.go | 10 ++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/e2e/e2etests/test_precompiles_bank.go b/e2e/e2etests/test_precompiles_bank.go index 5aa7a00f95..2517410339 100644 --- a/e2e/e2etests/test_precompiles_bank.go +++ b/e2e/e2etests/test_precompiles_bank.go @@ -4,6 +4,7 @@ import ( "math/big" "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" "github.com/zeta-chain/node/e2e/runner" @@ -14,6 +15,12 @@ import ( func TestPrecompilesBank(r *runner.E2ERunner, args []string) { require.Len(r, args, 0, "No arguments expected") + totalAmount := big.NewInt(1e3) + depositAmount := big.NewInt(500) + higherBalanceAmount := big.NewInt(1001) + higherAllowanceAmount := big.NewInt(501) + spender := r.EVMAddress() + // Increase the gasLimit. It's required because of the gas consumed by precompiled functions. previousGasLimit := r.ZEVMAuth.GasLimit r.ZEVMAuth.GasLimit = 10_000_000 @@ -26,13 +33,17 @@ func TestPrecompilesBank(r *runner.E2ERunner, args []string) { require.NoError(r, err) receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) utils.RequireTxSuccessful(r, receipt, "Resetting allowance failed") - }() - totalAmount := big.NewInt(1e3) - depositAmount := big.NewInt(500) - higherBalanceAmount := big.NewInt(1001) - higherAllowanceAmount := big.NewInt(501) - spender := r.EVMAddress() + // Reset balance to 0; this is needed when running upgrade tests where this test runs twice. + tx, err = r.ERC20ZRC20.Transfer( + r.ZEVMAuth, + common.HexToAddress("0x000000000000000000000000000000000000dEaD"), + totalAmount, + ) + require.NoError(r, err) + receipt = utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) + utils.RequireTxSuccessful(r, receipt, "Resetting balance failed") + }() // Get ERC20ZRC20. txHash := r.DepositERC20WithAmountAndMessage(r.EVMAddress(), totalAmount, []byte{}) diff --git a/e2e/e2etests/test_precompiles_bank_through_contract.go b/e2e/e2etests/test_precompiles_bank_through_contract.go index 2226927761..480663284e 100644 --- a/e2e/e2etests/test_precompiles_bank_through_contract.go +++ b/e2e/e2etests/test_precompiles_bank_through_contract.go @@ -44,6 +44,16 @@ func TestPrecompilesBankThroughContract(r *runner.E2ERunner, args []string) { // Reset the allowance to 0; this is needed when running upgrade tests where this test runs twice. approveAllowance(r, bank.ContractAddress, big.NewInt(0)) + + // Reset balance to 0; this is needed when running upgrade tests where this test runs twice. + tx, err = r.ERC20ZRC20.Transfer( + r.ZEVMAuth, + common.HexToAddress("0x000000000000000000000000000000000000dEaD"), + oneThousand, + ) + require.NoError(r, err) + receipt = utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) + utils.RequireTxSuccessful(r, receipt, "Resetting balance failed") }() // Check initial balances.