Skip to content

Commit

Permalink
Test clear_packet behavior (#1881)
Browse files Browse the repository at this point in the history
* 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 <adi@informal.systems>
  • Loading branch information
soareschen and adizere authored Feb 16, 2022
1 parent 1f5e17d commit 202ae4e
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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))
`clear_on_start = false` ([#1872](https://github.com/informalsystems/ibc-rs/issues/1872))
2 changes: 2 additions & 0 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:
- relayer-cli/**
- relayer-rest/**
- telemetry/**
- tools/**
push:
branches: master
paths:
Expand All @@ -27,6 +28,7 @@ on:
- relayer-cli/**
- relayer-rest/**
- telemetry/**
- tools/**

env:
CARGO_INCREMENTAL: 0
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:
- relayer-cli/**
- relayer-rest/**
- telemetry/**
- tools/**
push:
branches: master
paths:
Expand All @@ -27,6 +28,7 @@ on:
- relayer-cli/**
- relayer-rest/**
- telemetry/**
- tools/**

env:
CARGO_INCREMENTAL: 0
Expand Down
3 changes: 3 additions & 0 deletions tools/integration-test/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
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;
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};
Expand Down
119 changes: 119 additions & 0 deletions tools/integration-test/src/tests/clear_packet.rs
Original file line number Diff line number Diff line change
@@ -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<impl ChainHandle>,
) -> Result<Option<SupervisorHandle>, Error> {
Ok(None)
}
}

impl BinaryChannelTest for ClearPacketTest {
fn run<ChainA: ChainHandle, ChainB: ChainHandle>(
&self,
_config: &TestConfig,
chains: ConnectedChains<ChainA, ChainB>,
channel: ConnectedChannel<ChainA, ChainB>,
) -> 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(())
}
}
1 change: 1 addition & 0 deletions tools/integration-test/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 202ae4e

Please sign in to comment.