Skip to content

test(beacon_api): add 62 unit tests for Beacon Atlas Flask API [T4]#6324

Open
waefrebeorn wants to merge 43 commits into
Scottcjn:mainfrom
waefrebeorn:test-beacon-api-t4
Open

test(beacon_api): add 62 unit tests for Beacon Atlas Flask API [T4]#6324
waefrebeorn wants to merge 43 commits into
Scottcjn:mainfrom
waefrebeorn:test-beacon-api-t4

Conversation

@waefrebeorn
Copy link
Copy Markdown

@waefrebeorn waefrebeorn commented May 25, 2026

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

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
@github-actions github-actions Bot added documentation Improvements or additions to documentation BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) node Node server related api API endpoint related tests Test suite changes size/XL PR: 500+ lines labels May 25, 2026
waefrebeorn added a commit to waefrebeorn/Rustchain that referenced this pull request May 25, 2026
Copy link
Copy Markdown
Contributor

@jaxint jaxint left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work on this PR! The code looks clean and well-structured. Thanks for contributing to RustChain! 🦀

Copy link
Copy Markdown
Contributor

@jaxint jaxint left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Great work on this PR. 🚀

Copy link
Copy Markdown
Contributor

@jaxint jaxint left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for the contribution.

Copy link
Copy Markdown
Contributor

@jaxint jaxint left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great contribution! LGTM.

Copy link
Copy Markdown
Contributor

@jaxint jaxint left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

@jaxint jaxint left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing! 🦀

Code looks good. Keep it up! 🚀


Wallet: AhqbFaPBPLMMiaLDzA9WhQcyvv4hMxiteLhPk3NhG1iG

Copy link
Copy Markdown
Contributor

@jaxint jaxint left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! Thanks for contributing to RustChain! 🦀

Copy link
Copy Markdown
Contributor

@jaxint jaxint left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work on this PR! The changes look solid. Keep building! 🚀


RTC Wallet: AhqbFaPBPLMMiaLDzA9WhQcyvv4hMxiteLhPk3NhG1iG

Copy link
Copy Markdown

@shadow88sky shadow88sky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api API endpoint related BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) documentation Improvements or additions to documentation node Node server related size/XL PR: 500+ lines tests Test suite changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants