Skip to content

Commit 294dab4

Browse files
committed
feat: add batch response ordering test
1 parent 0964ab8 commit 294dab4

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/raw_client.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,25 @@ mod test {
11911191
assert_eq!(resp.hash_function, Some("sha256".into()));
11921192
assert_eq!(resp.pruning, None);
11931193
}
1194+
1195+
#[test]
1196+
fn test_batch_response_ordering() {
1197+
// The electrum.blockstream.info:50001 node always sends back ordered responses which will make this always pass.
1198+
// However, many servers do not, so we use one of those servers for this test.
1199+
let client = RawClient::new("exs.dyshek.org:50001", None).unwrap();
1200+
let heights: Vec<u32> = vec![1, 4, 8, 12, 222, 6666, 12];
1201+
let result_times = [
1202+
1231469665, 1231470988, 1231472743, 1231474888, 1231770653, 1236456633, 1231474888,
1203+
];
1204+
// Check ordering 10 times. This usually fails within 5 if ordering is incorrect.
1205+
for _ in 0..10 {
1206+
let results = client.batch_block_header(&heights).unwrap();
1207+
for (index, result) in results.iter().enumerate() {
1208+
assert_eq!(result_times[index], result.time);
1209+
}
1210+
}
1211+
}
1212+
11941213
#[test]
11951214
fn test_relay_fee() {
11961215
let client = RawClient::new(get_test_server(), None).unwrap();

0 commit comments

Comments
 (0)