Skip to content

test: Cover IsNull() for PSBT, PSBTInput, PSBTOutput - #35848

Closed
nebula-21 wants to merge 1 commit into
bitcoin:masterfrom
nebula-21:add-psbt-isnull-test
Closed

nebula-21 wants to merge 1 commit into
bitcoin:masterfrom
nebula-21:add-psbt-isnull-test

Conversation

@nebula-21

Copy link
Copy Markdown
Contributor

The motivation for this PR came while reviewing PR#35553, I noticed on corecheck that the IsNull() functions of PartiallySignedTransaction, PSBTInput, PSBTOutput weren't covered by any test.

This PR adds coverage for all of them.

This cases can be tested with the next diffs that don't cause test failure prior to this PR, but with this new test do:

Diff for PartiallySignedTransaction
diff --git a/src/psbt.cpp b/src/psbt.cpp
index 8f2e9ab16f..59bb05822d 100644
--- a/src/psbt.cpp
+++ b/src/psbt.cpp
@@ -33,7 +33,7 @@ PartiallySignedTransaction::PartiallySignedTransaction(const CMutableTransaction
 
 bool PartiallySignedTransaction::IsNull() const
 {
-    return inputs.empty() && outputs.empty() && unknown.empty();
+    return inputs.empty() && outputs.empty() && !unknown.empty();
 }
Diff for PSBTInput
diff --git a/src/psbt.cpp b/src/psbt.cpp
index 8f2e9ab16f..20c745f7a4 100644
--- a/src/psbt.cpp
+++ b/src/psbt.cpp
@@ -291,7 +291,7 @@ COutPoint PSBTInput::GetOutPoint() const
 
 bool PSBTInput::IsNull() const
 {
-    return !non_witness_utxo && witness_utxo.IsNull() && partial_sigs.empty() && unknown.empty() && hd_keypaths.empty() && redeem_script.empty() && witness_script.empty();
+    return non_witness_utxo && witness_utxo.IsNull() && partial_sigs.empty() && unknown.empty() && hd_keypaths.empty() && redeem_script.empty() && witness_script.empty();
 }
Diff for PSBTOutput
diff --git a/src/psbt.cpp b/src/psbt.cpp
index 8f2e9ab16f..fdfdfe903f 100644
--- a/src/psbt.cpp
+++ b/src/psbt.cpp
@@ -530,7 +530,7 @@ void PSBTOutput::FromSignatureData(const SignatureData& sigdata)
 
 bool PSBTOutput::IsNull() const
 {
-    return redeem_script.empty() && witness_script.empty() && hd_keypaths.empty() && unknown.empty();
+    return !redeem_script.empty() && witness_script.empty() && hd_keypaths.empty() && unknown.empty();
 }

@DrahtBot DrahtBot added the Tests label Jul 30, 2026
@DrahtBot

DrahtBot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35848.

Reviews

See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #35797 (psbt: support output metadata updates before inputs are added by l0rinc)
  • #35747 (wallet: Fix FillPSBT failing to sign owned inputs when UTXOs disagree by nervana21)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@nebula-21 nebula-21 changed the title test: Cover IsNull() for PSBT, PSBTInput, PSBTOutput test: Cover IsNull() for PSBT, PSBTInput, PSBTOutput Jul 30, 2026
@DrahtBot

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task tidy: https://github.com/bitcoin/bitcoin/actions/runs/30558606139/job/90925472611
LLM reason (✨ experimental): CI failed because clang-tidy reported a bugprone-argument-comment warning-as-error: the comment argument name amount in test/psbt_tests.cpp doesn’t match the parameter name nValueIn.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

@jeanpablojp

Copy link
Copy Markdown
Contributor

The test works and I have no objections to the code. But other than this PR's test, the only caller of the three IsNull() in the tree is the fuzz target, and I couldn't find any other test in the codebase with this pattern (covering a function with no production use).

I have a concept question: does it make sense to cover these methods, or would it be better to remove them (and the fuzzer calls)?

@maflcko

maflcko commented Aug 18, 2026

Copy link
Copy Markdown
Member

@nebula-21 Are you still working on this, or can it be closed?

@DrahtBot

Copy link
Copy Markdown
Contributor

🐙 This pull request conflicts with the target branch and needs rebase.

@nebula-21

Copy link
Copy Markdown
Contributor Author

The test works and I have no objections to the code. But other than this PR's test, the only caller of the three IsNull() in the tree is the fuzz target, and I couldn't find any other test in the codebase with this pattern (covering a function with no production use).

I have a concept question: does it make sense to cover these methods, or would it be better to remove them (and the fuzzer calls)?

Agree, opened a new PR removing the methods and added you as coauthor.

@nebula-21
nebula-21 deleted the add-psbt-isnull-test branch August 18, 2026 18:33
sedited added a commit that referenced this pull request Aug 19, 2026
2c16efb psbt: Remove unused IsNull() methods (nebula-21)

Pull request description:

  This PR removes the `IsNull()` methods from `PartiallySignedTransaction`, `PSBTInput`, and `PSBTOutput`, along with their calls from the fuzz target.

  This methods have no production callers, their only callers are the fuzz target. As such, keeping these methods seems not useful.

  The motivation for this PR came from jeanpablojp's comment on [#35848](#35848 (comment)), added him as coauthor.

ACKs for top commit:
  maflcko:
    review ACK 2c16efb 🥑
  vicjuma:
    ACK 2c16efb
  sedited:
    ACK 2c16efb

Tree-SHA512: 129933ae9803a2d053e340ee2a85efd1e5d9e5e38833fac0a0a9cbd467fec3157087959c464a8eeedb04ea99b1e5d7eba5a2fafde2e78a4fabcd247fac855477
Kino1994 pushed a commit to Kino1994/bitcoin-full-history that referenced this pull request Aug 23, 2026
2c16efbb7b5b5f0b188f320d9d4c92af602e9128 psbt: Remove unused IsNull() methods (nebula-21)

Pull request description:

  This PR removes the `IsNull()` methods from `PartiallySignedTransaction`, `PSBTInput`, and `PSBTOutput`, along with their calls from the fuzz target.

  This methods have no production callers, their only callers are the fuzz target. As such, keeping these methods seems not useful.

  The motivation for this PR came from jeanpablojp's comment on [#35848](bitcoin/bitcoin#35848 (comment)), added him as coauthor.

ACKs for top commit:
  maflcko:
    review ACK 2c16efbb7b5b5f0b188f320d9d4c92af602e9128 🥑
  vicjuma:
    ACK 2c16efbb7b5b5f0b188f320d9d4c92af602e9128
  sedited:
    ACK 2c16efbb7b5b5f0b188f320d9d4c92af602e9128

Tree-SHA512: 129933ae9803a2d053e340ee2a85efd1e5d9e5e38833fac0a0a9cbd467fec3157087959c464a8eeedb04ea99b1e5d7eba5a2fafde2e78a4fabcd247fac855477
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants