Skip to content

Commit

Permalink
test: revert balance between tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fbac committed Sep 25, 2024
1 parent 35013e3 commit de990fa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
23 changes: 17 additions & 6 deletions e2e/e2etests/test_precompiles_bank.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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{})
Expand Down
10 changes: 10 additions & 0 deletions e2e/e2etests/test_precompiles_bank_through_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit de990fa

Please sign in to comment.