[−][src]Struct exonum_testkit::TestKitBuilder
Builder for TestKit
.
Testkit server
By calling the serve
method, you can transform testkit into a web server useful for
client-side testing. The testkit-specific APIs are exposed on the private address
with the /api/testkit
prefix (hereinafter denoted as {baseURL}
).
In all APIs, the request body (if applicable) and response are JSON-encoded.
Testkit status
GET {baseURL}/v1/status
Outputs the status of the testkit, which includes:
- Current blockchain height
- Current test network configuration
- Next network configuration if it is scheduled with
commit_configuration_change
.
Create block
POST {baseURL}/v1/blocks/create
Creates a new block in the testkit blockchain. If the
JSON body of the request is an empty object, the call is functionally equivalent
to create_block
. Otherwise, if the body has the tx_hashes
field specifying an array
of transaction hashes, the call is equivalent to create_block_with_tx_hashes
supplied
with these hashes.
Returns the latest block from the blockchain on success.
Roll back
POST {baseURL}/v1/blocks/rollback
Acts as a rough rollback
equivalent. The blocks are rolled back up and including the block
at the specified in JSON body height
value (a positive integer), so that after the request
the blockchain height is equal to height - 1
. If the specified height is greater than the
blockchain height, the request performs no action.
Returns the latest block from the blockchain on success.
Example
let mut testkit = TestKitBuilder::validator() .with_service(MyService) .with_validators(4) .create(); testkit.create_block(); // Other test code
Methods
impl TestKitBuilder
[src]
pub fn validator() -> Self
[src]
Creates testkit for the validator node.
pub fn auditor() -> Self
[src]
Creates testkit for the auditor node.
pub fn with_validators(self, validator_count: u16) -> Self
[src]
Sets the number of validator nodes in the test network.
pub fn with_service<S>(self, service: S) -> Self where
S: Into<Box<dyn Service>>,
[src]
S: Into<Box<dyn Service>>,
Adds a service to the testkit.
pub fn with_logger(self) -> Self
[src]
Enables a logger inside the testkit.
pub fn create(self) -> TestKit
[src]
Creates the testkit.
pub fn serve(
self,
public_api_address: SocketAddr,
private_api_address: SocketAddr
)
[src]
self,
public_api_address: SocketAddr,
private_api_address: SocketAddr
)
Starts a testkit web server, which listens to public and private APIs exposed by
the testkit, on the respective addresses. The private address also exposes the testkit
APIs with the /api/testkit
URL prefix.
Unlike real Exonum nodes, the testkit web server does not create peer-to-peer connections with other nodes, and does not create blocks automatically. The only way to commit transactions is thus to use the testkit API.
Trait Implementations
Auto Trait Implementations
impl Send for TestKitBuilder
impl Sync for TestKitBuilder
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Erased for T
impl<T> Same for T
type Output = T
Should always be Self