Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for flaky test #117

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading