This PR adds test coverage for PartiallySignedTransaction::Merge() divided into 3 tests:
Only merge PSBTs with same version: The test can be triggered with this mutant as an example:
diff --git a/src/psbt.cpp b/src/psbt.cpp
index 51fb19591a..cf5eef0089 100644
--- a/src/psbt.cpp
+++ b/src/psbt.cpp
@@ -43,7 +43,7 @@ bool PartiallySignedTransaction::Merge(const PartiallySignedTransaction& psbt)
return false;
}
if (GetVersion() != psbt.GetVersion()) {
- return false;
+ return true;
}
for (unsigned int i = 0; i < inputs.size(); ++i) {
Merge PSBT fallback_locktime coverage: If the psbt has no fallback locktime, it adopts the one from the psbt it is merging. The test can be triggered with this mutant as an example:
diff --git a/src/psbt.cpp b/src/psbt.cpp
index 51fb19591a..ce909eb062 100644
--- a/src/psbt.cpp
+++ b/src/psbt.cpp
@@ -53,7 +53,7 @@ bool PartiallySignedTransaction::Merge(const PartiallySignedTransaction& psbt)
outputs[i].Merge(psbt.outputs[i]);
}
MergeGlobalXPubs(psbt);
- if (fallback_locktime == std::nullopt && psbt.fallback_locktime != std::nullopt) fallback_locktime = psbt.fallback_locktime;
+ if (fallback_locktime == std::nullopt || psbt.fallback_locktime != std::nullopt) fallback_locktime = psbt.fallback_locktime;
// Set m_tx_modifiable only if either PSBT had it set
if (m_tx_modifiable.has_value() || psbt.m_tx_modifiable.has_value()) {
While writing this test I had a question: If both PSBTs have a fallback_locktime value, the "this" (receiving side) wins silently. Is this the expected behavior? Why not keep the max or directly fail merging if we have two conflicting fallback_locktimes? The test can be triggered with this mutant as one of the various examples:
diff --git a/src/psbt.cpp b/src/psbt.cpp
index 51fb19591a..29eb910014 100644
--- a/src/psbt.cpp
+++ b/src/psbt.cpp
@@ -56,7 +56,7 @@ bool PartiallySignedTransaction::Merge(const PartiallySignedTransaction& psbt)
if (fallback_locktime == std::nullopt && psbt.fallback_locktime != std::nullopt) fallback_locktime = psbt.fallback_locktime;
// Set m_tx_modifiable only if either PSBT had it set
- if (m_tx_modifiable.has_value() || psbt.m_tx_modifiable.has_value()) {
+ if (m_tx_modifiable.has_value() && psbt.m_tx_modifiable.has_value()) {
// In general, we AND the modifiable flags
std::bitset<8> this_modifiable = m_tx_modifiable.value_or(0);
std::bitset<8> psbt_modifiable = psbt.m_tx_modifiable.value_or(0);