Merge pull request #382 from ethcore/coverage-effort
Coverage effort [in progress]
This commit is contained in:
commit
46d3fe3070
@ -23,8 +23,6 @@ use spec::*;
|
|||||||
use engine::*;
|
use engine::*;
|
||||||
use evm::Schedule;
|
use evm::Schedule;
|
||||||
use evm::Factory;
|
use evm::Factory;
|
||||||
#[cfg(test)]
|
|
||||||
use tests::helpers::*;
|
|
||||||
|
|
||||||
/// Engine using Ethash proof-of-work consensus algorithm, suitable for Ethereum
|
/// Engine using Ethash proof-of-work consensus algorithm, suitable for Ethereum
|
||||||
/// mainnet chains in the Olympic, Frontier and Homestead eras.
|
/// mainnet chains in the Olympic, Frontier and Homestead eras.
|
||||||
@ -49,6 +47,17 @@ impl Ethash {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
fn new_test(spec: Spec) -> Ethash {
|
||||||
|
Ethash {
|
||||||
|
spec: spec,
|
||||||
|
pow: EthashManager::new(),
|
||||||
|
factory: Factory::default(),
|
||||||
|
u64_params: RwLock::new(HashMap::new()),
|
||||||
|
u256_params: RwLock::new(HashMap::new())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn u64_param(&self, name: &str) -> u64 {
|
fn u64_param(&self, name: &str) -> u64 {
|
||||||
*self.u64_params.write().unwrap().entry(name.to_owned()).or_insert_with(||
|
*self.u64_params.write().unwrap().entry(name.to_owned()).or_insert_with(||
|
||||||
self.spec().engine_params.get(name).map_or(0u64, |a| decode(&a)))
|
self.spec().engine_params.get(name).map_or(0u64, |a| decode(&a)))
|
||||||
@ -123,6 +132,11 @@ impl Engine for Ethash {
|
|||||||
|
|
||||||
fn verify_block_basic(&self, header: &Header, _block: Option<&[u8]>) -> result::Result<(), Error> {
|
fn verify_block_basic(&self, header: &Header, _block: Option<&[u8]>) -> result::Result<(), Error> {
|
||||||
// check the seal fields.
|
// check the seal fields.
|
||||||
|
if header.seal.len() != self.seal_fields() {
|
||||||
|
return Err(From::from(BlockError::InvalidSealArity(
|
||||||
|
Mismatch { expected: self.seal_fields(), found: header.seal.len() }
|
||||||
|
)));
|
||||||
|
}
|
||||||
try!(UntrustedRlp::new(&header.seal[0]).as_val::<H256>());
|
try!(UntrustedRlp::new(&header.seal[0]).as_val::<H256>());
|
||||||
try!(UntrustedRlp::new(&header.seal[1]).as_val::<H64>());
|
try!(UntrustedRlp::new(&header.seal[1]).as_val::<H64>());
|
||||||
|
|
||||||
@ -143,6 +157,11 @@ impl Engine for Ethash {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn verify_block_unordered(&self, header: &Header, _block: Option<&[u8]>) -> result::Result<(), Error> {
|
fn verify_block_unordered(&self, header: &Header, _block: Option<&[u8]>) -> result::Result<(), Error> {
|
||||||
|
if header.seal.len() != self.seal_fields() {
|
||||||
|
return Err(From::from(BlockError::InvalidSealArity(
|
||||||
|
Mismatch { expected: self.seal_fields(), found: header.seal.len() }
|
||||||
|
)));
|
||||||
|
}
|
||||||
let result = self.pow.compute_light(header.number as u64, &Ethash::to_ethash(header.bare_hash()), header.nonce().low_u64());
|
let result = self.pow.compute_light(header.number as u64, &Ethash::to_ethash(header.bare_hash()), header.nonce().low_u64());
|
||||||
let mix = Ethash::from_ethash(result.mix_hash);
|
let mix = Ethash::from_ethash(result.mix_hash);
|
||||||
let difficulty = Ethash::boundary_to_difficulty(&Ethash::from_ethash(result.value));
|
let difficulty = Ethash::boundary_to_difficulty(&Ethash::from_ethash(result.value));
|
||||||
@ -242,9 +261,19 @@ impl Header {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[cfg(test)]
|
||||||
fn on_close_block() {
|
mod tests {
|
||||||
|
extern crate ethash;
|
||||||
|
|
||||||
|
use common::*;
|
||||||
|
use block::*;
|
||||||
|
use engine::*;
|
||||||
|
use tests::helpers::*;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use super::super::new_morden;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn on_close_block() {
|
||||||
let engine = new_morden().to_engine().unwrap();
|
let engine = new_morden().to_engine().unwrap();
|
||||||
let genesis_header = engine.spec().genesis_header();
|
let genesis_header = engine.spec().genesis_header();
|
||||||
let mut db_result = get_temp_journal_db();
|
let mut db_result = get_temp_journal_db();
|
||||||
@ -254,11 +283,10 @@ fn on_close_block() {
|
|||||||
let b = OpenBlock::new(engine.deref(), db, &genesis_header, &last_hashes, Address::zero(), vec![]);
|
let b = OpenBlock::new(engine.deref(), db, &genesis_header, &last_hashes, Address::zero(), vec![]);
|
||||||
let b = b.close();
|
let b = b.close();
|
||||||
assert_eq!(b.state().balance(&Address::zero()), U256::from_str("4563918244f40000").unwrap());
|
assert_eq!(b.state().balance(&Address::zero()), U256::from_str("4563918244f40000").unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn on_close_block_with_uncle() {
|
fn on_close_block_with_uncle() {
|
||||||
use super::*;
|
|
||||||
let engine = new_morden().to_engine().unwrap();
|
let engine = new_morden().to_engine().unwrap();
|
||||||
let genesis_header = engine.spec().genesis_header();
|
let genesis_header = engine.spec().genesis_header();
|
||||||
let mut db_result = get_temp_journal_db();
|
let mut db_result = get_temp_journal_db();
|
||||||
@ -274,6 +302,146 @@ fn on_close_block_with_uncle() {
|
|||||||
let b = b.close();
|
let b = b.close();
|
||||||
assert_eq!(b.state().balance(&Address::zero()), U256::from_str("478eae0e571ba000").unwrap());
|
assert_eq!(b.state().balance(&Address::zero()), U256::from_str("478eae0e571ba000").unwrap());
|
||||||
assert_eq!(b.state().balance(&uncle_author), U256::from_str("3cb71f51fc558000").unwrap());
|
assert_eq!(b.state().balance(&uncle_author), U256::from_str("3cb71f51fc558000").unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn has_valid_metadata() {
|
||||||
|
let engine = Ethash::new_boxed(new_morden());
|
||||||
|
assert!(!engine.name().is_empty());
|
||||||
|
assert!(engine.version().major >= 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn can_return_params() {
|
||||||
|
let engine = Ethash::new_test(new_morden());
|
||||||
|
assert!(engine.u64_param("durationLimit") > 0);
|
||||||
|
assert!(engine.u256_param("minimumDifficulty") > U256::zero());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn can_return_factory() {
|
||||||
|
let engine = Ethash::new_test(new_morden());
|
||||||
|
engine.vm_factory();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn can_return_schedule() {
|
||||||
|
let engine = Ethash::new_test(new_morden());
|
||||||
|
let schedule = engine.schedule(&EnvInfo {
|
||||||
|
number: 10000000,
|
||||||
|
author: x!(0),
|
||||||
|
timestamp: 0,
|
||||||
|
difficulty: x!(0),
|
||||||
|
last_hashes: vec![],
|
||||||
|
gas_used: x!(0),
|
||||||
|
gas_limit: x!(0)
|
||||||
|
});
|
||||||
|
|
||||||
|
assert!(schedule.stack_limit > 0);
|
||||||
|
|
||||||
|
let schedule = engine.schedule(&EnvInfo {
|
||||||
|
number: 100,
|
||||||
|
author: x!(0),
|
||||||
|
timestamp: 0,
|
||||||
|
difficulty: x!(0),
|
||||||
|
last_hashes: vec![],
|
||||||
|
gas_used: x!(0),
|
||||||
|
gas_limit: x!(0)
|
||||||
|
});
|
||||||
|
|
||||||
|
assert!(!schedule.have_delegate_call);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn can_do_seal_verification_fail() {
|
||||||
|
let engine = Ethash::new_test(new_morden());
|
||||||
|
let header: Header = Header::default();
|
||||||
|
|
||||||
|
let verify_result = engine.verify_block_basic(&header, None);
|
||||||
|
|
||||||
|
match verify_result {
|
||||||
|
Err(Error::Block(BlockError::InvalidSealArity(_))) => {},
|
||||||
|
Err(_) => { panic!("should be block seal-arity mismatch error (got {:?})", verify_result); },
|
||||||
|
_ => { panic!("Should be error, got Ok"); },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn can_do_difficulty_verification_fail() {
|
||||||
|
let engine = Ethash::new_test(new_morden());
|
||||||
|
let mut header: Header = Header::default();
|
||||||
|
header.set_seal(vec![rlp::encode(&H256::zero()).to_vec(), rlp::encode(&H64::zero()).to_vec()]);
|
||||||
|
|
||||||
|
let verify_result = engine.verify_block_basic(&header, None);
|
||||||
|
|
||||||
|
match verify_result {
|
||||||
|
Err(Error::Block(BlockError::DifficultyOutOfBounds(_))) => {},
|
||||||
|
Err(_) => { panic!("should be block difficulty error (got {:?})", verify_result); },
|
||||||
|
_ => { panic!("Should be error, got Ok"); },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn can_do_proof_of_work_verification_fail() {
|
||||||
|
let engine = Ethash::new_test(new_morden());
|
||||||
|
let mut header: Header = Header::default();
|
||||||
|
header.set_seal(vec![rlp::encode(&H256::zero()).to_vec(), rlp::encode(&H64::zero()).to_vec()]);
|
||||||
|
header.set_difficulty(U256::from_str("ffffffffffffffffffffffffffffffffffffffffffffaaaaaaaaaaaaaaaaaaaa").unwrap());
|
||||||
|
|
||||||
|
let verify_result = engine.verify_block_basic(&header, None);
|
||||||
|
|
||||||
|
match verify_result {
|
||||||
|
Err(Error::Block(BlockError::InvalidProofOfWork(_))) => {},
|
||||||
|
Err(_) => { panic!("should be invalid proof of work error (got {:?})", verify_result); },
|
||||||
|
_ => { panic!("Should be error, got Ok"); },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn can_do_seal_unordered_verification_fail() {
|
||||||
|
let engine = Ethash::new_test(new_morden());
|
||||||
|
let header: Header = Header::default();
|
||||||
|
|
||||||
|
let verify_result = engine.verify_block_unordered(&header, None);
|
||||||
|
|
||||||
|
match verify_result {
|
||||||
|
Err(Error::Block(BlockError::InvalidSealArity(_))) => {},
|
||||||
|
Err(_) => { panic!("should be block seal-arity mismatch error (got {:?})", verify_result); },
|
||||||
|
_ => { panic!("Should be error, got Ok"); },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn can_do_seal256_verification_fail() {
|
||||||
|
let engine = Ethash::new_test(new_morden());
|
||||||
|
let mut header: Header = Header::default();
|
||||||
|
header.set_seal(vec![rlp::encode(&H256::zero()).to_vec(), rlp::encode(&H64::zero()).to_vec()]);
|
||||||
|
let verify_result = engine.verify_block_unordered(&header, None);
|
||||||
|
|
||||||
|
match verify_result {
|
||||||
|
Err(Error::Block(BlockError::MismatchedH256SealElement(_))) => {},
|
||||||
|
Err(_) => { panic!("should be invalid 256-bit seal fail (got {:?})", verify_result); },
|
||||||
|
_ => { panic!("Should be error, got Ok"); },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn can_do_proof_of_work_unordered_verification_fail() {
|
||||||
|
let engine = Ethash::new_test(new_morden());
|
||||||
|
let mut header: Header = Header::default();
|
||||||
|
header.set_seal(vec![rlp::encode(&H256::from("b251bd2e0283d0658f2cadfdc8ca619b5de94eca5742725e2e757dd13ed7503d")).to_vec(), rlp::encode(&H64::zero()).to_vec()]);
|
||||||
|
header.set_difficulty(U256::from_str("ffffffffffffffffffffffffffffffffffffffffffffaaaaaaaaaaaaaaaaaaaa").unwrap());
|
||||||
|
|
||||||
|
let verify_result = engine.verify_block_unordered(&header, None);
|
||||||
|
|
||||||
|
match verify_result {
|
||||||
|
Err(Error::Block(BlockError::InvalidProofOfWork(_))) => {},
|
||||||
|
Err(_) => { panic!("should be invalid proof-of-work fail (got {:?})", verify_result); },
|
||||||
|
_ => { panic!("Should be error, got Ok"); },
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: difficulty test
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: difficulty test
|
|
||||||
|
@ -159,11 +159,13 @@ macro_rules! evm_test_ignore(
|
|||||||
#[test]
|
#[test]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
#[cfg(feature = "jit")]
|
#[cfg(feature = "jit")]
|
||||||
|
#[cfg(feature = "ignored-tests")]
|
||||||
fn $name_jit() {
|
fn $name_jit() {
|
||||||
$name_test(Factory::new(VMType::Jit));
|
$name_test(Factory::new(VMType::Jit));
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
|
#[cfg(feature = "ignored-tests")]
|
||||||
fn $name_int() {
|
fn $name_int() {
|
||||||
$name_test(Factory::new(VMType::Interpreter));
|
$name_test(Factory::new(VMType::Interpreter));
|
||||||
}
|
}
|
||||||
|
@ -360,6 +360,7 @@ impl<'a> Executive<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
#[allow(dead_code)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use common::*;
|
use common::*;
|
||||||
@ -599,6 +600,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// test is incorrect, mk
|
// test is incorrect, mk
|
||||||
|
// TODO: fix (preferred) or remove
|
||||||
evm_test_ignore!{test_aba_calls: test_aba_calls_jit, test_aba_calls_int}
|
evm_test_ignore!{test_aba_calls: test_aba_calls_jit, test_aba_calls_int}
|
||||||
fn test_aba_calls(factory: Factory) {
|
fn test_aba_calls(factory: Factory) {
|
||||||
// 60 00 - push 0
|
// 60 00 - push 0
|
||||||
@ -659,6 +661,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// test is incorrect, mk
|
// test is incorrect, mk
|
||||||
|
// TODO: fix (preferred) or remove
|
||||||
evm_test_ignore!{test_recursive_bomb1: test_recursive_bomb1_jit, test_recursive_bomb1_int}
|
evm_test_ignore!{test_recursive_bomb1: test_recursive_bomb1_jit, test_recursive_bomb1_int}
|
||||||
fn test_recursive_bomb1(factory: Factory) {
|
fn test_recursive_bomb1(factory: Factory) {
|
||||||
// 60 01 - push 1
|
// 60 01 - push 1
|
||||||
@ -704,6 +707,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// test is incorrect, mk
|
// test is incorrect, mk
|
||||||
|
// TODO: fix (preferred) or remove
|
||||||
evm_test_ignore!{test_transact_simple: test_transact_simple_jit, test_transact_simple_int}
|
evm_test_ignore!{test_transact_simple: test_transact_simple_jit, test_transact_simple_int}
|
||||||
fn test_transact_simple(factory: Factory) {
|
fn test_transact_simple(factory: Factory) {
|
||||||
let keypair = KeyPair::create().unwrap();
|
let keypair = KeyPair::create().unwrap();
|
||||||
@ -902,5 +906,4 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ mod test_common;
|
|||||||
mod transaction;
|
mod transaction;
|
||||||
mod executive;
|
mod executive;
|
||||||
mod state;
|
mod state;
|
||||||
mod client;
|
|
||||||
mod chain;
|
mod chain;
|
||||||
mod homestead_state;
|
mod homestead_state;
|
||||||
mod homestead_chain;
|
mod homestead_chain;
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use client::{BlockChainClient,Client};
|
use client::{BlockChainClient,Client};
|
||||||
use super::test_common::*;
|
|
||||||
use tests::helpers::*;
|
use tests::helpers::*;
|
||||||
|
use common::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn created() {
|
fn created() {
|
@ -14,7 +14,6 @@
|
|||||||
// 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/>.
|
||||||
|
|
||||||
#[cfg(feature = "json-tests")]
|
|
||||||
use client::{BlockChainClient, Client};
|
use client::{BlockChainClient, Client};
|
||||||
use std::env;
|
use std::env;
|
||||||
use common::*;
|
use common::*;
|
||||||
@ -134,7 +133,6 @@ pub fn create_test_block_with_data(header: &Header, transactions: &[&SignedTrans
|
|||||||
rlp.out()
|
rlp.out()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "json-tests")]
|
|
||||||
pub fn generate_dummy_client(block_number: u32) -> GuardedTempResult<Arc<Client>> {
|
pub fn generate_dummy_client(block_number: u32) -> GuardedTempResult<Arc<Client>> {
|
||||||
let dir = RandomTempPath::new();
|
let dir = RandomTempPath::new();
|
||||||
|
|
||||||
@ -174,7 +172,6 @@ pub fn generate_dummy_client(block_number: u32) -> GuardedTempResult<Arc<Client>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "json-tests")]
|
|
||||||
pub fn get_test_client_with_blocks(blocks: Vec<Bytes>) -> GuardedTempResult<Arc<Client>> {
|
pub fn get_test_client_with_blocks(blocks: Vec<Bytes>) -> GuardedTempResult<Arc<Client>> {
|
||||||
let dir = RandomTempPath::new();
|
let dir = RandomTempPath::new();
|
||||||
let client = Client::new(get_test_spec(), dir.as_path(), IoChannel::disconnected()).unwrap();
|
let client = Client::new(get_test_spec(), dir.as_path(), IoChannel::disconnected()).unwrap();
|
||||||
@ -271,7 +268,6 @@ pub fn get_good_dummy_block() -> Bytes {
|
|||||||
create_test_block(&block_header)
|
create_test_block(&block_header)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "json-tests")]
|
|
||||||
pub fn get_bad_state_dummy_block() -> Bytes {
|
pub fn get_bad_state_dummy_block() -> Bytes {
|
||||||
let mut block_header = Header::new();
|
let mut block_header = Header::new();
|
||||||
let test_spec = get_test_spec();
|
let test_spec = get_test_spec();
|
||||||
|
@ -15,3 +15,4 @@
|
|||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
pub mod helpers;
|
pub mod helpers;
|
||||||
|
mod client;
|
Loading…
Reference in New Issue
Block a user