chainwayxyz / bitcoin-mock-rpc

Mock library for bitcoincore_rpc's RpcTrait interface
MIT License
1 stars 0 forks source link
bitcoin bitcoin-rpc bitcoin-rpc-test rust-bitcoin

Bitcoin Mock Remote Procedure Call

This library is a mock of bitcoincore-rpc library, which is a wrapper of Bitcoin RPC for Rust. This library aims to mock RpcApi trait interface of bitcoincore-rpc and provide a separate mock blockchain for every unit and integration test.

Usage

This mock won't provide a CLI tool. Instead, you should use this in your Rust code. You can use generics as your RPC struct and use this mock in your tests and real RPC interface in your application code.

Example:

struct MyStruct<R: RpcApiWrapper> {
    data: u32,
    rpc: R,
}

fn my_func() {
    let strct = MyStruct {
        data: 0x45,
        // This will connect Bitcoin RPC.
        rpc: bitcoincore_rpc::Client::new(/** parameters here **/),
    };

    // Do stuff...
}

#[test]
fn test() {
    let strct = MyStruct {
        data: 0x1F,
        // This will create a mock blockchain, on memory.
        rpc: bitcoin_mock_rpc::Client::new(/** parameters here **/),
    };

    // Do stuff...
}

This library is aimed to help development of clementine. Therefore, it's usage of this library can be taken as a reference.

Testing

Standard Rust tools are sufficient for testing:

cargo test

Documentation

No external documentation is provided. Please read comments in code for documentation.

License

This project is licensed with MIT license.