diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 5ad00d20b9..1500d176fa 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -67,7 +67,7 @@ jobs: - uses: actions-rs/cargo@v1 with: command: test - args: --all-features --no-fail-fast + args: --all-features --no-fail-fast -- --nocapture # test-coverage: # runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index e76c684077..f337532a68 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,5 @@ data # Ignore Python artifacts .mypy_cache/ __pycache__/ + +.modelator diff --git a/Cargo.lock b/Cargo.lock index e3a030b14a..0ed63266ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -697,6 +697,19 @@ dependencies = [ "zeroize", ] +[[package]] +name = "env_logger" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17392a012ea30ef05a610aa97dfb49496e71c9f676b27879922ea5bdf60d9d3f" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + [[package]] name = "ff" version = "0.9.0" @@ -1196,6 +1209,7 @@ dependencies = [ "bytes", "chrono", "dyn-clonable", + "env_logger", "ibc-proto", "ics23", "modelator", @@ -1211,8 +1225,10 @@ dependencies = [ "tendermint-proto", "tendermint-rpc", "tendermint-testgen", + "test-env-log", "thiserror", "tracing", + "tracing-subscriber 0.2.18", ] [[package]] @@ -1242,6 +1258,7 @@ dependencies = [ "dirs-next", "dyn-clonable", "dyn-clone", + "env_logger", "futures", "hdpath", "hex", @@ -1267,12 +1284,14 @@ dependencies = [ "tendermint-proto", "tendermint-rpc", "tendermint-testgen", + "test-env-log", "thiserror", "tiny-bip39", "tokio", "toml", "tonic", "tracing", + "tracing-subscriber 0.2.18", ] [[package]] @@ -2645,6 +2664,17 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "test-env-log" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3e4b132a630cc8a0d06cfcb400da67adef3d0087a94b3332d4692908f0c2544" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "textwrap" version = "0.12.1" diff --git a/modules/Cargo.toml b/modules/Cargo.toml index 11ba49e762..6de3d27718 100644 --- a/modules/Cargo.toml +++ b/modules/Cargo.toml @@ -48,6 +48,9 @@ version = "=0.19.0" optional = true [dev-dependencies] +env_logger = "0.8.3" +tracing-subscriber = "0.2.18" +test-env-log = { version = "0.2.7", features = ["trace"] } modelator = { git = "https://github.com/informalsystems/modelator", rev = "99f656fa8b3cf46a2aa0b6513e4e140d1778c4bd" } tendermint-rpc = { version = "=0.19.0", features = ["http-client", "websocket-client"] } tendermint-testgen = { version = "=0.19.0" } # Needed for generating (synthetic) light blocks. diff --git a/modules/src/ics02_client/client_state.rs b/modules/src/ics02_client/client_state.rs index c14135a194..4e5f54a3af 100644 --- a/modules/src/ics02_client/client_state.rs +++ b/modules/src/ics02_client/client_state.rs @@ -209,6 +209,7 @@ impl From for IdentifiedClientState { #[cfg(test)] mod tests { use std::convert::TryFrom; + use test_env_log::test; use prost_types::Any; diff --git a/modules/src/ics02_client/client_type.rs b/modules/src/ics02_client/client_type.rs index b6119305f3..d5caaf4747 100644 --- a/modules/src/ics02_client/client_type.rs +++ b/modules/src/ics02_client/client_type.rs @@ -49,6 +49,7 @@ impl std::str::FromStr for ClientType { #[cfg(test)] mod tests { use std::str::FromStr; + use test_env_log::test; use super::ClientType; diff --git a/modules/src/ics02_client/handler/create_client.rs b/modules/src/ics02_client/handler/create_client.rs index c96531c4d7..7d6f75fd74 100644 --- a/modules/src/ics02_client/handler/create_client.rs +++ b/modules/src/ics02_client/handler/create_client.rs @@ -59,6 +59,7 @@ pub fn process( mod tests { use std::convert::TryInto; use std::time::Duration; + use test_env_log::test; use tendermint::trust_threshold::TrustThresholdFraction as TrustThreshold; diff --git a/modules/src/ics02_client/handler/update_client.rs b/modules/src/ics02_client/handler/update_client.rs index 49ae367e26..25ef38f74e 100644 --- a/modules/src/ics02_client/handler/update_client.rs +++ b/modules/src/ics02_client/handler/update_client.rs @@ -74,6 +74,7 @@ pub fn process( #[cfg(test)] mod tests { use std::str::FromStr; + use test_env_log::test; use crate::events::IbcEvent; use crate::handler::HandlerOutput; diff --git a/modules/src/ics02_client/msgs/create_client.rs b/modules/src/ics02_client/msgs/create_client.rs index 296055b2df..5309239167 100644 --- a/modules/src/ics02_client/msgs/create_client.rs +++ b/modules/src/ics02_client/msgs/create_client.rs @@ -102,6 +102,7 @@ impl From for RawMsgCreateClient { #[cfg(test)] mod tests { use std::convert::{TryFrom, TryInto}; + use test_env_log::test; use ibc_proto::ibc::core::client::v1::MsgCreateClient; diff --git a/modules/src/ics02_client/msgs/update_client.rs b/modules/src/ics02_client/msgs/update_client.rs index 85f8b6ed7f..1214f66db7 100644 --- a/modules/src/ics02_client/msgs/update_client.rs +++ b/modules/src/ics02_client/msgs/update_client.rs @@ -78,6 +78,7 @@ impl From for RawMsgUpdateClient { #[cfg(test)] mod tests { use std::convert::TryFrom; + use test_env_log::test; use ibc_proto::ibc::core::client::v1::MsgUpdateClient; diff --git a/modules/src/ics03_connection/handler/conn_open_ack.rs b/modules/src/ics03_connection/handler/conn_open_ack.rs index 17cb830e49..a7cb42e576 100644 --- a/modules/src/ics03_connection/handler/conn_open_ack.rs +++ b/modules/src/ics03_connection/handler/conn_open_ack.rs @@ -104,6 +104,7 @@ pub(crate) fn process( mod tests { use std::convert::TryFrom; use std::str::FromStr; + use test_env_log::test; use crate::events::IbcEvent; use crate::ics03_connection::connection::{ConnectionEnd, Counterparty, State}; diff --git a/modules/src/ics03_connection/handler/conn_open_confirm.rs b/modules/src/ics03_connection/handler/conn_open_confirm.rs index 67fbc3fa92..8813f855b9 100644 --- a/modules/src/ics03_connection/handler/conn_open_confirm.rs +++ b/modules/src/ics03_connection/handler/conn_open_confirm.rs @@ -78,6 +78,7 @@ pub(crate) fn process( mod tests { use std::convert::TryFrom; use std::str::FromStr; + use test_env_log::test; use crate::events::IbcEvent; use crate::ics03_connection::connection::{ConnectionEnd, Counterparty, State}; diff --git a/modules/src/ics03_connection/handler/conn_open_init.rs b/modules/src/ics03_connection/handler/conn_open_init.rs index 7397be4e2a..2553c54886 100644 --- a/modules/src/ics03_connection/handler/conn_open_init.rs +++ b/modules/src/ics03_connection/handler/conn_open_init.rs @@ -56,6 +56,7 @@ pub(crate) fn process( #[cfg(test)] mod tests { use std::convert::TryFrom; + use test_env_log::test; use crate::events::IbcEvent; use crate::ics03_connection::connection::State; diff --git a/modules/src/ics03_connection/handler/conn_open_try.rs b/modules/src/ics03_connection/handler/conn_open_try.rs index b330d6f8fc..ace6b2e37f 100644 --- a/modules/src/ics03_connection/handler/conn_open_try.rs +++ b/modules/src/ics03_connection/handler/conn_open_try.rs @@ -122,6 +122,7 @@ pub(crate) fn process( #[cfg(test)] mod tests { use std::convert::TryFrom; + use test_env_log::test; use crate::events::IbcEvent; use crate::ics03_connection::connection::State; diff --git a/modules/src/ics03_connection/msgs/conn_open_ack.rs b/modules/src/ics03_connection/msgs/conn_open_ack.rs index 375ca46e3f..41868d9916 100644 --- a/modules/src/ics03_connection/msgs/conn_open_ack.rs +++ b/modules/src/ics03_connection/msgs/conn_open_ack.rs @@ -198,6 +198,7 @@ pub mod test_util { #[cfg(test)] mod tests { use std::convert::TryFrom; + use test_env_log::test; use ibc_proto::ibc::core::client::v1::Height; use ibc_proto::ibc::core::connection::v1::MsgConnectionOpenAck as RawMsgConnectionOpenAck; diff --git a/modules/src/ics03_connection/msgs/conn_open_confirm.rs b/modules/src/ics03_connection/msgs/conn_open_confirm.rs index cfe48e4dec..0e8bfd6a04 100644 --- a/modules/src/ics03_connection/msgs/conn_open_confirm.rs +++ b/modules/src/ics03_connection/msgs/conn_open_confirm.rs @@ -104,6 +104,7 @@ pub mod test_util { #[cfg(test)] mod tests { use std::convert::TryFrom; + use test_env_log::test; use ibc_proto::ibc::core::client::v1::Height; use ibc_proto::ibc::core::connection::v1::MsgConnectionOpenConfirm as RawMsgConnectionOpenConfirm; diff --git a/modules/src/ics03_connection/msgs/conn_open_init.rs b/modules/src/ics03_connection/msgs/conn_open_init.rs index acf93b9ac4..ae8eb8d515 100644 --- a/modules/src/ics03_connection/msgs/conn_open_init.rs +++ b/modules/src/ics03_connection/msgs/conn_open_init.rs @@ -122,6 +122,7 @@ pub mod test_util { #[cfg(test)] mod tests { use std::convert::TryFrom; + use test_env_log::test; use ibc_proto::ibc::core::connection::v1::Counterparty as RawCounterparty; use ibc_proto::ibc::core::connection::v1::MsgConnectionOpenInit as RawMsgConnectionOpenInit; diff --git a/modules/src/ics03_connection/msgs/conn_open_try.rs b/modules/src/ics03_connection/msgs/conn_open_try.rs index 3c506587bb..7bc9ee6b82 100644 --- a/modules/src/ics03_connection/msgs/conn_open_try.rs +++ b/modules/src/ics03_connection/msgs/conn_open_try.rs @@ -268,6 +268,7 @@ pub mod test_util { #[cfg(test)] mod tests { use std::convert::TryFrom; + use test_env_log::test; use ibc_proto::ibc::core::client::v1::Height; use ibc_proto::ibc::core::connection::v1::Counterparty as RawCounterparty; diff --git a/modules/src/ics03_connection/version.rs b/modules/src/ics03_connection/version.rs index d008d1808e..d24e8d2f32 100644 --- a/modules/src/ics03_connection/version.rs +++ b/modules/src/ics03_connection/version.rs @@ -95,6 +95,7 @@ pub fn pick_version( #[cfg(test)] mod tests { use std::convert::{TryFrom, TryInto}; + use test_env_log::test; use ibc_proto::ibc::core::connection::v1::Version as RawVersion; diff --git a/modules/src/ics04_channel/channel.rs b/modules/src/ics04_channel/channel.rs index c59cba5c6f..b2ff4b3535 100644 --- a/modules/src/ics04_channel/channel.rs +++ b/modules/src/ics04_channel/channel.rs @@ -468,6 +468,7 @@ pub mod test_util { mod tests { use std::convert::TryFrom; use std::str::FromStr; + use test_env_log::test; use ibc_proto::ibc::core::channel::v1::Channel as RawChannel; diff --git a/modules/src/ics04_channel/handler/acknowledgement.rs b/modules/src/ics04_channel/handler/acknowledgement.rs index 93b5e1a323..e5acf11bad 100644 --- a/modules/src/ics04_channel/handler/acknowledgement.rs +++ b/modules/src/ics04_channel/handler/acknowledgement.rs @@ -143,6 +143,7 @@ mod tests { use crate::ics24_host::identifier::{ChannelId, ClientId, ConnectionId, PortId}; use crate::mock::context::MockContext; use crate::timestamp::ZERO_DURATION; + use test_env_log::test; use std::convert::TryFrom; diff --git a/modules/src/ics04_channel/handler/chan_open_ack.rs b/modules/src/ics04_channel/handler/chan_open_ack.rs index ebdf0529ed..bef8204731 100644 --- a/modules/src/ics04_channel/handler/chan_open_ack.rs +++ b/modules/src/ics04_channel/handler/chan_open_ack.rs @@ -103,6 +103,7 @@ pub(crate) fn process( mod tests { use std::convert::TryFrom; use std::str::FromStr; + use test_env_log::test; use crate::events::IbcEvent; use crate::ics03_connection::connection::ConnectionEnd; diff --git a/modules/src/ics04_channel/handler/chan_open_confirm.rs b/modules/src/ics04_channel/handler/chan_open_confirm.rs index a89a307b15..4e47ff35ae 100644 --- a/modules/src/ics04_channel/handler/chan_open_confirm.rs +++ b/modules/src/ics04_channel/handler/chan_open_confirm.rs @@ -99,6 +99,7 @@ pub(crate) fn process( #[cfg(test)] mod tests { use std::convert::TryFrom; + use test_env_log::test; use crate::events::IbcEvent; use crate::ics02_client::client_type::ClientType; diff --git a/modules/src/ics04_channel/handler/chan_open_init.rs b/modules/src/ics04_channel/handler/chan_open_init.rs index 3d2e815a1e..5224d67ad6 100644 --- a/modules/src/ics04_channel/handler/chan_open_init.rs +++ b/modules/src/ics04_channel/handler/chan_open_init.rs @@ -86,6 +86,7 @@ pub(crate) fn process( #[cfg(test)] mod tests { use std::convert::TryFrom; + use test_env_log::test; use crate::events::IbcEvent; use crate::ics03_connection::connection::ConnectionEnd; diff --git a/modules/src/ics04_channel/handler/chan_open_try.rs b/modules/src/ics04_channel/handler/chan_open_try.rs index 2f899e2b9f..33483fe6bb 100644 --- a/modules/src/ics04_channel/handler/chan_open_try.rs +++ b/modules/src/ics04_channel/handler/chan_open_try.rs @@ -155,6 +155,7 @@ pub(crate) fn process( #[cfg(test)] mod tests { use std::convert::TryFrom; + use test_env_log::test; use crate::events::IbcEvent; use crate::ics02_client::client_type::ClientType; diff --git a/modules/src/ics04_channel/handler/recv_packet.rs b/modules/src/ics04_channel/handler/recv_packet.rs index c3b5ab14c4..4ebb06baee 100644 --- a/modules/src/ics04_channel/handler/recv_packet.rs +++ b/modules/src/ics04_channel/handler/recv_packet.rs @@ -136,6 +136,7 @@ pub fn process(ctx: &dyn ChannelReader, msg: MsgRecvPacket) -> HandlerResult HandlerResult for RawClientState { #[cfg(test)] mod tests { use std::time::Duration; + use test_env_log::test; use tendermint::trust_threshold::TrustThresholdFraction as TrustThreshold; use tendermint_rpc::endpoint::abci_query::AbciQuery; diff --git a/modules/src/ics07_tendermint/consensus_state.rs b/modules/src/ics07_tendermint/consensus_state.rs index 7e7a5569a6..b7510dd14e 100644 --- a/modules/src/ics07_tendermint/consensus_state.rs +++ b/modules/src/ics07_tendermint/consensus_state.rs @@ -106,6 +106,7 @@ impl From
for ConsensusState { #[cfg(test)] mod tests { use tendermint_rpc::endpoint::abci_query::AbciQuery; + use test_env_log::test; use crate::test::test_serialization_roundtrip; diff --git a/modules/src/ics18_relayer/utils.rs b/modules/src/ics18_relayer/utils.rs index 50358ec6d1..a5ca5fbf67 100644 --- a/modules/src/ics18_relayer/utils.rs +++ b/modules/src/ics18_relayer/utils.rs @@ -60,6 +60,7 @@ mod tests { use crate::mock::context::MockContext; use crate::mock::host::HostType; use crate::Height; + use test_env_log::test; #[test] /// Serves to test both ICS 26 `dispatch` & `build_client_update_datagram` functions. diff --git a/modules/src/ics24_host/validate.rs b/modules/src/ics24_host/validate.rs index 98b415f382..2650f732c9 100644 --- a/modules/src/ics24_host/validate.rs +++ b/modules/src/ics24_host/validate.rs @@ -91,6 +91,7 @@ mod tests { validate_channel_identifier, validate_client_identifier, validate_connection_identifier, validate_identifier, validate_port_identifier, }; + use test_env_log::test; #[test] fn parse_invalid_port_id_min() { diff --git a/modules/src/ics26_routing/handler.rs b/modules/src/ics26_routing/handler.rs index 44b5fcfacc..58cf63e589 100644 --- a/modules/src/ics26_routing/handler.rs +++ b/modules/src/ics26_routing/handler.rs @@ -240,6 +240,7 @@ where #[cfg(test)] mod tests { use std::convert::TryFrom; + use test_env_log::test; use crate::application::ics20_fungible_token_transfer::msgs::transfer::test_util::get_dummy_msg_transfer; use crate::events::IbcEvent; diff --git a/modules/src/mock/context.rs b/modules/src/mock/context.rs index 7ff4cd13dc..5837fb832a 100644 --- a/modules/src/mock/context.rs +++ b/modules/src/mock/context.rs @@ -817,6 +817,7 @@ mod tests { use crate::mock::context::MockContext; use crate::mock::host::HostType; use crate::Height; + use test_env_log::test; #[test] fn test_history_manipulation() { diff --git a/modules/src/timestamp.rs b/modules/src/timestamp.rs index a5a8a87ecc..20180a64b5 100644 --- a/modules/src/timestamp.rs +++ b/modules/src/timestamp.rs @@ -192,6 +192,7 @@ mod tests { use std::convert::TryInto; use std::thread::sleep; use std::time::Duration; + use test_env_log::test; use super::{Expiry, Timestamp, ZERO_DURATION}; diff --git a/relayer/Cargo.toml b/relayer/Cargo.toml index 778ebeb0d6..6fa3682883 100644 --- a/relayer/Cargo.toml +++ b/relayer/Cargo.toml @@ -69,6 +69,9 @@ version = "=0.19.0" [dev-dependencies] serial_test = "0.5.0" +env_logger = "0.8.3" +tracing-subscriber = "0.2.18" +test-env-log = { version = "0.2.7", features = ["trace"] } ibc = { version = "0.3.2", path = "../modules", features = ["mocks"] } # Needed for generating (synthetic) light blocks. diff --git a/relayer/src/chain/mock.rs b/relayer/src/chain/mock.rs index b840576793..3a8fcf661a 100644 --- a/relayer/src/chain/mock.rs +++ b/relayer/src/chain/mock.rs @@ -42,7 +42,7 @@ use ibc_proto::ibc::core::connection::v1::{ use crate::chain::Chain; use crate::config::ChainConfig; use crate::error::{Error, Kind}; -use crate::event::monitor::EventReceiver; +use crate::event::monitor::{EventReceiver, EventSender}; use crate::keyring::{KeyEntry, KeyRing}; use crate::light_client::{mock::LightClient as MockLightClient, LightClient}; @@ -53,6 +53,10 @@ use crate::light_client::{mock::LightClient as MockLightClient, LightClient}; pub struct MockChain { config: ChainConfig, context: MockContext, + + // keep a reference to event sender to prevent it from being dropped + _event_sender: EventSender, + event_receiver: EventReceiver, } impl Chain for MockChain { @@ -62,6 +66,7 @@ impl Chain for MockChain { type ClientState = TendermintClientState; fn bootstrap(config: ChainConfig, _rt: Arc) -> Result { + let (sender, receiver) = channel::unbounded(); Ok(MockChain { config: config.clone(), context: MockContext::new( @@ -70,6 +75,8 @@ impl Chain for MockChain { 50, Height::new(config.id.version(), 20), ), + _event_sender: sender, + event_receiver: receiver, }) } @@ -81,8 +88,7 @@ impl Chain for MockChain { &self, _rt: Arc, ) -> Result<(EventReceiver, Option>), Error> { - let (_, rx) = channel::unbounded(); - Ok((rx, None)) + Ok((self.event_receiver.clone(), None)) } fn id(&self) -> &ChainId { diff --git a/relayer/src/chain/runtime.rs b/relayer/src/chain/runtime.rs index 51746cae6e..33a5bcc05f 100644 --- a/relayer/src/chain/runtime.rs +++ b/relayer/src/chain/runtime.rs @@ -170,7 +170,10 @@ impl ChainRuntime { .broadcast(Arc::new(event_batch)) .map_err(Kind::channel)?; }, - Err(e) => error!("received error via event bus: {}", e), + Err(e) => { + error!("received error via event bus: {}", e); + return Err(Kind::Channel.into()); + }, } }, recv(self.request_receiver) -> event => { diff --git a/relayer/src/config.rs b/relayer/src/config.rs index b269ae252b..ed40e46a52 100644 --- a/relayer/src/config.rs +++ b/relayer/src/config.rs @@ -179,6 +179,7 @@ pub(crate) fn store_writer(config: &Config, mut writer: impl Write) -> Result<() #[cfg(test)] mod tests { use super::{parse, store_writer}; + use test_env_log::test; #[test] fn parse_valid_config() { diff --git a/relayer/src/event/bus.rs b/relayer/src/event/bus.rs index 38ccda485d..1adc13e2dd 100644 --- a/relayer/src/event/bus.rs +++ b/relayer/src/event/bus.rs @@ -44,6 +44,7 @@ mod tests { use serial_test::serial; use std::sync::atomic::{AtomicUsize, Ordering}; + use test_env_log::test; static COUNTER: AtomicUsize = AtomicUsize::new(0); diff --git a/relayer/src/event/monitor.rs b/relayer/src/event/monitor.rs index 7b213c0f65..8d8d591b50 100644 --- a/relayer/src/event/monitor.rs +++ b/relayer/src/event/monitor.rs @@ -90,6 +90,7 @@ type SubscriptionStream = dyn Stream + Send + Sync + pub type Result = std::result::Result; +pub type EventSender = channel::Sender>; pub type EventReceiver = channel::Receiver>; /// Connect to a Tendermint node, subscribe to a set of queries, diff --git a/relayer/src/foreign_client.rs b/relayer/src/foreign_client.rs index dad8993dd5..baf256bf83 100644 --- a/relayer/src/foreign_client.rs +++ b/relayer/src/foreign_client.rs @@ -935,6 +935,7 @@ mod test { use std::str::FromStr; use std::sync::Arc; + use test_env_log::test; use tokio::runtime::Runtime as TokioRuntime; use ibc::events::IbcEvent; diff --git a/relayer/src/util/retry.rs b/relayer/src/util/retry.rs index 77f896b4c8..f63e09e8fd 100644 --- a/relayer/src/util/retry.rs +++ b/relayer/src/util/retry.rs @@ -76,6 +76,7 @@ pub fn clamp_total( #[cfg(test)] mod tests { use super::*; + use test_env_log::test; const CONST_STRATEGY: ConstantGrowth = ConstantGrowth::new(Duration::from_secs(1), Duration::from_millis(500)); diff --git a/relayer/src/util/stream.rs b/relayer/src/util/stream.rs index a567066349..20aeba702b 100644 --- a/relayer/src/util/stream.rs +++ b/relayer/src/util/stream.rs @@ -50,6 +50,7 @@ where mod tests { use super::group_while; use futures::{executor::block_on, stream, StreamExt}; + use test_env_log::test; #[test] fn group_while_non_empty() {