Skip to content

Commit

Permalink
feat(electrum): Test sync in reorg and no-reorg situations
Browse files Browse the repository at this point in the history
Add test for `bdk_electrum` to make sure previously unconfirmed
transactions get confirmed again in both reorg and no-reorg
situations.
  • Loading branch information
LagginTimes committed Aug 8, 2024
1 parent 8c62606 commit f274e4c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions crates/electrum/tests/test_electrum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub fn test_update_tx_graph_without_keychain() -> anyhow::Result<()> {
None,
)?;
env.mine_blocks(1, None)?;
env.wait_until_electrum_sees_block()?;
env.wait_until_electrum_sees_block(6)?;

// use a full checkpoint linked list (since this is not what we are testing)
let cp_tip = env.make_checkpoint_tip();
Expand Down Expand Up @@ -198,7 +198,7 @@ pub fn test_update_tx_graph_stop_gap() -> anyhow::Result<()> {
None,
)?;
env.mine_blocks(1, None)?;
env.wait_until_electrum_sees_block()?;
env.wait_until_electrum_sees_block(6)?;

// use a full checkpoint linked list (since this is not what we are testing)
let cp_tip = env.make_checkpoint_tip();
Expand Down Expand Up @@ -240,7 +240,7 @@ pub fn test_update_tx_graph_stop_gap() -> anyhow::Result<()> {
None,
)?;
env.mine_blocks(1, None)?;
env.wait_until_electrum_sees_block()?;
env.wait_until_electrum_sees_block(6)?;

// A scan with gap limit 5 won't find the second transaction, but a scan with gap limit 6 will.
// The last active indice won't be updated in the first case but will in the second one.
Expand Down Expand Up @@ -302,11 +302,11 @@ fn test_sync() -> anyhow::Result<()> {

// Mine some blocks.
env.mine_blocks(101, Some(addr_to_mine))?;
env.wait_until_electrum_sees_block()?;
env.wait_until_electrum_sees_block(6)?;

// Broadcast transaction to mempool.
let txid = env.send(&addr_to_track, SEND_AMOUNT)?;
env.wait_until_electrum_sees_txid(txid)?;
env.wait_until_electrum_sees_txid(txid, 6)?;

sync_with_electrum(
&client,
Expand All @@ -327,7 +327,7 @@ fn test_sync() -> anyhow::Result<()> {

// Mine block to confirm transaction.
env.mine_blocks(1, None)?;
env.wait_until_electrum_sees_block()?;
env.wait_until_electrum_sees_block(6)?;

sync_with_electrum(
&client,
Expand All @@ -348,7 +348,7 @@ fn test_sync() -> anyhow::Result<()> {

// Perform reorg on block with confirmed transaction.
env.reorg_empty_blocks(1)?;
env.wait_until_electrum_sees_block()?;
env.wait_until_electrum_sees_block(6)?;

sync_with_electrum(
&client,
Expand All @@ -368,7 +368,7 @@ fn test_sync() -> anyhow::Result<()> {

// Mine block to confirm transaction again.
env.mine_blocks(1, None)?;
env.wait_until_electrum_sees_block()?;
env.wait_until_electrum_sees_block(6)?;

sync_with_electrum(&client, [spk_to_track], &mut recv_chain, &mut recv_graph)?;

Expand Down Expand Up @@ -455,7 +455,7 @@ fn tx_can_become_unconfirmed_after_reorg() -> anyhow::Result<()> {
}

// Sync up to tip.
env.wait_until_electrum_sees_block()?;
env.wait_until_electrum_sees_block(6)?;
let update = sync_with_electrum(
&client,
[spk_to_track.clone()],
Expand Down Expand Up @@ -487,7 +487,7 @@ fn tx_can_become_unconfirmed_after_reorg() -> anyhow::Result<()> {
for depth in 1..=REORG_COUNT {
env.reorg_empty_blocks(depth)?;

env.wait_until_electrum_sees_block()?;
env.wait_until_electrum_sees_block(6)?;
let update = sync_with_electrum(
&client,
[spk_to_track.clone()],
Expand Down

0 comments on commit f274e4c

Please sign in to comment.