From 202ae4eb7c0c61363fb0bb9e6a09e6286f23831d Mon Sep 17 00:00:00 2001 From: Soares Chen Date: Wed, 16 Feb 2022 18:45:40 +0800 Subject: [PATCH] Test `clear_packet` behavior (#1881) * Cleaned up clear_packets logic from RelayPath. * changelog * Test on ordered channel relaying behavior * Test now shows correct behavior * Change test names to target clear_packet test * Add tools/ directory to CI trigger * Add tools/ directory to integration-test CI trigger Co-authored-by: Adi Seredinschi --- .../bug-fixes/relayer/1872-clear-packets.md | 2 +- .github/workflows/integration.yaml | 2 + .github/workflows/rust.yml | 2 + tools/integration-test/src/prelude.rs | 3 + .../src/tests/clear_packet.rs | 119 ++++++++++++++++++ tools/integration-test/src/tests/mod.rs | 1 + 6 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 tools/integration-test/src/tests/clear_packet.rs diff --git a/.changelog/unreleased/bug-fixes/relayer/1872-clear-packets.md b/.changelog/unreleased/bug-fixes/relayer/1872-clear-packets.md index 24f15ed941..4a72814e75 100644 --- a/.changelog/unreleased/bug-fixes/relayer/1872-clear-packets.md +++ b/.changelog/unreleased/bug-fixes/relayer/1872-clear-packets.md @@ -1,2 +1,2 @@ - Fixed bug where Hermes cleared packets at startup, despite - `clear_on_start = false` ([#1872](https://github.com/informalsystems/ibc-rs/issues/1872)) \ No newline at end of file + `clear_on_start = false` ([#1872](https://github.com/informalsystems/ibc-rs/issues/1872)) diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index 3497f7e9b0..349bf2f091 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -13,6 +13,7 @@ on: - relayer-cli/** - relayer-rest/** - telemetry/** + - tools/** push: branches: master paths: @@ -27,6 +28,7 @@ on: - relayer-cli/** - relayer-rest/** - telemetry/** + - tools/** env: CARGO_INCREMENTAL: 0 diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 6c60c3fa27..aa4d85f717 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -13,6 +13,7 @@ on: - relayer-cli/** - relayer-rest/** - telemetry/** + - tools/** push: branches: master paths: @@ -27,6 +28,7 @@ on: - relayer-cli/** - relayer-rest/** - telemetry/** + - tools/** env: CARGO_INCREMENTAL: 0 diff --git a/tools/integration-test/src/prelude.rs b/tools/integration-test/src/prelude.rs index 7012f295c5..f206db7c81 100644 --- a/tools/integration-test/src/prelude.rs +++ b/tools/integration-test/src/prelude.rs @@ -2,6 +2,7 @@ Re-export of common constructs that are used by test cases. */ +pub use core::time::Duration; pub use eyre::eyre; pub use ibc::core::ics24_host::identifier::{ChainId, ChannelId, ClientId, ConnectionId, PortId}; pub use ibc_relayer::chain::handle::ChainHandle; @@ -9,6 +10,8 @@ pub use ibc_relayer::config::Config; pub use ibc_relayer::config::SharedConfig; pub use ibc_relayer::foreign_client::ForeignClient; pub use ibc_relayer::registry::SharedRegistry; +pub use ibc_relayer::supervisor::SupervisorHandle; +pub use std::thread::sleep; pub use tracing::{debug, error, info, warn}; pub use crate::chain::driver::{tagged::TaggedChainDriverExt, ChainDriver}; diff --git a/tools/integration-test/src/tests/clear_packet.rs b/tools/integration-test/src/tests/clear_packet.rs new file mode 100644 index 0000000000..ec9d0331d2 --- /dev/null +++ b/tools/integration-test/src/tests/clear_packet.rs @@ -0,0 +1,119 @@ +use ibc_relayer::supervisor::{spawn_supervisor, SupervisorHandle, SupervisorOptions}; + +use crate::ibc::denom::derive_ibc_denom; +use crate::prelude::*; +use crate::util::random::random_u64_range; + +#[test] +fn test_clear_packet() -> Result<(), Error> { + run_binary_channel_test(&ClearPacketTest) +} +pub struct ClearPacketTest; + +impl TestOverrides for ClearPacketTest { + fn modify_relayer_config(&self, config: &mut Config) { + // Disabling clear_on_start should make the relayer not + // relay any packet it missed before starting. + config.mode.packets.clear_on_start = false; + config.mode.packets.clear_interval = 0; + } + + // Do not start supervisor at the beginning of test + fn spawn_supervisor( + &self, + _config: &SharedConfig, + _registry: &SharedRegistry, + ) -> Result, Error> { + Ok(None) + } +} + +impl BinaryChannelTest for ClearPacketTest { + fn run( + &self, + _config: &TestConfig, + chains: ConnectedChains, + channel: ConnectedChannel, + ) -> Result<(), Error> { + let denom_a = chains.node_a.denom(); + + let wallet_a = chains.node_a.wallets().user1().cloned(); + let wallet_b = chains.node_b.wallets().user1().cloned(); + + let balance_a = chains + .node_a + .chain_driver() + .query_balance(&wallet_a.address(), &denom_a)?; + + let amount1 = random_u64_range(1000, 5000); + + info!( + "Performing IBC transfer with amount {}, which should *not* be relayed", + amount1 + ); + + chains.node_a.chain_driver().transfer_token( + &channel.port_a.as_ref(), + &channel.channel_id_a.as_ref(), + &wallet_a.address(), + &wallet_b.address(), + amount1, + &denom_a, + )?; + + sleep(Duration::from_secs(1)); + + // Spawn the supervisor only after the first IBC trasnfer + let _supervisor = spawn_supervisor( + chains.config.clone(), + chains.registry.clone(), + None, + SupervisorOptions { + health_check: false, + force_full_scan: false, + }, + )?; + + sleep(Duration::from_secs(1)); + + let amount2 = random_u64_range(1000, 5000); + + info!( + "Performing IBC transfer with amount {}, which should be relayed", + amount2 + ); + + chains.node_a.chain_driver().transfer_token( + &channel.port_a.as_ref(), + &channel.channel_id_a.as_ref(), + &wallet_a.address(), + &wallet_b.address(), + amount2, + &denom_a, + )?; + + sleep(Duration::from_secs(1)); + + let denom_b = derive_ibc_denom( + &channel.port_b.as_ref(), + &channel.channel_id_b.as_ref(), + &denom_a, + )?; + + // Wallet on chain A should have both amount deducted. + chains.node_a.chain_driver().assert_eventual_wallet_amount( + &wallet_a.as_ref(), + balance_a - amount1 - amount2, + &denom_a, + )?; + + // Wallet on chain B should only receive the second IBC transfer + chains.node_b.chain_driver().assert_eventual_wallet_amount( + &wallet_b.as_ref(), + amount2, + &denom_b.as_ref(), + )?; + + Ok(()) + } +} diff --git a/tools/integration-test/src/tests/mod.rs b/tools/integration-test/src/tests/mod.rs index 1828ddd79e..bcd2627ef9 100644 --- a/tools/integration-test/src/tests/mod.rs +++ b/tools/integration-test/src/tests/mod.rs @@ -5,6 +5,7 @@ will pick up the definition by default. */ +pub mod clear_packet; pub mod client_expiration; pub mod memo; pub mod supervisor;