Skip to content

Commit

Permalink
test: start bitcoind from test
Browse files Browse the repository at this point in the history
  • Loading branch information
rustaceanrob committed Nov 18, 2024
1 parent dabf290 commit 4220a30
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions protocol/tests/round_trips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ fn hello_world_happy_path() {
#[cfg(feature = "std")]
#[ignore = "requires a running bitcoin daemon."]
fn regtest_handshake() {
use core::time::Duration;
use std::{
io::{Read, Write},
net::{IpAddr, Ipv4Addr, SocketAddr, TcpStream},
process::{Command, Stdio},
time::{SystemTime, UNIX_EPOCH},
};

Expand All @@ -81,6 +83,23 @@ fn regtest_handshake() {
};
use bitcoin::p2p::{message_network::VersionMessage, Address, ServiceFlags};

#[allow(clippy::zombie_processes)]
Command::new("bitcoind")
.arg("--chain=regtest")
.arg("--rpcport=18443")
.arg("--rpcuser=test")
.arg("--rpcpassword=bip324")
.arg("--rest=1")
.arg("--server=1")
.arg("--listen=1")
.arg("--v2transport=1")
.stdout(Stdio::null())
.spawn()
.expect("failed to start bitcoind");

println!("Waiting for bitcoind to initialize");
std::thread::sleep(Duration::from_secs(1));

let mut stream = TcpStream::connect(format!("127.0.0.1:{PORT}")).unwrap();
let mut public_key = [0u8; 64];
let mut handshake = Handshake::new(
Expand Down Expand Up @@ -150,4 +169,15 @@ fn regtest_handshake() {
let msg = decrypter.decrypt_payload(&response_message, None).unwrap();
let message = deserialize(msg.contents()).unwrap();
assert_eq!(message.cmd(), "version");

Command::new("bitcoin-cli")
.arg("--chain=regtest")
.arg("--rpcuser=test")
.arg("--rpcpassword=bip324")
.arg("stop")
.stdout(Stdio::null())
.spawn()
.expect("failed to stop bitcoind")
.wait()
.expect("failed to stop bitcoind");
}

0 comments on commit 4220a30

Please sign in to comment.