2019-01-07 11:33:07 +01:00
|
|
|
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
|
|
|
|
// This file is part of Parity Ethereum.
|
2019-01-04 14:05:46 +01:00
|
|
|
|
2019-01-07 11:33:07 +01:00
|
|
|
// Parity Ethereum is free software: you can redistribute it and/or modify
|
2019-01-04 14:05:46 +01:00
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
2019-01-07 11:33:07 +01:00
|
|
|
// Parity Ethereum is distributed in the hope that it will be useful,
|
2019-01-04 14:05:46 +01:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
2019-01-07 11:33:07 +01:00
|
|
|
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
2019-01-04 14:05:46 +01:00
|
|
|
|
|
|
|
use blockchain::BlockProvider;
|
|
|
|
|
|
|
|
use test_helpers::{
|
|
|
|
generate_dummy_blockchain,
|
|
|
|
generate_dummy_blockchain_with_extra,
|
|
|
|
generate_dummy_empty_blockchain,
|
|
|
|
};
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn can_contain_arbitrary_block_sequence() {
|
|
|
|
let bc = generate_dummy_blockchain(50);
|
|
|
|
assert_eq!(bc.best_block_number(), 49);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn can_collect_garbage() {
|
|
|
|
let bc = generate_dummy_blockchain(3000);
|
|
|
|
|
|
|
|
assert_eq!(bc.best_block_number(), 2999);
|
|
|
|
let best_hash = bc.best_block_hash();
|
|
|
|
let mut block_header = bc.block_header_data(&best_hash);
|
|
|
|
|
|
|
|
while !block_header.is_none() {
|
|
|
|
block_header = bc.block_header_data(&block_header.unwrap().parent_hash());
|
|
|
|
}
|
|
|
|
assert!(bc.cache_size().blocks > 1024 * 1024);
|
|
|
|
|
|
|
|
for _ in 0..2 {
|
|
|
|
bc.collect_garbage();
|
|
|
|
}
|
|
|
|
assert!(bc.cache_size().blocks < 1024 * 1024);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn can_contain_arbitrary_block_sequence_with_extra() {
|
|
|
|
let bc = generate_dummy_blockchain_with_extra(25);
|
|
|
|
assert_eq!(bc.best_block_number(), 24);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn can_contain_only_genesis_block() {
|
|
|
|
let bc = generate_dummy_empty_blockchain();
|
|
|
|
assert_eq!(bc.best_block_number(), 0);
|
|
|
|
}
|