diff --git a/integrationTests/relayers/slowTests/common.go b/integrationTests/relayers/slowTests/common.go index b59adfa1..f3c8e92d 100644 --- a/integrationTests/relayers/slowTests/common.go +++ b/integrationTests/relayers/slowTests/common.go @@ -118,10 +118,11 @@ func GenerateTestUSDCToken() framework.TestTokenParams { }, MintBurnChecks: &framework.MintBurnBalances{ TotalUniversalMint: big.NewInt(5000 + 7000 + 1000), - TotalChainSpecificMint: big.NewInt(5000 + 7000 + 1000), + TotalChainSpecificMint: big.NewInt(5000 + 7000 + 1000 + 900), TotalUniversalBurn: big.NewInt(2500 + 300), - TotalChainSpecificBurn: big.NewInt(2500 - 50 + 300 - 50), - MintBurnValues: nil, + TotalChainSpecificBurn: big.NewInt(2500 - 50 + 300 - 50 + 900 - 50), + SafeMintValue: big.NewInt(5000 + 7000 + 1000 + 900), + SafeBurnValue: big.NewInt(2500 - 50 + 300 - 50 + 900 - 50), }, } } @@ -139,8 +140,9 @@ func ApplyUSDCRefundBalances(token *framework.TestTokenParams) { // no funds remain in the called test SC token.DeltaBalances[framework.SecondHalfBridge][framework.CalledTestSC].OnMvx = big.NewInt(0) - token.MintBurnChecks.TotalChainSpecificBurn = big.NewInt(2500 - 50 + 300 - 50 + 1000 - 50) + token.MintBurnChecks.TotalChainSpecificBurn = big.NewInt(2500 - 50 + 300 - 50 + 1000 - 50 + 900 - 50) token.MintBurnChecks.TotalUniversalBurn = big.NewInt(2500 + 300 + 1000) + token.MintBurnChecks.SafeBurnValue = big.NewInt(2500 - 50 + 300 - 50 + 1000 - 50 + 900 - 50) } // GenerateTestMEMEToken will generate a test MEME token @@ -242,7 +244,8 @@ func GenerateTestMEMEToken() framework.TestTokenParams { TotalChainSpecificMint: big.NewInt(0), TotalUniversalBurn: big.NewInt(0), TotalChainSpecificBurn: big.NewInt(0), - MintBurnValues: nil, + SafeMintValue: big.NewInt(0), + SafeBurnValue: big.NewInt(0), }, } } @@ -356,11 +359,12 @@ func GenerateTestEUROCToken() framework.TestTokenParams { }, }, MintBurnChecks: &framework.MintBurnBalances{ - TotalUniversalMint: big.NewInt(5010 + 7010 + 1010), + TotalUniversalMint: big.NewInt(5010 + 7010 + 1010 + 700), TotalChainSpecificMint: big.NewInt(0), - TotalUniversalBurn: big.NewInt(2510 - 50 + 310 - 50), + TotalUniversalBurn: big.NewInt(2510 - 50 + 310 - 50 + 700 - 50), TotalChainSpecificBurn: big.NewInt(0), - MintBurnValues: nil, + SafeMintValue: big.NewInt(5010 + 7010 + 1010 + 700), + SafeBurnValue: big.NewInt(2510 - 50 + 310 - 50 + 700 - 50), }, } } @@ -375,6 +379,9 @@ func ApplyEUROCRefundBalances(token *framework.TestTokenParams) { token.DeltaBalances[framework.SecondHalfBridge][framework.Alice].OnEth = big.NewInt(-5010 - 7010 - 1010 - 700 + 960 + 650) // no funds remain in the called test SC token.DeltaBalances[framework.SecondHalfBridge][framework.CalledTestSC].OnMvx = big.NewInt(0) + + token.MintBurnChecks.TotalUniversalBurn = big.NewInt(2510 - 50 + 310 - 50 + 700 - 50 + 1010 - 50) + token.MintBurnChecks.SafeBurnValue = big.NewInt(2510 - 50 + 310 - 50 + 700 - 50 + 1010 - 50) } // GenerateTestMEXToken will generate a test MEX token @@ -476,7 +483,8 @@ func GenerateTestMEXToken() framework.TestTokenParams { TotalChainSpecificMint: big.NewInt(0), TotalUniversalBurn: big.NewInt(4010 - 50 + 6010 - 50 + 2010 - 50), TotalChainSpecificBurn: big.NewInt(0), - MintBurnValues: nil, + SafeMintValue: big.NewInt(2410 + 210 + 1010), + SafeBurnValue: big.NewInt(4010 - 50 + 6010 - 50 + 2010 - 50), }, } } @@ -489,6 +497,9 @@ func ApplyMEXRefundBalances(token *framework.TestTokenParams) { token.DeltaBalances[framework.SecondHalfBridge][framework.Bob].OnEth = big.NewInt(4010 - 50 - 2410 + 6010 - 50 - 210 + 2010 - 50 - 1010 + 960) // no funds remain in the test caller SC token.DeltaBalances[framework.SecondHalfBridge][framework.CalledTestSC].OnMvx = big.NewInt(0) + + token.MintBurnChecks.TotalUniversalBurn = big.NewInt(4010 - 50 + 6010 - 50 + 2010 - 50 + 1010 - 50) + token.MintBurnChecks.SafeBurnValue = big.NewInt(4010 - 50 + 6010 - 50 + 2010 - 50 + 1010 - 50) } // GenerateUnlistedTokenFromEth will generate an unlisted token on Eth @@ -582,6 +593,14 @@ func GenerateUnlistedTokenFromEth() framework.TestTokenParams { }, }, }, + MintBurnChecks: &framework.MintBurnBalances{ + TotalUniversalMint: big.NewInt(0), + TotalChainSpecificMint: big.NewInt(0), + TotalUniversalBurn: big.NewInt(0), + TotalChainSpecificBurn: big.NewInt(0), + SafeMintValue: big.NewInt(0), + SafeBurnValue: big.NewInt(0), + }, } } @@ -674,6 +693,14 @@ func GenerateUnlistedTokenFromMvx() framework.TestTokenParams { }, }, }, + MintBurnChecks: &framework.MintBurnBalances{ + TotalUniversalMint: big.NewInt(0), + TotalChainSpecificMint: big.NewInt(0), + TotalUniversalBurn: big.NewInt(0), + TotalChainSpecificBurn: big.NewInt(0), + SafeMintValue: big.NewInt(0), + SafeBurnValue: big.NewInt(0), + }, } } diff --git a/integrationTests/relayers/slowTests/edgeCases_test.go b/integrationTests/relayers/slowTests/edgeCases_test.go index 77e4026d..cc290eb1 100644 --- a/integrationTests/relayers/slowTests/edgeCases_test.go +++ b/integrationTests/relayers/slowTests/edgeCases_test.go @@ -90,7 +90,8 @@ func TestRelayerShouldExecuteSimultaneousSwapsAndNotCatchErrors(t *testing.T) { TotalChainSpecificMint: big.NewInt(5000 + 5000), TotalUniversalBurn: big.NewInt(200), TotalChainSpecificBurn: big.NewInt(200 - 50), - MintBurnValues: nil, + SafeMintValue: big.NewInt(5000 + 5000), + SafeBurnValue: big.NewInt(200 - 50), } _ = testRelayersWithChainSimulatorAndTokensForSimultaneousSwaps( diff --git a/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go b/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go index 6a2ccb08..9c4b5beb 100644 --- a/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go +++ b/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go @@ -144,11 +144,14 @@ func TestRelayerShouldExecuteTransfersAndNotCatchErrors(t *testing.T) { } func TestRelayersShouldExecuteTransfersWithInitSupply(t *testing.T) { + usdcInitialValue := big.NewInt(100000) usdcToken := GenerateTestUSDCToken() - usdcToken.InitialSupplyValue = "100000" + usdcToken.InitialSupplyValue = usdcInitialValue.String() + usdcToken.MintBurnChecks.SafeMintValue.Add(usdcToken.MintBurnChecks.SafeMintValue, usdcInitialValue) + memeInitialValue := big.NewInt(200000) memeToken := GenerateTestMEMEToken() - memeToken.InitialSupplyValue = "200000" + memeToken.InitialSupplyValue = memeInitialValue.String() _ = testRelayersWithChainSimulatorAndTokens( t, @@ -159,11 +162,15 @@ func TestRelayersShouldExecuteTransfersWithInitSupply(t *testing.T) { } func TestRelayersShouldExecuteTransfersWithInitSupplyMintBurn(t *testing.T) { + eurocInitialValue := big.NewInt(100010) eurocToken := GenerateTestEUROCToken() - eurocToken.InitialSupplyValue = "100010" + eurocToken.InitialSupplyValue = eurocInitialValue.String() + eurocToken.MintBurnChecks.SafeMintValue.Add(eurocToken.MintBurnChecks.SafeMintValue, eurocInitialValue) + mexInitialValue := big.NewInt(300000) mexToken := GenerateTestMEXToken() - mexToken.InitialSupplyValue = "300000" + mexToken.InitialSupplyValue = mexInitialValue.String() + mexToken.MintBurnChecks.SafeBurnValue.Add(mexToken.MintBurnChecks.SafeBurnValue, mexInitialValue) _ = testRelayersWithChainSimulatorAndTokens( t, @@ -370,7 +377,8 @@ func createBadToken() framework.TestTokenParams { TotalChainSpecificMint: big.NewInt(0), TotalUniversalBurn: big.NewInt(0), TotalChainSpecificBurn: big.NewInt(0), - MintBurnValues: nil, + SafeMintValue: big.NewInt(0), + SafeBurnValue: big.NewInt(0), }, } } diff --git a/integrationTests/relayers/slowTests/framework/multiversxHandler.go b/integrationTests/relayers/slowTests/framework/multiversxHandler.go index d1746d93..d96cd8b3 100644 --- a/integrationTests/relayers/slowTests/framework/multiversxHandler.go +++ b/integrationTests/relayers/slowTests/framework/multiversxHandler.go @@ -77,11 +77,11 @@ const ( getRefundFeesForEthereumFunction = "getRefundFeesForEthereum" withdrawTransactionFeesFunction = "withdrawTransactionFees" getTransactionFeesFunction = "getTransactionFees" - initSupplyMintBurnEsdtSafe = "initSupplyMintBurnEsdtSafe" - initSupplyEsdtSafe = "initSupplyEsdtSafe" - getMintBalances = "getMintBalances" - getBurnBalances = "getBurnBalances" - getTotalBalances = "getTotalBalances" + initSupplyMintBurnEsdtSafeFunction = "initSupplyMintBurnEsdtSafe" + initSupplyEsdtSafeFunction = "initSupplyEsdtSafe" + getMintBalancesFunction = "getMintBalances" + getBurnBalancesFunction = "getBurnBalances" + getTotalBalancesFunction = "getTotalBalances" ) var ( @@ -854,7 +854,7 @@ func (handler *MultiversxHandler) setInitialSupply(ctx context.Context, params I handler.MultisigAddress, zeroStringValue, setCallsGasLimit, - initSupplyMintBurnEsdtSafe, + initSupplyMintBurnEsdtSafeFunction, scCallParams) log.Info("initial supply tx executed", "hash", hash, "status", txResult.Status, @@ -863,7 +863,7 @@ func (handler *MultiversxHandler) setInitialSupply(ctx context.Context, params I scCallParams := []string{ hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), hex.EncodeToString(initialSupply.Bytes()), - hex.EncodeToString([]byte(initSupplyEsdtSafe)), + hex.EncodeToString([]byte(initSupplyEsdtSafeFunction)), hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), hex.EncodeToString(initialSupply.Bytes()), } @@ -1165,7 +1165,7 @@ func (handler *MultiversxHandler) GetTotalBalancesForToken(ctx context.Context, queryParams := []string{ hex.EncodeToString([]byte(token)), } - responseData := handler.ChainSimulator.ExecuteVMQuery(ctx, handler.SafeAddress, getTotalBalances, queryParams) + responseData := handler.ChainSimulator.ExecuteVMQuery(ctx, handler.SafeAddress, getTotalBalancesFunction, queryParams) require.Greater(handler, len(responseData), 0) value := big.NewInt(0).SetBytes(responseData[0]) return value @@ -1176,7 +1176,7 @@ func (handler *MultiversxHandler) GetMintedAmountForToken(ctx context.Context, t queryParams := []string{ hex.EncodeToString([]byte(token)), } - responseData := handler.ChainSimulator.ExecuteVMQuery(ctx, handler.SafeAddress, getMintBalances, queryParams) + responseData := handler.ChainSimulator.ExecuteVMQuery(ctx, handler.SafeAddress, getMintBalancesFunction, queryParams) require.Greater(handler, len(responseData), 0) value := big.NewInt(0).SetBytes(responseData[0]) return value @@ -1187,7 +1187,7 @@ func (handler *MultiversxHandler) GetBurnedAmountForToken(ctx context.Context, t queryParams := []string{ hex.EncodeToString([]byte(token)), } - responseData := handler.ChainSimulator.ExecuteVMQuery(ctx, handler.SafeAddress, getBurnBalances, queryParams) + responseData := handler.ChainSimulator.ExecuteVMQuery(ctx, handler.SafeAddress, getBurnBalancesFunction, queryParams) require.Greater(handler, len(responseData), 0) value := big.NewInt(0).SetBytes(responseData[0]) return value diff --git a/integrationTests/relayers/slowTests/framework/testSetup.go b/integrationTests/relayers/slowTests/framework/testSetup.go index 498f8dde..ff1bb7d6 100644 --- a/integrationTests/relayers/slowTests/framework/testSetup.go +++ b/integrationTests/relayers/slowTests/framework/testSetup.go @@ -678,41 +678,39 @@ func (setup *TestSetup) TestWithdrawTotalFeesOnEthereumForTokens(tokensParams .. } } -// CheckTotalMintBurn will return true if all tokens successfully passed the mint/burn checks for total values -func (setup *TestSetup) CheckTotalMintBurn(tokens ...TestTokenParams) bool { - isDone := true +// CheckCorrectnessOnMintBurnTokens will check the correctness on the mint/burn tokens +func (setup *TestSetup) CheckCorrectnessOnMintBurnTokens(tokens ...TestTokenParams) { for _, params := range tokens { - isDone = isDone && setup.isTotalMintBurnCheckOKOnMvx(params) + setup.checkTotalMintBurnOnMvx(params) + setup.checkSafeContractMintBurnOnMvx(params) } - - return isDone } -func (setup *TestSetup) isTotalMintBurnCheckOKOnMvx(token TestTokenParams) bool { +func (setup *TestSetup) checkTotalMintBurnOnMvx(token TestTokenParams) { tokenData := setup.TokensRegistry.GetTokenData(token.AbstractTokenIdentifier) esdtSupplyForUniversal := setup.MultiversxHandler.ChainSimulator.GetESDTSupplyValues(setup.Ctx, tokenData.MvxUniversalToken) - if esdtSupplyForUniversal.Minted != token.MintBurnChecks.TotalUniversalMint.String() { - return false - } - if esdtSupplyForUniversal.Burned != token.MintBurnChecks.TotalUniversalBurn.String() { - return false - } + require.Equal(setup, token.MintBurnChecks.TotalUniversalMint.String(), esdtSupplyForUniversal.Minted, fmt.Sprintf("token: %s", tokenData.MvxUniversalToken)) + require.Equal(setup, token.MintBurnChecks.TotalUniversalBurn.String(), esdtSupplyForUniversal.Burned, fmt.Sprintf("token: %s", tokenData.MvxUniversalToken)) if tokenData.MvxUniversalToken == tokenData.MvxChainSpecificToken { // we do not have a chain specific token, we can return true here - return true + return } esdtSupplyForChainSpecific := setup.MultiversxHandler.ChainSimulator.GetESDTSupplyValues(setup.Ctx, tokenData.MvxChainSpecificToken) - if esdtSupplyForChainSpecific.Minted != token.MintBurnChecks.TotalChainSpecificMint.String() { - return false - } - if esdtSupplyForChainSpecific.Burned != token.MintBurnChecks.TotalChainSpecificBurn.String() { - return false - } + require.Equal(setup, token.MintBurnChecks.TotalChainSpecificMint.String(), esdtSupplyForChainSpecific.Minted, fmt.Sprintf("token: %s", tokenData.MvxChainSpecificToken)) + require.Equal(setup, token.MintBurnChecks.TotalChainSpecificBurn.String(), esdtSupplyForChainSpecific.Burned, fmt.Sprintf("token: %s", tokenData.MvxChainSpecificToken)) +} - return true +func (setup *TestSetup) checkSafeContractMintBurnOnMvx(token TestTokenParams) { + tokenData := setup.TokensRegistry.GetTokenData(token.AbstractTokenIdentifier) + + minted := setup.MultiversxHandler.GetMintedAmountForToken(setup.Ctx, tokenData.MvxChainSpecificToken) + require.Equal(setup, token.MintBurnChecks.SafeMintValue.String(), minted.String(), fmt.Sprintf("safe contract, token: %s", tokenData.MvxChainSpecificToken)) + + burn := setup.MultiversxHandler.GetBurnedAmountForToken(setup.Ctx, tokenData.MvxChainSpecificToken) + require.Equal(setup, token.MintBurnChecks.SafeBurnValue.String(), burn.String(), fmt.Sprintf("safe contract, token: %s", tokenData.MvxChainSpecificToken)) } // Close will close the test subcomponents diff --git a/integrationTests/relayers/slowTests/framework/types.go b/integrationTests/relayers/slowTests/framework/types.go index 0c2a2357..6ab2e2f7 100644 --- a/integrationTests/relayers/slowTests/framework/types.go +++ b/integrationTests/relayers/slowTests/framework/types.go @@ -87,14 +87,8 @@ type MintBurnBalances struct { TotalChainSpecificMint *big.Int TotalUniversalBurn *big.Int TotalChainSpecificBurn *big.Int - MintBurnValues map[HalfBridgeIdentifier]MintBurnBalanceHolder -} - -// MintBurnBalanceHolder holds the mint/burn values for a specific address -type MintBurnBalanceHolder struct { - OnEth *big.Int - OnMvx *big.Int - MvxToken TokenBalanceType + SafeMintValue *big.Int + SafeBurnValue *big.Int } // ESDTSupply represents the DTO that holds the supply values for a token diff --git a/integrationTests/relayers/slowTests/testFlow.go b/integrationTests/relayers/slowTests/testFlow.go index b79dd9d7..8fc3bc5e 100644 --- a/integrationTests/relayers/slowTests/testFlow.go +++ b/integrationTests/relayers/slowTests/testFlow.go @@ -54,8 +54,9 @@ func (flow *testFlow) process() (finished bool) { } transferDoneForSecondHalf := flow.setup.AreAllTransfersCompleted(framework.SecondHalfBridge, flow.tokens...) - transferDoneForSecondHalf = transferDoneForSecondHalf && flow.setup.CheckTotalMintBurn(flow.tokens...) if !flow.secondHalfBridgeDone && transferDoneForSecondHalf { + flow.setup.CheckCorrectnessOnMintBurnTokens(flow.tokens...) + flow.secondHalfBridgeDone = true log.Info(fmt.Sprintf(framework.LogStepMarker, flow.messageAfterSecondHalfBridge))