[][src]Struct exonum_testkit::TestKitApi

pub struct TestKitApi { /* fields omitted */ }

API encapsulation for the testkit. Allows to execute and asynchronously retrieve results for REST-ful endpoints of services.

Note that TestKitApi instantiation spawns a new HTTP server. Hence, it is advised to reuse existing instances unless it is impossible. The latter may be the case if changes to the testkit modify the set of its HTTP endpoints, for example, if a new service is instantiated.

The HTTP server uses actix under the hood, so in order to execute asynchronous methods, the user should use this API inside the actix_rt or tokio runtime. The easiest way to do that is to use #[tokio::test] or #[actix_rt::test] instead of #[test].

Examples

use exonum_rust_runtime::{ProtoSourcesQuery, ProtoSourceFile};

#[tokio::test]
async fn test_api() {
    let mut testkit = TestKitBuilder::validator().build();
    let api = testkit.api();
    // Without services / plugins, API only contains endpoints
    // provided by the Rust runtime.
    let proto_sources: Vec<ProtoSourceFile> = api
        .public(ApiKind::RustRuntime)
        .query(&ProtoSourcesQuery::Core)
        .get("proto-sources")
        .await
        .expect("Request to the valid endpoint failed");
}

Methods

impl TestKitApi[src]

pub fn new(testkit: &mut TestKit) -> Self[src]

Creates a new instance of API.

pub async fn send<'_, T>(&'_ self, transaction: T) where
    T: Into<Verified<AnyTx>>, 
[src]

Sends a transaction to the node.

pub fn public_url(&self, url: &str) -> String[src]

Returns the resolved URL for the public API.

pub fn private_url(&self, url: &str) -> String[src]

Returns the resolved URL for the private API.

pub fn public(&self, kind: impl Display) -> RequestBuilder[src]

Creates a requests builder for the public API scope.

pub fn private(&self, kind: impl Display) -> RequestBuilder[src]

Creates a requests builder for the private API scope.

pub fn client(&self) -> &TestKitApiClient[src]

Return reference to the underlying API client.

Trait Implementations

impl Debug for TestKitApi[src]

Auto Trait Implementations

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> From<T> for T[src]

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

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>,