From: Carl Dong Date: Mon, 25 Mar 2019 21:39:22 +0000 (-0400) Subject: Add test for tie breaking when sorting outputs X-Git-Tag: v0.0.12~216^2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=4db0d6ed16f07f1f67c61239bd49be5df6fcde7e;p=rust-lightning Add test for tie breaking when sorting outputs --- diff --git a/src/util/transaction_utils.rs b/src/util/transaction_utils.rs index f9ee1bd82..a7c1e6bc6 100644 --- a/src/util/transaction_utils.rs +++ b/src/util/transaction_utils.rs @@ -88,6 +88,26 @@ mod tests { assert_eq!(&outputs, &vec![(txout1_, "ignore"), (txout2_, "ignore")]); } + #[test] + fn sort_output_tie_breaker_test() { + let txout1 = TxOut { + value: 100, + script_pubkey: Builder::new().push_int(1).push_int(2).into_script() + }; + let txout1_ = txout1.clone(); + + let txout2 = txout1.clone(); + let txout2_ = txout1.clone(); + + let mut outputs = vec![(txout1, 420), (txout2, 69)]; + sort_outputs(&mut outputs, |a, b| { a.cmp(b) }); + + assert_eq!( + &outputs, + &vec![(txout2_, 69), (txout1_, 420)] + ); + } + fn script_from_hex(hex_str: &str) -> Script { Script::from(decode(hex_str).unwrap()) }