From dd7655a1af2f8f38e2407f7477e5546aceeb2dca Mon Sep 17 00:00:00 2001 From: cosmatudor Date: Wed, 13 Nov 2024 17:20:38 +0200 Subject: [PATCH 01/17] add test for euroc and mex --- .../refundWithChainSimulator_test.go | 129 ++++++++++++++++-- 1 file changed, 120 insertions(+), 9 deletions(-) diff --git a/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go b/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go index 9c749875..74398b4f 100644 --- a/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go +++ b/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go @@ -27,15 +27,11 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { memeToken.TestOperations[2].MvxSCCallData = callData memeToken.TestOperations[2].MvxFaultySCCall = true - testRelayersWithChainSimulatorAndTokensAndRefund( - t, - make(chan error), - usdcToken, - memeToken, - ) - }) - t.Run("unknown marker and malformed SC call data should refund with MEX", func(t *testing.T) { - callData := []byte{5, 4, 55} + eurocToken := GenerateTestEUROCToken() + eurocToken.TestOperations[2].MvxSCCallData = callData + eurocToken.TestOperations[2].MvxFaultySCCall = true + eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + mexToken := GenerateTestMEXToken() mexToken.TestOperations[2].MvxSCCallData = callData mexToken.TestOperations[2].MvxFaultySCCall = true @@ -43,6 +39,9 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { testRelayersWithChainSimulatorAndTokensAndRefund( t, make(chan error), + usdcToken, + memeToken, + eurocToken, mexToken, ) }) @@ -57,11 +56,22 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { memeToken.TestOperations[2].MvxSCCallData = callData memeToken.TestOperations[2].MvxFaultySCCall = true + eurocToken := GenerateTestEUROCToken() + eurocToken.TestOperations[2].MvxSCCallData = callData + eurocToken.TestOperations[2].MvxFaultySCCall = true + eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + + mexToken := GenerateTestMEXToken() + mexToken.TestOperations[2].MvxSCCallData = callData + mexToken.TestOperations[2].MvxFaultySCCall = true + testRelayersWithChainSimulatorAndTokensAndRefund( t, make(chan error), usdcToken, memeToken, + eurocToken, + mexToken, ) }) t.Run("unknown function should refund", func(t *testing.T) { @@ -75,11 +85,22 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { memeToken.TestOperations[2].MvxSCCallData = callData memeToken.TestOperations[2].MvxFaultySCCall = true + eurocToken := GenerateTestEUROCToken() + eurocToken.TestOperations[2].MvxSCCallData = callData + eurocToken.TestOperations[2].MvxFaultySCCall = true + eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + + mexToken := GenerateTestMEXToken() + mexToken.TestOperations[2].MvxSCCallData = callData + mexToken.TestOperations[2].MvxFaultySCCall = true + testRelayersWithChainSimulatorAndTokensAndRefund( t, make(chan error), usdcToken, memeToken, + eurocToken, + mexToken, ) }) t.Run("wrong deposit with empty sc call data should refund", func(t *testing.T) { @@ -94,11 +115,24 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { memeToken.TestOperations[2].MvxFaultySCCall = true memeToken.TestOperations[2].MvxForceSCCall = true + eurocToken := GenerateTestEUROCToken() + eurocToken.TestOperations[2].MvxSCCallData = nil + eurocToken.TestOperations[2].MvxFaultySCCall = true + eurocToken.TestOperations[2].MvxForceSCCall = true + eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + + mexToken := GenerateTestMEXToken() + mexToken.TestOperations[2].MvxSCCallData = nil + mexToken.TestOperations[2].MvxFaultySCCall = true + mexToken.TestOperations[2].MvxForceSCCall = true + testRelayersWithChainSimulatorAndTokensAndRefund( t, make(chan error), usdcToken, memeToken, + eurocToken, + mexToken, ) }) t.Run("0 gas limit should refund", func(t *testing.T) { @@ -112,11 +146,22 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { memeToken.TestOperations[2].MvxSCCallData = callData memeToken.TestOperations[2].MvxFaultySCCall = true + eurocToken := GenerateTestEUROCToken() + eurocToken.TestOperations[2].MvxSCCallData = callData + eurocToken.TestOperations[2].MvxFaultySCCall = true + eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + + mexToken := GenerateTestMEXToken() + mexToken.TestOperations[2].MvxSCCallData = callData + mexToken.TestOperations[2].MvxFaultySCCall = true + testRelayersWithChainSimulatorAndTokensAndRefund( t, make(chan error), usdcToken, memeToken, + eurocToken, + mexToken, ) }) t.Run("small gas limit should refund", func(t *testing.T) { @@ -130,11 +175,22 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { memeToken.TestOperations[2].MvxSCCallData = callData memeToken.TestOperations[2].MvxFaultySCCall = true + eurocToken := GenerateTestEUROCToken() + eurocToken.TestOperations[2].MvxSCCallData = callData + eurocToken.TestOperations[2].MvxFaultySCCall = true + eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + + mexToken := GenerateTestMEXToken() + mexToken.TestOperations[2].MvxSCCallData = callData + mexToken.TestOperations[2].MvxFaultySCCall = true + testRelayersWithChainSimulatorAndTokensAndRefund( t, make(chan error), usdcToken, memeToken, + eurocToken, + mexToken, ) }) t.Run("extra parameter should refund", func(t *testing.T) { @@ -148,11 +204,22 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { memeToken.TestOperations[2].MvxSCCallData = callData memeToken.TestOperations[2].MvxFaultySCCall = true + eurocToken := GenerateTestEUROCToken() + eurocToken.TestOperations[2].MvxSCCallData = callData + eurocToken.TestOperations[2].MvxFaultySCCall = true + eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + + mexToken := GenerateTestMEXToken() + mexToken.TestOperations[2].MvxSCCallData = callData + mexToken.TestOperations[2].MvxFaultySCCall = true + testRelayersWithChainSimulatorAndTokensAndRefund( t, make(chan error), usdcToken, memeToken, + eurocToken, + mexToken, ) }) t.Run("no arguments should refund", func(t *testing.T) { @@ -166,11 +233,22 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { memeToken.TestOperations[2].MvxSCCallData = callData memeToken.TestOperations[2].MvxFaultySCCall = true + eurocToken := GenerateTestEUROCToken() + eurocToken.TestOperations[2].MvxSCCallData = callData + eurocToken.TestOperations[2].MvxFaultySCCall = true + eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + + mexToken := GenerateTestMEXToken() + mexToken.TestOperations[2].MvxSCCallData = callData + mexToken.TestOperations[2].MvxFaultySCCall = true + testRelayersWithChainSimulatorAndTokensAndRefund( t, make(chan error), usdcToken, memeToken, + eurocToken, + mexToken, ) }) t.Run("wrong number of arguments should refund", func(t *testing.T) { @@ -184,11 +262,22 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { memeToken.TestOperations[2].MvxSCCallData = callData memeToken.TestOperations[2].MvxFaultySCCall = true + eurocToken := GenerateTestEUROCToken() + eurocToken.TestOperations[2].MvxSCCallData = callData + eurocToken.TestOperations[2].MvxFaultySCCall = true + eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + + mexToken := GenerateTestMEXToken() + mexToken.TestOperations[2].MvxSCCallData = callData + mexToken.TestOperations[2].MvxFaultySCCall = true + testRelayersWithChainSimulatorAndTokensAndRefund( t, make(chan error), usdcToken, memeToken, + eurocToken, + mexToken, ) }) t.Run("not an uint64 argument should refund", func(t *testing.T) { @@ -205,11 +294,22 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { memeToken.TestOperations[2].MvxSCCallData = callData memeToken.TestOperations[2].MvxFaultySCCall = true + eurocToken := GenerateTestEUROCToken() + eurocToken.TestOperations[2].MvxSCCallData = callData + eurocToken.TestOperations[2].MvxFaultySCCall = true + eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + + mexToken := GenerateTestMEXToken() + mexToken.TestOperations[2].MvxSCCallData = callData + mexToken.TestOperations[2].MvxFaultySCCall = true + testRelayersWithChainSimulatorAndTokensAndRefund( t, make(chan error), usdcToken, memeToken, + eurocToken, + mexToken, ) }) t.Run("wrong arguments encoding should refund", func(t *testing.T) { @@ -228,11 +328,22 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { memeToken.TestOperations[2].MvxSCCallData = callData memeToken.TestOperations[2].MvxFaultySCCall = true + eurocToken := GenerateTestEUROCToken() + eurocToken.TestOperations[2].MvxSCCallData = callData + eurocToken.TestOperations[2].MvxFaultySCCall = true + eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + + mexToken := GenerateTestMEXToken() + mexToken.TestOperations[2].MvxSCCallData = callData + mexToken.TestOperations[2].MvxFaultySCCall = true + testRelayersWithChainSimulatorAndTokensAndRefund( t, make(chan error), usdcToken, memeToken, + eurocToken, + mexToken, ) }) } From 729b6d0197576de3f1da0cdac533c47bfc37c878 Mon Sep 17 00:00:00 2001 From: cosmatudor Date: Mon, 18 Nov 2024 18:38:10 +0200 Subject: [PATCH 02/17] add new fields to TestTokenParams --- integrationTests/relayers/slowTests/common.go | 10 ++++++++++ .../relayers/slowTests/framework/ethereumHandler.go | 6 +++++- integrationTests/relayers/slowTests/framework/types.go | 3 +++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/integrationTests/relayers/slowTests/common.go b/integrationTests/relayers/slowTests/common.go index 71db6440..01658157 100644 --- a/integrationTests/relayers/slowTests/common.go +++ b/integrationTests/relayers/slowTests/common.go @@ -52,6 +52,11 @@ func GenerateTestUSDCToken() framework.TestTokenParams { ValueToSendFromMvX: nil, MvxSCCallData: createScCallData("callPayable", 50000000), }, + { + ValueToTransferToMvx: big.NewInt(49), + ValueToSendFromMvX: nil, + IsFaultyDeposit: true, + }, }, ESDTSafeExtraBalance: big.NewInt(100), // extra is just for the fees for the 2 transfers mvx->eth ExtraBalances: map[string]framework.ExtraBalanceHolder{ @@ -107,6 +112,11 @@ func GenerateTestMEMEToken() framework.TestTokenParams { ValueToSendFromMvX: big.NewInt(2000), MvxSCCallData: createScCallData("callPayable", 50000000), }, + { + ValueToTransferToMvx: nil, + ValueToSendFromMvX: big.NewInt(38), + IsFaultyDeposit: true, + }, }, ESDTSafeExtraBalance: big.NewInt(4000 + 6000 + 2000), // everything is locked in the safe esdt contract ExtraBalances: map[string]framework.ExtraBalanceHolder{ diff --git a/integrationTests/relayers/slowTests/framework/ethereumHandler.go b/integrationTests/relayers/slowTests/framework/ethereumHandler.go index 834c2966..9a416dbc 100644 --- a/integrationTests/relayers/slowTests/framework/ethereumHandler.go +++ b/integrationTests/relayers/slowTests/framework/ethereumHandler.go @@ -435,7 +435,11 @@ func (handler *EthereumHandler) SendDepositTransactionFromEthereum( tx, err = handler.SafeContract.Deposit(auth, token.EthErc20Address, operation.ValueToTransferToMvx, to.MvxAddress.AddressSlice()) } - require.NoError(handler, err) + if operation.IsFaultyDeposit { + require.NotNil(handler, err) + } else { + require.NoError(handler, err) + } handler.SimulatedChain.Commit() handler.checkEthTxResult(ctx, tx.Hash()) } diff --git a/integrationTests/relayers/slowTests/framework/types.go b/integrationTests/relayers/slowTests/framework/types.go index 85a2900f..853c3297 100644 --- a/integrationTests/relayers/slowTests/framework/types.go +++ b/integrationTests/relayers/slowTests/framework/types.go @@ -10,6 +10,7 @@ import ( type IssueTokenParams struct { InitialSupplyParams AbstractTokenIdentifier string + AvoidWhiteList bool // MultiversX NumOfDecimalsUniversal int @@ -43,6 +44,8 @@ type TokenOperations struct { MvxSCCallData []byte MvxFaultySCCall bool MvxForceSCCall bool + IsFaultyDeposit bool + InvalidReceiver []byte } // TestTokenParams defines a token collection of operations in one or 2 batches From 361d97d17b28d43ce87df8fc19e7ecad185e790a Mon Sep 17 00:00:00 2001 From: cosmatudor Date: Tue, 19 Nov 2024 17:35:37 +0200 Subject: [PATCH 03/17] stuff --- docker/docker-compose.yaml | 140 ++++++++++++++++++ docker/scripts/send-tx.sh | 64 ++++++++ integrationTests/relayers/slowTests/common.go | 63 +++++++- .../ethToMultiversXWithChainSimulator_test.go | 4 +- .../slowTests/framework/ethereumHandler.go | 4 +- .../relayers/slowTests/framework/keys.go | 1 + .../relayers/slowTests/framework/testSetup.go | 93 ++++++++++-- .../refundWithChainSimulator_test.go | 2 - .../slowTests/startsFromEthereumFlow.go | 2 - .../slowTests/startsFromMultiversxFlow.go | 2 - 10 files changed, 345 insertions(+), 30 deletions(-) create mode 100644 docker/docker-compose.yaml create mode 100755 docker/scripts/send-tx.sh diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml new file mode 100644 index 00000000..3429227f --- /dev/null +++ b/docker/docker-compose.yaml @@ -0,0 +1,140 @@ +version: "3.9" + +services: + rabbitmq: + ports: + - 127.0.0.1:5672:5672 + - 127.0.0.1:15672:15672 + container_name: rabbitmq-container + image: "rabbitmq:3-management" + healthcheck: + test: rabbitmq-diagnostics -q ping + interval: 10s + timeout: 5s + retries: 5 + + redis: + image: "redis:alpine" + command: redis-server + ports: + - "127.0.0.1:6379:6379" + environment: + - REDIS_REPLICATION_MODE=master + + events-notifier: + container_name: events-notifier-container + image: multiversx/events-notifier:latest + depends_on: + rabbitmq: + condition: service_healthy + entrypoint: > + /bin/bash -c "apt-get update && apt-get install curl -y + && sed -i '/Enabled will determine if websocket connector will be enabled or not/{n;s/Enabled = false/Enabled = true/}' ./config/config.toml + && sed -i 's|localhost:22111|0.0.0.0:22111|g' ./config/config.toml + && sed -i 's|localhost:6379|redis:6379|g' ./config/config.toml + && sed -i 's|amqp://guest:guest@localhost:5672|amqp://guest:guest@rabbitmq:5672|g' ./config/config.toml + && cat ./config/config.toml + && ./notifier --check-duplicates=false --api-type=rabbit-api" + healthcheck: + test: ["CMD", "curl", "-f", "http://127.0.0.1:5000/status/metrics"] + interval: 10s + timeout: 5s + retries: 5 + + elasticsearch: + ports: + - 127.0.0.1:9200:9200 + container_name: elasticsearch-container + image: docker.elastic.co/elasticsearch/elasticsearch:7.16.1 + environment: + - "discovery.type=single-node" + - "xpack.security.enabled=false" + - "ES_JAVA_OPTS=-Xms512m -Xmx512m" + ulimits: + memlock: + soft: -1 + hard: -1 + healthcheck: + test: ["CMD", "curl", "-f", "http://127.0.0.1:9200"] + interval: 10s + timeout: 5s + retries: 5 + + # TODO use the websockets based elastic indexer when the communication problems are solved + elastic-indexer: + #ports: 22112 + container_name: elastic-indexer + image: multiversx/elastic-indexer:latest + depends_on: + elasticsearch: + condition: service_healthy + entrypoint: > + /bin/bash -c "sed -i 's|http://localhost:9200|http://elasticsearch:9200|g' ./config/prefs.toml + && sed -i 's|url = \"localhost:22111\"|url = \"0.0.0.0:22111\"|g' ./config/prefs.toml + && cat ./config/prefs.toml + && ./elasticindexer -log-level *:DEBUG" + + chain-simulator: + container_name: chain-simulator + ports: + - 8085:8085 + image: multiversx/chainsimulator:latest + environment: + EVENTS_NOTIFIER_URL: 'events-notifier:22111' + ELASTIC_SEARCH_URL: 'elasticsearch:9200' # just a dummy string for now + depends_on: + elasticsearch: + condition: service_healthy + events-notifier: + condition: service_healthy + entrypoint: > + /bin/bash -c " sed -i 's|http://localhost:9200|http://elasticsearch:9200|g' ./config/node/config/external.toml + && ./start-with-services.sh -log-level *:INFO" + healthcheck: + test: [ "CMD", "curl", "-f", "http://127.0.0.1:8085/simulator/observers" ] + interval: 10s + timeout: 5s + retries: 5 + + api: + ports: + - 127.0.0.1:3001:3001 + container_name: api + image: multiversx/mx-api-service:test1 + environment: + MVX_ENV: devnet + REDIS_IP: redis + GATEWAY_URL: http://chain-simulator:8085 + ELASTICSEARCH_URL: http://elasticsearch:9200 + depends_on: + elasticsearch: + condition: service_healthy + redis: + condition: service_started + + explorer: + ports: + - 3002:80 + container_name: explorer + image: multiversx/mx-explorer-dapp:main + environment: + START_NAME_STOP: devnet + START_CHAIN_ID_STOP: D + START_EGLD_LABEL_STOP: xEGLD + START_WALLET_ADDRESS_STOP: https://devnet-wallet.multiversx.com + START_EXPLORER_ADDRESS_STOP: https://devnet-explorer.multiversx.com + START_NFT_EXPLORER_ADDRESS_STOP: https://devnet.xspotlight.com + START_API_ADDRESS_STOP: http://127.0.0.1:3001 + + lite-wallet: + ports: + - 3003:80 + container_name: lite-wallet + image: multiversx/mx-lite-wallet-dapp:main + environment: + START_NETWORK_ID_STOP: custom + START_NETWORK_NAME_STOP: custom + START_API_ADDRESS_STOP: http://127.0.0.1:3001 + START_GATEWAY_URL_STOP: http://127.0.0.1:8085 + START_WALLET_ADDRESS_STOP: https://testnet-wallet.multiversx.com + START_WEGLD_ID_STOP: xEGLD diff --git a/docker/scripts/send-tx.sh b/docker/scripts/send-tx.sh new file mode 100755 index 00000000..1455196e --- /dev/null +++ b/docker/scripts/send-tx.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +# Call the endpoint and store the response in a variable +response=$(curl -s "http://localhost:8085/simulator/initial-wallets") + +# Use jq to extract the "bech32" address from the JSON response +bech32_address=$(echo "$response" | jq -r '.data.balanceWallets | to_entries[0].value.address.bech32') + +# Print the address to verify it was extracted correctly +echo "Extracted Bech32 Address: $bech32_address" + +# Get account information +account_info_response=$(curl -s --request GET \ + --url "http://localhost:8085/address/$bech32_address" \ + --header 'User-Agent: insomnia/10.0.0') + +# Print the response for debugging +echo "Account info response: $account_info_response" + +# Step 2: Extract the nonce using jq +nonce=$(echo "$account_info_response" | jq -r '.data.account.nonce') + +# Check if nonce is not empty +if [ -n "$nonce" ]; then + echo "Extracted nonce: $nonce" +else + echo "Error: No nonce found in the account info response." + exit 1 +fi + +tx_send_response=$(curl -s --request POST \ + --url http://localhost:8085/transaction/send \ + --header 'Content-Type: application/json' \ + --header 'User-Agent: insomnia/10.0.0' \ + --data '{ + "nonce": '$nonce', + "value": "50000000000000000000", + "sender": "'$bech32_address'", + "receiver": "erd12js50s7ycclwpac4qpx7lty3prhpu8hy00thjgz9f67p33w7m94qmzttem", + "gasLimit": 50000, + "gasPrice": 1000000000, + "chainId": "chain", + "signature": "aa", + "version": 1 +}') + +echo $tx_send_response + +# Extract txHash using jq +tx_hash=$(echo "$tx_send_response" | jq -r '.data.txHash') + +# Print the extracted txHash +echo "Extracted txHash: $tx_hash" + +sleep 2 + +# Make the second call to generate blocks until the transaction is processed +generate_blocks_response=$(curl -s --request POST \ + --url "http://localhost:8085/simulator/generate-blocks-until-transaction-processed/$tx_hash" \ + --header 'Content-Type: application/json' \ + --header 'User-Agent: insomnia/10.0.0') + +# Print the response from the second call +echo "Response from generate blocks: $generate_blocks_response" diff --git a/integrationTests/relayers/slowTests/common.go b/integrationTests/relayers/slowTests/common.go index 01658157..cbd3258f 100644 --- a/integrationTests/relayers/slowTests/common.go +++ b/integrationTests/relayers/slowTests/common.go @@ -1,8 +1,7 @@ -//go:build slow - package slowTests import ( + "bytes" "math/big" bridgeCore "github.com/multiversx/mx-bridge-eth-go/core" @@ -13,7 +12,9 @@ import ( ) var ( - log = logger.GetOrCreate("integrationTests/relayers/slowTests") + log = logger.GetOrCreate("integrationTests/relayers/slowTests") + ethZeroAddress = bytes.Repeat([]byte{0x00}, 20) + mvxZeroAddress = bytes.Repeat([]byte{0x00}, 32) ) // GenerateTestUSDCToken will generate a test USDC token @@ -53,15 +54,20 @@ func GenerateTestUSDCToken() framework.TestTokenParams { MvxSCCallData: createScCallData("callPayable", 50000000), }, { - ValueToTransferToMvx: big.NewInt(49), + ValueToTransferToMvx: big.NewInt(20), ValueToSendFromMvX: nil, IsFaultyDeposit: true, }, + { + ValueToTransferToMvx: big.NewInt(900), + ValueToSendFromMvX: nil, + InvalidReceiver: mvxZeroAddress, + }, }, 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), + SentAmount: big.NewInt(-5000 - 7000 - 1000 - 900), ReceivedAmount: big.NewInt(0), }, framework.Bob: { @@ -72,6 +78,10 @@ func GenerateTestUSDCToken() framework.TestTokenParams { SentAmount: big.NewInt(0), ReceivedAmount: big.NewInt(2500 - 50 + 300 - 50), }, + framework.AddressZero: { + SentAmount: big.NewInt(0), + ReceivedAmount: big.NewInt(900), + }, }, } } @@ -112,10 +122,15 @@ func GenerateTestMEMEToken() framework.TestTokenParams { ValueToSendFromMvX: big.NewInt(2000), MvxSCCallData: createScCallData("callPayable", 50000000), }, + //{ + // ValueToTransferToMvx: nil, + // ValueToSendFromMvX: big.NewInt(38), + // IsFaultyDeposit: true, + //}, { ValueToTransferToMvx: nil, - ValueToSendFromMvX: big.NewInt(38), - IsFaultyDeposit: true, + ValueToSendFromMvX: big.NewInt(650), + InvalidReceiver: ethZeroAddress, }, }, ESDTSafeExtraBalance: big.NewInt(4000 + 6000 + 2000), // everything is locked in the safe esdt contract @@ -132,6 +147,10 @@ func GenerateTestMEMEToken() framework.TestTokenParams { SentAmount: big.NewInt(0), ReceivedAmount: big.NewInt(2400 + 200), }, + framework.AddressZero: { + SentAmount: big.NewInt(0), + ReceivedAmount: big.NewInt(650), + }, }, } } @@ -172,6 +191,17 @@ func GenerateTestEUROCToken() framework.TestTokenParams { ValueToSendFromMvX: nil, MvxSCCallData: createScCallData("callPayable", 50000000), }, + { + ValueToTransferToMvx: big.NewInt(49), + ValueToSendFromMvX: nil, + IsFaultyDeposit: true, + }, + { + ValueToTransferToMvx: big.NewInt(700), + ValueToSendFromMvX: nil, + InvalidReceiver: mvxZeroAddress, + IsFaultyDeposit: true, + }, }, ESDTSafeExtraBalance: big.NewInt(100), // extra is just for the fees for the 2 transfers mvx->eth ExtraBalances: map[string]framework.ExtraBalanceHolder{ @@ -187,6 +217,10 @@ func GenerateTestEUROCToken() framework.TestTokenParams { SentAmount: big.NewInt(0), ReceivedAmount: big.NewInt(2510 - 50 + 310 - 50), }, + framework.AddressZero: { + SentAmount: big.NewInt(0), + ReceivedAmount: big.NewInt(700), + }, }, } } @@ -227,6 +261,17 @@ func GenerateTestMEXToken() framework.TestTokenParams { ValueToSendFromMvX: big.NewInt(2010), MvxSCCallData: createScCallData("callPayable", 50000000), }, + //{ + // ValueToTransferToMvx: big.NewInt(10), + // ValueToSendFromMvX: nil, + // IsFaultyDeposit: true, + //}, + { + ValueToTransferToMvx: nil, + ValueToSendFromMvX: big.NewInt(800), + InvalidReceiver: ethZeroAddress, + IsFaultyDeposit: true, + }, }, ESDTSafeExtraBalance: big.NewInt(150), // just the fees should be collected in ESDT safe ExtraBalances: map[string]framework.ExtraBalanceHolder{ @@ -242,6 +287,10 @@ func GenerateTestMEXToken() framework.TestTokenParams { SentAmount: big.NewInt(0), ReceivedAmount: big.NewInt(2410 + 210), }, + framework.AddressZero: { + SentAmount: big.NewInt(0), + ReceivedAmount: big.NewInt(800), + }, }, } } diff --git a/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go b/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go index 617cdb68..ffc9815d 100644 --- a/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go +++ b/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go @@ -1,5 +1,3 @@ -//go:build slow - // To run these slow tests, simply add the slow tag on the go test command. Also, provide a chain simulator instance on the 8085 port // example: go test -tags slow @@ -35,7 +33,7 @@ func TestRelayersShouldExecuteTransfers(t *testing.T) { t, make(chan error), GenerateTestUSDCToken(), - GenerateTestMEMEToken(), + //GenerateTestMEMEToken(), ) } diff --git a/integrationTests/relayers/slowTests/framework/ethereumHandler.go b/integrationTests/relayers/slowTests/framework/ethereumHandler.go index ee3bae85..fbbcb124 100644 --- a/integrationTests/relayers/slowTests/framework/ethereumHandler.go +++ b/integrationTests/relayers/slowTests/framework/ethereumHandler.go @@ -446,9 +446,9 @@ func (handler *EthereumHandler) SendDepositTransactionFromEthereum( if operation.IsFaultyDeposit { require.NotNil(handler, err) - } else { - require.NoError(handler, err) + return } + require.NoError(handler, err) handler.SimulatedChain.Commit() handler.checkEthTxResult(ctx, tx.Hash()) } diff --git a/integrationTests/relayers/slowTests/framework/keys.go b/integrationTests/relayers/slowTests/framework/keys.go index 30c97919..d3103068 100644 --- a/integrationTests/relayers/slowTests/framework/keys.go +++ b/integrationTests/relayers/slowTests/framework/keys.go @@ -58,6 +58,7 @@ const ( Alice = "Alice" Bob = "Bob" Charlie = "Charlie" + AddressZero = "AddressZero" ) // NewKeysStore will create a KeysStore instance and generate all keys diff --git a/integrationTests/relayers/slowTests/framework/testSetup.go b/integrationTests/relayers/slowTests/framework/testSetup.go index ce2c78a8..2f7bafd4 100644 --- a/integrationTests/relayers/slowTests/framework/testSetup.go +++ b/integrationTests/relayers/slowTests/framework/testSetup.go @@ -1,8 +1,10 @@ package framework import ( + "bytes" "context" "fmt" + "github.com/ethereum/go-ethereum/common" "math/big" "os" "path" @@ -243,6 +245,10 @@ func (setup *TestSetup) isTransferDoneFromEthereumForToken(sender, receiver Keys return false } + //if !setup.checkMvxAddressZeroBalanceForToken(params) { + // return false + //} + if !setup.checkContractMvxBalanceForToken(params) { return false } @@ -261,7 +267,7 @@ func (setup *TestSetup) checkHolderEthBalanceForToken(holder KeysHolder, isSende } actualBalance := setup.EthereumHandler.GetBalance(holder.EthAddress, params.AbstractTokenIdentifier) - + fmt.Println("----------------------ETH-------------------------") return setup.checkHolderBalanceForTokenHelper(balanceMapping, params, actualBalance, holder.EthAddress.String(), isSender) } @@ -272,29 +278,25 @@ func (setup *TestSetup) checkHolderMvxBalanceForToken(holder KeysHolder, isSende } actualBalance := setup.MultiversxHandler.GetESDTUniversalTokenBalance(setup.Ctx, holder.MvxAddress, params.AbstractTokenIdentifier) - + fmt.Println("---------------------MVX--------------------------") return setup.checkHolderBalanceForTokenHelper(balanceMapping, params, actualBalance, holder.MvxAddress.String(), isSender) } -func (setup *TestSetup) getBalanceMappingForAddress(addr string) (map[string]*big.Int, bool) { +func (setup *TestSetup) getBalanceMappingForAddress(address string) (map[string]*big.Int, bool) { setup.mutBalances.Lock() defer setup.mutBalances.Unlock() - if strings.HasPrefix(addr, mvxHrp) { - balanceMapping, exists := setup.mvxBalances[addr] + if strings.HasPrefix(address, mvxHrp) { + balanceMapping, exists := setup.mvxBalances[address] return balanceMapping, exists } - balanceMapping, exists := setup.ethBalances[addr] + balanceMapping, exists := setup.ethBalances[address] 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() - +func (setup *TestSetup) checkHolderBalanceForTokenHelper(balanceMapping map[string]*big.Int, params TestTokenParams, actualBalance *big.Int, address string, isSender bool) bool { + extraBalances := setup.getExtraBalanceForHolder(address, params) expectedBalance := big.NewInt(0).Set(balanceMapping[params.AbstractTokenIdentifier]) expectedBalance.Add(expectedBalance, extraBalances.ReceivedAmount) @@ -302,9 +304,36 @@ func (setup *TestSetup) checkHolderBalanceForTokenHelper(balanceMapping map[stri expectedBalance.Add(expectedBalance, extraBalances.SentAmount) } + fmt.Println("expectedBalance", expectedBalance.String()) + fmt.Println("actualBalance", actualBalance.String()) + fmt.Println("-----------------------------------------------") return actualBalance.String() == expectedBalance.String() } +func (setup *TestSetup) checkMvxAddressZeroBalanceForToken(params TestTokenParams) bool { + extraBalances := setup.getExtraBalanceForHolder("", params) + expectedBalance := big.NewInt(0).Set(extraBalances.ReceivedAmount) + + zeroAddressMvx := NewMvxAddressFromBytes(setup, bytes.Repeat([]byte{0x00}, 32)) + actualBalance := setup.MultiversxHandler.GetESDTUniversalTokenBalance(setup.Ctx, zeroAddressMvx, params.AbstractTokenIdentifier) + + fmt.Println("expectedBalance", expectedBalance.String()) + fmt.Println("actualBalance", actualBalance.String()) + return expectedBalance == actualBalance +} + +func (setup *TestSetup) getExtraBalanceForHolder(address string, params TestTokenParams) ExtraBalanceHolder { + setup.mutBalances.Lock() + defer setup.mutBalances.Unlock() + + holderName := AddressZero + if address != "" { + holderName = setup.AddressToName[address] + } + + return params.ExtraBalances[holderName] +} + func (setup *TestSetup) checkContractMvxBalanceForToken(params TestTokenParams) bool { mvxBalance := setup.MultiversxHandler.GetESDTUniversalTokenBalance(setup.Ctx, setup.MultiversxHandler.CalleeScAddress, params.AbstractTokenIdentifier) expectedValueOnContract := big.NewInt(0) @@ -322,6 +351,10 @@ func (setup *TestSetup) checkContractMvxBalanceForToken(params TestTokenParams) expectedValueOnContract.Add(expectedValueOnContract, operation.ValueToTransferToMvx) } + fmt.Println("---------------------CONTRACT--------------------------") + fmt.Println("expectedValueOnContract", expectedValueOnContract.String()) + fmt.Println("mvxBalance", mvxBalance.String()) + fmt.Println("-----------------------------------------------") return mvxBalance.String() == expectedValueOnContract.String() } @@ -358,6 +391,10 @@ func (setup *TestSetup) checkEthLockedBalanceForToken(params TestTokenParams, br expectedValue.Sub(expectedValue, setup.getMvxTotalRefundAmountForToken(params)) // unlock possible refund amount to be bridged back to Eth } + fmt.Println("----------------------ETH-------------------------") + fmt.Println("lockedTokens", lockedTokens.String()) + fmt.Println("expectedValue", expectedValue.String()) + fmt.Println("-----------------------------------------------") return lockedTokens.String() == expectedValue.String() } @@ -392,6 +429,10 @@ func (setup *TestSetup) checkMvxMintedBalanceForToken(params TestTokenParams) bo } } + fmt.Println("---------------------MVX--------------------------") + fmt.Println("mintedTokens", mintedTokens.String()) + fmt.Println("expectedValue", expectedValue.String()) + fmt.Println("-----------------------------------------------") return mintedTokens.String() == expectedValue.String() } @@ -401,6 +442,9 @@ func (setup *TestSetup) computeExpectedValueToMvx(params TestTokenParams) *big.I if operation.ValueToTransferToMvx == nil { continue } + if operation.IsFaultyDeposit { + continue + } expectedValue.Add(expectedValue, operation.ValueToTransferToMvx) } @@ -482,6 +526,10 @@ func (setup *TestSetup) isTransferDoneFromMultiversXForToken(sender, receiver Ke return false } + //if !setup.checkEthAddressZeroBalanceForToken(params) { + // return false + //} + if !setup.checkMvxBalanceForSafe(params) { return false } @@ -493,6 +541,16 @@ func (setup *TestSetup) isTransferDoneFromMultiversXForToken(sender, receiver Ke return setup.checkTokenOnEthSecondBridge(params) } +func (setup *TestSetup) checkEthAddressZeroBalanceForToken(params TestTokenParams) bool { + extraBalances := setup.getExtraBalanceForHolder("", params) + expectedBalance := big.NewInt(0).Set(extraBalances.SentAmount) + + zeroAddressEth := bytes.Repeat([]byte{0x00}, 20) + actualBalance := setup.EthereumHandler.GetBalance(common.Address(zeroAddressEth), params.AbstractTokenIdentifier) + + return expectedBalance == actualBalance +} + func (setup *TestSetup) checkMvxBalanceForSafe(params TestTokenParams) bool { setup.mutBalances.Lock() initialBalance := setup.esdtBalanceForSafe[params.AbstractTokenIdentifier] @@ -649,6 +707,11 @@ func (setup *TestSetup) createDepositOnMultiversxForToken(from KeysHolder, to Ke continue } + if operation.InvalidReceiver != nil { + badEthAddress := common.Address(bytes.Repeat([]byte{0x00}, 20)) + to = KeysHolder{EthAddress: badEthAddress} + } + depositValue.Add(depositValue, operation.ValueToSendFromMvX) setup.MultiversxHandler.SendDepositTransactionFromMultiversx(setup.Ctx, from, to, token, operation.ValueToSendFromMvX) } @@ -704,6 +767,12 @@ func (setup *TestSetup) createDepositOnEthereumForToken(from KeysHolder, to Keys continue } + if operation.InvalidReceiver != nil { + badMvxAddress := NewMvxAddressFromBytes(setup, operation.InvalidReceiver) + to = KeysHolder{MvxAddress: badMvxAddress} + fmt.Println("to", to.MvxAddress.AddressSlice()) + } + setup.EthereumHandler.SendDepositTransactionFromEthereum(setup.Ctx, from, to, targetSCAddress, token, operation) } } diff --git a/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go b/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go index e87cf497..4a510a77 100644 --- a/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go +++ b/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go @@ -1,5 +1,3 @@ -//go:build slow - // To run these slow tests, simply add the slow tag on the go test command. Also, provide a chain simulator instance on the 8085 port // example: go test -tags slow diff --git a/integrationTests/relayers/slowTests/startsFromEthereumFlow.go b/integrationTests/relayers/slowTests/startsFromEthereumFlow.go index 56f3080b..ba33f59a 100644 --- a/integrationTests/relayers/slowTests/startsFromEthereumFlow.go +++ b/integrationTests/relayers/slowTests/startsFromEthereumFlow.go @@ -1,5 +1,3 @@ -//go:build slow - package slowTests import ( diff --git a/integrationTests/relayers/slowTests/startsFromMultiversxFlow.go b/integrationTests/relayers/slowTests/startsFromMultiversxFlow.go index 5e877542..7e2c11f3 100644 --- a/integrationTests/relayers/slowTests/startsFromMultiversxFlow.go +++ b/integrationTests/relayers/slowTests/startsFromMultiversxFlow.go @@ -1,5 +1,3 @@ -//go:build slow - package slowTests import ( From 4308c261feb014902ae4aedb7e6aad3ec8648f4f Mon Sep 17 00:00:00 2001 From: cosmatudor Date: Wed, 27 Nov 2024 17:22:36 +0200 Subject: [PATCH 04/17] add checks for - deposits with less amount - bridges to address zero - deposits of non whitelisted tokens --- integrationTests/relayers/slowTests/common.go | 126 ++-- .../ethToMultiversXWithChainSimulator_test.go | 21 +- .../framework/chainSimulatorWrapper.go | 22 +- .../slowTests/framework/ethereumHandler.go | 4 + .../relayers/slowTests/framework/interface.go | 7 +- .../slowTests/framework/multiversxHandler.go | 591 ++++++++---------- .../relayers/slowTests/framework/testSetup.go | 157 +++-- .../relayers/slowTests/framework/types.go | 3 +- .../refundWithChainSimulator_test.go | 2 + .../slowTests/startsFromEthereumFlow.go | 17 + .../slowTests/startsFromMultiversxFlow.go | 4 +- 11 files changed, 496 insertions(+), 458 deletions(-) diff --git a/integrationTests/relayers/slowTests/common.go b/integrationTests/relayers/slowTests/common.go index cbd3258f..3991f622 100644 --- a/integrationTests/relayers/slowTests/common.go +++ b/integrationTests/relayers/slowTests/common.go @@ -1,3 +1,5 @@ +//go:build !slow + package slowTests import ( @@ -13,7 +15,6 @@ import ( var ( log = logger.GetOrCreate("integrationTests/relayers/slowTests") - ethZeroAddress = bytes.Repeat([]byte{0x00}, 20) mvxZeroAddress = bytes.Repeat([]byte{0x00}, 32) ) @@ -69,6 +70,7 @@ func GenerateTestUSDCToken() framework.TestTokenParams { framework.Alice: { SentAmount: big.NewInt(-5000 - 7000 - 1000 - 900), ReceivedAmount: big.NewInt(0), + RefundAmount: big.NewInt(900 - 50), }, framework.Bob: { SentAmount: big.NewInt(-2500 - 300), @@ -78,10 +80,6 @@ func GenerateTestUSDCToken() framework.TestTokenParams { SentAmount: big.NewInt(0), ReceivedAmount: big.NewInt(2500 - 50 + 300 - 50), }, - framework.AddressZero: { - SentAmount: big.NewInt(0), - ReceivedAmount: big.NewInt(900), - }, }, } } @@ -122,16 +120,12 @@ func GenerateTestMEMEToken() framework.TestTokenParams { ValueToSendFromMvX: big.NewInt(2000), MvxSCCallData: createScCallData("callPayable", 50000000), }, - //{ - // ValueToTransferToMvx: nil, - // ValueToSendFromMvX: big.NewInt(38), - // IsFaultyDeposit: true, - //}, { ValueToTransferToMvx: nil, - ValueToSendFromMvX: big.NewInt(650), - InvalidReceiver: ethZeroAddress, + ValueToSendFromMvX: big.NewInt(38), + IsFaultyDeposit: true, }, + // TODO: add a test where the receiver is the zero address }, ESDTSafeExtraBalance: big.NewInt(4000 + 6000 + 2000), // everything is locked in the safe esdt contract ExtraBalances: map[string]framework.ExtraBalanceHolder{ @@ -142,15 +136,12 @@ func GenerateTestMEMEToken() framework.TestTokenParams { framework.Bob: { SentAmount: big.NewInt(-2400 - 200 - 1000), ReceivedAmount: big.NewInt(4000 - 50 + 6000 - 50 + 2000 - 50), + RefundAmount: big.NewInt(1000 - 50), }, framework.Charlie: { SentAmount: big.NewInt(0), ReceivedAmount: big.NewInt(2400 + 200), }, - framework.AddressZero: { - SentAmount: big.NewInt(0), - ReceivedAmount: big.NewInt(650), - }, }, } } @@ -192,7 +183,7 @@ func GenerateTestEUROCToken() framework.TestTokenParams { MvxSCCallData: createScCallData("callPayable", 50000000), }, { - ValueToTransferToMvx: big.NewInt(49), + ValueToTransferToMvx: big.NewInt(24), ValueToSendFromMvX: nil, IsFaultyDeposit: true, }, @@ -200,14 +191,14 @@ func GenerateTestEUROCToken() framework.TestTokenParams { ValueToTransferToMvx: big.NewInt(700), ValueToSendFromMvX: nil, InvalidReceiver: mvxZeroAddress, - IsFaultyDeposit: true, }, }, 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), + SentAmount: big.NewInt(-5010 - 7010 - 1010 - 700), ReceivedAmount: big.NewInt(0), + RefundAmount: big.NewInt(700 - 50), }, framework.Bob: { SentAmount: big.NewInt(-2510 - 310), @@ -217,15 +208,11 @@ func GenerateTestEUROCToken() framework.TestTokenParams { SentAmount: big.NewInt(0), ReceivedAmount: big.NewInt(2510 - 50 + 310 - 50), }, - framework.AddressZero: { - SentAmount: big.NewInt(0), - ReceivedAmount: big.NewInt(700), - }, }, } } -// GenerateTestMEXToken will generate a test EUROC token +// GenerateTestMEXToken will generate a test MEX token func GenerateTestMEXToken() framework.TestTokenParams { //MEX is ethNative = false, ethMintBurn = true, mvxNative = true, mvxMintBurn = true return framework.TestTokenParams{ @@ -261,37 +248,106 @@ func GenerateTestMEXToken() framework.TestTokenParams { ValueToSendFromMvX: big.NewInt(2010), MvxSCCallData: createScCallData("callPayable", 50000000), }, - //{ - // ValueToTransferToMvx: big.NewInt(10), - // ValueToSendFromMvX: nil, - // IsFaultyDeposit: true, - //}, { - ValueToTransferToMvx: nil, - ValueToSendFromMvX: big.NewInt(800), - InvalidReceiver: ethZeroAddress, + ValueToTransferToMvx: big.NewInt(10), + ValueToSendFromMvX: nil, IsFaultyDeposit: true, }, + // TODO: add a test where the receiver is the zero address }, 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), + RefundAmount: big.NewInt(0), }, framework.Bob: { SentAmount: big.NewInt(-2410 - 210 - 1010), ReceivedAmount: big.NewInt(4010 - 50 + 6010 - 50 + 2010 - 50), + RefundAmount: big.NewInt(1010 - 50), }, framework.Charlie: { SentAmount: big.NewInt(0), ReceivedAmount: big.NewInt(2410 + 210), }, - framework.AddressZero: { - SentAmount: big.NewInt(0), - ReceivedAmount: big.NewInt(800), + }, + } +} + +// GenerateTestDOGEToken will generate a test DOGE token +func GenerateTestDOGEToken() framework.TestTokenParams { + return framework.TestTokenParams{ + IssueTokenParams: framework.IssueTokenParams{ + AbstractTokenIdentifier: "DOGE", + NumOfDecimalsUniversal: 6, + NumOfDecimalsChainSpecific: 6, + MvxUniversalTokenTicker: "DOGE", + MvxChainSpecificTokenTicker: "DOGE", + MvxUniversalTokenDisplayName: "TestDOGE", + MvxChainSpecificTokenDisplayName: "TestDOGE", + ValueToMintOnMvx: "10000000000", + IsMintBurnOnMvX: true, + IsNativeOnMvX: false, + HasChainSpecificToken: false, + EthTokenName: "EthDOGE", + EthTokenSymbol: "DOGE", + ValueToMintOnEth: "10000000000", + IsMintBurnOnEth: true, + IsNativeOnEth: true, + PreventWhitelist: true, + }, + TestOperations: []framework.TokenOperations{ + { + ValueToTransferToMvx: big.NewInt(5010), + ValueToSendFromMvX: nil, + IsFaultyDeposit: true, + }, + { + ValueToTransferToMvx: big.NewInt(1010), + ValueToSendFromMvX: nil, + MvxSCCallData: createScCallData("callPayable", 50000000), + IsFaultyDeposit: true, }, }, + ESDTSafeExtraBalance: big.NewInt(100), // extra is just for the fees for the 2 transfers mvx->eth + } +} + +// GenerateTestBOBERToken will generate a test BOBER token +func GenerateTestBOBERToken() framework.TestTokenParams { + return framework.TestTokenParams{ + IssueTokenParams: framework.IssueTokenParams{ + AbstractTokenIdentifier: "BOBER", + NumOfDecimalsUniversal: 2, + NumOfDecimalsChainSpecific: 2, + MvxUniversalTokenTicker: "BOBER", + MvxChainSpecificTokenTicker: "BOBER", + MvxUniversalTokenDisplayName: "TestBOBER", + MvxChainSpecificTokenDisplayName: "TestBOBER", + ValueToMintOnMvx: "10000000000", + IsMintBurnOnMvX: true, + IsNativeOnMvX: true, + HasChainSpecificToken: false, + EthTokenName: "EthBOBER", + EthTokenSymbol: "BOBER", + ValueToMintOnEth: "10000000000", + IsMintBurnOnEth: true, + IsNativeOnEth: false, + PreventWhitelist: true, + }, + TestOperations: []framework.TokenOperations{ + { + ValueToTransferToMvx: nil, + ValueToSendFromMvX: big.NewInt(4010), + }, + { + ValueToTransferToMvx: nil, + ValueToSendFromMvX: big.NewInt(2010), + MvxSCCallData: createScCallData("callPayable", 50000000), + }, + }, + ESDTSafeExtraBalance: big.NewInt(150), // just the fees should be collected in ESDT safe } } diff --git a/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go b/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go index ffc9815d..cd09c96b 100644 --- a/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go +++ b/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go @@ -1,3 +1,5 @@ +//go:build !slow + // To run these slow tests, simply add the slow tag on the go test command. Also, provide a chain simulator instance on the 8085 port // example: go test -tags slow @@ -33,7 +35,7 @@ func TestRelayersShouldExecuteTransfers(t *testing.T) { t, make(chan error), GenerateTestUSDCToken(), - //GenerateTestMEMEToken(), + GenerateTestMEMEToken(), ) } @@ -46,6 +48,15 @@ func TestRelayersShouldExecuteTransfersWithMintBurnTokens(t *testing.T) { ) } +func TestRelayersShouldNotExecuteTransfersWithNonWhitelistedTokens(t *testing.T) { + _ = testRelayersWithChainSimulatorAndTokens( + t, + make(chan error), + GenerateTestDOGEToken(), + GenerateTestBOBERToken(), + ) +} + func TestRelayersShouldExecuteTransfersWithSCCallsWithArguments(t *testing.T) { dummyAddress := strings.Repeat("2", 32) dummyUint64 := string([]byte{37}) @@ -180,7 +191,7 @@ func testRelayersWithChainSimulatorAndTokens(tb testing.TB, manualStopChan chan } processFunc := func(tb testing.TB, setup *framework.TestSetup) bool { - if startsFromEthFlow.process() && startsFromMvXFlow.process() { + if startsFromEthFlow.process() && startsFromMvXFlow.process() && startsFromEthFlow.areTokensFullyRefunded() { setup.TestWithdrawTotalFeesOnEthereumForTokens(startsFromMvXFlow.tokens...) setup.TestWithdrawTotalFeesOnEthereumForTokens(startsFromEthFlow.tokens...) @@ -302,9 +313,9 @@ func createBadToken() framework.TestTokenParams { }, 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)}, + "Alice": {big.NewInt(-5000 - 7000 - 1000), big.NewInt(0), big.NewInt(0)}, + "Bob": {big.NewInt(-2500 - 300), big.NewInt(5000 + 7000), big.NewInt(0)}, + "Charlie": {big.NewInt(0), big.NewInt(2500 - 50 + 300 - 50), big.NewInt(0)}, }, } } diff --git a/integrationTests/relayers/slowTests/framework/chainSimulatorWrapper.go b/integrationTests/relayers/slowTests/framework/chainSimulatorWrapper.go index 49bb6633..0c1983a8 100644 --- a/integrationTests/relayers/slowTests/framework/chainSimulatorWrapper.go +++ b/integrationTests/relayers/slowTests/framework/chainSimulatorWrapper.go @@ -146,13 +146,17 @@ func (instance *chainSimulatorWrapper) DeploySC(ctx context.Context, wasmFilePat } hash := instance.signAndSend(ctx, ownerSK, ftx, 1) - txResult := instance.GetTransactionResult(ctx, hash) + txResult, txStatus := instance.GetTransactionResult(ctx, hash) + + jsonData, err := json.MarshalIndent(txResult, "", " ") + require.Nil(instance, err) + require.Equal(instance, transaction.TxStatusSuccess, txStatus, fmt.Sprintf("tx hash: %s,\n tx: %s", hash, string(jsonData))) return NewMvxAddressFromBech32(instance.TB, txResult.Logs.Events[0].Address), hash, txResult } // GetTransactionResult tries to get a transaction result. It may wait a few blocks -func (instance *chainSimulatorWrapper) GetTransactionResult(ctx context.Context, hash string) *data.TransactionOnNetwork { +func (instance *chainSimulatorWrapper) GetTransactionResult(ctx context.Context, hash string) (*data.TransactionOnNetwork, transaction.TxStatus) { instance.GenerateBlocksUntilTxProcessed(ctx, hash) txResult, err := instance.proxyInstance.GetTransactionInfoWithResults(ctx, hash) @@ -161,11 +165,7 @@ func (instance *chainSimulatorWrapper) GetTransactionResult(ctx context.Context, txStatus, err := instance.proxyInstance.ProcessTransactionStatus(ctx, hash) require.Nil(instance, err) - jsonData, err := json.MarshalIndent(txResult.Data.Transaction, "", " ") - require.Nil(instance, err) - require.Equal(instance, transaction.TxStatusSuccess, txStatus, fmt.Sprintf("tx hash: %s,\n tx: %s", hash, string(jsonData))) - - return &txResult.Data.Transaction + return &txResult.Data.Transaction, txStatus } // GenerateBlocks calls the chain simulator generate block endpoint @@ -200,7 +200,7 @@ func (instance *chainSimulatorWrapper) GenerateBlocksUntilTxProcessed(ctx contex } // ScCall will make the provided sc call -func (instance *chainSimulatorWrapper) ScCall(ctx context.Context, senderSK []byte, contract *MvxAddress, value string, gasLimit uint64, function string, parameters []string) (string, *data.TransactionOnNetwork) { +func (instance *chainSimulatorWrapper) ScCall(ctx context.Context, senderSK []byte, contract *MvxAddress, value string, gasLimit uint64, function string, parameters []string) (string, *data.TransactionOnNetwork, transaction.TxStatus) { return instance.SendTx(ctx, senderSK, contract, value, gasLimit, createTxData(function, parameters)) } @@ -218,12 +218,12 @@ func createTxData(function string, parameters []string) []byte { } // SendTx will build and send a transaction -func (instance *chainSimulatorWrapper) SendTx(ctx context.Context, senderSK []byte, receiver *MvxAddress, value string, gasLimit uint64, dataField []byte) (string, *data.TransactionOnNetwork) { +func (instance *chainSimulatorWrapper) SendTx(ctx context.Context, senderSK []byte, receiver *MvxAddress, value string, gasLimit uint64, dataField []byte) (string, *data.TransactionOnNetwork, transaction.TxStatus) { hash := instance.SendTxWithoutGenerateBlocks(ctx, senderSK, receiver, value, gasLimit, dataField) instance.GenerateBlocks(ctx, 1) - txResult := instance.GetTransactionResult(ctx, hash) + txResult, txStatus := instance.GetTransactionResult(ctx, hash) - return hash, txResult + return hash, txResult, txStatus } // SendTxWithoutGenerateBlocks will build and send a transaction and won't call the generate blocks command diff --git a/integrationTests/relayers/slowTests/framework/ethereumHandler.go b/integrationTests/relayers/slowTests/framework/ethereumHandler.go index fbbcb124..50e75b54 100644 --- a/integrationTests/relayers/slowTests/framework/ethereumHandler.go +++ b/integrationTests/relayers/slowTests/framework/ethereumHandler.go @@ -259,6 +259,10 @@ func (handler *EthereumHandler) IssueAndWhitelistToken(ctx context.Context, para handler.TokensRegistry.RegisterEthAddressAndContract(params.AbstractTokenIdentifier, erc20Address, erc20ContractInstance) + if params.PreventWhitelist { + return + } + // whitelist eth token auth, _ := bind.NewKeyedTransactorWithChainID(handler.OwnerKeys.EthSK, handler.ChainID) tx, err := handler.SafeContract.WhitelistToken( diff --git a/integrationTests/relayers/slowTests/framework/interface.go b/integrationTests/relayers/slowTests/framework/interface.go index 7b5e9db6..790063fe 100644 --- a/integrationTests/relayers/slowTests/framework/interface.go +++ b/integrationTests/relayers/slowTests/framework/interface.go @@ -9,6 +9,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/multiversx/mx-bridge-eth-go/clients/multiversx" + "github.com/multiversx/mx-chain-core-go/data/transaction" sdkCore "github.com/multiversx/mx-sdk-go/core" "github.com/multiversx/mx-sdk-go/data" ) @@ -32,16 +33,16 @@ type ChainSimulatorWrapper interface { Proxy() multiversx.Proxy GetNetworkAddress() string DeploySC(ctx context.Context, path string, ownerSK []byte, gasLimit uint64, extraParams []string) (*MvxAddress, string, *data.TransactionOnNetwork) - ScCall(ctx context.Context, senderSK []byte, contract *MvxAddress, value string, gasLimit uint64, function string, parameters []string) (string, *data.TransactionOnNetwork) + ScCall(ctx context.Context, senderSK []byte, contract *MvxAddress, value string, gasLimit uint64, function string, parameters []string) (string, *data.TransactionOnNetwork, transaction.TxStatus) ScCallWithoutGenerateBlocks(ctx context.Context, senderSK []byte, contract *MvxAddress, value string, gasLimit uint64, function string, parameters []string) string - SendTx(ctx context.Context, senderSK []byte, receiver *MvxAddress, value string, gasLimit uint64, dataField []byte) (string, *data.TransactionOnNetwork) + SendTx(ctx context.Context, senderSK []byte, receiver *MvxAddress, value string, gasLimit uint64, dataField []byte) (string, *data.TransactionOnNetwork, transaction.TxStatus) SendTxWithoutGenerateBlocks(ctx context.Context, senderSK []byte, receiver *MvxAddress, value string, gasLimit uint64, dataField []byte) string FundWallets(ctx context.Context, wallets []string) GenerateBlocksUntilEpochReached(ctx context.Context, epoch uint32) GenerateBlocks(ctx context.Context, numBlocks int) GetESDTBalance(ctx context.Context, address *MvxAddress, token string) string GetBlockchainTimeStamp(ctx context.Context) uint64 - GetTransactionResult(ctx context.Context, hash string) *data.TransactionOnNetwork + GetTransactionResult(ctx context.Context, hash string) (*data.TransactionOnNetwork, transaction.TxStatus) ExecuteVMQuery(ctx context.Context, scAddress *MvxAddress, function string, hexParams []string) [][]byte } diff --git a/integrationTests/relayers/slowTests/framework/multiversxHandler.go b/integrationTests/relayers/slowTests/framework/multiversxHandler.go index 580bec33..8eb8c14c 100644 --- a/integrationTests/relayers/slowTests/framework/multiversxHandler.go +++ b/integrationTests/relayers/slowTests/framework/multiversxHandler.go @@ -3,11 +3,13 @@ package framework import ( "context" "encoding/hex" + "encoding/json" "fmt" "math/big" "strings" "testing" + "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-sdk-go/data" "github.com/stretchr/testify/require" ) @@ -48,6 +50,8 @@ const ( setEsdtSafeOnMultiTransferFunction = "setEsdtSafeOnMultiTransfer" setEsdtSafeOnWrapperFunction = "setEsdtSafeContractAddress" setEsdtSafeAddressFunction = "setEsdtSafeAddress" + moveRefundBatchToSafeFromChildContractFunction = "moveRefundBatchToSafeFromChildContract" + getCurrentRefundBatchFunction = "getCurrentRefundBatch" stakeFunction = "stake" unpauseFunction = "unpause" unpauseEsdtSafeFunction = "unpauseEsdtSafe" @@ -255,165 +259,99 @@ func (handler *MultiversxHandler) deployContracts(ctx context.Context) { func (handler *MultiversxHandler) wireMultiTransfer(ctx context.Context) { // setBridgeProxyContractAddress - hash, txResult := handler.ChainSimulator.ScCall( - ctx, - handler.OwnerKeys.MvxSk, - handler.MultiTransferAddress, - zeroStringValue, - setCallsGasLimit, - setBridgeProxyContractAddressFunction, - []string{ - handler.ScProxyAddress.Hex(), - }, - ) + params := []string{ + handler.ScProxyAddress.Hex(), + } + hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.MultiTransferAddress, zeroStringValue, setCallsGasLimit, setBridgeProxyContractAddressFunction, params) + log.Info("Set in multi-transfer contract the SC proxy contract", "transaction hash", hash, "status", txResult.Status) // setWrappingContractAddress - hash, txResult = handler.ChainSimulator.ScCall( - ctx, - handler.OwnerKeys.MvxSk, - handler.MultiTransferAddress, - zeroStringValue, - setCallsGasLimit, - setWrappingContractAddressFunction, - []string{ - handler.WrapperAddress.Hex(), - }, - ) + params = []string{ + handler.WrapperAddress.Hex(), + } + hash, txResult = handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.MultiTransferAddress, zeroStringValue, setCallsGasLimit, setWrappingContractAddressFunction, params) + log.Info("Set in multi-transfer contract the wrapper contract", "transaction hash", hash, "status", txResult.Status) } func (handler *MultiversxHandler) wireSCProxy(ctx context.Context) { // setBridgedTokensWrapper in SC bridge proxy - hash, txResult := handler.ChainSimulator.ScCall( - ctx, - handler.OwnerKeys.MvxSk, - handler.ScProxyAddress, - zeroStringValue, - setCallsGasLimit, - setBridgedTokensWrapperAddressFunction, - []string{ - handler.WrapperAddress.Hex(), - }, - ) + params := []string{ + handler.WrapperAddress.Hex(), + } + hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.ScProxyAddress, zeroStringValue, setCallsGasLimit, setBridgedTokensWrapperAddressFunction, params) + log.Info("Set in SC proxy contract the wrapper contract", "transaction hash", hash, "status", txResult.Status) // setMultiTransferAddress in SC bridge proxy - hash, txResult = handler.ChainSimulator.ScCall( - ctx, - handler.OwnerKeys.MvxSk, - handler.ScProxyAddress, - zeroStringValue, - setCallsGasLimit, - setMultiTransferAddressFunction, - []string{ - handler.MultiTransferAddress.Hex(), - }, - ) + params = []string{ + handler.MultiTransferAddress.Hex(), + } + hash, txResult = handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.ScProxyAddress, zeroStringValue, setCallsGasLimit, setMultiTransferAddressFunction, params) + log.Info("Set in SC proxy contract the multi-transfer contract", "transaction hash", hash, "status", txResult.Status) // setEsdtSafeAddress on bridge proxy - hash, txResult = handler.ChainSimulator.ScCall( - ctx, - handler.OwnerKeys.MvxSk, - handler.ScProxyAddress, - zeroStringValue, - setCallsGasLimit, - setEsdtSafeAddressFunction, - []string{ - handler.SafeAddress.Hex(), - }, - ) + params = []string{ + handler.SafeAddress.Hex(), + } + hash, txResult = handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.ScProxyAddress, zeroStringValue, setCallsGasLimit, setEsdtSafeAddressFunction, params) + log.Info("Set in SC proxy contract the safe contract", "transaction hash", hash, "status", txResult.Status) } func (handler *MultiversxHandler) wireWrapper(ctx context.Context) { // setEsdtSafeOnWrapper - hash, txResult := handler.ChainSimulator.ScCall( - ctx, - handler.OwnerKeys.MvxSk, - handler.WrapperAddress, - zeroStringValue, - setCallsGasLimit, - setEsdtSafeOnWrapperFunction, - []string{ - handler.SafeAddress.Hex(), - }, - ) + params := []string{ + handler.SafeAddress.Hex(), + } + hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.WrapperAddress, zeroStringValue, setCallsGasLimit, setEsdtSafeOnWrapperFunction, params) + log.Info("Set in wrapper contract the safe contract", "transaction hash", hash, "status", txResult.Status) } func (handler *MultiversxHandler) wireSafe(ctx context.Context) { // setBridgedTokensWrapperAddress - hash, txResult := handler.ChainSimulator.ScCall( - ctx, - handler.OwnerKeys.MvxSk, - handler.SafeAddress, - zeroStringValue, - setCallsGasLimit, - setBridgedTokensWrapperAddressFunction, - []string{ - handler.WrapperAddress.Hex(), - }, - ) + params := []string{ + handler.WrapperAddress.Hex(), + } + hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.SafeAddress, zeroStringValue, setCallsGasLimit, setBridgedTokensWrapperAddressFunction, params) + log.Info("Set in safe contract the wrapper contract", "transaction hash", hash, "status", txResult.Status) //setBridgeProxyContractAddress - hash, txResult = handler.ChainSimulator.ScCall( - ctx, - handler.OwnerKeys.MvxSk, - handler.SafeAddress, - zeroStringValue, - setCallsGasLimit, - setBridgeProxyContractAddressFunction, - []string{ - handler.ScProxyAddress.Hex(), - }, - ) + params = []string{ + handler.ScProxyAddress.Hex(), + } + hash, txResult = handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.SafeAddress, zeroStringValue, setCallsGasLimit, setBridgeProxyContractAddressFunction, params) + log.Info("Set in safe contract the SC proxy contract", "transaction hash", hash, "status", txResult.Status) } func (handler *MultiversxHandler) changeOwners(ctx context.Context) { // ChangeOwnerAddress for safe - hash, txResult := handler.ChainSimulator.ScCall( - ctx, - handler.OwnerKeys.MvxSk, - handler.SafeAddress, - zeroStringValue, - setCallsGasLimit, - changeOwnerAddressFunction, - []string{ - handler.MultisigAddress.Hex(), - }, - ) + params := []string{ + handler.MultisigAddress.Hex(), + } + hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.SafeAddress, zeroStringValue, setCallsGasLimit, changeOwnerAddressFunction, params) + log.Info("ChangeOwnerAddress for safe contract", "transaction hash", hash, "status", txResult.Status) // ChangeOwnerAddress for multi-transfer - hash, txResult = handler.ChainSimulator.ScCall( - ctx, - handler.OwnerKeys.MvxSk, - handler.MultiTransferAddress, - zeroStringValue, - setCallsGasLimit, - changeOwnerAddressFunction, - []string{ - handler.MultisigAddress.Hex(), - }, - ) + params = []string{ + handler.MultisigAddress.Hex(), + } + hash, txResult = handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.MultiTransferAddress, zeroStringValue, setCallsGasLimit, changeOwnerAddressFunction, params) + log.Info("ChangeOwnerAddress for multi-transfer contract", "transaction hash", hash, "status", txResult.Status) // ChangeOwnerAddress for bridge proxy - hash, txResult = handler.ChainSimulator.ScCall( - ctx, - handler.OwnerKeys.MvxSk, - handler.ScProxyAddress, - zeroStringValue, - setCallsGasLimit, - changeOwnerAddressFunction, - []string{ - handler.MultisigAddress.Hex(), - }, - ) + params = []string{ + handler.MultisigAddress.Hex(), + } + hash, txResult = handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.ScProxyAddress, zeroStringValue, setCallsGasLimit, changeOwnerAddressFunction, params) + log.Info("ChangeOwnerAddress for SC proxy contract", "transaction hash", hash, "status", txResult.Status) } @@ -423,15 +361,8 @@ func (handler *MultiversxHandler) finishSettings(ctx context.Context) { log.Info("Un-paused SC proxy contract", "transaction hash", hash, "status", txResult.Status) // setEsdtSafeOnMultiTransfer - hash, txResult = handler.ChainSimulator.ScCall( - ctx, - handler.OwnerKeys.MvxSk, - handler.MultisigAddress, - zeroStringValue, - setCallsGasLimit, - setEsdtSafeOnMultiTransferFunction, - []string{}, - ) + hash, txResult = handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.MultisigAddress, zeroStringValue, setCallsGasLimit, setEsdtSafeOnMultiTransferFunction, []string{}) + log.Info("Set in multisig contract the safe contract (automatically)", "transaction hash", hash, "status", txResult.Status) // stake relayers on multisig @@ -498,15 +429,7 @@ func (handler *MultiversxHandler) GetESDTChainSpecificTokenBalance( } func (handler *MultiversxHandler) callContractNoParams(ctx context.Context, contract *MvxAddress, endpoint string) (string, *data.TransactionOnNetwork) { - return handler.ChainSimulator.ScCall( - ctx, - handler.OwnerKeys.MvxSk, - contract, - zeroStringValue, - setCallsGasLimit, - endpoint, - []string{}, - ) + return handler.sendAndCheckTx(ctx, handler.OwnerKeys, contract, zeroStringValue, setCallsGasLimit, endpoint, []string{}) } // UnPauseContractsAfterTokenChanges can unpause contracts after token changes @@ -541,7 +464,7 @@ func (handler *MultiversxHandler) PauseContractsForTokenChanges(ctx context.Cont func (handler *MultiversxHandler) stakeAddressesOnContract(ctx context.Context, contract *MvxAddress, allKeys []KeysHolder) { for _, keys := range allKeys { - hash, txResult := handler.ChainSimulator.SendTx( + hash, txResult, _ := handler.ChainSimulator.SendTx( ctx, keys.MvxSk, contract, @@ -568,10 +491,12 @@ func (handler *MultiversxHandler) issueAndWhitelistTokensWithChainSpecific(ctx c handler.setLocalRolesForUniversalTokenOnWrapper(ctx, params) handler.transferChainSpecificTokenToSCs(ctx, params) handler.addUniversalTokenToWrapper(ctx, params) - handler.whitelistTokenOnWrapper(ctx, params) + if !params.PreventWhitelist { + handler.whitelistTokenOnMultisig(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) @@ -586,7 +511,9 @@ func (handler *MultiversxHandler) issueAndWhitelistTokens(ctx context.Context, p handler.setRolesForSpecificTokenOnSafe(ctx, params) handler.addMappingInMultisig(ctx, params) - handler.whitelistTokenOnMultisig(ctx, params) + if !params.PreventWhitelist { + handler.whitelistTokenOnMultisig(ctx, params) + } handler.setInitialSupply(ctx, params) handler.setPairDecimalsOnAggregator(ctx, params) handler.setMaxBridgeAmountOnSafe(ctx, params) @@ -601,20 +528,15 @@ func (handler *MultiversxHandler) issueUniversalToken(ctx context.Context, param require.True(handler, ok) // issue universal token - hash, txResult := handler.ChainSimulator.ScCall( - ctx, - handler.OwnerKeys.MvxSk, - handler.ESDTSystemContractAddress, - esdtIssueCost, - issueTokenGasLimit, - issueFunction, - []string{ - hex.EncodeToString([]byte(params.MvxUniversalTokenDisplayName)), - hex.EncodeToString([]byte(params.MvxUniversalTokenTicker)), - hex.EncodeToString(valueToMintInt.Bytes()), - fmt.Sprintf("%02x", params.NumOfDecimalsUniversal), - hex.EncodeToString([]byte(canAddSpecialRoles)), - hex.EncodeToString([]byte(trueStr))}) + scCallParams := []string{ + hex.EncodeToString([]byte(params.MvxUniversalTokenDisplayName)), + hex.EncodeToString([]byte(params.MvxUniversalTokenTicker)), + hex.EncodeToString(valueToMintInt.Bytes()), + fmt.Sprintf("%02x", params.NumOfDecimalsUniversal), + hex.EncodeToString([]byte(canAddSpecialRoles)), + hex.EncodeToString([]byte(trueStr))} + + hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.ESDTSystemContractAddress, esdtIssueCost, issueTokenGasLimit, issueFunction, scCallParams) mvxUniversalToken := handler.getTokenNameFromResult(*txResult) require.Greater(handler, len(mvxUniversalToken), 0) handler.TokensRegistry.RegisterUniversalToken(params.AbstractTokenIdentifier, mvxUniversalToken) @@ -625,20 +547,15 @@ func (handler *MultiversxHandler) issueChainSpecificToken(ctx context.Context, p valueToMintInt, ok := big.NewInt(0).SetString(params.ValueToMintOnMvx, 10) require.True(handler, ok) - hash, txResult := handler.ChainSimulator.ScCall( - ctx, - handler.OwnerKeys.MvxSk, - handler.ESDTSystemContractAddress, - esdtIssueCost, - issueTokenGasLimit, - issueFunction, - []string{ - hex.EncodeToString([]byte(params.MvxChainSpecificTokenDisplayName)), - hex.EncodeToString([]byte(params.MvxChainSpecificTokenTicker)), - hex.EncodeToString(valueToMintInt.Bytes()), - fmt.Sprintf("%02x", params.NumOfDecimalsChainSpecific), - hex.EncodeToString([]byte(canAddSpecialRoles)), - hex.EncodeToString([]byte(trueStr))}) + scCallParams := []string{ + hex.EncodeToString([]byte(params.MvxChainSpecificTokenDisplayName)), + hex.EncodeToString([]byte(params.MvxChainSpecificTokenTicker)), + hex.EncodeToString(valueToMintInt.Bytes()), + fmt.Sprintf("%02x", params.NumOfDecimalsChainSpecific), + hex.EncodeToString([]byte(canAddSpecialRoles)), + hex.EncodeToString([]byte(trueStr))} + + hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.ESDTSystemContractAddress, esdtIssueCost, issueTokenGasLimit, issueFunction, scCallParams) mvxChainSpecificToken := handler.getTokenNameFromResult(*txResult) require.Greater(handler, len(mvxChainSpecificToken), 0) handler.TokensRegistry.RegisterChainSpecificToken(params.AbstractTokenIdentifier, mvxChainSpecificToken) @@ -649,18 +566,14 @@ func (handler *MultiversxHandler) setLocalRolesForUniversalTokenOnWrapper(ctx co tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) // set local roles bridged tokens wrapper - hash, txResult := handler.ChainSimulator.ScCall( - ctx, - handler.OwnerKeys.MvxSk, - handler.ESDTSystemContractAddress, - zeroStringValue, - setCallsGasLimit, - setSpecialRoleFunction, - []string{ - hex.EncodeToString([]byte(tkData.MvxUniversalToken)), - handler.WrapperAddress.Hex(), - hex.EncodeToString([]byte(esdtRoleLocalMint)), - hex.EncodeToString([]byte(esdtRoleLocalBurn))}) + scCallParams := []string{ + hex.EncodeToString([]byte(tkData.MvxUniversalToken)), + handler.WrapperAddress.Hex(), + hex.EncodeToString([]byte(esdtRoleLocalMint)), + hex.EncodeToString([]byte(esdtRoleLocalBurn))} + + hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.ESDTSystemContractAddress, zeroStringValue, setCallsGasLimit, setSpecialRoleFunction, scCallParams) + log.Info("set local roles bridged tokens wrapper tx executed", "hash", hash, "status", txResult.Status) } @@ -672,30 +585,22 @@ func (handler *MultiversxHandler) transferChainSpecificTokenToSCs(ctx context.Co // transfer to wrapper sc initialMintValue := valueToMintInt.Div(valueToMintInt, big.NewInt(3)) - hash, txResult := handler.ChainSimulator.ScCall( - ctx, - handler.OwnerKeys.MvxSk, - handler.WrapperAddress, - zeroStringValue, - setCallsGasLimit, - esdtTransferFunction, - []string{ - hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), - hex.EncodeToString(initialMintValue.Bytes()), - hex.EncodeToString([]byte(depositLiquidityFunction))}) + scCallParams := []string{ + hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), + hex.EncodeToString(initialMintValue.Bytes()), + hex.EncodeToString([]byte(depositLiquidityFunction))} + + hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.WrapperAddress, zeroStringValue, setCallsGasLimit, esdtTransferFunction, scCallParams) + log.Info("transfer to wrapper sc tx executed", "hash", hash, "status", txResult.Status) // transfer to safe sc - hash, txResult = handler.ChainSimulator.ScCall( - ctx, - handler.OwnerKeys.MvxSk, - handler.SafeAddress, - zeroStringValue, - setCallsGasLimit, - esdtTransferFunction, - []string{ - hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), - hex.EncodeToString(initialMintValue.Bytes())}) + scCallParams = []string{ + hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), + hex.EncodeToString(initialMintValue.Bytes())} + + hash, txResult = handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.SafeAddress, zeroStringValue, setCallsGasLimit, esdtTransferFunction, scCallParams) + log.Info("transfer to safe sc tx executed", "hash", hash, "status", txResult.Status) } @@ -703,17 +608,13 @@ func (handler *MultiversxHandler) addUniversalTokenToWrapper(ctx context.Context tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) // add wrapped token - hash, txResult := handler.ChainSimulator.ScCall( - ctx, - handler.OwnerKeys.MvxSk, - handler.WrapperAddress, - zeroStringValue, - setCallsGasLimit, - addWrappedTokenFunction, - []string{ - hex.EncodeToString([]byte(tkData.MvxUniversalToken)), - fmt.Sprintf("%02x", params.NumOfDecimalsUniversal), - }) + scCallParams := []string{ + hex.EncodeToString([]byte(tkData.MvxUniversalToken)), + fmt.Sprintf("%02x", params.NumOfDecimalsUniversal), + } + + hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.WrapperAddress, zeroStringValue, setCallsGasLimit, addWrappedTokenFunction, scCallParams) + log.Info("add wrapped token tx executed", "hash", hash, "status", txResult.Status) } @@ -721,17 +622,13 @@ func (handler *MultiversxHandler) whitelistTokenOnWrapper(ctx context.Context, p tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) // wrapper whitelist token - hash, txResult := handler.ChainSimulator.ScCall( - ctx, - handler.OwnerKeys.MvxSk, - handler.WrapperAddress, - zeroStringValue, - setCallsGasLimit, - whitelistTokenFunction, - []string{ - hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), - fmt.Sprintf("%02x", params.NumOfDecimalsChainSpecific), - hex.EncodeToString([]byte(tkData.MvxUniversalToken))}) + scCallParams := []string{ + hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), + fmt.Sprintf("%02x", params.NumOfDecimalsChainSpecific), + hex.EncodeToString([]byte(tkData.MvxUniversalToken))} + + hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.WrapperAddress, zeroStringValue, setCallsGasLimit, whitelistTokenFunction, scCallParams) + log.Info("wrapper whitelist token tx executed", "hash", hash, "status", txResult.Status) } @@ -739,18 +636,14 @@ func (handler *MultiversxHandler) setRolesForSpecificTokenOnSafe(ctx context.Con tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) // set local roles esdt safe - hash, txResult := handler.ChainSimulator.ScCall( - ctx, - handler.OwnerKeys.MvxSk, - handler.ESDTSystemContractAddress, - zeroStringValue, - setCallsGasLimit, - setSpecialRoleFunction, - []string{ - hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), - handler.SafeAddress.Hex(), - hex.EncodeToString([]byte(esdtRoleLocalMint)), - hex.EncodeToString([]byte(esdtRoleLocalBurn))}) + scCallParams := []string{ + hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), + handler.SafeAddress.Hex(), + hex.EncodeToString([]byte(esdtRoleLocalMint)), + hex.EncodeToString([]byte(esdtRoleLocalBurn))} + + hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.ESDTSystemContractAddress, zeroStringValue, setCallsGasLimit, setSpecialRoleFunction, scCallParams) + log.Info("set local roles esdt safe tx executed", "hash", hash, "status", txResult.Status) } @@ -758,16 +651,12 @@ func (handler *MultiversxHandler) addMappingInMultisig(ctx context.Context, para tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) // add mapping - hash, txResult := handler.ChainSimulator.ScCall( - ctx, - handler.OwnerKeys.MvxSk, - handler.MultisigAddress, - zeroStringValue, - setCallsGasLimit, - addMappingFunction, - []string{ - hex.EncodeToString(tkData.EthErc20Address.Bytes()), - hex.EncodeToString([]byte(tkData.MvxChainSpecificToken))}) + scCallParams := []string{ + hex.EncodeToString(tkData.EthErc20Address.Bytes()), + hex.EncodeToString([]byte(tkData.MvxChainSpecificToken))} + + hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.MultisigAddress, zeroStringValue, setCallsGasLimit, addMappingFunction, scCallParams) + log.Info("add mapping tx executed", "hash", hash, "status", txResult.Status) } @@ -775,22 +664,18 @@ func (handler *MultiversxHandler) whitelistTokenOnMultisig(ctx context.Context, tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) // whitelist token - hash, txResult := handler.ChainSimulator.ScCall( - ctx, - handler.OwnerKeys.MvxSk, - handler.MultisigAddress, - zeroStringValue, - setCallsGasLimit, - esdtSafeAddTokenToWhitelistFunction, - []string{ - hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), - hex.EncodeToString([]byte(params.MvxChainSpecificTokenTicker)), - getHexBool(params.IsMintBurnOnMvX), - getHexBool(params.IsNativeOnMvX), - hex.EncodeToString(zeroValueBigInt.Bytes()), // total_balance - hex.EncodeToString(zeroValueBigInt.Bytes()), // mint_balance - hex.EncodeToString(zeroValueBigInt.Bytes()), // burn_balance - }) + scCallParams := []string{ + hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), + hex.EncodeToString([]byte(params.MvxChainSpecificTokenTicker)), + getHexBool(params.IsMintBurnOnMvX), + getHexBool(params.IsNativeOnMvX), + hex.EncodeToString(zeroValueBigInt.Bytes()), // total_balance + hex.EncodeToString(zeroValueBigInt.Bytes()), // mint_balance + hex.EncodeToString(zeroValueBigInt.Bytes()), // burn_balance + } + + hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.MultisigAddress, zeroStringValue, setCallsGasLimit, esdtSafeAddTokenToWhitelistFunction, scCallParams) + log.Info("whitelist token tx executed", "hash", hash, "status", txResult.Status) } @@ -812,37 +697,24 @@ func (handler *MultiversxHandler) setInitialSupply(ctx context.Context, params I mintAmount = initialSupply } - hash, txResult := handler.ChainSimulator.ScCall( - ctx, - handler.OwnerKeys.MvxSk, - handler.MultisigAddress, - zeroStringValue, - setCallsGasLimit, - initSupplyMintBurnEsdtSafe, - []string{ - hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), - hex.EncodeToString(mintAmount.Bytes()), - hex.EncodeToString(burnAmount.Bytes()), - }, - ) + scCallParams := []string{ + hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), + hex.EncodeToString(mintAmount.Bytes()), + hex.EncodeToString(burnAmount.Bytes()), + } + hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.MultisigAddress, zeroStringValue, setCallsGasLimit, initSupplyMintBurnEsdtSafe, scCallParams) log.Info("initial supply tx executed", "hash", hash, "status", txResult.Status, "initial mint", mintAmount.String(), "initial burned", burnAmount.String()) } else { - hash, txResult := handler.ChainSimulator.ScCall( - ctx, - handler.OwnerKeys.MvxSk, - handler.MultisigAddress, - zeroStringValue, - setCallsGasLimit, - esdtTransferFunction, - []string{ - hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), - hex.EncodeToString(initialSupply.Bytes()), - hex.EncodeToString([]byte(initSupplyEsdtSafe)), - hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), - hex.EncodeToString(initialSupply.Bytes()), - }) + scCallParams := []string{ + hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), + hex.EncodeToString(initialSupply.Bytes()), + hex.EncodeToString([]byte(initSupplyEsdtSafe)), + hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), + hex.EncodeToString(initialSupply.Bytes()), + } + hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.MultisigAddress, zeroStringValue, setCallsGasLimit, esdtTransferFunction, scCallParams) log.Info("initial supply tx executed", "hash", hash, "status", txResult.Status, "initial value", params.InitialSupplyValue) @@ -852,17 +724,12 @@ func (handler *MultiversxHandler) setInitialSupply(ctx context.Context, params I func (handler *MultiversxHandler) setPairDecimalsOnAggregator(ctx context.Context, params IssueTokenParams) { // setPairDecimals on aggregator - hash, txResult := handler.ChainSimulator.ScCall( - ctx, - handler.OwnerKeys.MvxSk, - handler.AggregatorAddress, - zeroStringValue, - setCallsGasLimit, - setPairDecimalsFunction, - []string{ - hex.EncodeToString([]byte(gwei)), - hex.EncodeToString([]byte(params.MvxChainSpecificTokenTicker)), - fmt.Sprintf("%02x", params.NumOfDecimalsChainSpecific)}) + scCallParams := []string{ + hex.EncodeToString([]byte(gwei)), + hex.EncodeToString([]byte(params.MvxChainSpecificTokenTicker)), + fmt.Sprintf("%02x", params.NumOfDecimalsChainSpecific)} + hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.AggregatorAddress, zeroStringValue, setCallsGasLimit, setPairDecimalsFunction, scCallParams) + log.Info("setPairDecimals tx executed", "hash", hash, "status", txResult.Status) } @@ -871,16 +738,11 @@ func (handler *MultiversxHandler) setMaxBridgeAmountOnSafe(ctx context.Context, // safe set max bridge amount for token maxBridgedAmountForTokenInt, _ := big.NewInt(0).SetString(maxBridgedAmountForToken, 10) - hash, txResult := handler.ChainSimulator.ScCall( - ctx, - handler.OwnerKeys.MvxSk, - handler.MultisigAddress, - zeroStringValue, - setCallsGasLimit, - esdtSafeSetMaxBridgedAmountForTokenFunction, - []string{ - hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), - hex.EncodeToString(maxBridgedAmountForTokenInt.Bytes())}) + scCallParams := []string{ + hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), + hex.EncodeToString(maxBridgedAmountForTokenInt.Bytes())} + hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.MultisigAddress, zeroStringValue, setCallsGasLimit, esdtSafeSetMaxBridgedAmountForTokenFunction, scCallParams) + log.Info("safe set max bridge amount for token tx executed", "hash", hash, "status", txResult.Status) } @@ -889,16 +751,11 @@ func (handler *MultiversxHandler) setMaxBridgeAmountOnMultitransfer(ctx context. // multi-transfer set max bridge amount for token maxBridgedAmountForTokenInt, _ := big.NewInt(0).SetString(maxBridgedAmountForToken, 10) - hash, txResult := handler.ChainSimulator.ScCall( - ctx, - handler.OwnerKeys.MvxSk, - handler.MultisigAddress, - zeroStringValue, - setCallsGasLimit, - multiTransferEsdtSetMaxBridgedAmountForTokenFunction, - []string{ - hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), - hex.EncodeToString(maxBridgedAmountForTokenInt.Bytes())}) + scCallParams := []string{ + hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), + hex.EncodeToString(maxBridgedAmountForTokenInt.Bytes())} + hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.MultisigAddress, zeroStringValue, setCallsGasLimit, multiTransferEsdtSetMaxBridgedAmountForTokenFunction, scCallParams) + log.Info("multi-transfer set max bridge amount for token tx executed", "hash", hash, "status", txResult.Status) } @@ -924,7 +781,7 @@ func (handler *MultiversxHandler) SubmitAggregatorBatch(ctx context.Context, par } for _, hash := range txHashes { - txResult := handler.ChainSimulator.GetTransactionResult(ctx, hash) + txResult, _ := handler.ChainSimulator.GetTransactionResult(ctx, hash) log.Info("submit aggregator batch tx", "hash", hash, "status", txResult.Status) } } @@ -956,7 +813,6 @@ func (handler *MultiversxHandler) submitAggregatorBatchForKey(ctx context.Contex // SendDepositTransactionFromMultiversx will send the deposit transaction from MultiversX 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()), @@ -965,8 +821,23 @@ func (handler *MultiversxHandler) SendDepositTransactionFromMultiversx(ctx conte hex.EncodeToString(to.EthAddress.Bytes()), } dataField := strings.Join(params, "@") + hash, txResult := handler.sendAndCheckTx(ctx, from, handler.WrapperAddress, zeroStringValue, createDepositGasLimit+gasLimitPerDataByte*uint64(len(dataField)), esdtTransferFunction, params) - hash, txResult := handler.ChainSimulator.ScCall( + log.Info("MultiversX->Ethereum transaction sent", "hash", hash, "token", token.MvxUniversalToken, "status", txResult.Status) +} + +// SendWrongDepositTransactionFromMultiversx will send a wrong deposit transaction from MultiversX +func (handler *MultiversxHandler) SendWrongDepositTransactionFromMultiversx(ctx context.Context, from KeysHolder, to KeysHolder, token *TokenData, value *big.Int) { + params := []string{ + hex.EncodeToString([]byte(token.MvxUniversalToken)), + hex.EncodeToString(value.Bytes()), + hex.EncodeToString([]byte(unwrapTokenCreateTransactionFunction)), + hex.EncodeToString([]byte(token.MvxChainSpecificToken)), + hex.EncodeToString(to.EthAddress.Bytes()), + } + dataField := strings.Join(params, "@") + + _, txResult, txStatus := handler.ChainSimulator.ScCall( ctx, from.MvxSk, handler.WrapperAddress, @@ -975,7 +846,11 @@ func (handler *MultiversxHandler) SendDepositTransactionFromMultiversx(ctx conte esdtTransferFunction, params, ) - log.Info("MultiversX->Ethereum transaction sent", "hash", hash, "token", token.MvxUniversalToken, "status", txResult.Status) + + _, err := json.MarshalIndent(txResult, "", " ") + fmt.Println("EROARE", err) + require.Nil(handler, err) + require.Equal(handler, transaction.TxStatusFail, txStatus) } // TestWithdrawFees will try to withdraw the fees for the provided token from the safe contract to the owner @@ -1011,17 +886,10 @@ func (handler *MultiversxHandler) withdrawFees(ctx context.Context, initialBalance, ok := big.NewInt(0).SetString(initialBalanceStr, 10) require.True(handler, ok) - handler.ChainSimulator.ScCall( - ctx, - handler.OwnerKeys.MvxSk, - handler.MultisigAddress, - zeroStringValue, - generalSCCallGasLimit, - withdrawFunction, - []string{ - hex.EncodeToString([]byte(token)), - }, - ) + params := []string{ + hex.EncodeToString([]byte(token)), + } + handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.MultisigAddress, zeroStringValue, generalSCCallGasLimit, withdrawFunction, params) handler.ChainSimulator.GenerateBlocks(ctx, 5) // ensure block finality finalBalanceStr := handler.ChainSimulator.GetESDTBalance(ctx, handler.OwnerKeys.MvxAddress, token) @@ -1038,16 +906,10 @@ func (handler *MultiversxHandler) TransferToken(ctx context.Context, source Keys tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) // transfer to receiver, 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())}) + scCallParams := []string{ + hex.EncodeToString([]byte(tkData.MvxUniversalToken)), + hex.EncodeToString(amount.Bytes())} + hash, txResult := handler.sendAndCheckTx(ctx, source, receiver.MvxAddress, zeroStringValue, createDepositGasLimit, esdtTransferFunction, scCallParams) log.Info("transfer to tx executed", "source address", source.MvxAddress.Bech32(), @@ -1090,6 +952,41 @@ func (handler *MultiversxHandler) GetBurnedAmountForToken(ctx context.Context, t return value } +// MoveRefundBatchToSafe will move the refund batch from the multisig to the safe +func (handler *MultiversxHandler) MoveRefundBatchToSafe(ctx context.Context) { + hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.MultisigAddress, zeroStringValue, setCallsGasLimit, moveRefundBatchToSafeFromChildContractFunction, []string{}) + log.Info("Moved refund batch from Multisig to EsdtSafe", "transaction hash", hash, "status", txResult.Status) +} + +// HasRefundBatch will check if there is a refund batch in the multisig +func (handler *MultiversxHandler) HasRefundBatch(ctx context.Context) bool { + responseData := handler.ChainSimulator.ExecuteVMQuery(ctx, handler.MultisigAddress, getCurrentRefundBatchFunction, []string{}) + if len(responseData) != 0 { + return true + } + return false +} + +func (handler *MultiversxHandler) sendAndCheckTx(ctx context.Context, sender KeysHolder, receiver *MvxAddress, value string, gasLimit uint64, function string, params []string) (string, *data.TransactionOnNetwork) { + hash, txResult, txStatus := handler.ChainSimulator.ScCall( + ctx, + sender.MvxSk, + receiver, + value, + gasLimit, + function, + params, + ) + + jsonData, err := json.MarshalIndent(txResult, "", " ") + require.Nil(handler, err) + require.Equal(handler, transaction.TxStatusSuccess, txStatus, fmt.Sprintf("tx hash: %s,\n tx: %s", hash, string(jsonData))) + + log.Info(fmt.Sprintf("Transaction hash %s, status %s", hash, txResult.Status)) + + return hash, txResult +} + 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 2f7bafd4..6224acd9 100644 --- a/integrationTests/relayers/slowTests/framework/testSetup.go +++ b/integrationTests/relayers/slowTests/framework/testSetup.go @@ -34,6 +34,22 @@ const ( type currentBridge string +type CurrentActorState struct { + isSender bool + HasToReceiveRefund bool +} + +var ( + senderState = CurrentActorState{ + isSender: true, + HasToReceiveRefund: false, + } + receiverState = CurrentActorState{ + isSender: false, + HasToReceiveRefund: false, + } +) + // TestSetup is the struct that holds all subcomponents for the testing infrastructure type TestSetup struct { testing.TB @@ -176,8 +192,9 @@ 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 - + if token.IsNativeOnMvX { + setup.transferTokensToMvxTestKey(token) // TODO: (Next PRs) this will be moved an batch creation time + } setup.ChainSimulator.GenerateBlocks(setup.Ctx, 10) esdtBalanceForSafe := setup.MultiversxHandler.GetESDTChainSpecificTokenBalance(setup.Ctx, setup.MultiversxHandler.SafeAddress, token.AbstractTokenIdentifier) @@ -238,16 +255,18 @@ func (setup *TestSetup) IsTransferDoneFromEthereum(sender KeysHolder, receiver K } func (setup *TestSetup) isTransferDoneFromEthereumForToken(sender, receiver KeysHolder, params TestTokenParams) bool { - if !setup.checkHolderEthBalanceForToken(sender, true, params) { - return false + // if token is prevented from whitelist, we can't check the balances + if params.PreventWhitelist { + return true } - if !setup.checkHolderMvxBalanceForToken(receiver, false, params) { + + if !setup.checkHolderEthBalanceForToken(sender, senderState, params) { return false } - //if !setup.checkMvxAddressZeroBalanceForToken(params) { - // return false - //} + if !setup.checkHolderMvxBalanceForToken(receiver, receiverState, params) { + return false + } if !setup.checkContractMvxBalanceForToken(params) { return false @@ -260,7 +279,7 @@ func (setup *TestSetup) isTransferDoneFromEthereumForToken(sender, receiver Keys return setup.checkTokenOnMvxSecondBridge(params) } -func (setup *TestSetup) checkHolderEthBalanceForToken(holder KeysHolder, isSender bool, params TestTokenParams) bool { +func (setup *TestSetup) checkHolderEthBalanceForToken(holder KeysHolder, actorState CurrentActorState, params TestTokenParams) bool { balanceMapping, exists := setup.getBalanceMappingForAddress(holder.EthAddress.String()) if !exists { return false @@ -268,10 +287,10 @@ func (setup *TestSetup) checkHolderEthBalanceForToken(holder KeysHolder, isSende actualBalance := setup.EthereumHandler.GetBalance(holder.EthAddress, params.AbstractTokenIdentifier) fmt.Println("----------------------ETH-------------------------") - return setup.checkHolderBalanceForTokenHelper(balanceMapping, params, actualBalance, holder.EthAddress.String(), isSender) + return setup.checkHolderBalanceForTokenHelper(balanceMapping, params, actualBalance, holder.EthAddress.String(), actorState) } -func (setup *TestSetup) checkHolderMvxBalanceForToken(holder KeysHolder, isSender bool, params TestTokenParams) bool { +func (setup *TestSetup) checkHolderMvxBalanceForToken(holder KeysHolder, actorState CurrentActorState, params TestTokenParams) bool { balanceMapping, exists := setup.getBalanceMappingForAddress(holder.MvxAddress.String()) if !exists { return false @@ -279,7 +298,7 @@ func (setup *TestSetup) checkHolderMvxBalanceForToken(holder KeysHolder, isSende actualBalance := setup.MultiversxHandler.GetESDTUniversalTokenBalance(setup.Ctx, holder.MvxAddress, params.AbstractTokenIdentifier) fmt.Println("---------------------MVX--------------------------") - return setup.checkHolderBalanceForTokenHelper(balanceMapping, params, actualBalance, holder.MvxAddress.String(), isSender) + return setup.checkHolderBalanceForTokenHelper(balanceMapping, params, actualBalance, holder.MvxAddress.String(), actorState) } func (setup *TestSetup) getBalanceMappingForAddress(address string) (map[string]*big.Int, bool) { @@ -295,13 +314,16 @@ func (setup *TestSetup) getBalanceMappingForAddress(address string) (map[string] return balanceMapping, exists } -func (setup *TestSetup) checkHolderBalanceForTokenHelper(balanceMapping map[string]*big.Int, params TestTokenParams, actualBalance *big.Int, address string, isSender bool) bool { +func (setup *TestSetup) checkHolderBalanceForTokenHelper(balanceMapping map[string]*big.Int, params TestTokenParams, actualBalance *big.Int, address string, actorState CurrentActorState) bool { extraBalances := setup.getExtraBalanceForHolder(address, params) expectedBalance := big.NewInt(0).Set(balanceMapping[params.AbstractTokenIdentifier]) expectedBalance.Add(expectedBalance, extraBalances.ReceivedAmount) - if isSender { + if actorState.isSender { expectedBalance.Add(expectedBalance, extraBalances.SentAmount) + if actorState.HasToReceiveRefund { + expectedBalance.Add(expectedBalance, extraBalances.RefundAmount) + } } fmt.Println("expectedBalance", expectedBalance.String()) @@ -458,6 +480,9 @@ func (setup *TestSetup) computeExpectedValueFromMvx(params TestTokenParams) *big if operation.ValueToSendFromMvX == nil { continue } + if operation.IsFaultyDeposit { + continue + } expectedValue.Add(expectedValue, operation.ValueToSendFromMvX) expectedValue.Sub(expectedValue, feeInt) @@ -467,45 +492,27 @@ func (setup *TestSetup) computeExpectedValueFromMvx(params TestTokenParams) *big } // IsTransferDoneFromEthereumWithRefund returns true if all provided tokens are bridged from Ethereum towards MultiversX including refunds -func (setup *TestSetup) IsTransferDoneFromEthereumWithRefund(tokens ...TestTokenParams) bool { +func (setup *TestSetup) IsTransferDoneFromEthereumWithRefund(holder KeysHolder, tokens ...TestTokenParams) bool { isDone := true for _, params := range tokens { - isDone = isDone && setup.isTransferDoneFromEthereumWithRefundForToken(params) + isDone = isDone && setup.isTransferDoneFromEthWithRefundForToken(holder, params) } return isDone } -func (setup *TestSetup) isTransferDoneFromEthereumWithRefundForToken(params TestTokenParams) bool { - expectedValueOnReceiver := big.NewInt(0) - for _, operation := range params.TestOperations { - valueToTransferToMvx := big.NewInt(0) - if operation.ValueToTransferToMvx != nil { - valueToTransferToMvx.Set(operation.ValueToTransferToMvx) - } - - valueToSendFromMvX := big.NewInt(0) - if operation.ValueToSendFromMvX != nil { - valueToSendFromMvX.Set(operation.ValueToSendFromMvX) - // we subtract the fee also - expectedValueOnReceiver.Sub(expectedValueOnReceiver, feeInt) - } - - expectedValueOnReceiver.Add(expectedValueOnReceiver, big.NewInt(0).Sub(valueToSendFromMvX, valueToTransferToMvx)) - if len(operation.MvxSCCallData) == 0 && !operation.MvxForceSCCall { - continue - } - if !operation.MvxFaultySCCall { - continue - } +func (setup *TestSetup) isTransferDoneFromEthWithRefundForToken(holder KeysHolder, params TestTokenParams) bool { + // if token is prevented from whitelist, we can't check the balances + if params.PreventWhitelist { + return true + } - // the balance should be bridged back to the receiver on Ethereum - fee - expectedValueOnReceiver.Add(expectedValueOnReceiver, valueToTransferToMvx) - expectedValueOnReceiver.Sub(expectedValueOnReceiver, feeInt) + actorState := CurrentActorState{ + isSender: true, + HasToReceiveRefund: true, } - receiverBalance := setup.EthereumHandler.GetBalance(setup.BobKeys.EthAddress, params.AbstractTokenIdentifier) - return receiverBalance.String() == expectedValueOnReceiver.String() + return setup.checkHolderEthBalanceForToken(holder, actorState, params) } // IsTransferDoneFromMultiversX returns true if all provided tokens are bridged from MultiversX towards Ethereum @@ -519,17 +526,17 @@ func (setup *TestSetup) IsTransferDoneFromMultiversX(sender KeysHolder, receiver } func (setup *TestSetup) isTransferDoneFromMultiversXForToken(sender, receiver KeysHolder, params TestTokenParams) bool { - if !setup.checkHolderMvxBalanceForToken(sender, true, params) { + if params.PreventWhitelist { + return true + } + + if !setup.checkHolderMvxBalanceForToken(sender, senderState, params) { return false } - if !setup.checkHolderEthBalanceForToken(receiver, false, params) { + if !setup.checkHolderEthBalanceForToken(receiver, receiverState, params) { return false } - //if !setup.checkEthAddressZeroBalanceForToken(params) { - // return false - //} - if !setup.checkMvxBalanceForSafe(params) { return false } @@ -655,6 +662,29 @@ func (setup *TestSetup) getMvxTotalRefundAmountForToken(params TestTokenParams) return totalRefund } +func (setup *TestSetup) getEthTotalRefundAmountForToken(params TestTokenParams) *big.Int { + totalRefund := big.NewInt(0) + for _, operation := range params.TestOperations { + if operation.InvalidReceiver != nil { + totalRefund.Add(totalRefund, operation.ValueToSendFromMvX) + totalRefund.Sub(totalRefund, feeInt) + continue + } + + if len(operation.MvxSCCallData) == 0 && !operation.MvxForceSCCall { + continue + } + + if !operation.MvxFaultySCCall { + continue + } + + totalRefund.Add(totalRefund, operation.ValueToSendFromMvX) + totalRefund.Sub(totalRefund, feeInt) + } + return totalRefund +} + // CreateBatchOnMultiversX will create deposits that will be gathered in a batch on MultiversX func (setup *TestSetup) CreateBatchOnMultiversX(tokensParams ...TestTokenParams) { for _, params := range tokensParams { @@ -671,7 +701,7 @@ func (setup *TestSetup) createBatchOnMultiversXForToken(params TestTokenParams) setup.EthereumHandler.Mint(setup.Ctx, params, valueToMintOnEthereum) } -func (setup *TestSetup) transferTokensToTestKey(params TestTokenParams) { +func (setup *TestSetup) transferTokensToMvxTestKey(params TestTokenParams) { depositValue := big.NewInt(0) for _, operation := range params.TestOperations { if operation.ValueToSendFromMvX == nil { @@ -708,12 +738,17 @@ func (setup *TestSetup) createDepositOnMultiversxForToken(from KeysHolder, to Ke } if operation.InvalidReceiver != nil { - badEthAddress := common.Address(bytes.Repeat([]byte{0x00}, 20)) - to = KeysHolder{EthAddress: badEthAddress} + invalidReceiver := common.Address(operation.InvalidReceiver) + to = KeysHolder{EthAddress: invalidReceiver} } depositValue.Add(depositValue, operation.ValueToSendFromMvX) - setup.MultiversxHandler.SendDepositTransactionFromMultiversx(setup.Ctx, from, to, token, operation.ValueToSendFromMvX) + + if operation.IsFaultyDeposit || params.PreventWhitelist { + setup.MultiversxHandler.SendWrongDepositTransactionFromMultiversx(setup.Ctx, from, to, token, operation.ValueToSendFromMvX) + } else { + setup.MultiversxHandler.SendDepositTransactionFromMultiversx(setup.Ctx, from, to, token, operation.ValueToSendFromMvX) + } } return depositValue @@ -782,19 +817,31 @@ func (setup *TestSetup) TestWithdrawTotalFeesOnEthereumForTokens(tokensParams .. for _, param := range tokensParams { token := setup.TokensRegistry.GetTokenData(param.AbstractTokenIdentifier) + expectedRefund := big.NewInt(0) expectedAccumulated := big.NewInt(0) + + if param.PreventWhitelist { + continue + } + for _, operation := range param.TestOperations { + if operation.InvalidReceiver != nil { + expectedRefund.Add(expectedRefund, feeInt) + } + if operation.ValueToSendFromMvX == nil { continue } if operation.ValueToSendFromMvX.Cmp(zeroValueBigInt) == 0 { continue } + if operation.IsFaultyDeposit { + continue + } expectedAccumulated.Add(expectedAccumulated, feeInt) } - - setup.MultiversxHandler.TestWithdrawFees(setup.Ctx, token.MvxChainSpecificToken, zeroValueBigInt, expectedAccumulated) + setup.MultiversxHandler.TestWithdrawFees(setup.Ctx, token.MvxChainSpecificToken, expectedRefund, expectedAccumulated) } } diff --git a/integrationTests/relayers/slowTests/framework/types.go b/integrationTests/relayers/slowTests/framework/types.go index 853c3297..472f71c4 100644 --- a/integrationTests/relayers/slowTests/framework/types.go +++ b/integrationTests/relayers/slowTests/framework/types.go @@ -10,7 +10,7 @@ import ( type IssueTokenParams struct { InitialSupplyParams AbstractTokenIdentifier string - AvoidWhiteList bool + PreventWhitelist bool // MultiversX NumOfDecimalsUniversal int @@ -75,4 +75,5 @@ type TokenData struct { type ExtraBalanceHolder struct { SentAmount *big.Int ReceivedAmount *big.Int + RefundAmount *big.Int } diff --git a/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go b/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go index 4a510a77..2ae954d6 100644 --- a/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go +++ b/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go @@ -1,3 +1,5 @@ +//go:build !slow + // To run these slow tests, simply add the slow tag on the go test command. Also, provide a chain simulator instance on the 8085 port // example: go test -tags slow diff --git a/integrationTests/relayers/slowTests/startsFromEthereumFlow.go b/integrationTests/relayers/slowTests/startsFromEthereumFlow.go index ba33f59a..0639944e 100644 --- a/integrationTests/relayers/slowTests/startsFromEthereumFlow.go +++ b/integrationTests/relayers/slowTests/startsFromEthereumFlow.go @@ -1,3 +1,5 @@ +//go:build !slow + package slowTests import ( @@ -44,3 +46,18 @@ func (flow *startsFromEthereumFlow) process() (finished bool) { return false } + +func (flow *startsFromEthereumFlow) areTokensFullyRefunded() bool { + if len(flow.tokens) == 0 { + return true + } + if !flow.ethToMvxDone { + return false // regular flow is not completed + } + + if flow.setup.MultiversxHandler.HasRefundBatch(flow.setup.Ctx) { + flow.setup.MultiversxHandler.MoveRefundBatchToSafe(flow.setup.Ctx) + } + + return flow.setup.IsTransferDoneFromEthereumWithRefund(flow.setup.AliceKeys, flow.tokens...) +} diff --git a/integrationTests/relayers/slowTests/startsFromMultiversxFlow.go b/integrationTests/relayers/slowTests/startsFromMultiversxFlow.go index 7e2c11f3..8203470f 100644 --- a/integrationTests/relayers/slowTests/startsFromMultiversxFlow.go +++ b/integrationTests/relayers/slowTests/startsFromMultiversxFlow.go @@ -1,3 +1,5 @@ +//go:build !slow + package slowTests import ( @@ -53,5 +55,5 @@ func (flow *startsFromMultiversXFlow) areTokensFullyRefunded() bool { return false // regular flow is not completed } - return flow.setup.IsTransferDoneFromEthereumWithRefund(flow.tokens...) + return flow.setup.IsTransferDoneFromEthereumWithRefund(flow.setup.BobKeys, flow.tokens...) } From 1366d297c7e86dbac7df645c8cec5d0e650c8baf Mon Sep 17 00:00:00 2001 From: cosmatudor Date: Wed, 27 Nov 2024 18:33:46 +0200 Subject: [PATCH 05/17] delete prints --- .../slowTests/framework/multiversxHandler.go | 6 +- .../relayers/slowTests/framework/testSetup.go | 58 +------------------ 2 files changed, 3 insertions(+), 61 deletions(-) diff --git a/integrationTests/relayers/slowTests/framework/multiversxHandler.go b/integrationTests/relayers/slowTests/framework/multiversxHandler.go index 8e11fc6b..6e83cc8e 100644 --- a/integrationTests/relayers/slowTests/framework/multiversxHandler.go +++ b/integrationTests/relayers/slowTests/framework/multiversxHandler.go @@ -872,7 +872,6 @@ func (handler *MultiversxHandler) SendWrongDepositTransactionFromMultiversx(ctx ) _, err := json.MarshalIndent(txResult, "", " ") - fmt.Println("EROARE", err) require.Nil(handler, err) require.Equal(handler, transaction.TxStatusFail, txStatus) } @@ -985,10 +984,7 @@ func (handler *MultiversxHandler) MoveRefundBatchToSafe(ctx context.Context) { // HasRefundBatch will check if there is a refund batch in the multisig func (handler *MultiversxHandler) HasRefundBatch(ctx context.Context) bool { responseData := handler.ChainSimulator.ExecuteVMQuery(ctx, handler.MultisigAddress, getCurrentRefundBatchFunction, []string{}) - if len(responseData) != 0 { - return true - } - return false + return len(responseData) != 0 } func (handler *MultiversxHandler) sendAndCheckTx(ctx context.Context, sender KeysHolder, receiver *MvxAddress, value string, gasLimit uint64, function string, params []string) (string, *data.TransactionOnNetwork) { diff --git a/integrationTests/relayers/slowTests/framework/testSetup.go b/integrationTests/relayers/slowTests/framework/testSetup.go index 4fd70da2..27152a09 100644 --- a/integrationTests/relayers/slowTests/framework/testSetup.go +++ b/integrationTests/relayers/slowTests/framework/testSetup.go @@ -1,7 +1,6 @@ package framework import ( - "bytes" "context" "fmt" "math/big" @@ -286,7 +285,6 @@ func (setup *TestSetup) checkHolderEthBalanceForToken(holder KeysHolder, actorSt } actualBalance := setup.EthereumHandler.GetBalance(holder.EthAddress, params.AbstractTokenIdentifier) - fmt.Println("----------------------ETH-------------------------") return setup.checkHolderBalanceForTokenHelper(balanceMapping, params, actualBalance, holder.EthAddress.String(), actorState) } @@ -297,7 +295,6 @@ func (setup *TestSetup) checkHolderMvxBalanceForToken(holder KeysHolder, actorSt } actualBalance := setup.MultiversxHandler.GetESDTUniversalTokenBalance(setup.Ctx, holder.MvxAddress, params.AbstractTokenIdentifier) - fmt.Println("---------------------MVX--------------------------") return setup.checkHolderBalanceForTokenHelper(balanceMapping, params, actualBalance, holder.MvxAddress.String(), actorState) } @@ -326,24 +323,9 @@ func (setup *TestSetup) checkHolderBalanceForTokenHelper(balanceMapping map[stri } } - fmt.Println("expectedBalance", expectedBalance.String()) - fmt.Println("actualBalance", actualBalance.String()) - fmt.Println("-----------------------------------------------") return actualBalance.String() == expectedBalance.String() } -func (setup *TestSetup) checkMvxAddressZeroBalanceForToken(params TestTokenParams) bool { - extraBalances := setup.getExtraBalanceForHolder("", params) - expectedBalance := big.NewInt(0).Set(extraBalances.ReceivedAmount) - - zeroAddressMvx := NewMvxAddressFromBytes(setup, bytes.Repeat([]byte{0x00}, 32)) - actualBalance := setup.MultiversxHandler.GetESDTUniversalTokenBalance(setup.Ctx, zeroAddressMvx, params.AbstractTokenIdentifier) - - fmt.Println("expectedBalance", expectedBalance.String()) - fmt.Println("actualBalance", actualBalance.String()) - return expectedBalance == actualBalance -} - func (setup *TestSetup) getExtraBalanceForHolder(address string, params TestTokenParams) ExtraBalanceHolder { setup.mutBalances.Lock() defer setup.mutBalances.Unlock() @@ -373,10 +355,6 @@ func (setup *TestSetup) checkContractMvxBalanceForToken(params TestTokenParams) expectedValueOnContract.Add(expectedValueOnContract, operation.ValueToTransferToMvx) } - fmt.Println("---------------------CONTRACT--------------------------") - fmt.Println("expectedValueOnContract", expectedValueOnContract.String()) - fmt.Println("mvxBalance", mvxBalance.String()) - fmt.Println("-----------------------------------------------") return mvxBalance.String() == expectedValueOnContract.String() } @@ -413,10 +391,6 @@ func (setup *TestSetup) checkEthLockedBalanceForToken(params TestTokenParams, br expectedValue.Sub(expectedValue, setup.getMvxTotalRefundAmountForToken(params)) // unlock possible refund amount to be bridged back to Eth } - fmt.Println("----------------------ETH-------------------------") - fmt.Println("lockedTokens", lockedTokens.String()) - fmt.Println("expectedValue", expectedValue.String()) - fmt.Println("-----------------------------------------------") return lockedTokens.String() == expectedValue.String() } @@ -451,10 +425,6 @@ func (setup *TestSetup) checkMvxMintedBalanceForToken(params TestTokenParams) bo } } - fmt.Println("---------------------MVX--------------------------") - fmt.Println("mintedTokens", mintedTokens.String()) - fmt.Println("expectedValue", expectedValue.String()) - fmt.Println("-----------------------------------------------") return mintedTokens.String() == expectedValue.String() } @@ -652,29 +622,6 @@ func (setup *TestSetup) getMvxTotalRefundAmountForToken(params TestTokenParams) return totalRefund } -func (setup *TestSetup) getEthTotalRefundAmountForToken(params TestTokenParams) *big.Int { - totalRefund := big.NewInt(0) - for _, operation := range params.TestOperations { - if operation.InvalidReceiver != nil { - totalRefund.Add(totalRefund, operation.ValueToSendFromMvX) - totalRefund.Sub(totalRefund, feeInt) - continue - } - - if len(operation.MvxSCCallData) == 0 && !operation.MvxForceSCCall { - continue - } - - if !operation.MvxFaultySCCall { - continue - } - - totalRefund.Add(totalRefund, operation.ValueToSendFromMvX) - totalRefund.Sub(totalRefund, feeInt) - } - return totalRefund -} - // CreateBatchOnMultiversX will create deposits that will be gathered in a batch on MultiversX func (setup *TestSetup) CreateBatchOnMultiversX(tokensParams ...TestTokenParams) { for _, params := range tokensParams { @@ -793,9 +740,8 @@ func (setup *TestSetup) createDepositOnEthereumForToken(from KeysHolder, to Keys } if operation.InvalidReceiver != nil { - badMvxAddress := NewMvxAddressFromBytes(setup, operation.InvalidReceiver) - to = KeysHolder{MvxAddress: badMvxAddress} - fmt.Println("to", to.MvxAddress.AddressSlice()) + invalidReceiver := NewMvxAddressFromBytes(setup, operation.InvalidReceiver) + to = KeysHolder{MvxAddress: invalidReceiver} } setup.EthereumHandler.SendDepositTransactionFromEthereum(setup.Ctx, from, to, targetSCAddress, token, operation) From eb81e89fab08608f8f4ef7f239ae09d4931bacd3 Mon Sep 17 00:00:00 2001 From: cosmatudor Date: Thu, 28 Nov 2024 10:30:37 +0200 Subject: [PATCH 06/17] fix --- integrationTests/relayers/slowTests/common.go | 2 +- .../slowTests/ethToMultiversXWithChainSimulator_test.go | 8 ++++---- .../relayers/slowTests/refundWithChainSimulator_test.go | 2 +- .../relayers/slowTests/startsFromEthereumFlow.go | 2 +- .../relayers/slowTests/startsFromMultiversxFlow.go | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/integrationTests/relayers/slowTests/common.go b/integrationTests/relayers/slowTests/common.go index 3991f622..25975f8b 100644 --- a/integrationTests/relayers/slowTests/common.go +++ b/integrationTests/relayers/slowTests/common.go @@ -1,4 +1,4 @@ -//go:build !slow +//go:build slow package slowTests diff --git a/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go b/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go index cd09c96b..7843ed71 100644 --- a/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go +++ b/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go @@ -1,4 +1,4 @@ -//go:build !slow +//go:build slow // To run these slow tests, simply add the slow tag on the go test command. Also, provide a chain simulator instance on the 8085 port // example: go test -tags slow @@ -313,9 +313,9 @@ func createBadToken() framework.TestTokenParams { }, ESDTSafeExtraBalance: big.NewInt(0), ExtraBalances: map[string]framework.ExtraBalanceHolder{ - "Alice": {big.NewInt(-5000 - 7000 - 1000), big.NewInt(0), big.NewInt(0)}, - "Bob": {big.NewInt(-2500 - 300), big.NewInt(5000 + 7000), big.NewInt(0)}, - "Charlie": {big.NewInt(0), big.NewInt(2500 - 50 + 300 - 50), big.NewInt(0)}, + "Alice": {SentAmount: big.NewInt(-5000 - 7000 - 1000), ReceivedAmount: big.NewInt(0), RefundAmount: big.NewInt(0)}, + "Bob": {SentAmount: big.NewInt(-2500 - 300), ReceivedAmount: big.NewInt(5000 + 7000), RefundAmount: big.NewInt(0)}, + "Charlie": {SentAmount: big.NewInt(0), ReceivedAmount: big.NewInt(2500 - 50 + 300 - 50), RefundAmount: big.NewInt(0)}, }, } } diff --git a/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go b/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go index 2ae954d6..e87cf497 100644 --- a/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go +++ b/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go @@ -1,4 +1,4 @@ -//go:build !slow +//go:build slow // To run these slow tests, simply add the slow tag on the go test command. Also, provide a chain simulator instance on the 8085 port // example: go test -tags slow diff --git a/integrationTests/relayers/slowTests/startsFromEthereumFlow.go b/integrationTests/relayers/slowTests/startsFromEthereumFlow.go index 0639944e..d7fd7100 100644 --- a/integrationTests/relayers/slowTests/startsFromEthereumFlow.go +++ b/integrationTests/relayers/slowTests/startsFromEthereumFlow.go @@ -1,4 +1,4 @@ -//go:build !slow +//go:build slow package slowTests diff --git a/integrationTests/relayers/slowTests/startsFromMultiversxFlow.go b/integrationTests/relayers/slowTests/startsFromMultiversxFlow.go index 8203470f..689bf1fe 100644 --- a/integrationTests/relayers/slowTests/startsFromMultiversxFlow.go +++ b/integrationTests/relayers/slowTests/startsFromMultiversxFlow.go @@ -1,4 +1,4 @@ -//go:build !slow +//go:build slow package slowTests From 57dec7a52ba612db33e2e5ceffeafe3c54459fc2 Mon Sep 17 00:00:00 2001 From: cosmatudor Date: Mon, 2 Dec 2024 11:13:56 +0200 Subject: [PATCH 07/17] add ApplyEUROCRefundBalances function --- integrationTests/relayers/slowTests/common.go | 14 ++++++++-- .../relayers/slowTests/edgeCases_test.go | 2 -- .../ethToMultiversXWithChainSimulator_test.go | 2 -- .../refundWithChainSimulator_test.go | 26 +++++++++---------- .../startsFromEthereumEdgecaseFlow.go | 2 -- .../slowTests/startsFromEthereumFlow.go | 2 -- .../slowTests/startsFromMultiversxFlow.go | 2 -- 7 files changed, 24 insertions(+), 26 deletions(-) diff --git a/integrationTests/relayers/slowTests/common.go b/integrationTests/relayers/slowTests/common.go index c0551686..2ff81a90 100644 --- a/integrationTests/relayers/slowTests/common.go +++ b/integrationTests/relayers/slowTests/common.go @@ -1,5 +1,3 @@ -//go:build slow - package slowTests import ( @@ -119,6 +117,18 @@ func ApplyUSDCRefundBalances(token *framework.TestTokenParams) { token.DeltaBalances[framework.SecondHalfBridge][framework.CalledTestSC].OnMvx = big.NewInt(0) } +// ApplyEUROCRefundBalances will apply the refund balances on the involved entities for the EUROC token +func ApplyEUROCRefundBalances(token *framework.TestTokenParams) { + // Adjust SafeSC.OnMvx to account for the fees for the 2 transfers and the failed one that needed refund + token.DeltaBalances[framework.SecondHalfBridge][framework.SafeSC].OnMvx = big.NewInt(50 + 50 + 50) + // we need to subtract the refunded value from the Ethereum Safe contract + token.DeltaBalances[framework.SecondHalfBridge][framework.SafeSC].OnEth = big.NewInt(5010 + 7010 + 1010 - 2450 - 250 - 950) + // Alice will get her tokens back from the refund + token.DeltaBalances[framework.SecondHalfBridge][framework.Alice].OnEth = big.NewInt(-5010 - 7010 - 1010 + 960) + // No funds remain in the test caller SC + token.DeltaBalances[framework.SecondHalfBridge][framework.CalledTestSC].OnMvx = big.NewInt(0) +} + // GenerateTestMEMEToken will generate a test MEME token func GenerateTestMEMEToken() framework.TestTokenParams { //MEME is ethNative = false, ethMintBurn = true, mvxNative = true, mvxMintBurn = false diff --git a/integrationTests/relayers/slowTests/edgeCases_test.go b/integrationTests/relayers/slowTests/edgeCases_test.go index 12354ebd..15b8cb6c 100644 --- a/integrationTests/relayers/slowTests/edgeCases_test.go +++ b/integrationTests/relayers/slowTests/edgeCases_test.go @@ -1,5 +1,3 @@ -//go:build slow - package slowTests import ( diff --git a/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go b/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go index 5a909fa5..ad476c60 100644 --- a/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go +++ b/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go @@ -1,5 +1,3 @@ -//go:build slow - // To run these slow tests, simply add the slow tag on the go test command. Also, provide a chain simulator instance on the 8085 port // example: go test -tags slow diff --git a/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go b/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go index c00e4b78..83862e65 100644 --- a/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go +++ b/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go @@ -1,5 +1,3 @@ -//go:build slow - // To run these slow tests, simply add the slow tag on the go test command. Also, provide a chain simulator instance on the 8085 port // example: go test -tags slow @@ -30,7 +28,7 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { eurocToken := GenerateTestEUROCToken() eurocToken.TestOperations[2].MvxSCCallData = callData eurocToken.TestOperations[2].MvxFaultySCCall = true - eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + //eurocToken.ESDTSafeExtraBalance = big.NewInt(150) mexToken := GenerateTestMEXToken() mexToken.TestOperations[2].MvxSCCallData = callData @@ -42,7 +40,7 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { make(chan error), usdcToken, memeToken, - eurocToken, + //eurocToken, mexToken, ) }) @@ -61,7 +59,7 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { eurocToken := GenerateTestEUROCToken() eurocToken.TestOperations[2].MvxSCCallData = callData eurocToken.TestOperations[2].MvxFaultySCCall = true - eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + //eurocToken.ESDTSafeExtraBalance = big.NewInt(150) mexToken := GenerateTestMEXToken() mexToken.TestOperations[2].MvxSCCallData = callData @@ -91,7 +89,7 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { eurocToken := GenerateTestEUROCToken() eurocToken.TestOperations[2].MvxSCCallData = callData eurocToken.TestOperations[2].MvxFaultySCCall = true - eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + //eurocToken.ESDTSafeExtraBalance = big.NewInt(150) mexToken := GenerateTestMEXToken() mexToken.TestOperations[2].MvxSCCallData = callData @@ -123,7 +121,7 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { eurocToken.TestOperations[2].MvxSCCallData = nil eurocToken.TestOperations[2].MvxFaultySCCall = true eurocToken.TestOperations[2].MvxForceSCCall = true - eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + //eurocToken.ESDTSafeExtraBalance = big.NewInt(150) mexToken := GenerateTestMEXToken() mexToken.TestOperations[2].MvxSCCallData = nil @@ -154,7 +152,7 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { eurocToken := GenerateTestEUROCToken() eurocToken.TestOperations[2].MvxSCCallData = callData eurocToken.TestOperations[2].MvxFaultySCCall = true - eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + //eurocToken.ESDTSafeExtraBalance = big.NewInt(150) mexToken := GenerateTestMEXToken() mexToken.TestOperations[2].MvxSCCallData = callData @@ -184,7 +182,7 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { eurocToken := GenerateTestEUROCToken() eurocToken.TestOperations[2].MvxSCCallData = callData eurocToken.TestOperations[2].MvxFaultySCCall = true - eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + //eurocToken.ESDTSafeExtraBalance = big.NewInt(150) mexToken := GenerateTestMEXToken() mexToken.TestOperations[2].MvxSCCallData = callData @@ -214,7 +212,7 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { eurocToken := GenerateTestEUROCToken() eurocToken.TestOperations[2].MvxSCCallData = callData eurocToken.TestOperations[2].MvxFaultySCCall = true - eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + //eurocToken.ESDTSafeExtraBalance = big.NewInt(150) mexToken := GenerateTestMEXToken() mexToken.TestOperations[2].MvxSCCallData = callData @@ -244,7 +242,7 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { eurocToken := GenerateTestEUROCToken() eurocToken.TestOperations[2].MvxSCCallData = callData eurocToken.TestOperations[2].MvxFaultySCCall = true - eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + //eurocToken.ESDTSafeExtraBalance = big.NewInt(150) mexToken := GenerateTestMEXToken() mexToken.TestOperations[2].MvxSCCallData = callData @@ -274,7 +272,7 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { eurocToken := GenerateTestEUROCToken() eurocToken.TestOperations[2].MvxSCCallData = callData eurocToken.TestOperations[2].MvxFaultySCCall = true - eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + //eurocToken.ESDTSafeExtraBalance = big.NewInt(150) mexToken := GenerateTestMEXToken() mexToken.TestOperations[2].MvxSCCallData = callData @@ -307,7 +305,7 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { eurocToken := GenerateTestEUROCToken() eurocToken.TestOperations[2].MvxSCCallData = callData eurocToken.TestOperations[2].MvxFaultySCCall = true - eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + //eurocToken.ESDTSafeExtraBalance = big.NewInt(150) mexToken := GenerateTestMEXToken() mexToken.TestOperations[2].MvxSCCallData = callData @@ -342,7 +340,7 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { eurocToken := GenerateTestEUROCToken() eurocToken.TestOperations[2].MvxSCCallData = callData eurocToken.TestOperations[2].MvxFaultySCCall = true - eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + //eurocToken.ESDTSafeExtraBalance = big.NewInt(150) mexToken := GenerateTestMEXToken() mexToken.TestOperations[2].MvxSCCallData = callData diff --git a/integrationTests/relayers/slowTests/startsFromEthereumEdgecaseFlow.go b/integrationTests/relayers/slowTests/startsFromEthereumEdgecaseFlow.go index 654b8abf..1990f45e 100644 --- a/integrationTests/relayers/slowTests/startsFromEthereumEdgecaseFlow.go +++ b/integrationTests/relayers/slowTests/startsFromEthereumEdgecaseFlow.go @@ -1,5 +1,3 @@ -//go:build slow - package slowTests import ( diff --git a/integrationTests/relayers/slowTests/startsFromEthereumFlow.go b/integrationTests/relayers/slowTests/startsFromEthereumFlow.go index 291d269a..fdda8955 100644 --- a/integrationTests/relayers/slowTests/startsFromEthereumFlow.go +++ b/integrationTests/relayers/slowTests/startsFromEthereumFlow.go @@ -1,5 +1,3 @@ -//go:build slow - package slowTests import ( diff --git a/integrationTests/relayers/slowTests/startsFromMultiversxFlow.go b/integrationTests/relayers/slowTests/startsFromMultiversxFlow.go index b7b0a1ed..8a44586e 100644 --- a/integrationTests/relayers/slowTests/startsFromMultiversxFlow.go +++ b/integrationTests/relayers/slowTests/startsFromMultiversxFlow.go @@ -1,5 +1,3 @@ -//go:build slow - package slowTests import ( From f3f041bb49a2ac48a53ba189b6d99fa63eea014a Mon Sep 17 00:00:00 2001 From: cosmatudor Date: Mon, 2 Dec 2024 12:41:58 +0200 Subject: [PATCH 08/17] fixes after review --- integrationTests/relayers/slowTests/common.go | 45 ++- .../ethToMultiversXWithChainSimulator_test.go | 4 +- .../slowTests/framework/multiversxHandler.go | 314 +++++++++++++++--- .../relayers/slowTests/framework/testSetup.go | 1 + 4 files changed, 296 insertions(+), 68 deletions(-) diff --git a/integrationTests/relayers/slowTests/common.go b/integrationTests/relayers/slowTests/common.go index 25975f8b..a72a4838 100644 --- a/integrationTests/relayers/slowTests/common.go +++ b/integrationTests/relayers/slowTests/common.go @@ -275,23 +275,23 @@ func GenerateTestMEXToken() framework.TestTokenParams { } } -// GenerateTestDOGEToken will generate a test DOGE token -func GenerateTestDOGEToken() framework.TestTokenParams { +// GenerateUnlistedTokenFromEth will generate an unlisted token on Eth +func GenerateUnlistedTokenFromEth() framework.TestTokenParams { return framework.TestTokenParams{ IssueTokenParams: framework.IssueTokenParams{ - AbstractTokenIdentifier: "DOGE", + AbstractTokenIdentifier: "ULTkE", NumOfDecimalsUniversal: 6, NumOfDecimalsChainSpecific: 6, - MvxUniversalTokenTicker: "DOGE", - MvxChainSpecificTokenTicker: "DOGE", - MvxUniversalTokenDisplayName: "TestDOGE", - MvxChainSpecificTokenDisplayName: "TestDOGE", + MvxUniversalTokenTicker: "ULTkE", + MvxChainSpecificTokenTicker: "ULTkE", + MvxUniversalTokenDisplayName: "TestULTkE", + MvxChainSpecificTokenDisplayName: "TestULTkE", ValueToMintOnMvx: "10000000000", IsMintBurnOnMvX: true, IsNativeOnMvX: false, HasChainSpecificToken: false, - EthTokenName: "EthDOGE", - EthTokenSymbol: "DOGE", + EthTokenName: "EthULTkE", + EthTokenSymbol: "ULTkE", ValueToMintOnEth: "10000000000", IsMintBurnOnEth: true, IsNativeOnEth: true, @@ -310,27 +310,27 @@ func GenerateTestDOGEToken() framework.TestTokenParams { IsFaultyDeposit: true, }, }, - ESDTSafeExtraBalance: big.NewInt(100), // extra is just for the fees for the 2 transfers mvx->eth + ESDTSafeExtraBalance: big.NewInt(0), } } -// GenerateTestBOBERToken will generate a test BOBER token -func GenerateTestBOBERToken() framework.TestTokenParams { +// GenerateUnlistedTokenFromMvx will generate an unlisted token on Mvx +func GenerateUnlistedTokenFromMvx() framework.TestTokenParams { return framework.TestTokenParams{ IssueTokenParams: framework.IssueTokenParams{ - AbstractTokenIdentifier: "BOBER", + AbstractTokenIdentifier: "ULTKM", NumOfDecimalsUniversal: 2, NumOfDecimalsChainSpecific: 2, - MvxUniversalTokenTicker: "BOBER", - MvxChainSpecificTokenTicker: "BOBER", - MvxUniversalTokenDisplayName: "TestBOBER", - MvxChainSpecificTokenDisplayName: "TestBOBER", + MvxUniversalTokenTicker: "ULTKM", + MvxChainSpecificTokenTicker: "ULTKM", + MvxUniversalTokenDisplayName: "TestULTKM", + MvxChainSpecificTokenDisplayName: "TestULTKM", ValueToMintOnMvx: "10000000000", IsMintBurnOnMvX: true, IsNativeOnMvX: true, HasChainSpecificToken: false, - EthTokenName: "EthBOBER", - EthTokenSymbol: "BOBER", + EthTokenName: "EthULTKM", + EthTokenSymbol: "ULTKM", ValueToMintOnEth: "10000000000", IsMintBurnOnEth: true, IsNativeOnEth: false, @@ -341,13 +341,8 @@ func GenerateTestBOBERToken() framework.TestTokenParams { ValueToTransferToMvx: nil, ValueToSendFromMvX: big.NewInt(4010), }, - { - ValueToTransferToMvx: nil, - ValueToSendFromMvX: big.NewInt(2010), - MvxSCCallData: createScCallData("callPayable", 50000000), - }, }, - ESDTSafeExtraBalance: big.NewInt(150), // just the fees should be collected in ESDT safe + ESDTSafeExtraBalance: big.NewInt(0), } } diff --git a/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go b/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go index 7843ed71..265ff00a 100644 --- a/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go +++ b/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go @@ -52,8 +52,8 @@ func TestRelayersShouldNotExecuteTransfersWithNonWhitelistedTokens(t *testing.T) _ = testRelayersWithChainSimulatorAndTokens( t, make(chan error), - GenerateTestDOGEToken(), - GenerateTestBOBERToken(), + GenerateUnlistedTokenFromEth(), + GenerateUnlistedTokenFromMvx(), ) } diff --git a/integrationTests/relayers/slowTests/framework/multiversxHandler.go b/integrationTests/relayers/slowTests/framework/multiversxHandler.go index 6e83cc8e..d1746d93 100644 --- a/integrationTests/relayers/slowTests/framework/multiversxHandler.go +++ b/integrationTests/relayers/slowTests/framework/multiversxHandler.go @@ -48,7 +48,6 @@ const ( setWrappingContractAddressFunction = "setWrappingContractAddress" changeOwnerAddressFunction = "ChangeOwnerAddress" setEsdtSafeOnMultiTransferFunction = "setEsdtSafeOnMultiTransfer" - setEsdtSafeOnWrapperFunction = "setEsdtSafeContractAddress" setEsdtSafeAddressFunction = "setEsdtSafeAddress" moveRefundBatchToSafeFromChildContractFunction = "moveRefundBatchToSafeFromChildContract" getCurrentRefundBatchFunction = "getCurrentRefundBatch" @@ -262,7 +261,14 @@ func (handler *MultiversxHandler) wireMultiTransfer(ctx context.Context) { params := []string{ handler.ScProxyAddress.Hex(), } - hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.MultiTransferAddress, zeroStringValue, setCallsGasLimit, setBridgeProxyContractAddressFunction, params) + hash, txResult := handler.scCallAndCheckTx( + ctx, + handler.OwnerKeys, + handler.MultiTransferAddress, + zeroStringValue, + setCallsGasLimit, + setBridgeProxyContractAddressFunction, + params) log.Info("Set in multi-transfer contract the SC proxy contract", "transaction hash", hash, "status", txResult.Status) @@ -270,7 +276,14 @@ func (handler *MultiversxHandler) wireMultiTransfer(ctx context.Context) { params = []string{ handler.WrapperAddress.Hex(), } - hash, txResult = handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.MultiTransferAddress, zeroStringValue, setCallsGasLimit, setWrappingContractAddressFunction, params) + hash, txResult = handler.scCallAndCheckTx( + ctx, + handler.OwnerKeys, + handler.MultiTransferAddress, + zeroStringValue, + setCallsGasLimit, + setWrappingContractAddressFunction, + params) log.Info("Set in multi-transfer contract the wrapper contract", "transaction hash", hash, "status", txResult.Status) } @@ -280,7 +293,14 @@ func (handler *MultiversxHandler) wireSCProxy(ctx context.Context) { params := []string{ handler.WrapperAddress.Hex(), } - hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.ScProxyAddress, zeroStringValue, setCallsGasLimit, setBridgedTokensWrapperAddressFunction, params) + hash, txResult := handler.scCallAndCheckTx( + ctx, + handler.OwnerKeys, + handler.ScProxyAddress, + zeroStringValue, + setCallsGasLimit, + setBridgedTokensWrapperAddressFunction, + params) log.Info("Set in SC proxy contract the wrapper contract", "transaction hash", hash, "status", txResult.Status) @@ -288,7 +308,14 @@ func (handler *MultiversxHandler) wireSCProxy(ctx context.Context) { params = []string{ handler.MultiTransferAddress.Hex(), } - hash, txResult = handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.ScProxyAddress, zeroStringValue, setCallsGasLimit, setMultiTransferAddressFunction, params) + hash, txResult = handler.scCallAndCheckTx( + ctx, + handler.OwnerKeys, + handler.ScProxyAddress, + zeroStringValue, + setCallsGasLimit, + setMultiTransferAddressFunction, + params) log.Info("Set in SC proxy contract the multi-transfer contract", "transaction hash", hash, "status", txResult.Status) @@ -296,7 +323,14 @@ func (handler *MultiversxHandler) wireSCProxy(ctx context.Context) { params = []string{ handler.SafeAddress.Hex(), } - hash, txResult = handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.ScProxyAddress, zeroStringValue, setCallsGasLimit, setEsdtSafeAddressFunction, params) + hash, txResult = handler.scCallAndCheckTx( + ctx, + handler.OwnerKeys, + handler.ScProxyAddress, + zeroStringValue, + setCallsGasLimit, + setEsdtSafeAddressFunction, + params) log.Info("Set in SC proxy contract the safe contract", "transaction hash", hash, "status", txResult.Status) } @@ -306,7 +340,14 @@ func (handler *MultiversxHandler) wireSafe(ctx context.Context) { params := []string{ handler.WrapperAddress.Hex(), } - hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.SafeAddress, zeroStringValue, setCallsGasLimit, setBridgedTokensWrapperAddressFunction, params) + hash, txResult := handler.scCallAndCheckTx( + ctx, + handler.OwnerKeys, + handler.SafeAddress, + zeroStringValue, + setCallsGasLimit, + setBridgedTokensWrapperAddressFunction, + params) log.Info("Set in safe contract the wrapper contract", "transaction hash", hash, "status", txResult.Status) @@ -314,7 +355,14 @@ func (handler *MultiversxHandler) wireSafe(ctx context.Context) { params = []string{ handler.ScProxyAddress.Hex(), } - hash, txResult = handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.SafeAddress, zeroStringValue, setCallsGasLimit, setBridgeProxyContractAddressFunction, params) + hash, txResult = handler.scCallAndCheckTx( + ctx, + handler.OwnerKeys, + handler.SafeAddress, + zeroStringValue, + setCallsGasLimit, + setBridgeProxyContractAddressFunction, + params) log.Info("Set in safe contract the SC proxy contract", "transaction hash", hash, "status", txResult.Status) } @@ -324,7 +372,14 @@ func (handler *MultiversxHandler) changeOwners(ctx context.Context) { params := []string{ handler.MultisigAddress.Hex(), } - hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.SafeAddress, zeroStringValue, setCallsGasLimit, changeOwnerAddressFunction, params) + hash, txResult := handler.scCallAndCheckTx( + ctx, + handler.OwnerKeys, + handler.SafeAddress, + zeroStringValue, + setCallsGasLimit, + changeOwnerAddressFunction, + params) log.Info("ChangeOwnerAddress for safe contract", "transaction hash", hash, "status", txResult.Status) @@ -332,7 +387,14 @@ func (handler *MultiversxHandler) changeOwners(ctx context.Context) { params = []string{ handler.MultisigAddress.Hex(), } - hash, txResult = handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.MultiTransferAddress, zeroStringValue, setCallsGasLimit, changeOwnerAddressFunction, params) + hash, txResult = handler.scCallAndCheckTx( + ctx, + handler.OwnerKeys, + handler.MultiTransferAddress, + zeroStringValue, + setCallsGasLimit, + changeOwnerAddressFunction, + params) log.Info("ChangeOwnerAddress for multi-transfer contract", "transaction hash", hash, "status", txResult.Status) @@ -340,7 +402,14 @@ func (handler *MultiversxHandler) changeOwners(ctx context.Context) { params = []string{ handler.MultisigAddress.Hex(), } - hash, txResult = handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.ScProxyAddress, zeroStringValue, setCallsGasLimit, changeOwnerAddressFunction, params) + hash, txResult = handler.scCallAndCheckTx( + ctx, + handler.OwnerKeys, + handler.ScProxyAddress, + zeroStringValue, + setCallsGasLimit, + changeOwnerAddressFunction, + params) log.Info("ChangeOwnerAddress for SC proxy contract", "transaction hash", hash, "status", txResult.Status) } @@ -351,7 +420,14 @@ func (handler *MultiversxHandler) finishSettings(ctx context.Context) { log.Info("Un-paused SC proxy contract", "transaction hash", hash, "status", txResult.Status) // setEsdtSafeOnMultiTransfer - hash, txResult = handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.MultisigAddress, zeroStringValue, setCallsGasLimit, setEsdtSafeOnMultiTransferFunction, []string{}) + hash, txResult = handler.scCallAndCheckTx( + ctx, + handler.OwnerKeys, + handler.MultisigAddress, + zeroStringValue, + setCallsGasLimit, + setEsdtSafeOnMultiTransferFunction, + []string{}) log.Info("Set in multisig contract the safe contract (automatically)", "transaction hash", hash, "status", txResult.Status) @@ -419,7 +495,14 @@ func (handler *MultiversxHandler) GetESDTChainSpecificTokenBalance( } func (handler *MultiversxHandler) callContractNoParams(ctx context.Context, contract *MvxAddress, endpoint string) (string, *data.TransactionOnNetwork) { - return handler.sendAndCheckTx(ctx, handler.OwnerKeys, contract, zeroStringValue, setCallsGasLimit, endpoint, []string{}) + return handler.scCallAndCheckTx( + ctx, + handler.OwnerKeys, + contract, + zeroStringValue, + setCallsGasLimit, + endpoint, + []string{}) } // UnPauseContractsAfterTokenChanges can unpause contracts after token changes @@ -478,13 +561,13 @@ func (handler *MultiversxHandler) IssueAndWhitelistToken(ctx context.Context, pa func (handler *MultiversxHandler) issueAndWhitelistTokensWithChainSpecific(ctx context.Context, params IssueTokenParams) { handler.issueUniversalToken(ctx, params) handler.issueChainSpecificToken(ctx, params) + if params.PreventWhitelist { + return + } handler.setLocalRolesForUniversalTokenOnWrapper(ctx, params) handler.transferChainSpecificTokenToSCs(ctx, params) handler.addUniversalTokenToWrapper(ctx, params) - if !params.PreventWhitelist { - handler.whitelistTokenOnMultisig(ctx, params) - handler.whitelistTokenOnWrapper(ctx, params) - } + handler.whitelistTokenOnWrapper(ctx, params) handler.setRolesForSpecificTokenOnSafe(ctx, params) handler.addMappingInMultisig(ctx, params) handler.whitelistTokenOnMultisig(ctx, params) @@ -500,11 +583,13 @@ func (handler *MultiversxHandler) issueAndWhitelistTokens(ctx context.Context, p tkData := handler.TokensRegistry.GetTokenData(params.AbstractTokenIdentifier) handler.TokensRegistry.RegisterChainSpecificToken(params.AbstractTokenIdentifier, tkData.MvxUniversalToken) + if params.PreventWhitelist { + return + } + handler.setRolesForSpecificTokenOnSafe(ctx, params) handler.addMappingInMultisig(ctx, params) - if !params.PreventWhitelist { - handler.whitelistTokenOnMultisig(ctx, params) - } + handler.whitelistTokenOnMultisig(ctx, params) handler.setInitialSupply(ctx, params) handler.setPairDecimalsOnAggregator(ctx, params) handler.setMaxBridgeAmountOnSafe(ctx, params) @@ -527,7 +612,14 @@ func (handler *MultiversxHandler) issueUniversalToken(ctx context.Context, param hex.EncodeToString([]byte(canAddSpecialRoles)), hex.EncodeToString([]byte(trueStr))} - hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.ESDTSystemContractAddress, esdtIssueCost, issueTokenGasLimit, issueFunction, scCallParams) + hash, txResult := handler.scCallAndCheckTx( + ctx, + handler.OwnerKeys, + handler.ESDTSystemContractAddress, + esdtIssueCost, + issueTokenGasLimit, + issueFunction, + scCallParams) mvxUniversalToken := handler.getTokenNameFromResult(*txResult) require.Greater(handler, len(mvxUniversalToken), 0) handler.TokensRegistry.RegisterUniversalToken(params.AbstractTokenIdentifier, mvxUniversalToken) @@ -546,7 +638,14 @@ func (handler *MultiversxHandler) issueChainSpecificToken(ctx context.Context, p hex.EncodeToString([]byte(canAddSpecialRoles)), hex.EncodeToString([]byte(trueStr))} - hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.ESDTSystemContractAddress, esdtIssueCost, issueTokenGasLimit, issueFunction, scCallParams) + hash, txResult := handler.scCallAndCheckTx( + ctx, + handler.OwnerKeys, + handler.ESDTSystemContractAddress, + esdtIssueCost, + issueTokenGasLimit, + issueFunction, + scCallParams) mvxChainSpecificToken := handler.getTokenNameFromResult(*txResult) require.Greater(handler, len(mvxChainSpecificToken), 0) handler.TokensRegistry.RegisterChainSpecificToken(params.AbstractTokenIdentifier, mvxChainSpecificToken) @@ -563,7 +662,14 @@ func (handler *MultiversxHandler) setLocalRolesForUniversalTokenOnWrapper(ctx co hex.EncodeToString([]byte(esdtRoleLocalMint)), hex.EncodeToString([]byte(esdtRoleLocalBurn))} - hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.ESDTSystemContractAddress, zeroStringValue, setCallsGasLimit, setSpecialRoleFunction, scCallParams) + hash, txResult := handler.scCallAndCheckTx( + ctx, + handler.OwnerKeys, + handler.ESDTSystemContractAddress, + zeroStringValue, + setCallsGasLimit, + setSpecialRoleFunction, + scCallParams) log.Info("set local roles bridged tokens wrapper tx executed", "hash", hash, "status", txResult.Status) } @@ -581,7 +687,14 @@ func (handler *MultiversxHandler) transferChainSpecificTokenToSCs(ctx context.Co hex.EncodeToString(initialMintValue.Bytes()), hex.EncodeToString([]byte(depositLiquidityFunction))} - hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.WrapperAddress, zeroStringValue, setCallsGasLimit, esdtTransferFunction, scCallParams) + hash, txResult := handler.scCallAndCheckTx( + ctx, + handler.OwnerKeys, + handler.WrapperAddress, + zeroStringValue, + setCallsGasLimit, + esdtTransferFunction, + scCallParams) log.Info("transfer to wrapper sc tx executed", "hash", hash, "status", txResult.Status) @@ -590,7 +703,14 @@ func (handler *MultiversxHandler) transferChainSpecificTokenToSCs(ctx context.Co hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), hex.EncodeToString(initialMintValue.Bytes())} - hash, txResult = handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.SafeAddress, zeroStringValue, setCallsGasLimit, esdtTransferFunction, scCallParams) + hash, txResult = handler.scCallAndCheckTx( + ctx, + handler.OwnerKeys, + handler.SafeAddress, + zeroStringValue, + setCallsGasLimit, + esdtTransferFunction, + scCallParams) log.Info("transfer to safe sc tx executed", "hash", hash, "status", txResult.Status) } @@ -604,7 +724,14 @@ func (handler *MultiversxHandler) addUniversalTokenToWrapper(ctx context.Context fmt.Sprintf("%02x", params.NumOfDecimalsUniversal), } - hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.WrapperAddress, zeroStringValue, setCallsGasLimit, addWrappedTokenFunction, scCallParams) + hash, txResult := handler.scCallAndCheckTx( + ctx, + handler.OwnerKeys, + handler.WrapperAddress, + zeroStringValue, + setCallsGasLimit, + addWrappedTokenFunction, + scCallParams) log.Info("add wrapped token tx executed", "hash", hash, "status", txResult.Status) } @@ -618,7 +745,14 @@ func (handler *MultiversxHandler) whitelistTokenOnWrapper(ctx context.Context, p fmt.Sprintf("%02x", params.NumOfDecimalsChainSpecific), hex.EncodeToString([]byte(tkData.MvxUniversalToken))} - hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.WrapperAddress, zeroStringValue, setCallsGasLimit, whitelistTokenFunction, scCallParams) + hash, txResult := handler.scCallAndCheckTx( + ctx, + handler.OwnerKeys, + handler.WrapperAddress, + zeroStringValue, + setCallsGasLimit, + whitelistTokenFunction, + scCallParams) log.Info("wrapper whitelist token tx executed", "hash", hash, "status", txResult.Status) } @@ -633,7 +767,14 @@ func (handler *MultiversxHandler) setRolesForSpecificTokenOnSafe(ctx context.Con hex.EncodeToString([]byte(esdtRoleLocalMint)), hex.EncodeToString([]byte(esdtRoleLocalBurn))} - hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.ESDTSystemContractAddress, zeroStringValue, setCallsGasLimit, setSpecialRoleFunction, scCallParams) + hash, txResult := handler.scCallAndCheckTx( + ctx, + handler.OwnerKeys, + handler.ESDTSystemContractAddress, + zeroStringValue, + setCallsGasLimit, + setSpecialRoleFunction, + scCallParams) log.Info("set local roles esdt safe tx executed", "hash", hash, "status", txResult.Status) } @@ -646,7 +787,14 @@ func (handler *MultiversxHandler) addMappingInMultisig(ctx context.Context, para hex.EncodeToString(tkData.EthErc20Address.Bytes()), hex.EncodeToString([]byte(tkData.MvxChainSpecificToken))} - hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.MultisigAddress, zeroStringValue, setCallsGasLimit, addMappingFunction, scCallParams) + hash, txResult := handler.scCallAndCheckTx( + ctx, + handler.OwnerKeys, + handler.MultisigAddress, + zeroStringValue, + setCallsGasLimit, + addMappingFunction, + scCallParams) log.Info("add mapping tx executed", "hash", hash, "status", txResult.Status) } @@ -665,7 +813,14 @@ func (handler *MultiversxHandler) whitelistTokenOnMultisig(ctx context.Context, hex.EncodeToString(zeroValueBigInt.Bytes()), // burn_balance } - hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.MultisigAddress, zeroStringValue, setCallsGasLimit, esdtSafeAddTokenToWhitelistFunction, scCallParams) + hash, txResult := handler.scCallAndCheckTx( + ctx, + handler.OwnerKeys, + handler.MultisigAddress, + zeroStringValue, + setCallsGasLimit, + esdtSafeAddTokenToWhitelistFunction, + scCallParams) log.Info("whitelist token tx executed", "hash", hash, "status", txResult.Status) } @@ -693,7 +848,14 @@ func (handler *MultiversxHandler) setInitialSupply(ctx context.Context, params I hex.EncodeToString(mintAmount.Bytes()), hex.EncodeToString(burnAmount.Bytes()), } - hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.MultisigAddress, zeroStringValue, setCallsGasLimit, initSupplyMintBurnEsdtSafe, scCallParams) + hash, txResult := handler.scCallAndCheckTx( + ctx, + handler.OwnerKeys, + handler.MultisigAddress, + zeroStringValue, + setCallsGasLimit, + initSupplyMintBurnEsdtSafe, + scCallParams) log.Info("initial supply tx executed", "hash", hash, "status", txResult.Status, "initial mint", mintAmount.String(), "initial burned", burnAmount.String()) @@ -705,7 +867,14 @@ func (handler *MultiversxHandler) setInitialSupply(ctx context.Context, params I hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), hex.EncodeToString(initialSupply.Bytes()), } - hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.MultisigAddress, zeroStringValue, setCallsGasLimit, esdtTransferFunction, scCallParams) + hash, txResult := handler.scCallAndCheckTx( + ctx, + handler.OwnerKeys, + handler.MultisigAddress, + zeroStringValue, + setCallsGasLimit, + esdtTransferFunction, + scCallParams) log.Info("initial supply tx executed", "hash", hash, "status", txResult.Status, "initial value", params.InitialSupplyValue) @@ -719,7 +888,14 @@ func (handler *MultiversxHandler) setPairDecimalsOnAggregator(ctx context.Contex hex.EncodeToString([]byte(gwei)), hex.EncodeToString([]byte(params.MvxChainSpecificTokenTicker)), fmt.Sprintf("%02x", params.NumOfDecimalsChainSpecific)} - hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.AggregatorAddress, zeroStringValue, setCallsGasLimit, setPairDecimalsFunction, scCallParams) + hash, txResult := handler.scCallAndCheckTx( + ctx, + handler.OwnerKeys, + handler.AggregatorAddress, + zeroStringValue, + setCallsGasLimit, + setPairDecimalsFunction, + scCallParams) log.Info("setPairDecimals tx executed", "hash", hash, "status", txResult.Status) } @@ -732,7 +908,14 @@ func (handler *MultiversxHandler) setMaxBridgeAmountOnSafe(ctx context.Context, scCallParams := []string{ hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), hex.EncodeToString(maxBridgedAmountForTokenInt.Bytes())} - hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.MultisigAddress, zeroStringValue, setCallsGasLimit, esdtSafeSetMaxBridgedAmountForTokenFunction, scCallParams) + hash, txResult := handler.scCallAndCheckTx( + ctx, + handler.OwnerKeys, + handler.MultisigAddress, + zeroStringValue, + setCallsGasLimit, + esdtSafeSetMaxBridgedAmountForTokenFunction, + scCallParams) log.Info("safe set max bridge amount for token tx executed", "hash", hash, "status", txResult.Status) } @@ -745,7 +928,14 @@ func (handler *MultiversxHandler) setMaxBridgeAmountOnMultitransfer(ctx context. scCallParams := []string{ hex.EncodeToString([]byte(tkData.MvxChainSpecificToken)), hex.EncodeToString(maxBridgedAmountForTokenInt.Bytes())} - hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.MultisigAddress, zeroStringValue, setCallsGasLimit, multiTransferEsdtSetMaxBridgedAmountForTokenFunction, scCallParams) + hash, txResult := handler.scCallAndCheckTx( + ctx, + handler.OwnerKeys, + handler.MultisigAddress, + zeroStringValue, + setCallsGasLimit, + multiTransferEsdtSetMaxBridgedAmountForTokenFunction, + scCallParams) log.Info("multi-transfer set max bridge amount for token tx executed", "hash", hash, "status", txResult.Status) } @@ -828,7 +1018,14 @@ func (handler *MultiversxHandler) createTransactionWithoutUnwrap( } dataField := strings.Join(params, "@") - hash, txResult := handler.sendAndCheckTx(ctx, from, handler.SafeAddress, zeroStringValue, createDepositGasLimit+gasLimitPerDataByte*uint64(len(dataField)), esdtTransferFunction, params) + hash, txResult := handler.scCallAndCheckTx( + ctx, + from, + handler.SafeAddress, + zeroStringValue, + createDepositGasLimit+gasLimitPerDataByte*uint64(len(dataField)), + esdtTransferFunction, + params) log.Info("MultiversX->Ethereum createTransaction sent", "hash", hash, "token", token.MvxUniversalToken, "status", txResult.Status) } @@ -845,7 +1042,14 @@ func (handler *MultiversxHandler) unwrapCreateTransaction(ctx context.Context, t } dataField := strings.Join(params, "@") - hash, txResult := handler.sendAndCheckTx(ctx, from, handler.WrapperAddress, zeroStringValue, createDepositGasLimit+gasLimitPerDataByte*uint64(len(dataField)), esdtTransferFunction, params) + hash, txResult := handler.scCallAndCheckTx( + ctx, + from, + handler.WrapperAddress, + zeroStringValue, + createDepositGasLimit+gasLimitPerDataByte*uint64(len(dataField)), + esdtTransferFunction, + params) log.Info("MultiversX->Ethereum unwrapCreateTransaction sent", "hash", hash, "token", token.MvxUniversalToken, "status", txResult.Status) } @@ -912,7 +1116,14 @@ func (handler *MultiversxHandler) withdrawFees(ctx context.Context, params := []string{ hex.EncodeToString([]byte(token)), } - handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.MultisigAddress, zeroStringValue, generalSCCallGasLimit, withdrawFunction, params) + handler.scCallAndCheckTx( + ctx, + handler.OwnerKeys, + handler.MultisigAddress, + zeroStringValue, + generalSCCallGasLimit, + withdrawFunction, + params) handler.ChainSimulator.GenerateBlocks(ctx, 5) // ensure block finality finalBalanceStr := handler.ChainSimulator.GetESDTBalance(ctx, handler.OwnerKeys.MvxAddress, token) @@ -932,7 +1143,14 @@ func (handler *MultiversxHandler) TransferToken(ctx context.Context, source Keys scCallParams := []string{ hex.EncodeToString([]byte(tkData.MvxUniversalToken)), hex.EncodeToString(amount.Bytes())} - hash, txResult := handler.sendAndCheckTx(ctx, source, receiver.MvxAddress, zeroStringValue, createDepositGasLimit, esdtTransferFunction, scCallParams) + hash, txResult := handler.scCallAndCheckTx( + ctx, + source, + receiver.MvxAddress, + zeroStringValue, + createDepositGasLimit, + esdtTransferFunction, + scCallParams) log.Info("transfer to tx executed", "source address", source.MvxAddress.Bech32(), @@ -977,7 +1195,14 @@ func (handler *MultiversxHandler) GetBurnedAmountForToken(ctx context.Context, t // MoveRefundBatchToSafe will move the refund batch from the multisig to the safe func (handler *MultiversxHandler) MoveRefundBatchToSafe(ctx context.Context) { - hash, txResult := handler.sendAndCheckTx(ctx, handler.OwnerKeys, handler.MultisigAddress, zeroStringValue, setCallsGasLimit, moveRefundBatchToSafeFromChildContractFunction, []string{}) + hash, txResult := handler.scCallAndCheckTx( + ctx, + handler.OwnerKeys, + handler.MultisigAddress, + zeroStringValue, + setCallsGasLimit, + moveRefundBatchToSafeFromChildContractFunction, + []string{}) log.Info("Moved refund batch from Multisig to EsdtSafe", "transaction hash", hash, "status", txResult.Status) } @@ -987,7 +1212,14 @@ func (handler *MultiversxHandler) HasRefundBatch(ctx context.Context) bool { return len(responseData) != 0 } -func (handler *MultiversxHandler) sendAndCheckTx(ctx context.Context, sender KeysHolder, receiver *MvxAddress, value string, gasLimit uint64, function string, params []string) (string, *data.TransactionOnNetwork) { +func (handler *MultiversxHandler) scCallAndCheckTx( + ctx context.Context, + sender KeysHolder, + receiver *MvxAddress, + value string, + gasLimit uint64, + function string, + params []string) (string, *data.TransactionOnNetwork) { hash, txResult, txStatus := handler.ChainSimulator.ScCall( ctx, sender.MvxSk, diff --git a/integrationTests/relayers/slowTests/framework/testSetup.go b/integrationTests/relayers/slowTests/framework/testSetup.go index 27152a09..c38021d7 100644 --- a/integrationTests/relayers/slowTests/framework/testSetup.go +++ b/integrationTests/relayers/slowTests/framework/testSetup.go @@ -33,6 +33,7 @@ const ( type currentBridge string +// CurrentActorState represents the state of an actor in a transaction type CurrentActorState struct { isSender bool HasToReceiveRefund bool From 62ef2a3ec2fc9fe1302c470a6e2078814bdf3556 Mon Sep 17 00:00:00 2001 From: cosmatudor Date: Mon, 2 Dec 2024 14:17:01 +0200 Subject: [PATCH 09/17] fixes --- integrationTests/relayers/slowTests/common.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/integrationTests/relayers/slowTests/common.go b/integrationTests/relayers/slowTests/common.go index a72a4838..f09a1a73 100644 --- a/integrationTests/relayers/slowTests/common.go +++ b/integrationTests/relayers/slowTests/common.go @@ -279,19 +279,19 @@ func GenerateTestMEXToken() framework.TestTokenParams { func GenerateUnlistedTokenFromEth() framework.TestTokenParams { return framework.TestTokenParams{ IssueTokenParams: framework.IssueTokenParams{ - AbstractTokenIdentifier: "ULTkE", + AbstractTokenIdentifier: "ULTKE", NumOfDecimalsUniversal: 6, NumOfDecimalsChainSpecific: 6, - MvxUniversalTokenTicker: "ULTkE", - MvxChainSpecificTokenTicker: "ULTkE", - MvxUniversalTokenDisplayName: "TestULTkE", - MvxChainSpecificTokenDisplayName: "TestULTkE", + MvxUniversalTokenTicker: "ULTKE", + MvxChainSpecificTokenTicker: "ULTKE", + MvxUniversalTokenDisplayName: "TestULTKE", + MvxChainSpecificTokenDisplayName: "TestULTKE", ValueToMintOnMvx: "10000000000", IsMintBurnOnMvX: true, IsNativeOnMvX: false, HasChainSpecificToken: false, - EthTokenName: "EthULTkE", - EthTokenSymbol: "ULTkE", + EthTokenName: "EthULTKE", + EthTokenSymbol: "ULTKE", ValueToMintOnEth: "10000000000", IsMintBurnOnEth: true, IsNativeOnEth: true, @@ -341,6 +341,11 @@ func GenerateUnlistedTokenFromMvx() framework.TestTokenParams { ValueToTransferToMvx: nil, ValueToSendFromMvX: big.NewInt(4010), }, + { + ValueToTransferToMvx: nil, + ValueToSendFromMvX: big.NewInt(2010), + MvxSCCallData: createScCallData("callPayable", 50000000), + }, }, ESDTSafeExtraBalance: big.NewInt(0), } From 610f8f93c88fd4bf2c69d1591334424f40caede0 Mon Sep 17 00:00:00 2001 From: cosmatudor Date: Mon, 2 Dec 2024 14:53:52 +0200 Subject: [PATCH 10/17] delete unused files --- docker/docker-compose.yaml | 140 ------------------------------------- docker/scripts/send-tx.sh | 64 ----------------- 2 files changed, 204 deletions(-) delete mode 100644 docker/docker-compose.yaml delete mode 100755 docker/scripts/send-tx.sh diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml deleted file mode 100644 index 3429227f..00000000 --- a/docker/docker-compose.yaml +++ /dev/null @@ -1,140 +0,0 @@ -version: "3.9" - -services: - rabbitmq: - ports: - - 127.0.0.1:5672:5672 - - 127.0.0.1:15672:15672 - container_name: rabbitmq-container - image: "rabbitmq:3-management" - healthcheck: - test: rabbitmq-diagnostics -q ping - interval: 10s - timeout: 5s - retries: 5 - - redis: - image: "redis:alpine" - command: redis-server - ports: - - "127.0.0.1:6379:6379" - environment: - - REDIS_REPLICATION_MODE=master - - events-notifier: - container_name: events-notifier-container - image: multiversx/events-notifier:latest - depends_on: - rabbitmq: - condition: service_healthy - entrypoint: > - /bin/bash -c "apt-get update && apt-get install curl -y - && sed -i '/Enabled will determine if websocket connector will be enabled or not/{n;s/Enabled = false/Enabled = true/}' ./config/config.toml - && sed -i 's|localhost:22111|0.0.0.0:22111|g' ./config/config.toml - && sed -i 's|localhost:6379|redis:6379|g' ./config/config.toml - && sed -i 's|amqp://guest:guest@localhost:5672|amqp://guest:guest@rabbitmq:5672|g' ./config/config.toml - && cat ./config/config.toml - && ./notifier --check-duplicates=false --api-type=rabbit-api" - healthcheck: - test: ["CMD", "curl", "-f", "http://127.0.0.1:5000/status/metrics"] - interval: 10s - timeout: 5s - retries: 5 - - elasticsearch: - ports: - - 127.0.0.1:9200:9200 - container_name: elasticsearch-container - image: docker.elastic.co/elasticsearch/elasticsearch:7.16.1 - environment: - - "discovery.type=single-node" - - "xpack.security.enabled=false" - - "ES_JAVA_OPTS=-Xms512m -Xmx512m" - ulimits: - memlock: - soft: -1 - hard: -1 - healthcheck: - test: ["CMD", "curl", "-f", "http://127.0.0.1:9200"] - interval: 10s - timeout: 5s - retries: 5 - - # TODO use the websockets based elastic indexer when the communication problems are solved - elastic-indexer: - #ports: 22112 - container_name: elastic-indexer - image: multiversx/elastic-indexer:latest - depends_on: - elasticsearch: - condition: service_healthy - entrypoint: > - /bin/bash -c "sed -i 's|http://localhost:9200|http://elasticsearch:9200|g' ./config/prefs.toml - && sed -i 's|url = \"localhost:22111\"|url = \"0.0.0.0:22111\"|g' ./config/prefs.toml - && cat ./config/prefs.toml - && ./elasticindexer -log-level *:DEBUG" - - chain-simulator: - container_name: chain-simulator - ports: - - 8085:8085 - image: multiversx/chainsimulator:latest - environment: - EVENTS_NOTIFIER_URL: 'events-notifier:22111' - ELASTIC_SEARCH_URL: 'elasticsearch:9200' # just a dummy string for now - depends_on: - elasticsearch: - condition: service_healthy - events-notifier: - condition: service_healthy - entrypoint: > - /bin/bash -c " sed -i 's|http://localhost:9200|http://elasticsearch:9200|g' ./config/node/config/external.toml - && ./start-with-services.sh -log-level *:INFO" - healthcheck: - test: [ "CMD", "curl", "-f", "http://127.0.0.1:8085/simulator/observers" ] - interval: 10s - timeout: 5s - retries: 5 - - api: - ports: - - 127.0.0.1:3001:3001 - container_name: api - image: multiversx/mx-api-service:test1 - environment: - MVX_ENV: devnet - REDIS_IP: redis - GATEWAY_URL: http://chain-simulator:8085 - ELASTICSEARCH_URL: http://elasticsearch:9200 - depends_on: - elasticsearch: - condition: service_healthy - redis: - condition: service_started - - explorer: - ports: - - 3002:80 - container_name: explorer - image: multiversx/mx-explorer-dapp:main - environment: - START_NAME_STOP: devnet - START_CHAIN_ID_STOP: D - START_EGLD_LABEL_STOP: xEGLD - START_WALLET_ADDRESS_STOP: https://devnet-wallet.multiversx.com - START_EXPLORER_ADDRESS_STOP: https://devnet-explorer.multiversx.com - START_NFT_EXPLORER_ADDRESS_STOP: https://devnet.xspotlight.com - START_API_ADDRESS_STOP: http://127.0.0.1:3001 - - lite-wallet: - ports: - - 3003:80 - container_name: lite-wallet - image: multiversx/mx-lite-wallet-dapp:main - environment: - START_NETWORK_ID_STOP: custom - START_NETWORK_NAME_STOP: custom - START_API_ADDRESS_STOP: http://127.0.0.1:3001 - START_GATEWAY_URL_STOP: http://127.0.0.1:8085 - START_WALLET_ADDRESS_STOP: https://testnet-wallet.multiversx.com - START_WEGLD_ID_STOP: xEGLD diff --git a/docker/scripts/send-tx.sh b/docker/scripts/send-tx.sh deleted file mode 100755 index 1455196e..00000000 --- a/docker/scripts/send-tx.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/bash - -# Call the endpoint and store the response in a variable -response=$(curl -s "http://localhost:8085/simulator/initial-wallets") - -# Use jq to extract the "bech32" address from the JSON response -bech32_address=$(echo "$response" | jq -r '.data.balanceWallets | to_entries[0].value.address.bech32') - -# Print the address to verify it was extracted correctly -echo "Extracted Bech32 Address: $bech32_address" - -# Get account information -account_info_response=$(curl -s --request GET \ - --url "http://localhost:8085/address/$bech32_address" \ - --header 'User-Agent: insomnia/10.0.0') - -# Print the response for debugging -echo "Account info response: $account_info_response" - -# Step 2: Extract the nonce using jq -nonce=$(echo "$account_info_response" | jq -r '.data.account.nonce') - -# Check if nonce is not empty -if [ -n "$nonce" ]; then - echo "Extracted nonce: $nonce" -else - echo "Error: No nonce found in the account info response." - exit 1 -fi - -tx_send_response=$(curl -s --request POST \ - --url http://localhost:8085/transaction/send \ - --header 'Content-Type: application/json' \ - --header 'User-Agent: insomnia/10.0.0' \ - --data '{ - "nonce": '$nonce', - "value": "50000000000000000000", - "sender": "'$bech32_address'", - "receiver": "erd12js50s7ycclwpac4qpx7lty3prhpu8hy00thjgz9f67p33w7m94qmzttem", - "gasLimit": 50000, - "gasPrice": 1000000000, - "chainId": "chain", - "signature": "aa", - "version": 1 -}') - -echo $tx_send_response - -# Extract txHash using jq -tx_hash=$(echo "$tx_send_response" | jq -r '.data.txHash') - -# Print the extracted txHash -echo "Extracted txHash: $tx_hash" - -sleep 2 - -# Make the second call to generate blocks until the transaction is processed -generate_blocks_response=$(curl -s --request POST \ - --url "http://localhost:8085/simulator/generate-blocks-until-transaction-processed/$tx_hash" \ - --header 'Content-Type: application/json' \ - --header 'User-Agent: insomnia/10.0.0') - -# Print the response from the second call -echo "Response from generate blocks: $generate_blocks_response" From 4a32880d6d59ec073801727d31380edaf4680bac Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Mon, 2 Dec 2024 17:54:39 +0200 Subject: [PATCH 11/17] - fixes after merge --- integrationTests/relayers/slowTests/common.go | 136 ++++++++++++++++-- .../ethToMultiversXWithChainSimulator_test.go | 2 +- .../relayers/slowTests/framework/testSetup.go | 55 +------ .../refundWithChainSimulator_test.go | 2 +- .../slowTests/startsFromEthereumFlow.go | 19 +-- .../slowTests/startsFromMultiversxFlow.go | 11 -- 6 files changed, 130 insertions(+), 95 deletions(-) diff --git a/integrationTests/relayers/slowTests/common.go b/integrationTests/relayers/slowTests/common.go index 864dd172..699f16a2 100644 --- a/integrationTests/relayers/slowTests/common.go +++ b/integrationTests/relayers/slowTests/common.go @@ -68,7 +68,7 @@ func GenerateTestUSDCToken() framework.TestTokenParams { DeltaBalances: map[framework.HalfBridgeIdentifier]framework.DeltaBalancesOnKeys{ framework.FirstHalfBridge: map[string]*framework.DeltaBalanceHolder{ framework.Alice: { - OnEth: big.NewInt(-5000 - 7000 - 1000), + OnEth: big.NewInt(-5000 - 7000 - 1000 - 900), OnMvx: big.NewInt(0), MvxToken: framework.UniversalToken, }, @@ -78,7 +78,7 @@ func GenerateTestUSDCToken() framework.TestTokenParams { MvxToken: framework.UniversalToken, }, framework.SafeSC: { - OnEth: big.NewInt(5000 + 7000 + 1000), + OnEth: big.NewInt(5000 + 7000 + 1000 + 900), OnMvx: big.NewInt(0), MvxToken: framework.ChainSpecificToken, }, @@ -90,7 +90,7 @@ func GenerateTestUSDCToken() framework.TestTokenParams { }, framework.SecondHalfBridge: map[string]*framework.DeltaBalanceHolder{ framework.Alice: { - OnEth: big.NewInt(-5000 - 7000 - 1000), + OnEth: big.NewInt(-5000 - 7000 - 1000 - 900 + 850), // 850 is the refund value OnMvx: big.NewInt(0), MvxToken: framework.UniversalToken, }, @@ -105,8 +105,8 @@ func GenerateTestUSDCToken() framework.TestTokenParams { MvxToken: framework.UniversalToken, }, framework.SafeSC: { - OnEth: big.NewInt(5000 + 7000 + 1000 - 2450 - 250), - OnMvx: big.NewInt(50 + 50), + OnEth: big.NewInt(5000 + 7000 + 1000 + 900 - 2450 - 250 - 850), + OnMvx: big.NewInt(50 + 50 + 50), MvxToken: framework.ChainSpecificToken, }, framework.CalledTestSC: { @@ -122,11 +122,11 @@ func GenerateTestUSDCToken() framework.TestTokenParams { // ApplyUSDCRefundBalances will apply the refund balances on the involved entities for the USDC token func ApplyUSDCRefundBalances(token *framework.TestTokenParams) { // extra is just for the fees for the 2 transfers mvx->eth and the failed eth->mvx that needed refund - token.DeltaBalances[framework.SecondHalfBridge][framework.SafeSC].OnMvx = big.NewInt(50 + 50 + 50) + token.DeltaBalances[framework.SecondHalfBridge][framework.SafeSC].OnMvx = big.NewInt(50 + 50 + 50 + 50) // we need to subtract the refunded value from the Ethereum Safe contract - token.DeltaBalances[framework.SecondHalfBridge][framework.SafeSC].OnEth = big.NewInt(5000 + 7000 + 1000 - 2450 - 250 - 950) + token.DeltaBalances[framework.SecondHalfBridge][framework.SafeSC].OnEth = big.NewInt(5000 + 7000 + 1000 + 900 - 2450 - 250 - 950 - 850) // Alice will get her tokens back from the refund - token.DeltaBalances[framework.SecondHalfBridge][framework.Alice].OnEth = big.NewInt(-5000 - 7000 - 1000 + 950) + token.DeltaBalances[framework.SecondHalfBridge][framework.Alice].OnEth = big.NewInt(-5000 - 7000 - 1000 - 900 + 950 + 850) // no funds remain in the test caller SC token.DeltaBalances[framework.SecondHalfBridge][framework.CalledTestSC].OnMvx = big.NewInt(0) } @@ -288,7 +288,7 @@ func GenerateTestEUROCToken() framework.TestTokenParams { DeltaBalances: map[framework.HalfBridgeIdentifier]framework.DeltaBalancesOnKeys{ framework.FirstHalfBridge: map[string]*framework.DeltaBalanceHolder{ framework.Alice: { - OnEth: big.NewInt(-5010 - 7010 - 1010), + OnEth: big.NewInt(-5010 - 7010 - 1010 - 700), OnMvx: big.NewInt(0), MvxToken: framework.UniversalToken, }, @@ -310,7 +310,7 @@ func GenerateTestEUROCToken() framework.TestTokenParams { }, framework.SecondHalfBridge: map[string]*framework.DeltaBalanceHolder{ framework.Alice: { - OnEth: big.NewInt(-5010 - 7010 - 1010), + OnEth: big.NewInt(-5010 - 7010 - 1010 - 700 + 650), // 650 is the refund value OnMvx: big.NewInt(0), MvxToken: framework.UniversalToken, }, @@ -326,7 +326,7 @@ func GenerateTestEUROCToken() framework.TestTokenParams { }, framework.SafeSC: { OnEth: big.NewInt(0), - OnMvx: big.NewInt(50 + 50), + OnMvx: big.NewInt(50 + 50 + 50), MvxToken: framework.ChainSpecificToken, }, framework.CalledTestSC: { @@ -481,7 +481,62 @@ func GenerateUnlistedTokenFromEth() framework.TestTokenParams { IsFaultyDeposit: true, }, }, - ESDTSafeExtraBalance: big.NewInt(0), + DeltaBalances: map[framework.HalfBridgeIdentifier]framework.DeltaBalancesOnKeys{ + framework.FirstHalfBridge: map[string]*framework.DeltaBalanceHolder{ + framework.Alice: { + OnEth: big.NewInt(0), + OnMvx: big.NewInt(0), + MvxToken: framework.UniversalToken, + }, + framework.Bob: { + OnEth: big.NewInt(0), + OnMvx: big.NewInt(0), + MvxToken: framework.UniversalToken, + }, + framework.Charlie: { + OnEth: big.NewInt(0), + OnMvx: big.NewInt(0), + MvxToken: framework.UniversalToken, + }, + framework.SafeSC: { + OnEth: big.NewInt(0), + OnMvx: big.NewInt(0), + MvxToken: framework.ChainSpecificToken, + }, + framework.CalledTestSC: { + OnEth: big.NewInt(0), + OnMvx: big.NewInt(0), + MvxToken: framework.UniversalToken, + }, + }, + framework.SecondHalfBridge: map[string]*framework.DeltaBalanceHolder{ + framework.Alice: { + OnEth: big.NewInt(0), + OnMvx: big.NewInt(0), + MvxToken: framework.UniversalToken, + }, + framework.Bob: { + OnEth: big.NewInt(0), + OnMvx: big.NewInt(0), + MvxToken: framework.UniversalToken, + }, + framework.Charlie: { + OnEth: big.NewInt(0), + OnMvx: big.NewInt(0), + MvxToken: framework.UniversalToken, + }, + framework.SafeSC: { + OnEth: big.NewInt(0), + OnMvx: big.NewInt(0), + MvxToken: framework.ChainSpecificToken, + }, + framework.CalledTestSC: { + OnEth: big.NewInt(0), + OnMvx: big.NewInt(0), + MvxToken: framework.UniversalToken, + }, + }, + }, } } @@ -518,7 +573,62 @@ func GenerateUnlistedTokenFromMvx() framework.TestTokenParams { MvxSCCallData: createScCallData("callPayable", 50000000), }, }, - ESDTSafeExtraBalance: big.NewInt(0), + DeltaBalances: map[framework.HalfBridgeIdentifier]framework.DeltaBalancesOnKeys{ + framework.FirstHalfBridge: map[string]*framework.DeltaBalanceHolder{ + framework.Alice: { + OnEth: big.NewInt(0), + OnMvx: big.NewInt(0), + MvxToken: framework.UniversalToken, + }, + framework.Bob: { + OnEth: big.NewInt(0), + OnMvx: big.NewInt(0), + MvxToken: framework.UniversalToken, + }, + framework.Charlie: { + OnEth: big.NewInt(0), + OnMvx: big.NewInt(0), + MvxToken: framework.UniversalToken, + }, + framework.SafeSC: { + OnEth: big.NewInt(0), + OnMvx: big.NewInt(0), + MvxToken: framework.ChainSpecificToken, + }, + framework.CalledTestSC: { + OnEth: big.NewInt(0), + OnMvx: big.NewInt(0), + MvxToken: framework.UniversalToken, + }, + }, + framework.SecondHalfBridge: map[string]*framework.DeltaBalanceHolder{ + framework.Alice: { + OnEth: big.NewInt(0), + OnMvx: big.NewInt(0), + MvxToken: framework.UniversalToken, + }, + framework.Bob: { + OnEth: big.NewInt(0), + OnMvx: big.NewInt(0), + MvxToken: framework.UniversalToken, + }, + framework.Charlie: { + OnEth: big.NewInt(0), + OnMvx: big.NewInt(0), + MvxToken: framework.UniversalToken, + }, + framework.SafeSC: { + OnEth: big.NewInt(0), + OnMvx: big.NewInt(0), + MvxToken: framework.ChainSpecificToken, + }, + framework.CalledTestSC: { + OnEth: big.NewInt(0), + OnMvx: big.NewInt(0), + MvxToken: framework.UniversalToken, + }, + }, + }, } } diff --git a/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go b/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go index 3731dbc8..5ef5a02e 100644 --- a/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go +++ b/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go @@ -191,7 +191,7 @@ func testRelayersWithChainSimulatorAndTokens(tb testing.TB, manualStopChan chan } processFunc := func(tb testing.TB, setup *framework.TestSetup) bool { - if startsFromEthFlow.process() && startsFromMvXFlow.process() && startsFromEthFlow.areTokensFullyRefunded() { + if startsFromEthFlow.process() && startsFromMvXFlow.process() { setup.TestWithdrawTotalFeesOnEthereumForTokens(startsFromMvXFlow.tokens...) setup.TestWithdrawTotalFeesOnEthereumForTokens(startsFromEthFlow.tokens...) diff --git a/integrationTests/relayers/slowTests/framework/testSetup.go b/integrationTests/relayers/slowTests/framework/testSetup.go index 6ee2873d..4c911efb 100644 --- a/integrationTests/relayers/slowTests/framework/testSetup.go +++ b/integrationTests/relayers/slowTests/framework/testSetup.go @@ -29,23 +29,6 @@ const ( mvxHrp = "erd" ) -// CurrentActorState represents the state of an actor in a transaction -type CurrentActorState struct { - isSender bool - HasToReceiveRefund bool -} - -var ( - senderState = CurrentActorState{ - isSender: true, - HasToReceiveRefund: false, - } - receiverState = CurrentActorState{ - isSender: false, - HasToReceiveRefund: false, - } -) - // TestSetup is the struct that holds all subcomponents for the testing infrastructure type TestSetup struct { testing.TB @@ -331,7 +314,7 @@ func (setup *TestSetup) getMvxAddressFromEntityName(entityName string) *MvxAddre return nil } -func (setup *TestSetup) getBalanceMappingForAddressAndToken(addr string, token TestTokenParams) *big.Int { +func (setup *TestSetup) getBalanceMappingForAddressAndToken(address string, token TestTokenParams) *big.Int { setup.mutBalances.Lock() defer setup.mutBalances.Unlock() @@ -385,18 +368,6 @@ func (setup *TestSetup) getEthAddressFromEntityName(entityName string) (common.A return common.Address{}, false } -func (setup *TestSetup) getExtraBalanceForHolder(address string, params TestTokenParams) ExtraBalanceHolder { - setup.mutBalances.Lock() - defer setup.mutBalances.Unlock() - - holderName := AddressZero - if address != "" { - holderName = setup.AddressToName[address] - } - - return params.ExtraBalances[holderName] -} - func (setup *TestSetup) checkContractMvxBalanceForToken(params TestTokenParams) bool { mvxBalance := setup.MultiversxHandler.GetESDTUniversalTokenBalance(setup.Ctx, setup.MultiversxHandler.CalleeScAddress, params.AbstractTokenIdentifier) expectedValueOnContract := big.NewInt(0) @@ -484,30 +455,6 @@ func (setup *TestSetup) computeExpectedValueFromMvx(params TestTokenParams) *big return expectedValue } -// IsTransferDoneFromEthereumWithRefund returns true if all provided tokens are bridged from Ethereum towards MultiversX including refunds -func (setup *TestSetup) IsTransferDoneFromEthereumWithRefund(holder KeysHolder, tokens ...TestTokenParams) bool { - isDone := true - for _, params := range tokens { - isDone = isDone && setup.isTransferDoneFromEthWithRefundForToken(holder, params) - } - - return isDone -} - -func (setup *TestSetup) isTransferDoneFromEthWithRefundForToken(holder KeysHolder, params TestTokenParams) bool { - // if token is prevented from whitelist, we can't check the balances - if params.PreventWhitelist { - return true - } - - actorState := CurrentActorState{ - isSender: true, - HasToReceiveRefund: true, - } - - return setup.checkHolderEthBalanceForToken(holder, actorState, params) -} - func (setup *TestSetup) checkMvxBurnedTokenBalance(params TestTokenParams) bool { token := setup.GetTokenData(params.AbstractTokenIdentifier) burnedTokens := setup.MultiversxHandler.GetBurnedAmountForToken(setup.Ctx, token.MvxChainSpecificToken) diff --git a/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go b/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go index da94d5f4..f673c248 100644 --- a/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go +++ b/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go @@ -266,7 +266,7 @@ func testRelayersWithChainSimulatorAndTokensAndRefund(tb testing.TB, manualStopC } processFunc := func(tb testing.TB, setup *framework.TestSetup) bool { - if startsFromEthFlow.process() && startsFromMvXFlow.process() && startsFromMvXFlow.areTokensFullyRefunded() { + if startsFromEthFlow.process() && startsFromMvXFlow.process() { return true } diff --git a/integrationTests/relayers/slowTests/startsFromEthereumFlow.go b/integrationTests/relayers/slowTests/startsFromEthereumFlow.go index ad2ce16b..d77f0451 100644 --- a/integrationTests/relayers/slowTests/startsFromEthereumFlow.go +++ b/integrationTests/relayers/slowTests/startsFromEthereumFlow.go @@ -37,6 +37,10 @@ func (flow *startsFromEthereumFlow) process() (finished bool) { return false } + if flow.setup.MultiversxHandler.HasRefundBatch(flow.setup.Ctx) { + flow.setup.MultiversxHandler.MoveRefundBatchToSafe(flow.setup.Ctx) + } + transferDoneForSecondHalf := flow.setup.AreAllTransfersCompleted(framework.SecondHalfBridge, flow.tokens...) if !flow.mvxToEthDone && transferDoneForSecondHalf { flow.mvxToEthDone = true @@ -46,18 +50,3 @@ func (flow *startsFromEthereumFlow) process() (finished bool) { return false } - -func (flow *startsFromEthereumFlow) areTokensFullyRefunded() bool { - if len(flow.tokens) == 0 { - return true - } - if !flow.ethToMvxDone { - return false // regular flow is not completed - } - - if flow.setup.MultiversxHandler.HasRefundBatch(flow.setup.Ctx) { - flow.setup.MultiversxHandler.MoveRefundBatchToSafe(flow.setup.Ctx) - } - - return flow.setup.IsTransferDoneFromEthereumWithRefund(flow.setup.AliceKeys, flow.tokens...) -} diff --git a/integrationTests/relayers/slowTests/startsFromMultiversxFlow.go b/integrationTests/relayers/slowTests/startsFromMultiversxFlow.go index 75133f6d..bf048c2f 100644 --- a/integrationTests/relayers/slowTests/startsFromMultiversxFlow.go +++ b/integrationTests/relayers/slowTests/startsFromMultiversxFlow.go @@ -49,14 +49,3 @@ func (flow *startsFromMultiversXFlow) process() (finished bool) { return false } - -func (flow *startsFromMultiversXFlow) areTokensFullyRefunded() bool { - if len(flow.tokens) == 0 { - return true - } - if !flow.ethToMvxDone { - return false // regular flow is not completed - } - - return flow.setup.IsTransferDoneFromEthereumWithRefund(flow.setup.BobKeys, flow.tokens...) -} From 8d096b31f84fab5e51ac8410f018ff259f7d370b Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Tue, 3 Dec 2024 09:49:32 +0200 Subject: [PATCH 12/17] - fixes after merge --- integrationTests/relayers/slowTests/testFlow.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/integrationTests/relayers/slowTests/testFlow.go b/integrationTests/relayers/slowTests/testFlow.go index 14ca0100..5840ba81 100644 --- a/integrationTests/relayers/slowTests/testFlow.go +++ b/integrationTests/relayers/slowTests/testFlow.go @@ -49,6 +49,10 @@ func (flow *testFlow) process() (finished bool) { return false } + if flow.setup.MultiversxHandler.HasRefundBatch(flow.setup.Ctx) { + flow.setup.MultiversxHandler.MoveRefundBatchToSafe(flow.setup.Ctx) + } + transferDoneForSecondHalf := flow.setup.AreAllTransfersCompleted(framework.SecondHalfBridge, flow.tokens...) if !flow.secondHalfBridgeDone && transferDoneForSecondHalf { flow.secondHalfBridgeDone = true From cebcf2f20f6c4d242184f031c5407fa79b27e111 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Tue, 3 Dec 2024 10:01:23 +0200 Subject: [PATCH 13/17] - fixes after merge --- .../relayers/slowTests/refundWithChainSimulator_test.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go b/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go index 0c8ee5b4..974ccabb 100644 --- a/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go +++ b/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go @@ -267,9 +267,6 @@ func testRelayersWithChainSimulatorAndTokensAndRefund(tb testing.TB, manualStopC allFlowsFinished := true for _, flow := range flows { allFlowsFinished = allFlowsFinished && flow.process() - if flow.flowType == startFromMultiversXFlow && len(flow.tokens) >= 0 { - allFlowsFinished = allFlowsFinished && flow.setup.IsTransferDoneFromEthereumWithRefund(flow.tokens...) - } } // commit blocks in order to execute incoming txs from relayers From 9dba4b6025b03735d8bff7c16c121f85224dab83 Mon Sep 17 00:00:00 2001 From: cosmatudor Date: Tue, 3 Dec 2024 14:54:40 +0200 Subject: [PATCH 14/17] refactor extra balances --- integrationTests/relayers/slowTests/common.go | 36 ++++++++++--------- .../refundWithChainSimulator_test.go | 34 +++++++++++------- 2 files changed, 41 insertions(+), 29 deletions(-) diff --git a/integrationTests/relayers/slowTests/common.go b/integrationTests/relayers/slowTests/common.go index 2ff81a90..b5d03720 100644 --- a/integrationTests/relayers/slowTests/common.go +++ b/integrationTests/relayers/slowTests/common.go @@ -70,7 +70,7 @@ func GenerateTestUSDCToken() framework.TestTokenParams { }, framework.CalledTestSC: { OnEth: big.NewInt(0), - OnMvx: big.NewInt(0), + OnMvx: big.NewInt(1000), MvxToken: framework.UniversalToken, }, }, @@ -82,11 +82,11 @@ func GenerateTestUSDCToken() framework.TestTokenParams { }, framework.Bob: { OnEth: big.NewInt(0), - OnMvx: big.NewInt(2500 + 6700), + OnMvx: big.NewInt(5000 - 2500 + 7000 - 300), MvxToken: framework.UniversalToken, }, framework.Charlie: { - OnEth: big.NewInt(2450 + 250), + OnEth: big.NewInt(2500 - 50 + 300 - 50), OnMvx: big.NewInt(0), MvxToken: framework.UniversalToken, }, @@ -107,25 +107,15 @@ func GenerateTestUSDCToken() framework.TestTokenParams { // ApplyUSDCRefundBalances will apply the refund balances on the involved entities for the USDC token func ApplyUSDCRefundBalances(token *framework.TestTokenParams) { + // called test SC will have 0 balance since eth->mvx transfer failed + token.DeltaBalances[framework.FirstHalfBridge][framework.CalledTestSC].OnMvx = big.NewInt(0) // extra is just for the fees for the 2 transfers mvx->eth and the failed eth->mvx that needed refund token.DeltaBalances[framework.SecondHalfBridge][framework.SafeSC].OnMvx = big.NewInt(50 + 50 + 50) // we need to subtract the refunded value from the Ethereum Safe contract token.DeltaBalances[framework.SecondHalfBridge][framework.SafeSC].OnEth = big.NewInt(5000 + 7000 + 1000 - 2450 - 250 - 950) // Alice will get her tokens back from the refund token.DeltaBalances[framework.SecondHalfBridge][framework.Alice].OnEth = big.NewInt(-5000 - 7000 - 1000 + 950) - // no funds remain in the test caller SC - token.DeltaBalances[framework.SecondHalfBridge][framework.CalledTestSC].OnMvx = big.NewInt(0) -} - -// ApplyEUROCRefundBalances will apply the refund balances on the involved entities for the EUROC token -func ApplyEUROCRefundBalances(token *framework.TestTokenParams) { - // Adjust SafeSC.OnMvx to account for the fees for the 2 transfers and the failed one that needed refund - token.DeltaBalances[framework.SecondHalfBridge][framework.SafeSC].OnMvx = big.NewInt(50 + 50 + 50) - // we need to subtract the refunded value from the Ethereum Safe contract - token.DeltaBalances[framework.SecondHalfBridge][framework.SafeSC].OnEth = big.NewInt(5010 + 7010 + 1010 - 2450 - 250 - 950) - // Alice will get her tokens back from the refund - token.DeltaBalances[framework.SecondHalfBridge][framework.Alice].OnEth = big.NewInt(-5010 - 7010 - 1010 + 960) - // No funds remain in the test caller SC + // no funds remain in the called test SC token.DeltaBalances[framework.SecondHalfBridge][framework.CalledTestSC].OnMvx = big.NewInt(0) } @@ -321,7 +311,19 @@ func GenerateTestEUROCToken() framework.TestTokenParams { } } -// GenerateTestMEXToken will generate a test EUROC token +// ApplyEUROCRefundBalances will apply the refund balances on the involved entities for the EUROC token +func ApplyEUROCRefundBalances(token *framework.TestTokenParams) { + // called test SC will have 0 balance since eth->mvx transfer failed + token.DeltaBalances[framework.FirstHalfBridge][framework.CalledTestSC].OnMvx = big.NewInt(0) + // extra is just for the fees for the 2 transfers mvx->eth and the failed eth->mvx that needed refund + token.DeltaBalances[framework.SecondHalfBridge][framework.SafeSC].OnMvx = big.NewInt(50 + 50 + 50) + // Alice will get her tokens back from the refund + token.DeltaBalances[framework.SecondHalfBridge][framework.Alice].OnEth = big.NewInt(-5010 - 7010 - 1010 + 960) + // no funds remain in the called test SC + token.DeltaBalances[framework.SecondHalfBridge][framework.CalledTestSC].OnMvx = big.NewInt(0) +} + +// GenerateTestMEXToken will generate a test MEX token func GenerateTestMEXToken() framework.TestTokenParams { //MEX is ethNative = false, ethMintBurn = true, mvxNative = true, mvxMintBurn = true return framework.TestTokenParams{ diff --git a/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go b/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go index 83862e65..5032feab 100644 --- a/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go +++ b/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go @@ -28,7 +28,7 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { eurocToken := GenerateTestEUROCToken() eurocToken.TestOperations[2].MvxSCCallData = callData eurocToken.TestOperations[2].MvxFaultySCCall = true - //eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + ApplyEUROCRefundBalances(&eurocToken) mexToken := GenerateTestMEXToken() mexToken.TestOperations[2].MvxSCCallData = callData @@ -40,7 +40,7 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { make(chan error), usdcToken, memeToken, - //eurocToken, + eurocToken, mexToken, ) }) @@ -59,11 +59,12 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { eurocToken := GenerateTestEUROCToken() eurocToken.TestOperations[2].MvxSCCallData = callData eurocToken.TestOperations[2].MvxFaultySCCall = true - //eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + ApplyEUROCRefundBalances(&eurocToken) mexToken := GenerateTestMEXToken() mexToken.TestOperations[2].MvxSCCallData = callData mexToken.TestOperations[2].MvxFaultySCCall = true + ApplyMEXRefundBalances(&mexToken) testRelayersWithChainSimulatorAndTokensAndRefund( t, @@ -89,11 +90,12 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { eurocToken := GenerateTestEUROCToken() eurocToken.TestOperations[2].MvxSCCallData = callData eurocToken.TestOperations[2].MvxFaultySCCall = true - //eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + ApplyEUROCRefundBalances(&eurocToken) mexToken := GenerateTestMEXToken() mexToken.TestOperations[2].MvxSCCallData = callData mexToken.TestOperations[2].MvxFaultySCCall = true + ApplyMEXRefundBalances(&mexToken) testRelayersWithChainSimulatorAndTokensAndRefund( t, @@ -121,12 +123,13 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { eurocToken.TestOperations[2].MvxSCCallData = nil eurocToken.TestOperations[2].MvxFaultySCCall = true eurocToken.TestOperations[2].MvxForceSCCall = true - //eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + ApplyEUROCRefundBalances(&eurocToken) mexToken := GenerateTestMEXToken() mexToken.TestOperations[2].MvxSCCallData = nil mexToken.TestOperations[2].MvxFaultySCCall = true mexToken.TestOperations[2].MvxForceSCCall = true + ApplyMEXRefundBalances(&mexToken) testRelayersWithChainSimulatorAndTokensAndRefund( t, @@ -152,11 +155,12 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { eurocToken := GenerateTestEUROCToken() eurocToken.TestOperations[2].MvxSCCallData = callData eurocToken.TestOperations[2].MvxFaultySCCall = true - //eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + ApplyEUROCRefundBalances(&eurocToken) mexToken := GenerateTestMEXToken() mexToken.TestOperations[2].MvxSCCallData = callData mexToken.TestOperations[2].MvxFaultySCCall = true + ApplyMEXRefundBalances(&mexToken) testRelayersWithChainSimulatorAndTokensAndRefund( t, @@ -182,11 +186,12 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { eurocToken := GenerateTestEUROCToken() eurocToken.TestOperations[2].MvxSCCallData = callData eurocToken.TestOperations[2].MvxFaultySCCall = true - //eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + ApplyEUROCRefundBalances(&eurocToken) mexToken := GenerateTestMEXToken() mexToken.TestOperations[2].MvxSCCallData = callData mexToken.TestOperations[2].MvxFaultySCCall = true + ApplyMEXRefundBalances(&mexToken) testRelayersWithChainSimulatorAndTokensAndRefund( t, @@ -212,11 +217,12 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { eurocToken := GenerateTestEUROCToken() eurocToken.TestOperations[2].MvxSCCallData = callData eurocToken.TestOperations[2].MvxFaultySCCall = true - //eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + ApplyEUROCRefundBalances(&eurocToken) mexToken := GenerateTestMEXToken() mexToken.TestOperations[2].MvxSCCallData = callData mexToken.TestOperations[2].MvxFaultySCCall = true + ApplyMEXRefundBalances(&mexToken) testRelayersWithChainSimulatorAndTokensAndRefund( t, @@ -242,11 +248,12 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { eurocToken := GenerateTestEUROCToken() eurocToken.TestOperations[2].MvxSCCallData = callData eurocToken.TestOperations[2].MvxFaultySCCall = true - //eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + ApplyEUROCRefundBalances(&eurocToken) mexToken := GenerateTestMEXToken() mexToken.TestOperations[2].MvxSCCallData = callData mexToken.TestOperations[2].MvxFaultySCCall = true + ApplyMEXRefundBalances(&mexToken) testRelayersWithChainSimulatorAndTokensAndRefund( t, @@ -272,11 +279,12 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { eurocToken := GenerateTestEUROCToken() eurocToken.TestOperations[2].MvxSCCallData = callData eurocToken.TestOperations[2].MvxFaultySCCall = true - //eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + ApplyEUROCRefundBalances(&eurocToken) mexToken := GenerateTestMEXToken() mexToken.TestOperations[2].MvxSCCallData = callData mexToken.TestOperations[2].MvxFaultySCCall = true + ApplyMEXRefundBalances(&mexToken) testRelayersWithChainSimulatorAndTokensAndRefund( t, @@ -305,11 +313,12 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { eurocToken := GenerateTestEUROCToken() eurocToken.TestOperations[2].MvxSCCallData = callData eurocToken.TestOperations[2].MvxFaultySCCall = true - //eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + ApplyEUROCRefundBalances(&eurocToken) mexToken := GenerateTestMEXToken() mexToken.TestOperations[2].MvxSCCallData = callData mexToken.TestOperations[2].MvxFaultySCCall = true + ApplyMEXRefundBalances(&mexToken) testRelayersWithChainSimulatorAndTokensAndRefund( t, @@ -340,11 +349,12 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { eurocToken := GenerateTestEUROCToken() eurocToken.TestOperations[2].MvxSCCallData = callData eurocToken.TestOperations[2].MvxFaultySCCall = true - //eurocToken.ESDTSafeExtraBalance = big.NewInt(150) + ApplyEUROCRefundBalances(&eurocToken) mexToken := GenerateTestMEXToken() mexToken.TestOperations[2].MvxSCCallData = callData mexToken.TestOperations[2].MvxFaultySCCall = true + ApplyMEXRefundBalances(&mexToken) testRelayersWithChainSimulatorAndTokensAndRefund( t, From 7542404fa450d3d27f259c19374fd34203f8afbb Mon Sep 17 00:00:00 2001 From: cosmatudor Date: Tue, 3 Dec 2024 15:44:45 +0200 Subject: [PATCH 15/17] fixes after merge --- integrationTests/relayers/slowTests/common.go | 7 ++++--- integrationTests/relayers/slowTests/edgeCases_test.go | 2 ++ .../slowTests/ethToMultiversXWithChainSimulator_test.go | 2 ++ .../relayers/slowTests/refundWithChainSimulator_test.go | 2 ++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/integrationTests/relayers/slowTests/common.go b/integrationTests/relayers/slowTests/common.go index f818706f..dc7a5750 100644 --- a/integrationTests/relayers/slowTests/common.go +++ b/integrationTests/relayers/slowTests/common.go @@ -3,6 +3,7 @@ package slowTests import ( + "bytes" "math/big" bridgeCore "github.com/multiversx/mx-bridge-eth-go/core" @@ -83,7 +84,7 @@ func GenerateTestUSDCToken() framework.TestTokenParams { }, framework.CalledTestSC: { OnEth: big.NewInt(0), - OnMvx: big.NewInt(0), + OnMvx: big.NewInt(1000), MvxToken: framework.UniversalToken, }, }, @@ -345,9 +346,9 @@ func ApplyEUROCRefundBalances(token *framework.TestTokenParams) { // called test SC will have 0 balance since eth->mvx transfer failed token.DeltaBalances[framework.FirstHalfBridge][framework.CalledTestSC].OnMvx = big.NewInt(0) // extra is just for the fees for the 2 transfers mvx->eth and the failed eth->mvx that needed refund - token.DeltaBalances[framework.SecondHalfBridge][framework.SafeSC].OnMvx = big.NewInt(50 + 50 + 50) + token.DeltaBalances[framework.SecondHalfBridge][framework.SafeSC].OnMvx = big.NewInt(50 + 50 + 50 + 50) // Alice will get her tokens back from the refund - token.DeltaBalances[framework.SecondHalfBridge][framework.Alice].OnEth = big.NewInt(-5010 - 7010 - 1010 + 960) + token.DeltaBalances[framework.SecondHalfBridge][framework.Alice].OnEth = big.NewInt(-5010 - 7010 - 1010 - 700 + 960 + 650) // no funds remain in the called test SC token.DeltaBalances[framework.SecondHalfBridge][framework.CalledTestSC].OnMvx = big.NewInt(0) } diff --git a/integrationTests/relayers/slowTests/edgeCases_test.go b/integrationTests/relayers/slowTests/edgeCases_test.go index 7d963358..056b5176 100644 --- a/integrationTests/relayers/slowTests/edgeCases_test.go +++ b/integrationTests/relayers/slowTests/edgeCases_test.go @@ -1,3 +1,5 @@ +//go:build slow + package slowTests import ( diff --git a/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go b/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go index 0f882141..be6f5777 100644 --- a/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go +++ b/integrationTests/relayers/slowTests/ethToMultiversXWithChainSimulator_test.go @@ -1,3 +1,5 @@ +//go:build slow + // To run these slow tests, simply add the slow tag on the go test command. Also, provide a chain simulator instance on the 8085 port // example: go test -tags slow diff --git a/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go b/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go index 4eee2fdf..116385c5 100644 --- a/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go +++ b/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go @@ -1,3 +1,5 @@ +//go:build slow + // To run these slow tests, simply add the slow tag on the go test command. Also, provide a chain simulator instance on the 8085 port // example: go test -tags slow From 70f377cd7758328d5efa83be8ab225170607070b Mon Sep 17 00:00:00 2001 From: cosmatudor Date: Wed, 4 Dec 2024 15:01:56 +0200 Subject: [PATCH 16/17] add tests for: - built-in functions - gas limit too high --- .../refundWithChainSimulator_test.go | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go b/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go index 116385c5..c42ae532 100644 --- a/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go +++ b/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go @@ -108,6 +108,38 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { mexToken, ) }) + // TODO: add a test for uninitialised SC addressyyyyyyy + t.Run("built-in function should refund", func(t *testing.T) { + callData := createScCallData("SaveKeyValue", 50000000, "6b657930", "76616c756530") + usdcToken := GenerateTestUSDCToken() + usdcToken.TestOperations[2].MvxSCCallData = callData + usdcToken.TestOperations[2].MvxFaultySCCall = true + ApplyUSDCRefundBalances(&usdcToken) + + memeToken := GenerateTestMEMEToken() + memeToken.TestOperations[2].MvxSCCallData = callData + memeToken.TestOperations[2].MvxFaultySCCall = true + ApplyMEMERefundBalances(&memeToken) + + eurocToken := GenerateTestEUROCToken() + eurocToken.TestOperations[2].MvxSCCallData = callData + eurocToken.TestOperations[2].MvxFaultySCCall = true + ApplyEUROCRefundBalances(&eurocToken) + + mexToken := GenerateTestMEXToken() + mexToken.TestOperations[2].MvxSCCallData = callData + mexToken.TestOperations[2].MvxFaultySCCall = true + ApplyMEXRefundBalances(&mexToken) + + testRelayersWithChainSimulatorAndTokensAndRefund( + t, + make(chan error), + usdcToken, + memeToken, + eurocToken, + mexToken, + ) + }) t.Run("wrong deposit with empty sc call data should refund", func(t *testing.T) { usdcToken := GenerateTestUSDCToken() usdcToken.TestOperations[2].MvxSCCallData = nil @@ -204,6 +236,37 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { mexToken, ) }) + t.Run("high gas limit should refund", func(t *testing.T) { + callData := createScCallData("callPayable", 610000000) + usdcToken := GenerateTestUSDCToken() + usdcToken.TestOperations[2].MvxSCCallData = callData + usdcToken.TestOperations[2].MvxFaultySCCall = true + ApplyUSDCRefundBalances(&usdcToken) + + memeToken := GenerateTestMEMEToken() + memeToken.TestOperations[2].MvxSCCallData = callData + memeToken.TestOperations[2].MvxFaultySCCall = true + ApplyMEMERefundBalances(&memeToken) + + eurocToken := GenerateTestEUROCToken() + eurocToken.TestOperations[2].MvxSCCallData = callData + eurocToken.TestOperations[2].MvxFaultySCCall = true + ApplyEUROCRefundBalances(&eurocToken) + + mexToken := GenerateTestMEXToken() + mexToken.TestOperations[2].MvxSCCallData = callData + mexToken.TestOperations[2].MvxFaultySCCall = true + ApplyMEXRefundBalances(&mexToken) + + testRelayersWithChainSimulatorAndTokensAndRefund( + t, + make(chan error), + usdcToken, + memeToken, + eurocToken, + mexToken, + ) + }) t.Run("extra parameter should refund", func(t *testing.T) { callData := createScCallData("callPayable", 50000000, "extra parameter") usdcToken := GenerateTestUSDCToken() From 5b9464259ade4015e02ec62f56e786881c1dd758 Mon Sep 17 00:00:00 2001 From: cosmatudor Date: Thu, 5 Dec 2024 12:28:48 +0200 Subject: [PATCH 17/17] add tests for uninitialised sc address --- .../relayers/slowTests/framework/testSetup.go | 17 +++++++-- .../refundWithChainSimulator_test.go | 38 ++++++++++++++++++- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/integrationTests/relayers/slowTests/framework/testSetup.go b/integrationTests/relayers/slowTests/framework/testSetup.go index 4c911efb..8141db4c 100644 --- a/integrationTests/relayers/slowTests/framework/testSetup.go +++ b/integrationTests/relayers/slowTests/framework/testSetup.go @@ -375,7 +375,7 @@ func (setup *TestSetup) checkContractMvxBalanceForToken(params TestTokenParams) if operation.ValueToTransferToMvx == nil { continue } - if len(operation.MvxSCCallData) == 0 && !operation.MvxForceSCCall { + if !setup.hasCallData(operation) { continue } if operation.MvxFaultySCCall { @@ -496,7 +496,7 @@ func (setup *TestSetup) checkEthMintedBalanceForToken(params TestTokenParams) bo func (setup *TestSetup) getMvxTotalRefundAmountForToken(params TestTokenParams) *big.Int { totalRefund := big.NewInt(0) for _, operation := range params.TestOperations { - if len(operation.MvxSCCallData) == 0 && !operation.MvxForceSCCall { + if !setup.hasCallData(operation) { continue } if !operation.MvxFaultySCCall { @@ -561,7 +561,7 @@ func (setup *TestSetup) createDepositOnMultiversxForToken(from KeysHolder, to Ke continue } - if operation.InvalidReceiver != nil { + if operation.InvalidReceiver != nil && !setup.hasCallData(operation) { invalidReceiver := common.Address(operation.InvalidReceiver) to = KeysHolder{EthAddress: invalidReceiver} } @@ -628,13 +628,22 @@ func (setup *TestSetup) createDepositOnEthereumForToken(from KeysHolder, to Keys if operation.InvalidReceiver != nil { invalidReceiver := NewMvxAddressFromBytes(setup, operation.InvalidReceiver) - to = KeysHolder{MvxAddress: invalidReceiver} + + if setup.hasCallData(operation) { + targetSCAddress = invalidReceiver + } else { + to = KeysHolder{MvxAddress: invalidReceiver} + } } setup.EthereumHandler.SendDepositTransactionFromEthereum(setup.Ctx, from, to, targetSCAddress, token, operation) } } +func (setup *TestSetup) hasCallData(operation TokenOperations) bool { + return len(operation.MvxSCCallData) != 0 || operation.MvxForceSCCall +} + // TestWithdrawTotalFeesOnEthereumForTokens will test the withdrawal functionality for the provided test tokens func (setup *TestSetup) TestWithdrawTotalFeesOnEthereumForTokens(tokensParams ...TestTokenParams) { for _, param := range tokensParams { diff --git a/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go b/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go index c42ae532..680a7820 100644 --- a/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go +++ b/integrationTests/relayers/slowTests/refundWithChainSimulator_test.go @@ -11,6 +11,7 @@ import ( bridgeCore "github.com/multiversx/mx-bridge-eth-go/core" "github.com/multiversx/mx-bridge-eth-go/integrationTests/relayers/slowTests/framework" + "github.com/multiversx/mx-sdk-go/data" "github.com/stretchr/testify/require" ) @@ -108,7 +109,42 @@ func TestRelayersShouldExecuteTransfersWithRefund(t *testing.T) { mexToken, ) }) - // TODO: add a test for uninitialised SC addressyyyyyyy + t.Run("uninitialized contract should refund", func(t *testing.T) { + callData := createScCallData("claim", 50000000) + uninitializedSCAddressBytes, _ := data.NewAddressFromBech32String("erd1qqqqqqqqqqqqqpgqcc69ts8409p3h77q5chsaqz57y6hugvc4fvs64k74v") + usdcToken := GenerateTestUSDCToken() + usdcToken.TestOperations[2].MvxSCCallData = callData + usdcToken.TestOperations[2].MvxFaultySCCall = true + usdcToken.TestOperations[2].InvalidReceiver = uninitializedSCAddressBytes.AddressBytes() + ApplyUSDCRefundBalances(&usdcToken) + + memeToken := GenerateTestMEMEToken() + memeToken.TestOperations[2].MvxSCCallData = callData + memeToken.TestOperations[2].MvxFaultySCCall = true + memeToken.TestOperations[2].InvalidReceiver = uninitializedSCAddressBytes.AddressBytes() + ApplyMEMERefundBalances(&memeToken) + + eurocToken := GenerateTestEUROCToken() + eurocToken.TestOperations[2].MvxSCCallData = callData + eurocToken.TestOperations[2].MvxFaultySCCall = true + eurocToken.TestOperations[2].InvalidReceiver = uninitializedSCAddressBytes.AddressBytes() + ApplyEUROCRefundBalances(&eurocToken) + + mexToken := GenerateTestMEXToken() + mexToken.TestOperations[2].MvxSCCallData = callData + mexToken.TestOperations[2].MvxFaultySCCall = true + mexToken.TestOperations[2].InvalidReceiver = uninitializedSCAddressBytes.AddressBytes() + ApplyMEXRefundBalances(&mexToken) + + testRelayersWithChainSimulatorAndTokensAndRefund( + t, + make(chan error), + usdcToken, + memeToken, + eurocToken, + mexToken, + ) + }) t.Run("built-in function should refund", func(t *testing.T) { callData := createScCallData("SaveKeyValue", 50000000, "6b657930", "76616c756530") usdcToken := GenerateTestUSDCToken()