From 69aa8675c7ec83886aa18c5616c3a41cf1d417f8 Mon Sep 17 00:00:00 2001 From: Nipunn Koorapati Date: Sat, 27 Aug 2016 13:06:03 -0700 Subject: [PATCH] Fix compiler errors from callsites in tests --- ethcore/src/block.rs | 6 +- ethcore/src/blockchain/blockchain.rs | 2 +- ethcore/src/blockchain/generator/block.rs | 7 +- ethcore/src/blockchain/generator/generator.rs | 4 +- ethcore/src/ethereum/ethash.rs | 2 +- ethcore/src/ethereum/mod.rs | 2 +- ethcore/src/header.rs | 2 + ethcore/src/tests/client.rs | 4 +- ethcore/src/tests/helpers.rs | 66 ++++++++-------- ethcore/src/verification/verification.rs | 77 ++++++++++--------- 10 files changed, 88 insertions(+), 84 deletions(-) diff --git a/ethcore/src/block.rs b/ethcore/src/block.rs index 2a78ec686c8..784e71dc0da 100644 --- a/ethcore/src/block.rs +++ b/ethcore/src/block.rs @@ -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(); @@ -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()); diff --git a/ethcore/src/blockchain/blockchain.rs b/ethcore/src/blockchain/blockchain.rs index 379d7740781..a581e59e9ad 100644 --- a/ethcore/src/blockchain/blockchain.rs +++ b/ethcore/src/blockchain/blockchain.rs @@ -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); diff --git a/ethcore/src/blockchain/generator/block.rs b/ethcore/src/blockchain/generator/block.rs index 0a3dad3996a..238051d2a82 100644 --- a/ethcore/src/blockchain/generator/block.rs +++ b/ethcore/src/blockchain/generator/block.rs @@ -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() } } diff --git a/ethcore/src/blockchain/generator/generator.rs b/ethcore/src/blockchain/generator/generator.rs index 07ce7242bca..179839b5ac0 100644 --- a/ethcore/src/blockchain/generator/generator.rs +++ b/ethcore/src/blockchain/generator/generator.rs @@ -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 } } diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index 99c76291dc6..82a74d9ea02 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -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(); diff --git a/ethcore/src/ethereum/mod.rs b/ethcore/src/ethereum/mod.rs index 40e85d61953..1efe001e54a 100644 --- a/ethcore/src/ethereum/mod.rs +++ b/ethcore/src/ethereum/mod.rs @@ -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()); diff --git a/ethcore/src/header.rs b/ethcore/src/header.rs index 729e99da431..9b0e155f4f8 100644 --- a/ethcore/src/header.rs +++ b/ethcore/src/header.rs @@ -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 } diff --git a/ethcore/src/tests/client.rs b/ethcore/src/tests/client.rs index 1ac26c83b07..26256a760ec 100644 --- a/ethcore/src/tests/client.rs +++ b/ethcore/src/tests/client.rs @@ -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] diff --git a/ethcore/src/tests/helpers.rs b/ethcore/src/tests/helpers.rs index 4942ace5a63..f3975a0d0ec 100644 --- a/ethcore/src/tests/helpers.rs +++ b/ethcore/src/tests/helpers.rs @@ -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 { 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 = vec![base + 1, base + 2, base + 3]; generated } - }; + }); create_test_block(&header) } @@ -204,7 +204,7 @@ pub fn push_blocks_to_client(client: &Arc, 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; @@ -212,12 +212,12 @@ pub fn push_blocks_to_client(client: &Arc, timestamp_salt: u64, starting 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; @@ -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; @@ -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) } @@ -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) } diff --git a/ethcore/src/verification/verification.rs b/ethcore/src/verification/verification.rs index bd6ddb7bf93..aa719cf236e 100644 --- a/ethcore/src/verification/verification.rs +++ b/ethcore/src/verification/verification.rs @@ -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(), } }) @@ -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(); @@ -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(); @@ -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)); @@ -439,7 +439,7 @@ 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()); @@ -447,29 +447,30 @@ mod tests { 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)); @@ -477,7 +478,7 @@ mod tests { 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);