From 44d728cf81b26c60f067cee6df1af2daf65c2d54 Mon Sep 17 00:00:00 2001 From: Tiago Carvalho Date: Tue, 19 Nov 2024 15:33:47 +0000 Subject: [PATCH] Add signer str ext --- crates/packet-forward/src/tests.rs | 12 ++++++------ crates/packet-forward/src/tests/utils.rs | 19 +++++++++++++++---- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/crates/packet-forward/src/tests.rs b/crates/packet-forward/src/tests.rs index b60f1d2..e12778a 100644 --- a/crates/packet-forward/src/tests.rs +++ b/crates/packet-forward/src/tests.rs @@ -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, ), ); @@ -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(); @@ -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(), @@ -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(), }, diff --git a/crates/packet-forward/src/tests/utils.rs b/crates/packet-forward/src/tests/utils.rs index a7e9625..2bd7c99 100644 --- a/crates/packet-forward/src/tests/utils.rs +++ b/crates/packet-forward/src/tests/utils.rs @@ -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 { @@ -356,7 +367,7 @@ impl PfmContext for Store { _channel: &ChannelId, _original_sender: &Signer, ) -> Result { - Ok(addresses::ESCROW_ACCOUNT.to_string().into()) + Ok(addresses::ESCROW_ACCOUNT.signer()) } fn timeout_timestamp( @@ -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(), } @@ -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,