Skip to content

Commit

Permalink
Make some tests faster (#543)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Sep 20, 2022
1 parent 1971363 commit 7787675
Show file tree
Hide file tree
Showing 20 changed files with 258 additions and 259 deletions.
3 changes: 1 addition & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,12 @@ use {
redb::{Database, ReadableTable, Table, TableDefinition, WriteTransaction},
serde::{Deserialize, Serialize},
std::{
cmp::Ordering,
collections::VecDeque,
env,
fmt::{self, Display, Formatter},
fs, io,
net::ToSocketAddrs,
ops::{Add, AddAssign, Deref, Mul, Sub},
ops::{Add, AddAssign, Mul, Sub},
path::{Path, PathBuf},
process,
str::FromStr,
Expand Down
6 changes: 3 additions & 3 deletions src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod find;
mod index;
mod info;
mod list;
mod name;
mod parse;
mod range;
mod server;
mod supply;
Expand All @@ -19,7 +19,7 @@ pub(crate) enum Subcommand {
Index,
Info,
List(list::List),
Name(name::Name),
Parse(parse::Parse),
Range(range::Range),
Server(server::Server),
Supply,
Expand All @@ -36,7 +36,7 @@ impl Subcommand {
Self::Index => index::run(options),
Self::Info => info::run(options),
Self::List(list) => list.run(options),
Self::Name(name) => name.run(),
Self::Parse(parse) => parse.run(),
Self::Range(range) => range.run(),
Self::Server(server) => server.run(options),
Self::Supply => supply::run(),
Expand Down
45 changes: 0 additions & 45 deletions src/subcommand/name.rs

This file was deleted.

13 changes: 13 additions & 0 deletions src/subcommand/parse.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use super::*;

#[derive(Debug, Parser)]
pub(crate) struct Parse {
ordinal: Ordinal,
}

impl Parse {
pub(crate) fn run(self) -> Result {
println!("{}", self.ordinal);
Ok(())
}
}
5 changes: 0 additions & 5 deletions src/subcommand/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ pub(crate) struct Traits {

impl Traits {
pub(crate) fn run(self) -> Result {
if self.ordinal > Ordinal::LAST {
bail!("Invalid ordinal");
}

print!("{}", self);

Ok(())
}
}
Expand Down
72 changes: 36 additions & 36 deletions tests/epochs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,44 @@ use super::*;

#[test]
fn empty() {
Test::new()
.args(&["epochs"])
TestCommand::new()
.command("epochs")
.expected_stdout(
"
0
1050000000000000
1575000000000000
1837500000000000
1968750000000000
2034375000000000
2067187500000000
2083593750000000
2091796875000000
2095898437500000
2097949218750000
2098974609270000
2099487304530000
2099743652160000
2099871825870000
2099935912620000
2099967955890000
2099983977420000
2099991988080000
2099995993410000
2099997995970000
2099998997250000
2099999497890000
2099999748210000
2099999873370000
2099999935950000
2099999967240000
2099999982780000
2099999990550000
2099999994330000
2099999996220000
2099999997060000
2099999997480000
2099999997690000
0
1050000000000000
1575000000000000
1837500000000000
1968750000000000
2034375000000000
2067187500000000
2083593750000000
2091796875000000
2095898437500000
2097949218750000
2098974609270000
2099487304530000
2099743652160000
2099871825870000
2099935912620000
2099967955890000
2099983977420000
2099991988080000
2099995993410000
2099997995970000
2099998997250000
2099999497890000
2099999748210000
2099999873370000
2099999935950000
2099999967240000
2099999982780000
2099999990550000
2099999994330000
2099999996220000
2099999997060000
2099999997480000
2099999997690000
"
.unindent(),
)
Expand Down
20 changes: 10 additions & 10 deletions tests/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::*;

#[test]
fn first_satoshi() {
Test::new()
SlowTest::new()
.command("find 0")
.expected_stdout("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0:0\n")
.run();
Expand All @@ -11,7 +11,7 @@ fn first_satoshi() {
#[test]
#[ignore]
fn first_satoshi_slot() {
Test::new()
SlowTest::new()
.command("find 0 --slot")
.expected_stdout("0x0x0x0\n")
.blocks(1)
Expand All @@ -20,7 +20,7 @@ fn first_satoshi_slot() {

#[test]
fn second_satoshi() {
Test::new()
SlowTest::new()
.command("find 1")
.expected_stdout("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0:1\n")
.run();
Expand All @@ -29,7 +29,7 @@ fn second_satoshi() {
#[test]
#[ignore]
fn second_satoshi_slot() {
Test::new()
SlowTest::new()
.command("find 1 --slot")
.expected_stdout("0x0x0x1\n")
.blocks(1)
Expand All @@ -38,7 +38,7 @@ fn second_satoshi_slot() {

#[test]
fn first_satoshi_of_second_block() {
Test::new()
SlowTest::new()
.command("find 5000000000")
.blocks(1)
.expected_stdout("150ba822b458a19615e70a604d8dd9d3482fc165fa4e9cc150d74e11916ce8ae:0:0\n")
Expand All @@ -48,7 +48,7 @@ fn first_satoshi_of_second_block() {
#[test]
#[ignore]
fn first_satoshi_of_second_block_slot() {
Test::new()
SlowTest::new()
.command("find 5000000000 --slot")
.expected_stdout("1x0x0x0\n")
.blocks(1)
Expand All @@ -58,7 +58,7 @@ fn first_satoshi_of_second_block_slot() {

#[test]
fn first_satoshi_spent_in_second_block() {
Test::new()
SlowTest::new()
.command("find 0")
.blocks(101)
.transaction(TransactionOptions {
Expand All @@ -75,7 +75,7 @@ fn first_satoshi_spent_in_second_block() {
#[test]
#[ignore]
fn first_satoshi_spent_in_second_block_slot() {
Test::new()
SlowTest::new()
.command("find 0 --slot")
.expected_stdout("1x1x0x0\n")
.blocks(1)
Expand All @@ -92,7 +92,7 @@ fn first_satoshi_spent_in_second_block_slot() {
#[test]
#[ignore]
fn mining_and_spending_transaction_in_same_block() {
Test::new()
SlowTest::new()
.command("find 0 --slot")
.blocks(1)
.blocks(1)
Expand All @@ -114,7 +114,7 @@ fn mining_and_spending_transaction_in_same_block() {

#[test]
fn unmined_satoshi_in_second_block() {
Test::new()
SlowTest::new()
.expected_stderr("error: Ordinal has not been mined as of index height\n")
.expected_status(1)
.command("find 5000000000")
Expand Down
2 changes: 1 addition & 1 deletion tests/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::*;

#[test]
fn custom_index_size() {
let state = Test::new()
let state = SlowTest::new()
.command("--max-index-size 1mib find 0")
.expected_stdout("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0:0\n")
.blocks(1)
Expand Down
4 changes: 2 additions & 2 deletions tests/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use super::*;

#[test]
fn basic() {
let output = Test::new().command("index").output();
let output = SlowTest::new().command("index").output();

Test::with_state(output.state)
SlowTest::with_state(output.state)
.command("info")
.stdout_regex(
r"
Expand Down
10 changes: 7 additions & 3 deletions tests/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#![allow(clippy::type_complexity)]

use {
self::{expected::Expected, state::State, test::Test, transaction_options::TransactionOptions},
self::{
expected::Expected, slow_test::SlowTest, state::State, test_command::TestCommand,
transaction_options::TransactionOptions,
},
bdk::{
blockchain::{
rpc::{RpcBlockchain, RpcConfig},
Expand Down Expand Up @@ -40,12 +43,13 @@ mod find;
mod index;
mod info;
mod list;
mod name;
mod parse;
mod range;
mod server;
mod slow_test;
mod state;
mod supply;
mod test;
mod test_command;
mod traits;
mod transaction_options;
mod version;
Expand Down
Loading

0 comments on commit 7787675

Please sign in to comment.