Skip to content

Commit

Permalink
test for packet timeout on channel close
Browse files Browse the repository at this point in the history
  • Loading branch information
rnbguy committed May 7, 2024
1 parent b3a1f0a commit 7fb3ffc
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions ibc-testkit/src/relayer/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,68 @@ where

// timeout the packet on A; never relay the packet to B
relayer.timeout_packet_on_a(packet.clone(), signer.clone());

// timeout packet from A to B; using close channel

// generate packet for DummyTransferModule
let packet_data = PacketData {
token: PrefixedCoin::from_str("1000uibc").expect("valid prefixed coin"),
sender: signer.clone(),
receiver: signer.clone(),
memo: "sample memo".into(),
};

// packet with ibc metadata
// either height timeout or timestamp timeout must be set
let msg = MsgTransfer {
port_id_on_a: PortId::transfer(),
chan_id_on_a: chan_id_on_a.clone(),
packet_data,
// setting timeout height to 10 blocks from B's current height.
timeout_height_on_b: relayer.get_ctx_b().latest_height().add(10).into(),
// not setting timeout timestamp.
timeout_timestamp_on_b: Timestamp::none(),
};

// module creates the send_packet
send_transfer(
relayer.get_ctx_a_mut().ibc_store_mut(),
&mut DummyTransferModule,
msg,
)
.expect("successfully created send_packet");

// send_packet wasn't committed, hence produce a block
relayer.get_ctx_a_mut().advance_block_height();

// retrieve the send_packet event
let Some(IbcEvent::SendPacket(send_packet_event)) = relayer
.get_ctx_a()
.ibc_store()
.events
.lock()
.iter()
.rev()
.nth(2)
.cloned()
else {
panic!("unexpected event")
};

// create the IBC packet type
let packet = Packet {
port_id_on_a: send_packet_event.port_id_on_a().clone(),
chan_id_on_a: send_packet_event.chan_id_on_a().clone(),
seq_on_a: *send_packet_event.seq_on_a(),
data: send_packet_event.packet_data().to_vec(),
timeout_height_on_b: *send_packet_event.timeout_height_on_b(),
timeout_timestamp_on_b: *send_packet_event.timeout_timestamp_on_b(),
port_id_on_b: send_packet_event.port_id_on_b().clone(),
chan_id_on_b: send_packet_event.chan_id_on_b().clone(),
};

// timeout the packet on A; never relay the packet to B
relayer.timeout_packet_on_channel_close_on_a(packet.clone(), signer.clone());
}

#[cfg(test)]
Expand Down

0 comments on commit 7fb3ffc

Please sign in to comment.