dash_sdk/mock.rs
1//! Mocking support for Dash SDK.
2//!
3//! This module provides a way to mock SDK operations. It is used in tests and examples.
4//!
5//! In order to mock SDK operations, you need to create a mock SDK instance using
6//! [Sdk::new_mock()](crate::Sdk::new_mock()).
7//! Next step is to create mock query expectations on [MockDashPlatformSdk] object returned by
8//! [Sdk::mock()](crate::Sdk::mock()), using [MockDashPlatformSdk::expect_fetch()]
9//! and [MockDashPlatformSdk::expect_fetch_many()].
10//!
11//!
12//! ## Example
13//!
14//! ```no_run
15//! let mut sdk = dash_sdk::Sdk::new_mock();
16//! let query = dash_sdk::platform::Identifier::random();
17//! sdk.mock().expect_fetch(query, None as Option<dash_sdk::platform::Identity>);
18//! ```
19//!
20//! See `tests/fetch/mock_fetch.rs` and `tests/fetch/mock_fetch_many.rs` for more detailed examples.
21
22#[cfg(not(feature = "mocks"))]
23mod noop;
24#[cfg(feature = "mocks")]
25pub mod provider;
26#[cfg(feature = "mocks")]
27mod requests;
28#[cfg(feature = "mocks")]
29pub mod sdk;
30
31// Mockable reexport is needed even if mocks feature is disabled - it just does nothing.
32// Otherwise dash_platform_macros::Mockable fails.
33// TODO: move Mockable to some crate that can be shared between dapi-grpc, rs-dapi-client, and dash-sdk
34pub use dapi_grpc::mock::Mockable;
35// MockResponse is needed even if mocks feature is disabled - it just does nothing.
36#[cfg(not(feature = "mocks"))]
37pub use noop::MockResponse;
38#[cfg(feature = "mocks")]
39pub use requests::MockResponse;
40#[cfg(feature = "mocks")]
41pub use sdk::MockDashPlatformSdk;