-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1193cbc
commit 5761a0d
Showing
3 changed files
with
187 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
use std::time::Duration; | ||
|
||
use anyhow::bail; | ||
use async_trait::async_trait; | ||
use bitcoincore_rpc::{json::IndexStatus, RpcApi}; | ||
use citrea_e2e::{ | ||
config::{BitcoinConfig, TestCaseConfig}, | ||
framework::TestFramework, | ||
test_case::{TestCase, TestCaseRunner}, | ||
traits::Restart, | ||
Result, | ||
}; | ||
|
||
struct BasicSyncTest; | ||
|
||
#[async_trait] | ||
impl TestCase for BasicSyncTest { | ||
fn test_config() -> TestCaseConfig { | ||
TestCaseConfig { | ||
with_sequencer: false, | ||
n_nodes: 2, | ||
timeout: Duration::from_secs(60), | ||
..Default::default() | ||
} | ||
} | ||
|
||
async fn run_test(&mut self, f: &mut TestFramework) -> Result<()> { | ||
let (Some(da0), Some(da1)) = (f.bitcoin_nodes.get(0), f.bitcoin_nodes.get(1)) else { | ||
bail!("bitcoind not running. Test should run with two da nodes") | ||
}; | ||
let initial_height = f.initial_da_height; | ||
|
||
// Generate some blocks on node0 | ||
da0.generate(5, None).await?; | ||
|
||
let height0 = da0.get_block_count().await?; | ||
let height1 = da1.get_block_count().await?; | ||
|
||
// Nodes are now out of sync | ||
assert_eq!(height0, initial_height + 5); | ||
assert_eq!(height1, 0); | ||
|
||
// Sync both nodes | ||
f.bitcoin_nodes | ||
.wait_for_sync(Some(Duration::from_secs(30))) | ||
.await?; | ||
|
||
let height0 = da0.get_block_count().await?; | ||
let height1 = da1.get_block_count().await?; | ||
|
||
// Assert that nodes are in sync | ||
assert_eq!(height0, height1, "Block heights don't match"); | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_basic_sync() -> Result<()> { | ||
TestCaseRunner::new(BasicSyncTest).run().await | ||
} | ||
|
||
struct RestartBitcoinTest; | ||
|
||
#[async_trait] | ||
impl TestCase for RestartBitcoinTest { | ||
fn test_config() -> TestCaseConfig { | ||
TestCaseConfig { | ||
with_sequencer: false, | ||
..Default::default() | ||
} | ||
} | ||
|
||
fn bitcoin_config() -> BitcoinConfig { | ||
BitcoinConfig { | ||
extra_args: vec!["-txindex=0"], | ||
..Default::default() | ||
} | ||
} | ||
|
||
async fn run_test(&mut self, f: &mut TestFramework) -> Result<()> { | ||
let da = f.bitcoin_nodes.get_mut(0).unwrap(); | ||
// Add txindex flag to check that restart takes into account the extra args | ||
let new_conf = BitcoinConfig { | ||
extra_args: vec!["-txindex=1"], | ||
..da.config.clone() | ||
}; | ||
|
||
let block_before = da.get_block_count().await?; | ||
let info = da.get_index_info().await?; | ||
|
||
assert_eq!(info.txindex, None); | ||
|
||
// Restart node with txindex | ||
da.restart(Some(new_conf)).await?; | ||
|
||
let block_after = da.get_block_count().await?; | ||
let info = da.get_index_info().await?; | ||
|
||
assert!(matches!( | ||
info.txindex, | ||
Some(IndexStatus { synced: true, .. }) | ||
)); | ||
// Assert that state is kept between restarts | ||
assert_eq!(block_before, block_after); | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_restart_bitcoin() -> Result<()> { | ||
TestCaseRunner::new(RestartBitcoinTest).run().await | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use async_trait::async_trait; | ||
use bitcoincore_rpc::RpcApi; | ||
use citrea_e2e::{ | ||
bitcoin::FINALITY_DEPTH, | ||
config::{TestCaseConfig, TestCaseDockerConfig}, | ||
framework::TestFramework, | ||
test_case::{TestCase, TestCaseRunner}, | ||
Result, | ||
}; | ||
|
||
struct DockerIntegrationTest; | ||
|
||
#[async_trait] | ||
impl TestCase for DockerIntegrationTest { | ||
fn test_config() -> TestCaseConfig { | ||
TestCaseConfig { | ||
with_batch_prover: true, | ||
with_full_node: true, | ||
docker: TestCaseDockerConfig { | ||
bitcoin: true, | ||
citrea: true, | ||
}, | ||
..Default::default() | ||
} | ||
} | ||
|
||
async fn run_test(&mut self, f: &mut TestFramework) -> Result<()> { | ||
let sequencer = f.sequencer.as_ref().unwrap(); | ||
let batch_prover = f.batch_prover.as_ref().unwrap(); | ||
let full_node = f.full_node.as_ref().unwrap(); | ||
let da = f.bitcoin_nodes.get(0).unwrap(); | ||
|
||
let min_soft_confirmations_per_commitment = | ||
sequencer.min_soft_confirmations_per_commitment(); | ||
|
||
for _ in 0..min_soft_confirmations_per_commitment { | ||
sequencer.client.send_publish_batch_request().await?; | ||
} | ||
|
||
// Wait for blob inscribe tx to be in mempool | ||
da.wait_mempool_len(1, None).await?; | ||
|
||
da.generate(FINALITY_DEPTH, None).await?; | ||
let finalized_height = da.get_finalized_height().await?; | ||
|
||
batch_prover | ||
.wait_for_l1_height(finalized_height, None) | ||
.await?; | ||
|
||
let commitments = full_node | ||
.wait_for_sequencer_commitments(finalized_height, None) | ||
.await?; | ||
|
||
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(()) | ||
} | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_docker_integration() -> Result<()> { | ||
TestCaseRunner::new(DockerIntegrationTest).run().await | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,2 @@ | ||
use async_trait::async_trait; | ||
use bitcoincore_rpc::RpcApi; | ||
use citrea_e2e::{ | ||
bitcoin::FINALITY_DEPTH, | ||
config::{TestCaseConfig, TestCaseDockerConfig}, | ||
framework::TestFramework, | ||
test_case::{TestCase, TestCaseRunner}, | ||
Result, | ||
}; | ||
|
||
struct DockerIntegrationTest; | ||
|
||
#[async_trait] | ||
impl TestCase for DockerIntegrationTest { | ||
fn test_config() -> TestCaseConfig { | ||
TestCaseConfig { | ||
with_batch_prover: true, | ||
with_full_node: true, | ||
docker: TestCaseDockerConfig { | ||
bitcoin: true, | ||
citrea: true, | ||
}, | ||
..Default::default() | ||
} | ||
} | ||
|
||
async fn run_test(&mut self, f: &mut TestFramework) -> Result<()> { | ||
let sequencer = f.sequencer.as_ref().unwrap(); | ||
let batch_prover = f.batch_prover.as_ref().unwrap(); | ||
let full_node = f.full_node.as_ref().unwrap(); | ||
let da = f.bitcoin_nodes.get(0).unwrap(); | ||
|
||
let min_soft_confirmations_per_commitment = | ||
sequencer.min_soft_confirmations_per_commitment(); | ||
|
||
for _ in 0..min_soft_confirmations_per_commitment { | ||
sequencer.client.send_publish_batch_request().await?; | ||
} | ||
|
||
// Wait for blob inscribe tx to be in mempool | ||
da.wait_mempool_len(1, None).await?; | ||
|
||
da.generate(FINALITY_DEPTH, None).await?; | ||
let finalized_height = da.get_finalized_height().await?; | ||
|
||
batch_prover | ||
.wait_for_l1_height(finalized_height, None) | ||
.await?; | ||
|
||
let commitments = full_node | ||
.wait_for_sequencer_commitments(finalized_height, None) | ||
.await?; | ||
|
||
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(()) | ||
} | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_docker_integration() -> Result<()> { | ||
TestCaseRunner::new(DockerIntegrationTest).run().await | ||
} | ||
mod bitcoin; | ||
mod docker; |