Skip to content

Commit ed0b4a8

Browse files
committed
feat(test): add unified test for mempool methods
1 parent 0a87280 commit ed0b4a8

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

src/lib.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,4 +1336,66 @@ mod test {
13361336
// Assert that both outputs are returned as unspent (spent == false).
13371337
assert!(outspends_blocking.iter().all(|output| !output.spent));
13381338
}
1339+
1340+
#[cfg(all(feature = "blocking", feature = "async"))]
1341+
#[tokio::test]
1342+
async fn test_mempool_methods() {
1343+
let (blocking_client, async_client) = setup_clients().await;
1344+
1345+
let address = BITCOIND
1346+
.client
1347+
.new_address_with_type(AddressType::Legacy)
1348+
.unwrap();
1349+
1350+
for _ in 0..5 {
1351+
let _txid = BITCOIND
1352+
.client
1353+
.send_to_address(&address, Amount::from_sat(1000))
1354+
.unwrap()
1355+
.txid()
1356+
.unwrap();
1357+
}
1358+
1359+
// Wait for transactions to propagate to electrs' mempool.
1360+
tokio::time::sleep(tokio::time::Duration::from_secs(10)).await;
1361+
1362+
// Test `get_mempool_stats`
1363+
let stats_blocking = blocking_client.get_mempool_stats().unwrap();
1364+
let stats_async = async_client.get_mempool_stats().await.unwrap();
1365+
assert_eq!(stats_blocking, stats_async);
1366+
assert!(stats_blocking.count >= 5);
1367+
1368+
// Test `get_mempool_recent_txs`
1369+
let recent_blocking = blocking_client.get_mempool_recent_txs().unwrap();
1370+
let recent_async = async_client.get_mempool_recent_txs().await.unwrap();
1371+
assert_eq!(recent_blocking, recent_async);
1372+
assert!(recent_blocking.len() <= 10);
1373+
assert!(!recent_blocking.is_empty());
1374+
1375+
// Test `get_mempool_txids`
1376+
let txids_blocking = blocking_client.get_mempool_txids().unwrap();
1377+
let txids_async = async_client.get_mempool_txids().await.unwrap();
1378+
assert_eq!(txids_blocking, txids_async);
1379+
assert!(txids_blocking.len() >= 5);
1380+
1381+
// Test `get_mempool_scripthash_txs`
1382+
let script = address.script_pubkey();
1383+
let scripthash_txs_blocking = blocking_client.get_mempool_scripthash_txs(&script).unwrap();
1384+
let scripthash_txs_async = async_client
1385+
.get_mempool_scripthash_txs(&script)
1386+
.await
1387+
.unwrap();
1388+
assert_eq!(scripthash_txs_blocking, scripthash_txs_async);
1389+
assert_eq!(scripthash_txs_blocking.len(), 5);
1390+
1391+
// Test `get_mempool_address_txs`
1392+
let mempool_address_txs_blocking =
1393+
blocking_client.get_mempool_address_txs(&address).unwrap();
1394+
let mempool_address_txs_async = async_client
1395+
.get_mempool_address_txs(&address)
1396+
.await
1397+
.unwrap();
1398+
assert_eq!(mempool_address_txs_blocking, mempool_address_txs_async);
1399+
assert_eq!(mempool_address_txs_blocking.len(), 5);
1400+
}
13391401
}

0 commit comments

Comments
 (0)