cleaning up

This commit is contained in:
Svyatoslav Nikolsky 2018-11-13 15:42:20 +03:00
parent 1eb6cbe622
commit 29f3996f26
9 changed files with 29 additions and 20 deletions

View File

@ -67,7 +67,7 @@ mod tests {
#[test]
fn test_message_header_serialization() {
let expected = "f9beb4d96164647200000000000000001f000000ed52399b".into();
let expected = "24e927646164647200000000000000001f000000ed52399b".into();
let header = MessageHeader {
magic: Network::Mainnet.magic(),
command: "addr".into(),
@ -80,7 +80,7 @@ mod tests {
#[test]
fn test_message_header_deserialization() {
let raw: Bytes = "f9beb4d96164647200000000000000001f000000ed52399b".into();
let raw: Bytes = "24e927646164647200000000000000001f000000ed52399b".into();
let expected = MessageHeader {
magic: Network::Mainnet.magic(),
command: "addr".into(),

View File

@ -71,7 +71,7 @@ impl ConsensusParams {
Network::Regtest | Network::Unitest => ConsensusParams {
network: network,
bip16_time: 0,
bip34_height: 1,
bip34_height: 100000000,
bip65_height: 0,
bip66_height: 0,
segwit_deployment: None,

View File

@ -50,8 +50,9 @@ impl Network {
pub fn max_bits(&self) -> U256 {
match *self {
Network::Mainnet => ZCASH_MAX_BITS_MAINNET.clone(),
Network::Testnet | Network::Unitest | Network::Regtest => ZCASH_MAX_BITS_TESTNET.clone(),
Network::Testnet | Network::Regtest => ZCASH_MAX_BITS_TESTNET.clone(),
Network::Other(_) => Compact::max_value().into(),
Network::Unitest => Compact::max_value().into(),
}
}

View File

@ -69,7 +69,7 @@ mod tests {
#[test]
fn test_read_any_message() {
let raw: Bytes = "f9beb4d970696e6700000000000000000800000083c00c765845303b6da97786".into();
let raw: Bytes = "24e9276470696e6700000000000000000800000083c00c765845303b6da97786".into();
let name = "ping".into();
let nonce = "5845303b6da97786".into();
let expected = (name, nonce);
@ -80,14 +80,14 @@ mod tests {
#[test]
fn test_read_too_short_any_message() {
let raw: Bytes = "f9beb4d970696e6700000000000000000800000083c00c765845303b6da977".into();
let raw: Bytes = "24e9276470696e6700000000000000000800000083c00c765845303b6da977".into();
assert!(read_any_message(raw.as_ref(), Network::Mainnet.magic()).wait().is_err());
}
#[test]
fn test_read_any_message_with_invalid_checksum() {
let raw: Bytes = "f9beb4d970696e6700000000000000000800000083c01c765845303b6da97786".into();
let raw: Bytes = "24e9276470696e6700000000000000000800000083c01c765845303b6da97786".into();
assert_eq!(read_any_message(raw.as_ref(), Network::Mainnet.magic()).wait().unwrap(), Err(Error::InvalidChecksum));
}
}

View File

@ -38,7 +38,7 @@ mod tests {
#[test]
fn test_read_header() {
let raw: Bytes = "f9beb4d96164647200000000000000001f000000ed52399b".into();
let raw: Bytes = "24e927646164647200000000000000001f000000ed52399b".into();
let expected = MessageHeader {
magic: Network::Mainnet.magic(),
command: "addr".into(),
@ -58,7 +58,7 @@ mod tests {
#[test]
fn test_read_too_short_header() {
let raw: Bytes = "f9beb4d96164647200000000000000001f000000ed5239".into();
let raw: Bytes = "24e927646164647200000000000000001f000000ed5239".into();
assert!(read_header(raw.as_ref(), Network::Mainnet.magic()).wait().is_err());
}
}

View File

@ -77,7 +77,7 @@ mod tests {
#[test]
fn test_read_message() {
let raw: Bytes = "f9beb4d970696e6700000000000000000800000083c00c765845303b6da97786".into();
let raw: Bytes = "24e9276470696e6700000000000000000800000083c00c765845303b6da97786".into();
let ping = Ping::new(u64::from_str_radix("8677a96d3b304558", 16).unwrap());
assert_eq!(read_message(raw.as_ref(), Network::Mainnet.magic(), 0).wait().unwrap().1, Ok(ping));
assert_eq!(read_message::<Ping, _>(raw.as_ref(), Network::Testnet.magic(), 0).wait().unwrap().1, Err(Error::InvalidMagic));
@ -86,14 +86,14 @@ mod tests {
#[test]
fn test_read_too_short_message() {
let raw: Bytes = "f9beb4d970696e6700000000000000000800000083c00c765845303b6da977".into();
let raw: Bytes = "24e9276470696e6700000000000000000800000083c00c765845303b6da977".into();
assert!(read_message::<Ping, _>(raw.as_ref(), Network::Mainnet.magic(), 0).wait().is_err());
}
#[test]
fn test_read_message_with_invalid_checksum() {
let raw: Bytes = "f9beb4d970696e6700000000000000000800000083c01c765845303b6da97786".into();
let raw: Bytes = "24e9276470696e6700000000000000000800000083c01c765845303b6da97786".into();
assert_eq!(read_message::<Ping, _>(raw.as_ref(), Network::Mainnet.magic(), 0).wait().unwrap().1, Err(Error::InvalidChecksum));
}
}

View File

@ -1,4 +1,4 @@
use network::{ConsensusParams};
use network::{Network, ConsensusParams};
use storage::BlockHeaderProvider;
use canon::CanonHeader;
use error::Error;
@ -81,6 +81,11 @@ impl<'a> HeaderEquihashSolution<'a> {
}
fn check(&self) -> Result<(), Error> {
match self.consensus.network {
Network::Unitest => return Ok(()),
_ => (),
};
use equihash;
let is_solution_correct = equihash::verify_block_equihash_solution(&equihash::EquihashParams {
N: 200,

View File

@ -175,8 +175,8 @@ mod tests {
fn verify_smoky() {
let storage = Arc::new(BlockChainDatabase::init_test_chain(vec![test_data::genesis().into()]));
let b1 = test_data::block_h1();
let verifier = ChainVerifier::new(storage, ConsensusParams::new(Network::Unitest));
assert!(verifier.verify(VerificationLevel::Full, &b1.into()).is_ok());
let verifier = ChainVerifier::new(storage, ConsensusParams::new(Network::Mainnet));
assert_eq!(verifier.verify(VerificationLevel::Full, &b1.into()), Ok(()));
}
#[test]
@ -187,8 +187,8 @@ mod tests {
test_data::block_h1().into(),
]);
let b1 = test_data::block_h2();
let verifier = ChainVerifier::new(Arc::new(storage), ConsensusParams::new(Network::Unitest));
assert!(verifier.verify(VerificationLevel::Full, &b1.into()).is_ok());
let verifier = ChainVerifier::new(Arc::new(storage), ConsensusParams::new(Network::Mainnet));
assert_eq!(verifier.verify(VerificationLevel::Full, &b1.into()), Ok(()));
}
#[test]
@ -255,7 +255,7 @@ mod tests {
.build();
let verifier = ChainVerifier::new(Arc::new(storage), ConsensusParams::new(Network::Unitest));
assert!(verifier.verify(VerificationLevel::Full, &block.into()).is_ok());
assert_eq!(verifier.verify(VerificationLevel::Full, &block.into()), Ok(()));
}
#[test]

View File

@ -243,7 +243,10 @@ fn to_big_endian(num: u32) -> [u8; 4] {
#[cfg(test)]
mod tests {
/*
use primitives::bigint::{U256, Uint};
use byteorder::WriteBytesExt;
use super::*;
fn get_minimal_from_indices(indices: &[u32], collision_bit_length: usize) -> Vec<u8> {
let indices_len = indices.len() * 4;
let min_len = (collision_bit_length + 1) * indices_len / (8 * 4);
@ -313,5 +316,5 @@ mod tests {
2261, 15185, 36112, 104243, 23779, 118390, 118332, 130041, 32642, 69878, 76925, 80080, 45858, 116805, 92842, 111026, 15972, 115059, 85191, 90330, 68190, 122819, 81830, 91132, 23460, 49807, 52426, 80391, 69567, 114474, 104973, 122568,
],
));
}*/
}
}