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 1 commit
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
41 changes: 35 additions & 6 deletions integrationTests/relayers/slowTests/framework/ethereumHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,22 @@ func (handler *EthereumHandler) IssueAndWhitelistToken(ctx context.Context, para
handler.checkEthTxResult(ctx, tx.Hash())

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

tx, err = handler.SafeContract.InitSupplyMintBurn(auth, erc20Address, mintAmount, zeroValueBigInt)
require.NoError(handler, err)
if params.IsMintBurnOnEth {
var tx2 *types.Transaction
iulianpascalau marked this conversation as resolved.
Show resolved Hide resolved
var err2 error
if params.IsNativeOnEth {
burnAmount := initialSupply
tx2, err2 = handler.SafeContract.InitSupplyMintBurn(auth, erc20Address, zeroValueBigInt, burnAmount)
} else {
mintAmount := initialSupply
tx2, err2 = handler.SafeContract.InitSupplyMintBurn(auth, erc20Address, mintAmount, zeroValueBigInt)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps extract txInitSupplyMintBurn, errInitSupplyMintBurn := handler.SafeContract.InitSupplyMintBurn(auth, erc20Address, mintAmount, burnAmount) to be called only once after this if and only set minAmount and burnAmount here

require.NoError(handler, err2)
handler.SimulatedChain.Commit()
handler.checkEthTxResult(ctx, tx.Hash())
handler.checkEthTxResult(ctx, tx2.Hash())
} else {
// reset the tokens value for the safe contract, so it will "know" about the balance that it has in the ERC20 contract
tx, err = handler.SafeContract.ResetTotalBalance(auth, erc20Address)
Expand Down Expand Up @@ -492,6 +500,27 @@ func (handler *EthereumHandler) Mint(ctx context.Context, params TestTokenParams
handler.checkEthTxResult(ctx, tx.Hash())
}

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
}

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
}

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
80 changes: 65 additions & 15 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,21 +803,41 @@ func (handler *MultiversxHandler) setInitialSupply(ctx context.Context, params I
require.True(handler, okConvert)

if params.IsMintBurnOnMvX {
hash, txResult := handler.ChainSimulator.ScCall(
ctx,
handler.OwnerKeys.MvxSk,
handler.MultisigAddress,
zeroStringValue,
setCallsGasLimit,
initSupplyMintBurnEsdtSafe,
[]string{
hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)),
hex.EncodeToString(initialSupply.Bytes()),
hex.EncodeToString([]byte{0}),
},
)
log.Info("initial supply tx executed", "hash", hash, "status", txResult.Status,
"initial mint", params.InitialSupplyValue, "initial burned", "0")
if params.IsNativeOnMvX {
burnAmount := initialSupply
hash, txResult := handler.ChainSimulator.ScCall(
ctx,
handler.OwnerKeys.MvxSk,
handler.MultisigAddress,
zeroStringValue,
setCallsGasLimit,
initSupplyMintBurnEsdtSafe,
[]string{
hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)),
hex.EncodeToString(zeroValueBigInt.Bytes()),
hex.EncodeToString(burnAmount.Bytes()),
},
)
log.Info("initial supply tx executed", "hash", hash, "status", txResult.Status,
"initial mint", "0", "initial burned", params.InitialSupplyValue)
} else {
mintAmount := initialSupply
hash, txResult := handler.ChainSimulator.ScCall(
ctx,
handler.OwnerKeys.MvxSk,
handler.MultisigAddress,
zeroStringValue,
setCallsGasLimit,
initSupplyMintBurnEsdtSafe,
[]string{
hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)),
hex.EncodeToString(mintAmount.Bytes()),
hex.EncodeToString(zeroValueBigInt.Bytes()),
},
)
log.Info("initial supply tx executed", "hash", hash, "status", txResult.Status,
"initial mint", params.InitialSupplyValue, "initial burned", "0")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

same here, you can call ScCall only once, just set the proper variables inside ifs

} else {
hash, txResult := handler.ChainSimulator.ScCall(
ctx,
Expand Down Expand Up @@ -1043,6 +1066,33 @@ func (handler *MultiversxHandler) TransferToken(ctx context.Context, source Keys
"hash", hash, "status", txResult.Status)
}

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)
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
}

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)
value := big.NewInt(0).SetBytes(responseData[0])
return value
}

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)
value := big.NewInt(0).SetBytes(responseData[0])
return value
}

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