def test_contract_storage_size_on_latest(initial_scenario):
    block = initial_scenario.get_block()
    db = initial_scenario.db
    state = StateDataset(db, decode_hex(block.stateRoot))
    contract_address = initial_scenario.contract_address
    contract_size = initial_scenario.contract_storage_size
    logging.info('w3 code size %i  on acc: %s on latest blk', contract_size,
                 contract_address)
    contract = state.get_account(contract_address)
    assert contract_size == contract.storage_size(db)
def test_account_balance_on_latest(initial_scenario):
    for n in range(NBR_RANDOM_TESTS):
        to_account = random.choice(initial_scenario.accounts)
        to_account_balance = initial_scenario.get_account_balance(to_account)
        logging.info('w3 balance %i on acc: %s on latest blk',
                     to_account_balance, to_account)
        block = initial_scenario.get_block()
        db = initial_scenario.db
        state = StateDataset(db, block.stateRoot)
        state_dict = state.to_dict()
        assert to_account_balance == state_dict[to_account][1]
def test_get_account(initial_scenario):
    latest_block = initial_scenario.get_block()
    latest_block_nbr = latest_block['number']
    for n in range(NBR_RANDOM_TESTS):
        is_block_with_txn = False
        while not is_block_with_txn:
            n_blk = initial_scenario.get_block(
                random.randrange(1, latest_block_nbr))
            if len(n_blk['transactions']) > 0:
                is_block_with_txn = True
        n_blk_nbr = n_blk['number']
        to_account = random.choice(initial_scenario.accounts)
        to_account_nonce = initial_scenario.get_account_nonce(
            to_account, n_blk_nbr)
        logging.info('w3 nonce %i on acc: %s  on blk: %i', to_account_nonce,
                     to_account, n_blk_nbr)
        db = initial_scenario.db
        state = StateDataset(db, decode_hex(n_blk.stateRoot))
        account = state.get_account(to_account)
        assert to_account_nonce == account.nonce
 def get_first_state_in_db(db):
     blk = BlockHeader.get_latest_block_header(db)
     state = StateDataset(db, blk.state_root)
     step = -1 * blk.number // 2
     while state.is_in_db:
         blk = BlockHeader.get_block_header_by_number(blk.number + step)
def test_to_panda_dataset(initial_scenario):
    latest_block = initial_scenario.get_block()
    db = initial_scenario.db
    state = StateDataset(db, decode_hex(latest_block.stateRoot))
    df = state.to_panda_dataframe()
    logging.info('Panda dataset\n%s', df.describe())