From 1da0cbc981b8a410429bdf9a3931c90891b2f7b2 Mon Sep 17 00:00:00 2001 From: Tiago Carvalho Date: Fri, 6 Dec 2024 00:51:02 +0100 Subject: [PATCH] Reduce test code boilerplate --- crates/packet-forward/src/tests/utils.rs | 206 ++--------------------- 1 file changed, 18 insertions(+), 188 deletions(-) diff --git a/crates/packet-forward/src/tests/utils.rs b/crates/packet-forward/src/tests/utils.rs index 9734438..3b63184 100644 --- a/crates/packet-forward/src/tests/utils.rs +++ b/crates/packet-forward/src/tests/utils.rs @@ -97,11 +97,27 @@ impl Store { } } -impl IbcCoreModule for Store +from_middleware! { + impl IbcCoreModule for Store + where + M: IbcCoreModule, +} + +impl MiddlewareModule for Store where M: IbcCoreModule, { - fn on_recv_packet_execute( + type NextMiddleware = M; + + fn next_middleware(&self) -> &M { + &self.middleware + } + + fn next_middleware_mut(&mut self) -> &mut M { + &mut self.middleware + } + + fn middleware_on_recv_packet_execute( &mut self, packet: &Packet, relayer: &Signer, @@ -137,192 +153,6 @@ where }), ) } - - fn on_acknowledgement_packet_validate( - &self, - packet: &Packet, - acknowledgement: &Acknowledgement, - relayer: &Signer, - ) -> Result<(), PacketError> { - self.middleware - .on_acknowledgement_packet_validate(packet, acknowledgement, relayer) - } - - fn on_acknowledgement_packet_execute( - &mut self, - packet: &Packet, - acknowledgement: &Acknowledgement, - relayer: &Signer, - ) -> (ModuleExtras, Result<(), PacketError>) { - self.middleware - .on_acknowledgement_packet_execute(packet, acknowledgement, relayer) - } - - fn on_timeout_packet_validate( - &self, - packet: &Packet, - relayer: &Signer, - ) -> Result<(), PacketError> { - self.middleware.on_timeout_packet_validate(packet, relayer) - } - - fn on_timeout_packet_execute( - &mut self, - packet: &Packet, - relayer: &Signer, - ) -> (ModuleExtras, Result<(), PacketError>) { - self.middleware.on_timeout_packet_execute(packet, relayer) - } - - fn on_chan_open_init_validate( - &self, - order: Order, - connection_hops: &[ConnectionId], - port_id: &PortId, - channel_id: &ChannelId, - counterparty: &Counterparty, - version: &Version, - ) -> Result { - self.middleware.on_chan_open_init_validate( - order, - connection_hops, - port_id, - channel_id, - counterparty, - version, - ) - } - - fn on_chan_open_init_execute( - &mut self, - order: Order, - connection_hops: &[ConnectionId], - port_id: &PortId, - channel_id: &ChannelId, - counterparty: &Counterparty, - version: &Version, - ) -> Result<(ModuleExtras, Version), ChannelError> { - self.middleware.on_chan_open_init_execute( - order, - connection_hops, - port_id, - channel_id, - counterparty, - version, - ) - } - - fn on_chan_open_try_validate( - &self, - order: Order, - connection_hops: &[ConnectionId], - port_id: &PortId, - channel_id: &ChannelId, - counterparty: &Counterparty, - counterparty_version: &Version, - ) -> Result { - self.middleware.on_chan_open_try_validate( - order, - connection_hops, - port_id, - channel_id, - counterparty, - counterparty_version, - ) - } - - fn on_chan_open_try_execute( - &mut self, - order: Order, - connection_hops: &[ConnectionId], - port_id: &PortId, - channel_id: &ChannelId, - counterparty: &Counterparty, - counterparty_version: &Version, - ) -> Result<(ModuleExtras, Version), ChannelError> { - self.middleware.on_chan_open_try_execute( - order, - connection_hops, - port_id, - channel_id, - counterparty, - counterparty_version, - ) - } - - fn on_chan_open_ack_validate( - &self, - port_id: &PortId, - channel_id: &ChannelId, - counterparty_version: &Version, - ) -> Result<(), ChannelError> { - self.middleware - .on_chan_open_ack_validate(port_id, channel_id, counterparty_version) - } - - fn on_chan_open_ack_execute( - &mut self, - port_id: &PortId, - channel_id: &ChannelId, - counterparty_version: &Version, - ) -> Result { - self.middleware - .on_chan_open_ack_execute(port_id, channel_id, counterparty_version) - } - - fn on_chan_open_confirm_validate( - &self, - port_id: &PortId, - channel_id: &ChannelId, - ) -> Result<(), ChannelError> { - self.middleware - .on_chan_open_confirm_validate(port_id, channel_id) - } - - fn on_chan_open_confirm_execute( - &mut self, - port_id: &PortId, - channel_id: &ChannelId, - ) -> Result { - self.middleware - .on_chan_open_confirm_execute(port_id, channel_id) - } - - fn on_chan_close_init_validate( - &self, - port_id: &PortId, - channel_id: &ChannelId, - ) -> Result<(), ChannelError> { - self.middleware - .on_chan_close_init_validate(port_id, channel_id) - } - - fn on_chan_close_init_execute( - &mut self, - port_id: &PortId, - channel_id: &ChannelId, - ) -> Result { - self.middleware - .on_chan_close_init_execute(port_id, channel_id) - } - - fn on_chan_close_confirm_validate( - &self, - port_id: &PortId, - channel_id: &ChannelId, - ) -> Result<(), ChannelError> { - self.middleware - .on_chan_close_confirm_validate(port_id, channel_id) - } - - fn on_chan_close_confirm_execute( - &mut self, - port_id: &PortId, - channel_id: &ChannelId, - ) -> Result { - self.middleware - .on_chan_close_confirm_execute(port_id, channel_id) - } } impl PfmContext for Store {