def apply_fixture_block_to_chain( block_fixture: Dict[str, Any], chain: BaseChain, perform_validation: bool = True ) -> Tuple[BaseBlock, BaseBlock, BaseBlock]: """ :return: (premined_block, mined_block, rlp_encoded_mined_block) """ # The block to import may be in a different block-class-range than the # chain's current one, so we use the block number specified in the # fixture to look up the correct block class. if 'blockHeader' in block_fixture: block_number = block_fixture['blockHeader']['number'] block_class = chain.get_vm_class_for_block_number( block_number).get_block_class() else: block_class = chain.get_vm().get_block_class() block = rlp.decode(block_fixture['rlp'], sedes=block_class) mined_block, _, _ = chain.import_block( block, perform_validation=perform_validation) rlp_encoded_mined_block = rlp.encode(mined_block, sedes=block_class) return (block, mined_block, rlp_encoded_mined_block)
def dict_to_spoof_transaction( chain: BaseChain, header: BlockHeader, transaction_dict: Dict[str, Any]) -> SpoofTransaction: """ Convert dicts used in calls & gas estimates into a spoof transaction """ txn_dict = normalize_transaction_dict(transaction_dict) sender = txn_dict.get('from', ZERO_ADDRESS) if 'nonce' in txn_dict: nonce = txn_dict['nonce'] else: vm = chain.get_vm(header) nonce = vm.state.account_db.get_nonce(sender) gas_price = txn_dict.get('gasPrice', 0) gas = txn_dict.get('gas', header.gas_limit) unsigned = chain.get_vm_class(header).create_unsigned_transaction( nonce=nonce, gas_price=gas_price, gas=gas, to=txn_dict['to'], value=txn_dict['value'], data=txn_dict['data'], ) return SpoofTransaction(unsigned, from_=sender)
def account_db_at_block(chain: BaseChain, at_block: Union[str, int], read_only: bool=True) ->BaseAccountDB: at_header = get_header(chain, at_block) vm = chain.get_vm(at_header) return vm.state.account_db