Skip to content

Commit

Permalink
Merge pull request #96 from multiversx/spica-20-1
Browse files Browse the repository at this point in the history
Tests and formatting
  • Loading branch information
andreibancioiu authored Aug 20, 2024
2 parents c363fb8 + 7450e63 commit bbc257b
Show file tree
Hide file tree
Showing 20 changed files with 311 additions and 238 deletions.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"[json]": {
"editor.tabSize": 4
},
"prettier"
}
16 changes: 8 additions & 8 deletions cmd/rosetta/testdata/custom-currencies.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[
{
"symbol": "WEGLD-bd4d79",
"decimals": 18
},
{
"symbol": "USDC-c76f1f",
"decimals": 6
}
{
"symbol": "WEGLD-bd4d79",
"decimals": 18
},
{
"symbol": "USDC-c76f1f",
"decimals": 6
}
]
6 changes: 1 addition & 5 deletions server/services/testdata/blocks_with_esdt_burn.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
{
"address": "erd1r69gk66fmedhhcg24g2c5kn2f2a5k4kvpr6jfw67dn2lyydd8cfswy6ede",
"identifier": "ESDTLocalBurn",
"topics": [
"VEVTVC00ODRmYTE=",
"",
"Mg=="
],
"topics": ["VEVTVC00ODRmYTE=", "", "Mg=="],
"data": null
},
{
Expand Down
6 changes: 1 addition & 5 deletions server/services/testdata/blocks_with_esdt_mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
{
"address": "erd1r69gk66fmedhhcg24g2c5kn2f2a5k4kvpr6jfw67dn2lyydd8cfswy6ede",
"identifier": "ESDTLocalMint",
"topics": [
"VEVTVC00ODRmYTE=",
"",
"yA=="
],
"topics": ["VEVTVC00ODRmYTE=", "", "yA=="],
"data": null
},
{
Expand Down
29 changes: 29 additions & 0 deletions server/services/transactionEventsController_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package services

import (
"encoding/hex"
"testing"

"github.com/multiversx/mx-chain-core-go/data/transaction"
Expand Down Expand Up @@ -174,6 +175,34 @@ func TestTransactionEventsController_ExtractEvents(t *testing.T) {
networkProvider := testscommon.NewNetworkProviderMock()
controller := newTransactionEventsController(networkProvider)

t.Run("SCDeploy", func(t *testing.T) {
topic0, _ := hex.DecodeString("00000000000000000500def8dad1161f8f0c38f3e6e73515ed81058f0b5606b8")
topic1, _ := hex.DecodeString("5cf4abc83e50c5309d807fc3f676988759a1e301001bc9a0265804f42af806b8")
topic2, _ := hex.DecodeString("be5560e0d7d3857d438a3678269039f8f80ded90dcbc2cda268a0847ba9cb379")

tx := &transaction.ApiTransactionResult{
Logs: &transaction.ApiLogs{
Events: []*transaction.Events{
{
Identifier: "SCDeploy",
Address: "erd1qqqqqqqqqqqqqpgqmmud45gkr78scw8numnn290dsyzc7z6kq6uqw2jcza",
Topics: [][]byte{
topic0,
topic1,
topic2,
},
},
},
},
}

events, err := controller.extractEventSCDeploy(tx)
require.NoError(t, err)
require.Len(t, events, 1)
require.Equal(t, "erd1qqqqqqqqqqqqqpgqmmud45gkr78scw8numnn290dsyzc7z6kq6uqw2jcza", events[0].contractAddress)
require.Equal(t, "erd1tn62hjp72rznp8vq0lplva5csav6rccpqqdungpxtqz0g2hcq6uq9k4cc6", events[0].deployerAddress)
})

t.Run("ESDTNFTCreate", func(t *testing.T) {
tx := &transaction.ApiTransactionResult{
Logs: &transaction.ApiLogs{
Expand Down
Binary file added systemtests/adder.wasm
Binary file not shown.
14 changes: 9 additions & 5 deletions systemtests/check_with_mesh_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ def main() -> int:
configuration = CONFIGURATIONS[args.network]

process_rosetta = run_rosetta(configuration)
process_adapter = run_proxy_to_observer_adapter(configuration)
process_adapter = optionally_run_proxy_to_observer_adapter(configuration)
process_checker = run_mesh_cli(mode, configuration)

# Handle termination signals
def signal_handler(sig: Any, frame: Any):
process_rosetta.kill()
process_adapter.kill()
process_adapter.kill() if process_adapter else None
process_checker.kill()
sys.exit(1)

Expand All @@ -39,7 +39,7 @@ def signal_handler(sig: Any, frame: Any):
exit_code = process_checker.wait()

process_rosetta.kill()
process_adapter.kill()
process_adapter.kill() if process_adapter else None

time.sleep(1)

Expand All @@ -61,7 +61,7 @@ def run_rosetta(configuration: Configuration):
command = [
str(constants.PATH_ROSETTA),
f"--port={constants.PORT_ROSETTA}",
f"--observer-http-url=http://localhost:{constants.PORT_OBSERVER_SURROGATE}",
f"--observer-http-url={constants.URL_OBSERVER_SURROGATE}",
f"--observer-actual-shard={configuration.network_shard}",
f"--network-id={configuration.network_id}",
f"--network-name={configuration.network_name}",
Expand All @@ -74,7 +74,11 @@ def run_rosetta(configuration: Configuration):
return subprocess.Popen(command)


def run_proxy_to_observer_adapter(configuration: Configuration):
def optionally_run_proxy_to_observer_adapter(configuration: Configuration) -> Any:
if configuration.observer_url:
# If observer URL is provided, we don't need the adapter.
return None

command = [
str(constants.PATH_PROXY_TO_OBSERVER_ADAPTER),
f"--proxy={configuration.proxy_url}",
Expand Down
43 changes: 42 additions & 1 deletion systemtests/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
from dataclasses import dataclass
from typing import List


@dataclass
Expand All @@ -9,11 +11,16 @@ class Configuration:
native_currency: str
config_file_custom_currencies: str
num_historical_epochs: int
observer_url: str
proxy_url: str
check_construction_native_configuration_file: str
check_construction_custom_configuration_file: str
check_data_configuration_file: str
check_data_directory: str
known_contracts: List[str]
explorer_url: str
sponsor_secret_key: bytes = bytes.fromhex(os.environ.get("SPONSOR_SECRET_KEY", ""))
users_mnemonic: str = os.environ.get("USERS_MNEMONIC", "")


CONFIGURATIONS = {
Expand All @@ -24,23 +31,57 @@ class Configuration:
native_currency="EGLD",
config_file_custom_currencies="systemtests/rosetta_config/devnet-custom-currencies.json",
num_historical_epochs=2,
observer_url="",
proxy_url="https://devnet-gateway.multiversx.com",
check_construction_native_configuration_file="systemtests/mesh_cli_config/devnet-construction-native.json",
check_construction_custom_configuration_file="systemtests/mesh_cli_config/devnet-construction-custom.json",
check_data_configuration_file="systemtests/mesh_cli_config/check-data.json",
check_data_directory="systemtests/devnet-data",
known_contracts=[
"erd1qqqqqqqqqqqqqpgqagjekf5mxv86hy5c62vvtug5vc6jmgcsq6uq8reras",
"erd1qqqqqqqqqqqqqpgq89t5xm4x04tnt9lv747wdrsaycf3rcwcggzsa7crse",
"erd1qqqqqqqqqqqqqpgqeesfamasje5zru7ku79m8p4xqfqnywvqxj0qhtyzdr"
],
explorer_url="https://devnet-explorer.multiversx.com",
),
"testnet": Configuration(
network_shard=0,
network_id="T",
network_name="untitled",
native_currency="EGLD",
config_file_custom_currencies="systemtests/rosetta_config/testnet-custom-currencies.json",
num_historical_epochs=2,
num_historical_epochs=1,
observer_url="",
proxy_url="https://testnet-gateway.multiversx.com",
check_construction_native_configuration_file="systemtests/mesh_cli_config/testnet-construction-native.json",
check_construction_custom_configuration_file="systemtests/mesh_cli_config/testnet-construction-custom.json",
check_data_configuration_file="systemtests/mesh_cli_config/check-data.json",
check_data_directory="systemtests/testnet-data",
known_contracts=[
"erd1qqqqqqqqqqqqqpgqagjekf5mxv86hy5c62vvtug5vc6jmgcsq6uq8reras",
"erd1qqqqqqqqqqqqqpgq89t5xm4x04tnt9lv747wdrsaycf3rcwcggzsa7crse",
"erd1qqqqqqqqqqqqqpgqeesfamasje5zru7ku79m8p4xqfqnywvqxj0qhtyzdr"
],
explorer_url="https://testnet-explorer.multiversx.com",
),
"localnet": Configuration(
network_shard=0,
network_id="localnet",
network_name="untitled",
native_currency="EGLD",
config_file_custom_currencies="systemtests/rosetta_config/localnet-custom-currencies.json",
num_historical_epochs=2,
observer_url="",
proxy_url="http://localhost:7950",
check_construction_native_configuration_file="systemtests/mesh_cli_config/localnet-construction-native.json",
check_construction_custom_configuration_file="systemtests/mesh_cli_config/localnet-construction-custom.json",
check_data_configuration_file="systemtests/mesh_cli_config/check-data.json",
check_data_directory="systemtests/localnet-data",
known_contracts=[
"erd1qqqqqqqqqqqqqpgqagjekf5mxv86hy5c62vvtug5vc6jmgcsq6uq8reras",
"erd1qqqqqqqqqqqqqpgq89t5xm4x04tnt9lv747wdrsaycf3rcwcggzsa7crse",
"erd1qqqqqqqqqqqqqpgqeesfamasje5zru7ku79m8p4xqfqnywvqxj0qhtyzdr"
],
explorer_url="",
),
}
4 changes: 2 additions & 2 deletions systemtests/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
PATH_ROSETTA = PATH_REPOSITORY / "cmd" / "rosetta" / "rosetta"
PATH_PROXY_TO_OBSERVER_ADAPTER = PATH_REPOSITORY / "systemtests" / "proxyToObserverAdapter"
PORT_ROSETTA = 7091
PORT_OBSERVER_SURROGATE = 8080
ADAPTER_DELAY_IN_MILLISECONDS = 100
URL_OBSERVER_SURROGATE = "http://localhost:8080"
ADAPTER_DELAY_IN_MILLISECONDS = 80
Binary file added systemtests/dummy.wasm
Binary file not shown.
86 changes: 43 additions & 43 deletions systemtests/mesh_cli_config/check-data.json
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
{
"network": {
"blockchain": "MultiversX",
"network": "untitled"
},
"http_timeout": 30,
"max_retries": 10,
"retry_elapsed_time": 20,
"max_online_connections": 8,
"max_sync_concurrency": 4,
"tip_delay": 10,
"max_reorg_depth": 100,
"log_configuration": false,
"compression_disabled": false,
"l0_in_memory_enabled": false,
"error_stack_trace_disabled": false,
"coin_supported": false,
"construction": null,
"data": {
"active_reconciliation_concurrency": 8,
"inactive_reconciliation_concurrency": 1,
"inactive_reconciliation_frequency": 8,
"log_blocks": false,
"log_transactions": true,
"log_balance_changes": true,
"log_reconciliations": true,
"ignore_reconciliation_error": false,
"reconciliation_disabled": false,
"reconciliation_drain_disabled": false,
"inactive_discrepancy_search_disabled": false,
"balance_tracking_disabled": false,
"coin_tracking_disabled": false,
"status_port": 9091,
"results_output_file": "",
"pruning_block_disabled": false,
"pruning_balance_disabled": false,
"initial_balance_fetch_disabled": false,
"historical_balance_disabled": false,
"end_conditions": {
"reconciliation_coverage": {
"coverage": 1,
"from_tip": true
}
"network": {
"blockchain": "MultiversX",
"network": "untitled"
},
"http_timeout": 30,
"max_retries": 10,
"retry_elapsed_time": 20,
"max_online_connections": 8,
"max_sync_concurrency": 4,
"tip_delay": 10,
"max_reorg_depth": 100,
"log_configuration": false,
"compression_disabled": false,
"l0_in_memory_enabled": false,
"error_stack_trace_disabled": false,
"coin_supported": false,
"construction": null,
"data": {
"active_reconciliation_concurrency": 8,
"inactive_reconciliation_concurrency": 1,
"inactive_reconciliation_frequency": 8,
"log_blocks": false,
"log_transactions": true,
"log_balance_changes": true,
"log_reconciliations": true,
"ignore_reconciliation_error": false,
"reconciliation_disabled": false,
"reconciliation_drain_disabled": false,
"inactive_discrepancy_search_disabled": false,
"balance_tracking_disabled": false,
"coin_tracking_disabled": false,
"status_port": 9091,
"results_output_file": "",
"pruning_block_disabled": false,
"pruning_balance_disabled": false,
"initial_balance_fetch_disabled": false,
"historical_balance_disabled": false,
"end_conditions": {
"reconciliation_coverage": {
"coverage": 1,
"from_tip": true
}
}
}
}
}
Loading

0 comments on commit bbc257b

Please sign in to comment.