Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Fix compiler errors from callsites in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nipunn1313 committed Aug 27, 2016
1 parent 8678e5e commit 69aa867
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 84 deletions.
6 changes: 3 additions & 3 deletions ethcore/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,9 +623,9 @@ mod tests {
let last_hashes = Arc::new(vec![genesis_header.hash()]);
let mut open_block = OpenBlock::new(engine, Default::default(), false, db, &genesis_header, last_hashes.clone(), Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap();
let mut uncle1_header = Header::new();
uncle1_header.extra_data = b"uncle1".to_vec();
uncle1_header.set_extra_data(b"uncle1".to_vec());
let mut uncle2_header = Header::new();
uncle2_header.extra_data = b"uncle2".to_vec();
uncle2_header.set_extra_data(b"uncle2".to_vec());
open_block.push_uncle(uncle1_header).unwrap();
open_block.push_uncle(uncle2_header).unwrap();
let b = open_block.close_and_lock().seal(engine, vec![]).unwrap();
Expand All @@ -641,7 +641,7 @@ mod tests {
let bytes = e.rlp_bytes();
assert_eq!(bytes, orig_bytes);
let uncles = BlockView::new(&bytes).uncles();
assert_eq!(uncles[1].extra_data, b"uncle2");
assert_eq!(uncles[1].extra_data(), b"uncle2");

let db = e.drain();
assert_eq!(orig_db.keys(), db.keys());
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/blockchain/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ mod tests {
let mut block_header = bc.block_header(&best_hash);

while !block_header.is_none() {
block_header = bc.block_header(&block_header.unwrap().parent_hash);
block_header = bc.block_header(&block_header.unwrap().parent_hash());
}
assert!(bc.cache_size().blocks > 1024 * 1024);

Expand Down
7 changes: 4 additions & 3 deletions ethcore/src/blockchain/generator/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,22 @@ impl Encodable for Block {

impl Forkable for Block {
fn fork(mut self, fork_number: usize) -> Self where Self: Sized {
self.header.difficulty = self.header.difficulty - U256::from(fork_number);
let difficulty = self.header.difficulty().clone() - U256::from(fork_number);
self.header.set_difficulty(difficulty);
self
}
}

impl WithBloom for Block {
fn with_bloom(mut self, bloom: H2048) -> Self where Self: Sized {
self.header.log_bloom = bloom;
self.header.set_log_bloom(bloom);
self
}
}

impl CompleteBlock for Block {
fn complete(mut self, parent_hash: H256) -> Bytes {
self.header.parent_hash = parent_hash;
self.header.set_parent_hash(parent_hash);
encode(&self).to_vec()
}
}
4 changes: 2 additions & 2 deletions ethcore/src/blockchain/generator/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ pub struct ChainGenerator {
impl ChainGenerator {
fn prepare_block(&self) -> Block {
let mut block = Block::default();
block.header.number = self.number;
block.header.difficulty = self.difficulty;
block.header.set_number(self.number);
block.header.set_difficulty(self.difficulty);
block
}
}
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/ethereum/ethash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ mod tests {
let mut b = OpenBlock::new(engine, Default::default(), false, db, &genesis_header, last_hashes, Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap();
let mut uncle = Header::new();
let uncle_author: Address = "ef2d6d194084c2de36e0dabfce45d046b37d1106".into();
uncle.author = uncle_author.clone();
uncle.set_author(uncle_author);
b.push_uncle(uncle).unwrap();

let b = b.close();
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/ethereum/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ mod tests {
let mut db_result = get_temp_journal_db();
let mut db = db_result.take();
spec.ensure_db_good(db.as_hashdb_mut()).unwrap();
let s = State::from_existing(db, genesis_header.state_root.clone(), engine.account_start_nonce(), Default::default()).unwrap();
let s = State::from_existing(db, genesis_header.state_root().clone(), engine.account_start_nonce(), Default::default()).unwrap();
assert_eq!(s.balance(&"0000000000000000000000000000000000000001".into()), 1u64.into());
assert_eq!(s.balance(&"0000000000000000000000000000000000000002".into()), 1u64.into());
assert_eq!(s.balance(&"0000000000000000000000000000000000000003".into()), 1u64.into());
Expand Down
2 changes: 2 additions & 0 deletions ethcore/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ impl Header {

/// Get the extra data field of the header.
pub fn extra_data(&self) -> &Bytes { &self.extra_data }
/// Get a mutable reference to extra_data
pub fn extra_data_mut(&mut self) -> &mut Bytes { self.note_dirty(); &mut self.extra_data }

/// Get the state root field of the header.
pub fn state_root(&self) -> &H256 { &self.state_root }
Expand Down
4 changes: 2 additions & 2 deletions ethcore/src/tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ fn returns_state_root_basic() {
let client_result = generate_dummy_client(6);
let client = client_result.reference();
let test_spec = get_test_spec();
let state_root = test_spec.genesis_header().state_root;
let genesis_header = test_spec.genesis_header();

assert!(client.state_data(&state_root).is_some());
assert!(client.state_data(genesis_header.state_root()).is_some());
}

#[test]
Expand Down
66 changes: 33 additions & 33 deletions ethcore/src/tests/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,26 @@ pub fn create_test_block(header: &Header) -> Bytes {

fn create_unverifiable_block_header(order: u32, parent_hash: H256) -> Header {
let mut header = Header::new();
header.gas_limit = 0.into();
header.difficulty = (order * 100).into();
header.timestamp = (order * 10) as u64;
header.number = order as u64;
header.parent_hash = parent_hash;
header.state_root = H256::zero();
header.set_gas_limit(0.into());
header.set_difficulty((order * 100).into());
header.set_timestamp((order * 10) as u64);
header.set_number(order as u64);
header.set_parent_hash(parent_hash);
header.set_state_root(H256::zero());

header
}

fn create_unverifiable_block_with_extra(order: u32, parent_hash: H256, extra: Option<Bytes>) -> Bytes {
let mut header = create_unverifiable_block_header(order, parent_hash);
header.extra_data = match extra {
header.set_extra_data(match extra {
Some(extra_data) => extra_data,
None => {
let base = (order & 0x000000ff) as u8;
let generated: Vec<u8> = vec![base + 1, base + 2, base + 3];
generated
}
};
});
create_test_block(&header)
}

Expand Down Expand Up @@ -204,20 +204,20 @@ pub fn push_blocks_to_client(client: &Arc<Client>, timestamp_salt: u64, starting
let test_spec = get_test_spec();
let test_engine = &test_spec.engine;
//let test_engine = test_spec.to_engine().unwrap();
let state_root = test_spec.genesis_header().state_root;
let state_root = test_spec.genesis_header().state_root().clone();
let mut rolling_hash = client.chain_info().best_block_hash;
let mut rolling_block_number = starting_number as u64;
let mut rolling_timestamp = timestamp_salt + starting_number as u64 * 10;

for _ in 0..block_number {
let mut header = Header::new();

header.gas_limit = test_engine.params().min_gas_limit;
header.difficulty = U256::from(0x20000);
header.timestamp = rolling_timestamp;
header.number = rolling_block_number;
header.parent_hash = rolling_hash;
header.state_root = state_root.clone();
header.set_gas_limit(test_engine.params().min_gas_limit);
header.set_difficulty(U256::from(0x20000));
header.set_timestamp(rolling_timestamp);
header.set_number(rolling_block_number);
header.set_parent_hash(rolling_hash);
header.set_state_root(state_root);

rolling_hash = header.hash();
rolling_block_number = rolling_block_number + 1;
Expand Down Expand Up @@ -345,12 +345,12 @@ pub fn get_good_dummy_block_fork_seq(start_number: usize, count: usize, parent_h
let mut r = Vec::new();
for i in start_number .. start_number + count + 1 {
let mut block_header = Header::new();
block_header.gas_limit = test_engine.params().min_gas_limit;
block_header.difficulty = U256::from(i).mul(U256([0, 1, 0, 0]));
block_header.timestamp = rolling_timestamp;
block_header.number = i as u64;
block_header.parent_hash = parent;
block_header.state_root = test_spec.genesis_header().state_root;
block_header.set_gas_limit(test_engine.params().min_gas_limit);
block_header.set_difficulty(U256::from(i).mul(U256([0, 1, 0, 0])));
block_header.set_timestamp(rolling_timestamp);
block_header.set_number(i as u64);
block_header.set_parent_hash(parent);
block_header.set_state_root(test_spec.genesis_header().state_root().clone());

parent = block_header.hash();
rolling_timestamp = rolling_timestamp + 10;
Expand All @@ -365,12 +365,12 @@ pub fn get_good_dummy_block() -> Bytes {
let mut block_header = Header::new();
let test_spec = get_test_spec();
let test_engine = &test_spec.engine;
block_header.gas_limit = test_engine.params().min_gas_limit;
block_header.difficulty = U256::from(0x20000);
block_header.timestamp = 40;
block_header.number = 1;
block_header.parent_hash = test_spec.genesis_header().hash();
block_header.state_root = test_spec.genesis_header().state_root;
block_header.set_gas_limit(test_engine.params().min_gas_limit);
block_header.set_difficulty(U256::from(0x20000));
block_header.set_timestamp(40);
block_header.set_number(1);
block_header.set_parent_hash(test_spec.genesis_header().hash());
block_header.set_state_root(test_spec.genesis_header().state_root().clone());

create_test_block(&block_header)
}
Expand All @@ -379,12 +379,12 @@ pub fn get_bad_state_dummy_block() -> Bytes {
let mut block_header = Header::new();
let test_spec = get_test_spec();
let test_engine = &test_spec.engine;
block_header.gas_limit = test_engine.params().min_gas_limit;
block_header.difficulty = U256::from(0x20000);
block_header.timestamp = 40;
block_header.number = 1;
block_header.parent_hash = test_spec.genesis_header().hash();
block_header.state_root = 0xbad.into();
block_header.set_gas_limit(test_engine.params().min_gas_limit);
block_header.set_difficulty(U256::from(0x20000));
block_header.set_timestamp(40);
block_header.set_number(1);
block_header.set_parent_hash(test_spec.genesis_header().hash());
block_header.set_state_root(0xbad.into());

create_test_block(&block_header)
}
77 changes: 39 additions & 38 deletions ethcore/src/verification/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ mod tests {
let header = BlockView::new(bytes).header();
BlockDetails {
number: header.number(),
total_difficulty: header.difficulty(),
parent: header.parent_hash(),
total_difficulty: header.difficulty().clone(),
parent: header.parent_hash().clone(),
children: Vec::new(),
}
})
Expand Down Expand Up @@ -352,9 +352,9 @@ mod tests {
let engine = &*spec.engine;

let min_gas_limit = engine.params().min_gas_limit;
good.gas_limit = min_gas_limit;
good.timestamp = 40;
good.number = 10;
good.set_gas_limit(min_gas_limit);
good.set_timestamp(40);
good.set_number(10);

let keypair = Random.generate().unwrap();

Expand All @@ -381,31 +381,31 @@ mod tests {
let diff_inc = U256::from(0x40);

let mut parent6 = good.clone();
parent6.number = 6;
parent6.set_number(6);
let mut parent7 = good.clone();
parent7.number = 7;
parent7.parent_hash = parent6.hash();
parent7.difficulty = parent6.difficulty + diff_inc;
parent7.timestamp = parent6.timestamp + 10;
parent7.set_number(7);
parent7.set_parent_hash(parent6.hash());
parent7.set_difficulty(parent6.difficulty().clone() + diff_inc);
parent7.set_timestamp(parent6.timestamp() + 10);
let mut parent8 = good.clone();
parent8.number = 8;
parent8.parent_hash = parent7.hash();
parent8.difficulty = parent7.difficulty + diff_inc;
parent8.timestamp = parent7.timestamp + 10;
parent8.set_number(8);
parent8.set_parent_hash(parent7.hash());
parent8.set_difficulty(parent7.difficulty().clone() + diff_inc);
parent8.set_timestamp(parent7.timestamp() + 10);

let mut good_uncle1 = good.clone();
good_uncle1.number = 9;
good_uncle1.parent_hash = parent8.hash();
good_uncle1.difficulty = parent8.difficulty + diff_inc;
good_uncle1.timestamp = parent8.timestamp + 10;
good_uncle1.extra_data.push(1u8);
good_uncle1.set_number(9);
good_uncle1.set_parent_hash(parent8.hash());
good_uncle1.set_difficulty(parent8.difficulty().clone() + diff_inc);
good_uncle1.set_timestamp(parent8.timestamp() + 10);
good_uncle1.extra_data_mut().push(1u8);

let mut good_uncle2 = good.clone();
good_uncle2.number = 8;
good_uncle2.parent_hash = parent7.hash();
good_uncle2.difficulty = parent7.difficulty + diff_inc;
good_uncle2.timestamp = parent7.timestamp + 10;
good_uncle2.extra_data.push(2u8);
good_uncle2.set_number(8);
good_uncle2.set_parent_hash(parent7.hash());
good_uncle2.set_difficulty(parent7.difficulty().clone() + diff_inc);
good_uncle2.set_timestamp(parent7.timestamp() + 10);
good_uncle2.extra_data_mut().push(2u8);

let good_uncles = vec![ good_uncle1.clone(), good_uncle2.clone() ];
let mut uncles_rlp = RlpStream::new();
Expand All @@ -415,13 +415,13 @@ mod tests {

let mut parent = good.clone();
parent.set_number(9);
parent.set_timestamp(parent8.timestamp + 10);
parent.set_timestamp(parent8.timestamp() + 10);
parent.set_parent_hash(parent8.hash());
parent.set_difficulty(parent8.difficulty + diff_inc);
parent.set_difficulty(parent8.difficulty().clone() + diff_inc);

good.parent_hash = parent.hash();
good.difficulty = parent.difficulty() + diff_inc;
good.timestamp = parent.timestamp() + 10;
good.set_parent_hash(parent.hash());
good.set_difficulty(parent.difficulty().clone() + diff_inc);
good.set_timestamp(parent.timestamp() + 10);

let mut bc = TestBlockChain::new();
bc.insert(create_test_block(&good));
Expand All @@ -439,45 +439,46 @@ mod tests {

header.set_gas_limit(min_gas_limit - From::from(1));
check_fail(basic_test(&create_test_block(&header), engine),
InvalidGasLimit(OutOfBounds { min: Some(min_gas_limit), max: None, found: header.gas_limit() }));
InvalidGasLimit(OutOfBounds { min: Some(min_gas_limit), max: None, found: header.gas_limit().clone() }));

header = good.clone();
header.set_number(BlockNumber::max_value());
check_fail(basic_test(&create_test_block(&header), engine),
RidiculousNumber(OutOfBounds { max: Some(BlockNumber::max_value()), min: None, found: header.number() }));

header = good.clone();
header.set_gas_used(header.gas_limit() + From::from(1));
let gas_used = header.gas_limit().clone() + 1.into();
header.set_gas_used(gas_used);
check_fail(basic_test(&create_test_block(&header), engine),
TooMuchGasUsed(OutOfBounds { max: Some(header.gas_limit()), min: None, found: header.gas_used() }));
TooMuchGasUsed(OutOfBounds { max: Some(header.gas_limit().clone()), min: None, found: header.gas_used().clone() }));

header = good.clone();
header.extra_data().resize(engine.maximum_extra_data_size() + 1, 0u8);
header.extra_data_mut().resize(engine.maximum_extra_data_size() + 1, 0u8);
check_fail(basic_test(&create_test_block(&header), engine),
ExtraDataOutOfBounds(OutOfBounds { max: Some(engine.maximum_extra_data_size()), min: None, found: header.extra_data().len() }));

header = good.clone();
header.extra_data().resize(engine.maximum_extra_data_size() + 1, 0u8);
header.extra_data_mut().resize(engine.maximum_extra_data_size() + 1, 0u8);
check_fail(basic_test(&create_test_block(&header), engine),
ExtraDataOutOfBounds(OutOfBounds { max: Some(engine.maximum_extra_data_size()), min: None, found: header.extra_data().len() }));

header = good.clone();
header.uncles_hash = good_uncles_hash.clone();
header.set_uncles_hash(good_uncles_hash.clone());
check_fail(basic_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine),
InvalidTransactionsRoot(Mismatch { expected: good_transactions_root.clone(), found: header.transactions_root() }));
InvalidTransactionsRoot(Mismatch { expected: good_transactions_root.clone(), found: header.transactions_root().clone() }));

header = good.clone();
header.set_transactions_root(good_transactions_root.clone());
check_fail(basic_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine),
InvalidUnclesHash(Mismatch { expected: good_uncles_hash.clone(), found: header.uncles_hash() }));
InvalidUnclesHash(Mismatch { expected: good_uncles_hash.clone(), found: header.uncles_hash().clone() }));

check_ok(family_test(&create_test_block(&good), engine, &bc));
check_ok(family_test(&create_test_block_with_data(&good, &good_transactions, &good_uncles), engine, &bc));

header = good.clone();
header.set_parent_hash(H256::random());
check_fail(family_test(&create_test_block_with_data(&header, &good_transactions, &good_uncles), engine, &bc),
UnknownParent(header.parent_hash()));
UnknownParent(header.parent_hash().clone()));

header = good.clone();
header.set_timestamp(10);
Expand Down

0 comments on commit 69aa867

Please sign in to comment.