Skip to content

Commit

Permalink
Test forward to next middleware on ack exec
Browse files Browse the repository at this point in the history
  • Loading branch information
sug0 committed Nov 19, 2024
1 parent f1bdb1d commit 0bd3d1b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
37 changes: 37 additions & 0 deletions crates/packet-forward/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use ibc_testkit::fixtures::core::channel::dummy_raw_packet;

use self::utils::*;
use super::*;
use crate::new_error_ack;

#[test]
fn decode_ics20_msg_forwards_to_next_middleware() {
Expand Down Expand Up @@ -542,3 +543,39 @@ fn no_state_changes_if_next_fails_on_b() {
assert!(pfm.next.refunds_sent.is_empty());
assert!(pfm.next.ack_and_events_written.is_empty());
}

#[test]
fn nonexisting_ack_for_inflight_packet_not_handled_by_pfm() {
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);

// first, check that we fail exactly where we intend to
// (after checking that we have an ICS-20 packet)
let mut pfm = get_dummy_pfm();
pfm.inject_failure(FailurePoint::RetrieveInFlightPacket);
assert_failure_injection(
FailurePoint::RetrieveInFlightPacket,
pfm.on_acknowledgement_packet_execute_inner(
&mut ModuleExtras::empty(),
&packet,
&new_error_ack("RIP").into(),
),
);

//========

let mut pfm = get_dummy_pfm();
assert!(matches!(
pfm.on_acknowledgement_packet_execute_inner(
&mut ModuleExtras::empty(),
&packet,
&new_error_ack("RIP").into(),
),
Err(MiddlewareError::ForwardToNextMiddleware)
));
}
2 changes: 2 additions & 0 deletions crates/packet-forward/src/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub enum FailurePoint {
AfterNextMiddlewareOnRecvPacket,
BeforeStoreInFlightPacket,
AfterStoreInFlightPacket,
RetrieveInFlightPacket,
}

#[derive(Debug)]
Expand Down Expand Up @@ -396,6 +397,7 @@ impl<M> PfmContext for Store<M> {
&self,
key: &InFlightPacketKey,
) -> Result<Option<InFlightPacket>, Self::Error> {
self.check_failure_injection(FailurePoint::RetrieveInFlightPacket)?;
Ok(self.inflight_packet_store.get(key).cloned())
}

Expand Down

0 comments on commit 0bd3d1b

Please sign in to comment.