Skip to content

Commit

Permalink
fix for flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
dusannosovic-ethernal committed Feb 20, 2024
1 parent 21a55bb commit c743095
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions e2e-polybft/e2e/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,7 @@ 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) {
t.Log("Checking balance of native ERC20 token on root and child", "Address", address,
"Root expected", rootExpected, "Child Expected", childExpected)

Expand All @@ -1319,20 +1319,24 @@ 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 {

Check failure on line 1322 in e2e-polybft/e2e/bridge_test.go

View workflow job for this annotation

GitHub Actions / Lint / Run Lint

if statements should only be cuddled with assignments (wsl)
require.True(t, balance.Cmp(childExpected) >= 0) // because of London fork
} else {
require.True(t, balance.Cmp(childExpected) <= 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 +1405,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 c743095

Please sign in to comment.