@pytest.mark.skipif(('TRAVIS' in os.environ), reason='Flaky test due to mark.timeout not being scheduled. Issue #319')
@pytest.mark.timeout(60)
@pytest.mark.parametrize('privatekey_seed', ['blockchain:{}'])
@pytest.mark.parametrize('number_of_nodes', [3])
def test_blockchain(blockchain_type, blockchain_backend, blockchain_rpc_ports, private_keys, poll_timeout):
    if (blockchain_type not in ('geth',)):
        return
    addresses = [privatekey_to_address(priv) for priv in private_keys]
    privatekey = private_keys[0]
    address = privatekey_to_address(privatekey)
    total_asset = 100
    jsonrpc_client = JSONRPCClient(port=blockchain_rpc_ports[0], privkey=privatekey, print_communication=False)
    patch_send_transaction(jsonrpc_client)
    patch_send_message(jsonrpc_client)
    humantoken_path = get_contract_path('HumanStandardToken.sol')
    humantoken_contracts = compile_file(humantoken_path, libraries=dict())
    token_proxy = jsonrpc_client.deploy_solidity_contract(address, 'HumanStandardToken', humantoken_contracts, dict(), (total_asset, 'raiden', 2, 'Rd'), contract_path=humantoken_path, gasprice=default_gasprice, timeout=poll_timeout)
    registry_path = get_contract_path('Registry.sol')
    registry_contracts = compile_file(registry_path)
    registry_proxy = jsonrpc_client.deploy_solidity_contract(address, 'Registry', registry_contracts, dict(), tuple(), contract_path=registry_path, gasprice=default_gasprice, timeout=poll_timeout)
    log_list = jsonrpc_client.call('eth_getLogs', {'fromBlock': '0x0', 'toBlock': 'latest', 'topics': []})
    assert (len(log_list) == 0)
    assert (token_proxy.balanceOf(address) == total_asset)
    transaction_hash = registry_proxy.addAsset.transact(token_proxy.address, gasprice=denoms.wei)
    jsonrpc_client.poll(transaction_hash.decode('hex'), timeout=poll_timeout)
    assert (len(registry_proxy.assetAddresses.call()) == 1)
    log_list = jsonrpc_client.call('eth_getLogs', {'fromBlock': '0x0', 'toBlock': 'latest', 'topics': []})
    assert (len(log_list) == 1)
    channel_manager_address_encoded = registry_proxy.channelManagerByAsset.call(token_proxy.address)
    channel_manager_address = channel_manager_address_encoded.decode('hex')
    log = log_list[0]
    log_topics = [decode_topic(topic) for topic in log['topics']]
    log_data = log['data']
    event = registry_proxy.translator.decode_event(log_topics, log_data[2:].decode('hex'))
    assert (channel_manager_address == event['channel_manager_address'].decode('hex'))
    assert (token_proxy.address == event['asset_address'].decode('hex'))
    channel_manager_proxy = jsonrpc_client.new_contract_proxy(CHANNEL_MANAGER_ABI, channel_manager_address)
    transaction_hash = channel_manager_proxy.newChannel.transact(addresses[1], 10, gasprice=denoms.wei)
    jsonrpc_client.poll(transaction_hash.decode('hex'), timeout=poll_timeout)
    log_list = jsonrpc_client.call('eth_getLogs', {'fromBlock': '0x0', 'toBlock': 'latest', 'topics': []})
    assert (len(log_list) == 2)
@pytest.mark.skipif(('TRAVIS' in os.environ), reason='Flaky test due to mark.timeout not being scheduled. Issue #319')
@pytest.mark.timeout(60)
@pytest.mark.parametrize('privatekey_seed', ['blockchain:{}'])
@pytest.mark.parametrize('number_of_nodes', [3])
def test_blockchain(blockchain_type, blockchain_backend, blockchain_rpc_ports, private_keys, poll_timeout):
    if (blockchain_type not in ('geth',)):
        return
    addresses = [privatekey_to_address(priv) for priv in private_keys]
    privatekey = private_keys[0]
    address = privatekey_to_address(privatekey)
    total_asset = 100
    jsonrpc_client = JSONRPCClient(port=blockchain_rpc_ports[0], privkey=privatekey, print_communication=False)
    patch_send_transaction(jsonrpc_client)
    patch_send_message(jsonrpc_client)
    humantoken_path = get_contract_path('HumanStandardToken.sol')
    humantoken_contracts = compile_file(humantoken_path, libraries=dict())
    token_proxy = jsonrpc_client.deploy_solidity_contract(address, 'HumanStandardToken', humantoken_contracts, dict(), (total_asset, 'raiden', 2, 'Rd'), contract_path=humantoken_path, gasprice=default_gasprice, timeout=poll_timeout)
    registry_path = get_contract_path('Registry.sol')
    registry_contracts = compile_file(registry_path)
    registry_proxy = jsonrpc_client.deploy_solidity_contract(address, 'Registry', registry_contracts, dict(), tuple(), contract_path=registry_path, gasprice=default_gasprice, timeout=poll_timeout)
    log_list = jsonrpc_client.call('eth_getLogs', {'fromBlock': '0x0', 'toBlock': 'latest', 'topics': []})
    assert (len(log_list) == 0)
    assert (token_proxy.balanceOf(address) == total_asset)
    transaction_hash = registry_proxy.addAsset.transact(token_proxy.address, gasprice=denoms.wei)
    jsonrpc_client.poll(transaction_hash.decode('hex'), timeout=poll_timeout)
    assert (len(registry_proxy.assetAddresses.call()) == 1)
    log_list = jsonrpc_client.call('eth_getLogs', {'fromBlock': '0x0', 'toBlock': 'latest', 'topics': []})
    assert (len(log_list) == 1)
    channel_manager_address_encoded = registry_proxy.channelManagerByAsset.call(token_proxy.address)
    channel_manager_address = channel_manager_address_encoded.decode('hex')
    log = log_list[0]
    log_topics = [decode_topic(topic) for topic in log['topics']]
    log_data = log['data']
    event = registry_proxy.translator.decode_event(log_topics, log_data[2:].decode('hex'))
    assert (channel_manager_address == event['channel_manager_address'].decode('hex'))
    assert (token_proxy.address == event['asset_address'].decode('hex'))
    channel_manager_proxy = jsonrpc_client.new_contract_proxy(CHANNEL_MANAGER_ABI, channel_manager_address)
    transaction_hash = channel_manager_proxy.newChannel.transact(addresses[1], 10, gasprice=denoms.wei)
    jsonrpc_client.poll(transaction_hash.decode('hex'), timeout=poll_timeout)
    log_list = jsonrpc_client.call('eth_getLogs', {'fromBlock': '0x0', 'toBlock': 'latest', 'topics': []})
    assert (len(log_list) == 2)