Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmatudor committed Nov 19, 2024
1 parent 871aec5 commit 361d97d
Show file tree
Hide file tree
Showing 10 changed files with 345 additions and 30 deletions.
140 changes: 140 additions & 0 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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
64 changes: 64 additions & 0 deletions docker/scripts/send-tx.sh
Original file line number Diff line number Diff line change
@@ -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"
63 changes: 56 additions & 7 deletions integrationTests/relayers/slowTests/common.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//go:build slow

package slowTests

import (
"bytes"
"math/big"

bridgeCore "github.com/multiversx/mx-bridge-eth-go/core"
Expand All @@ -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
Expand Down Expand Up @@ -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: {
Expand All @@ -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),
},
},
}
}
Expand Down Expand Up @@ -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
Expand All @@ -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),
},
},
}
}
Expand Down Expand Up @@ -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{
Expand All @@ -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),
},
},
}
}
Expand Down Expand Up @@ -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{
Expand All @@ -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),
},
},
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -35,7 +33,7 @@ func TestRelayersShouldExecuteTransfers(t *testing.T) {
t,
make(chan error),
GenerateTestUSDCToken(),
GenerateTestMEMEToken(),
//GenerateTestMEMEToken(),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
1 change: 1 addition & 0 deletions integrationTests/relayers/slowTests/framework/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const (
Alice = "Alice"
Bob = "Bob"
Charlie = "Charlie"
AddressZero = "AddressZero"
)

// NewKeysStore will create a KeysStore instance and generate all keys
Expand Down
Loading

0 comments on commit 361d97d

Please sign in to comment.