add test for handling failed RGB forward swaps#121
add test for handling failed RGB forward swaps#121Arshia-r-m wants to merge 1 commit intoRGB-Tools:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a regression test intended to reproduce Issue #119 (“swaps stuck in PENDING”) by simulating a failed RGB forward during an intercepted swap, plus a small test-only fault-injection hook in the LDK event handler to trigger the failure path deterministically.
Changes:
- Add a new swap roundtrip test that expects the taker swap to be marked
Failedwhen RGB forwarding fails. - Introduce a
#[cfg(test)]global flag to force the next intercepted swap RGB forward to fail by altering the outbound RGB payment amount. - Register the new test module in
src/test/mod.rs.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/test/swap_roundtrip_fail_forward.rs |
New test that reproduces the stuck-Pending behavior by forcing an RGB forward failure and asserting swaps reach Failed. |
src/test/mod.rs |
Adds the new test module to the test suite. |
src/ldk.rs |
Adds a test-only failure injection flag and uses it to mutate outbound RGB payment during Event::HTLCIntercepted forwarding. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // 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; |
There was a problem hiding this comment.
This test currently asserts taker reaches SwapStatus::Failed, but the comment indicates this is known to fail (taker stays Pending). As written it will make cargo test hang up to 70s and then fail CI. If the fix isn’t included in this PR, mark the test #[ignore] (or otherwise gate it) so the suite stays green; alternatively, include the production fix so the assertion can pass reliably.
| crate::ldk::FORCE_NEXT_INTERCEPTED_SWAP_RGB_FORWARD_FAILURE | ||
| .store(true, std::sync::atomic::Ordering::SeqCst); | ||
|
|
There was a problem hiding this comment.
The global FORCE_NEXT_INTERCEPTED_SWAP_RGB_FORWARD_FAILURE flag is set here but only reset when an intercepted HTLC is processed (via swap(false, ...)). If this test fails/panics before that event occurs, the flag can remain true and potentially affect later tests in the same run. Consider resetting it back to false with a small RAII drop-guard (or an explicit cleanup in a finally-style block) to prevent cross-test contamination.
f9407d7 to
0c05618
Compare
0c05618 to
8689530
Compare
prove the problem on #119