Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more checks #375

Merged
merged 9 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing comments on exported items. Here, on L510 & L517

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing comment on all new methods

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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing comments on new methods

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])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any chance that responseData is nil here, resulting in a panic while trying to access index 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
Loading