diff --git a/e2e-polybft/e2e/bridge_test.go b/e2e-polybft/e2e/bridge_test.go index b370fc3581..921e26605c 100644 --- a/e2e-polybft/e2e/bridge_test.go +++ b/e2e-polybft/e2e/bridge_test.go @@ -1307,7 +1307,10 @@ func TestE2E_Bridge_NonMintableERC20Token_WithPremine(t *testing.T) { polybftCfg, err := polybft.LoadPolyBFTConfig(path.Join(cluster.Config.TmpDir, chainConfigFileName)) require.NoError(t, err) - checkBalancesFn := func(address types.Address, rootExpected, childExpected *big.Int) { + checkBalancesFn := func(address types.Address, rootExpected, childExpected *big.Int, isValidator bool) { + offset := ethgo.Gwei(10) + expectedValue := new(big.Int) + t.Log("Checking balance of native ERC20 token on root and child", "Address", address, "Root expected", rootExpected, "Child Expected", childExpected) @@ -1319,20 +1322,26 @@ func TestE2E_Bridge_NonMintableERC20Token_WithPremine(t *testing.T) { balance, err = childEthEndpoint.GetBalance(ethgo.Address(address), ethgo.Latest) require.NoError(t, err) t.Log("Balance of native ERC20 token on child", balance, "Address", address) - require.True(t, balance.Cmp(childExpected) >= 0) // because of London fork + + if isValidator { + require.True(t, balance.Cmp(childExpected) >= 0) // because of London fork + } else { + //this check is implemented because non-validators incur fees, potentially resulting in a balance lower than anticipated + require.True(t, balance.Cmp(expectedValue.Sub(childExpected, offset)) >= 0) + } } t.Run("check the balances at the beginning", func(t *testing.T) { // check the balances on root and child at the beginning to see if they are as expected - checkBalancesFn(types.Address(nonValidatorKey.Address()), bigZero, command.DefaultPremineBalance) - checkBalancesFn(types.Address(rewardWalletKey.Address()), bigZero, command.DefaultPremineBalance) + checkBalancesFn(types.Address(nonValidatorKey.Address()), bigZero, command.DefaultPremineBalance, false) + checkBalancesFn(types.Address(rewardWalletKey.Address()), bigZero, command.DefaultPremineBalance, true) validatorsExpectedBalance := new(big.Int).Sub(command.DefaultPremineBalance, command.DefaultStake) for _, server := range cluster.Servers { validatorAccount, err := validatorHelper.GetAccountFromDir(server.DataDir()) require.NoError(t, err) - checkBalancesFn(validatorAccount.Address(), bigZero, validatorsExpectedBalance) + checkBalancesFn(validatorAccount.Address(), bigZero, validatorsExpectedBalance, true) } }) @@ -1401,8 +1410,8 @@ func TestE2E_Bridge_NonMintableERC20Token_WithPremine(t *testing.T) { })) // assert that receiver's balances on RootERC20 smart contract are expected - checkBalancesFn(validatorAcc.Address(), tokensToTransfer, validatorBalanceAfterWithdraw) - checkBalancesFn(types.Address(nonValidatorKey.Address()), tokensToTransfer, nonValidatorBalanceAfterWithdraw) + checkBalancesFn(validatorAcc.Address(), tokensToTransfer, validatorBalanceAfterWithdraw, true) + checkBalancesFn(types.Address(nonValidatorKey.Address()), tokensToTransfer, nonValidatorBalanceAfterWithdraw, false) }) t.Run("Do a deposit to some validator and non-validator address", func(t *testing.T) {