Struct tendermint_rpc::MockClient[][src]

pub struct MockClient<M: MockRequestMatcher> { /* fields omitted */ }

A mock client implementation for use in testing.

Examples

use tendermint_rpc::{Client, Method, MockClient, MockRequestMatcher, MockRequestMethodMatcher};

const ABCI_INFO_RESPONSE: &str = r#"{
  "jsonrpc": "2.0",
  "id": "",
  "result": {
    "response": {
      "data": "GaiaApp",
      "version": "0.17.0",
      "app_version": "1",
      "last_block_height": "488120",
      "last_block_app_hash": "2LnCw0fN+Zq/gs5SOuya/GRHUmtWftAqAkTUuoxl4g4="
    }
  }
}"#;

#[tokio::main]
async fn main() {
    let matcher = MockRequestMethodMatcher::default()
        .map(Method::AbciInfo, Ok(ABCI_INFO_RESPONSE.to_string()));
    let (client, driver) = MockClient::new(matcher);
    let driver_hdl = tokio::spawn(async move { driver.run().await });

    let abci_info = client.abci_info().await.unwrap();
    println!("Got mock ABCI info: {:?}", abci_info);
    assert_eq!("GaiaApp".to_string(), abci_info.data);

    client.close();
    driver_hdl.await.unwrap();
}

Implementations

impl<M: MockRequestMatcher> MockClient<M>[src]

pub fn new(matcher: M) -> (Self, MockClientDriver)[src]

Create a new mock RPC client using the given request matcher.

pub fn publish(&self, ev: &Event)[src]

Publishes the given event to all subscribers whose query exactly matches that of the event.

pub fn close(self)[src]

Signal to the mock client’s driver to terminate.

Trait Implementations

impl<M: MockRequestMatcher> Client for MockClient<M>[src]

impl<M: Debug + MockRequestMatcher> Debug for MockClient<M>[src]

impl<M: MockRequestMatcher> SubscriptionClient for MockClient<M>[src]

Auto Trait Implementations

impl<M> !RefUnwindSafe for MockClient<M>

impl<M> Send for MockClient<M>

impl<M> Sync for MockClient<M>

impl<M> Unpin for MockClient<M> where
    M: Unpin

impl<M> !UnwindSafe for MockClient<M>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Conv for T

impl<T> FmtForward for T

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

impl<T> TryConv for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,