test(rip-202): B1 integration tests against real derive_verified_device + HARDWARE_WEIGHTS#6746
Conversation
…device + HARDWARE_WEIGHTS B1 unit tests use injected mocks; this proves derive_block_enrollment wires correctly to the REAL anti-VM policy by AST-extracting the closure from the node file (no Flask/DB import). 6 tests, 0 production code touched. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
✅ BCOS v2 Scan Results
What does this mean?The BCOS (Beacon Certified Open Source) engine scans for:
BCOS v2 Engine - Free & Open Source (MIT) - Elyan Labs |
FakerHideInBush
left a comment
There was a problem hiding this comment.
Reviewed current head cefd86570eb3b62dbe366a0c2978fa07ed09530f.
I found one portability blocker in the new integration test:
node/tests/test_rip0202_enrollment_integration.py:120reads the integrated node source withopen(NODE_FILE).read()and no explicit encoding. On Windows, Python defaults to the active ANSI codepage (cp1252in my environment), and collection fails before any test runs becauserustchain_v2_integrated_v2.2.1_rip200.pycontains bytes that are valid UTF-8 but not decodable as cp1252:
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 348384: character maps to <undefined>
That makes the new test file non-portable even though the suite itself is intended to be path-robust. Please open the node file with an explicit encoding, for example:
with open(NODE_FILE, encoding=utf-8) as f:
REAL_DERIVE, REAL_WEIGHTS = _extract_real_funcs(f.read())Validation I ran locally:
python -m py_compile node\tests\test_rip0202_enrollment_integration.py node\rip0202_enrollment.py-> passedgit diff --check origin/main...HEAD -- node/tests/test_rip0202_enrollment_integration.py-> passedpython -m pytest node/tests/test_rip0202_enrollment_integration.py -q-> fails during collection with theUnicodeDecodeErrorabove- With UTF-8 mode forced (
PYTHONUTF8=1),python -m pytest node/tests/test_rip0202_enrollment_integration.py -q-> 6 passed - With UTF-8 mode forced,
python -m pytest node/tests/test_rip0202_enrollment.py node/tests/test_rip0202_enrollment_integration.py -q-> 43 passed
So the harness logic looks sound once the file is decoded as UTF-8; the requested change is just to make that assumption explicit in the test file.
Disclosure: submitting this review for the RustChain code review bounty program (#73); no payment is asserted unless/until maintainers accept it.
MolhamHamwi
left a comment
There was a problem hiding this comment.
I reviewed the RIP-202 enrollment integration test coverage.
Two technical observations:
-
The AST extraction approach is a good compromise for this codebase: it exercises the real
derive_verified_deviceandHARDWARE_WEIGHTSobjects while avoiding the Flask/DB/thread side effects from importing the integrated node module. The test also resolves transitive top-level helper dependencies, so it is less brittle than copying a hand-written stub. -
The duplicate-miner test checks a consensus-relevant edge case: two attestations for the same miner resolve by deterministic total ordering rather than input order. That protects the enrollment snapshot hash from forking if peers receive the same attestations in a different sequence.
I received RTC compensation for this review.
BCOS Checklist
# SPDX-License-Identifier: MIT)What Changed
Adds
node/tests/test_rip0202_enrollment_integration.py— integration tests for the RIP-202 B1 deterministic enrollment module (node/rip0202_enrollment.py, merged dormant in #6692).The existing B1 unit tests (
test_rip0202_enrollment.py) drive the module with injected mockderive_fn/weight_table. This closes the gap the module's own docstring flags:derive_verified_devicelives in the ~10k-line Flask node file and can't be imported directly (module-level app/DB/thread side effects). The test AST-extracts onlyderive_verified_device+HARDWARE_WEIGHTSand their transitive top-level dependency closure into an isolated namespace and execs it — no Flask app, no DB, no network. It then drives the real B1 pipeline with the real anti-VM policy.Key property proved:
derive_block_enrollment(atts, REAL_derive, REAL_weights)equals an independent direct application of the same real functions, for arbitrary device fixtures — so the wiring is correct without hardcoding fragile classification expectations. Also covers the anti-VM invariant (failed fingerprint → excluded regardless of device), snapshot-hash determinism + order-independence, and deterministic duplicate-miner resolution.Scope per operator decision D4 = (a) attestation-level anti-VM (eligibility, not reward magnitude). No production code touched.
Testing / Evidence
Tests are path-robust (resolve the module + node file from
../in the repo layout, or alongside in a flat staging dir;RC_NODE_FILEenv override supported).🤖 Generated with Claude Code