Skip to content

Commit 584ac71

Browse files
authored
Merge pull request #5099 from jbencin/fix/stop-bitcoind-config
fix: Use correct config opts in `stop_bitcoind()`
2 parents f16beb3 + 7bc0b8b commit 584ac71

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

testnet/stacks-node/src/tests/bitcoin_regtest.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,22 @@ impl BitcoinCoreController {
4444
}
4545
}
4646

47+
fn add_rpc_cli_args(&self, command: &mut Command) {
48+
command.arg(format!("-rpcport={}", self.config.burnchain.rpc_port));
49+
50+
match (
51+
&self.config.burnchain.username,
52+
&self.config.burnchain.password,
53+
) {
54+
(Some(username), Some(password)) => {
55+
command
56+
.arg(format!("-rpcuser={username}"))
57+
.arg(format!("-rpcpassword={password}"));
58+
}
59+
_ => {}
60+
}
61+
}
62+
4763
pub fn start_bitcoind(&mut self) -> BitcoinResult<()> {
4864
std::fs::create_dir_all(&self.config.get_burnchain_path_str()).unwrap();
4965

@@ -58,30 +74,16 @@ impl BitcoinCoreController {
5874
.arg("-server=1")
5975
.arg("-listenonion=0")
6076
.arg("-rpcbind=127.0.0.1")
61-
.arg(&format!("-port={}", self.config.burnchain.peer_port))
62-
.arg(&format!(
63-
"-datadir={}",
64-
self.config.get_burnchain_path_str()
65-
))
66-
.arg(&format!("-rpcport={}", self.config.burnchain.rpc_port));
77+
.arg(format!("-port={}", self.config.burnchain.peer_port))
78+
.arg(format!("-datadir={}", self.config.get_burnchain_path_str()));
6779

68-
match (
69-
&self.config.burnchain.username,
70-
&self.config.burnchain.password,
71-
) {
72-
(Some(username), Some(password)) => {
73-
command
74-
.arg(&format!("-rpcuser={}", username))
75-
.arg(&format!("-rpcpassword={}", password));
76-
}
77-
_ => {}
78-
}
80+
self.add_rpc_cli_args(&mut command);
7981

80-
eprintln!("bitcoind spawn: {:?}", command);
82+
eprintln!("bitcoind spawn: {command:?}");
8183

8284
let mut process = match command.spawn() {
8385
Ok(child) => child,
84-
Err(e) => return Err(BitcoinCoreError::SpawnFailed(format!("{:?}", e))),
86+
Err(e) => return Err(BitcoinCoreError::SpawnFailed(format!("{e:?}"))),
8587
};
8688

8789
let mut out_reader = BufReader::new(process.stdout.take().unwrap());
@@ -108,17 +110,15 @@ impl BitcoinCoreController {
108110
pub fn stop_bitcoind(&mut self) -> Result<(), BitcoinCoreError> {
109111
if let Some(_) = self.bitcoind_process.take() {
110112
let mut command = Command::new("bitcoin-cli");
111-
command
112-
.stdout(Stdio::piped())
113-
.arg("-rpcconnect=127.0.0.1")
114-
.arg("-rpcport=8332")
115-
.arg("-rpcuser=neon-tester")
116-
.arg("-rpcpassword=neon-tester-pass")
117-
.arg("stop");
113+
command.stdout(Stdio::piped()).arg("-rpcconnect=127.0.0.1");
114+
115+
self.add_rpc_cli_args(&mut command);
116+
117+
command.arg("stop");
118118

119119
let mut process = match command.spawn() {
120120
Ok(child) => child,
121-
Err(e) => return Err(BitcoinCoreError::SpawnFailed(format!("{:?}", e))),
121+
Err(e) => return Err(BitcoinCoreError::SpawnFailed(format!("{e:?}"))),
122122
};
123123

124124
let mut out_reader = BufReader::new(process.stdout.take().unwrap());
@@ -127,7 +127,7 @@ impl BitcoinCoreController {
127127
if bytes_read == 0 {
128128
break;
129129
}
130-
eprintln!("{}", &line);
130+
eprintln!("{line}");
131131
}
132132
}
133133
Ok(())

0 commit comments

Comments
 (0)