[−][src]Struct exonum_testkit::StoppedTestKit
Persistent state of an Exonum node allowing to emulate node restart.
The persistent state holds the database (including uncommitted transactions) and the network configuration, but does not retain the internal state of the services.
This method is useful to test scenarios that may play a different way depending
on node restarts, such as services with dynamic internal state modified in response
to blockchain events (e.g., in Service::after_commit
).
Examples
// Service with internal state modified by a custom `after_commit` hook. #[derive(Clone)] struct AfterCommitService { counter: Arc<AtomicUsize>, } impl AfterCommitService { pub fn new() -> Self { AfterCommitService { counter: Arc::new(AtomicUsize::default()) } } pub fn counter(&self) -> usize { self.counter.load(Ordering::SeqCst) } } impl Service for AfterCommitService { // Other methods... fn after_commit(&self, context: &ServiceContext) { self.counter.fetch_add(1, Ordering::SeqCst); } } let service = AfterCommitService::new(); let mut testkit = TestKit::for_service(service.clone()); testkit.create_blocks_until(Height(5)); assert_eq!(service.counter(), 5); // Stop the testkit. let stopped = testkit.stop(); assert_eq!(stopped.height(), Height(5)); // Resume with the same single service with a fresh state. let service = AfterCommitService::new(); let mut testkit = stopped.resume(vec![service.clone().into()]); testkit.create_blocks_until(Height(8)); assert_eq!(service.counter(), 3); // We've only created 3 new blocks.
Methods
impl StoppedTestKit
[src]
pub fn snapshot(&self) -> Box<dyn Snapshot>
[src]
Returns a snapshot of the database state.
pub fn height(&self) -> Height
[src]
Returns the height of latest committed block.
pub fn network(&self) -> &TestNetwork
[src]
Returns the reference to test network.
pub fn resume(self, services: Vec<Box<dyn Service>>) -> TestKit
[src]
Resumes the operation of the testkit.
Note that services
may differ from the vector of services initially passed to
the TestKit
(which is also what may happen with real Exonum apps).
Trait Implementations
Auto Trait Implementations
impl Sync for StoppedTestKit
impl Send for StoppedTestKit
impl Unpin for StoppedTestKit
impl RefUnwindSafe for StoppedTestKit
impl UnwindSafe for StoppedTestKit
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> 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, U> TryInto<U> 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> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,
fn vzip(self) -> V
impl<T> Erased for T
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
U: TryFrom<T>,