Skip to content

Commit

Permalink
verifier: Small details to let it work.
Browse files Browse the repository at this point in the history
  • Loading branch information
ceyhunsen committed Oct 11, 2024
1 parent e25e730 commit 7162243
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 26 deletions.
38 changes: 19 additions & 19 deletions src/clementine/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{fs::File, process::Stdio, time::Duration};

use anyhow::Context;
use async_trait::async_trait;
use tokio::{process::Command, time::Instant};
use tokio::process::Command;
use tracing::info;

use crate::{
Expand Down Expand Up @@ -87,24 +87,24 @@ where
&mut self.spawn_output
}

async fn wait_for_ready(&self, timeout: Option<Duration>) -> Result<()> {
let start = Instant::now();
let timeout = timeout.unwrap_or(Duration::from_secs(30));
while start.elapsed() < timeout {
// if self
// .client
// .ledger_get_head_soft_confirmation()
// .await
// .is_ok()
// {
return Ok(());
// }
// sleep(Duration::from_millis(500)).await;
}
anyhow::bail!(
"{} failed to become ready within the specified timeout",
C::node_kind()
)
async fn wait_for_ready(&self, _timeout: Option<Duration>) -> Result<()> {
// let start = Instant::now();
// let timeout = timeout.unwrap_or(Duration::from_secs(30));
// while start.elapsed() < timeout {
// if self
// .client
// .ledger_get_head_soft_confirmation()
// .await
// .is_ok()
// {
return Ok(());
// }
// sleep(Duration::from_millis(500)).await;
// }
// anyhow::bail!(
// "{} failed to become ready within the specified timeout",
// C::node_kind()
// )
}

fn client(&self) -> &Self::Client {
Expand Down
3 changes: 2 additions & 1 deletion src/config/test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{
bitcoin::BitcoinConfig, test_case::TestCaseConfig, FullBatchProverConfig, FullFullNodeConfig,
FullLightClientProverConfig, FullSequencerConfig,
FullLightClientProverConfig, FullSequencerConfig, FullVerifierConfig,
};

#[derive(Clone)]
Expand All @@ -10,5 +10,6 @@ pub struct TestConfig {
pub sequencer: FullSequencerConfig,
pub batch_prover: FullBatchProverConfig,
pub light_client_prover: FullLightClientProverConfig,
pub verifier: FullVerifierConfig,
pub full_node: FullFullNodeConfig,
}
7 changes: 7 additions & 0 deletions src/config/test_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct TestCaseEnv {
pub batch_prover: Vec<(&'static str, &'static str)>,
pub light_client_prover: Vec<(&'static str, &'static str)>,
pub bitcoin: Vec<(&'static str, &'static str)>,
pub verifier: Vec<(&'static str, &'static str)>,
}

impl TestCaseEnv {
Expand Down Expand Up @@ -41,6 +42,10 @@ impl TestCaseEnv {
pub fn bitcoin(&self) -> Vec<(&'static str, &'static str)> {
[self.test_env(), self.bitcoin.clone()].concat()
}

pub fn verifier(&self) -> Vec<(&'static str, &'static str)> {
[self.test_env(), self.verifier.clone()].concat()
}
}

#[derive(Clone)]
Expand All @@ -50,6 +55,7 @@ pub struct TestCaseConfig {
pub with_full_node: bool,
pub with_batch_prover: bool,
pub with_light_client_prover: bool,
pub with_verifier: bool,
pub timeout: Duration,
pub dir: PathBuf,
pub docker: bool,
Expand All @@ -67,6 +73,7 @@ impl Default for TestCaseConfig {
with_batch_prover: false,
with_light_client_prover: false,
with_full_node: false,
with_verifier: false,
timeout: Duration::from_secs(60),
dir: TempDir::new()
.expect("Failed to create temporary directory")
Expand Down
24 changes: 20 additions & 4 deletions src/test_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ use super::{
};
use crate::{
config::{
BatchProverConfig, BitcoinServiceConfig, FullLightClientProverConfig,
LightClientProverConfig, RpcConfig, RunnerConfig, SequencerConfig, StorageConfig,
BatchProverConfig, BitcoinServiceConfig, ClementineConfig, FullLightClientProverConfig,
FullVerifierConfig, LightClientProverConfig, RpcConfig, RunnerConfig, SequencerConfig,
StorageConfig,
},
traits::NodeT,
utils::{get_default_genesis_path, get_workspace_root},
Expand Down Expand Up @@ -129,8 +130,9 @@ impl<T: TestCase> TestCaseRunner<T> {
let batch_prover_rollup = default_rollup_config();
let light_client_prover_rollup = default_rollup_config();
let full_node_rollup = default_rollup_config();
let clementine_config = T::clementine_config();

let [bitcoin_dir, dbs_dir, batch_prover_dir, light_client_prover_dir, sequencer_dir, full_node_dir, genesis_dir, tx_backup_dir] =
let [bitcoin_dir, dbs_dir, batch_prover_dir, light_client_prover_dir, sequencer_dir, full_node_dir, genesis_dir, tx_backup_dir, verifier_dir] =
create_dirs(&test_case.dir)?;

copy_genesis_dir(&test_case.genesis_dir, &genesis_dir)?;
Expand Down Expand Up @@ -298,6 +300,13 @@ impl<T: TestCase> TestCaseRunner<T> {
node: (),
env: env.full_node(),
},
verifier: FullVerifierConfig {
config: ClementineConfig::default(),
docker_image: None,
env: env.verifier(),
node: clementine_config,
dir: verifier_dir,
},
test_case,
})
}
Expand Down Expand Up @@ -346,6 +355,12 @@ pub trait TestCase: Send + Sync + 'static {
LightClientProverConfig::default()
}

/// Returns the light clementine configuration for the test.
/// Override this method to provide a custom clementine configuration.
fn clementine_config() -> ClementineConfig {
ClementineConfig::default()
}

/// Returns the test setup
/// Override this method to add custom initialization logic
async fn setup(&self, _framework: &mut TestFramework) -> Result<()> {
Expand All @@ -366,14 +381,15 @@ pub trait TestCase: Send + Sync + 'static {
}
}

fn create_dirs(base_dir: &Path) -> Result<[PathBuf; 8]> {
fn create_dirs(base_dir: &Path) -> Result<[PathBuf; 9]> {
let paths = [
NodeKind::Bitcoin.to_string(),
"dbs".to_string(),
NodeKind::BatchProver.to_string(),
NodeKind::LightClientProver.to_string(),
NodeKind::Sequencer.to_string(),
NodeKind::FullNode.to_string(),
NodeKind::Verifier.to_string(),
"genesis".to_string(),
"inscription_txs".to_string(),
]
Expand Down
4 changes: 2 additions & 2 deletions src/verifier.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::path::PathBuf;

use crate::{config::FullVerifierConfig, node::Node, traits::NodeT};
use crate::{clementine, config::FullVerifierConfig, traits::NodeT};

pub type Verifier = Node<FullVerifierConfig>;
pub type Verifier = clementine::node::ClementineNode<FullVerifierConfig>;

impl Verifier {
pub fn dir(&self) -> &PathBuf {
Expand Down

0 comments on commit 7162243

Please sign in to comment.