From ac863a495d929daeddec71fb3fcaca2bff9284fb Mon Sep 17 00:00:00 2001 From: Thales Lima Date: Thu, 27 Jun 2024 21:07:19 +0200 Subject: [PATCH] Make db url configurable --- testing/Dockerfile | 2 +- testing/cli.py | 7 ++++++- testing/runner.py | 10 ++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/testing/Dockerfile b/testing/Dockerfile index ff7c6cc..8019ebd 100644 --- a/testing/Dockerfile +++ b/testing/Dockerfile @@ -30,4 +30,4 @@ RUN wget -c https://github.com/streamingfast/substreams/releases/download/v1.8.0 RUN mv substreams /usr/local/bin/substreams && chmod +x /usr/local/bin/substreams # Run the command to start your application -CMD ["python", "testing/cli.py", "--test_yaml_path", "/app/substreams/my_substream/test_assets.yaml", "--with_binary_logs"] \ No newline at end of file +CMD ["python", "testing/cli.py", "--test_yaml_path", "/app/substreams/my_substream/test_assets.yaml", "--with_binary_logs", "--db_url", "postgres://postgres:mypassword@db:5432"] \ No newline at end of file diff --git a/testing/cli.py b/testing/cli.py index 745b59d..0243c8f 100644 --- a/testing/cli.py +++ b/testing/cli.py @@ -14,9 +14,14 @@ def main() -> None: action="store_true", help="Flag to activate logs from Tycho.", ) + parser.add_argument( + "--db_url", + type=str, + help="Postgres database URL for the Tycho indexer.", + ) args = parser.parse_args() - test_runner = TestRunner(args.test_yaml_path, args.with_binary_logs) + test_runner = TestRunner(args.test_yaml_path, args.with_binary_logs, db_url=args.db_url) test_runner.run_tests() diff --git a/testing/runner.py b/testing/runner.py index 6c767d3..bbf8933 100644 --- a/testing/runner.py +++ b/testing/runner.py @@ -30,10 +30,11 @@ def load_config(yaml_path: str) -> dict: class TestRunner: - def __init__(self, config_path: str, with_binary_logs: bool): + def __init__(self, config_path: str, with_binary_logs: bool, db_url: str): self.config = load_config(config_path) self.base_dir = os.path.dirname(config_path) self.tycho_runner = TychoRunner(with_binary_logs) + self.db_url = db_url def run_tests(self) -> None: """Run all tests specified in the configuration.""" @@ -61,7 +62,7 @@ class TestRunner: print(f"❗️ {test['name']} failed: {result.message}") self.tycho_runner.empty_database( - "postgres://postgres:mypassword@db:5432" + self.db_url ) def validate_state(self, expected_state: dict, stop_block: int) -> TestResult: @@ -89,7 +90,7 @@ class TestRunner: ) if isinstance(value, list): if set(map(str.lower, value)) != set( - map(str.lower, component[key]) + map(str.lower, component[key]) ): return TestResult.Failed( f"List mismatch for key '{key}': {value} != {component[key]}" @@ -112,7 +113,8 @@ class TestRunner: node_balance = get_token_balance(token, comp_id, stop_block) tycho_balance = int(balance_hex, 16) if node_balance != tycho_balance: - return TestResult.Failed(f"Balance mismatch for {comp_id}:{token} at block {stop_block}: got {node_balance} from rpc call and {tycho_balance} from Substreams") + return TestResult.Failed( + f"Balance mismatch for {comp_id}:{token} at block {stop_block}: got {node_balance} from rpc call and {tycho_balance} from Substreams") return TestResult.Passed() except Exception as e: return TestResult.Failed(str(e))