Skip to content

Commit

Permalink
Add signer str ext
Browse files Browse the repository at this point in the history
  • Loading branch information
sug0 committed Nov 19, 2024
1 parent 0e35ffc commit 44d728c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
12 changes: 6 additions & 6 deletions crates/packet-forward/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ fn events_kept_on_errors() {
&mut extras,
Left((&packet, packet_data)),
fwd_metadata,
addresses::A.to_string().into(),
addresses::ESCROW_ACCOUNT.to_string().into(),
addresses::A.signer(),
addresses::ESCROW_ACCOUNT.signer(),
coin_on_this_chain,
),
);
Expand Down Expand Up @@ -286,7 +286,7 @@ fn on_recv_packet_execute_inner(
.unwrap(),
};

pfm.on_recv_packet_execute_inner(&mut extras, &packet, &String::from("relayer").into())?;
pfm.on_recv_packet_execute_inner(&mut extras, &packet, &addresses::RELAYER.signer())?;

let expected_extras = {
let mut ex = ModuleExtras::empty();
Expand Down Expand Up @@ -323,7 +323,7 @@ fn on_recv_packet_execute_inner(
sequence: 0u64.into(),
},
InFlightPacket {
original_sender_address: addresses::A.to_string().into(),
original_sender_address: addresses::A.signer(),
refund_port_id: PortId::transfer(),
refund_channel_id: ChannelId::new(channels::BA),
packet_src_port_id: PortId::transfer(),
Expand All @@ -346,8 +346,8 @@ fn on_recv_packet_execute_inner(
timeout_height_on_b: TimeoutHeight::Never,
timeout_timestamp_on_b: pfm.next.timeout_timestamp(DEFAULT_FORWARD_TIMEOUT).unwrap(),
packet_data: PacketData {
sender: addresses::ESCROW_ACCOUNT.to_string().into(),
receiver: addresses::C.to_string().into(),
sender: addresses::ESCROW_ACCOUNT.signer(),
receiver: addresses::C.signer(),
token: coin_on_this_chain,
memo: String::new().into(),
},
Expand Down
19 changes: 15 additions & 4 deletions crates/packet-forward/src/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,20 @@ pub mod addresses {
pub const D: &str = "d1dionysus";

pub const NULL: &str = "NULL";
pub const RELAYER: &str = "RELAYER";
pub const ESCROW_ACCOUNT: &str = "b1escrowaccount";
}

pub trait StrExt {
fn signer(&self) -> Signer;
}

impl StrExt for str {
fn signer(&self) -> Signer {
self.to_string().into()
}
}

// NOTE: Assume we have three chains: A, B, and C. The tests will be set
// up as if we were chain B, forwarding a packet from A to C.
pub mod channels {
Expand Down Expand Up @@ -356,7 +367,7 @@ impl<M> PfmContext for Store<M> {
_channel: &ChannelId,
_original_sender: &Signer,
) -> Result<Signer, Self::Error> {
Ok(addresses::ESCROW_ACCOUNT.to_string().into())
Ok(addresses::ESCROW_ACCOUNT.signer())
}

fn timeout_timestamp(
Expand Down Expand Up @@ -537,9 +548,9 @@ pub fn get_dummy_packet_data_with_memo(
memo: String,
) -> PacketData {
PacketData {
sender: addresses::A.to_string().into(),
sender: addresses::A.signer(),
// NB: the ICS-20 receiver field is overriden
receiver: addresses::NULL.to_string().into(),
receiver: addresses::NULL.signer(),
token: transfer_coin,
memo: memo.into(),
}
Expand All @@ -564,7 +575,7 @@ pub fn get_dummy_packet_with_data(seq: u64, packet_data: &PacketData) -> Packet

pub fn get_dummy_fwd_metadata() -> msg::ForwardMetadata {
msg::ForwardMetadata {
receiver: addresses::C.to_string().into(),
receiver: addresses::C.signer(),
port: PortId::transfer(),
channel: ChannelId::new(channels::BC),
timeout: None,
Expand Down

0 comments on commit 44d728c

Please sign in to comment.