-
Notifications
You must be signed in to change notification settings - Fork 41
add test for handling failed RGB forward swaps #121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| use super::*; | ||
|
|
||
| const TEST_DIR_BASE: &str = "tmp/swap_roundtrip_fail_forward/"; | ||
|
|
||
| #[serial_test::serial] | ||
| #[tokio::test(flavor = "multi_thread", worker_threads = 1)] | ||
| #[traced_test] | ||
| async fn swap_fail_forward_marks_taker_failed() { | ||
| initialize(); | ||
|
|
||
| let test_dir_node1 = format!("{TEST_DIR_BASE}node1"); | ||
| let test_dir_node2 = format!("{TEST_DIR_BASE}node2"); | ||
| let (node1_addr, _) = start_node(&test_dir_node1, NODE1_PEER_PORT, false).await; | ||
| let (node2_addr, _) = start_node(&test_dir_node2, NODE2_PEER_PORT, false).await; | ||
|
|
||
| fund_and_create_utxos(node1_addr, None).await; | ||
| fund_and_create_utxos(node2_addr, None).await; | ||
|
|
||
| let asset_id = issue_asset_nia(node2_addr).await.asset_id; | ||
|
|
||
| let node1_pubkey = node_info(node1_addr).await.pubkey; | ||
| let node2_pubkey = node_info(node2_addr).await.pubkey; | ||
|
|
||
| open_channel( | ||
| node1_addr, | ||
| &node2_pubkey, | ||
| Some(NODE2_PEER_PORT), | ||
| Some(5000000), | ||
| Some(546000), | ||
| None, | ||
| None, | ||
| ) | ||
| .await; | ||
| open_channel( | ||
| node2_addr, | ||
| &node1_pubkey, | ||
| Some(NODE1_PEER_PORT), | ||
| None, | ||
| None, | ||
| Some(600), | ||
| Some(&asset_id), | ||
| ) | ||
| .await; | ||
| wait_for_usable_channels(node1_addr, 2).await; | ||
| wait_for_usable_channels(node2_addr, 2).await; | ||
|
|
||
| println!("\nsetup swap"); | ||
| let maker_addr = node1_addr; | ||
| let taker_addr = node2_addr; | ||
| let qty_from = 10; | ||
| let qty_to = 50000; | ||
| let maker_init_response = | ||
| maker_init(maker_addr, qty_from, Some(&asset_id), qty_to, None, 3600).await; | ||
| taker(taker_addr, maker_init_response.swapstring.clone()).await; | ||
|
|
||
| let swaps_maker = list_swaps(maker_addr).await; | ||
| assert!(swaps_maker.taker.is_empty()); | ||
| assert_eq!(swaps_maker.maker.len(), 1); | ||
| assert_eq!( | ||
| swaps_maker.maker.first().unwrap().status, | ||
| SwapStatus::Waiting | ||
| ); | ||
|
|
||
| let swaps_taker = list_swaps(taker_addr).await; | ||
| assert!(swaps_taker.maker.is_empty()); | ||
| assert_eq!(swaps_taker.taker.len(), 1); | ||
| assert_eq!( | ||
| swaps_taker.taker.first().unwrap().status, | ||
| SwapStatus::Waiting | ||
| ); | ||
|
|
||
| crate::ldk::FORCE_NEXT_INTERCEPTED_SWAP_RGB_FORWARD_FAILURE | ||
| .store(true, std::sync::atomic::Ordering::SeqCst); | ||
|
|
||
| println!("\nexecute swap"); | ||
| maker_execute( | ||
| maker_addr, | ||
| maker_init_response.swapstring, | ||
| maker_init_response.payment_secret, | ||
| node2_pubkey, | ||
| ) | ||
| .await; | ||
|
|
||
| wait_for_swap_status( | ||
| maker_addr, | ||
| &maker_init_response.payment_hash, | ||
| SwapStatus::Failed, | ||
| ) | ||
| .await; | ||
|
|
||
| // This assertion documents the expected behavior and currently fails because the | ||
| // HTLCHandlingFailed event is ignored, leaving the taker swap stuck as Pending. | ||
| wait_for_swap_status( | ||
| taker_addr, | ||
| &maker_init_response.payment_hash, | ||
| SwapStatus::Failed, | ||
| ) | ||
| .await; | ||
|
Comment on lines
+91
to
+98
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The global
FORCE_NEXT_INTERCEPTED_SWAP_RGB_FORWARD_FAILUREflag is set here but only reset when an intercepted HTLC is processed (viaswap(false, ...)). If this test fails/panics before that event occurs, the flag can remaintrueand potentially affect later tests in the same run. Consider resetting it back tofalsewith a small RAII drop-guard (or an explicit cleanup in afinally-style block) to prevent cross-test contamination.