Skip to content

Commit

Permalink
- added checks for mint/burn tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
iulianpascalau committed Dec 10, 2024
1 parent 60677dd commit 3ded781
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 55 deletions.
45 changes: 36 additions & 9 deletions integrationTests/relayers/slowTests/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
}
}
Expand All @@ -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
Expand Down Expand Up @@ -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),
},
}
}
Expand Down Expand Up @@ -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),
},
}
}
Expand All @@ -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
Expand Down Expand Up @@ -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),
},
}
}
Expand All @@ -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
Expand Down Expand Up @@ -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),
},
}
}

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

Expand Down
3 changes: 2 additions & 1 deletion integrationTests/relayers/slowTests/edgeCases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
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 @@ -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),
},
}
}
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
40 changes: 19 additions & 21 deletions integrationTests/relayers/slowTests/framework/testSetup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions integrationTests/relayers/slowTests/framework/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion integrationTests/relayers/slowTests/testFlow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down

0 comments on commit 3ded781

Please sign in to comment.