Make db url configurable

This commit is contained in:
Thales Lima
2024-06-27 21:07:19 +02:00
parent a9954873d9
commit ac863a495d
3 changed files with 13 additions and 6 deletions

View File

@@ -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 mv substreams /usr/local/bin/substreams && chmod +x /usr/local/bin/substreams
# Run the command to start your application # 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"] 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"]

View File

@@ -14,9 +14,14 @@ def main() -> None:
action="store_true", action="store_true",
help="Flag to activate logs from Tycho.", 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() 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() test_runner.run_tests()

View File

@@ -30,10 +30,11 @@ def load_config(yaml_path: str) -> dict:
class TestRunner: 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.config = load_config(config_path)
self.base_dir = os.path.dirname(config_path) self.base_dir = os.path.dirname(config_path)
self.tycho_runner = TychoRunner(with_binary_logs) self.tycho_runner = TychoRunner(with_binary_logs)
self.db_url = db_url
def run_tests(self) -> None: def run_tests(self) -> None:
"""Run all tests specified in the configuration.""" """Run all tests specified in the configuration."""
@@ -61,7 +62,7 @@ class TestRunner:
print(f"❗️ {test['name']} failed: {result.message}") print(f"❗️ {test['name']} failed: {result.message}")
self.tycho_runner.empty_database( self.tycho_runner.empty_database(
"postgres://postgres:mypassword@db:5432" self.db_url
) )
def validate_state(self, expected_state: dict, stop_block: int) -> TestResult: def validate_state(self, expected_state: dict, stop_block: int) -> TestResult:
@@ -112,7 +113,8 @@ class TestRunner:
node_balance = get_token_balance(token, comp_id, stop_block) node_balance = get_token_balance(token, comp_id, stop_block)
tycho_balance = int(balance_hex, 16) tycho_balance = int(balance_hex, 16)
if node_balance != tycho_balance: 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() return TestResult.Passed()
except Exception as e: except Exception as e:
return TestResult.Failed(str(e)) return TestResult.Failed(str(e))