test(beacon_api): add 62 unit tests for Beacon Atlas Flask API [T4]#6324
test(beacon_api): add 62 unit tests for Beacon Atlas Flask API [T4]#6324waefrebeorn wants to merge 43 commits into
Conversation
Adds max_length parameter to _clean_string_field and caps all user input fields in POST route handlers: - /lock: sender_wallet(128), target_wallet(128), tx_hash(128), receipt_signature(256) - /confirm: proof_ref(256), notes(1024) - /release: release_tx(128), notes(1024) Prevents storage of arbitrarily large strings in bridge_ledger DB.
…s + Row M error handling + Row T test gaps + Row E infrastructure
F6: bare 'except Exception: pass' in inline query miners handler F7: bare 'except Exception: pass' in inline query epoch handler Both now log a warning with exc_info=True so silent failures are observable without changing the fallthrough behaviour. Also: - Mark F3-F5 as FALSE POSITIVES (explorer-api pass is intentional, WalletCheckError exception class is standard Python) - Update board: 107/400 cells vaulted, 49 PRs, 290 fresh gaps
Covers 1109-line Flask API with 22 routes across: - Pure helper functions (required_text_field, positive_float_field, coinbase_addresses_match, clean_pubkey_hex) - 20 tests - Ed25519 signature verification (cryptography lib) - 5 tests - init_beacon_tables (5 tables, 7 indexes) - 3 tests - Health check endpoint - 1 test - Beacon join (register, update, validation, pubkey immutability, coinbase validation, CORS) - 10 tests - Agent query routes (list, single, not found) - 4 tests - Beacon atlas (list, status filter, CORS) - 3 tests - Contracts (list, create) - 3 tests - Bounties list - 1 test - Reputation (list, single, not found) - 2 tests - Relay discover - 1 test - Chat auth - 1 test - Error handling (invalid JSON body) - 1 test Key edge cases: - Pubkey immutability enforced (same pubkey OK, different blocked) - Coinbase address validation (0x prefix, 20-byte length, hex) - CORS preflight handling - Ed25519 real-key verification via cryptography library - Stale connection avoidance (monkey-patched get_db) - NaN/Inf rejection in float fields 62 tests, all pass. Coverage: 0% to covered. RTC: rtc17c0d21f04f6f65c1a85c0aeb5d4a305d57531096
jaxint
left a comment
There was a problem hiding this comment.
Great work on this PR! The code looks clean and well-structured. Thanks for contributing to RustChain! 🦀
jaxint
left a comment
There was a problem hiding this comment.
LGTM! Great work on this PR. 🚀
jaxint
left a comment
There was a problem hiding this comment.
LGTM! Thanks for the contribution.
jaxint
left a comment
There was a problem hiding this comment.
Great contribution! LGTM.
jaxint
left a comment
There was a problem hiding this comment.
Thanks for contributing to RustChain! 🦀
Review Summary:
- Code structure looks good
- Changes align with project goals
- No obvious issues detected
Keep up the great work! 🚀
Wallet: AhqbFaPBPLMMiaLDzA9WhQcyvv4hMxiteLhPk3NhG1iG
jaxint
left a comment
There was a problem hiding this comment.
Thanks for contributing! 🦀
Code looks good. Keep it up! 🚀
Wallet: AhqbFaPBPLMMiaLDzA9WhQcyvv4hMxiteLhPk3NhG1iG
jaxint
left a comment
There was a problem hiding this comment.
Great work! Thanks for contributing to RustChain! 🦀
jaxint
left a comment
There was a problem hiding this comment.
Great work on this PR! The changes look solid. Keep building! 🚀
RTC Wallet: AhqbFaPBPLMMiaLDzA9WhQcyvv4hMxiteLhPk3NhG1iG
shadow88sky
left a comment
There was a problem hiding this comment.
Reviewed the Beacon API test-coverage PR and ran the submitted focused suite locally.
The new test file is not dependency-safe in the current repository environment. It includes test_returns_false_when_cryptography_unavailable, but two other tests still import cryptography unconditionally, so the focused suite fails when that optional dependency is absent.
Local validation:
PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 .venv/bin/python -m pytest node/tests/test_beacon_api.py -q
2 failed, 60 passed
Failing tests:
TestVerifyAgentSignature.test_wrong_signature_returns_false
TestVerifyAgentSignature.test_valid_signature
ModuleNotFoundError: No module named 'cryptography'
Because this PR is test-only, the suite needs to be reliable in the repo normal test environment. Either add cryptography to the project/test dependencies, or guard these two Ed25519 round-trip tests with an explicit pytest.importorskip("cryptography") while keeping the unavailable-dependency behavior test.
Additional validation:
.venv/bin/python -m py_compile node/tests/test_beacon_api.py node/beacon_api.py
passed
git diff --check HEAD~35..HEAD
failed
The branch also changes 21 files despite being titled test(beacon_api): add 62 unit tests for Beacon Atlas Flask API [T4], and git diff --check reports trailing whitespace in unrelated files. I recommend splitting this down to node/tests/test_beacon_api.py and fixing the optional dependency handling before merge.
I received RTC compensation for this review.
T4 \u2014 beacon_api.py test coverage (HIGH criticality)\n\n62 unit tests for (1109 lines, 22 routes) \u2014 was 0% coverage, now covered.\n\n### Test categories:\n| Category | Tests | Key coverage |\n|----------|-------|-------------|\n| Pure helpers | 20 | Required text, positive float, coinbase match, pubkey clean |\n| Signature verify | 5 | Real Ed25519, unavailable, wrong sig, bad hex |\n| DB init | 3 | 5 tables, 7 indexes, idempotent |\n| Health check | 1 | /api/health |\n| Beacon join | 10 | Register, update, missing fields, invalid hex, pubkey immutability, coinbase validation, CORS |\n| Agent queries | 4 | List all, single agent, not found |\n| Beacon atlas | 3 | List agents, CORS |\n| Contracts | 3 | List, create |\n| Bounties | 1 | List |\n| Reputation | 2 | List all, agent not found |\n| Other routes | 3 | Relay discover, chat auth, error handling |\n\n### Key patterns tested:\n- Pubkey immutability (security: prevent identity takeover)\n- Real Ed25519 signing/verification via library\n- CORS preflight headers\n- Coinbase address format validation (0x prefix + 20 bytes hex)\n- Flask g.context workaround for test client DB caching\n\nAll 62 tests pass \u2705\n\n---\nRTC Wallet: rtc17c0d21f04f6f65c1a85c0aeb5d4a305d57531096\n\n## RTC Wallet\nRTC17c0d21f04f6f65c1a85c0aeb5d4a305d57531096