Skip to content

Commit

Permalink
Merge #178: pset: fix remove_output
Browse files Browse the repository at this point in the history
06d7f90 pset: tests: add coverage for remove_input/output (Leonardo Comandini)
3674c17 pset: fix remove_output (Leonardo Comandini)

Pull request description:

ACKs for top commit:
  RCasatta:
    utACK 06d7f90

Tree-SHA512: 35313fb45267d0c067efbd60af86f588b11d99275f50f7392b16a5845cb8de68950d24e034c576fe0a2f45cd3ea24ee5a44cecb4b8816f7fb04f4eaefddf11dc
  • Loading branch information
RCasatta committed Oct 3, 2023
2 parents 5d80b94 + 06d7f90 commit ecfc231
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/pset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl PartiallySignedTransaction {
/// Remove the output at `index` and return it if any, otherwise returns None
/// This also updates the pset global output count
pub fn remove_output(&mut self, index: usize) -> Option<Output> {
if self.inputs.get(index).is_some() {
if self.outputs.get(index).is_some() {
self.global.tx_data.output_count -= 1;
return Some(self.outputs.remove(index));
}
Expand Down Expand Up @@ -955,4 +955,19 @@ mod tests {
let pset = encode::deserialize::<PartiallySignedTransaction>(&bytes).unwrap();
assert_eq!(&back_hex, &encode::serialize(&pset).to_hex());
}

#[test]
fn pset_remove_in_out() {
let pset_str = include_str!("../../tests/data/pset_swap_tutorial.hex");

let bytes = Vec::<u8>::from_hex(pset_str).unwrap();
let mut pset = encode::deserialize::<PartiallySignedTransaction>(&bytes).unwrap();

let n_inputs = pset.n_inputs();
let n_outputs = pset.n_outputs();
pset.remove_input(n_inputs - 1).unwrap();
pset.remove_output(n_outputs - 1).unwrap();
assert_eq!(pset.n_inputs(), n_inputs - 1);
assert_eq!(pset.n_outputs(), n_outputs - 1);
}
}

0 comments on commit ecfc231

Please sign in to comment.