diff --git a/src/framework.rs b/src/framework.rs index cc16d4e..d3596be 100644 --- a/src/framework.rs +++ b/src/framework.rs @@ -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) + ) ), )?; diff --git a/src/node.rs b/src/node.rs index 5abc49b..508b809 100644 --- a/src/node.rs +++ b/src/node.rs @@ -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 { @@ -81,6 +82,8 @@ pub struct Node { spawn_output: SpawnOutput, config: C, pub client: Client, + // Bitcoin client targetting node's wallet endpoint + pub da: BitcoinClient, } impl Node @@ -88,14 +91,32 @@ where C: Config + LogPathProvider + Send + Sync + Debug, DockerConfig: From, { - pub async fn new(config: &C, docker: Arc>) -> Result { + pub async fn new( + config: &C, + da_config: &BitcoinConfig, + docker: Arc>, + ) -> Result { let spawn_output = ::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, }) } diff --git a/tests/mod.rs b/tests/mod.rs index bc3b3fe..f214fd7 100644 --- a/tests/mod.rs +++ b/tests/mod.rs @@ -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(()) } }