Skip to content

Commit

Permalink
Add clean-data recipe, rename data/ dir to tmp-db/ (#306)
Browse files Browse the repository at this point in the history
The `data` directory was used for ChainStore databases generated during testing. It has been renamed to `tmp-db` to explicitly signal it's a temporary log (we are using another `tests/data` directory for python tests but this one is non-generated and permanent).

A new shell script and just recipe have been added in order to delete all test-generated data. It prompts the user for confirmation with the found `tmp` and `tmp-db` directories.
  • Loading branch information
JoseSK999 authored Dec 13, 2024
1 parent 5b41277 commit 730995e
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 13 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# Temporary files and generated data
tmp/
tmp-db/
data/
output.log

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# Temporary files and generated data
tmp/
tmp-db/
data/
output.log

Expand Down
27 changes: 27 additions & 0 deletions contrib/clean_data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# Find all 'tmp-db' directories in subdirectories
dirs=$(find . -type d -name 'tmp-db')

# Display the directories that will be deleted
echo "The following 'tmp-db' directories will be deleted:"
echo "$dirs"

# Prompt the user for confirmation
read -r -p "Are you sure you want to delete './tmp' and all 'tmp-db' directories listed above? [y/N] " ans

# Check the user's response
if [[ "$ans" =~ ^[Yy]$ ]]; then
# User confirmed, proceed with deletion

# Delete 'tmp' in the current directory (if run via justfile this is the root)
rm -rf tmp

# Delete all 'tmp-db' directories found
find . -type d -name 'tmp-db' -exec rm -rf {} +

echo "Directories deleted."
else
# User did not confirm, cancel the operation
echo "Deletion cancelled."
fi
2 changes: 1 addition & 1 deletion crates/floresta-chain/benches/chain_state_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn setup_test_chain<'a>(
assume_valid_arg: AssumeValidArg,
) -> ChainState<KvChainStore<'a>> {
let test_id = rand::random::<u64>();
let chainstore = KvChainStore::new(format!("./data/{test_id}/")).unwrap();
let chainstore = KvChainStore::new(format!("./tmp-db/{test_id}/")).unwrap();
ChainState::new(chainstore, network, assume_valid_arg)
}

Expand Down
2 changes: 1 addition & 1 deletion crates/floresta-chain/src/pruned_utreexo/chain_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,7 @@ mod test {
assume_valid_arg: AssumeValidArg,
) -> ChainState<KvChainStore<'a>> {
let test_id = rand::random::<u64>();
let chainstore = KvChainStore::new(format!("./data/{test_id}/")).unwrap();
let chainstore = KvChainStore::new(format!("./tmp-db/{test_id}/")).unwrap();
ChainState::new(chainstore, network, assume_valid_arg)
}

Expand Down
2 changes: 1 addition & 1 deletion crates/floresta-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ mod tests {
false => debug_path,
};

// makes a temporary directory
// Makes a temporary directory to store the chain db, SSL certificates, logs, etc.
let test_code = rand::random::<u64>();
let dirname = format!("{root}/tmp/floresta.{test_code}");
fs::DirBuilder::new()
Expand Down
6 changes: 3 additions & 3 deletions crates/floresta-electrum/src/electrum_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ mod test {

fn get_test_cache() -> Arc<AddressCache<KvDatabase>> {
let test_id: u32 = rand::random();
let cache = KvDatabase::new(format!("./data/{test_id}.floresta")).unwrap();
let cache = KvDatabase::new(format!("./tmp-db/{test_id}.floresta")).unwrap();
let cache = AddressCache::new(cache);

// Inserting test transactions in the wallet
Expand Down Expand Up @@ -1032,7 +1032,7 @@ mod test {

// Create test_chain_state
let test_id = rand::random::<u32>();
let chainstore = KvChainStore::new(format!("./data/{test_id}.floresta/")).unwrap();
let chainstore = KvChainStore::new(format!("./tmp-db/{test_id}.floresta/")).unwrap();
let chain =
ChainState::<KvChainStore>::new(chainstore, Network::Signet, AssumeValidArg::Hardcoded);

Expand All @@ -1045,7 +1045,7 @@ mod test {
network: bitcoin::Network::Signet,
pow_fraud_proofs: true,
proxy: None,
datadir: "/data".to_string(),
datadir: "/tmp-db".to_string(),
fixed_peer: None,
max_banscore: 50,
compact_filters: false,
Expand Down
2 changes: 1 addition & 1 deletion crates/floresta-watch-only/src/kv_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ mod test {
fn get_test_db() -> KvDatabase {
let test_id = rand::random::<u32>();

KvDatabase::new(format!("./data/{test_id}.floresta/")).unwrap()
KvDatabase::new(format!("./tmp-db/{test_id}.floresta/")).unwrap()
}
fn get_test_address() -> (Address<NetworkChecked>, sha256::Hash) {
let address = Address::from_str("tb1q9d4zjf92nvd3zhg6cvyckzaqumk4zre26x02q9")
Expand Down
2 changes: 1 addition & 1 deletion crates/floresta-wire/src/p2p_wire/tests/sync_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ mod tests_utils {
pow_fraud_proofs: bool,
network: floresta_chain::Network,
) -> Arc<ChainState<KvChainStore<'static>>> {
let datadir = format!("./data/{}.sync_node", rand::random::<u32>());
let datadir = format!("./tmp-db/{}.sync_node", rand::random::<u32>());
let chainstore = KvChainStore::new(datadir.clone()).unwrap();
let mempool = Arc::new(RwLock::new(Mempool::new()));
let chain = ChainState::new(chainstore, network, AssumeValidArg::Disabled);
Expand Down
2 changes: 1 addition & 1 deletion crates/floresta/examples/chainstate-builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use floresta_chain::pruned_utreexo::chain_state_builder::ChainStateBuilder;
use floresta_chain::ChainParams;
use rustreexo::accumulator::stump::Stump;

const DATA_DIR: &str = "./data";
const DATA_DIR: &str = "./tmp-db";

#[tokio::main]
async fn main() {
Expand Down
2 changes: 1 addition & 1 deletion crates/floresta/examples/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use floresta_wire::running_node::RunningNode;
use floresta_wire::UtreexoNodeConfig;
use tokio::sync::RwLock;

const DATA_DIR: &str = "./data";
const DATA_DIR: &str = "./tmp-db";

#[tokio::main]
async fn main() {
Expand Down
9 changes: 6 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ test name="":

# Execute doc tests
test-doc name="":
cargo test {{name}} --doc
cargo test {{name}} --doc

# Execute unit tests
test-unit name="":
Expand All @@ -57,8 +57,11 @@ fmt:
format:
cargo +nightly fmt --all --check

# Test all feature combinations for each crate using cargo hack (arg: optional, e.g., --quiet or --verbose)
# Will try to install or update the cargo-hack package
# Test all feature combinations for each crate using cargo-hack (arg: optional, e.g., --quiet or --verbose)
test-features arg="":
cargo install cargo-hack --locked
./contrib/test_features.sh {{arg}}

# Remove test-generated data
clean-data:
./contrib/clean_data.sh

0 comments on commit 730995e

Please sign in to comment.