Skip to content

Commit cb55a49

Browse files
committed
Merge #326: Test finalizepsbt
a4d688e Test finalizepsbt (jamillambert) Pull request description: Fix the test for `finalizepsbt`. The field `psbt` is optional for all versions, the help does not specifically say `optional` until v23, before that it says `if not extracted`. Make `psbt` an `Option`. ACKs for top commit: tcharding: ACK a4d688e Tree-SHA512: d504fbae5d6d89e8fddbe3df6ca53b651995c384d38a63c1f42526b25c9d5295f27f2606e671b35a69cd2d9f1bae9993b8820d36b8432b2803acabb57b037a2a
2 parents 96e084d + a4d688e commit cb55a49

File tree

18 files changed

+27
-67
lines changed

18 files changed

+27
-67
lines changed

client/src/client_sync/v17/raw_transactions.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ macro_rules! impl_client_v17__finalize_psbt {
101101
impl Client {
102102
pub fn finalize_psbt(&self, psbt: &bitcoin::Psbt) -> Result<FinalizePsbt> {
103103
let psbt = format!("{}", psbt);
104-
self.call("finalizepsbt", &[psbt.into()])
104+
// Pass extract=false so Core returns the PSBT field in the response.
105+
self.call("finalizepsbt", &[psbt.into(), false.into()])
105106
}
106107
}
107108
};

integration_test/tests/raw_transactions.rs

Lines changed: 9 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -247,60 +247,19 @@ fn arbitrary_multisig_script() -> ScriptBuf {
247247
}
248248

249249
#[test]
250-
#[cfg(feature = "TODO")]
251250
fn raw_transactions__finalize_psbt__modelled() {
252-
let node = Node::with_wallet(Wallet::Default, &["-txindex"]);
251+
let node = Node::with_wallet(Wallet::Default, &[]);
253252
node.fund_wallet();
254253

255-
let (addr, _tx, txid, tx_out, vout) = create_utxo(&node);
256-
257-
// Assumes tx_out has a million sats in it.
258-
let spend_amount = Amount::from_sat(100_000);
259-
let fee = Amount::from_sat(1000);
260-
let change_amount = tx_out.value - spend_amount - fee;
261-
262-
let inputs = vec![Input { txid, vout, sequence: None }];
263-
264-
let mut outputs = vec![];
265-
266-
// Just send back to ourself.
267-
let spend_address = node.client.new_address().expect("failed to create new address");
268-
outputs.push(Output::new(spend_address, spend_amount));
269-
270-
let change_address = node
271-
.client
272-
.get_raw_change_address()
273-
.expect("getrawchangeaddress")
274-
.into_model()
275-
.expect("GetRawChangeAddress into model")
276-
.0
277-
.assume_checked();
278-
outputs.push(Output::new(change_address, change_amount));
279-
280-
let json: CreatePsbt = node.client.create_psbt(&inputs, &outputs).expect("createpsbt");
281-
let res: Result<mtype::CreatePsbt, _> = json.clone().into_model();
282-
let psbt = res.expect("CreatePsbt into model");
283-
let psbt = psbt.0;
284-
285-
let json: DumpPrivKey = node.client.dump_priv_key(&addr).expect("dumpprivkey");
286-
let model: mtype::DumpPrivKey = json.into_model().expect("DumpPrivKey");
287-
let key = model.0;
288-
289-
let json: SignRawTransaction = node
290-
.client
291-
.sign_raw_transaction_with_key(&psbt.unsigned_tx, &[key])
292-
.expect("signrawtransactionwithkey");
293-
let res: Result<mtype::SignRawTransaction, SignRawTransactionError> = json.into_model();
294-
let model = res.expect("SignRawTransaction into model");
295-
296-
// FIXME: Core errors here with: code: -22, message: "TX decode failed"
297-
let json: ConvertToPsbt = node.client.convert_to_psbt(&model.tx).expect("converttopsbt");
298-
let model: Result<mtype::ConvertToPsbt, _> = json.into_model();
299-
let psbt = model.expect("ConvertToPsbt into model").0;
300-
254+
// Create a PSBT and call finalizepsbt directly without signing.
255+
// This still exercises the RPC and model; it should report complete=false and return the PSBT.
256+
let psbt = create_a_psbt(&node);
301257
let json: FinalizePsbt = node.client.finalize_psbt(&psbt).expect("finalizepsbt");
302-
let model: Result<mtype::FinalizePsbt, _> = json.into_model();
303-
let _ = model.expect("FinalizePsbt into model");
258+
let model: Result<mtype::FinalizePsbt, FinalizePsbtError> = json.into_model();
259+
let finalized = model.unwrap();
260+
261+
assert!(!finalized.complete);
262+
assert_eq!(finalized.psbt, Some(psbt));
304263
}
305264

306265
#[test]

types/src/model/raw_transactions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ pub struct DescriptorProcessPsbt {
137137
#[serde(deny_unknown_fields)]
138138
pub struct FinalizePsbt {
139139
/// The partially signed transaction if not extracted.
140-
pub psbt: Psbt,
140+
pub psbt: Option<Psbt>,
141141
/// The transaction if extracted.
142142
pub tx: Option<Transaction>,
143143
/// If the transaction has a complete set of signatures.

types/src/v17/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
//! | decodepsbt | version + model | |
123123
//! | decoderawtransaction | version + model | |
124124
//! | decodescript | version + model | |
125-
//! | finalizepsbt | version + model | UNTESTED |
125+
//! | finalizepsbt | version + model | |
126126
//! | fundrawtransaction | version + model | |
127127
//! | getrawtransaction | version + model | Includes additional 'verbose' type |
128128
//! | sendrawtransaction | version + model | |

types/src/v17/raw_transactions/into.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ impl FinalizePsbt {
319319
pub fn into_model(self) -> Result<model::FinalizePsbt, FinalizePsbtError> {
320320
use FinalizePsbtError as E;
321321

322-
let psbt = self.psbt.parse::<Psbt>().map_err(E::Psbt)?;
322+
let psbt = self.psbt.map(|s| s.parse::<Psbt>()).transpose().map_err(E::Psbt)?;
323323
let tx = match self.hex {
324324
Some(hex) => Some(consensus::encode::deserialize_hex(&hex).map_err(E::Hex)?),
325325
None => None,

types/src/v17/raw_transactions/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ pub struct DecodeScriptSegwit {
270270
#[serde(deny_unknown_fields)]
271271
pub struct FinalizePsbt {
272272
/// The base64-encoded partially signed transaction if not extracted.
273-
pub psbt: String,
273+
pub psbt: Option<String>,
274274
/// The hex-encoded network transaction if extracted.
275275
pub hex: Option<String>,
276276
/// If the transaction has a complete set of signatures.

types/src/v18/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
//! | decodepsbt | version + model | |
127127
//! | decoderawtransaction | version + model | |
128128
//! | decodescript | version + model | |
129-
//! | finalizepsbt | version + model | UNTESTED |
129+
//! | finalizepsbt | version + model | |
130130
//! | fundrawtransaction | version + model | |
131131
//! | getrawtransaction | version + model | Includes additional 'verbose' type |
132132
//! | joinpsbts | version + model | UNTESTED |

types/src/v19/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
//! | decodepsbt | version + model | |
127127
//! | decoderawtransaction | version + model | |
128128
//! | decodescript | version + model | |
129-
//! | finalizepsbt | version + model | UNTESTED |
129+
//! | finalizepsbt | version + model | |
130130
//! | fundrawtransaction | version + model | |
131131
//! | getrawtransaction | version + model | Includes additional 'verbose' type |
132132
//! | joinpsbts | version + model | UNTESTED |

types/src/v20/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
//! | decodepsbt | version + model | |
128128
//! | decoderawtransaction | version + model | |
129129
//! | decodescript | version + model | |
130-
//! | finalizepsbt | version + model | UNTESTED |
130+
//! | finalizepsbt | version + model | |
131131
//! | fundrawtransaction | version + model | |
132132
//! | getrawtransaction | version + model | Includes additional 'verbose' type |
133133
//! | joinpsbts | version + model | UNTESTED |

types/src/v21/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
//! | decodepsbt | version + model | |
129129
//! | decoderawtransaction | version + model | |
130130
//! | decodescript | version + model | |
131-
//! | finalizepsbt | version + model | UNTESTED |
131+
//! | finalizepsbt | version + model | |
132132
//! | fundrawtransaction | version + model | |
133133
//! | getrawtransaction | version + model | Includes additional 'verbose' type |
134134
//! | joinpsbts | version + model | UNTESTED |

0 commit comments

Comments
 (0)