Skip to content

Commit 167804c

Browse files
committed
readme: Update description, add usage, documentation and testing sections.
1 parent 374c0bb commit 167804c

File tree

1 file changed

+54
-9
lines changed

1 file changed

+54
-9
lines changed

Diff for: README.md

+54-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,61 @@
11
# Bitcoin Mock Remote Procedure Call
22

3-
This library mocks [bitcoincore-rpc](https://github.com/rust-bitcoin/rust-bitcoincore-rpc)
4-
library. This mock takes the advantage of `bitcoincore-rpc` trait interface,
5-
called `RpcApi`. With this mock, every test can have an isolated Bitcoin
6-
environment without changing your existing code too much.
3+
This library is a mock of [bitcoincore-rpc](https://github.com/rust-bitcoin/rust-bitcoincore-rpc)
4+
library, which is a wrapper of Bitcoin RPC for Rust. This library aims to mock
5+
`RpcApi` trait interface of bitcoincore-rpc and provide a separate mock
6+
blockchain for every unit and integration test.
77

8-
[bitcoin-simulator](https://github.com/Bitcoin-Wildlife-Sanctuary/bitcoin-simulator)
9-
is used for creating an isolated Bitcoin environment. Which can be also called a
10-
mock.
8+
## Usage
119

12-
These 2 means one don't need any external connection/binary to test code that
13-
uses Bitcoin network.
10+
This mock won't provide a CLI tool. Instead, you should use this in your Rust
11+
code. You can use generics as your RPC struct and use this mock in your tests
12+
and real RPC interface in your application code.
13+
14+
Example:
15+
16+
```rust
17+
struct MyStruct<R: RpcApiWrapper> {
18+
data: u32,
19+
rpc: R,
20+
}
21+
22+
fn my_func() {
23+
let strct = MyStruct {
24+
data: 0x45,
25+
// This will connect Bitcoin RPC.
26+
rpc: bitcoincore_rpc::Client::new(/** parameters here **/),
27+
};
28+
29+
// Do stuff...
30+
}
31+
32+
#[test]
33+
fn test() {
34+
let strct = MyStruct {
35+
data: 0x1F,
36+
// This will create a mock blockchain, on memory.
37+
rpc: bitcoin_mock_rpc::Client::new(/** parameters here **/),
38+
};
39+
40+
// Do stuff...
41+
}
42+
```
43+
44+
This library is aimed to help development of [clementine](https://github.com/chainwayxyz/clementine).
45+
Therefore, it's usage of this library can be taken as a reference.
46+
47+
## Testing
48+
49+
Standard Rust tools are sufficient for testing:
50+
51+
```bash
52+
cargo test
53+
```
54+
55+
## Documentation
56+
57+
No external documentation is provided. Please read comments in code for
58+
documentation.
1459

1560
## License
1661

0 commit comments

Comments
 (0)