use super::*;
pub(crate) struct ContextBuilder {
args: Vec<OsString>,
chain: Chain,
tempdir: Option<TempDir>,
}
impl ContextBuilder {
pub(crate) fn build(self) -> Context {
self.try_build().unwrap()
}
pub(crate) fn try_build(self) -> Result<Context> {
let rpc_server = test_bitcoincore_rpc::builder()
.network(self.chain.network())
.build();
let tempdir = self.tempdir.unwrap_or_else(|| TempDir::new().unwrap());
let cookie_file = tempdir.path().join("cookie");
fs::write(&cookie_file, "username:password").unwrap();
let command: Vec<OsString> = vec![
"ord".into(),
"--rpc-url".into(),
rpc_server.url().into(),
"--data-dir".into(),
tempdir.path().into(),
"--cookie-file".into(),
cookie_file.into(),
format!("--chain={}", self.chain).into(),
];
let options = Options::try_parse_from(command.into_iter().chain(self.args)).unwrap();
let index = Index::open(&options)?;
index.update().unwrap();
Ok(Context {