fn mock_db() -> MockLibraDB {
    let mut gen = ValueGenerator::new();
    let blocks = gen.generate(arb_blocks_to_commit());
    let mut account_state_with_proof = gen.generate(any::<AccountStateWithProof>());

    let mut version = 1;
    let mut all_accounts = BTreeMap::new();
    let mut all_txns = vec![];
    let mut events = vec![];
    let mut timestamps = vec![0 as u64];

    for (txns_to_commit, ledger_info_with_sigs) in &blocks {
        for (idx, txn) in txns_to_commit.iter().enumerate() {
            timestamps.push(ledger_info_with_sigs.ledger_info().timestamp_usecs());
            events.extend(
                txn.events()
                    .iter()
                    .map(|e| ((idx + version) as u64, e.clone())),
            );
        }
        version += txns_to_commit.len();
        let mut account_states = HashMap::new();
        // Get the ground truth of account states.
        txns_to_commit.iter().for_each(|txn_to_commit| {
            account_states.extend(txn_to_commit.account_states().clone())
        });

        // Record all account states.
        for (address, blob) in account_states.into_iter() {
            all_accounts.insert(address, blob.clone());
        }

        // Record all transactions.
        all_txns.extend(txns_to_commit.iter().map(|txn_to_commit| {
            (
                txn_to_commit.transaction().clone(),
                txn_to_commit.major_status(),
            )
        }));
    }

    if account_state_with_proof.blob.is_none() {
        let (_, blob) = all_accounts.iter().next().unwrap();
        account_state_with_proof.blob = Some(blob.clone());
    }
    let account_state_with_proof = vec![account_state_with_proof];

    if events.is_empty() {
        // mock the first event
        let mock_event = ContractEvent::new(
            EventKey::new_from_address(&AccountAddress::random(), 0),
            0,
            TypeTag::Bool,
            b"event_data".to_vec(),
        );
        events.push((version as u64, mock_event));
    }

    MockLibraDB {
        version: version as u64,
        all_accounts,
        all_txns,
        events,
        account_state_with_proof,
        timestamps,
    }
}
// returns MockLibraDB for unit-testing
returns MockLibraDB for unit-testing
returns MockLibraDB for unit - testing
fn mock_db() -> MockLibraDB {
    let mut gen = ValueGenerator::new();
    let blocks = gen.generate(arb_blocks_to_commit());
    let mut account_state_with_proof = gen.generate(any::<AccountStateWithProof>());
    let mut version = 1;
    let mut all_accounts = BTreeMap::new();
    let mut all_txns = vec![];
    let mut events = vec![];
    let mut timestamps = vec![0 as u64];
    for (txns_to_commit, ledger_info_with_sigs) in &blocks {
        for (idx, txn) in txns_to_commit.iter().enumerate() {
            timestamps.push(ledger_info_with_sigs.ledger_info().timestamp_usecs());
            events.extend(
                txn.events()
                    .iter()
                    .map(|e| ((idx + version) as u64, e.clone())),
            );
        }
        version += txns_to_commit.len();
        let mut account_states = HashMap::new();
        // Get the ground truth of account states.
        txns_to_commit.iter().for_each(|txn_to_commit| {
            account_states.extend(txn_to_commit.account_states().clone())
        });
        // Record all account states.
        for (address, blob) in account_states.into_iter() {
            all_accounts.insert(address, blob.clone());
        }
        // Record all transactions.
        all_txns.extend(txns_to_commit.iter().map(|txn_to_commit| {
            (
                txn_to_commit.transaction().clone(),
                txn_to_commit.major_status(),
            )
        }));
    }
    if account_state_with_proof.blob.is_none() {
        let (_, blob) = all_accounts.iter().next().unwrap();
        account_state_with_proof.blob = Some(blob.clone());
    }
    let account_state_with_proof = vec![account_state_with_proof];
    if events.is_empty() {
        // mock the first event
        let mock_event = ContractEvent::new(
            EventKey::new_from_address(&AccountAddress::random(), 0),
            0,
            TypeTag::Bool,
            b"event_data".to_vec(),
        );
        events.push((version as u64, mock_event));
    }
    MockLibraDB {
        version: version as u64,
        all_accounts,
        all_txns,
        events,
        account_state_with_proof,
        timestamps,
    }
}
fn mock_db ( ) -> MockLibraDB { let mut gen = ValueGenerator :: new ( ) ; let blocks = gen . generate ( arb_blocks_to_commit ( ) ) ; let mut account_state_with_proof = gen . generate ( any :: < AccountStateWithProof > ( ) ) ; let mut version = 1 ; let mut all_accounts = BTreeMap :: new ( ) ; let mut all_txns = vec ! [ ] ; let mut events = vec ! [ ] ; let mut timestamps = vec ! [ 0 as u64 ] ; for ( txns_to_commit , ledger_info_with_sigs ) in & blocks { for ( idx , txn ) in txns_to_commit . iter ( ) . enumerate ( ) { timestamps . push ( ledger_info_with_sigs . ledger_info ( ) . timestamp_usecs ( ) ) ; events . extend ( txn . events ( ) . iter ( ) . map ( | e | ( ( idx + version ) as u64 , e . clone ( ) ) ) , ) ; } version += txns_to_commit . len ( ) ; let mut account_states = HashMap :: new ( ) ; // Get the ground truth of account states. txns_to_commit . iter ( ) . for_each ( | txn_to_commit | { account_states . extend ( txn_to_commit . account_states ( ) . clone ( ) ) } ) ; // Record all account states. for ( address , blob ) in account_states . into_iter ( ) { all_accounts . insert ( address , blob . clone ( ) ) ; } // Record all transactions. all_txns . extend ( txns_to_commit . iter ( ) . map ( | txn_to_commit | { ( txn_to_commit . transaction ( ) . clone ( ) , txn_to_commit . major_status ( ) , ) } ) ) ; } if account_state_with_proof . blob . is_none ( ) { let ( _ , blob ) = all_accounts . iter ( ) . next ( ) . unwrap ( ) ; account_state_with_proof . blob = Some ( blob . clone ( ) ) ; } let account_state_with_proof = vec ! [ account_state_with_proof ] ; if events . is_empty ( ) { // mock the first event let mock_event = ContractEvent :: new ( EventKey :: new_from_address ( & AccountAddress :: random ( ) , 0 ) , 0 , TypeTag :: Bool , b" " . to_vec ( ) , ) ; events . push ( ( version as u64 , mock_event ) ) ; } MockLibraDB { version : version as u64 , all_accounts , all_txns , events , account_state_with_proof , timestamps , } }
returns MockLibraDB for unit-testing
returns MockLibraDB for unit - testing