Skip to content

Commit 08c0ac3

Browse files
committed
Expose da client per node
1 parent fc12cb0 commit 08c0ac3

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

src/framework.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,28 +99,45 @@ impl TestFramework {
9999
}
100100

101101
pub async fn init_nodes(&mut self) -> Result<()> {
102+
// Use first node config for now, as we expect citrea nodes to interact only with this main node for now.
103+
// Additional bitcoin node are solely used for simulating a bitcoin network and tx propagation/re-orgs
104+
let bitcoin_config = &self.ctx.config.bitcoin[0];
105+
102106
// Has to initialize sequencer first since provers and full node depend on it
103107
self.sequencer = create_optional(
104108
self.ctx.config.test_case.with_sequencer,
105-
Sequencer::new(&self.ctx.config.sequencer, Arc::clone(&self.ctx.docker)),
109+
Sequencer::new(
110+
&self.ctx.config.sequencer,
111+
bitcoin_config,
112+
Arc::clone(&self.ctx.docker),
113+
),
106114
)
107115
.await?;
108116

109117
(self.batch_prover, self.light_client_prover, self.full_node) = tokio::try_join!(
110118
create_optional(
111119
self.ctx.config.test_case.with_batch_prover,
112-
BatchProver::new(&self.ctx.config.batch_prover, Arc::clone(&self.ctx.docker))
120+
BatchProver::new(
121+
&self.ctx.config.batch_prover,
122+
bitcoin_config,
123+
Arc::clone(&self.ctx.docker)
124+
)
113125
),
114126
create_optional(
115127
self.ctx.config.test_case.with_light_client_prover,
116128
LightClientProver::new(
117129
&self.ctx.config.light_client_prover,
130+
bitcoin_config,
118131
Arc::clone(&self.ctx.docker)
119132
)
120133
),
121134
create_optional(
122135
self.ctx.config.test_case.with_full_node,
123-
FullNode::new(&self.ctx.config.full_node, Arc::clone(&self.ctx.docker))
136+
FullNode::new(
137+
&self.ctx.config.full_node,
138+
bitcoin_config,
139+
Arc::clone(&self.ctx.docker)
140+
)
124141
),
125142
)?;
126143

src/node.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ use tracing::{debug, info, trace};
1818

1919
use crate::{
2020
client::Client,
21-
config::{DaLayer, DockerConfig, RollupConfig},
21+
config::{BitcoinConfig, DaLayer, DockerConfig, RollupConfig},
2222
docker::DockerEnv,
2323
log_provider::LogPathProvider,
2424
traits::{NodeT, Restart, SpawnOutput},
2525
utils::{get_citrea_path, get_genesis_path},
2626
Result,
2727
};
28+
use bitcoincore_rpc::{Auth, Client as BitcoinClient};
2829

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

8689
impl<C> Node<C>
8790
where
8891
C: Config + LogPathProvider + Send + Sync + Debug,
8992
DockerConfig: From<C>,
9093
{
91-
pub async fn new(config: &C, docker: Arc<Option<DockerEnv>>) -> Result<Self> {
94+
pub async fn new(
95+
config: &C,
96+
da_config: &BitcoinConfig,
97+
docker: Arc<Option<DockerEnv>>,
98+
) -> Result<Self> {
9299
let spawn_output = <Self as NodeT>::spawn(config, &docker).await?;
93100

94101
let client = Client::new(config.rpc_bind_host(), config.rpc_bind_port())?;
102+
103+
let da_rpc_url = format!(
104+
"http://127.0.0.1:{}/wallet/{}",
105+
da_config.rpc_port,
106+
C::kind()
107+
);
108+
let da_client = BitcoinClient::new(
109+
&da_rpc_url,
110+
Auth::UserPass(da_config.rpc_user.clone(), da_config.rpc_password.clone()),
111+
)
112+
.await
113+
.context("Failed to create RPC client")?;
114+
95115
Ok(Self {
96116
spawn_output,
97117
config: config.clone(),
98118
client,
119+
da: da_client,
99120
})
100121
}
101122

tests/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ impl TestCase for DockerIntegrationTest {
5151

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

54+
let unspent_sequencer = sequencer
55+
.da
56+
.list_unspent(None, None, None, None, None)
57+
.await?;
58+
let unspent_da = da.list_unspent(None, None, None, None, None).await?;
59+
// Make sure sequencer.da and da don't hit the same wallet
60+
assert_ne!(unspent_sequencer, unspent_da);
61+
5462
Ok(())
5563
}
5664
}

0 commit comments

Comments
 (0)