Skip to content

Commit

Permalink
force tests to wait until blockchain is ready #69
Browse files Browse the repository at this point in the history
  • Loading branch information
marsella committed Feb 25, 2022
1 parent bbd85d1 commit 6eacfac
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ RUN git clone https://github.com/boltlabs-inc/zeekoe.git
WORKDIR /root/zeekoe

RUN git submodule update --init --recursive
RUN ./dev/generate-certificates; CARGO_NET_GIT_FETCH_WITH_CLI=true cargo build --features "allow_explicit_certificate_trust"
RUN ./dev/generate-certificates; CARGO_NET_GIT_FETCH_WITH_CLI=true cargo build --features "allow_explicit_certificate_trust allow_custom_self_delay"

RUN wget https://github.com/serokell/tezos-packaging/releases/latest/download/tezos-client
RUN chmod +x tezos-client
Expand Down
42 changes: 42 additions & 0 deletions integration_tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,45 @@ fn write_config_file(path: &str, contents: String) {
.write_all(contents.as_bytes())
.unwrap_or_else(|_| panic!("Failed to write to config file: {}", path));
}

/// Wrapper type to deserialize blockchain level.
#[derive(Debug, serde::Deserialize)]
struct BlockchainLevel {
level: BlockchainLevelDetail,
}

/// Inner type used to deserialize blockchain level.
#[derive(Debug, serde::Deserialize)]
struct BlockchainLevelDetail {
level: u64,
}

/// The minimum required depth to originate contracts on the Tezos blockchain.
static MINIMUM_LEVEL: u64 = 120;

pub async fn await_leveled_blockchain(
config: &zeekoe::customer::Config,
) -> Result<(), anyhow::Error> {
loop {
let body = reqwest::get(format!(
"{}/chains/main/blocks/head/metadata",
config.tezos_uri
))
.await?
.text()
.await?;

let level = serde_json::from_str::<BlockchainLevel>(&body)?.level.level;
eprintln!("current: {:?} minimum: {}", level, MINIMUM_LEVEL);

if level >= MINIMUM_LEVEL {
break;
}
eprintln!(" wait time: {}", (MINIMUM_LEVEL - level) * 2);
tokio::time::sleep(tokio::time::Duration::from_secs(
(MINIMUM_LEVEL - level) * 2,
))
.await;
}
Ok(())
}
4 changes: 4 additions & 0 deletions integration_tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ pub async fn main() {
.await
.expect("Failed to load merchant config");

common::await_leveled_blockchain(&customer_config)
.await
.expect("Failed to check blockchain level");

// Run every test, printing out details if it fails
let tests = tests();
println!("Executing {} tests", tests.len());
Expand Down

0 comments on commit 6eacfac

Please sign in to comment.