Add test for tie breaking when sorting outputs
authorCarl Dong <accounts@carldong.me>
Mon, 25 Mar 2019 21:39:22 +0000 (17:39 -0400)
committerCarl Dong <accounts@carldong.me>
Mon, 25 Mar 2019 21:39:22 +0000 (17:39 -0400)
src/util/transaction_utils.rs

index f9ee1bd82effd4737176359e64f21087fd8bf51b..a7c1e6bc6f78a48e15b69cf4081f0b88534b30e3 100644 (file)
@@ -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())
        }