Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,28 +99,45 @@ impl TestFramework {
}

pub async fn init_nodes(&mut self) -> Result<()> {
// Use first node config for now, as we expect citrea nodes to interact only with this main node for now.
// Additional bitcoin node are solely used for simulating a bitcoin network and tx propagation/re-orgs
let bitcoin_config = &self.ctx.config.bitcoin[0];

// Has to initialize sequencer first since provers and full node depend on it
self.sequencer = create_optional(
self.ctx.config.test_case.with_sequencer,
Sequencer::new(&self.ctx.config.sequencer, Arc::clone(&self.ctx.docker)),
Sequencer::new(
&self.ctx.config.sequencer,
bitcoin_config,
Arc::clone(&self.ctx.docker),
),
)
.await?;

(self.batch_prover, self.light_client_prover, self.full_node) = tokio::try_join!(
create_optional(
self.ctx.config.test_case.with_batch_prover,
BatchProver::new(&self.ctx.config.batch_prover, Arc::clone(&self.ctx.docker))
BatchProver::new(
&self.ctx.config.batch_prover,
bitcoin_config,
Arc::clone(&self.ctx.docker)
)
),
create_optional(
self.ctx.config.test_case.with_light_client_prover,
LightClientProver::new(
&self.ctx.config.light_client_prover,
bitcoin_config,
Arc::clone(&self.ctx.docker)
)
),
create_optional(
self.ctx.config.test_case.with_full_node,
FullNode::new(&self.ctx.config.full_node, Arc::clone(&self.ctx.docker))
FullNode::new(
&self.ctx.config.full_node,
bitcoin_config,
Arc::clone(&self.ctx.docker)
)
),
)?;

Expand Down
25 changes: 23 additions & 2 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ use tracing::{debug, info, trace};

use crate::{
client::Client,
config::{DaLayer, DockerConfig, RollupConfig},
config::{BitcoinConfig, DaLayer, DockerConfig, RollupConfig},
docker::DockerEnv,
log_provider::LogPathProvider,
traits::{NodeT, Restart, SpawnOutput},
utils::{get_citrea_path, get_genesis_path},
Result,
};
use bitcoincore_rpc::{Auth, Client as BitcoinClient};

#[derive(Debug, Clone, Eq, Hash, PartialEq)]
pub enum NodeKind {
Expand Down Expand Up @@ -81,21 +82,41 @@ pub struct Node<C: Config + LogPathProvider + Send + Sync> {
spawn_output: SpawnOutput,
config: C,
pub client: Client,
// Bitcoin client targetting node's wallet endpoint
pub da: BitcoinClient,
}

impl<C> Node<C>
where
C: Config + LogPathProvider + Send + Sync + Debug,
DockerConfig: From<C>,
{
pub async fn new(config: &C, docker: Arc<Option<DockerEnv>>) -> Result<Self> {
pub async fn new(
config: &C,
da_config: &BitcoinConfig,
docker: Arc<Option<DockerEnv>>,
) -> Result<Self> {
let spawn_output = <Self as NodeT>::spawn(config, &docker).await?;

let client = Client::new(config.rpc_bind_host(), config.rpc_bind_port())?;

let da_rpc_url = format!(
"http://127.0.0.1:{}/wallet/{}",
da_config.rpc_port,
C::kind()
);
let da_client = BitcoinClient::new(
&da_rpc_url,
Auth::UserPass(da_config.rpc_user.clone(), da_config.rpc_password.clone()),
)
.await
.context("Failed to create RPC client")?;

Ok(Self {
spawn_output,
config: config.clone(),
client,
da: da_client,
})
}

Expand Down
8 changes: 8 additions & 0 deletions tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ impl TestCase for DockerIntegrationTest {

assert_eq!(commitments.len(), 1);

let unspent_sequencer = sequencer
.da
.list_unspent(None, None, None, None, None)
.await?;
let unspent_da = da.list_unspent(None, None, None, None, None).await?;
// Make sure sequencer.da and da don't hit the same wallet
assert_ne!(unspent_sequencer, unspent_da);

Ok(())
}
}
Expand Down
Loading