From 8d9844628adf890ccbe2962dfb9d0a63baf2c1f9 Mon Sep 17 00:00:00 2001 From: Dusan Nosovic Date: Wed, 14 Feb 2024 15:45:44 +0100 Subject: [PATCH 1/8] fix for flaky test --- e2e-polybft/e2e/bridge_test.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/e2e-polybft/e2e/bridge_test.go b/e2e-polybft/e2e/bridge_test.go index b370fc3581..c93d7d1609 100644 --- a/e2e-polybft/e2e/bridge_test.go +++ b/e2e-polybft/e2e/bridge_test.go @@ -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) @@ -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 { + 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) } }) @@ -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) { From f78e0313dcc91d219660e39626b9abc15c84baa8 Mon Sep 17 00:00:00 2001 From: Dusan Nosovic Date: Tue, 20 Feb 2024 10:05:10 +0100 Subject: [PATCH 2/8] lint fix --- e2e-polybft/e2e/bridge_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/e2e-polybft/e2e/bridge_test.go b/e2e-polybft/e2e/bridge_test.go index c93d7d1609..91e6c0d483 100644 --- a/e2e-polybft/e2e/bridge_test.go +++ b/e2e-polybft/e2e/bridge_test.go @@ -1319,6 +1319,7 @@ 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) + if isValidator { require.True(t, balance.Cmp(childExpected) >= 0) // because of London fork } else { From 9a3c03ea383ef833d92535d26f1bffebee64e27b Mon Sep 17 00:00:00 2001 From: Dusan Nosovic Date: Tue, 20 Feb 2024 10:50:53 +0100 Subject: [PATCH 3/8] test fix --- e2e-polybft/e2e/bridge_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/e2e-polybft/e2e/bridge_test.go b/e2e-polybft/e2e/bridge_test.go index 91e6c0d483..20ff8561d4 100644 --- a/e2e-polybft/e2e/bridge_test.go +++ b/e2e-polybft/e2e/bridge_test.go @@ -1308,6 +1308,8 @@ func TestE2E_Bridge_NonMintableERC20Token_WithPremine(t *testing.T) { require.NoError(t, err) checkBalancesFn := func(address types.Address, rootExpected, childExpected *big.Int, isValidator bool) { + offset := big.NewInt(100) + t.Log("Checking balance of native ERC20 token on root and child", "Address", address, "Root expected", rootExpected, "Child Expected", childExpected) @@ -1323,7 +1325,7 @@ func TestE2E_Bridge_NonMintableERC20Token_WithPremine(t *testing.T) { if isValidator { require.True(t, balance.Cmp(childExpected) >= 0) // because of London fork } else { - require.True(t, balance.Cmp(childExpected) <= 0) + require.True(t, balance.Cmp(childExpected.Sub(childExpected, offset)) >= 0) } } From 46cf157abaa589dce9ef4c72ad55ace84906078e Mon Sep 17 00:00:00 2001 From: Dusan Nosovic Date: Tue, 20 Feb 2024 11:19:28 +0100 Subject: [PATCH 4/8] to gwei --- e2e-polybft/e2e/bridge_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e-polybft/e2e/bridge_test.go b/e2e-polybft/e2e/bridge_test.go index 20ff8561d4..de8f1ba1d2 100644 --- a/e2e-polybft/e2e/bridge_test.go +++ b/e2e-polybft/e2e/bridge_test.go @@ -1308,7 +1308,7 @@ func TestE2E_Bridge_NonMintableERC20Token_WithPremine(t *testing.T) { require.NoError(t, err) checkBalancesFn := func(address types.Address, rootExpected, childExpected *big.Int, isValidator bool) { - offset := big.NewInt(100) + offset := ethgo.Gwei(10) t.Log("Checking balance of native ERC20 token on root and child", "Address", address, "Root expected", rootExpected, "Child Expected", childExpected) From f91c5f85968fd0b9c9b16a407051c04e12bc5f99 Mon Sep 17 00:00:00 2001 From: Dusan Nosovic Date: Thu, 22 Feb 2024 10:15:55 +0100 Subject: [PATCH 5/8] added comment --- e2e-polybft/e2e/bridge_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/e2e-polybft/e2e/bridge_test.go b/e2e-polybft/e2e/bridge_test.go index de8f1ba1d2..3fd072429b 100644 --- a/e2e-polybft/e2e/bridge_test.go +++ b/e2e-polybft/e2e/bridge_test.go @@ -1325,6 +1325,7 @@ func TestE2E_Bridge_NonMintableERC20Token_WithPremine(t *testing.T) { 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(childExpected.Sub(childExpected, offset)) >= 0) } } From c3fc7cf3770d6ee73a6c7b859dd8d820cd5a25dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Thu, 22 Feb 2024 14:42:32 +0100 Subject: [PATCH 6/8] Add logs for total supply and initial total supply --- e2e-polybft/e2e/consensus_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/e2e-polybft/e2e/consensus_test.go b/e2e-polybft/e2e/consensus_test.go index 0115d6bcb1..ba251f4740 100644 --- a/e2e-polybft/e2e/consensus_test.go +++ b/e2e-polybft/e2e/consensus_test.go @@ -52,6 +52,8 @@ func TestE2E_Consensus_Basic(t *testing.T) { // check if initial total supply of native ERC20 token is the same as expected totalSupply := queryNativeERC20Metadata(t, "totalSupply", uint256ABIType, relayer) + t.Log("Initial total supply", initialTotalSupply) + t.Log("Total supply", totalSupply) require.True(t, initialTotalSupply.Cmp(totalSupply.(*big.Int)) == 0) t.Run("consensus protocol", func(t *testing.T) { @@ -416,6 +418,8 @@ func TestE2E_Consensus_MintableERC20NativeToken(t *testing.T) { uint8ABIType := abi.MustNewType("tuple(uint8)") totalSupply := queryNativeERC20Metadata(t, "totalSupply", uint256ABIType, relayer) + t.Log("Initial total supply", initialTotalSupply) + t.Log("Total supply", totalSupply) require.True(t, initialTotalSupply.Cmp(totalSupply.(*big.Int)) == 0) // check if initial total supply of native ERC20 token is the same as expected From 6984a9e6a82983fc2a6205bb71be592ef9e4b006 Mon Sep 17 00:00:00 2001 From: Dusan Nosovic Date: Fri, 23 Feb 2024 14:22:36 +0100 Subject: [PATCH 7/8] test fix --- e2e-polybft/e2e/bridge_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/e2e-polybft/e2e/bridge_test.go b/e2e-polybft/e2e/bridge_test.go index 3fd072429b..921e26605c 100644 --- a/e2e-polybft/e2e/bridge_test.go +++ b/e2e-polybft/e2e/bridge_test.go @@ -1309,6 +1309,7 @@ func TestE2E_Bridge_NonMintableERC20Token_WithPremine(t *testing.T) { 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) @@ -1326,7 +1327,7 @@ func TestE2E_Bridge_NonMintableERC20Token_WithPremine(t *testing.T) { 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(childExpected.Sub(childExpected, offset)) >= 0) + require.True(t, balance.Cmp(expectedValue.Sub(childExpected, offset)) >= 0) } } From cfb118535a634d014a53fca4e707f35af12a52ea Mon Sep 17 00:00:00 2001 From: Dusan Nosovic Date: Fri, 23 Feb 2024 15:09:57 +0100 Subject: [PATCH 8/8] logs delete --- e2e-polybft/e2e/consensus_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/e2e-polybft/e2e/consensus_test.go b/e2e-polybft/e2e/consensus_test.go index ba251f4740..0115d6bcb1 100644 --- a/e2e-polybft/e2e/consensus_test.go +++ b/e2e-polybft/e2e/consensus_test.go @@ -52,8 +52,6 @@ func TestE2E_Consensus_Basic(t *testing.T) { // check if initial total supply of native ERC20 token is the same as expected totalSupply := queryNativeERC20Metadata(t, "totalSupply", uint256ABIType, relayer) - t.Log("Initial total supply", initialTotalSupply) - t.Log("Total supply", totalSupply) require.True(t, initialTotalSupply.Cmp(totalSupply.(*big.Int)) == 0) t.Run("consensus protocol", func(t *testing.T) { @@ -418,8 +416,6 @@ func TestE2E_Consensus_MintableERC20NativeToken(t *testing.T) { uint8ABIType := abi.MustNewType("tuple(uint8)") totalSupply := queryNativeERC20Metadata(t, "totalSupply", uint256ABIType, relayer) - t.Log("Initial total supply", initialTotalSupply) - t.Log("Total supply", totalSupply) require.True(t, initialTotalSupply.Cmp(totalSupply.(*big.Int)) == 0) // check if initial total supply of native ERC20 token is the same as expected