Skip to content

Commit 4db0d6e

Browse files
committed
Add test for tie breaking when sorting outputs
1 parent 91dc91f commit 4db0d6e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/util/transaction_utils.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,26 @@ mod tests {
8888
assert_eq!(&outputs, &vec![(txout1_, "ignore"), (txout2_, "ignore")]);
8989
}
9090

91+
#[test]
92+
fn sort_output_tie_breaker_test() {
93+
let txout1 = TxOut {
94+
value: 100,
95+
script_pubkey: Builder::new().push_int(1).push_int(2).into_script()
96+
};
97+
let txout1_ = txout1.clone();
98+
99+
let txout2 = txout1.clone();
100+
let txout2_ = txout1.clone();
101+
102+
let mut outputs = vec![(txout1, 420), (txout2, 69)];
103+
sort_outputs(&mut outputs, |a, b| { a.cmp(b) });
104+
105+
assert_eq!(
106+
&outputs,
107+
&vec![(txout2_, 69), (txout1_, 420)]
108+
);
109+
}
110+
91111
fn script_from_hex(hex_str: &str) -> Script {
92112
Script::from(decode(hex_str).unwrap())
93113
}

0 commit comments

Comments
 (0)