From f1bdb1d3ab716b9f46060189b08705cff38c94f5 Mon Sep 17 00:00:00 2001 From: Tiago Carvalho Date: Tue, 19 Nov 2024 15:42:05 +0000 Subject: [PATCH] Test no state changes on err from next middleware --- crates/packet-forward/src/tests.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/crates/packet-forward/src/tests.rs b/crates/packet-forward/src/tests.rs index e12778a..6e031df 100644 --- a/crates/packet-forward/src/tests.rs +++ b/crates/packet-forward/src/tests.rs @@ -515,3 +515,30 @@ fn happy_flow_from_a_to_c() -> Result<(), crate::MiddlewareError> { Ok(()) } + +#[test] +fn no_state_changes_if_next_fails_on_b() { + let mut pfm = get_dummy_pfm(); + pfm.inject_failure(FailurePoint::AfterNextMiddlewareOnRecvPacket); + + let mut extras = ModuleExtras::empty(); + + let packet_data = get_dummy_packet_data_with_fwd_meta( + get_dummy_coin(100), + msg::PacketMetadata { + forward: get_dummy_fwd_metadata(), + }, + ); + let packet = get_dummy_packet_with_data(0, &packet_data); + + assert_failure_injection( + FailurePoint::AfterNextMiddlewareOnRecvPacket, + pfm.on_recv_packet_execute_inner(&mut extras, &packet, &addresses::RELAYER.signer()), + ); + + assert!(pfm.next.inflight_packet_store.is_empty()); + assert!(pfm.next.sent_transfers.is_empty()); + assert!(pfm.next.refunds_received.is_empty()); + assert!(pfm.next.refunds_sent.is_empty()); + assert!(pfm.next.ack_and_events_written.is_empty()); +}