fix tests compilation

This commit is contained in:
keorn 2016-09-29 16:57:52 +01:00
parent d085146254
commit d59e9e816e
5 changed files with 31 additions and 29 deletions

View File

@ -19,6 +19,7 @@
use super::{Height, Round, BlockHash}; use super::{Height, Round, BlockHash};
use rlp::{View, DecoderError, Decodable, Decoder, Encodable, RlpStream, Stream}; use rlp::{View, DecoderError, Decodable, Decoder, Encodable, RlpStream, Stream};
#[derive(Debug)]
pub enum ConsensusMessage { pub enum ConsensusMessage {
Prevote(Height, Round, BlockHash), Prevote(Height, Round, BlockHash),
Precommit(Height, Round, BlockHash), Precommit(Height, Round, BlockHash),

View File

@ -73,7 +73,7 @@ impl Tendermint {
let engine = Arc::new( let engine = Arc::new(
Tendermint { Tendermint {
params: params, params: params,
timeout: AtomicUsize::new(our_params.timeouts.propose()), timeout: AtomicUsize::new(our_params.timeouts.propose),
our_params: our_params, our_params: our_params,
builtins: builtins, builtins: builtins,
timeout_service: IoService::<NextStep>::start().expect("Error creating engine timeout service"), timeout_service: IoService::<NextStep>::start().expect("Error creating engine timeout service"),
@ -244,6 +244,8 @@ impl Engine for Tendermint {
} }
fn handle_message(&self, sender: Address, signature: H520, message: UntrustedRlp) -> Result<Bytes, Error> { fn handle_message(&self, sender: Address, signature: H520, message: UntrustedRlp) -> Result<Bytes, Error> {
let c: ConsensusMessage = try!(message.as_val());
println!("{:?}", c);
// Check if correct round. // Check if correct round.
if self.r.load(AtomicOrdering::Relaxed) != try!(message.val_at(0)) { if self.r.load(AtomicOrdering::Relaxed) != try!(message.val_at(0)) {
try!(Err(EngineError::WrongRound)) try!(Err(EngineError::WrongRound))
@ -325,11 +327,8 @@ mod tests {
use account_provider::AccountProvider; use account_provider::AccountProvider;
use spec::Spec; use spec::Spec;
use engines::{Engine, EngineError}; use engines::{Engine, EngineError};
use super::{Tendermint, TendermintParams}; use super::Tendermint;
use super::params::TendermintParams;
/// Create a new test chain spec with `Tendermint` consensus engine.
/// Account "0".sha3() and "1".sha3() are a validators.
fn new_test_tendermint() -> Spec { Spec::load(include_bytes!("../../res/tendermint.json")) }
fn propose_default(engine: &Arc<Engine>, round: u8, proposer: Address) -> Result<Bytes, Error> { fn propose_default(engine: &Arc<Engine>, round: u8, proposer: Address) -> Result<Bytes, Error> {
let mut s = RlpStream::new_list(3); let mut s = RlpStream::new_list(3);
@ -372,14 +371,14 @@ mod tests {
#[test] #[test]
fn has_valid_metadata() { fn has_valid_metadata() {
let engine = new_test_tendermint().engine; let engine = Spec::new_test_tendermint().engine;
assert!(!engine.name().is_empty()); assert!(!engine.name().is_empty());
assert!(engine.version().major >= 1); assert!(engine.version().major >= 1);
} }
#[test] #[test]
fn can_return_schedule() { fn can_return_schedule() {
let engine = new_test_tendermint().engine; let engine = Spec::new_test_tendermint().engine;
let schedule = engine.schedule(&EnvInfo { let schedule = engine.schedule(&EnvInfo {
number: 10000000, number: 10000000,
author: 0.into(), author: 0.into(),
@ -395,7 +394,7 @@ mod tests {
#[test] #[test]
fn verification_fails_on_short_seal() { fn verification_fails_on_short_seal() {
let engine = new_test_tendermint().engine; let engine = Spec::new_test_tendermint().engine;
let header: Header = Header::default(); let header: Header = Header::default();
let verify_result = engine.verify_block_basic(&header, None); let verify_result = engine.verify_block_basic(&header, None);
@ -409,7 +408,7 @@ mod tests {
#[test] #[test]
fn verification_fails_on_wrong_signatures() { fn verification_fails_on_wrong_signatures() {
let engine = new_test_tendermint().engine; let engine = Spec::new_test_tendermint().engine;
let mut header = Header::default(); let mut header = Header::default();
let tap = AccountProvider::transient_provider(); let tap = AccountProvider::transient_provider();
@ -445,7 +444,7 @@ mod tests {
#[test] #[test]
fn seal_with_enough_signatures_is_ok() { fn seal_with_enough_signatures_is_ok() {
let engine = new_test_tendermint().engine; let engine = Spec::new_test_tendermint().engine;
let mut header = Header::default(); let mut header = Header::default();
let seal = good_seal(&header); let seal = good_seal(&header);
@ -460,7 +459,7 @@ mod tests {
#[test] #[test]
fn can_generate_seal() { fn can_generate_seal() {
let spec = new_test_tendermint(); let spec = Spec::new_test_tendermint();
let ref engine = *spec.engine; let ref engine = *spec.engine;
let tender = Tendermint::new(engine.params().clone(), TendermintParams::default(), BTreeMap::new()); let tender = Tendermint::new(engine.params().clone(), TendermintParams::default(), BTreeMap::new());
@ -480,7 +479,7 @@ mod tests {
#[test] #[test]
fn propose_step() { fn propose_step() {
let engine = new_test_tendermint().engine; let engine = Spec::new_test_tendermint().engine;
let tap = AccountProvider::transient_provider(); let tap = AccountProvider::transient_provider();
let r = 0; let r = 0;
@ -499,7 +498,7 @@ mod tests {
#[test] #[test]
fn proposer_switching() { fn proposer_switching() {
let engine = new_test_tendermint().engine; let engine = Spec::new_test_tendermint().engine;
let tap = AccountProvider::transient_provider(); let tap = AccountProvider::transient_provider();
// Currently not a proposer. // Currently not a proposer.
@ -514,7 +513,7 @@ mod tests {
#[test] #[test]
fn prevote_step() { fn prevote_step() {
let engine = new_test_tendermint().engine; let engine = Spec::new_test_tendermint().engine;
let tap = AccountProvider::transient_provider(); let tap = AccountProvider::transient_provider();
let r = 0; let r = 0;
@ -533,7 +532,7 @@ mod tests {
#[test] #[test]
fn precommit_step() { fn precommit_step() {
let engine = new_test_tendermint().engine; let engine = Spec::new_test_tendermint().engine;
let tap = AccountProvider::transient_provider(); let tap = AccountProvider::transient_provider();
let r = 0; let r = 0;
@ -553,7 +552,7 @@ mod tests {
#[test] #[test]
fn timeout_switching() { fn timeout_switching() {
let tender = { let tender = {
let engine = new_test_tendermint().engine; let engine = Spec::new_test_tendermint().engine;
Tendermint::new(engine.params().clone(), TendermintParams::default(), BTreeMap::new()) Tendermint::new(engine.params().clone(), TendermintParams::default(), BTreeMap::new())
}; };
@ -563,7 +562,7 @@ mod tests {
#[test] #[test]
fn increments_round() { fn increments_round() {
let spec = new_test_tendermint(); let spec = Spec::new_test_tendermint();
let ref engine = *spec.engine; let ref engine = *spec.engine;
let def_params = TendermintParams::default(); let def_params = TendermintParams::default();
let tender = Tendermint::new(engine.params().clone(), def_params.clone(), BTreeMap::new()); let tender = Tendermint::new(engine.params().clone(), def_params.clone(), BTreeMap::new());

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Tendermint BFT consensus engine with round robin proof-of-authority. //! Tendermint specific parameters.
use common::{Address, U256}; use common::{Address, U256};
use ethjson; use ethjson;

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Tendermint BFT consensus engine with round robin proof-of-authority. //! Tendermint timeout handling.
use std::sync::atomic::{Ordering as AtomicOrdering}; use std::sync::atomic::{Ordering as AtomicOrdering};
use std::sync::Weak; use std::sync::Weak;
@ -35,14 +35,10 @@ impl TimerHandler {
/// Base timeout of each step in ms. /// Base timeout of each step in ms.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct DefaultTimeouts { pub struct DefaultTimeouts {
propose: Ms, pub propose: Ms,
prevote: Ms, pub prevote: Ms,
precommit: Ms, pub precommit: Ms,
commit: Ms pub commit: Ms
}
impl DefaultTimeouts {
pub fn propose(&self) -> usize { self.propose }
} }
impl Default for DefaultTimeouts { impl Default for DefaultTimeouts {
@ -56,7 +52,7 @@ impl Default for DefaultTimeouts {
} }
} }
type Ms = usize; pub type Ms = usize;
#[derive(Clone)] #[derive(Clone)]
pub struct NextStep; pub struct NextStep;

View File

@ -266,6 +266,12 @@ impl Spec {
pub fn new_test_instant() -> Self { pub fn new_test_instant() -> Self {
Spec::load(include_bytes!("../../res/instant_seal.json") as &[u8]).expect("instant_seal.json is invalid") Spec::load(include_bytes!("../../res/instant_seal.json") as &[u8]).expect("instant_seal.json is invalid")
} }
/// Create a new Spec with Tendermint consensus which does internal sealing (not requiring work).
/// Account "0".sha3() and "1".sha3() are a validators.
pub fn new_test_tendermint() -> Self {
Spec::load(include_bytes!("../../res/tendermint.json") as &[u8]).expect("tendermint.json is invalid")
}
} }
#[cfg(test)] #[cfg(test)]