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]
fn api(&self) -> TestKitApi
[src]
Creates an instance of TestKitApi
to test the API provided by services.
fn poll_events(&mut self) -> Option<Result<(), ()>>
[src]
Polls the existing events from the event loop until exhaustion. Does not wait until new events arrive.
fn snapshot(&self) -> Box<Snapshot>
[src]
Returns a snapshot of the current blockchain state.
fn blockchain_mut(&mut self) -> &mut Blockchain
[src]
Returns a blockchain instance for low level manipulations with storage.
fn probe_all(&self, transactions: Vec<Box<Transaction>>) -> Box<Snapshot>
[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.
fn probe<T: Transaction>(&self, transaction: T) -> Box<Snapshot>
[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.
fn create_block_with_transactions<I>(&mut self, txs: I) where
I: IntoIterator<Item = Box<Transaction>>,
[src]
I: IntoIterator<Item = Box<Transaction>>,
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.
fn create_block_with_tx_hashes(&mut self, tx_hashes: &[Hash])
[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.
fn create_block(&mut self)
[src]
Creates block with all transactions in the mempool.
fn create_blocks_until(&mut self, height: Height)
[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());
fn last_block_hash(&self) -> Hash
[src]
Returns the hash of latest committed block.
fn height(&self) -> Height
[src]
Returns the height of latest committed block.
fn actual_configuration(&self) -> StoredConfiguration
[src]
Returns the actual blockchain configuration.
fn validator(&self, id: ValidatorId) -> &TestNode
[src]
Returns reference to validator with the given identifier.
Panics
- Panics if validator with the given id is absent in test network.
fn majority_count(&self) -> usize
[src]
Returns sufficient number of validators for the Byzantine Fault Toulerance consensus.
fn mempool(&self) -> RwLockReadGuard<BTreeMap<Hash, Box<Transaction>>>
[src]
Returns the test node memory pool handle.
fn leader(&self) -> &TestNode
[src]
Returns the leader on the current height. At the moment first validator.
fn network(&self) -> &TestNetwork
[src]
Returns the reference to test network.
fn network_mut(&mut self) -> &mut TestNetwork
[src]
Returns the mutable reference to test network for manual modifications.
fn configuration_change_proposal(&self) -> TestNetworkConfiguration
[src]
Returns a copy of the actual configuration of the testkit.
The returned configuration could be modified for use with
commit_configuration_change
method.
fn commit_configuration_change(&mut self, proposal: TestNetworkConfiguration)
[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 ); }