diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 1976c07649..48b95da242 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -81,7 +81,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 aa2baa2153..56700c72de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -824,6 +824,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" @@ -1350,6 +1363,7 @@ dependencies = [ "bytes", "chrono", "dyn-clonable", + "env_logger", "ibc-proto", "ics23", "modelator", @@ -1365,8 +1379,10 @@ dependencies = [ "tendermint-proto", "tendermint-rpc", "tendermint-testgen", + "test-env-log", "thiserror", "tracing", + "tracing-subscriber 0.2.18", ] [[package]] @@ -1396,6 +1412,7 @@ dependencies = [ "dirs-next", "dyn-clonable", "dyn-clone", + "env_logger", "futures", "hdpath", "hex", @@ -1422,12 +1439,14 @@ dependencies = [ "tendermint-proto", "tendermint-rpc", "tendermint-testgen", + "test-env-log", "thiserror", "tiny-bip39", "tokio", "toml", "tonic", "tracing", + "tracing-subscriber 0.2.18", ] [[package]] @@ -3157,6 +3176,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/relayer/Cargo.toml b/relayer/Cargo.toml index c8369c04c8..c74987da7d 100644 --- a/relayer/Cargo.toml +++ b/relayer/Cargo.toml @@ -71,6 +71,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 b756eaab06..988f98ca3c 100644 --- a/relayer/src/config.rs +++ b/relayer/src/config.rs @@ -166,6 +166,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 c30205c034..77a5126ceb 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() {