def _get_block_by_number(method, params, block_info=_block_info): block_id = params[0] blocks = block_info['blocks'] head_block_number = block_info['head_block_number'] if block_id == 'latest': return blocks[head_block_number] elif block_id == 'pending': if head_block_number + 1 >= len(blocks): raise ValueError("no pending block") return blocks[head_block_number + 1] elif block_id == 'earliest': return blocks[0] elif is_integer(block_id): if block_id <= head_block_number: return blocks[block_id] else: return None elif is_hex(block_id): block_id = hex_to_integer(block_id) if block_id <= head_block_number: return blocks[block_id] else: return None else: raise TypeError('Invalid type for block_id')
def to_block(self) -> BlockNumber: if self._to_block is None: to_block = self.w3.eth.block_number elif self._to_block == "latest": to_block = self.w3.eth.block_number elif is_hex(self._to_block): to_block = BlockNumber(hex_to_integer(self._to_block)) # type: ignore else: to_block = cast(BlockNumber, self._to_block) return to_block
def test_eth_call_with_0_result(self, web3, math_contract, math_contract_address): coinbase = web3.eth.coinbase txn_params = math_contract._prepare_transaction( fn_name='add', fn_args=(0, 0), transaction={'from': coinbase, 'to': math_contract_address}, ) trace = web3.parity.traceCall(txn_params) assert trace['stateDiff'] is None assert trace['vmTrace'] is None result = hex_to_integer(trace['output']) assert result == 0
def numToDatetime(tdelta): tzero = datetime.strptime('1970-01-01T00:00:00+0000', '%Y-%m-%dT%H:%M:%S%z') if is_integer(tdelta): pass elif is_hex(tdelta): tdelta = hex_to_integer(tdelta) else: raise TypeError( 'Unrecognised raw date ', tdelta ) return tzero + timedelta(seconds = tdelta)
def test_eth_call_with_0_result( self, web3: "Web3", math_contract: "Contract", math_contract_address: ChecksumAddress ) -> None: coinbase = web3.eth.coinbase txn_params = math_contract._prepare_transaction( fn_name='add', fn_args=(0, 0), transaction={'from': coinbase, 'to': math_contract_address}, ) trace = web3.parity.traceCall(txn_params) assert trace['stateDiff'] is None assert trace['vmTrace'] is None result = hex_to_integer(trace['output']) assert result == 0
def test_trace_call(self, web3, math_contract, math_contract_address): coinbase = web3.eth.coinbase txn_params = math_contract._prepare_transaction( fn_name='add', fn_args=(7, 11), transaction={ 'from': coinbase, 'to': math_contract_address }, ) trace = web3.parity.traceCall(txn_params) assert trace['stateDiff'] is None assert trace['vmTrace'] is None result = hex_to_integer(trace['output']) assert result == 18
def test_traceCall_deprecated( self, web3: "Web3", math_contract: "Contract", math_contract_address: ChecksumAddress) -> None: coinbase = web3.eth.coinbase txn_params = math_contract._prepare_transaction( fn_name='add', fn_args=(7, 11), transaction={ 'from': coinbase, 'to': math_contract_address }, ) with pytest.warns( DeprecationWarning, match="traceCall is deprecated in favor of trace_call"): trace = web3.parity.traceCall(txn_params) assert trace['stateDiff'] is None assert trace['vmTrace'] is None result = hex_to_integer(trace['output']) assert result == 18
def __init__( self, w3: "Web3", from_block: Optional[Union[BlockNumber, LatestBlockParam]] = None, to_block: Optional[Union[BlockNumber, LatestBlockParam]] = None, address: Optional[Union[Address, ChecksumAddress, List[Union[Address, ChecksumAddress]]]] = None, topics: Optional[List[Optional[Union[_Hash32, List[_Hash32]]]]] = None ) -> None: self.address = address self.topics = topics self.w3 = w3 if from_block is None or from_block == "latest": self._from_block = BlockNumber(w3.eth.block_number + 1) elif is_string(from_block) and is_hex(from_block): self._from_block = BlockNumber( hex_to_integer(from_block)) # type: ignore else: # cast b/c LatestBlockParam is handled above self._from_block = cast(BlockNumber, from_block) self._to_block = to_block self.filter_changes = self._get_filter_changes()
def test_eth_chainId(self, web3): chain_id = web3.eth.chainId assert is_hex(chain_id) assert hex_to_integer(chain_id) is 61