Skip to content

Commit

Permalink
Merge pull request #393 from multiversx/check-mint-burn-tokens
Browse files Browse the repository at this point in the history
Check mint burn tokens
  • Loading branch information
iulianpascalau authored Dec 11, 2024
2 parents 05097de + 3ded781 commit 663f78e
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 16 deletions.
60 changes: 59 additions & 1 deletion integrationTests/relayers/slowTests/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
}
}

Expand All @@ -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
Expand All @@ -148,7 +160,7 @@ func GenerateTestMEMEToken() framework.TestTokenParams {
ValueToMintOnMvx: "10000000000",
IsMintBurnOnMvX: false,
IsNativeOnMvX: true,
HasChainSpecificToken: true,
HasChainSpecificToken: false,
EthTokenName: "EthMEME",
EthTokenSymbol: "MEME",
ValueToMintOnEth: "10000000000",
Expand Down Expand Up @@ -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),
},
}
}

Expand Down Expand Up @@ -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),
},
}
}

Expand All @@ -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
Expand Down Expand Up @@ -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),
},
}
}

Expand All @@ -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
Expand Down Expand Up @@ -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),
},
}
}

Expand Down Expand Up @@ -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),
},
}
}

Expand Down
8 changes: 8 additions & 0 deletions integrationTests/relayers/slowTests/edgeCases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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),
},
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
}
1 change: 1 addition & 0 deletions integrationTests/relayers/slowTests/framework/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions integrationTests/relayers/slowTests/framework/multiversxHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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,
Expand All @@ -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()),
}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
35 changes: 35 additions & 0 deletions integrationTests/relayers/slowTests/framework/testSetup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
19 changes: 18 additions & 1 deletion integrationTests/relayers/slowTests/framework/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type TestTokenParams struct {
IssueTokenParams
TestOperations []TokenOperations
DeltaBalances map[HalfBridgeIdentifier]DeltaBalancesOnKeys
MintBurnChecks *MintBurnBalances
}

// TokenData represents a test token data
Expand All @@ -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"`
}
3 changes: 3 additions & 0 deletions integrationTests/relayers/slowTests/testFlow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 663f78e

Please sign in to comment.