diff --git a/integrationTests/relayers/slowTests/common.go b/integrationTests/relayers/slowTests/common.go index 0746134d..71db6440 100644 --- a/integrationTests/relayers/slowTests/common.go +++ b/integrationTests/relayers/slowTests/common.go @@ -53,8 +53,21 @@ func GenerateTestUSDCToken() framework.TestTokenParams { MvxSCCallData: createScCallData("callPayable", 50000000), }, }, - ESDTSafeExtraBalance: big.NewInt(100), // extra is just for the fees for the 2 transfers mvx->eth - EthTestAddrExtraBalance: big.NewInt(-5000 + 2500 - 50 - 7000 + 300 - 50 - 1000), // -(eth->mvx) + (mvx->eth) - fees + ESDTSafeExtraBalance: big.NewInt(100), // extra is just for the fees for the 2 transfers mvx->eth + ExtraBalances: map[string]framework.ExtraBalanceHolder{ + framework.Alice: { + SentAmount: big.NewInt(-5000 - 7000 - 1000), + ReceivedAmount: big.NewInt(0), + }, + framework.Bob: { + SentAmount: big.NewInt(-2500 - 300), + ReceivedAmount: big.NewInt(5000 + 7000), + }, + framework.Charlie: { + SentAmount: big.NewInt(0), + ReceivedAmount: big.NewInt(2500 - 50 + 300 - 50), + }, + }, } } @@ -95,8 +108,21 @@ func GenerateTestMEMEToken() framework.TestTokenParams { MvxSCCallData: createScCallData("callPayable", 50000000), }, }, - ESDTSafeExtraBalance: big.NewInt(4000 + 6000 + 2000), // everything is locked in the safe esdt contract - EthTestAddrExtraBalance: big.NewInt(4000 - 50 + 6000 - 50 + 2000 - 50), + ESDTSafeExtraBalance: big.NewInt(4000 + 6000 + 2000), // everything is locked in the safe esdt contract + ExtraBalances: map[string]framework.ExtraBalanceHolder{ + framework.Alice: { + SentAmount: big.NewInt(-4000 - 6000 - 2000), + ReceivedAmount: big.NewInt(0), + }, + framework.Bob: { + SentAmount: big.NewInt(-2400 - 200 - 1000), + ReceivedAmount: big.NewInt(4000 - 50 + 6000 - 50 + 2000 - 50), + }, + framework.Charlie: { + SentAmount: big.NewInt(0), + ReceivedAmount: big.NewInt(2400 + 200), + }, + }, } } @@ -137,8 +163,21 @@ func GenerateTestEUROCToken() framework.TestTokenParams { MvxSCCallData: createScCallData("callPayable", 50000000), }, }, - ESDTSafeExtraBalance: big.NewInt(100), // extra is just for the fees for the 2 transfers mvx->eth - EthTestAddrExtraBalance: big.NewInt(-5010 + 2510 - 50 - 7010 + 310 - 50 - 1010), // -(eth->mvx) + (mvx->eth) - fees + ESDTSafeExtraBalance: big.NewInt(100), // extra is just for the fees for the 2 transfers mvx->eth + ExtraBalances: map[string]framework.ExtraBalanceHolder{ + framework.Alice: { + SentAmount: big.NewInt(-5010 - 7010 - 1010), + ReceivedAmount: big.NewInt(0), + }, + framework.Bob: { + SentAmount: big.NewInt(-2510 - 310), + ReceivedAmount: big.NewInt(5010 + 7010), + }, + framework.Charlie: { + SentAmount: big.NewInt(0), + ReceivedAmount: big.NewInt(2510 - 50 + 310 - 50), + }, + }, } } @@ -179,8 +218,21 @@ func GenerateTestMEXToken() framework.TestTokenParams { MvxSCCallData: createScCallData("callPayable", 50000000), }, }, - ESDTSafeExtraBalance: big.NewInt(150), // just the fees should be collected in ESDT safe - EthTestAddrExtraBalance: big.NewInt(4010 - 50 + 6010 - 50 + 2010 - 50), + ESDTSafeExtraBalance: big.NewInt(150), // just the fees should be collected in ESDT safe + ExtraBalances: map[string]framework.ExtraBalanceHolder{ + framework.Alice: { + SentAmount: big.NewInt(-4010 - 6010 - 2010), + ReceivedAmount: big.NewInt(0), + }, + framework.Bob: { + SentAmount: big.NewInt(-2410 - 210 - 1010), + ReceivedAmount: big.NewInt(4010 - 50 + 6010 - 50 + 2010 - 50), + }, + framework.Charlie: { + SentAmount: big.NewInt(0), + ReceivedAmount: big.NewInt(2410 + 210), + }, + }, } } diff --git a/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go b/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go index 6f4a00a1..75ef37da 100644 --- a/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go +++ b/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go @@ -159,7 +159,7 @@ func testRelayersWithChainSimulatorAndTokens(tb testing.TB, manualStopChan chan setup.IssueAndConfigureTokens(tokens...) setup.MultiversxHandler.CheckForZeroBalanceOnReceivers(setup.Ctx, tokens...) if len(startsFromEthFlow.tokens) > 0 { - setup.EthereumHandler.CreateBatchOnEthereum(setup.Ctx, setup.MultiversxHandler.TestCallerAddress, startsFromEthFlow.tokens...) + setup.EthereumHandler.CreateBatchOnEthereum(setup.Ctx, setup.MultiversxHandler.CalleeScAddress, startsFromEthFlow.tokens...) } if len(startsFromMvXFlow.tokens) > 0 { setup.CreateBatchOnMultiversX(startsFromMvXFlow.tokens...) @@ -287,8 +287,12 @@ func createBadToken() framework.TestTokenParams { MvxSCCallData: createScCallData("callPayable", 50000000), }, }, - ESDTSafeExtraBalance: big.NewInt(0), - EthTestAddrExtraBalance: big.NewInt(0), + ESDTSafeExtraBalance: big.NewInt(0), + ExtraBalances: map[string]framework.ExtraBalanceHolder{ + "Alice": {big.NewInt(-5000 - 7000 - 1000), big.NewInt(0)}, + "Bob": {big.NewInt(-2500 - 300), big.NewInt(5000 + 7000)}, + "Charlie": {big.NewInt(0), big.NewInt(2500 - 50 + 300 - 50)}, + }, } } @@ -351,7 +355,7 @@ func testRelayersShouldNotExecuteTransfers( setup.IssueAndConfigureTokens(tokens...) setup.MultiversxHandler.CheckForZeroBalanceOnReceivers(setup.Ctx, tokens...) if len(startsFromEthFlow.tokens) > 0 { - setup.EthereumHandler.CreateBatchOnEthereum(setup.Ctx, setup.MultiversxHandler.TestCallerAddress, startsFromEthFlow.tokens...) + setup.EthereumHandler.CreateBatchOnEthereum(setup.Ctx, setup.MultiversxHandler.CalleeScAddress, startsFromEthFlow.tokens...) } if len(startsFromMvXFlow.tokens) > 0 { setup.CreateBatchOnMultiversX(startsFromMvXFlow.tokens...) @@ -446,7 +450,7 @@ func testCallPayableWithParamsWasCalled(testSetup *framework.TestSetup, value ui } vmRequest := &data.VmValueRequest{ - Address: testSetup.MultiversxHandler.TestCallerAddress.Bech32(), + Address: testSetup.MultiversxHandler.CalleeScAddress.Bech32(), FuncName: "getCalledDataParams", } diff --git a/integrationTests/relayers/slowTests/framework/ethereumHandler.go b/integrationTests/relayers/slowTests/framework/ethereumHandler.go index 81d7b68a..5d3eb69c 100644 --- a/integrationTests/relayers/slowTests/framework/ethereumHandler.go +++ b/integrationTests/relayers/slowTests/framework/ethereumHandler.go @@ -3,7 +3,6 @@ package framework import ( "bytes" "context" - "crypto/ecdsa" "math/big" "os" "testing" @@ -50,7 +49,7 @@ type EthereumHandler struct { *KeysStore TokensRegistry TokensRegistry Quorum string - MvxTestCallerAddress core.AddressHandler + MvxCalleeScAddress core.AddressHandler SimulatedChain *simulated.Backend SimulatedChainWrapper EthereumBlockchainClient ChainID *big.Int @@ -340,7 +339,7 @@ func (handler *EthereumHandler) deployTestERC20Contract(ctx context.Context, par require.Equal(handler, mintAmount.String(), balance.String()) if params.IsNativeOnEth { - tx, err = ethMintBurnContract.Mint(auth, handler.TestKeys.EthAddress, mintAmount) + tx, err = ethMintBurnContract.Mint(auth, handler.AliceKeys.EthAddress, mintAmount) require.NoError(handler, err) handler.SimulatedChain.Commit() handler.checkEthTxResult(ctx, tx.Hash()) @@ -363,7 +362,7 @@ func (handler *EthereumHandler) deployTestERC20Contract(ctx context.Context, par require.NoError(handler, err) // mint the address that will create the transfers - handler.mintTokens(ctx, ethGenericTokenContract, params.ValueToMintOnEth, handler.TestKeys.EthAddress) + handler.mintTokens(ctx, ethGenericTokenContract, params.ValueToMintOnEth, handler.AliceKeys.EthAddress) if len(params.InitialSupplyValue) > 0 { handler.mintTokens(ctx, ethGenericTokenContract, params.InitialSupplyValue, handler.SafeAddress) } @@ -395,11 +394,11 @@ func (handler *EthereumHandler) mintTokens( // CreateBatchOnEthereum will create a batch on Ethereum using the provided tokens parameters list func (handler *EthereumHandler) CreateBatchOnEthereum( ctx context.Context, - mvxTestCallerAddress core.AddressHandler, + mvxCalleeScAddress core.AddressHandler, tokensParams ...TestTokenParams, ) { for _, params := range tokensParams { - handler.createDepositsOnEthereumForToken(ctx, params, handler.TestKeys.EthSK, mvxTestCallerAddress) + handler.createDepositsOnEthereumForToken(ctx, params, handler.AliceKeys, handler.BobKeys, mvxCalleeScAddress) } // wait until batch is settled @@ -409,14 +408,30 @@ func (handler *EthereumHandler) CreateBatchOnEthereum( } } +// SendFromEthereumToMultiversX will create the deposit transactions on the Ethereum side +func (handler *EthereumHandler) SendFromEthereumToMultiversX( + ctx context.Context, + from KeysHolder, + to KeysHolder, + mvxTestCallerAddress core.AddressHandler, + tokensParams ...TestTokenParams, +) { + for _, params := range tokensParams { + handler.createDepositsOnEthereumForToken(ctx, params, from, to, mvxTestCallerAddress) + } +} + func (handler *EthereumHandler) createDepositsOnEthereumForToken( ctx context.Context, params TestTokenParams, - from *ecdsa.PrivateKey, - mvxTestCallerAddress core.AddressHandler, + from KeysHolder, + to KeysHolder, + targetSCAddress core.AddressHandler, ) { + // TODO: transfer only required amount for deposit to the test key + // add allowance for the sender - auth, _ := bind.NewKeyedTransactorWithChainID(from, handler.ChainID) + auth, _ := bind.NewKeyedTransactorWithChainID(from.EthSK, handler.ChainID) token := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) require.NotNil(handler, token) @@ -450,11 +465,11 @@ func (handler *EthereumHandler) createDepositsOnEthereumForToken( auth, token.EthErc20Address, operation.ValueToTransferToMvx, - mvxTestCallerAddress.AddressSlice(), + targetSCAddress.AddressSlice(), operation.MvxSCCallData, ) } else { - tx, err = handler.SafeContract.Deposit(auth, token.EthErc20Address, operation.ValueToTransferToMvx, handler.TestKeys.MvxAddress.AddressSlice()) + tx, err = handler.SafeContract.Deposit(auth, token.EthErc20Address, operation.ValueToTransferToMvx, to.MvxAddress.AddressSlice()) } require.NoError(handler, err) @@ -463,17 +478,6 @@ func (handler *EthereumHandler) createDepositsOnEthereumForToken( } } -// SendFromEthereumToMultiversX will create the deposit transactions on the Ethereum side -func (handler *EthereumHandler) SendFromEthereumToMultiversX( - ctx context.Context, - mvxTestCallerAddress core.AddressHandler, - tokensParams ...TestTokenParams, -) { - for _, params := range tokensParams { - handler.createDepositsOnEthereumForToken(ctx, params, handler.TestKeys.EthSK, mvxTestCallerAddress) - } -} - // 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) diff --git a/integrationTests/relayers/slowTests/framework/keys.go b/integrationTests/relayers/slowTests/framework/keys.go index e05b1474..30c97919 100644 --- a/integrationTests/relayers/slowTests/framework/keys.go +++ b/integrationTests/relayers/slowTests/framework/keys.go @@ -42,14 +42,22 @@ type KeysStore struct { SCExecutorKeys KeysHolder OwnerKeys KeysHolder DepositorKeys KeysHolder - TestKeys KeysHolder + AliceKeys KeysHolder + BobKeys KeysHolder + CharlieKeys KeysHolder + AddressToName map[string]string workingDir string } const ( ethOwnerSK = "b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291" ethDepositorSK = "9bb971db41e3815a669a71c3f1bcb24e0b81f21e04bf11faa7a34b9b40e7cfb1" - ethTestSk = "dafea2c94bfe5d25f1a508808c2bc2c2e6c6f18b6b010fc841d8eb80755ba27a" + aliceSk = "3a944a35d9cb7be4dd4e91429d28cec594db960221724cc3a3c81594e0140acb" + bobSk = "c658971dab0b3f2586ef35444554a2ddf5169f750ca46c29d769930205078ded" + charlieSk = "43cba80c6e2ee37fc9cf13f1d445ebbb7fb74f54800884f1162603c6de8d4530" + Alice = "Alice" + Bob = "Bob" + Charlie = "Charlie" ) // NewKeysStore will create a KeysStore instance and generate all keys @@ -63,6 +71,7 @@ func NewKeysStore( TB: tb, RelayersKeys: make([]KeysHolder, 0, numRelayers), SCExecutorKeys: KeysHolder{}, + AddressToName: make(map[string]string), workingDir: workingDir, } @@ -74,7 +83,16 @@ func NewKeysStore( "MvX address", keysStore.OwnerKeys.MvxAddress.Bech32(), "Eth address", keysStore.OwnerKeys.EthAddress.String()) keysStore.DepositorKeys = keysStore.generateKey(ethDepositorSK, projectedShardForDepositor) - keysStore.TestKeys = keysStore.generateKey(ethTestSk, projectedShardForTestKeys) + keysStore.AliceKeys = keysStore.generateKey(aliceSk, projectedShardForTestKeys) + keysStore.BobKeys = keysStore.generateKey(bobSk, projectedShardForTestKeys) + keysStore.CharlieKeys = keysStore.generateKey(charlieSk, projectedShardForTestKeys) + + keysStore.AddressToName[keysStore.AliceKeys.MvxAddress.String()] = Alice + keysStore.AddressToName[keysStore.BobKeys.MvxAddress.String()] = Bob + keysStore.AddressToName[keysStore.CharlieKeys.MvxAddress.String()] = Charlie + keysStore.AddressToName[keysStore.AliceKeys.EthAddress.String()] = Alice + keysStore.AddressToName[keysStore.BobKeys.EthAddress.String()] = Bob + keysStore.AddressToName[keysStore.CharlieKeys.EthAddress.String()] = Charlie filename := path.Join(keysStore.workingDir, SCCallerFilename) SaveMvxKey(keysStore, filename, keysStore.SCExecutorKeys) @@ -139,7 +157,7 @@ func (keyStore *KeysStore) getAllKeys() []KeysHolder { allKeys := make([]KeysHolder, 0, len(keyStore.RelayersKeys)+10) allKeys = append(allKeys, keyStore.RelayersKeys...) allKeys = append(allKeys, keyStore.OraclesKeys...) - allKeys = append(allKeys, keyStore.SCExecutorKeys, keyStore.OwnerKeys, keyStore.DepositorKeys, keyStore.TestKeys) + allKeys = append(allKeys, keyStore.SCExecutorKeys, keyStore.OwnerKeys, keyStore.DepositorKeys, keyStore.AliceKeys, keyStore.BobKeys, keyStore.CharlieKeys) return allKeys } diff --git a/integrationTests/relayers/slowTests/framework/multiversxHandler.go b/integrationTests/relayers/slowTests/framework/multiversxHandler.go index 225abfe5..678fe55e 100644 --- a/integrationTests/relayers/slowTests/framework/multiversxHandler.go +++ b/integrationTests/relayers/slowTests/framework/multiversxHandler.go @@ -95,7 +95,7 @@ type MultiversxHandler struct { MultisigAddress *MvxAddress MultiTransferAddress *MvxAddress ScProxyAddress *MvxAddress - TestCallerAddress *MvxAddress + CalleeScAddress *MvxAddress ESDTSystemContractAddress *MvxAddress } @@ -239,15 +239,15 @@ func (handler *MultiversxHandler) deployContracts(ctx context.Context) { log.Info("Deploy: multisig contract", "address", handler.MultisigAddress, "transaction hash", hash) // deploy test-caller - handler.TestCallerAddress, hash, _ = handler.ChainSimulator.DeploySC( + handler.CalleeScAddress, hash, _ = handler.ChainSimulator.DeploySC( ctx, testCallerContractPath, handler.OwnerKeys.MvxSk, deployGasLimit, []string{}, ) - require.NotEqual(handler, emptyAddress, handler.TestCallerAddress) - log.Info("Deploy: test-caller contract", "address", handler.TestCallerAddress, "transaction hash", hash) + require.NotEqual(handler, emptyAddress, handler.CalleeScAddress) + log.Info("Deploy: test-caller contract", "address", handler.CalleeScAddress, "transaction hash", hash) } func (handler *MultiversxHandler) wireMultiTransfer(ctx context.Context) { @@ -453,10 +453,10 @@ func (handler *MultiversxHandler) CheckForZeroBalanceOnReceivers(ctx context.Con // CheckForZeroBalanceOnReceiversForToken will check that the balance for the test address and the test SC call address is 0 func (handler *MultiversxHandler) CheckForZeroBalanceOnReceiversForToken(ctx context.Context, token TestTokenParams) { - balance := handler.GetESDTUniversalTokenBalance(ctx, handler.TestKeys.MvxAddress, token.AbstractTokenIdentifier) + balance := handler.GetESDTUniversalTokenBalance(ctx, handler.BobKeys.MvxAddress, token.AbstractTokenIdentifier) require.Equal(handler, big.NewInt(0).String(), balance.String()) - balance = handler.GetESDTUniversalTokenBalance(ctx, handler.TestCallerAddress, token.AbstractTokenIdentifier) + balance = handler.GetESDTUniversalTokenBalance(ctx, handler.CalleeScAddress, token.AbstractTokenIdentifier) require.Equal(handler, big.NewInt(0).String(), balance.String()) } @@ -942,20 +942,20 @@ func (handler *MultiversxHandler) submitAggregatorBatchForKey(ctx context.Contex } // SendDepositTransactionFromMultiversx will send the deposit transaction from MultiversX -func (handler *MultiversxHandler) SendDepositTransactionFromMultiversx(ctx context.Context, token *TokenData, value *big.Int) { +func (handler *MultiversxHandler) SendDepositTransactionFromMultiversx(ctx context.Context, from KeysHolder, to KeysHolder, token *TokenData, value *big.Int) { // create transaction params params := []string{ hex.EncodeToString([]byte(token.MvxUniversalToken)), hex.EncodeToString(value.Bytes()), hex.EncodeToString([]byte(unwrapTokenCreateTransactionFunction)), hex.EncodeToString([]byte(token.MvxChainSpecificToken)), - hex.EncodeToString(handler.TestKeys.EthAddress.Bytes()), + hex.EncodeToString(to.EthAddress.Bytes()), } dataField := strings.Join(params, "@") hash, txResult := handler.ChainSimulator.ScCall( ctx, - handler.TestKeys.MvxSk, + from.MvxSk, handler.WrapperAddress, zeroStringValue, createDepositGasLimit+gasLimitPerDataByte*uint64(len(dataField)), @@ -1020,10 +1020,10 @@ func (handler *MultiversxHandler) withdrawFees(ctx context.Context, } // TransferToken is able to create an ESDT transfer -func (handler *MultiversxHandler) TransferToken(ctx context.Context, source KeysHolder, receiver KeysHolder, amount *big.Int, params TestTokenParams) { +func (handler *MultiversxHandler) TransferToken(ctx context.Context, source KeysHolder, receiver KeysHolder, amount *big.Int, params IssueTokenParams) { tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) - // transfer to the test key, so it will have funds to carry on with the deposits + // transfer to receiver, so it will have funds to carry on with the deposits hash, txResult := handler.ChainSimulator.ScCall( ctx, source.MvxSk, diff --git a/integrationTests/relayers/slowTests/framework/testSetup.go b/integrationTests/relayers/slowTests/framework/testSetup.go index 83ec55b0..5d07a875 100644 --- a/integrationTests/relayers/slowTests/framework/testSetup.go +++ b/integrationTests/relayers/slowTests/framework/testSetup.go @@ -6,6 +6,7 @@ import ( "math/big" "os" "path" + "strings" "sync" "sync/atomic" "testing" @@ -24,6 +25,7 @@ const ( NumRelayers = 3 NumOracles = 3 quorum = "03" + mvxHrp = "erd" ) // TestSetup is the struct that holds all subcomponents for the testing infrastructure @@ -39,12 +41,14 @@ type TestSetup struct { ScCallerKeys KeysHolder ScCallerModuleInstance SCCallerModule - ctxCancel func() - Ctx context.Context - mutBalances sync.RWMutex - esdtBalanceForSafe map[string]*big.Int - ethBalanceTestAddress map[string]*big.Int - numScCallsInTest uint32 + ctxCancel func() + Ctx context.Context + mutBalances sync.RWMutex + esdtBalanceForSafe map[string]*big.Int + mvxBalances map[string]map[string]*big.Int + ethBalances map[string]map[string]*big.Int + + numScCallsInTest uint32 } // NewTestSetup creates a new e2e test setup @@ -52,14 +56,23 @@ func NewTestSetup(tb testing.TB) *TestSetup { log.Info(fmt.Sprintf(LogStepMarker, "starting setup")) setup := &TestSetup{ - TB: tb, - TokensRegistry: NewTokenRegistry(tb), - WorkingDir: tb.TempDir(), - esdtBalanceForSafe: make(map[string]*big.Int), - ethBalanceTestAddress: make(map[string]*big.Int), + TB: tb, + TokensRegistry: NewTokenRegistry(tb), + WorkingDir: tb.TempDir(), + esdtBalanceForSafe: make(map[string]*big.Int), + mvxBalances: make(map[string]map[string]*big.Int), + ethBalances: make(map[string]map[string]*big.Int), } setup.KeysStore = NewKeysStore(tb, setup.WorkingDir, NumRelayers, NumOracles) + setup.mvxBalances[setup.AliceKeys.MvxAddress.String()] = make(map[string]*big.Int) + setup.mvxBalances[setup.BobKeys.MvxAddress.String()] = make(map[string]*big.Int) + setup.mvxBalances[setup.CharlieKeys.MvxAddress.String()] = make(map[string]*big.Int) + + setup.ethBalances[setup.AliceKeys.EthAddress.String()] = make(map[string]*big.Int) + setup.ethBalances[setup.BobKeys.EthAddress.String()] = make(map[string]*big.Int) + setup.ethBalances[setup.CharlieKeys.EthAddress.String()] = make(map[string]*big.Int) + // create a test context setup.Ctx, setup.ctxCancel = context.WithCancel(context.Background()) @@ -157,17 +170,26 @@ func (setup *TestSetup) IssueAndConfigureTokens(tokens ...TestTokenParams) { setup.AddToken(token.IssueTokenParams) setup.EthereumHandler.IssueAndWhitelistToken(setup.Ctx, token.IssueTokenParams) setup.MultiversxHandler.IssueAndWhitelistToken(setup.Ctx, token.IssueTokenParams) + setup.transferTokensToTestKey(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) - ethBalanceForTestAddr := setup.EthereumHandler.GetBalance(setup.TestKeys.EthAddress, token.AbstractTokenIdentifier) setup.mutBalances.Lock() setup.esdtBalanceForSafe[token.AbstractTokenIdentifier] = esdtBalanceForSafe - setup.ethBalanceTestAddress[token.AbstractTokenIdentifier] = ethBalanceForTestAddr + + setup.mvxBalances[setup.AliceKeys.MvxAddress.String()][token.AbstractTokenIdentifier] = setup.getTokenBalanceForAddress(true, setup.AliceKeys, token.AbstractTokenIdentifier) + setup.mvxBalances[setup.BobKeys.MvxAddress.String()][token.AbstractTokenIdentifier] = setup.getTokenBalanceForAddress(true, setup.BobKeys, token.AbstractTokenIdentifier) + setup.mvxBalances[setup.CharlieKeys.MvxAddress.String()][token.AbstractTokenIdentifier] = setup.getTokenBalanceForAddress(true, setup.CharlieKeys, token.AbstractTokenIdentifier) + + setup.ethBalances[setup.AliceKeys.EthAddress.String()][token.AbstractTokenIdentifier] = setup.getTokenBalanceForAddress(false, setup.AliceKeys, token.AbstractTokenIdentifier) + setup.ethBalances[setup.BobKeys.EthAddress.String()][token.AbstractTokenIdentifier] = setup.getTokenBalanceForAddress(false, setup.BobKeys, token.AbstractTokenIdentifier) + setup.ethBalances[setup.CharlieKeys.EthAddress.String()][token.AbstractTokenIdentifier] = setup.getTokenBalanceForAddress(false, setup.CharlieKeys, token.AbstractTokenIdentifier) + setup.mutBalances.Unlock() log.Info("recorded the ESDT balance for safe contract", "token", token.AbstractTokenIdentifier, "balance", esdtBalanceForSafe.String()) - log.Info("recorded the ETH balance for test address", "token", token.AbstractTokenIdentifier, "balance", ethBalanceForTestAddr.String()) } setup.EthereumHandler.UnPauseContractsAfterTokenChanges(setup.Ctx) @@ -178,6 +200,14 @@ func (setup *TestSetup) IssueAndConfigureTokens(tokens ...TestTokenParams) { } } +func (setup *TestSetup) getTokenBalanceForAddress(isOnMvx bool, holder KeysHolder, token string) *big.Int { + if isOnMvx { + return setup.MultiversxHandler.GetESDTUniversalTokenBalance(setup.Ctx, holder.MvxAddress, token) + } + + return setup.EthereumHandler.GetBalance(holder.EthAddress, token) +} + func (setup *TestSetup) processNumScCallsOperations(token TestTokenParams) { for _, op := range token.TestOperations { if len(op.MvxSCCallData) > 0 || op.MvxForceSCCall { @@ -192,17 +222,76 @@ func (setup *TestSetup) GetNumScCallsOperations() uint32 { } // IsTransferDoneFromEthereum returns true if all provided tokens are bridged from Ethereum towards MultiversX -func (setup *TestSetup) IsTransferDoneFromEthereum(tokens ...TestTokenParams) bool { +func (setup *TestSetup) IsTransferDoneFromEthereum(sender KeysHolder, receiver KeysHolder, tokens ...TestTokenParams) bool { isDone := true for _, params := range tokens { - isDone = isDone && setup.isTransferDoneFromEthereumForToken(params) + isDone = isDone && setup.isTransferDoneFromEthereumForToken(sender, receiver, params) } return isDone } -func (setup *TestSetup) isTransferDoneFromEthereumForToken(params TestTokenParams) bool { - expectedValueOnReceiver := big.NewInt(0) +func (setup *TestSetup) isTransferDoneFromEthereumForToken(sender KeysHolder, receiver KeysHolder, params TestTokenParams) bool { + okSender := setup.checkHolderEthBalanceForToken(sender, true, params) + okReceiver := setup.checkHolderMvxBalanceForToken(receiver, false, params) + okContract := setup.checkContractMvxBalanceForToken(params) + + return okSender && okReceiver && okContract +} + +func (setup *TestSetup) checkHolderMvxBalanceForToken(holder KeysHolder, isSender bool, params TestTokenParams) bool { + balanceMapping, exists := setup.getBalanceMappingForAddress(holder.MvxAddress.String()) + if !exists { + return false + } + + actualBalance := setup.MultiversxHandler.GetESDTUniversalTokenBalance(setup.Ctx, holder.MvxAddress, params.AbstractTokenIdentifier) + + return setup.checkHolderBalanceForTokenHelper(balanceMapping, params, actualBalance, holder.MvxAddress.String(), isSender) +} + +func (setup *TestSetup) checkHolderEthBalanceForToken(holder KeysHolder, isSender bool, params TestTokenParams) bool { + balanceMapping, exists := setup.getBalanceMappingForAddress(holder.EthAddress.String()) + if !exists { + return false + } + + actualBalance := setup.EthereumHandler.GetBalance(holder.EthAddress, params.AbstractTokenIdentifier) + + return setup.checkHolderBalanceForTokenHelper(balanceMapping, params, actualBalance, holder.EthAddress.String(), isSender) +} + +func (setup *TestSetup) getBalanceMappingForAddress(addr string) (map[string]*big.Int, bool) { + setup.mutBalances.Lock() + defer setup.mutBalances.Unlock() + + if strings.HasPrefix(addr, mvxHrp) { + balanceMapping, exists := setup.mvxBalances[addr] + return balanceMapping, exists + } + + balanceMapping, exists := setup.ethBalances[addr] + return balanceMapping, exists +} + +func (setup *TestSetup) checkHolderBalanceForTokenHelper(balanceMapping map[string]*big.Int, params TestTokenParams, actualBalance *big.Int, addr string, isSender bool) bool { + setup.mutBalances.Lock() + holderName := setup.AddressToName[addr] + extraBalances := params.ExtraBalances[holderName] + setup.mutBalances.Unlock() + + expectedBalance := big.NewInt(0).Set(balanceMapping[params.AbstractTokenIdentifier]) + + expectedBalance.Add(expectedBalance, extraBalances.ReceivedAmount) + if isSender { + expectedBalance.Add(expectedBalance, extraBalances.SentAmount) + } + + return actualBalance.String() == expectedBalance.String() +} + +func (setup *TestSetup) checkContractMvxBalanceForToken(params TestTokenParams) bool { + mvxBalance := setup.MultiversxHandler.GetESDTUniversalTokenBalance(setup.Ctx, setup.MultiversxHandler.CalleeScAddress, params.AbstractTokenIdentifier) expectedValueOnContract := big.NewInt(0) for _, operation := range params.TestOperations { if operation.ValueToTransferToMvx == nil { @@ -213,18 +302,10 @@ func (setup *TestSetup) isTransferDoneFromEthereumForToken(params TestTokenParam if !operation.MvxFaultySCCall { expectedValueOnContract.Add(expectedValueOnContract, operation.ValueToTransferToMvx) } - } else { - expectedValueOnReceiver.Add(expectedValueOnReceiver, operation.ValueToTransferToMvx) } } - receiverBalance := setup.MultiversxHandler.GetESDTUniversalTokenBalance(setup.Ctx, setup.TestKeys.MvxAddress, params.AbstractTokenIdentifier) - if receiverBalance.String() != expectedValueOnReceiver.String() { - return false - } - - contractBalance := setup.MultiversxHandler.GetESDTUniversalTokenBalance(setup.Ctx, setup.MultiversxHandler.TestCallerAddress, params.AbstractTokenIdentifier) - return contractBalance.String() == expectedValueOnContract.String() + return mvxBalance.String() == expectedValueOnContract.String() } // IsTransferDoneFromEthereumWithRefund returns true if all provided tokens are bridged from Ethereum towards MultiversX including refunds @@ -262,35 +343,33 @@ func (setup *TestSetup) isTransferDoneFromEthereumWithRefundForToken(params Test } } - receiverBalance := setup.EthereumHandler.GetBalance(setup.TestKeys.EthAddress, params.AbstractTokenIdentifier) + receiverBalance := setup.EthereumHandler.GetBalance(setup.BobKeys.EthAddress, params.AbstractTokenIdentifier) return receiverBalance.String() == expectedValueOnReceiver.String() } // IsTransferDoneFromMultiversX returns true if all provided tokens are bridged from MultiversX towards Ethereum -func (setup *TestSetup) IsTransferDoneFromMultiversX(tokens ...TestTokenParams) bool { +func (setup *TestSetup) IsTransferDoneFromMultiversX(sender KeysHolder, receiver KeysHolder, tokens ...TestTokenParams) bool { isDone := true for _, params := range tokens { - isDone = isDone && setup.isTransferDoneFromMultiversXForToken(params) + isDone = isDone && setup.isTransferDoneFromMultiversXForToken(sender, receiver, params) } return isDone } -func (setup *TestSetup) isTransferDoneFromMultiversXForToken(params TestTokenParams) bool { +func (setup *TestSetup) isTransferDoneFromMultiversXForToken(sender KeysHolder, receiver KeysHolder, params TestTokenParams) bool { setup.mutBalances.Lock() initialBalanceForSafe := setup.esdtBalanceForSafe[params.AbstractTokenIdentifier] - expectedReceiver := big.NewInt(0).Set(setup.ethBalanceTestAddress[params.AbstractTokenIdentifier]) - expectedReceiver.Add(expectedReceiver, params.EthTestAddrExtraBalance) setup.mutBalances.Unlock() - ethTestBalance := setup.EthereumHandler.GetBalance(setup.TestKeys.EthAddress, params.AbstractTokenIdentifier) - isTransferDoneFromMultiversX := ethTestBalance.String() == expectedReceiver.String() + okSender := setup.checkHolderMvxBalanceForToken(sender, true, params) + okReceiver := setup.checkHolderEthBalanceForToken(receiver, false, params) expectedEsdtSafe := big.NewInt(0).Add(initialBalanceForSafe, params.ESDTSafeExtraBalance) balanceForSafe := setup.MultiversxHandler.GetESDTChainSpecificTokenBalance(setup.Ctx, setup.MultiversxHandler.SafeAddress, params.AbstractTokenIdentifier) isSafeContractOnCorrectBalance := expectedEsdtSafe.String() == balanceForSafe.String() - return isTransferDoneFromMultiversX && isSafeContractOnCorrectBalance + return okSender && okReceiver && isSafeContractOnCorrectBalance } // CreateBatchOnMultiversX will create deposits that will be gathered in a batch on MultiversX @@ -304,8 +383,8 @@ func (setup *TestSetup) createBatchOnMultiversXForToken(params TestTokenParams) token := setup.GetTokenData(params.AbstractTokenIdentifier) require.NotNil(setup, token) - setup.transferTokensToTestKey(params) - valueToMintOnEthereum := setup.sendFromMultiversxToEthereumForToken(params) + // TODO: transfer only required amount for deposit to the test key + valueToMintOnEthereum := setup.createdDepositOnMultiversxForToken(setup.AliceKeys, setup.BobKeys, params) setup.EthereumHandler.Mint(setup.Ctx, params, valueToMintOnEthereum) } @@ -322,20 +401,20 @@ func (setup *TestSetup) transferTokensToTestKey(params TestTokenParams) { setup.MultiversxHandler.TransferToken( setup.Ctx, setup.OwnerKeys, - setup.TestKeys, + setup.AliceKeys, depositValue, - params, + params.IssueTokenParams, ) } // SendFromMultiversxToEthereum will create the deposits that will be gathered in a batch on MultiversX (without mint on Ethereum) -func (setup *TestSetup) SendFromMultiversxToEthereum(tokensParams ...TestTokenParams) { +func (setup *TestSetup) SendFromMultiversxToEthereum(from KeysHolder, to KeysHolder, tokensParams ...TestTokenParams) { for _, params := range tokensParams { - _ = setup.sendFromMultiversxToEthereumForToken(params) + _ = setup.createdDepositOnMultiversxForToken(from, to, params) } } -func (setup *TestSetup) sendFromMultiversxToEthereumForToken(params TestTokenParams) *big.Int { +func (setup *TestSetup) createdDepositOnMultiversxForToken(from KeysHolder, to KeysHolder, params TestTokenParams) *big.Int { token := setup.GetTokenData(params.AbstractTokenIdentifier) require.NotNil(setup, token) @@ -346,7 +425,7 @@ func (setup *TestSetup) sendFromMultiversxToEthereumForToken(params TestTokenPar } depositValue.Add(depositValue, operation.ValueToSendFromMvX) - setup.MultiversxHandler.SendDepositTransactionFromMultiversx(setup.Ctx, token, operation.ValueToSendFromMvX) + setup.MultiversxHandler.SendDepositTransactionFromMultiversx(setup.Ctx, from, to, token, operation.ValueToSendFromMvX) } return depositValue diff --git a/integrationTests/relayers/slowTests/framework/types.go b/integrationTests/relayers/slowTests/framework/types.go index dc165fe4..85a2900f 100644 --- a/integrationTests/relayers/slowTests/framework/types.go +++ b/integrationTests/relayers/slowTests/framework/types.go @@ -48,9 +48,9 @@ type TokenOperations struct { // TestTokenParams defines a token collection of operations in one or 2 batches type TestTokenParams struct { IssueTokenParams - TestOperations []TokenOperations - ESDTSafeExtraBalance *big.Int - EthTestAddrExtraBalance *big.Int + TestOperations []TokenOperations + ESDTSafeExtraBalance *big.Int + ExtraBalances map[string]ExtraBalanceHolder } // TokenData represents a test token data @@ -67,3 +67,9 @@ type TokenData struct { EthErc20Address common.Address EthErc20Contract ERC20Contract } + +// ExtraBalanceHolder holds the extra balances for a specific address +type ExtraBalanceHolder struct { + SentAmount *big.Int + ReceivedAmount *big.Int +} diff --git a/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go b/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go index 0a5d8b27..9c749875 100644 --- a/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go +++ b/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go @@ -21,8 +21,7 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { usdcToken := GenerateTestUSDCToken() usdcToken.TestOperations[2].MvxSCCallData = callData usdcToken.TestOperations[2].MvxFaultySCCall = true - usdcToken.EthTestAddrExtraBalance = big.NewInt(-5000 + 2500 - 50 - 7000 + 300 - 50 - 1000 + 950) // -(eth->mvx) + (mvx->eth) - fees + revert after bad SC call - usdcToken.ESDTSafeExtraBalance = big.NewInt(150) // extra is just for the fees for the 2 transfers mvx->eth and the failed eth->mvx that needed refund + usdcToken.ESDTSafeExtraBalance = big.NewInt(150) // extra is just for the fees for the 2 transfers mvx->eth and the failed eth->mvx that needed refund memeToken := GenerateTestMEMEToken() memeToken.TestOperations[2].MvxSCCallData = callData @@ -52,8 +51,7 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { usdcToken := GenerateTestUSDCToken() usdcToken.TestOperations[2].MvxSCCallData = callData usdcToken.TestOperations[2].MvxFaultySCCall = true - usdcToken.EthTestAddrExtraBalance = big.NewInt(-5000 + 2500 - 50 - 7000 + 300 - 50 - 1000 + 950) // -(eth->mvx) + (mvx->eth) - fees + revert after bad SC call - usdcToken.ESDTSafeExtraBalance = big.NewInt(150) // extra is just for the fees for the 2 transfers mvx->eth and the failed eth->mvx that needed refund + usdcToken.ESDTSafeExtraBalance = big.NewInt(150) // extra is just for the fees for the 2 transfers mvx->eth and the failed eth->mvx that needed refund memeToken := GenerateTestMEMEToken() memeToken.TestOperations[2].MvxSCCallData = callData @@ -71,8 +69,7 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { usdcToken := GenerateTestUSDCToken() usdcToken.TestOperations[2].MvxSCCallData = callData usdcToken.TestOperations[2].MvxFaultySCCall = true - usdcToken.EthTestAddrExtraBalance = big.NewInt(-5000 + 2500 - 50 - 7000 + 300 - 50 - 1000 + 950) // -(eth->mvx) + (mvx->eth) - fees + revert after bad SC call - usdcToken.ESDTSafeExtraBalance = big.NewInt(150) // extra is just for the fees for the 2 transfers mvx->eth and the failed eth->mvx that needed refund + usdcToken.ESDTSafeExtraBalance = big.NewInt(150) // extra is just for the fees for the 2 transfers mvx->eth and the failed eth->mvx that needed refund memeToken := GenerateTestMEMEToken() memeToken.TestOperations[2].MvxSCCallData = callData @@ -90,13 +87,12 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { usdcToken.TestOperations[2].MvxSCCallData = nil usdcToken.TestOperations[2].MvxFaultySCCall = true usdcToken.TestOperations[2].MvxForceSCCall = true - usdcToken.EthTestAddrExtraBalance = big.NewInt(-5000 + 2500 - 50 - 7000 + 300 - 50 - 1000 + 950) // -(eth->mvx) + (mvx->eth) - fees + revert after bad SC call - usdcToken.ESDTSafeExtraBalance = big.NewInt(150) // extra is just for the fees for the 2 transfers mvx->eth and the failed eth->mvx that needed refund + usdcToken.ESDTSafeExtraBalance = big.NewInt(150) // extra is just for the fees for the 2 transfers mvx->eth and the failed eth->mvx that needed refund memeToken := GenerateTestMEMEToken() memeToken.TestOperations[2].MvxSCCallData = nil memeToken.TestOperations[2].MvxFaultySCCall = true - usdcToken.TestOperations[2].MvxForceSCCall = true + memeToken.TestOperations[2].MvxForceSCCall = true testRelayersWithChainSimulatorAndTokensAndRefund( t, @@ -110,8 +106,7 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { usdcToken := GenerateTestUSDCToken() usdcToken.TestOperations[2].MvxSCCallData = callData usdcToken.TestOperations[2].MvxFaultySCCall = true - usdcToken.EthTestAddrExtraBalance = big.NewInt(-5000 + 2500 - 50 - 7000 + 300 - 50 - 1000 + 950) // -(eth->mvx) + (mvx->eth) - fees + revert after bad SC call - usdcToken.ESDTSafeExtraBalance = big.NewInt(150) // extra is just for the fees for the 2 transfers mvx->eth and the failed eth->mvx that needed refund + usdcToken.ESDTSafeExtraBalance = big.NewInt(150) // extra is just for the fees for the 2 transfers mvx->eth and the failed eth->mvx that needed refund memeToken := GenerateTestMEMEToken() memeToken.TestOperations[2].MvxSCCallData = callData @@ -129,8 +124,7 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { usdcToken := GenerateTestUSDCToken() usdcToken.TestOperations[2].MvxSCCallData = callData usdcToken.TestOperations[2].MvxFaultySCCall = true - usdcToken.EthTestAddrExtraBalance = big.NewInt(-5000 + 2500 - 50 - 7000 + 300 - 50 - 1000 + 950) // -(eth->mvx) + (mvx->eth) - fees + revert after bad SC call - usdcToken.ESDTSafeExtraBalance = big.NewInt(150) // extra is just for the fees for the 2 transfers mvx->eth and the failed eth->mvx that needed refund + usdcToken.ESDTSafeExtraBalance = big.NewInt(150) // extra is just for the fees for the 2 transfers mvx->eth and the failed eth->mvx that needed refund memeToken := GenerateTestMEMEToken() memeToken.TestOperations[2].MvxSCCallData = callData @@ -148,8 +142,7 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { usdcToken := GenerateTestUSDCToken() usdcToken.TestOperations[2].MvxSCCallData = callData usdcToken.TestOperations[2].MvxFaultySCCall = true - usdcToken.EthTestAddrExtraBalance = big.NewInt(-5000 + 2500 - 50 - 7000 + 300 - 50 - 1000 + 950) // -(eth->mvx) + (mvx->eth) - fees + revert after bad SC call - usdcToken.ESDTSafeExtraBalance = big.NewInt(150) // extra is just for the fees for the 2 transfers mvx->eth and the failed eth->mvx that needed refund + usdcToken.ESDTSafeExtraBalance = big.NewInt(150) // extra is just for the fees for the 2 transfers mvx->eth and the failed eth->mvx that needed refund memeToken := GenerateTestMEMEToken() memeToken.TestOperations[2].MvxSCCallData = callData @@ -167,8 +160,7 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { usdcToken := GenerateTestUSDCToken() usdcToken.TestOperations[2].MvxSCCallData = callData usdcToken.TestOperations[2].MvxFaultySCCall = true - usdcToken.EthTestAddrExtraBalance = big.NewInt(-5000 + 2500 - 50 - 7000 + 300 - 50 - 1000 + 950) // -(eth->mvx) + (mvx->eth) - fees + revert after bad SC call - usdcToken.ESDTSafeExtraBalance = big.NewInt(150) // extra is just for the fees for the 2 transfers mvx->eth and the failed eth->mvx that needed refund + usdcToken.ESDTSafeExtraBalance = big.NewInt(150) // extra is just for the fees for the 2 transfers mvx->eth and the failed eth->mvx that needed refund memeToken := GenerateTestMEMEToken() memeToken.TestOperations[2].MvxSCCallData = callData @@ -186,8 +178,7 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { usdcToken := GenerateTestUSDCToken() usdcToken.TestOperations[2].MvxSCCallData = callData usdcToken.TestOperations[2].MvxFaultySCCall = true - usdcToken.EthTestAddrExtraBalance = big.NewInt(-5000 + 2500 - 50 - 7000 + 300 - 50 - 1000 + 950) // -(eth->mvx) + (mvx->eth) - fees + revert after bad SC call - usdcToken.ESDTSafeExtraBalance = big.NewInt(150) // extra is just for the fees for the 2 transfers mvx->eth and the failed eth->mvx that needed refund + usdcToken.ESDTSafeExtraBalance = big.NewInt(150) // extra is just for the fees for the 2 transfers mvx->eth and the failed eth->mvx that needed refund memeToken := GenerateTestMEMEToken() memeToken.TestOperations[2].MvxSCCallData = callData @@ -208,8 +199,7 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { usdcToken := GenerateTestUSDCToken() usdcToken.TestOperations[2].MvxSCCallData = callData usdcToken.TestOperations[2].MvxFaultySCCall = true - usdcToken.EthTestAddrExtraBalance = big.NewInt(-5000 + 2500 - 50 - 7000 + 300 - 50 - 1000 + 950) // -(eth->mvx) + (mvx->eth) - fees + revert after bad SC call - usdcToken.ESDTSafeExtraBalance = big.NewInt(150) // extra is just for the fees for the 2 transfers mvx->eth and the failed eth->mvx that needed refund + usdcToken.ESDTSafeExtraBalance = big.NewInt(150) // extra is just for the fees for the 2 transfers mvx->eth and the failed eth->mvx that needed refund memeToken := GenerateTestMEMEToken() memeToken.TestOperations[2].MvxSCCallData = callData @@ -232,8 +222,7 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { usdcToken := GenerateTestUSDCToken() usdcToken.TestOperations[2].MvxSCCallData = callData usdcToken.TestOperations[2].MvxFaultySCCall = true - usdcToken.EthTestAddrExtraBalance = big.NewInt(-5000 + 2500 - 50 - 7000 + 300 - 50 - 1000 + 950) // -(eth->mvx) + (mvx->eth) - fees + revert after bad SC call - usdcToken.ESDTSafeExtraBalance = big.NewInt(150) // extra is just for the fees for the 2 transfers mvx->eth and the failed eth->mvx that needed refund + usdcToken.ESDTSafeExtraBalance = big.NewInt(150) // extra is just for the fees for the 2 transfers mvx->eth and the failed eth->mvx that needed refund memeToken := GenerateTestMEMEToken() memeToken.TestOperations[2].MvxSCCallData = callData @@ -258,7 +247,7 @@ func testRelayersWithChainSimulatorAndTokensAndRefund(tb testing.TB, manualStopC setup.IssueAndConfigureTokens(tokens...) setup.MultiversxHandler.CheckForZeroBalanceOnReceivers(setup.Ctx, tokens...) if len(startsFromEthFlow.tokens) > 0 { - setup.EthereumHandler.CreateBatchOnEthereum(setup.Ctx, setup.MultiversxHandler.TestCallerAddress, startsFromEthFlow.tokens...) + setup.EthereumHandler.CreateBatchOnEthereum(setup.Ctx, setup.MultiversxHandler.CalleeScAddress, startsFromEthFlow.tokens...) } if len(startsFromMvXFlow.tokens) > 0 { setup.CreateBatchOnMultiversX(startsFromMvXFlow.tokens...) diff --git a/integrationTests/relayers/slowTests/startsFromEthereumFlow.go b/integrationTests/relayers/slowTests/startsFromEthereumFlow.go index 76c13fe1..87a1f704 100644 --- a/integrationTests/relayers/slowTests/startsFromEthereumFlow.go +++ b/integrationTests/relayers/slowTests/startsFromEthereumFlow.go @@ -25,19 +25,20 @@ func (flow *startsFromEthereumFlow) process() (finished bool) { return true } - isTransferDoneFromEthereum := flow.setup.IsTransferDoneFromEthereum(flow.tokens...) + isTransferDoneFromEthereum := flow.setup.IsTransferDoneFromEthereum(flow.setup.AliceKeys, flow.setup.BobKeys, flow.tokens...) + fmt.Println(isTransferDoneFromEthereum) if !flow.ethToMvxDone && isTransferDoneFromEthereum { flow.ethToMvxDone = true log.Info(fmt.Sprintf(framework.LogStepMarker, "Ethereum->MultiversX transfer finished, now sending back to Ethereum...")) - flow.setup.SendFromMultiversxToEthereum(flow.tokens...) + flow.setup.SendFromMultiversxToEthereum(flow.setup.BobKeys, flow.setup.CharlieKeys, flow.tokens...) } if !flow.ethToMvxDone { // return here, no reason to check downwards return false } - isTransferDoneFromMultiversX := flow.setup.IsTransferDoneFromMultiversX(flow.tokens...) + isTransferDoneFromMultiversX := flow.setup.IsTransferDoneFromMultiversX(flow.setup.BobKeys, flow.setup.CharlieKeys, flow.tokens...) if !flow.mvxToEthDone && isTransferDoneFromMultiversX { flow.mvxToEthDone = true log.Info(fmt.Sprintf(framework.LogStepMarker, "MultiversX<->Ethereum from Ethereum transfers done")) diff --git a/integrationTests/relayers/slowTests/startsFromMultiversxFlow.go b/integrationTests/relayers/slowTests/startsFromMultiversxFlow.go index caa4dd06..7f15a95b 100644 --- a/integrationTests/relayers/slowTests/startsFromMultiversxFlow.go +++ b/integrationTests/relayers/slowTests/startsFromMultiversxFlow.go @@ -24,20 +24,20 @@ func (flow *startsFromMultiversXFlow) process() (finished bool) { if flow.mvxToEthDone && flow.ethToMvxDone { return true } + isTransferDoneFromMultiversX := flow.setup.IsTransferDoneFromMultiversX(flow.setup.AliceKeys, flow.setup.BobKeys, flow.tokens...) - isTransferDoneFromMultiversX := flow.setup.IsTransferDoneFromMultiversX(flow.tokens...) if !flow.mvxToEthDone && isTransferDoneFromMultiversX { flow.mvxToEthDone = true log.Info(fmt.Sprintf(framework.LogStepMarker, "MultiversX->Ethereum transfer finished, now sending back to MultiversX...")) - flow.setup.EthereumHandler.SendFromEthereumToMultiversX(flow.setup.Ctx, flow.setup.MultiversxHandler.TestCallerAddress, flow.tokens...) + flow.setup.EthereumHandler.SendFromEthereumToMultiversX(flow.setup.Ctx, flow.setup.BobKeys, flow.setup.CharlieKeys, flow.setup.MultiversxHandler.CalleeScAddress, flow.tokens...) } if !flow.mvxToEthDone { // return here, no reason to check downwards return false } - isTransferDoneFromEthereum := flow.setup.IsTransferDoneFromEthereum(flow.tokens...) + isTransferDoneFromEthereum := flow.setup.IsTransferDoneFromEthereum(flow.setup.BobKeys, flow.setup.CharlieKeys, flow.tokens...) if !flow.ethToMvxDone && isTransferDoneFromEthereum { flow.ethToMvxDone = true log.Info(fmt.Sprintf(framework.LogStepMarker, "MultiversX<->Ethereum from MultiversX transfers done"))