1
1
# Bitcoin Mock Remote Procedure Call
2
2
3
- Bitcoin-mock-rpc is a mock Bitcoin ledger with RPC interface but without a
4
- wallet support. Meaning there are only checks for consensus details of an
5
- operation. This library can be used to test Bitcoin applications, without
6
- needing to set up Bitcoin and with a ** sandboxed environment** , for each test.
7
-
8
- Bitcoin-mock-rpc is built on
9
- [ bitcoincore-rpc's] ( https://github.com/rust-bitcoin/rust-bitcoincore-rpc )
10
- ` RpcApi ` trait. Meaning no real servers are needed for Rust applications. There
11
- is also an RPC server that can communicate with any application: No rust
12
- dependencies!
3
+ ` bitcoin-mock-rpc ` is a mock Bitcoin ledger without a wallet support built on
4
+ ` RpcApi ` trait in
5
+ [ bitcoincore-rpc] ( https://github.com/rust-bitcoin/rust-bitcoincore-rpc ) library.
6
+ Meaning there are only checks for consensus details of an operation. This
7
+ library can be used to test Bitcoin applications, without needing to set up
8
+ Bitcoin and with a ** sandboxed environment** , for each test.
13
9
14
10
This library is aimed to help the development of
15
11
[ Clementine] ( https://github.com/chainwayxyz/clementine ) . Therefore, it's usage
@@ -19,55 +15,8 @@ of this library can be taken as a reference.
19
15
not gives any guarantee to act as the Bitcoin itself at any scale. Use it at
20
16
your own risk.
21
17
22
- ## Differences Between Real Bitcoin RPC and Feature Set
23
-
24
- This library is currently ** under heavy development** . And it is not expected to
25
- provide a full Bitcoin experience. Code needs to be checked for what really is
26
- available as futures. Also, [ changelog] ( CHANGELOG.md ) is a great summary for
27
- what's available.
28
-
29
- Some of the RPC functions behave similarly with real RPC while some of them are
30
- not (mostly wallet operations). To check if an RPC function behaves different
31
- than the real one, please check function comments in
32
- [ ` src/client/rpc_api.rs ` ] ( src/client/rpc_api.rs ) .
33
-
34
18
## Usage
35
19
36
- ### RPC Server
37
-
38
- RPC server can be spawned as long as there are available ports for them. Each
39
- server will have an independent blockchain.
40
-
41
- To run from CLI:
42
-
43
- ``` bash
44
- $ cargo run
45
- Server started at 127.0.0.1:1024
46
- # ^^^^^^^^^^^^^^
47
- # Use this address in applications
48
- $ cargo run -- --help # Prints usage information
49
- ```
50
-
51
- To run in a Rust application:
52
-
53
- ``` rust
54
- #[test]
55
- fn test () {
56
- // Calling `spawn_rpc_server` in a different test while this test is running
57
- // is OK and will spawn another blockchain. If parameters are the same
58
- // however, they will operate on the same blockchain. Note: (None, None)
59
- // will result to pick random values.
60
- let address = bitcoin_mock_rpc :: spawn_rpc_server (None , None ). unwrap ();
61
-
62
- let rpc =
63
- bitcoincore_rpc :: Client :: new (& address . 0. to_string (), bitcoincore_rpc :: Auth :: None ). unwrap ();
64
-
65
- // Use `bitcoincore_rpc` as is from now on. No code change is needed.
66
- }
67
- ```
68
-
69
- ### ` RpcApiWrapper ` Trait For Rust Applications
70
-
71
20
` RpcApiWrapper ` trait can be used to select between real and mock RPC:
72
21
73
22
``` rust
@@ -98,6 +47,18 @@ fn test() {
98
47
}
99
48
```
100
49
50
+ ## Differences Between Real Bitcoin RPC and Feature Set
51
+
52
+ This library is currently ** under heavy development** . And it is not expected to
53
+ provide a full Bitcoin experience. Code needs to be checked for what really is
54
+ available as futures. Also, [ changelog] ( CHANGELOG.md ) is a great summary for
55
+ what's available.
56
+
57
+ Some of the RPC functions behave similarly with real RPC while some of them are
58
+ not (mostly wallet operations). To check if an RPC function behaves different
59
+ than the real one, please check function comments in
60
+ [ ` src/client/rpc_api.rs ` ] ( src/client/rpc_api.rs ) .
61
+
101
62
## Testing
102
63
103
64
Standard Rust tools are sufficient for testing:
0 commit comments