Skip to content

Commit

Permalink
Fix flaky TestE2E_Bridge_NonMintableERC20Token_WithPremine
Browse files Browse the repository at this point in the history
* fix for flaky test

* lint fix

* test fix

* to gwei

* added comment

* Add logs for total supply and initial total supply

* test fix

* logs delete
  • Loading branch information
dusannosovic-ethernal authored Feb 23, 2024
1 parent ca993c5 commit 08e947f
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions e2e-polybft/e2e/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
}
})

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 08e947f

Please sign in to comment.