From 7f13d08f4caec15c9e0414dff6eb7430976504b6 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Mon, 21 Oct 2024 14:34:45 +0300 Subject: [PATCH 1/7] - refactor issue tokens steps --- .../slowTests/framework/ethereumHandler.go | 7 + .../slowTests/framework/multiversxHandler.go | 176 +++++++++++++----- .../relayers/slowTests/framework/types.go | 1 + 3 files changed, 142 insertions(+), 42 deletions(-) diff --git a/integrationTests/relayers/slowTests/framework/ethereumHandler.go b/integrationTests/relayers/slowTests/framework/ethereumHandler.go index 6db3c50a..81d7b68a 100644 --- a/integrationTests/relayers/slowTests/framework/ethereumHandler.go +++ b/integrationTests/relayers/slowTests/framework/ethereumHandler.go @@ -339,6 +339,13 @@ 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.TestKeys.EthAddress, mintAmount) + require.NoError(handler, err) + handler.SimulatedChain.Commit() + handler.checkEthTxResult(ctx, tx.Hash()) + } + return ethMintBurnAddress, ethMintBurnContract } diff --git a/integrationTests/relayers/slowTests/framework/multiversxHandler.go b/integrationTests/relayers/slowTests/framework/multiversxHandler.go index 93010ed4..be1c12ba 100644 --- a/integrationTests/relayers/slowTests/framework/multiversxHandler.go +++ b/integrationTests/relayers/slowTests/framework/multiversxHandler.go @@ -90,13 +90,14 @@ type MultiversxHandler struct { TokensRegistry TokensRegistry ChainSimulator ChainSimulatorWrapper - AggregatorAddress *MvxAddress - WrapperAddress *MvxAddress - SafeAddress *MvxAddress - MultisigAddress *MvxAddress - MultiTransferAddress *MvxAddress - ScProxyAddress *MvxAddress - TestCallerAddress *MvxAddress + AggregatorAddress *MvxAddress + WrapperAddress *MvxAddress + SafeAddress *MvxAddress + MultisigAddress *MvxAddress + MultiTransferAddress *MvxAddress + ScProxyAddress *MvxAddress + TestCallerAddress *MvxAddress + ESDTSystemContractAddress *MvxAddress } // NewMultiversxHandler will create the handler that will adapt all test operations on MultiversX @@ -116,6 +117,8 @@ func NewMultiversxHandler( Quorum: quorum, } + handler.ESDTSystemContractAddress = NewMvxAddressFromBech32(handler, esdtSystemSCAddress) + handler.ChainSimulator.GenerateBlocksUntilEpochReached(ctx, 1) handler.ChainSimulator.FundWallets(ctx, handler.WalletsToFundOnMultiversX()) @@ -550,16 +553,30 @@ func (handler *MultiversxHandler) stakeAddressesOnContract(ctx context.Context, // IssueAndWhitelistToken will issue and whitelist the token on MultiversX func (handler *MultiversxHandler) IssueAndWhitelistToken(ctx context.Context, params IssueTokenParams) { + handler.issueUniversalToken(ctx, params) + handler.issueChainSpecificToken(ctx, params) + handler.setLocalRolesForUniversalTokenOnWrapper(ctx, params) + handler.transferChainSpecificTokenToSCs(ctx, params) + handler.addUniversalTokenToWrapper(ctx, params) + handler.whitelistTokenOnWrapper(ctx, params) + handler.setRolesForSpecificTokenOnSafe(ctx, params) + handler.addMappingInMultisig(ctx, params) + handler.whitelistTokenOnMultisig(ctx, params) + handler.setInitialSupply(ctx, params) + handler.setPairDecimalsOnAggregator(ctx, params) + handler.setMaxBridgeAmountOnSafe(ctx, params) + handler.setMaxBridgeAmountOnMultitransfer(ctx, params) +} + +func (handler *MultiversxHandler) issueUniversalToken(ctx context.Context, params IssueTokenParams) { token := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) require.NotNil(handler, token) - esdtAddress := NewMvxAddressFromBech32(handler, esdtSystemSCAddress) - // issue universal token hash, txResult := handler.ChainSimulator.ScCall( ctx, handler.OwnerKeys.MvxSk, - esdtAddress, + handler.ESDTSystemContractAddress, esdtIssueCost, issueTokenGasLimit, issueFunction, @@ -574,15 +591,21 @@ func (handler *MultiversxHandler) IssueAndWhitelistToken(ctx context.Context, pa require.Greater(handler, len(mvxUniversalToken), 0) handler.TokensRegistry.RegisterUniversalToken(params.AbstractTokenIdentifier, mvxUniversalToken) log.Info("issue universal token tx executed", "hash", hash, "status", txResult.Status, "token", mvxUniversalToken, "owner", handler.OwnerKeys.MvxAddress) +} + +func (handler *MultiversxHandler) issueChainSpecificToken(ctx context.Context, params IssueTokenParams) { + //TODO: check + //if !params.HasChainSpecificToken { + // log.Info("skipping issuing the chain specific token", "token", params.AbstractTokenIdentifier) + //} - // issue chain specific token valueToMintInt, ok := big.NewInt(0).SetString(params.ValueToMintOnMvx, 10) require.True(handler, ok) - hash, txResult = handler.ChainSimulator.ScCall( + hash, txResult := handler.ChainSimulator.ScCall( ctx, handler.OwnerKeys.MvxSk, - esdtAddress, + handler.ESDTSystemContractAddress, esdtIssueCost, issueTokenGasLimit, issueFunction, @@ -597,25 +620,46 @@ func (handler *MultiversxHandler) IssueAndWhitelistToken(ctx context.Context, pa require.Greater(handler, len(mvxChainSpecificToken), 0) handler.TokensRegistry.RegisterChainSpecificToken(params.AbstractTokenIdentifier, mvxChainSpecificToken) log.Info("issue chain specific token tx executed", "hash", hash, "status", txResult.Status, "token", mvxChainSpecificToken, "owner", handler.OwnerKeys.MvxAddress) +} + +func (handler *MultiversxHandler) setLocalRolesForUniversalTokenOnWrapper(ctx context.Context, params IssueTokenParams) { + //TODO: check + //if !params.IsMintBurnOnMvX { + // log.Info("skipping setting the local mint-burn role for the universal token, not required", "token", params.AbstractTokenIdentifier) + //} + + tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) // set local roles bridged tokens wrapper - hash, txResult = handler.ChainSimulator.ScCall( + hash, txResult := handler.ChainSimulator.ScCall( ctx, handler.OwnerKeys.MvxSk, - esdtAddress, + handler.ESDTSystemContractAddress, zeroStringValue, setCallsGasLimit, setSpecialRoleFunction, []string{ - hex.EncodeToString([]byte(mvxUniversalToken)), + hex.EncodeToString([]byte(tkData.MvxUniversalToken)), handler.WrapperAddress.Hex(), hex.EncodeToString([]byte(esdtRoleLocalMint)), hex.EncodeToString([]byte(esdtRoleLocalBurn))}) log.Info("set local roles bridged tokens wrapper tx executed", "hash", hash, "status", txResult.Status) +} + +func (handler *MultiversxHandler) transferChainSpecificTokenToSCs(ctx context.Context, params IssueTokenParams) { + //TODO: check + //if !params.HasChainSpecificToken { + // log.Info("skipping transferring the chain specific token to the wrapper & ESDT safe contracts", "token", params.AbstractTokenIdentifier) + //} + + valueToMintInt, ok := big.NewInt(0).SetString(params.ValueToMintOnMvx, 10) + require.True(handler, ok) + + tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) // transfer to wrapper sc initialMintValue := valueToMintInt.Div(valueToMintInt, big.NewInt(3)) - hash, txResult = handler.ChainSimulator.ScCall( + hash, txResult := handler.ChainSimulator.ScCall( ctx, handler.OwnerKeys.MvxSk, handler.WrapperAddress, @@ -623,7 +667,7 @@ func (handler *MultiversxHandler) IssueAndWhitelistToken(ctx context.Context, pa setCallsGasLimit, esdtTransferFunction, []string{ - hex.EncodeToString([]byte(mvxChainSpecificToken)), + hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), hex.EncodeToString(initialMintValue.Bytes()), hex.EncodeToString([]byte(depositLiquidityFunction))}) log.Info("transfer to wrapper sc tx executed", "hash", hash, "status", txResult.Status) @@ -637,12 +681,17 @@ func (handler *MultiversxHandler) IssueAndWhitelistToken(ctx context.Context, pa setCallsGasLimit, esdtTransferFunction, []string{ - hex.EncodeToString([]byte(mvxChainSpecificToken)), + hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), hex.EncodeToString(initialMintValue.Bytes())}) log.Info("transfer to safe sc tx executed", "hash", hash, "status", txResult.Status) +} + +func (handler *MultiversxHandler) addUniversalTokenToWrapper(ctx context.Context, params IssueTokenParams) { + //TODO: check + tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) // add wrapped token - hash, txResult = handler.ChainSimulator.ScCall( + hash, txResult := handler.ChainSimulator.ScCall( ctx, handler.OwnerKeys.MvxSk, handler.WrapperAddress, @@ -650,13 +699,18 @@ func (handler *MultiversxHandler) IssueAndWhitelistToken(ctx context.Context, pa setCallsGasLimit, addWrappedTokenFunction, []string{ - hex.EncodeToString([]byte(mvxUniversalToken)), + hex.EncodeToString([]byte(tkData.MvxUniversalToken)), fmt.Sprintf("%02x", params.NumOfDecimalsUniversal), }) log.Info("add wrapped token tx executed", "hash", hash, "status", txResult.Status) +} + +func (handler *MultiversxHandler) whitelistTokenOnWrapper(ctx context.Context, params IssueTokenParams) { + //TODO: check + tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) // wrapper whitelist token - hash, txResult = handler.ChainSimulator.ScCall( + hash, txResult := handler.ChainSimulator.ScCall( ctx, handler.OwnerKeys.MvxSk, handler.WrapperAddress, @@ -664,28 +718,38 @@ func (handler *MultiversxHandler) IssueAndWhitelistToken(ctx context.Context, pa setCallsGasLimit, whitelistTokenFunction, []string{ - hex.EncodeToString([]byte(mvxChainSpecificToken)), + hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), fmt.Sprintf("%02x", params.NumOfDecimalsChainSpecific), - hex.EncodeToString([]byte(mvxUniversalToken))}) + hex.EncodeToString([]byte(tkData.MvxUniversalToken))}) log.Info("wrapper whitelist token tx executed", "hash", hash, "status", txResult.Status) +} + +func (handler *MultiversxHandler) setRolesForSpecificTokenOnSafe(ctx context.Context, params IssueTokenParams) { + //TODO: check + tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) // set local roles esdt safe - hash, txResult = handler.ChainSimulator.ScCall( + hash, txResult := handler.ChainSimulator.ScCall( ctx, handler.OwnerKeys.MvxSk, - esdtAddress, + handler.ESDTSystemContractAddress, zeroStringValue, setCallsGasLimit, setSpecialRoleFunction, []string{ - hex.EncodeToString([]byte(mvxChainSpecificToken)), + hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), handler.SafeAddress.Hex(), hex.EncodeToString([]byte(esdtRoleLocalMint)), hex.EncodeToString([]byte(esdtRoleLocalBurn))}) log.Info("set local roles esdt safe tx executed", "hash", hash, "status", txResult.Status) +} + +func (handler *MultiversxHandler) addMappingInMultisig(ctx context.Context, params IssueTokenParams) { + //TODO: check + tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) // add mapping - hash, txResult = handler.ChainSimulator.ScCall( + hash, txResult := handler.ChainSimulator.ScCall( ctx, handler.OwnerKeys.MvxSk, handler.MultisigAddress, @@ -693,12 +757,17 @@ func (handler *MultiversxHandler) IssueAndWhitelistToken(ctx context.Context, pa setCallsGasLimit, addMappingFunction, []string{ - hex.EncodeToString(token.EthErc20Address.Bytes()), - hex.EncodeToString([]byte(mvxChainSpecificToken))}) + hex.EncodeToString(tkData.EthErc20Address.Bytes()), + hex.EncodeToString([]byte(tkData.MvxChainSpecificToken))}) log.Info("add mapping tx executed", "hash", hash, "status", txResult.Status) +} + +func (handler *MultiversxHandler) whitelistTokenOnMultisig(ctx context.Context, params IssueTokenParams) { + // TODO: check + tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) // whitelist token - hash, txResult = handler.ChainSimulator.ScCall( + hash, txResult := handler.ChainSimulator.ScCall( ctx, handler.OwnerKeys.MvxSk, handler.MultisigAddress, @@ -706,7 +775,7 @@ func (handler *MultiversxHandler) IssueAndWhitelistToken(ctx context.Context, pa setCallsGasLimit, esdtSafeAddTokenToWhitelistFunction, []string{ - hex.EncodeToString([]byte(mvxChainSpecificToken)), + hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), hex.EncodeToString([]byte(params.MvxChainSpecificTokenTicker)), getHexBool(params.IsMintBurnOnMvX), getHexBool(params.IsNativeOnMvX), @@ -715,6 +784,12 @@ func (handler *MultiversxHandler) IssueAndWhitelistToken(ctx context.Context, pa hex.EncodeToString(zeroValueBigInt.Bytes()), // burn_balance }) log.Info("whitelist token tx executed", "hash", hash, "status", txResult.Status) +} + +func (handler *MultiversxHandler) setInitialSupply(ctx context.Context, params IssueTokenParams) { + //TODO: check + + tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) // set initial supply if len(params.InitialSupplyValue) > 0 { @@ -722,7 +797,7 @@ func (handler *MultiversxHandler) IssueAndWhitelistToken(ctx context.Context, pa require.True(handler, okConvert) if params.IsMintBurnOnMvX { - hash, txResult = handler.ChainSimulator.ScCall( + hash, txResult := handler.ChainSimulator.ScCall( ctx, handler.OwnerKeys.MvxSk, handler.MultisigAddress, @@ -730,7 +805,7 @@ func (handler *MultiversxHandler) IssueAndWhitelistToken(ctx context.Context, pa setCallsGasLimit, initSupplyMintBurnEsdtSafe, []string{ - hex.EncodeToString([]byte(mvxChainSpecificToken)), + hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), hex.EncodeToString(initialSupply.Bytes()), hex.EncodeToString([]byte{0}), }, @@ -738,7 +813,7 @@ func (handler *MultiversxHandler) IssueAndWhitelistToken(ctx context.Context, pa log.Info("initial supply tx executed", "hash", hash, "status", txResult.Status, "initial mint", params.InitialSupplyValue, "initial burned", "0") } else { - hash, txResult = handler.ChainSimulator.ScCall( + hash, txResult := handler.ChainSimulator.ScCall( ctx, handler.OwnerKeys.MvxSk, handler.MultisigAddress, @@ -746,10 +821,10 @@ func (handler *MultiversxHandler) IssueAndWhitelistToken(ctx context.Context, pa setCallsGasLimit, esdtTransferFunction, []string{ - hex.EncodeToString([]byte(mvxChainSpecificToken)), + hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), hex.EncodeToString(initialSupply.Bytes()), hex.EncodeToString([]byte(initSupplyEsdtSafe)), - hex.EncodeToString([]byte(mvxChainSpecificToken)), + hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), hex.EncodeToString(initialSupply.Bytes()), }) @@ -757,9 +832,13 @@ func (handler *MultiversxHandler) IssueAndWhitelistToken(ctx context.Context, pa "initial value", params.InitialSupplyValue) } } +} + +func (handler *MultiversxHandler) setPairDecimalsOnAggregator(ctx context.Context, params IssueTokenParams) { + //TODO: check // setPairDecimals on aggregator - hash, txResult = handler.ChainSimulator.ScCall( + hash, txResult := handler.ChainSimulator.ScCall( ctx, handler.OwnerKeys.MvxSk, handler.AggregatorAddress, @@ -771,10 +850,16 @@ func (handler *MultiversxHandler) IssueAndWhitelistToken(ctx context.Context, pa hex.EncodeToString([]byte(params.MvxChainSpecificTokenTicker)), fmt.Sprintf("%02x", params.NumOfDecimalsChainSpecific)}) log.Info("setPairDecimals tx executed", "hash", hash, "status", txResult.Status) +} + +func (handler *MultiversxHandler) setMaxBridgeAmountOnSafe(ctx context.Context, params IssueTokenParams) { + //TODO: check + + tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) // safe set max bridge amount for token maxBridgedAmountForTokenInt, _ := big.NewInt(0).SetString(maxBridgedAmountForToken, 10) - hash, txResult = handler.ChainSimulator.ScCall( + hash, txResult := handler.ChainSimulator.ScCall( ctx, handler.OwnerKeys.MvxSk, handler.MultisigAddress, @@ -782,12 +867,19 @@ func (handler *MultiversxHandler) IssueAndWhitelistToken(ctx context.Context, pa setCallsGasLimit, esdtSafeSetMaxBridgedAmountForTokenFunction, []string{ - hex.EncodeToString([]byte(mvxChainSpecificToken)), + hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), hex.EncodeToString(maxBridgedAmountForTokenInt.Bytes())}) log.Info("safe set max bridge amount for token tx executed", "hash", hash, "status", txResult.Status) +} + +func (handler *MultiversxHandler) setMaxBridgeAmountOnMultitransfer(ctx context.Context, params IssueTokenParams) { + //TODO: check + + tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) // multi-transfer set max bridge amount for token - hash, txResult = handler.ChainSimulator.ScCall( + maxBridgedAmountForTokenInt, _ := big.NewInt(0).SetString(maxBridgedAmountForToken, 10) + hash, txResult := handler.ChainSimulator.ScCall( ctx, handler.OwnerKeys.MvxSk, handler.MultisigAddress, @@ -795,7 +887,7 @@ func (handler *MultiversxHandler) IssueAndWhitelistToken(ctx context.Context, pa setCallsGasLimit, multiTransferEsdtSetMaxBridgedAmountForTokenFunction, []string{ - hex.EncodeToString([]byte(mvxChainSpecificToken)), + hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), hex.EncodeToString(maxBridgedAmountForTokenInt.Bytes())}) log.Info("multi-transfer set max bridge amount for token tx executed", "hash", hash, "status", txResult.Status) } diff --git a/integrationTests/relayers/slowTests/framework/types.go b/integrationTests/relayers/slowTests/framework/types.go index 9a01cb82..dc165fe4 100644 --- a/integrationTests/relayers/slowTests/framework/types.go +++ b/integrationTests/relayers/slowTests/framework/types.go @@ -21,6 +21,7 @@ type IssueTokenParams struct { ValueToMintOnMvx string IsMintBurnOnMvX bool IsNativeOnMvX bool + HasChainSpecificToken bool // Ethereum EthTokenName string From 4af0fb5651a59a7fd871ceee280c01341f25fc7c Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Mon, 21 Oct 2024 19:11:12 +0300 Subject: [PATCH 2/7] - added more tokens - fixed out of gas error in eth client in tests - integrated new contracts --- integrationTests/relayers/common.go | 2 +- integrationTests/relayers/slowTests/common.go | 94 +++++++++++++++- .../ethToMultiversXWithChainSimulator_test.go | 10 ++ .../slowTests/framework/multiversxHandler.go | 101 +++++++----------- .../refundWithChainSimulator_test.go | 12 +++ .../testdata/contracts/mvx/bridge-proxy.wasm | Bin 17129 -> 17215 bytes .../contracts/mvx/bridged-tokens-wrapper.wasm | Bin 12325 -> 12325 bytes .../testdata/contracts/mvx/esdt-safe.wasm | Bin 34390 -> 34390 bytes .../contracts/mvx/multi-transfer-esdt.wasm | Bin 21916 -> 21916 bytes .../testdata/contracts/mvx/multisig.wasm | Bin 38439 -> 38439 bytes 10 files changed, 154 insertions(+), 65 deletions(-) diff --git a/integrationTests/relayers/common.go b/integrationTests/relayers/common.go index 5fc45bf2..20745a0b 100644 --- a/integrationTests/relayers/common.go +++ b/integrationTests/relayers/common.go @@ -70,7 +70,7 @@ func CreateBridgeComponentsConfig(index int, workingDir string, gasStationURL st MultisigContractAddress: "3009d97FfeD62E57d444e552A9eDF9Ee6Bc8644c", PrivateKeyFile: fmt.Sprintf("testdata/ethereum%d.sk", index), IntervalToResendTxsInSeconds: 10, - GasLimitBase: 200000, + GasLimitBase: 350000, GasLimitForEach: 30000, GasStation: config.GasStationConfig{ Enabled: len(gasStationURL) > 0, diff --git a/integrationTests/relayers/slowTests/common.go b/integrationTests/relayers/slowTests/common.go index 157f3c50..0746134d 100644 --- a/integrationTests/relayers/slowTests/common.go +++ b/integrationTests/relayers/slowTests/common.go @@ -31,8 +31,9 @@ func GenerateTestUSDCToken() framework.TestTokenParams { ValueToMintOnMvx: "10000000000", IsMintBurnOnMvX: true, IsNativeOnMvX: false, - EthTokenName: "ETHTOKEN", - EthTokenSymbol: "ETHT", + HasChainSpecificToken: true, + EthTokenName: "EthUSDC", + EthTokenSymbol: "USDC", ValueToMintOnEth: "10000000000", IsMintBurnOnEth: false, IsNativeOnEth: true, @@ -72,8 +73,9 @@ func GenerateTestMEMEToken() framework.TestTokenParams { ValueToMintOnMvx: "10000000000", IsMintBurnOnMvX: false, IsNativeOnMvX: true, - EthTokenName: "ETHMEME", - EthTokenSymbol: "ETHM", + HasChainSpecificToken: true, + EthTokenName: "EthMEME", + EthTokenSymbol: "MEME", ValueToMintOnEth: "10000000000", IsMintBurnOnEth: true, IsNativeOnEth: false, @@ -98,6 +100,90 @@ func GenerateTestMEMEToken() framework.TestTokenParams { } } +// GenerateTestEUROCToken will generate a test EUROC token +func GenerateTestEUROCToken() framework.TestTokenParams { + //EUROC is ethNative = true, ethMintBurn = true, mvxNative = false, mvxMintBurn = true + return framework.TestTokenParams{ + IssueTokenParams: framework.IssueTokenParams{ + AbstractTokenIdentifier: "EUROC", + NumOfDecimalsUniversal: 6, + NumOfDecimalsChainSpecific: 6, + MvxUniversalTokenTicker: "EUROC", + MvxChainSpecificTokenTicker: "EUROC", + MvxUniversalTokenDisplayName: "TestEUROC", + MvxChainSpecificTokenDisplayName: "TestEUROC", + ValueToMintOnMvx: "10000000000", + IsMintBurnOnMvX: true, + IsNativeOnMvX: false, + HasChainSpecificToken: false, + EthTokenName: "EthEuroC", + EthTokenSymbol: "EUROC", + ValueToMintOnEth: "10000000000", + IsMintBurnOnEth: true, + IsNativeOnEth: true, + }, + TestOperations: []framework.TokenOperations{ + { + ValueToTransferToMvx: big.NewInt(5010), + ValueToSendFromMvX: big.NewInt(2510), + }, + { + ValueToTransferToMvx: big.NewInt(7010), + ValueToSendFromMvX: big.NewInt(310), + }, + { + ValueToTransferToMvx: big.NewInt(1010), + ValueToSendFromMvX: nil, + 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 + } +} + +// GenerateTestMEXToken will generate a test EUROC token +func GenerateTestMEXToken() framework.TestTokenParams { + //MEX is ethNative = false, ethMintBurn = true, mvxNative = true, mvxMintBurn = true + return framework.TestTokenParams{ + IssueTokenParams: framework.IssueTokenParams{ + AbstractTokenIdentifier: "MEX", + NumOfDecimalsUniversal: 2, + NumOfDecimalsChainSpecific: 2, + MvxUniversalTokenTicker: "MEX", + MvxChainSpecificTokenTicker: "MEX", + MvxUniversalTokenDisplayName: "TestMEX", + MvxChainSpecificTokenDisplayName: "TestMEX", + ValueToMintOnMvx: "10000000000", + IsMintBurnOnMvX: true, + IsNativeOnMvX: true, + HasChainSpecificToken: false, + EthTokenName: "EthMex", + EthTokenSymbol: "MEX", + ValueToMintOnEth: "10000000000", + IsMintBurnOnEth: true, + IsNativeOnEth: false, + }, + TestOperations: []framework.TokenOperations{ + { + ValueToTransferToMvx: big.NewInt(2410), + ValueToSendFromMvX: big.NewInt(4010), + }, + { + ValueToTransferToMvx: big.NewInt(210), + ValueToSendFromMvX: big.NewInt(6010), + }, + { + ValueToTransferToMvx: big.NewInt(1010), + ValueToSendFromMvX: big.NewInt(2010), + 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), + } +} + func createScCallData(function string, gasLimit uint64, args ...string) []byte { codec := testsCommon.TestMultiversXCodec{} callData := parsers.CallData{ diff --git a/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go b/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go index 21d90bf5..664f507b 100644 --- a/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go +++ b/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go @@ -36,6 +36,8 @@ func TestRelayersShouldExecuteTransfers(t *testing.T) { make(chan error), GenerateTestUSDCToken(), GenerateTestMEMEToken(), + GenerateTestEUROCToken(), + GenerateTestMEXToken(), ) } @@ -51,11 +53,19 @@ func TestRelayersShouldExecuteTransfersWithSCCallsWithArguments(t *testing.T) { memeToken := GenerateTestMEMEToken() memeToken.TestOperations[2].MvxSCCallData = callData + eurocToken := GenerateTestEUROCToken() + eurocToken.TestOperations[2].MvxSCCallData = callData + + mexToken := GenerateTestMEXToken() + mexToken.TestOperations[2].MvxSCCallData = callData + testSetup := testRelayersWithChainSimulatorAndTokens( t, make(chan error), usdcToken, memeToken, + eurocToken, + mexToken, ) testCallPayableWithParamsWasCalled(testSetup, 37, usdcToken.AbstractTokenIdentifier, memeToken.AbstractTokenIdentifier) diff --git a/integrationTests/relayers/slowTests/framework/multiversxHandler.go b/integrationTests/relayers/slowTests/framework/multiversxHandler.go index be1c12ba..b3230a50 100644 --- a/integrationTests/relayers/slowTests/framework/multiversxHandler.go +++ b/integrationTests/relayers/slowTests/framework/multiversxHandler.go @@ -66,8 +66,7 @@ const ( esdtSafeSetMaxBridgedAmountForTokenFunction = "esdtSafeSetMaxBridgedAmountForToken" multiTransferEsdtSetMaxBridgedAmountForTokenFunction = "multiTransferEsdtSetMaxBridgedAmountForToken" submitBatchFunction = "submitBatch" - createTransactionFunction = "createTransaction" - unwrapTokenFunction = "unwrapToken" + unwrapTokenCreateTransactionFunction = "unwrapTokenCreateTransaction" setBridgedTokensWrapperAddressFunction = "setBridgedTokensWrapperAddress" setMultiTransferAddressFunction = "setMultiTransferAddress" withdrawRefundFeesForEthereumFunction = "withdrawRefundFeesForEthereum" @@ -553,6 +552,14 @@ func (handler *MultiversxHandler) stakeAddressesOnContract(ctx context.Context, // IssueAndWhitelistToken will issue and whitelist the token on MultiversX func (handler *MultiversxHandler) IssueAndWhitelistToken(ctx context.Context, params IssueTokenParams) { + if params.HasChainSpecificToken { + handler.issueAndWhitelistTokensWithChainSpecific(ctx, params) + } else { + handler.issueAndWhitelistTokens(ctx, params) + } +} + +func (handler *MultiversxHandler) issueAndWhitelistTokensWithChainSpecific(ctx context.Context, params IssueTokenParams) { handler.issueUniversalToken(ctx, params) handler.issueChainSpecificToken(ctx, params) handler.setLocalRolesForUniversalTokenOnWrapper(ctx, params) @@ -568,10 +575,28 @@ func (handler *MultiversxHandler) IssueAndWhitelistToken(ctx context.Context, pa handler.setMaxBridgeAmountOnMultitransfer(ctx, params) } +func (handler *MultiversxHandler) issueAndWhitelistTokens(ctx context.Context, params IssueTokenParams) { + handler.issueUniversalToken(ctx, params) + + tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) + handler.TokensRegistry.RegisterChainSpecificToken(params.AbstractTokenIdentifier, tkData.MvxUniversalToken) + + handler.setRolesForSpecificTokenOnSafe(ctx, params) + handler.addMappingInMultisig(ctx, params) + handler.whitelistTokenOnMultisig(ctx, params) + handler.setInitialSupply(ctx, params) + handler.setPairDecimalsOnAggregator(ctx, params) + handler.setMaxBridgeAmountOnSafe(ctx, params) + handler.setMaxBridgeAmountOnMultitransfer(ctx, params) +} + func (handler *MultiversxHandler) issueUniversalToken(ctx context.Context, params IssueTokenParams) { token := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) require.NotNil(handler, token) + valueToMintInt, ok := big.NewInt(0).SetString(params.ValueToMintOnMvx, 10) + require.True(handler, ok) + // issue universal token hash, txResult := handler.ChainSimulator.ScCall( ctx, @@ -583,7 +608,7 @@ func (handler *MultiversxHandler) issueUniversalToken(ctx context.Context, param []string{ hex.EncodeToString([]byte(params.MvxUniversalTokenDisplayName)), hex.EncodeToString([]byte(params.MvxUniversalTokenTicker)), - "00", + hex.EncodeToString(valueToMintInt.Bytes()), fmt.Sprintf("%02x", params.NumOfDecimalsUniversal), hex.EncodeToString([]byte(canAddSpecialRoles)), hex.EncodeToString([]byte(trueStr))}) @@ -594,11 +619,6 @@ func (handler *MultiversxHandler) issueUniversalToken(ctx context.Context, param } func (handler *MultiversxHandler) issueChainSpecificToken(ctx context.Context, params IssueTokenParams) { - //TODO: check - //if !params.HasChainSpecificToken { - // log.Info("skipping issuing the chain specific token", "token", params.AbstractTokenIdentifier) - //} - valueToMintInt, ok := big.NewInt(0).SetString(params.ValueToMintOnMvx, 10) require.True(handler, ok) @@ -623,11 +643,6 @@ func (handler *MultiversxHandler) issueChainSpecificToken(ctx context.Context, p } func (handler *MultiversxHandler) setLocalRolesForUniversalTokenOnWrapper(ctx context.Context, params IssueTokenParams) { - //TODO: check - //if !params.IsMintBurnOnMvX { - // log.Info("skipping setting the local mint-burn role for the universal token, not required", "token", params.AbstractTokenIdentifier) - //} - tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) // set local roles bridged tokens wrapper @@ -647,11 +662,6 @@ func (handler *MultiversxHandler) setLocalRolesForUniversalTokenOnWrapper(ctx co } func (handler *MultiversxHandler) transferChainSpecificTokenToSCs(ctx context.Context, params IssueTokenParams) { - //TODO: check - //if !params.HasChainSpecificToken { - // log.Info("skipping transferring the chain specific token to the wrapper & ESDT safe contracts", "token", params.AbstractTokenIdentifier) - //} - valueToMintInt, ok := big.NewInt(0).SetString(params.ValueToMintOnMvx, 10) require.True(handler, ok) @@ -687,7 +697,6 @@ func (handler *MultiversxHandler) transferChainSpecificTokenToSCs(ctx context.Co } func (handler *MultiversxHandler) addUniversalTokenToWrapper(ctx context.Context, params IssueTokenParams) { - //TODO: check tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) // add wrapped token @@ -706,7 +715,6 @@ func (handler *MultiversxHandler) addUniversalTokenToWrapper(ctx context.Context } func (handler *MultiversxHandler) whitelistTokenOnWrapper(ctx context.Context, params IssueTokenParams) { - //TODO: check tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) // wrapper whitelist token @@ -725,7 +733,6 @@ func (handler *MultiversxHandler) whitelistTokenOnWrapper(ctx context.Context, p } func (handler *MultiversxHandler) setRolesForSpecificTokenOnSafe(ctx context.Context, params IssueTokenParams) { - //TODO: check tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) // set local roles esdt safe @@ -745,7 +752,6 @@ func (handler *MultiversxHandler) setRolesForSpecificTokenOnSafe(ctx context.Con } func (handler *MultiversxHandler) addMappingInMultisig(ctx context.Context, params IssueTokenParams) { - //TODO: check tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) // add mapping @@ -763,7 +769,6 @@ func (handler *MultiversxHandler) addMappingInMultisig(ctx context.Context, para } func (handler *MultiversxHandler) whitelistTokenOnMultisig(ctx context.Context, params IssueTokenParams) { - // TODO: check tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) // whitelist token @@ -787,8 +792,6 @@ func (handler *MultiversxHandler) whitelistTokenOnMultisig(ctx context.Context, } func (handler *MultiversxHandler) setInitialSupply(ctx context.Context, params IssueTokenParams) { - //TODO: check - tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) // set initial supply @@ -835,8 +838,6 @@ func (handler *MultiversxHandler) setInitialSupply(ctx context.Context, params I } func (handler *MultiversxHandler) setPairDecimalsOnAggregator(ctx context.Context, params IssueTokenParams) { - //TODO: check - // setPairDecimals on aggregator hash, txResult := handler.ChainSimulator.ScCall( ctx, @@ -853,8 +854,6 @@ func (handler *MultiversxHandler) setPairDecimalsOnAggregator(ctx context.Contex } func (handler *MultiversxHandler) setMaxBridgeAmountOnSafe(ctx context.Context, params IssueTokenParams) { - //TODO: check - tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) // safe set max bridge amount for token @@ -873,8 +872,6 @@ func (handler *MultiversxHandler) setMaxBridgeAmountOnSafe(ctx context.Context, } func (handler *MultiversxHandler) setMaxBridgeAmountOnMultitransfer(ctx context.Context, params IssueTokenParams) { - //TODO: check - tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) // multi-transfer set max bridge amount for token @@ -969,15 +966,16 @@ func (handler *MultiversxHandler) CreateDepositsOnMultiversxForToken( createDepositGasLimit, esdtTransferFunction, []string{ - hex.EncodeToString([]byte(token.MvxChainSpecificToken)), + hex.EncodeToString([]byte(token.MvxUniversalToken)), hex.EncodeToString(operation.ValueToSendFromMvX.Bytes())}) log.Info("transfer to sender tx executed", "hash", hash, "status", txResult.Status) // send tx to safe contract scCallParams := []string{ - hex.EncodeToString([]byte(token.MvxChainSpecificToken)), + hex.EncodeToString([]byte(token.MvxUniversalToken)), hex.EncodeToString(operation.ValueToSendFromMvX.Bytes()), - hex.EncodeToString([]byte(createTransactionFunction)), + hex.EncodeToString([]byte(unwrapTokenCreateTransactionFunction)), + hex.EncodeToString([]byte(token.MvxChainSpecificToken)), hex.EncodeToString(handler.TestKeys.EthAddress.Bytes()), } dataField := strings.Join(scCallParams, "@") @@ -985,7 +983,7 @@ func (handler *MultiversxHandler) CreateDepositsOnMultiversxForToken( hash, txResult = handler.ChainSimulator.ScCall( ctx, handler.TestKeys.MvxSk, - handler.SafeAddress, + handler.WrapperAddress, zeroStringValue, createDepositGasLimit+gasLimitPerDataByte*uint64(len(dataField)), esdtTransferFunction, @@ -998,43 +996,26 @@ func (handler *MultiversxHandler) CreateDepositsOnMultiversxForToken( // SendDepositTransactionFromMultiversx will send the deposit transaction from MultiversX func (handler *MultiversxHandler) SendDepositTransactionFromMultiversx(ctx context.Context, token *TokenData, value *big.Int) { - // unwrap token - paramsUnwrap := []string{ + // create transaction params + params := []string{ hex.EncodeToString([]byte(token.MvxUniversalToken)), hex.EncodeToString(value.Bytes()), - hex.EncodeToString([]byte(unwrapTokenFunction)), - hex.EncodeToString([]byte(token.MvxChainSpecificToken)), - } - - hash, txResult := handler.ChainSimulator.ScCall( - ctx, - handler.TestKeys.MvxSk, - handler.WrapperAddress, - zeroStringValue, - createDepositGasLimit, - esdtTransferFunction, - paramsUnwrap, - ) - log.Info("unwrap transaction sent", "hash", hash, "token", token.MvxUniversalToken, "status", txResult.Status) - - // send tx to safe contract - params := []string{ + hex.EncodeToString([]byte(unwrapTokenCreateTransactionFunction)), hex.EncodeToString([]byte(token.MvxChainSpecificToken)), - hex.EncodeToString(value.Bytes()), - hex.EncodeToString([]byte(createTransactionFunction)), hex.EncodeToString(handler.TestKeys.EthAddress.Bytes()), } dataField := strings.Join(params, "@") - hash, txResult = handler.ChainSimulator.ScCall( + hash, txResult := handler.ChainSimulator.ScCall( ctx, handler.TestKeys.MvxSk, - handler.SafeAddress, + handler.WrapperAddress, zeroStringValue, createDepositGasLimit+gasLimitPerDataByte*uint64(len(dataField)), esdtTransferFunction, - params) - log.Info("MultiversX->Ethereum transaction sent", "hash", hash, "status", txResult.Status) + params, + ) + log.Info("MultiversX->Ethereum transaction sent", "hash", hash, "token", token.MvxUniversalToken, "status", txResult.Status) } // TestWithdrawFees will try to withdraw the fees for the provided token from the safe contract to the owner diff --git a/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go b/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go index a90c2ad9..0a5d8b27 100644 --- a/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go +++ b/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go @@ -35,6 +35,18 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { memeToken, ) }) + t.Run("unknown marker and malformed SC call data should refund with MEX", func(t *testing.T) { + callData := []byte{5, 4, 55} + mexToken := GenerateTestMEXToken() + mexToken.TestOperations[2].MvxSCCallData = callData + mexToken.TestOperations[2].MvxFaultySCCall = true + + testRelayersWithChainSimulatorAndTokensAndRefund( + t, + make(chan error), + mexToken, + ) + }) t.Run("malformed SC call data should refund", func(t *testing.T) { callData := []byte{bridgeCore.DataPresentProtocolMarker, 4, 55} usdcToken := GenerateTestUSDCToken() diff --git a/integrationTests/relayers/slowTests/testdata/contracts/mvx/bridge-proxy.wasm b/integrationTests/relayers/slowTests/testdata/contracts/mvx/bridge-proxy.wasm index e39b6e01ebc8beaffe06931442f73fc4267b0913..c32618c444e4f9f50f39eedc16aeb0aabf7d81ae 100755 GIT binary patch delta 2043 zcmZuyYit!o6y7ttd+(K7+9?HWZ>`AfevgKE$q(;4_MbM`AF9_knQdu;Z8|%1&Y5q% zbIv!@Utgl(P1N7*%(UDoWL2e7B4xYerbSt~ZMkGwt`M%}T4cKw6=}=OIw|3nlZu>X zk+S0L&IzJ_)tXdC>2k(#OY{Qaub~e=R`@-w%u}PDdlZgXk!Q(I*dur8@lzgs0pB0m zw_98H@aU2J>}pIwY$OvEW+LAfJ^brYARgdho%|S~C2KNvg~cemw0<)V&&s_9D4ZQ} zRFQ{n!y}ZD>`%O#DZ(=Ecy>Vm00CF5s36|K%%f&|O}o8KPXp1GN66M>F+1-T#Adw+ zHxf3Kc3>etXVi9k8DMs5V9#l`VbI9UfXb)Z?S8ZE1H!Qdag0~^9^o%e*v(&n?=(>- znav34j8nH;59%zv$a6iLGa5itAP$nGeJadU^~OxVcbGaz1Y9_WW95E!lu;JUg7Mw( z8lss=n@9pagv;)8qq3@3CiCl`o2{gMlm z>L}cyp)1GQ9f)ef{|4WZL%dynq~X%wyMbpp&+^i8Si2?$xSlf>kV5PT2Y8wBnT46& zgkxDWC8&lem_&?tL_zE@ZM!foA}bLMT5I%z&KOaRsbvjN61BJ!%W;ibpbD)Pe2-8G zG6A-h3$PQp;3i!w7p^msM%l*YvQK9ROPQ}78Q)I2jGQ2QPiTc%6LljE3}0B#eH87x zDw?SVMgqo&#!cW5&2TON!NI^~|->8jUuyn(>h|{N4EfQLe=-uP;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+w!&3;qHPFfyry+wz>ama z_ra{()81SWTwB><(m|%e{yc$8(>MwDR|&<-L42 z()}U-*>dg?`El1awR;q!AMD<#*6ZcZ-8K}5d(L9$bWa|~n?2Xzl3du(3BSoi?}hCd*c{Af&B%ClazDSx zd@?ysNJqetk+F`+0R$C5dLBn%Y3vCV+$zWnUxp|+M924WC&37fT z86{4Ej8tHBnNI5VHJ_X4t0p$gn8-Xl=r<*rQ+cPm9ocvL? z4NS^So+ekucyKeX`~*gzz&r(MAh}E7G?*kx}5lWI^=|#^;->)Z0K-GHL|@$q=nzAh|-z SiSha5*IHA7-e}Zb!U6!X7j#?z delta 422 zcmaKnO-n*S6o&5^FX6Z22X#xc(ZtXC0j=`-4=mld2-}GvErOsHaix$}5*%tF`)}m0@!Ix`ZSy>ScoHx~>ODcLFF)8neB=!oC>*9mm+d$BfQ z5HEuJ(BY1yGY}6=<`=wYy-BTMGjt$CEnFefAVsHTro@RR5nwa4iZcdP^hei*CCNJwr7=8~I&H^~eP@GE&PzEMqGslWN`gO30J diff --git a/integrationTests/relayers/slowTests/testdata/contracts/mvx/esdt-safe.wasm b/integrationTests/relayers/slowTests/testdata/contracts/mvx/esdt-safe.wasm index dd7f90f36b5ca7cc303595dac21448b3e3fa50ce..2217c14240e50d8ef3891eea6c78882e9ff5f227 100755 GIT binary patch delta 2618 zcmai0Yitx%6rOWub~@YLmP@<4F1zhAyQP*ELMv&jfW=NhiXuu-9)`EHG+ESAsTCAy zQG}MZ2pk>}qE<1{#E63ke&;){ zd*|~u_IVq7rGw!f7RC-1F^{kuHiEm|OqCgPXUMW!mD6Rntg3yO+a+t7mZqspQ#H+{ zX`p5@28@KV!Z|SJ1H9H%L2o1iQ+Sz=zv$GEC7bBU`!gLCHdY0DKjhl4Y|_a>T} znxs;u=#tKGSZ04L%S^%iOrJS5^G5{>!$aUW&I|`|MQ}LQhl_A{@D}w(fJUCccZ0>y ziRXh~2Y$9dqM$Rw8#lJLH#bQ}AKry0`}v>?U7^R|G`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Po*beLefVet_!{6?74)b+q4u87Bo_x zuaHb8@OjZ?n8NyEAK|Iur-X%(eK2LTNAdv{@!s}hBnp(=hx5kUl5PfzMpNk_N;F>X zxJ3fv#LgB5lb9;2B8=$hTDtAUbobrMGkn&wXom09$%HXdej0p}W^)dv(lH&{50i*h zB2$~hx{62SlTjJd(-Kv?vZ9pq#}Lj<5bVOo11;wtNIwW z$Gp&oiC93nk?!n0&Q!mk&IY2t;T;atR1z-KL*ybAn_vNd)o!4rhxQx+7{{S% SkFs={al965ptZ<*yX8NRzYSLa delta 871 zcmZWmTS!z<6utYLnR`d?OkHQDnQP<{I-emHutat!av;FwLt_M}TvcbA_pj zgQ`D8Kp|m#H7W&FJOqr%(yI@gAlK^9Z+Ww`E zWr{aNglu04L58!Uh45%N2JJW$4$}X}@Gh5?>W7u;K^(Iq6;wYGX+cN&ZkU$)(jPHM zU?`)(Yb6hJ0d%v`X=XMO*qPB{9%sg2UN&T|=8%xBS=WF(a&u;3LWbAZa({rHAliEB zOk9aNj4rElfG)(tx#{v&ZZ^j| zt{^~otl%MGe&J3Slcx)F0Os)a=7S^(72Sbz@^w)MgE`q)yq6l~vn|(2Ae*aV^t?4!$6~He(IDmeMw5)nq0-|J7&nJ=GMzT-G`^cetPn0^9Ba$&kxz1Y zP1KU;M)#6ZiQb1Mqt|q#h5gO=BD-Oo*_IeyC_hB^*|%|X&ZLT~3`TIEGGw7o>#=4V z!KuopG+STnH@v~Vs&c})su*EObuHDgx)J8_XZ2cIMP&Pa!2U|Vwy>_Zc)6yYo<-f! Gq5c7xUlXAK diff --git a/integrationTests/relayers/slowTests/testdata/contracts/mvx/multisig.wasm b/integrationTests/relayers/slowTests/testdata/contracts/mvx/multisig.wasm index ddc0cd821c4c0e02e5a853631f192fc300356ca5..1d41892e51c22edeb620edfec863b54a82d1f8ee 100755 GIT binary patch delta 3130 zcmaJ@2~d^S75>lv7M90y;mPB%$_cQK-QE-Wf4AUmQ4JBg>0 zWUNh^PAP6Up}%b=w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+ox+BSP#m*tFx|6%?)IlXk7O!BrerYw`SsBapfIZv}q?KU=Gq1fsPss2f}pS*-yC z=lPwc$L${r{xWIwh0D0OHjFy6p|+4Pe5y7Iu8A1pm1l0gTj*cI#JbWxt(>Ppc)8du z+*y|?+I7F~=e-wV0#Uzp@kH(G cws6V13VP$STGKGI)r57eufQqQvfkhKe;tx4P5=M^ From 4942610c1d7dad88472b904bac74a020aa33f48a Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Mon, 21 Oct 2024 21:17:15 +0300 Subject: [PATCH 3/7] - fixed e2e tests --- .../ethToMultiversXWithChainSimulator_test.go | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go b/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go index 664f507b..6838b2d0 100644 --- a/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go +++ b/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go @@ -68,7 +68,14 @@ func TestRelayersShouldExecuteTransfersWithSCCallsWithArguments(t *testing.T) { mexToken, ) - testCallPayableWithParamsWasCalled(testSetup, 37, usdcToken.AbstractTokenIdentifier, memeToken.AbstractTokenIdentifier) + testCallPayableWithParamsWasCalled( + testSetup, + 37, + usdcToken.AbstractTokenIdentifier, + memeToken.AbstractTokenIdentifier, + eurocToken.AbstractTokenIdentifier, + mexToken.AbstractTokenIdentifier, + ) } func TestRelayerShouldExecuteTransfersAndNotCatchErrors(t *testing.T) { @@ -404,6 +411,12 @@ func testCallPayableWithParamsWasCalled(testSetup *framework.TestSetup, value ui return } + universalTokens := make([]string, 0, len(tokens)) + for _, identifier := range tokens { + tkData := testSetup.TokensRegistry.GetTokenData(identifier) + universalTokens = append(universalTokens, tkData.MvxUniversalToken) + } + vmRequest := &data.VmValueRequest{ Address: testSetup.MultiversxHandler.TestCallerAddress.Bech32(), FuncName: "getCalledDataParams", @@ -415,11 +428,20 @@ func testCallPayableWithParamsWasCalled(testSetup *framework.TestSetup, value ui returnedData := vmResponse.Data.ReturnData require.Equal(testSetup, len(tokens), len(returnedData)) - for i, token := range tokens { - buff := returnedData[i] + mapUniversalTokens := make(map[string]int) + for _, tokenIdentifier := range universalTokens { + mapUniversalTokens[tokenIdentifier] = 0 + } + + for _, buff := range returnedData { parsedValue, parsedToken := processCalledDataParams(buff) assert.Equal(testSetup, value, parsedValue) - assert.Contains(testSetup, parsedToken, token) + mapUniversalTokens[parsedToken]++ + } + + assert.Equal(testSetup, len(tokens), len(mapUniversalTokens)) + for _, numTokens := range mapUniversalTokens { + assert.Equal(testSetup, 1, numTokens) } } From dffa489b877f8162f110038297eb1e2609f626fe Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Mon, 21 Oct 2024 21:45:35 +0300 Subject: [PATCH 4/7] - more fixes on tests --- .../slowTests/ethToMultiversXWithChainSimulator_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go b/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go index 6838b2d0..ebcc24b8 100644 --- a/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go +++ b/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go @@ -275,6 +275,7 @@ func TestRelayersShouldNotExecuteTransfers(t *testing.T) { badToken.IsMintBurnOnEth = false badToken.IsNativeOnMvX = true badToken.IsMintBurnOnMvX = false + badToken.HasChainSpecificToken = true expectedStringInLogs := "error = invalid setup isNativeOnEthereum = true, isNativeOnMultiversX = true" testRelayersShouldNotExecuteTransfers(t, expectedStringInLogs, badToken) @@ -285,6 +286,7 @@ func TestRelayersShouldNotExecuteTransfers(t *testing.T) { badToken.IsMintBurnOnEth = false badToken.IsNativeOnMvX = true badToken.IsMintBurnOnMvX = true + badToken.HasChainSpecificToken = false expectedStringInLogs := "error = invalid setup isNativeOnEthereum = true, isNativeOnMultiversX = true" testRelayersShouldNotExecuteTransfers(t, expectedStringInLogs, badToken) @@ -295,6 +297,7 @@ func TestRelayersShouldNotExecuteTransfers(t *testing.T) { badToken.IsMintBurnOnEth = true badToken.IsNativeOnMvX = true badToken.IsMintBurnOnMvX = false + badToken.HasChainSpecificToken = true testEthContractsShouldError(t, badToken) }) @@ -304,6 +307,7 @@ func TestRelayersShouldNotExecuteTransfers(t *testing.T) { badToken.IsMintBurnOnEth = true badToken.IsNativeOnMvX = false badToken.IsMintBurnOnMvX = true + badToken.HasChainSpecificToken = true testEthContractsShouldError(t, badToken) }) From 2adf72642f599e52cf6cfd787dfc2c5d1c93f263 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Mon, 21 Oct 2024 23:11:24 +0300 Subject: [PATCH 5/7] - try tests fix --- .../ethToMultiversXWithChainSimulator_test.go | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go b/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go index ebcc24b8..6f4a00a1 100644 --- a/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go +++ b/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go @@ -36,6 +36,13 @@ func TestRelayersShouldExecuteTransfers(t *testing.T) { make(chan error), GenerateTestUSDCToken(), GenerateTestMEMEToken(), + ) +} + +func TestRelayersShouldExecuteTransfersWithMintBurnTokens(t *testing.T) { + _ = testRelayersWithChainSimulatorAndTokens( + t, + make(chan error), GenerateTestEUROCToken(), GenerateTestMEXToken(), ) @@ -53,6 +60,27 @@ func TestRelayersShouldExecuteTransfersWithSCCallsWithArguments(t *testing.T) { memeToken := GenerateTestMEMEToken() memeToken.TestOperations[2].MvxSCCallData = callData + testSetup := testRelayersWithChainSimulatorAndTokens( + t, + make(chan error), + usdcToken, + memeToken, + ) + + testCallPayableWithParamsWasCalled( + testSetup, + 37, + usdcToken.AbstractTokenIdentifier, + memeToken.AbstractTokenIdentifier, + ) +} + +func TestRelayersShouldExecuteTransfersWithSCCallsWithArgumentsWithMintBurnTokens(t *testing.T) { + dummyAddress := strings.Repeat("2", 32) + dummyUint64 := string([]byte{37}) + + callData := createScCallData("callPayableWithParams", 50000000, dummyUint64, dummyAddress) + eurocToken := GenerateTestEUROCToken() eurocToken.TestOperations[2].MvxSCCallData = callData @@ -62,8 +90,6 @@ func TestRelayersShouldExecuteTransfersWithSCCallsWithArguments(t *testing.T) { testSetup := testRelayersWithChainSimulatorAndTokens( t, make(chan error), - usdcToken, - memeToken, eurocToken, mexToken, ) @@ -71,8 +97,6 @@ func TestRelayersShouldExecuteTransfersWithSCCallsWithArguments(t *testing.T) { testCallPayableWithParamsWasCalled( testSetup, 37, - usdcToken.AbstractTokenIdentifier, - memeToken.AbstractTokenIdentifier, eurocToken.AbstractTokenIdentifier, mexToken.AbstractTokenIdentifier, ) From 16754f7fb405f8eaed30ea94be2087812e0d465c Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Tue, 22 Oct 2024 00:32:56 +0300 Subject: [PATCH 6/7] - fixed semi-integration test --- integrationTests/relayers/multiversXToEth_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/integrationTests/relayers/multiversXToEth_test.go b/integrationTests/relayers/multiversXToEth_test.go index 1372e406..c3cf23ef 100644 --- a/integrationTests/relayers/multiversXToEth_test.go +++ b/integrationTests/relayers/multiversXToEth_test.go @@ -22,6 +22,7 @@ import ( ) var zero = big.NewInt(0) +var relayerEthBalance = big.NewInt(1000000000) func asyncCancelCall(cancelHandler func(), delay time.Duration) { go func() { @@ -55,7 +56,7 @@ func TestRelayersShouldExecuteSimpleTransfersFromMultiversXToEth(t *testing.T) { return expectedStatuses, true } ethereumChainMock.BalanceAtCalled = func(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error) { - return big.NewInt(260000000), nil + return relayerEthBalance, nil } multiversXChainMock := mock.NewMultiversXChainMock() for i := 0; i < len(deposits); i++ { @@ -152,7 +153,7 @@ func testRelayersShouldExecuteTransfersFromMultiversXToEthIfTransactionsAppearIn return expectedStatuses, true } ethereumChainMock.BalanceAtCalled = func(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error) { - return big.NewInt(260000000), nil + return relayerEthBalance, nil } multiversXChainMock := mock.NewMultiversXChainMock() for i := 0; i < len(deposits); i++ { From 454107617426e940a86d3f8d112a8c268e2f3f63 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Tue, 22 Oct 2024 09:56:38 +0300 Subject: [PATCH 7/7] `duplicated code is the root of all evil` - removed duplicated code --- .../slowTests/framework/multiversxHandler.go | 77 ++++++------------- .../relayers/slowTests/framework/testSetup.go | 31 +++++++- 2 files changed, 51 insertions(+), 57 deletions(-) diff --git a/integrationTests/relayers/slowTests/framework/multiversxHandler.go b/integrationTests/relayers/slowTests/framework/multiversxHandler.go index b3230a50..225abfe5 100644 --- a/integrationTests/relayers/slowTests/framework/multiversxHandler.go +++ b/integrationTests/relayers/slowTests/framework/multiversxHandler.go @@ -941,59 +941,6 @@ func (handler *MultiversxHandler) submitAggregatorBatchForKey(ctx context.Contex return hash } -// CreateDepositsOnMultiversxForToken will send the deposit transactions on MultiversX returning how many tokens should be minted on Ethereum -func (handler *MultiversxHandler) CreateDepositsOnMultiversxForToken( - ctx context.Context, - params TestTokenParams, -) *big.Int { - token := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) - require.NotNil(handler, token) - - valueToMintOnEthereum := big.NewInt(0) - for _, operation := range params.TestOperations { - if operation.ValueToSendFromMvX == nil { - continue - } - - valueToMintOnEthereum.Add(valueToMintOnEthereum, operation.ValueToSendFromMvX) - - // transfer to sender tx - hash, txResult := handler.ChainSimulator.ScCall( - ctx, - handler.OwnerKeys.MvxSk, - handler.TestKeys.MvxAddress, - zeroStringValue, - createDepositGasLimit, - esdtTransferFunction, - []string{ - hex.EncodeToString([]byte(token.MvxUniversalToken)), - hex.EncodeToString(operation.ValueToSendFromMvX.Bytes())}) - log.Info("transfer to sender tx executed", "hash", hash, "status", txResult.Status) - - // send tx to safe contract - scCallParams := []string{ - hex.EncodeToString([]byte(token.MvxUniversalToken)), - hex.EncodeToString(operation.ValueToSendFromMvX.Bytes()), - hex.EncodeToString([]byte(unwrapTokenCreateTransactionFunction)), - hex.EncodeToString([]byte(token.MvxChainSpecificToken)), - hex.EncodeToString(handler.TestKeys.EthAddress.Bytes()), - } - dataField := strings.Join(scCallParams, "@") - - hash, txResult = handler.ChainSimulator.ScCall( - ctx, - handler.TestKeys.MvxSk, - handler.WrapperAddress, - zeroStringValue, - createDepositGasLimit+gasLimitPerDataByte*uint64(len(dataField)), - esdtTransferFunction, - scCallParams) - log.Info("MultiversX->Ethereum transaction sent", "hash", hash, "status", txResult.Status) - } - - return valueToMintOnEthereum -} - // SendDepositTransactionFromMultiversx will send the deposit transaction from MultiversX func (handler *MultiversxHandler) SendDepositTransactionFromMultiversx(ctx context.Context, token *TokenData, value *big.Int) { // create transaction params @@ -1072,6 +1019,30 @@ func (handler *MultiversxHandler) withdrawFees(ctx context.Context, withdrawFunction, initialBalanceStr, finalBalanceStr, expectedDelta.String())) } +// TransferToken is able to create an ESDT transfer +func (handler *MultiversxHandler) TransferToken(ctx context.Context, source KeysHolder, receiver KeysHolder, amount *big.Int, params TestTokenParams) { + tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) + + // transfer to the test key, so it will have funds to carry on with the deposits + hash, txResult := handler.ChainSimulator.ScCall( + ctx, + source.MvxSk, + receiver.MvxAddress, + zeroStringValue, + createDepositGasLimit, + esdtTransferFunction, + []string{ + hex.EncodeToString([]byte(tkData.MvxUniversalToken)), + hex.EncodeToString(amount.Bytes())}) + + log.Info("transfer to tx executed", + "source address", source.MvxAddress.Bech32(), + "receiver", receiver.MvxAddress.Bech32(), + "token", tkData.MvxUniversalToken, + "amount", amount.String(), + "hash", hash, "status", txResult.Status) +} + func getHexBool(input bool) string { if input { return hexTrue diff --git a/integrationTests/relayers/slowTests/framework/testSetup.go b/integrationTests/relayers/slowTests/framework/testSetup.go index d35232a9..83ec55b0 100644 --- a/integrationTests/relayers/slowTests/framework/testSetup.go +++ b/integrationTests/relayers/slowTests/framework/testSetup.go @@ -304,29 +304,52 @@ func (setup *TestSetup) createBatchOnMultiversXForToken(params TestTokenParams) token := setup.GetTokenData(params.AbstractTokenIdentifier) require.NotNil(setup, token) - valueToMintOnEthereum := setup.MultiversxHandler.CreateDepositsOnMultiversxForToken(setup.Ctx, params) - + setup.transferTokensToTestKey(params) + valueToMintOnEthereum := setup.sendFromMultiversxToEthereumForToken(params) setup.EthereumHandler.Mint(setup.Ctx, params, valueToMintOnEthereum) } +func (setup *TestSetup) transferTokensToTestKey(params TestTokenParams) { + depositValue := big.NewInt(0) + for _, operation := range params.TestOperations { + if operation.ValueToSendFromMvX == nil { + continue + } + + depositValue.Add(depositValue, operation.ValueToSendFromMvX) + } + + setup.MultiversxHandler.TransferToken( + setup.Ctx, + setup.OwnerKeys, + setup.TestKeys, + depositValue, + params, + ) +} + // SendFromMultiversxToEthereum will create the deposits that will be gathered in a batch on MultiversX (without mint on Ethereum) func (setup *TestSetup) SendFromMultiversxToEthereum(tokensParams ...TestTokenParams) { for _, params := range tokensParams { - setup.sendFromMultiversxToEthereumForToken(params) + _ = setup.sendFromMultiversxToEthereumForToken(params) } } -func (setup *TestSetup) sendFromMultiversxToEthereumForToken(params TestTokenParams) { +func (setup *TestSetup) sendFromMultiversxToEthereumForToken(params TestTokenParams) *big.Int { token := setup.GetTokenData(params.AbstractTokenIdentifier) require.NotNil(setup, token) + depositValue := big.NewInt(0) for _, operation := range params.TestOperations { if operation.ValueToSendFromMvX == nil { continue } + depositValue.Add(depositValue, operation.ValueToSendFromMvX) setup.MultiversxHandler.SendDepositTransactionFromMultiversx(setup.Ctx, token, operation.ValueToSendFromMvX) } + + return depositValue } // TestWithdrawTotalFeesOnEthereumForTokens will test the withdrawal functionality for the provided test tokens