Skip to content

Commit bbb7560

Browse files
committed
Merge #26: test: Add testenv module
f1db39a ci: Run `test_rpc_client` integration tests (valued mammal) ee52af4 test: Improve unit, integration tests (valued mammal) d77416c error: Unimplement `Error::source` (valued mammal) Pull request description: ### Description This is a follow up to #5 that introduces a `TestEnv` struct used for integration tests and fixes a number of nitpicks that were previously left out. Summary: - Add simple `TestEnv` struct with convenient interface for improved ergonomics - Avoid manually implementing RPC calls (e.g. `generate_to_address`) - Move auth tests to `client::test_auth` module - Ignore (or remove) test using potentially insecure `std::env::tempdir` - Don't call `node.stop()`, as this is handled by the `Drop` implementation of `Node` - Add missing tests for existing RPC methods `get_block_verbose`, `get_block_header_verbose` - Don't print to stdout - Have more effective test assertions. For example it's sufficient to check that the RPC method returns the expected type. Keep some basic "sanity check" assertions, but try to avoid testing functionality that is defined outside of this library (e.g. the length of a `BlockHash`, and Bitcoin Core itself). ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing ACKs for top commit: ValuedMammal: self-ACK f1db39a Tree-SHA512: 3634e0e00ed910b979eb998ad13b6a786f827a679495a12237c543a9a8e291eb04602cf0105753fa56dc542cdb57471d87bf630b8afee3bd1564d558cb1b016b
2 parents ae754b3 + f1db39a commit bbb7560

7 files changed

Lines changed: 197 additions & 224 deletions

File tree

.github/workflows/cont_integration.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ jobs:
7979
- name: Run doc tests
8080
run: cargo test ${{ matrix.features }} --doc --verbose
8181

82+
- name: Run RPC client tests
83+
run: cargo test --test test_rpc_client --verbose -- --test-threads=2
84+
8285
# MSRV
8386
msrv:
8487
name: MSRV

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ default = ["30_0"]
2222
28_0 = []
2323

2424
[dev-dependencies]
25+
anyhow = "1"
2526
corepc-node = { version = "0.10.1", features = ["download", "29_0"] }

src/client.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ mod test_auth {
284284
}
285285

286286
#[test]
287+
#[ignore = "modifies the local filesystem"]
287288
fn test_auth_cookie_file_get_user_pass() {
288289
let temp_dir = std::env::temp_dir();
289290
let cookie_path = temp_dir.join("test_auth_cookie");
@@ -299,4 +300,14 @@ mod test_auth {
299300

300301
std::fs::remove_file(cookie_path).ok();
301302
}
303+
304+
#[test]
305+
fn test_auth_invalid_cookie_file() {
306+
let dummy_url = "http://127.0.0.1:18443";
307+
let cookie_path = PathBuf::from("/nonexistent/path/to/cookie");
308+
309+
let result = Client::with_auth(dummy_url, Auth::CookieFile(cookie_path));
310+
311+
assert!(matches!(result, Err(Error::InvalidCookieFile)));
312+
}
302313
}

src/error.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,7 @@ impl fmt::Display for Error {
6767
}
6868
}
6969

70-
impl std::error::Error for Error {
71-
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
72-
match self {
73-
Error::DecodeHex(e) => Some(e),
74-
Error::JsonRpc(e) => Some(e),
75-
Error::HexToArray(e) => Some(e),
76-
Error::Json(e) => Some(e),
77-
Error::Io(e) => Some(e),
78-
Error::TryFromInt(e) => Some(e),
79-
Error::GetBlockVerboseOne(e) => Some(e),
80-
Error::GetBlockHeaderVerbose(e) => Some(e),
81-
Error::GetBlockFilter(e) => Some(e),
82-
_ => None,
83-
}
84-
}
85-
}
70+
impl std::error::Error for Error {}
8671

8772
// Conversions from other error types
8873
impl From<jsonrpc::Error> for Error {

0 commit comments

Comments
 (0)