diff --git a/integrationTests/relayers/slowTests/common.go b/integrationTests/relayers/slowTests/common.go index dc7a5750..f3c8e92d 100644 --- a/integrationTests/relayers/slowTests/common.go +++ b/integrationTests/relayers/slowTests/common.go @@ -116,6 +116,14 @@ func GenerateTestUSDCToken() framework.TestTokenParams { }, }, }, + MintBurnChecks: &framework.MintBurnBalances{ + TotalUniversalMint: big.NewInt(5000 + 7000 + 1000), + TotalChainSpecificMint: big.NewInt(5000 + 7000 + 1000 + 900), + TotalUniversalBurn: big.NewInt(2500 + 300), + 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), + }, } } @@ -131,6 +139,10 @@ func ApplyUSDCRefundBalances(token *framework.TestTokenParams) { token.DeltaBalances[framework.SecondHalfBridge][framework.Alice].OnEth = big.NewInt(-5000 - 7000 - 1000 - 900 + 950 + 850) // 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 + 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 @@ -148,7 +160,7 @@ func GenerateTestMEMEToken() framework.TestTokenParams { ValueToMintOnMvx: "10000000000", IsMintBurnOnMvX: false, IsNativeOnMvX: true, - HasChainSpecificToken: true, + HasChainSpecificToken: false, EthTokenName: "EthMEME", EthTokenSymbol: "MEME", ValueToMintOnEth: "10000000000", @@ -227,6 +239,14 @@ func GenerateTestMEMEToken() 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), + }, } } @@ -338,6 +358,14 @@ func GenerateTestEUROCToken() framework.TestTokenParams { }, }, }, + MintBurnChecks: &framework.MintBurnBalances{ + TotalUniversalMint: big.NewInt(5010 + 7010 + 1010 + 700), + TotalChainSpecificMint: big.NewInt(0), + TotalUniversalBurn: big.NewInt(2510 - 50 + 310 - 50 + 700 - 50), + TotalChainSpecificBurn: big.NewInt(0), + SafeMintValue: big.NewInt(5010 + 7010 + 1010 + 700), + SafeBurnValue: big.NewInt(2510 - 50 + 310 - 50 + 700 - 50), + }, } } @@ -351,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 @@ -447,6 +478,14 @@ func GenerateTestMEXToken() framework.TestTokenParams { }, }, }, + MintBurnChecks: &framework.MintBurnBalances{ + TotalUniversalMint: big.NewInt(2410 + 210 + 1010), + TotalChainSpecificMint: big.NewInt(0), + TotalUniversalBurn: big.NewInt(4010 - 50 + 6010 - 50 + 2010 - 50), + TotalChainSpecificBurn: big.NewInt(0), + SafeMintValue: big.NewInt(2410 + 210 + 1010), + SafeBurnValue: big.NewInt(4010 - 50 + 6010 - 50 + 2010 - 50), + }, } } @@ -458,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 @@ -551,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), + }, } } @@ -643,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 056b5176..cc290eb1 100644 --- a/integrationTests/relayers/slowTests/edgeCases_test.go +++ b/integrationTests/relayers/slowTests/edgeCases_test.go @@ -85,6 +85,14 @@ func TestRelayerShouldExecuteSimultaneousSwapsAndNotCatchErrors(t *testing.T) { }, }, } + usdcToken.MintBurnChecks = &framework.MintBurnBalances{ + TotalUniversalMint: big.NewInt(5000 + 5000), + TotalChainSpecificMint: big.NewInt(5000 + 5000), + TotalUniversalBurn: big.NewInt(200), + TotalChainSpecificBurn: big.NewInt(200 - 50), + SafeMintValue: big.NewInt(5000 + 5000), + SafeBurnValue: big.NewInt(200 - 50), + } _ = testRelayersWithChainSimulatorAndTokensForSimultaneousSwaps( t, diff --git a/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go b/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go index be6f5777..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, @@ -365,6 +372,14 @@ func createBadToken() 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/framework/chainSimulatorWrapper.go b/integrationTests/relayers/slowTests/framework/chainSimulatorWrapper.go index 0c1983a8..843b2231 100644 --- a/integrationTests/relayers/slowTests/framework/chainSimulatorWrapper.go +++ b/integrationTests/relayers/slowTests/framework/chainSimulatorWrapper.go @@ -37,6 +37,7 @@ const ( generateBlocksUntilTxProcessedEndpoint = "simulator/generate-blocks-until-transaction-processed/%s" numProbeRetries = 10 networkConfigEndpointTemplate = "network/status/%d" + esdtSupplyEndpointTemplate = "network/esdt/supply/%s" ) var ( @@ -380,3 +381,20 @@ func (instance *chainSimulatorWrapper) ExecuteVMQuery( return response.Data.ReturnData } + +// GetESDTSupplyValues get all supply parameters for a token +func (instance *chainSimulatorWrapper) GetESDTSupplyValues(ctx context.Context, token string) ESDTSupply { + resultBytes, status, err := instance.clientWrapper.GetHTTP(ctx, fmt.Sprintf(esdtSupplyEndpointTemplate, token)) + if err != nil || status != http.StatusOK { + require.Fail(instance, fmt.Sprintf("error %v, status code %d in chainSimulatorWrapper.GetESDTSupplyValues", err, status)) + } + + resultStruct := struct { + Data ESDTSupply `json:"data"` + }{} + + err = json.Unmarshal(resultBytes, &resultStruct) + require.Nil(instance, err) + + return resultStruct.Data +} diff --git a/integrationTests/relayers/slowTests/framework/interface.go b/integrationTests/relayers/slowTests/framework/interface.go index 790063fe..1ad94510 100644 --- a/integrationTests/relayers/slowTests/framework/interface.go +++ b/integrationTests/relayers/slowTests/framework/interface.go @@ -44,6 +44,7 @@ type ChainSimulatorWrapper interface { GetBlockchainTimeStamp(ctx context.Context) uint64 GetTransactionResult(ctx context.Context, hash string) (*data.TransactionOnNetwork, transaction.TxStatus) ExecuteVMQuery(ctx context.Context, scAddress *MvxAddress, function string, hexParams []string) [][]byte + GetESDTSupplyValues(ctx context.Context, token string) ESDTSupply } // EthereumBlockchainClient defines the operations supported by the Ethereum client 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 8141db4c..ff1bb7d6 100644 --- a/integrationTests/relayers/slowTests/framework/testSetup.go +++ b/integrationTests/relayers/slowTests/framework/testSetup.go @@ -678,6 +678,41 @@ func (setup *TestSetup) TestWithdrawTotalFeesOnEthereumForTokens(tokensParams .. } } +// CheckCorrectnessOnMintBurnTokens will check the correctness on the mint/burn tokens +func (setup *TestSetup) CheckCorrectnessOnMintBurnTokens(tokens ...TestTokenParams) { + for _, params := range tokens { + setup.checkTotalMintBurnOnMvx(params) + setup.checkSafeContractMintBurnOnMvx(params) + } +} + +func (setup *TestSetup) checkTotalMintBurnOnMvx(token TestTokenParams) { + tokenData := setup.TokensRegistry.GetTokenData(token.AbstractTokenIdentifier) + + esdtSupplyForUniversal := setup.MultiversxHandler.ChainSimulator.GetESDTSupplyValues(setup.Ctx, tokenData.MvxUniversalToken) + 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 + } + + esdtSupplyForChainSpecific := setup.MultiversxHandler.ChainSimulator.GetESDTSupplyValues(setup.Ctx, tokenData.MvxChainSpecificToken) + 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)) +} + +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 func (setup *TestSetup) Close() { log.Info(fmt.Sprintf(LogStepMarker, "closing relayers & sc execution module")) diff --git a/integrationTests/relayers/slowTests/framework/types.go b/integrationTests/relayers/slowTests/framework/types.go index f5a0dca9..6ab2e2f7 100644 --- a/integrationTests/relayers/slowTests/framework/types.go +++ b/integrationTests/relayers/slowTests/framework/types.go @@ -56,6 +56,7 @@ type TestTokenParams struct { IssueTokenParams TestOperations []TokenOperations DeltaBalances map[HalfBridgeIdentifier]DeltaBalancesOnKeys + MintBurnChecks *MintBurnBalances } // TokenData represents a test token data @@ -78,5 +79,21 @@ type DeltaBalanceHolder struct { OnEth *big.Int OnMvx *big.Int MvxToken TokenBalanceType - //TODO next PR: add checking for mint/burned tokens on ESDT & Wrapper contracts +} + +// MintBurnBalances holds the mint/burn tokens balances for a test token +type MintBurnBalances struct { + TotalUniversalMint *big.Int + TotalChainSpecificMint *big.Int + TotalUniversalBurn *big.Int + TotalChainSpecificBurn *big.Int + SafeMintValue *big.Int + SafeBurnValue *big.Int +} + +// ESDTSupply represents the DTO that holds the supply values for a token +type ESDTSupply struct { + Supply string `json:"supply"` + Minted string `json:"minted"` + Burned string `json:"burned"` } diff --git a/integrationTests/relayers/slowTests/testFlow.go b/integrationTests/relayers/slowTests/testFlow.go index 5840ba81..8fc3bc5e 100644 --- a/integrationTests/relayers/slowTests/testFlow.go +++ b/integrationTests/relayers/slowTests/testFlow.go @@ -55,8 +55,11 @@ func (flow *testFlow) process() (finished bool) { transferDoneForSecondHalf := flow.setup.AreAllTransfersCompleted(framework.SecondHalfBridge, flow.tokens...) if !flow.secondHalfBridgeDone && transferDoneForSecondHalf { + flow.setup.CheckCorrectnessOnMintBurnTokens(flow.tokens...) + flow.secondHalfBridgeDone = true log.Info(fmt.Sprintf(framework.LogStepMarker, flow.messageAfterSecondHalfBridge)) + return true }