From 4db0d6ed16f07f1f67c61239bd49be5df6fcde7e Mon Sep 17 00:00:00 2001 From: Carl Dong Date: Mon, 25 Mar 2019 17:39:22 -0400 Subject: [PATCH] Add test for tie breaking when sorting outputs --- src/util/transaction_utils.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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()) } -- 2.39.5