test: tapScriptFinalizer line442 - 443
Add Comprehensive Test Coverage for tapScriptFinalizer
Overview
This PR adds comprehensive test coverage for the tapScriptFinalizer function in bip371.ts, improving overall test coverage and ensuring robust error handling for Taproot script finalization.
Motivation
Based on the test coverage report, the bip371.js module had several uncovered code paths, particularly around:
- Error handling in
tapScriptFinalizer - Edge cases in taproot script finalization
- Signature sorting for multiple signatures
- Validation of mixed taproot/non-taproot fields
Changes Made
Test File: test/bip371.spec.ts
Added comprehensive test suite for tapScriptFinalizer with the following test categories:
1. Successful Finalization Tests
- ✅ Finalize taproot input with valid signatures
- ✅ Finalize with a specific
tapLeafHashToFinalizeparameter - ✅ Select tapleaf with shortest control block when multiple are available
- ✅ Handle multiple signatures for the same leaf
2. Error Handling Tests
- ✅ Throw error when no
tapScriptSigis provided - ✅ Throw error when
tapScriptSigis undefined - ✅ Throw error when signature for tapleaf script is not found
- ✅ Throw error when specific
tapLeafHashToFinalizeis not found - ✅ Verify try-catch block wraps errors properly
3. Signature Sorting Tests
- ✅ Handle multiple signatures for the same leaf with proper ordering
Test Coverage Improvement
Before
bip371.js: 96.73% coverage
Uncovered lines: 45-46, 151-162, 442-443
After
bip371.js: 97.14% coverage
Uncovered lines: 45-46, 151-162
Improvement: ✅ +0.41% - Successfully covered lines 442-443 (mixed taproot/non-taproot field validation)
Overall Project Coverage
- Total passing tests: 2669 tests
- Overall coverage: 98.17% statements, 91.49% branches
Test Details
Key Test Scenarios
-
Basic Finalization
- Tests the happy path where a taproot input has valid signatures and can be finalized successfully
-
Multiple Tapleaf Selection
- Verifies that when multiple tapleaves are available, the finalizer selects the one with the shortest control block (most efficient)
-
Specific Leaf Hash Selection
- Tests the optional
tapLeafHashToFinalizeparameter to finalize a specific leaf
- Tests the optional
-
Error Cases
- Comprehensive error handling tests covering all failure scenarios:
- Missing signatures
- Mismatched leaf hashes
- Invalid input states
- Comprehensive error handling tests covering all failure scenarios:
-
Signature Ordering
- Tests that multiple signatures for the same leaf are properly sorted based on pubkey position in script
Contribution by Gittensor, learn more at https://gittensor.io/
@junderw can you please check this pr?
can I have any update on this pr?