Skip to content

Commit

Permalink
Wait for block height 2 in IBC tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sug0 committed Jun 18, 2024
1 parent 7f90393 commit a66136e
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion crates/tests/src/e2e/ibc_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -2222,6 +2245,21 @@ fn make_ibc_data(message: Any) -> Vec<u8> {
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<Height> {
let rpc = get_actor_rpc(test, Who::Validator(0));
let tendermint_url = Url::from_str(&rpc).unwrap();
Expand Down

0 comments on commit a66136e

Please sign in to comment.