From a66136ed39adf85ce10e5fc8b41fbe9d33034aed Mon Sep 17 00:00:00 2001 From: Tiago Carvalho Date: Mon, 17 Jun 2024 15:28:14 +0100 Subject: [PATCH] Wait for block height 2 in IBC tests --- crates/tests/src/e2e/ibc_tests.rs | 40 ++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/crates/tests/src/e2e/ibc_tests.rs b/crates/tests/src/e2e/ibc_tests.rs index c1781b62955..44a763c2e14 100644 --- a/crates/tests/src/e2e/ibc_tests.rs +++ b/crates/tests/src/e2e/ibc_tests.rs @@ -117,9 +117,13 @@ fn run_ledger_ibc() -> Result<()> { setup::set_validators(1, genesis, base_dir, |_| 0) }; let (ledger_a, ledger_b, test_a, test_b) = run_two_nets(update_genesis)?; + let _bg_ledger_a = ledger_a.background(); let _bg_ledger_b = ledger_b.background(); + wait_height(&test_a, 2, std::time::Duration::from_secs(40))?; + wait_height(&test_b, 2, std::time::Duration::from_secs(40))?; + let (client_id_a, client_id_b) = create_client(&test_a, &test_b)?; let (conn_id_a, conn_id_b) = @@ -208,9 +212,13 @@ fn run_ledger_ibc_with_hermes() -> Result<()> { setup::set_validators(1, genesis, base_dir, |_| 0) }; let (ledger_a, ledger_b, test_a, test_b) = run_two_nets(update_genesis)?; + let _bg_ledger_a = ledger_a.background(); let _bg_ledger_b = ledger_b.background(); + wait_height(&test_a, 2, std::time::Duration::from_secs(40))?; + wait_height(&test_b, 2, std::time::Duration::from_secs(40))?; + setup_hermes(&test_a, &test_b)?; let port_id_a = "transfer".parse().unwrap(); let port_id_b = "transfer".parse().unwrap(); @@ -370,10 +378,13 @@ fn ibc_namada_gaia() -> Result<()> { setup::set_validators(1, genesis, base_dir, |_| 0) }; let (ledger, mut ledger_b, test, _test_b) = run_two_nets(update_genesis)?; - let _bg_ledger = ledger.background(); // chain B isn't used ledger_b.interrupt()?; + let _bg_ledger = ledger.background(); + + wait_height(&test, 2, std::time::Duration::from_secs(40))?; + // gaia let test_gaia = setup_gaia()?; let gaia = run_gaia(&test_gaia)?; @@ -538,9 +549,13 @@ fn pgf_over_ibc_with_hermes() -> Result<()> { setup::set_validators(1, genesis, base_dir, |_| 0) }; let (ledger_a, ledger_b, test_a, test_b) = run_two_nets(update_genesis)?; + let _bg_ledger_a = ledger_a.background(); let _bg_ledger_b = ledger_b.background(); + wait_height(&test_a, 2, std::time::Duration::from_secs(40))?; + wait_height(&test_b, 2, std::time::Duration::from_secs(40))?; + setup_hermes(&test_a, &test_b)?; let port_id_a = "transfer".parse().unwrap(); let port_id_b = "transfer".parse().unwrap(); @@ -615,9 +630,13 @@ fn proposal_ibc_token_inflation() -> Result<()> { setup::set_validators(1, genesis, base_dir, |_| 0) }; let (ledger_a, ledger_b, test_a, test_b) = run_two_nets(update_genesis)?; + let _bg_ledger_a = ledger_a.background(); let _bg_ledger_b = ledger_b.background(); + wait_height(&test_a, 2, std::time::Duration::from_secs(40))?; + wait_height(&test_b, 2, std::time::Duration::from_secs(40))?; + // Proposal on the destination (Chain B) // Delegate some token delegate_token(&test_b)?; @@ -695,9 +714,13 @@ fn ibc_rate_limit() -> Result<()> { setup::set_validators(1, genesis, base_dir, |_| 0) }; let (ledger_a, ledger_b, test_a, test_b) = run_two_nets(update_genesis)?; + let _bg_ledger_a = ledger_a.background(); let _bg_ledger_b = ledger_b.background(); + wait_height(&test_a, 2, std::time::Duration::from_secs(40))?; + wait_height(&test_b, 2, std::time::Duration::from_secs(40))?; + setup_hermes(&test_a, &test_b)?; let port_id_a = "transfer".parse().unwrap(); let port_id_b: PortId = "transfer".parse().unwrap(); @@ -2222,6 +2245,21 @@ fn make_ibc_data(message: Any) -> Vec { tx_data } +fn wait_height( + test: &Test, + height_to_wait_for: u64, + timeout: std::time::Duration, +) -> Result<()> { + let then = std::time::Instant::now(); + while then.elapsed() <= timeout { + let curr_height = query_height(test)?.revision_height(); + if curr_height >= height_to_wait_for { + return Ok(()); + } + } + Err(eyre!("Timed out waiting for height {height_to_wait_for}")) +} + fn query_height(test: &Test) -> Result { let rpc = get_actor_rpc(test, Who::Validator(0)); let tendermint_url = Url::from_str(&rpc).unwrap();