You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: apply_chain_range.rs
    path of file: ./repos/nearcore/tools/state-viewer/src
    
    the code of the file until where you have to start completion: use near_chain::chain::collect_receipts_from_response;
use near_chain::migrations::check_if_block_is_first_with_chunk_of_version;
use near_chain::types::{
    ApplyChunkBlockContext, ApplyChunkResult, ApplyChunkShardContext, RuntimeAdapter,
    RuntimeStorageConfig,
};
use near_chain::{ChainStore, ChainStoreAccess, ChainStoreUpdate};
use near_chain_configs::Genesis;
use near_epoch_manager::{EpochManagerAdapter, EpochManagerHandle};
use near_primitives::receipt::DelayedReceiptIndices;
use near_primitives::transaction::{Action, ExecutionOutcomeWithId, ExecutionOutcomeWithProof};
use near_primitives::trie_key::TrieKey;
use near_primitives::types::chunk_extra::ChunkExtra;
use near_primitives::types::{BlockHeight, ShardId};
use near_store::{DBCol, Store};
use nearcore::NightshadeRuntime;
use rayon::iter::{IntoParallelIterator, ParallelIterator};
use std::fs::File;
use std::io::Write;
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::{Arc, Mutex};

fn timestamp_ms() -> u64 {
    use std::time::{SystemTime, UNIX_EPOCH};
    SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis() as u64
}
pub const TGAS: u64 = 1024 * 1024 * 1024 * 1024;

struct ProgressReporter {
    cnt: AtomicU64,
    // Timestamp to make relative measurements of block processing speed (in ms)
    ts: AtomicU64,
    all: u64,
    skipped: AtomicU64,
    // Fields below get cleared after each print.
    empty_blocks: AtomicU64,
    non_empty_blocks: AtomicU64,
    // Total gas burned (in TGas)
    tgas_burned: AtomicU64,
}

impl ProgressReporter {
    pub fn inc_and_report_progress(&self, gas_burnt: u64) {
        let ProgressReporter { cnt, ts, all, skipped, empty_blocks, non_empty_blocks, tgas_burned } =
            self;
        if gas_burnt == 0 {
            empty_blocks.fetch_add(1, Ordering::Relaxed);
        } else {
            non_empty_blocks.fetch_add(1, Ordering::Relaxed);
            tgas_bu
    
    fn test_apply_chain_range_no_chunks() {
        let epoch_length = 4;
        let (store, genesis, mut env) = setup(epoch_length);
        let genesis_hash = *env.clients[0].chain.genesis().hash();
        let signer = InMemorySigner::from_seed("test1".parse().unwrap(), KeyType::ED25519, "test1");
        let tx = SignedTransaction::stake(
            1,
            "test1".parse().unwrap(),
            &signer,
            TESTING_INIT_STAKE,
            signer.public_key.clone(),
            genesis_hash,
        );
        assert_eq!(env.clients[0].process_tx(tx, false, false), ProcessTxResponse::ValidTx);

        safe_produce_blocks(&mut env, 1, epoch_length * 2 + 1, Some(5));

        initialize_genesis_state(store.clone(), &genesis, None);
        let epoch_manager = EpochManager::new_arc_handle(store.clone(), &genesis.config);
        let runtime = NightshadeRuntime::test(
            Path::new("."),
            store.clone(),
            &genesis.config,
            epoch_manager.clone(),
        );
        let mut file = tempfile::NamedTempFile::new().unwrap();
        apply_chain_range(
            store,
            &genesis,
            None,
            None,
            0,
            epoch_manager.as_ref(),
            runtime,
            true,
            Some(file.as_file_mut()),
            false,
            false,
            false,
        );
        let mut csv = String::new();
        file.as_file_mut().seek(SeekFrom::Start(0)).unwrap();
        file.as_file_mut().read_to_string(&mut csv).unwrap();
        let lines: Vec<&str> = csv.split("\n").collect();
        assert!(lines[0].contains("Height"));
        let mut has_tx = 0;
        let mut no_tx = 0;
        for line in &lines {
            if line.contains(",test0,1,0,") {
                has_tx += 1;
            }
            if line.contains(",test0,0,0,") {
                no_tx += 1;
            }
        }
        assert_eq!(has_tx, 1, "{:#?}", lines);
        assert_eq!(no_tx, 8, "{:#?}", lines);
    }