Skip to content

Commit 7e142a7

Browse files
committed
feat(test): add unified test for mempool methods
1 parent 9c76e43 commit 7e142a7

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

0 commit comments

Comments
 (0)