use {
  super::*,
  crate::command_builder::ToArgs,
  bitcoincore_rpc::{Auth, Client, RpcApi},
  reqwest::blocking::Response,
};

pub(crate) struct TestServer {
  child: Child,
  port: u16,
  #[allow(unused)]
  tempdir: TempDir,
  rpc_url: String,
}

impl TestServer {
  pub(crate) fn spawn_with_args(
    rpc_server: &test_bitcoincore_rpc::Handle,
    ord_args: &[&str],
  ) -> Self {
    Self::spawn_with_server_args(rpc_server, ord_args, &[])
  }

  pub(crate) fn spawn_with_server_args(
    rpc_server: &test_bitcoincore_rpc::Handle,
    ord_args: &[&str],
    server_args: &[&str],
  ) -> Self {
    let tempdir = TempDir::new().unwrap();
    fs::write(tempdir.path().join(".cookie"), "foo:bar").unwrap();
    let port = TcpListener::bind("127.0.0.1:0")
      .unwrap()
      .local_addr()
      .unwrap()
      .port();

    let child = Command::new(executable_path("ord")).args(format!(
      "--rpc-url {} --bitcoin-data-dir {} --data-dir {} {} server {} --http-port {port} --address 127.0.0.1",
      rpc_server.url(),