Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

converted more integration tests to unit test #548

Merged
merged 8 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ mod tests {
fn height_limit() {
let bitcoin_rpc_server = BitcoinRpcServer::spawn();

bitcoin_rpc_server.mine_block();
bitcoin_rpc_server.mine_blocks(1);

let tempdir = TempDir::new().unwrap();

Expand Down Expand Up @@ -602,7 +602,7 @@ mod tests {
fn first_coinbase_transaction() {
let bitcoin_rpc_server = BitcoinRpcServer::spawn();

bitcoin_rpc_server.mine_block();
bitcoin_rpc_server.mine_blocks(1);

let tempdir = TempDir::new().unwrap();

Expand Down
134 changes: 133 additions & 1 deletion src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ mod tests {
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(response.text().unwrap(), "0");

test_server.bitcoin_rpc_server.mine_block();
test_server.bitcoin_rpc_server.mine_blocks(1);

let response = test_server.get("height");

Expand Down Expand Up @@ -952,4 +952,136 @@ mod tests {
"Invalid URL: error parsing TXID: odd hex string length 3",
);
}
#[test]
fn output() {
let test_server = TestServer::new();

test_server.assert_response_regex(
"output/4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0",
StatusCode::OK,
".*<title>Output 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0</title>.*<h1>Output 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0</h1>
<h2>Ordinal Ranges</h2>
<ul class=monospace>
<li><a href=/range/0/5000000000 class=mythic>\\[0,5000000000\\)</a></li>
</ul>.*",
);
}

#[test]
fn unknown_output_returns_404() {
TestServer::new().assert_response(
"output/0000000000000000000000000000000000000000000000000000000000000000:0",
StatusCode::NOT_FOUND,
"Output unknown.",
);
}

#[test]
fn invalid_output_returns_400() {
TestServer::new().assert_response(
"output/foo:0",
StatusCode::BAD_REQUEST,
"Invalid URL: error parsing TXID: odd hex string length 3",
);
}

#[test]
fn home() {
let test_server = TestServer::new();

test_server.bitcoin_rpc_server.mine_blocks(1);

test_server.assert_response_regex(
"/",
StatusCode::OK,
".*<title>Ordinals</title>.*<h1>Ordinals</h1>
<nav>.*</nav>
.*
<h2>Recent Blocks</h2>
<ol start=1 reversed class=monospace>
<li><a href=/block/[[:xdigit:]]{64} class=uncommon>[[:xdigit:]]{64}</a></li>
<li><a href=/block/000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f class=mythic>000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f</a></li>
</ol>.*",
);
}

#[test]
fn home_block_limit() {
let test_server = TestServer::new();

test_server.bitcoin_rpc_server.mine_blocks(200);

test_server.assert_response_regex(
"/",
StatusCode::OK,
".*<ol start=200 reversed class=monospace>\n( <li><a href=/block/[[:xdigit:]]{64} class=uncommon>[[:xdigit:]]{64}</a></li>\n){100}</ol>.*"
);
}

#[test]
fn block_not_found() {
TestServer::new().assert_response(
"block/467a86f0642b1d284376d13a98ef58310caa49502b0f9a560ee222e0a122fe16",
StatusCode::NOT_FOUND,
"Not Found",
);
}

#[test]
fn unmined_ordinal() {
TestServer::new().assert_response_regex(
"ordinal/0",
StatusCode::OK,
".*<dt>time</dt><dd>2009-01-03 18:15:05</dd>.*",
);
}

#[test]
fn mined_ordinal() {
TestServer::new().assert_response_regex(
"ordinal/5000000000",
StatusCode::OK,
".*<dt>time</dt><dd>.* \\(expected\\)</dd>.*",
);
}

#[test]
fn static_asset() {
TestServer::new().assert_response_regex(
"static/index.css",
StatusCode::OK,
r".*\.rare \{
background-color: cornflowerblue;
}.*",
);
}

#[test]
fn favicon() {
TestServer::new().assert_response_regex("favicon.ico", StatusCode::OK, r".*");
}

#[test]
fn clock_updates() {
let test_server = TestServer::new();

test_server.assert_response_regex(
"clock",
StatusCode::OK,
r#".*<line y2="-9" transform="rotate\(0\)"/>.*"#,
);

test_server.bitcoin_rpc_server.mine_blocks(1);

test_server.assert_response_regex(
"clock",
StatusCode::OK,
r#".*<line y2="-9" transform="rotate\(0.00005194805194805195\)"/>.*"#,
);
}

#[test]
fn clock_is_served_with_svg_extension() {
TestServer::new().assert_response_regex("clock.svg", StatusCode::OK, "<svg.*");
}
}
4 changes: 2 additions & 2 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ impl BitcoinRpcServerHandle {
bitcoincore_rpc::Client::new(&self.url(), Auth::None).unwrap()
}

pub(crate) fn mine_block(&self) {
pub(crate) fn mine_blocks(&self, num: u64) {
self
.client()
.generate_to_address(1, &"1BitcoinEaterAddressDontSendf59kuE".parse().unwrap())
.generate_to_address(num, &"1BitcoinEaterAddressDontSendf59kuE".parse().unwrap())
.unwrap();
}
}
Expand Down
144 changes: 0 additions & 144 deletions tests/server.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,5 @@
use super::*;

#[test]
fn output() {
let mut state = State::new();

state.blocks(1);

state.request_regex(
"output/4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0",
200,
".*<title>Output 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0</title>.*<h1>Output 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0</h1>
<h2>Ordinal Ranges</h2>
<ul class=monospace>
<li><a href=/range/0/5000000000 class=mythic>\\[0,5000000000\\)</a></li>
</ul>.*",
);
}

#[test]
fn unknown_output_returns_404() {
let mut state = State::new();

state.request(
"output/0000000000000000000000000000000000000000000000000000000000000000:0",
404,
"Output unknown.",
);
}

#[test]
#[ignore]
fn spent_output_returns_200() {
Expand Down Expand Up @@ -78,50 +50,6 @@ fn spent_output_returns_200() {
);
}

#[test]
fn invalid_output_returns_400() {
let mut state = State::new();

state.request_regex(
"output/foo:0",
400,
"Invalid URL: error parsing TXID: odd hex string length 3",
);
}

#[test]
fn home() {
let mut state = State::new();

state.blocks(1);

state.request_regex(
"/",
200,
".*<title>Ordinals</title>.*<h1>Ordinals</h1>
<nav>.*</nav>
.*
<h2>Recent Blocks</h2>
<ol start=1 reversed class=monospace>
<li><a href=/block/[[:xdigit:]]{64} class=uncommon>[[:xdigit:]]{64}</a></li>
<li><a href=/block/0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206 class=mythic>0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206</a></li>
</ol>.*",
);
}

#[test]
fn home_block_limit() {
let mut state = State::new();

state.blocks(200);

state.request_regex(
"/",
200,
".*<ol start=200 reversed class=monospace>\n( <li><a href=/block/[[:xdigit:]]{64} class=uncommon>[[:xdigit:]]{64}</a></li>\n){100}</ol>.*"
);
}

#[test]
fn block() {
let mut state = State::new();
Expand Down Expand Up @@ -149,15 +77,6 @@ fn block() {
);
}

#[test]
fn block_not_found() {
State::new().request(
"block/467a86f0642b1d284376d13a98ef58310caa49502b0f9a560ee222e0a122fe16",
404,
"Not Found",
);
}

#[test]
fn transaction() {
let mut state = State::new();
Expand All @@ -183,66 +102,3 @@ fn transaction() {
</ul>.*"
);
}

#[test]
fn unmined_ordinal() {
let mut state = State::new();
state.request_regex(
"ordinal/0",
200,
".*<dt>time</dt><dd>2011-02-02 23:16:42</dd>.*",
);
}

#[test]
fn mined_ordinal() {
let mut state = State::new();
state.request_regex(
"ordinal/5000000000",
200,
".*<dt>time</dt><dd>.* \\(expected\\)</dd>.*",
);
}

#[test]
fn static_asset() {
let mut state = State::new();
state.request_regex(
"static/index.css",
200,
r".*\.rare \{
background-color: cornflowerblue;
}.*",
);
}

#[test]
fn favicon() {
let mut state = State::new();
state.request_expected("favicon.ico", 200, Expected::Ignore);
}

#[test]
fn clock_updates() {
let mut state = State::new();

state.request_regex(
"clock",
200,
r#".*<line y2="-9" transform="rotate\(0\)"/>.*"#,
);

state.blocks(1);

state.request_regex(
"clock",
200,
r#".*<line y2="-9" transform="rotate\(0.00005194805194805195\)"/>.*"#,
);
}

#[test]
fn clock_is_served_with_svg_extension() {
let mut state = State::new();
state.request_regex("clock.svg", 200, "<svg.*");
}
4 changes: 0 additions & 4 deletions tests/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,6 @@ impl State {
tx
}

pub(crate) fn request(&mut self, path: &str, status: u16, expected_response: &str) {
self.request_expected(path, status, Expected::String(expected_response.into()));
}

pub(crate) fn request_regex(&mut self, path: &str, status: u16, expected_response: &str) {
self.request_expected(path, status, Expected::regex(expected_response));
}
Expand Down