diff --git a/integrationTests/relayers/slowTests/framework/ethereumHandler.go b/integrationTests/relayers/slowTests/framework/ethereumHandler.go index 50e75b54..df9e432a 100644 --- a/integrationTests/relayers/slowTests/framework/ethereumHandler.go +++ b/integrationTests/relayers/slowTests/framework/ethereumHandler.go @@ -351,13 +351,6 @@ func (handler *EthereumHandler) deployTestERC20Contract(ctx context.Context, par require.NoError(handler, err) require.Equal(handler, mintAmount.String(), balance.String()) - if params.IsNativeOnEth { - tx, err = ethMintBurnContract.Mint(auth, handler.AliceKeys.EthAddress, mintAmount) - require.NoError(handler, err) - handler.SimulatedChain.Commit() - handler.checkEthTxResult(ctx, tx.Hash()) - } - return ethMintBurnAddress, ethMintBurnContract } @@ -374,8 +367,8 @@ func (handler *EthereumHandler) deployTestERC20Contract(ctx context.Context, par ethGenericTokenContract, err := contract.NewGenericERC20(ethGenericTokenAddress, handler.SimulatedChain.Client()) require.NoError(handler, err) - // mint the address that will create the transfers - handler.mintTokens(ctx, ethGenericTokenContract, params.ValueToMintOnEth, handler.AliceKeys.EthAddress) + // mint to the depositor + handler.mintTokens(ctx, ethGenericTokenContract, params.ValueToMintOnEth, handler.DepositorKeys.EthAddress) if len(params.InitialSupplyValue) > 0 { handler.mintTokens(ctx, ethGenericTokenContract, params.InitialSupplyValue, handler.SafeAddress) } @@ -465,15 +458,18 @@ func (handler *EthereumHandler) SettleBatchOnEthereum() { } } -// Mint will mint the provided token on Ethereum with the provided value on the behalf of the Depositor address -func (handler *EthereumHandler) Mint(ctx context.Context, params TestTokenParams, valueToMint *big.Int) { - token := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) - require.NotNil(handler, token) - require.NotNil(handler, token.EthErc20Contract) +// TransferToken will transfer the amount of tokens from one address to another +func (handler *EthereumHandler) TransferToken( + ctx context.Context, + params TestTokenParams, + from KeysHolder, + to KeysHolder, + amount *big.Int, +) { + tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) - // mint erc20 token into eth safe - auth, _ := bind.NewKeyedTransactorWithChainID(handler.DepositorKeys.EthSK, handler.ChainID) - tx, err := token.EthErc20Contract.Mint(auth, handler.SafeAddress, valueToMint) + auth, _ := bind.NewKeyedTransactorWithChainID(from.EthSK, handler.ChainID) + tx, err := tkData.EthErc20Contract.Transfer(auth, to.EthAddress, amount) require.NoError(handler, err) handler.SimulatedChain.Commit() handler.checkEthTxResult(ctx, tx.Hash()) diff --git a/integrationTests/relayers/slowTests/framework/interface.go b/integrationTests/relayers/slowTests/framework/interface.go index 790063fe..a02dcc2b 100644 --- a/integrationTests/relayers/slowTests/framework/interface.go +++ b/integrationTests/relayers/slowTests/framework/interface.go @@ -60,6 +60,7 @@ type ERC20Contract interface { BalanceOf(opts *bind.CallOpts, account common.Address) (*big.Int, error) Mint(opts *bind.TransactOpts, recipientAddress common.Address, amount *big.Int) (*types.Transaction, error) Approve(opts *bind.TransactOpts, spender common.Address, value *big.Int) (*types.Transaction, error) + Transfer(opts *bind.TransactOpts, to common.Address, value *big.Int) (*types.Transaction, error) } // TokensRegistry defines the registry used for the tokens in tests diff --git a/integrationTests/relayers/slowTests/framework/testSetup.go b/integrationTests/relayers/slowTests/framework/testSetup.go index 8141db4c..ed142881 100644 --- a/integrationTests/relayers/slowTests/framework/testSetup.go +++ b/integrationTests/relayers/slowTests/framework/testSetup.go @@ -161,12 +161,6 @@ func (setup *TestSetup) IssueAndConfigureTokens(tokens ...TestTokenParams) { setup.AddToken(token.IssueTokenParams) setup.EthereumHandler.IssueAndWhitelistToken(setup.Ctx, token.IssueTokenParams) setup.MultiversxHandler.IssueAndWhitelistToken(setup.Ctx, token.IssueTokenParams) - if token.IsNativeOnMvX { - setup.transferTokensToMvxTestKey(token) // TODO: (Next PRs) this will be moved an batch creation time - } - setup.ChainSimulator.GenerateBlocks(setup.Ctx, 10) - - esdtBalanceForSafe := setup.MultiversxHandler.GetESDTChainSpecificTokenBalance(setup.Ctx, setup.MultiversxHandler.SafeAddress, token.AbstractTokenIdentifier) setup.mutBalances.Lock() setup.initMvxInitialBalancesForUniversalUnsafe(token, @@ -188,6 +182,7 @@ func (setup *TestSetup) IssueAndConfigureTokens(tokens ...TestTokenParams) { ) setup.mutBalances.Unlock() + esdtBalanceForSafe := setup.MultiversxHandler.GetESDTChainSpecificTokenBalance(setup.Ctx, setup.MultiversxHandler.SafeAddress, token.AbstractTokenIdentifier) log.Info("recorded the ESDT balance for safe contract", "token", token.AbstractTokenIdentifier, "balance", esdtBalanceForSafe.String()) } @@ -521,11 +516,17 @@ func (setup *TestSetup) createBatchOnMultiversXForToken(params TestTokenParams) token := setup.GetTokenData(params.AbstractTokenIdentifier) require.NotNil(setup, token) - // TODO: transfer only required amount for deposit to the test key + setup.transferTokensToMvxTestKey(params, setup.AliceKeys) + setup.ChainSimulator.GenerateBlocks(setup.Ctx, 10) + + setup.mutBalances.Lock() + setup.initMvxInitialBalancesForUniversalUnsafe(params, setup.AliceKeys.MvxAddress) + setup.mutBalances.Unlock() + _ = setup.createDepositOnMultiversxForToken(setup.AliceKeys, setup.BobKeys, params) } -func (setup *TestSetup) transferTokensToMvxTestKey(params TestTokenParams) { +func (setup *TestSetup) transferTokensToMvxTestKey(params TestTokenParams, holder KeysHolder) { depositValue := big.NewInt(0) for _, operation := range params.TestOperations { if operation.ValueToSendFromMvX == nil { @@ -538,7 +539,7 @@ func (setup *TestSetup) transferTokensToMvxTestKey(params TestTokenParams) { setup.MultiversxHandler.TransferToken( setup.Ctx, setup.OwnerKeys, - setup.AliceKeys, + holder, depositValue, params.IssueTokenParams, ) @@ -592,10 +593,33 @@ func (setup *TestSetup) createBatchOnEthereumForToken(mvxCalleeScAddress sdkCore token := setup.GetTokenData(params.AbstractTokenIdentifier) require.NotNil(setup, token) - // TODO: transfer only required amount for deposit to the test key + setup.transferTokensToEthTestKey(params, setup.AliceKeys) + + setup.mutBalances.Lock() + setup.initEthInitialBalancesUnsafe(params, setup.AliceKeys.EthAddress) + setup.mutBalances.Unlock() + setup.createDepositOnEthereumForToken(setup.AliceKeys, setup.BobKeys, mvxCalleeScAddress, params) } +func (setup *TestSetup) transferTokensToEthTestKey(params TestTokenParams, holder KeysHolder) { + depositValue := big.NewInt(0) + for _, operation := range params.TestOperations { + if operation.ValueToTransferToMvx == nil { + continue + } + + depositValue.Add(depositValue, operation.ValueToTransferToMvx) + } + + setup.EthereumHandler.TransferToken( + setup.Ctx, + params, + setup.DepositorKeys, + holder, + depositValue) +} + // SendFromEthereumToMultiversX will create the deposits that will be gathered in a batch on Ethereum func (setup *TestSetup) SendFromEthereumToMultiversX(from KeysHolder, to KeysHolder, mvxTestCallerAddress sdkCore.AddressHandler, tokensParams ...TestTokenParams) { for _, params := range tokensParams {