Skip to content

Union Protocol: Base Tests + Documentation#228

Open
ValentinVaninetti wants to merge 5 commits intomainfrom
union_protocol_utilities_and_docs
Open

Union Protocol: Base Tests + Documentation#228
ValentinVaninetti wants to merge 5 commits intomainfrom
union_protocol_utilities_and_docs

Conversation

@ValentinVaninetti
Copy link
Contributor

@ValentinVaninetti ValentinVaninetti commented Dec 4, 2025

Summary
Adds comprehensive test coverage for Union protocol operations with supporting infrastructure and documentation.

Tests: 168 passing (<30ms total)
Coverage: Fee estimation, output construction, protocol IDs, transaction naming

What's Included
New Test Modules
Fee Estimation (25 tests)
Transaction weight calculation (BIP-141), monotonicity validation, overflow protection, boundary cases

Output Builders (18 tests)
P2WPKH operator outputs and Taproot deposit construction with dust threshold validation

Expanded Coverage
Common Utilities (50 tests)
Protocol ID generation with determinism and collision prevention across committee operations

Indexed Names (73 tests)
Transaction naming format validation with security checks (Unicode edge cases, leading zeros, malformed inputs)

Helper Infrastructure (tests/helpers/)
test_helpers.rs - Deterministic fixtures (keys, committees, Bitcoin constants) with #[cfg(test)] guards
test_generators.rs - Algorithmic test case generation (boundaries, powers of 2/10, fee combinations)
test_validators.rs - Independent validation oracle (Bitcoin Core methodology)
test_assertions.rs - Domain-specific assertions with clear error messages
Scripts
run_union_tests.sh - Filtered test execution with summary output
ci_check.sh - Pre-push validation (format, compile, test)
Key Design Decisions
Test Oracle Pattern:
test_validators.rs uses independent validation logic separate from production code. This follows Bitcoin Core's methodology - if production validation is refactored incorrectly, the independent oracle catches regressions.

Edge Case Coverage:
Bitcoin transaction handling requires testing boundary values (0, 1, u64::MAX), overflow scenarios (attack vectors in fee estimation), and relay policy compliance (546 sat dust threshold).

Safety:

Test-only crypto helpers guarded with #[cfg(test)] and explicit security warnings
Protocol invariant tests reference BIPs (BIP-141 for SegWit, BIP-340 for Taproot)
Removed 2 redundant tests after coverage analysis

**Review Focus:

Do tests validate actual Bitcoin behavior per BIPs?
Are critical invariants (fee estimation, output construction) properly tested?
Is test-only crypto material properly isolated?**

ValentinVaninetti and others added 3 commits December 19, 2025 12:27
- Refactor  TEST_GUIDE.md explaining test design principles and what each test validates
- Document real-world scenarios and security considerations (Unicode attacks, overflow)
- Explain helper architecture (generators, validators, oracles)
- Include rationale for testing patterns and edge cases
- Add future improvements section (proptest, fuzzing)
Removed references to ARCHITECTURE.md and FINAL_SUMMARY.md from README.
- Add #[cfg(test)] guards + security warnings to test key generators
- Fix 6 weak assertions using proper output type helpers
- Remove 2 redundant weight calculation tests
- Add expected panic messages for overflow tests
- Document test oracle pattern and BIP-141 references
Tests: 168 passing (was 170, removed 2 redundant)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant