fix: load withdrawal validation test module by path#5579
Conversation
|
Welcome to RustChain! Thanks for your first pull request. Before we review, please make sure:
Bounty tiers: Micro (1-10 RTC) | Standard (20-50) | Major (75-100) | Critical (100-150) A maintainer will review your PR soon. Thanks for contributing! |
|
Security Review ✅ Load withdrawal validation test module by path. Test infrastructure improvement. Reviewed by Xeophon - Solana: Lt9nERv6VHsojw15LpFeiaabuphAggzfLF9sM9UXRrZ |
ZacharyZhang-NY
left a comment
There was a problem hiding this comment.
Reviewed PR #5579 at head f23f292.
Approved. Loading rustchain_v2_integrated_v2.2.1_rip200.py by file path is the right shape for this test module because the filename contains dots and cannot be imported through a normal Python module path. The fixture also sets RUSTCHAIN_DB_PATH and RC_ADMIN_KEY before import, which keeps the integrated node import isolated for this test file.
Validation run:
git diff --check origin/main...HEAD -- node/tests/test_withdrawal_validation.py
python -B -m py_compile node/tests/test_withdrawal_validation.py
PYTHONPATH=node python -B -m pytest -q node/tests/test_withdrawal_validation.py --noconftest --tb=short
Result: diff check clean, py_compile clean, withdrawal validation tests 7 passed.
TJCurnutte
left a comment
There was a problem hiding this comment.
Approved.
I checked this on head f23f2920aa9c62f155abf73014e0a18fba6ecf54. The prior normal import path for rustchain_v2_integrated_v2.2.1_rip200.py is not a valid Python module path because of the dotted numeric filename, so loading it with importlib.util.spec_from_file_location() is the right shape here. The fixture also scopes RUSTCHAIN_DB_PATH to a tmp SQLite DB, sets/restores RC_ADMIN_KEY, and then drives the real Flask app through the existing withdrawal validation cases.
Validation run:
git diff --check origin/main...HEAD -- node/tests/test_withdrawal_validation.py
python3 -B -m py_compile node/tests/test_withdrawal_validation.py
PYTHONPATH=node python3 -B -m pytest -q node/tests/test_withdrawal_validation.pyResult: 7 passed, 1 warning in 0.38s.
No blockers from me.
jaxint
left a comment
There was a problem hiding this comment.
LGTM! Great work on this PR. 🚀
kekehanshujun
left a comment
There was a problem hiding this comment.
Requesting changes because this can still fail during pytest collection/import in a normal test run where prometheus_client is installed.
The repository tests/conftest.py already preloads node/rustchain_v2_integrated_v2.2.1_rip200.py as integrated_node. This PR's fixture then executes the same integrated node file again under a second module name via spec_from_file_location(...). Since that module defines Prometheus Counter/Gauge objects at import time with fixed names, the second import can raise duplicated-timeseries errors before the withdrawal tests run.
Please either reuse the conftest-loaded integrated_node module or patch/unregister the Prometheus metric constructors during the second import, matching the more defensive pattern used in other withdrawal-validation fixes.
|
Fixed in What changed:
RED check before the fix: Validation after the fix: No private keys, tokens, wallet secrets, production writes, withdrawals, transfers, or fund movement were used. |
|
Closing as duplicate of #5478 (canonical first-poster on this issue per Codex forensic audit 2026-05-18). Both PRs target the same root cause: test-loader module-import-with-dots fix. Bounty credit goes to #5478. Thanks for the contribution — for next time, please check open PRs against the same issue before filing. |
Summary
node/tests/test_withdrawal_validation.pyviaimportlib.util.spec_from_file_locationso the dotted filenamerustchain_v2_integrated_v2.2.1_rip200.pyis not parsed as a Python package importRUSTCHAIN_DB_PATHand testRC_ADMIN_KEYbefore importing the integrated node, then reuse the loaded module across the test fileCloses #5476.
Validation
python3 -B -m py_compile node/tests/test_withdrawal_validation.pyPYTEST_DISABLE_PLUGIN_AUTOLOAD=1 PYTHONPATH=. python3 -B -m pytest -q node/tests/test_withdrawal_validation.py --noconftest-> 7 passedgit diff --checkpython3 tools/bcos_spdx_check.py --base-ref origin/main-> BCOS SPDX check: OKNote
node/tests/test_withdraw_amount_validation.pystill exposes an existing cross-file integrated-node reimport/Prometheus registration problem outside this one-file fix; this PR keeps the test_withdrawal_validation.py fails to compile #5476 compile repair scoped.