diff --git a/.github/workflows/check_data.yml b/.github/workflows/check_data.yml deleted file mode 100644 index 5471b74c..00000000 --- a/.github/workflows/check_data.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Check data - -on: - pull_request: - workflow_dispatch: - -jobs: - test: - runs-on: ubuntu-latest - - steps: - - uses: actions/setup-python@v5 - with: - python-version: 3.11 - - - uses: actions/checkout@v4 - - - name: Install dependencies - run: | - pip3 install requests bottle - curl -sSfL https://raw.githubusercontent.com/coinbase/mesh-cli/master/scripts/install.sh | sh -s -- -b "$HOME/.local/bin" - echo "$HOME/.local/bin" >> $GITHUB_PATH - - - name: Build - run: | - cd $GITHUB_WORKSPACE/cmd/rosetta && go build . - cd $GITHUB_WORKSPACE/systemtests && go build ./proxyToObserverAdapter.go - - - name: Run scenario - run: | - PYTHONPATH=. python3 ./systemtests/check_data.py --network testnet - - diff --git a/.github/workflows/check_construction_native.yml b/.github/workflows/check_with_mesh_cli.yml similarity index 74% rename from .github/workflows/check_construction_native.yml rename to .github/workflows/check_with_mesh_cli.yml index bf1e3d6b..4c6d67bc 100644 --- a/.github/workflows/check_construction_native.yml +++ b/.github/workflows/check_with_mesh_cli.yml @@ -26,8 +26,12 @@ jobs: cd $GITHUB_WORKSPACE/cmd/rosetta && go build . cd $GITHUB_WORKSPACE/systemtests && go build ./proxyToObserverAdapter.go - - name: Run scenario + - name: check:data run: | - PYTHONPATH=. python3 ./systemtests/check_construction_native.py --network testnet + PYTHONPATH=. python3 ./systemtests/check.py --mode=data --network=testnet + + - name: check:construction + run: | + PYTHONPATH=. python3 ./systemtests/check.py --mode=construction --network=testnet diff --git a/systemtests/check_data.py b/systemtests/check.py similarity index 64% rename from systemtests/check_data.py rename to systemtests/check.py index 72d5e73a..0462535b 100644 --- a/systemtests/check_data.py +++ b/systemtests/check.py @@ -9,21 +9,21 @@ import requests from systemtests import constants -from systemtests.check_shared import (get_current_epoch, - run_proxy_to_observer_adapter) from systemtests.config import CONFIGURATIONS, Configuration def main() -> int: parser = ArgumentParser() + parser.add_argument("--mode", choices=["data", "construction"], required=True) parser.add_argument("--network", choices=CONFIGURATIONS.keys(), required=True) args = parser.parse_args() + mode = args.mode configuration = CONFIGURATIONS[args.network] process_rosetta = run_rosetta(configuration) process_adapter = run_proxy_to_observer_adapter(configuration) - process_checker = run_rosetta_checker(configuration) + process_checker = run_rosetta_checker(mode, configuration) # Handle termination signals def signal_handler(sig: Any, frame: Any): @@ -73,7 +73,46 @@ def run_rosetta(configuration: Configuration): return subprocess.Popen(command) -def run_rosetta_checker(configuration: Configuration): +def run_proxy_to_observer_adapter(configuration: Configuration): + command = [ + str(constants.PATH_PROXY_TO_OBSERVER_ADAPTER), + f"--proxy={configuration.proxy_url}", + f"--shard={configuration.network_shard}", + f"--sleep={constants.ADAPTER_DELAY_IN_MILLISECONDS}" + ] + + return subprocess.Popen(command) + + +def run_rosetta_checker(mode: str, configuration: Configuration): + if mode == "data": + return run_rosetta_checker_with_check_data(configuration) + elif mode == "construction": + return run_rosetta_checker_with_check_construction(configuration) + else: + raise ValueError(f"Unknown mode: {mode}") + + +def run_rosetta_checker_with_check_construction(configuration: Configuration): + """ + E.g. + + rosetta-cli check:construction --configuration-file devnet-construction.json \ + --online-url=http://localhost:7091 --offline-url=http://localhost:7091 + """ + + command = [ + "rosetta-cli", + "check:construction", + f"--configuration-file={configuration.check_construction_configuration_file}", + f"--online-url=http://localhost:{constants.PORT_ROSETTA}", + f"--offline-url=http://localhost:{constants.PORT_ROSETTA}", + ] + + return subprocess.Popen(command) + + +def run_rosetta_checker_with_check_data(configuration: Configuration): """ E.g. @@ -99,6 +138,12 @@ def run_rosetta_checker(configuration: Configuration): return subprocess.Popen(command) +def get_current_epoch(configuration: Configuration) -> int: + response = requests.get(f"{configuration.proxy_url}/network/status/{configuration.network_shard}") + response.raise_for_status() + return response.json()["data"]["status"]["erd_epoch_number"] + + def get_start_of_epoch(configuration: Configuration, epoch: int) -> int: response = requests.get(f"{configuration.proxy_url}/network/epoch-start/{configuration.network_shard}/by-epoch/{epoch}") response.raise_for_status() diff --git a/systemtests/check_construction_native.py b/systemtests/check_construction_native.py deleted file mode 100644 index 418b9471..00000000 --- a/systemtests/check_construction_native.py +++ /dev/null @@ -1,94 +0,0 @@ -import signal -import subprocess -import sys -import time -from argparse import ArgumentParser -from typing import Any - -from systemtests import constants -from systemtests.check_shared import (get_current_epoch, - run_proxy_to_observer_adapter) -from systemtests.config import CONFIGURATIONS, Configuration - - -def main() -> int: - parser = ArgumentParser() - parser.add_argument("--network", choices=CONFIGURATIONS.keys(), required=True) - args = parser.parse_args() - - configuration = CONFIGURATIONS[args.network] - - process_rosetta = run_rosetta(configuration) - process_adapter = run_proxy_to_observer_adapter(configuration) - process_checker = run_rosetta_checker(configuration) - - # Handle termination signals - def signal_handler(sig: Any, frame: Any): - process_rosetta.kill() - process_adapter.kill() - process_checker.kill() - sys.exit(1) - - signal.signal(signal.SIGINT, signal_handler) - signal.signal(signal.SIGTERM, signal_handler) - - # Wait for checker to finish - exit_code = process_checker.wait() - - process_rosetta.kill() - process_adapter.kill() - - time.sleep(1) - - print(f"Checker finished with exit code: {exit_code}.") - return exit_code - - -def run_rosetta(configuration: Configuration): - """ - E.g. - - rosetta --port=7091 --observer-http-url=http://localhost:8080 \ - --observer-actual-shard=0 --network-id=D --network-name=devnet --native-currency=EGLD \ - --first-historical-epoch=42 --num-historical-epochs=1 - """ - - current_epoch = get_current_epoch(configuration) - - command = [ - str(constants.PATH_ROSETTA), - f"--port={constants.PORT_ROSETTA}", - f"--observer-http-url=http://localhost:{constants.PORT_OBSERVER_SURROGATE}", - f"--observer-actual-shard={configuration.network_shard}", - f"--network-id={configuration.network_id}", - f"--network-name={configuration.network_name}", - f"--native-currency={configuration.native_currency}", - f"--first-historical-epoch={current_epoch}", - f"--num-historical-epochs={configuration.num_historical_epochs}", - ] - - return subprocess.Popen(command) - - -def run_rosetta_checker(configuration: Configuration): - """ - E.g. - - rosetta-cli check:construction --configuration-file devnet-construction.json \ - --online-url=http://localhost:7091 --offline-url=http://localhost:7091 - """ - - command = [ - "rosetta-cli", - "check:construction", - f"--configuration-file={configuration.check_construction_configuration_file}", - f"--online-url=http://localhost:{constants.PORT_ROSETTA}", - f"--offline-url=http://localhost:{constants.PORT_ROSETTA}", - ] - - return subprocess.Popen(command) - - -if __name__ == "__main__": - exit_code = main() - sys.exit(exit_code) diff --git a/systemtests/check_shared.py b/systemtests/check_shared.py deleted file mode 100644 index b91e7dde..00000000 --- a/systemtests/check_shared.py +++ /dev/null @@ -1,23 +0,0 @@ -import subprocess - -import requests - -from systemtests import constants -from systemtests.config import Configuration - - -def run_proxy_to_observer_adapter(configuration: Configuration): - command = [ - str(constants.PATH_PROXY_TO_OBSERVER_ADAPTER), - f"--proxy={configuration.proxy_url}", - f"--shard={configuration.network_shard}", - f"--sleep={constants.ADAPTER_DELAY_IN_MILLISECONDS}" - ] - - return subprocess.Popen(command) - - -def get_current_epoch(configuration: Configuration) -> int: - response = requests.get(f"{configuration.proxy_url}/network/status/{configuration.network_shard}") - response.raise_for_status() - return response.json()["data"]["status"]["erd_epoch_number"]