Skip to content

Commit

Permalink
Make index::custom_index_size test faster (#579)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Sep 29, 2022
1 parent a4fd75c commit ab879fc
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 28 deletions.
4 changes: 3 additions & 1 deletion tests/command_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl CommandBuilder {
}
}

pub(crate) fn run(self) {
pub(crate) fn run(self) -> TempDir {
let mut command = Command::new(executable_path("ord"));

if let Some(rpc_server_url) = self.rpc_server_url {
Expand Down Expand Up @@ -99,5 +99,7 @@ impl CommandBuilder {

self.expected_stderr.assert_match(stderr);
self.expected_stdout.assert_match(stdout);

self.tempdir
}
}
20 changes: 14 additions & 6 deletions tests/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@ use super::*;

#[test]
fn custom_index_size() {
let state = SlowTest::new()
.command("--max-index-size 1mib find 0")
let rpc_server = test_bitcoincore_rpc::spawn();
rpc_server.mine_blocks(1);

let tempdir = CommandBuilder::new("--max-index-size 1mib find 0")
.rpc_server(&rpc_server)
.expected_stdout("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0:0\n")
.blocks(1)
.output();
.run();

assert_eq!(
state
.ord_data_dir()
tempdir
.path()
.join(if cfg!(target_os = "macos") {
"Library/Application Support/"
} else {
".local/share"
})
.join("ord")
.join("index.redb")
.metadata()
.unwrap()
Expand Down
1 change: 0 additions & 1 deletion tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use {
std::{
fs,
net::TcpListener,
path::PathBuf,
process::{Child, Command, Stdio},
str,
sync::Once,
Expand Down
16 changes: 8 additions & 8 deletions tests/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,54 @@ use super::*;
fn genesis() {
CommandBuilder::new("range 0")
.expected_stdout("[0,5000000000)\n")
.run()
.run();
}

#[test]
fn second_block() {
CommandBuilder::new("range 1")
.expected_stdout("[5000000000,10000000000)\n")
.run()
.run();
}

#[test]
fn last_block_with_subsidy() {
CommandBuilder::new("range 6929999")
.expected_stdout("[2099999997689999,2099999997690000)\n")
.run()
.run();
}

#[test]
fn first_block_without_subsidy() {
CommandBuilder::new("range 6930000")
.expected_stdout("[2099999997690000,2099999997690000)\n")
.run()
.run();
}

#[test]
fn genesis_names() {
CommandBuilder::new("range --name 0")
.expected_stdout("[nvtdijuwxlp,nvtcsezkbth)\n")
.run()
.run();
}

#[test]
fn names_before_last() {
CommandBuilder::new("range --name 6929998")
.expected_stdout("[b,a)\n")
.run()
.run();
}

#[test]
fn last_name() {
CommandBuilder::new("range --name 6929999")
.expected_stdout("[a,)\n")
.run()
.run();
}

#[test]
fn block_with_no_subsidy_range() {
CommandBuilder::new("range --name 6930000")
.expected_stdout("[,)\n")
.run()
.run();
}
12 changes: 0 additions & 12 deletions tests/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,6 @@ impl State {

tx
}

pub(crate) fn ord_data_dir(&self) -> PathBuf {
self
.tempdir
.path()
.join(if cfg!(target_os = "macos") {
"Library/Application Support/"
} else {
".local/share"
})
.join("ord")
}
}

impl Drop for State {
Expand Down

0 comments on commit ab879fc

Please sign in to comment.