Skip to content

Commit

Permalink
tests/e2e: change epoch_sleep to use namadac epoch-sleep
Browse files Browse the repository at this point in the history
Instead of manually querying, we now epoch-sleep until the next epoch,
limiting the number of clients invoked to 1.

Also update the epoch sleep e2e test to check the return value (parsed
from the output of epoch-sleep).
  • Loading branch information
juped authored and tzemanovic committed Jul 11, 2023
1 parent 8f7a1b0 commit ab08395
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
37 changes: 23 additions & 14 deletions tests/src/e2e/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,20 +424,29 @@ pub fn epoch_sleep(
ledger_address: &str,
timeout_secs: u64,
) -> Result<Epoch> {
let old_epoch = get_epoch(test, ledger_address)?;
let start = Instant::now();
let loop_timeout = Duration::new(timeout_secs, 0);
loop {
if Instant::now().duration_since(start) > loop_timeout {
panic!("Timed out waiting for the next epoch");
}
let epoch = get_epoch(test, ledger_address)?;
if epoch > old_epoch {
break Ok(epoch);
} else {
sleep(10);
}
}
let mut find = run!(
test,
Bin::Client,
&["epoch-sleep", "--node", ledger_address],
Some(timeout_secs)
)?;
parse_reached_epoch(&mut find)
}

pub fn parse_reached_epoch(find: &mut NamadaCmd) -> Result<Epoch> {
let (unread, matched) = find.exp_regex("Reached epoch .*")?;
let epoch_str = strip_trailing_newline(&matched)
.trim()
.rsplit_once(' ')
.unwrap()
.1;
let epoch = u64::from_str(epoch_str).map_err(|e| {
eyre!(format!(
"Epoch: {} parsed from {}, Error: {}\n\nOutput: {}",
epoch_str, matched, e, unread
))
})?;
Ok(Epoch(epoch))
}

/// Wait for txs and VPs WASM compilations to finish. This is useful to avoid a
Expand Down
5 changes: 5 additions & 0 deletions tests/src/e2e/ledger_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use super::helpers::{
use super::setup::{get_all_wasms_hashes, set_ethereum_bridge_mode};
use crate::e2e::helpers::{
epoch_sleep, find_address, find_bonded_stake, get_actor_rpc, get_epoch,
parse_reached_epoch,
};
use crate::e2e::setup::{self, default_port_offset, sleep, Bin, Who};
use crate::{run, run_as};
Expand Down Expand Up @@ -4696,11 +4697,15 @@ fn test_epoch_sleep() -> Result<()> {
// 3. Use epoch-sleep to sleep for an epoch
let args = ["epoch-sleep", "--node", &validator_one_rpc];
let mut client = run!(test, Bin::Client, &args, None)?;
let reached_epoch = parse_reached_epoch(&mut client)?;
client.assert_success();

// 4. Confirm the current epoch is larger
// possibly badly, we assume we get here within 30 seconds of the last step
// should be fine haha (future debuggers: sorry)
let current_epoch = get_epoch(&test, &validator_one_rpc).unwrap();
assert!(current_epoch > start_epoch);
assert_eq!(current_epoch, reached_epoch);

Ok(())
}
Expand Down

0 comments on commit ab08395

Please sign in to comment.