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 rlp::{View, DecoderError, Decodable, Decoder, Encodable, RlpStream, Stream};
#[derive(Debug)]
pub enum ConsensusMessage {
Prevote(Height, Round, BlockHash),
Precommit(Height, Round, BlockHash),

View File

@ -73,7 +73,7 @@ impl Tendermint {
let engine = Arc::new(
Tendermint {
params: params,
timeout: AtomicUsize::new(our_params.timeouts.propose()),
timeout: AtomicUsize::new(our_params.timeouts.propose),
our_params: our_params,
builtins: builtins,
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> {
let c: ConsensusMessage = try!(message.as_val());
println!("{:?}", c);
// Check if correct round.
if self.r.load(AtomicOrdering::Relaxed) != try!(message.val_at(0)) {
try!(Err(EngineError::WrongRound))
@ -325,11 +327,8 @@ mod tests {
use account_provider::AccountProvider;
use spec::Spec;
use engines::{Engine, EngineError};
use super::{Tendermint, 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")) }
use super::Tendermint;
use super::params::TendermintParams;
fn propose_default(engine: &Arc<Engine>, round: u8, proposer: Address) -> Result<Bytes, Error> {
let mut s = RlpStream::new_list(3);
@ -372,14 +371,14 @@ mod tests {
#[test]
fn has_valid_metadata() {
let engine = new_test_tendermint().engine;
let engine = Spec::new_test_tendermint().engine;
assert!(!engine.name().is_empty());
assert!(engine.version().major >= 1);
}
#[test]
fn can_return_schedule() {
let engine = new_test_tendermint().engine;
let engine = Spec::new_test_tendermint().engine;
let schedule = engine.schedule(&EnvInfo {
number: 10000000,
author: 0.into(),
@ -395,7 +394,7 @@ mod tests {
#[test]
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 verify_result = engine.verify_block_basic(&header, None);
@ -409,7 +408,7 @@ mod tests {
#[test]
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 tap = AccountProvider::transient_provider();
@ -445,7 +444,7 @@ mod tests {
#[test]
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 seal = good_seal(&header);
@ -460,7 +459,7 @@ mod tests {
#[test]
fn can_generate_seal() {
let spec = new_test_tendermint();
let spec = Spec::new_test_tendermint();
let ref engine = *spec.engine;
let tender = Tendermint::new(engine.params().clone(), TendermintParams::default(), BTreeMap::new());
@ -480,7 +479,7 @@ mod tests {
#[test]
fn propose_step() {
let engine = new_test_tendermint().engine;
let engine = Spec::new_test_tendermint().engine;
let tap = AccountProvider::transient_provider();
let r = 0;
@ -499,7 +498,7 @@ mod tests {
#[test]
fn proposer_switching() {
let engine = new_test_tendermint().engine;
let engine = Spec::new_test_tendermint().engine;
let tap = AccountProvider::transient_provider();
// Currently not a proposer.
@ -514,7 +513,7 @@ mod tests {
#[test]
fn prevote_step() {
let engine = new_test_tendermint().engine;
let engine = Spec::new_test_tendermint().engine;
let tap = AccountProvider::transient_provider();
let r = 0;
@ -533,7 +532,7 @@ mod tests {
#[test]
fn precommit_step() {
let engine = new_test_tendermint().engine;
let engine = Spec::new_test_tendermint().engine;
let tap = AccountProvider::transient_provider();
let r = 0;
@ -553,7 +552,7 @@ mod tests {
#[test]
fn timeout_switching() {
let tender = {
let engine = new_test_tendermint().engine;
let engine = Spec::new_test_tendermint().engine;
Tendermint::new(engine.params().clone(), TendermintParams::default(), BTreeMap::new())
};
@ -563,7 +562,7 @@ mod tests {
#[test]
fn increments_round() {
let spec = new_test_tendermint();
let spec = Spec::new_test_tendermint();
let ref engine = *spec.engine;
let def_params = TendermintParams::default();
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
// 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 ethjson;

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// 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::Weak;
@ -35,14 +35,10 @@ impl TimerHandler {
/// Base timeout of each step in ms.
#[derive(Debug, Clone)]
pub struct DefaultTimeouts {
propose: Ms,
prevote: Ms,
precommit: Ms,
commit: Ms
}
impl DefaultTimeouts {
pub fn propose(&self) -> usize { self.propose }
pub propose: Ms,
pub prevote: Ms,
pub precommit: Ms,
pub commit: Ms
}
impl Default for DefaultTimeouts {
@ -56,7 +52,7 @@ impl Default for DefaultTimeouts {
}
}
type Ms = usize;
pub type Ms = usize;
#[derive(Clone)]
pub struct NextStep;

View File

@ -266,6 +266,12 @@ impl Spec {
pub fn new_test_instant() -> Self {
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)]