Merge bitcoin/bitcoin#36591: test: deduplicate PSBT unknown-field coverage in `rpc_psbt.py`
What changed, and why it matters
This commit only reorganizes existing test code in Bitcoin Core's functional test suite. It moves and deduplicates tests that check how unknown PSBT fields are preserved when PSBTs are combined or processed by the wallet. No production code was changed, and no security bug was fixed or introduced.
No security action required. This is a routine test-maintenance refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors test/functional/rpc_psbt.py. It extracts the ‘unknown values are just passed through’ walletprocesspsbt test into a new method test_unknown_fields_passthrough(), and merges redundant combinepsbt unknown-field coverage into the existing test_combinepsbt_preserves_unknown_fields(). The diff is purely test-code movement and consolidation (+25/-24 lines). No C++ source code (including psbt.cpp) is modified.
Changed components
test/functional/rpc_psbt.pyInspect captured patch +25 / −24
### test/functional/rpc_psbt.py
@@ -598,6 +598,30 @@ def build_psbt(key, global_value, input_value, output_value):
(unknown_key_a, output_value_b)
))
+ if psbt_version == 0:
+ # The explicit PSBT_GLOBAL_VERSION=0 encoding is equivalent to omitting the
+ # version field, and both accepted v0 encodings can be merged.
+ implicit_v0_psbt = build_psbt(unknown_key_a, None, input_value_a, None)
+ explicit_v0_psbt = build_psbt(unknown_key_b, None, input_value_b, None)
+ explicit_v0_psbt.g.map[PSBT_GLOBAL_VERSION] = (0).to_bytes(4, "little")
+ combined_v0_versions = self.nodes[0].combinepsbt([implicit_v0_psbt.to_base64(), explicit_v0_psbt.to_base64()])
+ decoded = self.nodes[0].decodepsbt(combined_v0_versions)
+ assert_equal(decoded["psbt_version"], psbt_version)
+ assert_equal(decoded["inputs"][0]["unknown"], unknown_fields(
+ (unknown_key_a, input_value_a),
+ (unknown_key_b, input_value_b),
+ ))
+
+ def test_unknown_fields_passthrough(self):
+ self.log.info("Test that unknown values are just passed through")
+ unknown_type = b'\xf0'
+ unknown_key = unknown_type + bytes(range(1, 10))
+ unknown_value = bytes(range(1, 16))
+
+ unknown_psbt = self.create_psbt(inputs={unknown_key: unknown_value}).to_base64()
+ unknown_out = self.nodes[0].walletprocesspsbt(unknown_psbt)['psbt']
+ assert_equal(unknown_psbt, unknown_out)
+
def test_sighash_mismatch(self):
self.log.info("Test sighash type mismatches")
self.nodes[0].createwallet("sighash_mismatch")
@@ -1262,30 +1286,7 @@ def run_test(self):
assert_raises_rpc_error(-4, "Insufficient funds", wunsafe.walletcreatefundedpsbt, [], [{self.nodes[0].getnewaddress(): 1}])
wunsafe.walletcreatefundedpsbt([], [{self.nodes[0].getnewaddress(): 1}], 0, {"include_unsafe": True})
- self.log.info("Test that unknown values are just passed through")
- unknown_type = b'\xf0'
- unknown_key = unknown_type + bytes(range(1, 10))
- unknown_value = bytes(range(1, 16))
-
- unknown_psbt = self.create_psbt(inputs={unknown_key: unknown_value}).to_base64()
- unknown_out = self.nodes[0].walletprocesspsbt(unknown_psbt)['psbt']
- assert_equal(unknown_psbt, unknown_out)
-
- unknown_key2 = unknown_type + bytes(range(1, 9)) + bytes(11)
- unknown_psbt2 = self.create_psbt(inputs={unknown_key2: unknown_value}).to_base64()
- merged_unknown = self.nodes[0].combinepsbt([unknown_psbt, unknown_psbt2])
- merged_unknown_psbt = PSBT.from_base64(merged_unknown)
- assert_equal(merged_unknown_psbt.i[0].map[unknown_key], unknown_value)
- assert_equal(merged_unknown_psbt.i[0].map[unknown_key2], unknown_value)
-
- # The explicit PSBT_GLOBAL_VERSION=0 encoding is equivalent to omitting the
- # version field, and both accepted v0 encodings can be merged.
- explicit_v0_psbt = self.create_psbt(inputs={unknown_key2: unknown_value})
- explicit_v0_psbt.g.map[PSBT_GLOBAL_VERSION] = (0).to_bytes(4, "little")
- merged_v0_versions = self.nodes[0].combinepsbt([unknown_psbt, explicit_v0_psbt.to_base64()])
- merged_v0_versions_psbt = PSBT.from_base64(merged_v0_versions)
- assert_equal(merged_v0_versions_psbt.i[0].map[unknown_key], unknown_value)
- assert_equal(merged_v0_versions_psbt.i[0].map[unknown_key2], unknown_value)
+ self.test_unknown_fields_passthrough()
# BIP 174 Test Vectors
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.