Skip to content

Commit

Permalink
Merge pull request #375 from multiversx/add-more-checks
Browse files Browse the repository at this point in the history
Add more checks
  • Loading branch information
cosmatudor authored Nov 18, 2024
2 parents 4b1aa1f + 25d6733 commit 301c95a
Show file tree
Hide file tree
Showing 4 changed files with 363 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,21 @@ func TestRelayersShouldExecuteTransfersWithInitSupply(t *testing.T) {
)
}

func TestRelayersShouldExecuteTransfersWithInitSupplyMintBurn(t *testing.T) {
eurocToken := GenerateTestEUROCToken()
eurocToken.InitialSupplyValue = "100010"

mexToken := GenerateTestMEXToken()
mexToken.InitialSupplyValue = "300000"

_ = testRelayersWithChainSimulatorAndTokens(
t,
make(chan error),
eurocToken,
mexToken,
)
}

func testRelayersWithChainSimulatorAndTokens(tb testing.TB, manualStopChan chan error, tokens ...framework.TestTokenParams) *framework.TestSetup {
startsFromEthFlow, startsFromMvXFlow := createFlowsBasedOnToken(tb, tokens...)

Expand Down
39 changes: 36 additions & 3 deletions integrationTests/relayers/slowTests/framework/ethereumHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,20 @@ func (handler *EthereumHandler) IssueAndWhitelistToken(ctx context.Context, para
handler.checkEthTxResult(ctx, tx.Hash())

if len(params.InitialSupplyValue) > 0 {
initialSupply, ok := big.NewInt(0).SetString(params.InitialSupplyValue, 10)
require.True(handler, ok)

if params.IsMintBurnOnEth {
mintAmount, ok := big.NewInt(0).SetString(params.InitialSupplyValue, 10)
require.True(handler, ok)
mintAmount := big.NewInt(0)
burnAmount := big.NewInt(0)

tx, err = handler.SafeContract.InitSupplyMintBurn(auth, erc20Address, mintAmount, zeroValueBigInt)
if params.IsNativeOnEth {
burnAmount = initialSupply
} else {
mintAmount = initialSupply
}

tx, err = handler.SafeContract.InitSupplyMintBurn(auth, erc20Address, mintAmount, burnAmount)
require.NoError(handler, err)
handler.SimulatedChain.Commit()
handler.checkEthTxResult(ctx, tx.Hash())
Expand Down Expand Up @@ -462,6 +471,30 @@ func (handler *EthereumHandler) Mint(ctx context.Context, params TestTokenParams
handler.checkEthTxResult(ctx, tx.Hash())
}

// GetTotalBalancesForToken will return the total locked balance for the provided token
func (handler *EthereumHandler) GetTotalBalancesForToken(ctx context.Context, address common.Address) *big.Int {
opts := &bind.CallOpts{Context: ctx}
balance, err := handler.SafeContract.TotalBalances(opts, address)
require.NoError(handler, err)
return balance
}

// GetBurnBalanceForToken will return burn balance for the provided token
func (handler *EthereumHandler) GetBurnBalanceForToken(ctx context.Context, address common.Address) *big.Int {
opts := &bind.CallOpts{Context: ctx}
balance, err := handler.SafeContract.BurnBalances(opts, address)
require.NoError(handler, err)
return balance
}

// GetMintBalanceForToken will return mint balance for the provided token
func (handler *EthereumHandler) GetMintBalanceForToken(ctx context.Context, address common.Address) *big.Int {
opts := &bind.CallOpts{Context: ctx}
balance, err := handler.SafeContract.MintBalances(opts, address)
require.NoError(handler, err)
return balance
}

// Close will close the resources allocated
func (handler *EthereumHandler) Close() error {
return handler.SimulatedChain.Close()
Expand Down
53 changes: 50 additions & 3 deletions integrationTests/relayers/slowTests/framework/multiversxHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ const (
getTransactionFeesFunction = "getTransactionFees"
initSupplyMintBurnEsdtSafe = "initSupplyMintBurnEsdtSafe"
initSupplyEsdtSafe = "initSupplyEsdtSafe"
getMintBalances = "getMintBalances"
getBurnBalances = "getBurnBalances"
getTotalBalances = "getTotalBalances"
)

var (
Expand Down Expand Up @@ -800,6 +803,15 @@ func (handler *MultiversxHandler) setInitialSupply(ctx context.Context, params I
require.True(handler, okConvert)

if params.IsMintBurnOnMvX {
mintAmount := big.NewInt(0)
burnAmount := big.NewInt(0)

if params.IsNativeOnMvX {
burnAmount = initialSupply
} else {
mintAmount = initialSupply
}

hash, txResult := handler.ChainSimulator.ScCall(
ctx,
handler.OwnerKeys.MvxSk,
Expand All @@ -809,12 +821,13 @@ func (handler *MultiversxHandler) setInitialSupply(ctx context.Context, params I
initSupplyMintBurnEsdtSafe,
[]string{
hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)),
hex.EncodeToString(initialSupply.Bytes()),
hex.EncodeToString([]byte{0}),
hex.EncodeToString(mintAmount.Bytes()),
hex.EncodeToString(burnAmount.Bytes()),
},
)

log.Info("initial supply tx executed", "hash", hash, "status", txResult.Status,
"initial mint", params.InitialSupplyValue, "initial burned", "0")
"initial mint", mintAmount.String(), "initial burned", burnAmount.String())
} else {
hash, txResult := handler.ChainSimulator.ScCall(
ctx,
Expand Down Expand Up @@ -986,6 +999,7 @@ func (handler *MultiversxHandler) withdrawFees(ctx context.Context,
hex.EncodeToString([]byte(token)),
}
responseData := handler.ChainSimulator.ExecuteVMQuery(ctx, handler.SafeAddress, getFunction, queryParams)
require.Greater(handler, len(responseData), 0)
value := big.NewInt(0).SetBytes(responseData[0])
require.Equal(handler, expectedDelta.String(), value.String())
if expectedDelta.Cmp(zeroValueBigInt) == 0 {
Expand Down Expand Up @@ -1043,6 +1057,39 @@ func (handler *MultiversxHandler) TransferToken(ctx context.Context, source Keys
"hash", hash, "status", txResult.Status)
}

// GetTotalBalancesForToken will return the total locked balance for the provided token
func (handler *MultiversxHandler) GetTotalBalancesForToken(ctx context.Context, token string) *big.Int {
queryParams := []string{
hex.EncodeToString([]byte(token)),
}
responseData := handler.ChainSimulator.ExecuteVMQuery(ctx, handler.SafeAddress, getTotalBalances, queryParams)
require.Greater(handler, len(responseData), 0)
value := big.NewInt(0).SetBytes(responseData[0])
return value
}

// GetMintedAmountForToken will return mint balance for token
func (handler *MultiversxHandler) GetMintedAmountForToken(ctx context.Context, token string) *big.Int {
queryParams := []string{
hex.EncodeToString([]byte(token)),
}
responseData := handler.ChainSimulator.ExecuteVMQuery(ctx, handler.SafeAddress, getMintBalances, queryParams)
require.Greater(handler, len(responseData), 0)
value := big.NewInt(0).SetBytes(responseData[0])
return value
}

// GetBurnedAmountForToken will return burn balance of token
func (handler *MultiversxHandler) GetBurnedAmountForToken(ctx context.Context, token string) *big.Int {
queryParams := []string{
hex.EncodeToString([]byte(token)),
}
responseData := handler.ChainSimulator.ExecuteVMQuery(ctx, handler.SafeAddress, getBurnBalances, queryParams)
require.Greater(handler, len(responseData), 0)
value := big.NewInt(0).SetBytes(responseData[0])
return value
}

func getHexBool(input bool) string {
if input {
return hexTrue
Expand Down
Loading

0 comments on commit 301c95a

Please sign in to comment.