Struct exonum_testkit::TestKit [] [src]

pub struct TestKit { /* fields omitted */ }

Testkit for testing blockchain services. It offers simple network configuration emulation (with no real network setup).

Methods

impl TestKit
[src]

[src]

Creates an instance of TestKitApi to test the API provided by services.

[src]

Polls the existing events from the event loop until exhaustion. Does not wait until new events arrive.

[src]

Returns a snapshot of the current blockchain state.

[src]

Returns a blockchain instance for low level manipulations with storage.

[src]

Executes a list of transactions given the current state of the blockchain, but does not commit execution results to the blockchain. The execution result is the same as if transactions were included into a new block; for example, transactions included into one of previous blocks do not lead to any state changes.

Panics

  • Panics if there are duplicate transactions.

[src]

Executes a transaction given the current state of the blockchain but does not commit execution results to the blockchain. The execution result is the same as if a transaction was included into a new block; for example, a transaction included into one of previous blocks does not lead to any state changes.

[src]

Creates block with the given transactions. Transactions that are in mempool will be ignored.

Panics

  • Panics if any of transactions has been already committed to the blockchain.

[src]

Creates block with the specified transactions. The transactions must be previously sent to the node via API or directly put into the channel().

Panics

  • Panics in the case any of transaction hashes are not in the mempool.

[src]

Creates block with all transactions in the mempool.

[src]

Creates a chain of blocks until a given height.

Example

let mut testkit = TestKitBuilder::validator().create();
testkit.create_blocks_until(Height(5));
assert_eq!(Height(5), testkit.height());

[src]

Returns the hash of latest committed block.

[src]

Returns the height of latest committed block.

[src]

Returns the actual blockchain configuration.

[src]

Returns reference to validator with the given identifier.

Panics

  • Panics if validator with the given id is absent in test network.

[src]

Returns sufficient number of validators for the Byzantine Fault Toulerance consensus.

[src]

Returns the test node memory pool handle.

[src]

Returns the leader on the current height. At the moment first validator.

[src]

Returns the reference to test network.

[src]

Returns the mutable reference to test network for manual modifications.

[src]

Returns a copy of the actual configuration of the testkit. The returned configuration could be modified for use with commit_configuration_change method.

[src]

Adds a new configuration proposal. Remember, to add this proposal to the blockchain, you should create at least one block.

Panics

  • Panics if actual_from is less than current height or equals.
  • Panics if configuration change has been already proposed but not executed.

Example

extern crate exonum;
extern crate exonum_testkit;
extern crate serde;
extern crate serde_json;

use exonum::helpers::{Height, ValidatorId};
use exonum_testkit::TestKitBuilder;
use exonum::blockchain::Schema;
use exonum::storage::StorageValue;

fn main() {
   let mut testkit = TestKitBuilder::auditor().with_validators(3).create();

   let cfg_change_height = Height(5);
   let proposal = {
        let mut cfg = testkit.configuration_change_proposal();
        // Add us to validators.
        let mut validators = cfg.validators().to_vec();
        validators.push(testkit.network().us().clone());
        cfg.set_validators(validators);
        // Change configuration of our service.
        cfg.set_service_config("my_service", "My config");
        // Set the height with which the configuration takes effect.
        cfg.set_actual_from(cfg_change_height);
        cfg
    };
    // Save proposed configuration.
    let stored = proposal.stored_configuration().clone();
    // Commit configuration change proposal to the testkit.
    testkit.commit_configuration_change(proposal);
    // Create blocks up to the height preceding the `actual_from` height.
    testkit.create_blocks_until(cfg_change_height.previous());
    // Check that the proposal has become actual.
    assert_eq!(testkit.network().us().validator_id(), Some(ValidatorId(3)));
    assert_eq!(testkit.validator(ValidatorId(3)), testkit.network().us());
    assert_eq!(testkit.actual_configuration(), stored);
    assert_eq!(
        Schema::new(&testkit.snapshot())
            .previous_configuration()
            .unwrap()
            .hash(),
        stored.previous_cfg_hash
    );
}

Trait Implementations

impl Debug for TestKit
[src]

[src]

Formats the value using the given formatter.