def test_check_json_rpc_geth(): g1, client = is_supported_client( 'Geth/v1.7.3-unstable-e9295163/linux-amd64/go1.9.1') g2, _ = is_supported_client( 'Geth/v1.7.2-unstable-e9295163/linux-amd64/go1.9.1') g3, _ = is_supported_client( 'Geth/v1.8.2-unstable-e9295163/linux-amd64/go1.9.1') g4, _ = is_supported_client( 'Geth/v2.0.3-unstable-e9295163/linux-amd64/go1.9.1') g5, _ = is_supported_client( 'Geth/v11.55.86-unstable-e9295163/linux-amd64/go1.9.1') g6, _ = is_supported_client( 'Geth/v999.999.999-unstable-e9295163/linux-amd64/go1.9.1') assert client is EthClient.GETH assert all([g1, g2, g3, g4, g5, g6]) b1, client = is_supported_client( 'Geth/v1.7.1-unstable-e9295163/linux-amd64/go1.9.1') b2, _ = is_supported_client( 'Geth/v0.7.1-unstable-e9295163/linux-amd64/go1.9.1') b3, _ = is_supported_client( 'Geth/v0.0.0-unstable-e9295163/linux-amd64/go1.9.1') b4, _ = is_supported_client( 'Geth/v0.0.0-unstable-e9295163/linux-amd64/go1.9.1') assert not client assert not any([b1, b2, b3, b4])
def __init__( self, web3: Web3, privkey: Optional[PrivateKey], gas_price_strategy: Callable = rpc_gas_price_strategy, gas_estimate_correction: Callable = lambda gas: gas, block_num_confirmations: int = 0, ) -> None: if privkey is None or len(privkey) != 32: raise ValueError("Invalid private key") if block_num_confirmations < 0: raise ValueError("Number of confirmations has to be positive") monkey_patch_web3(web3, gas_price_strategy) version = web3.version.node supported, eth_node, _ = is_supported_client(version) if not supported: raise EthNodeInterfaceError( f"Unsupported Ethereum client {version}") address = privatekey_to_address(privkey) address_checksumed = to_checksum_address(address) if eth_node is EthClient.PARITY: parity_assert_rpc_interfaces(web3) available_nonce = parity_discover_next_available_nonce( web3, address_checksumed) elif eth_node is EthClient.GETH: geth_assert_rpc_interfaces(web3) available_nonce = geth_discover_next_available_nonce( web3, address_checksumed) self.eth_node = eth_node self.privkey = privkey self.address = address self.web3 = web3 self.default_block_num_confirmations = block_num_confirmations # Ask for the chain id only once and store it here self.chain_id = ChainID(int(self.web3.version.network)) self._available_nonce = available_nonce self._nonce_lock = Semaphore() self._gas_estimate_correction = gas_estimate_correction log.debug( "JSONRPCClient created", node=to_checksum_address(self.address), available_nonce=available_nonce, client=version, )
def check_geth_version_for_tests(blockchain_type): if blockchain_type != "geth": return geth_version_string, _ = subprocess.Popen( ["geth", "version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() supported, _, our_version = is_supported_client( geth_version_string.decode()) if not supported: pytest.exit( f"You are trying to run tests with an unsupported GETH version. " f"Your Version: {our_version} " f"Min Supported Version {LOWEST_SUPPORTED_GETH_VERSION} " f"Max Supported Version {HIGHEST_SUPPORTED_GETH_VERSION}")
def check_ethereum_client_is_supported(web3: Web3) -> None: try: node_version = web3.clientVersion except ValueError: raise EthNodeInterfaceError( "The underlying ethereum node does not have the web3 rpc interface " "enabled. Please run it with --rpcapi eth,net,web3 for geth " "and --jsonrpc-apis=eth,net,web3,parity for parity.") supported, our_client, our_version = is_supported_client(node_version) if not supported: raise RaidenError( f"You need a Byzantium enabled ethereum node. Parity >= " f"{LOWEST_SUPPORTED_PARITY_VERSION} <= {HIGHEST_SUPPORTED_PARITY_VERSION}" f" or Geth >= {LOWEST_SUPPORTED_GETH_VERSION} <= {HIGHEST_SUPPORTED_GETH_VERSION}" f" but you have {our_version} {our_client}")
def check_parity_version_for_tests(blockchain_type): if blockchain_type != "parity": return parity_version_string, _ = subprocess.Popen( ["openethereum", "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() supported, _, our_version = is_supported_client( parity_version_string.decode()) if supported is VersionSupport.UNSUPPORTED: pytest.exit( f"You are trying to run tests with an unsupported PARITY version. " f"Your Version: {our_version} " f"Min Supported Version {LOWEST_SUPPORTED_PARITY_VERSION} " f"Max Supported Version {HIGHEST_SUPPORTED_PARITY_VERSION}")
def check_ethereum_client_is_supported(web3: Web3) -> None: try: node_version = web3.version.node # pylint: disable=no-member except ConnectTimeout: raise EthNodeCommunicationError( "Couldn't connect to the ethereum node") except ValueError: raise EthNodeInterfaceError( "The underlying ethereum node does not have the web3 rpc interface " "enabled. Please run it with --rpcapi eth,net,web3,txpool for geth " "and --jsonrpc-apis=eth,net,web3,parity for parity.") supported, _ = is_supported_client(node_version) if not supported: click.secho( "You need a Byzantium enabled ethereum node. Parity >= 1.7.6 or Geth >= 1.7.2", fg="red", ) sys.exit(1)
def _setup_web3(eth_rpc_endpoint): web3 = Web3(HTTPProvider(eth_rpc_endpoint)) try: node_version = web3.version.node # pylint: disable=no-member except ConnectTimeout: raise EthNodeCommunicationError( "Couldn't connect to the ethereum node") except ValueError: raise EthNodeInterfaceError( 'The underlying ethereum node does not have the web3 rpc interface ' 'enabled. Please run it with --rpcapi eth,net,web3,txpool for geth ' 'and --jsonrpc-apis=eth,net,web3,parity for parity.', ) supported, _ = is_supported_client(node_version) if not supported: click.secho( 'You need a Byzantium enabled ethereum node. Parity >= 1.7.6 or Geth >= 1.7.2', fg='red', ) sys.exit(1) return web3
def test_check_is_supported_unknown_client(): supported, client, version = is_supported_client("Aleth//v1.2.1") assert not supported assert not client assert not version
def run_test_check_json_rpc_geth(): g1, client, v1 = is_supported_client( "Geth/v1.7.3-unstable-e9295163/linux-amd64/go1.9.1") g2, _, v2 = is_supported_client( "Geth/v1.7.2-unstable-e9295163/linux-amd64/go1.9.1") g3, _, v3 = is_supported_client( "Geth/v1.8.2-unstable-e9295163/linux-amd64/go1.9.1") g4, _, v4 = is_supported_client( "Geth/v2.0.3-unstable-e9295163/linux-amd64/go1.9.1") g5, _, v5 = is_supported_client( "Geth/v11.55.86-unstable-e9295163/linux-amd64/go1.9.1") g6, _, v6 = is_supported_client( "Geth/v999.999.999-unstable-e9295163/linux-amd64/go1.9.1") # Test that patch version upgrades are not triggering the non-supported check g7, _, v7 = is_supported_client( "Geth/v1.9.3-unstable-e9295163/linux-amd64/go1.9.1") g8, _, v8 = is_supported_client( "Geth/v1.9.0-stable-52f24617/linux-amd64/go1.12.7") assert client is EthClient.GETH assert all([g1, g2, g3, g7, g8]) assert not any([g4, g5, g6]) assert v1 == "1.7.3" assert v2 == "1.7.2" assert v3 == "1.8.2" assert v4 == "2.0.3" assert v5 == "11.55.86" assert v6 == "999.999.999" assert v7 == "1.9.3" assert v8 == "1.9.0" b1, client, v1 = is_supported_client( "Geth/v1.7.1-unstable-e9295163/linux-amd64/go1.9.1") b2, _, v2 = is_supported_client( "Geth/v0.7.1-unstable-e9295163/linux-amd64/go1.9.1") b3, _, v3 = is_supported_client( "Geth/v0.0.0-unstable-e9295163/linux-amd64/go1.9.1") b4, _, _ = is_supported_client( "Geth/v0.0.0-unstable-e9295163/linux-amd64/go1.9.1") assert client is EthClient.GETH assert not any([b1, b2, b3, b4]) assert v1 == "1.7.1" assert v2 == "0.7.1" assert v3 == "0.0.0" supported, client, version = is_supported_client("Geth/faultyversion") assert not supported assert not client assert not version
def run_test_check_json_rpc_parity(): g1, client, v1 = is_supported_client( "Parity//v1.7.6-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0" ) g2, _, v2 = is_supported_client( "Parity//v1.7.7-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0" ) g3, _, v3 = is_supported_client( "Parity/v1.8.7-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0") g4, _, v4 = is_supported_client( "Parity//v2.9.7-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0" ) g5, _, v5 = is_supported_client( "Parity/v23.94.75-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0" ) g6, _, v6 = is_supported_client( "Parity//v99.994.975-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0" ) # Test that patch version upgrades are not triggering the non-supported check g7, _, v7 = is_supported_client( "Parity//v2.5.8-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0" ) g8, _, v8 = is_supported_client( "Parity//v2.5.0-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0" ) assert client is EthClient.PARITY assert all([g1, g2, g3, g7, g8]) assert not any([g4, g5, g6]) assert v1 == "1.7.6" assert v2 == "1.7.7" assert v3 == "1.8.7" assert v4 == "2.9.7" assert v5 == "23.94.75" assert v6 == "99.994.975" assert v7 == "2.5.8" assert v8 == "2.5.0" b1, client, v1 = is_supported_client( "Parity//v1.7.5-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0" ) b2, _, v2 = is_supported_client( "Parity/v1.5.1-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0") b3, _, v3 = is_supported_client( "Parity//v0.7.1-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0" ) b4, _, v4 = is_supported_client( "Parity/v0.8.7-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0") b5, _, v5 = is_supported_client( "Parity//v0.0.0-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0" ) assert client is EthClient.PARITY assert not any([b1, b2, b3, b4, b5]) assert v1 == "1.7.5" assert v2 == "1.5.1" assert v3 == "0.7.1" assert v4 == "0.8.7" assert v5 == "0.0.0" supported, client, version = is_supported_client("Parity//faultyversion") assert not supported assert not client assert not version
def test_check_json_rpc_parity(): g1, client = is_supported_client( 'Parity//v1.7.6-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0', ) g2, _ = is_supported_client( 'Parity//v1.7.7-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0', ) g3, _ = is_supported_client( 'Parity//v1.8.7-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0', ) g4, _ = is_supported_client( 'Parity//v2.9.7-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0', ) g5, _ = is_supported_client( 'Parity//v23.94.75-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0', ) g6, _ = is_supported_client( 'Parity//v99.994.975-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0', ) assert client is EthClient.PARITY assert all([g1, g2, g3, g4, g5, g6]) b1, client = is_supported_client( 'Parity//v1.7.5-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0', ) b2, _ = is_supported_client( 'Parity//v1.5.1-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0', ) b3, _ = is_supported_client( 'Parity//v0.7.1-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0', ) b4, _ = is_supported_client( 'Parity//v0.8.7-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0', ) b5, _ = is_supported_client( 'Parity//v0.0.0-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0', ) assert not client assert not any([b1, b2, b3, b4, b5])
def __init__( self, web3: Web3, privkey: bytes, gas_price_strategy: Callable = rpc_gas_price_strategy, gas_estimate_correction: Callable = lambda gas: gas, block_num_confirmations: int = 0, uses_infura=False, ): if privkey is None or len(privkey) != 32: raise ValueError("Invalid private key") if block_num_confirmations < 0: raise ValueError("Number of confirmations has to be positive") monkey_patch_web3(web3, gas_price_strategy) try: version = web3.version.node except ConnectTimeout: raise EthNodeCommunicationError("couldnt reach the ethereum node") _, eth_node = is_supported_client(version) address = privatekey_to_address(privkey) address_checksumed = to_checksum_address(address) if uses_infura: warnings.warn( "Infura does not provide an API to " "recover the latest used nonce. This may cause the Raiden node " "to error on restarts.\n" "The error will manifest while there is a pending transaction " "from a previous execution in the Ethereum's client pool. When " "Raiden restarts the same transaction with the same nonce will " "be retried and *rejected*, because the nonce is already used." ) # The first valid nonce is 0, therefore the count is already the next # available nonce available_nonce = web3.eth.getTransactionCount( address_checksumed, "pending") elif eth_node is constants.EthClient.PARITY: parity_assert_rpc_interfaces(web3) available_nonce = parity_discover_next_available_nonce( web3, address_checksumed) elif eth_node is constants.EthClient.GETH: geth_assert_rpc_interfaces(web3) available_nonce = geth_discover_next_available_nonce( web3, address_checksumed) else: raise EthNodeInterfaceError( f"Unsupported Ethereum client {version}") self.eth_node = eth_node self.privkey = privkey self.address = address self.web3 = web3 self.default_block_num_confirmations = block_num_confirmations self._available_nonce = available_nonce self._nonce_lock = Semaphore() self._gas_estimate_correction = gas_estimate_correction log.debug( "JSONRPCClient created", node=pex(self.address), available_nonce=available_nonce, client=version, )
def run_test_check_json_rpc_geth(): g1, client, v1 = is_supported_client( "Geth/v1.7.3-unstable-e9295163/linux-amd64/go1.9.1") g2, _, v2 = is_supported_client( "Geth/v1.7.2-unstable-e9295163/linux-amd64/go1.9.1") g3, _, v3 = is_supported_client( "Geth/v1.8.2-unstable-e9295163/linux-amd64/go1.9.1") g4, _, v4 = is_supported_client( "Geth/v2.0.3-unstable-e9295163/linux-amd64/go1.9.1") g5, _, v5 = is_supported_client( "Geth/v11.55.86-unstable-e9295163/linux-amd64/go1.9.1") g6, _, v6 = is_supported_client( "Geth/v999.999.999-unstable-e9295163/linux-amd64/go1.9.1") g8, _, v8 = is_supported_client( "Geth/v1.9.0-stable-52f24617/linux-amd64/go1.12.7") g9, _, v9 = is_supported_client( "Geth/v1.9.0-unstable-3d3e83ec-20190611/linux-amd64/go1.12.5") assert client is EthClient.GETH assert {g1, g2, g3, g8, g9} == {VersionSupport.SUPPORTED} assert {g4, g5, g6} == {VersionSupport.WARN} assert v1 == "1.7.3" assert v2 == "1.7.2" assert v3 == "1.8.2" assert v4 == "2.0.3" assert v5 == "11.55.86" assert v6 == "999.999.999" assert v8 == "1.9.0" assert v9 == "1.9.0" b1, client, v1 = is_supported_client( "Geth/v1.7.1-unstable-e9295163/linux-amd64/go1.9.1") b2, _, v2 = is_supported_client( "Geth/v0.7.1-unstable-e9295163/linux-amd64/go1.9.1") b3, _, v3 = is_supported_client( "Geth/v0.0.0-unstable-e9295163/linux-amd64/go1.9.1") b4, _, _ = is_supported_client( "Geth/v0.0.0-unstable-e9295163/linux-amd64/go1.9.1") assert client is EthClient.GETH assert {b1, b2, b3, b4} == {VersionSupport.UNSUPPORTED} assert v1 == "1.7.1" assert v2 == "0.7.1" assert v3 == "0.0.0" supported, client, version = is_supported_client("Geth/faultyversion") assert supported is VersionSupport.UNSUPPORTED assert not client assert not version
def test_check_is_supported_unknown_client(): supported, client, version = is_supported_client("Aleth//v1.2.1") assert supported is VersionSupport.UNSUPPORTED assert not client assert not version
def run_test_check_json_rpc_parity(): g1, client, v1 = is_supported_client( "Parity//v1.7.6-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0" ) g2, _, v2 = is_supported_client( "Parity//v1.7.7-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0" ) g3, _, v3 = is_supported_client( "Parity/v1.8.7-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0") g4, _, v4 = is_supported_client( "Parity//v2.9.7-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0" ) g5, _, v5 = is_supported_client( "Parity/v23.94.75-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0" ) g6, _, v6 = is_supported_client( "Parity//v99.994.975-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0" ) g8, _, v8 = is_supported_client( "Parity//v2.5.0-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0" ) assert client is EthClient.PARITY assert {g1, g2, g3, g8} == {VersionSupport.SUPPORTED} assert {g4, g5, g6} == {VersionSupport.WARN} assert v1 == "1.7.6" assert v2 == "1.7.7" assert v3 == "1.8.7" assert v4 == "2.9.7" assert v5 == "23.94.75" assert v6 == "99.994.975" assert v8 == "2.5.0" b1, client, v1 = is_supported_client( "Parity//v1.7.5-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0" ) b2, _, v2 = is_supported_client( "Parity/v1.5.1-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0") b3, _, v3 = is_supported_client( "Parity//v0.7.1-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0" ) b4, _, v4 = is_supported_client( "Parity/v0.8.7-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0") b5, _, v5 = is_supported_client( "Parity//v0.0.0-stable-19535333c-20171013/x86_64-linux-gnu/rustc1.20.0" ) assert client is EthClient.PARITY assert {b1, b2, b3, b4, b5} == {VersionSupport.UNSUPPORTED} assert v1 == "1.7.5" assert v2 == "1.5.1" assert v3 == "0.7.1" assert v4 == "0.8.7" assert v5 == "0.0.0" supported, client, version = is_supported_client("Parity//faultyversion") assert supported is VersionSupport.UNSUPPORTED assert not client assert not version