Skip to content

Commit

Permalink
btcio: more wallet checks (this is get annoying)
Browse files Browse the repository at this point in the history
  • Loading branch information
storopoli committed Nov 1, 2024
1 parent e588818 commit d2852b6
Showing 1 changed file with 70 additions and 36 deletions.
106 changes: 70 additions & 36 deletions crates/test-utils/src/bitcoind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ impl<'a> BitcoinD<'a> {
.wait()?;
trace!(?process, "wallet loaded");
}
if process.code() == Some(-18) {
info!("wallet not found");
let process = Command::new("bitcoin-cli")
.arg("-regtest")
.arg("-rpcuser=strata")
.arg("-rpcpassword=strata")
.arg(format!("-datadir={}", data_dir.display()))
.arg("createwallet")
.arg(format!("wallet-{timestamp}"))
.spawn()?
.wait()?;
trace!(?process, "wallet re-created");
}

thread::sleep(Duration::from_millis(200));

Expand Down Expand Up @@ -131,49 +144,70 @@ mod tests {
#[test]
fn test_bitcoind() {
logging::init();
debug!("Starting bitcoind");
let bitcoind = BitcoinD::default();
// test default bitcoind
{
debug!("Starting bitcoind");
let bitcoind = BitcoinD::default();

let data_dir = bitcoind.data_dir().clone();
debug!(?data_dir, "Data directory");
let data_dir = bitcoind.data_dir().clone();
debug!(?data_dir, "Data directory");

// Assert that the bitcoind is running
debug!("Checking if bitcoind is running");
assert!(Command::new("bitcoin-cli")
.arg("-regtest")
.arg("-rpcuser=strata")
.arg("-rpcpassword=strata")
.arg(format!("-datadir={}", data_dir.display()))
.arg("getblockchaininfo")
.output()
.is_ok());
// Assert that the bitcoind is running
debug!("Checking if bitcoind is running");
assert!(Command::new("bitcoin-cli")
.arg("-regtest")
.arg("-rpcuser=strata")
.arg("-rpcpassword=strata")
.arg(format!("-datadir={}", data_dir.display()))
.arg("getblockchaininfo")
.output()
.is_ok());

// Assert that the data directory is created
debug!("Checking if data directory is created");
assert!(data_dir.exists());
}
// Assert that the data directory is created
debug!("Checking if data directory is created");
assert!(data_dir.exists());
}

#[test]
fn bitcoind_drop_check() {
let bitcoind = BitcoinD::default();
let data_dir = bitcoind.data_dir().clone();
drop(bitcoind);
// test drop check
{
debug!("Starting bitcoind");
let bitcoind = BitcoinD::default();
let data_dir = bitcoind.data_dir().clone();
drop(bitcoind);

// Assert that the bitcoind is stopped
let output = Command::new("bitcoin-cli")
.arg("-regtest")
.arg("-rpcuser=strata")
.arg("-rpcpassword=strata")
.arg(format!("-datadir={}", data_dir.display()))
.arg("getblockchaininfo")
.output()
.unwrap();
// Assert that the bitcoind is stopped
let output = Command::new("bitcoin-cli")
.arg("-regtest")
.arg("-rpcuser=strata")
.arg("-rpcpassword=strata")
.arg(format!("-datadir={}", data_dir.display()))
.arg("getblockchaininfo")
.output()
.unwrap();

debug!(?output, "Output");

debug!(?output, "Output");
assert_eq!(output.status.code(), Some(1));

assert_eq!(output.status.code(), Some(1));
// Check if the data directory is deleted
assert!(!data_dir.exists());
}

// Check if the data directory is deleted
assert!(!data_dir.exists());
// test wallet info
{
debug!("Starting bitcoind");
let bitcoind = BitcoinD::default();
let data_dir = bitcoind.data_dir().clone();
let process = Command::new("bitcoin-cli")
.arg("-regtest")
.arg("-rpcuser=strata")
.arg("-rpcpassword=strata")
.arg(format!("-datadir={}", data_dir.display()))
.arg("getwalletinfo")
.output()
.unwrap();
debug!(?process, "Wallet info");
assert_eq!(process.status.code(), Some(0));
}
}
}

0 comments on commit d2852b6

Please sign in to comment.