diff --git a/docs/changelog.rst b/docs/changelog.rst index ae52988859..e90cd10c83 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -2,7 +2,7 @@ Changelog ========= -* :bug:`1138` REST and Python API close did not working if a transfer was made. +* :bug:`1138` REST and Python API close did not work if a transfer was made. * :feature:`1097` Added `--gas-price` command line option. * :feature:`1038` Introduce an upper limit for the ``settle_timeout`` attribute of the netting channel. * :bug:`1044` Rename ``/connection`` API endpoint to ``/connections`` for consistency. @@ -17,5 +17,5 @@ Changelog * :feature:`921` Add ``/api/1/connection`` API endpoint returning information about all connected token networks. * :bug:`1011` Remove ``settled`` attribute from the NettingChannel smart contract. -* :release:`0.1.0 <2017-09-12>`. +* :release:`0.1.0 <2017-09-12>` * :feature:`-` This is the `Raiden Developer Preview `_ release. Introduces a raiden test network on ropsten, the API and all the basic functionality required to use Raiden in Dapps. For more information read the `blog post `_ or the `documentation of v0.1.0 `_. diff --git a/raiden/tests/api/test_pythonapi.py b/raiden/tests/api/test_pythonapi.py index 2e436ef857..68f527f0eb 100644 --- a/raiden/tests/api/test_pythonapi.py +++ b/raiden/tests/api/test_pythonapi.py @@ -7,13 +7,13 @@ NODE_NETWORK_REACHABLE, NODE_NETWORK_UNKNOWN, ) +from raiden.tests.utils.blockchain import wait_until_block from raiden.transfer.state import ( CHANNEL_STATE_CLOSED, CHANNEL_STATE_OPENED, CHANNEL_STATE_SETTLED, ) from raiden.utils import get_contract_path -from raiden.tests.utils.blockchain import wait_until_block @pytest.mark.parametrize('privatekey_seed', ['test_token_addresses:{}']) @@ -112,7 +112,7 @@ def test_channel_lifecycle(blockchain_type, raiden_network, token_addresses, dep assert channel12.contract_balance == deposit assert api1.get_channel_list(token_address, api2.address) == [channel12] - # there is a channel open, they must be checking each other + # there is a channel open, they must be healthchecking each other assert api1.get_node_network_state(api2.address) == NODE_NETWORK_REACHABLE assert api2.get_node_network_state(api1.address) == NODE_NETWORK_REACHABLE diff --git a/raiden/tests/api/test_pythonapi_regression.py b/raiden/tests/api/test_pythonapi_regression.py index 1060e1296f..419b66a077 100644 --- a/raiden/tests/api/test_pythonapi_regression.py +++ b/raiden/tests/api/test_pythonapi_regression.py @@ -2,22 +2,57 @@ import pytest from raiden.api.python import RaidenAPI +from raiden.tests.utils.blockchain import wait_until_block +from raiden.transfer.state import ( + CHANNEL_STATE_CLOSED, + CHANNEL_STATE_SETTLED, +) @pytest.mark.parametrize('privatekey_seed', ['test_close_regression:{}']) @pytest.mark.parametrize('number_of_nodes', [2]) @pytest.mark.parametrize('channels_per_node', [1]) -def test_close_regression(raiden_network, token_addresses): +def test_close_regression(blockchain_type, raiden_network, token_addresses): """ The python api was using the wrong balance proof to close the channel, thus the close was failling if a transfer was made. """ + if blockchain_type == 'tester': + pytest.skip('event polling is not reliable') + node1, node2 = raiden_network token_address = token_addresses[0] api1 = RaidenAPI(node1.raiden) api2 = RaidenAPI(node2.raiden) + channel_list = api1.get_channel_list(token_address, node2.raiden.address) + channel12 = channel_list[0] + + token_proxy = node1.raiden.chain.token(token_address) + node1_balance_before = token_proxy.balance_of(api1.address) + node2_balance_before = token_proxy.balance_of(api2.address) + channel_balance = token_proxy.balance_of(channel12.channel_address) + amount = 10 assert api1.transfer(token_address, amount, api2.address) api1.close(token_address, api2.address) + + node1.raiden.poll_blockchain_events() + assert channel12.state == CHANNEL_STATE_CLOSED + + settlement_block = ( + channel12.external_state.closed_block + + channel12.settle_timeout + + 5 # arbitrary number of additional blocks, used to wait for the settle() call + ) + wait_until_block(node1.raiden.chain, settlement_block) + + node1.raiden.poll_blockchain_events() + assert channel12.state == CHANNEL_STATE_SETTLED + + node1_withdraw_amount = channel12.balance + node2_withdraw_amount = channel_balance - node1_withdraw_amount + + assert token_proxy.balance_of(api1.address) == node1_balance_before + node1_withdraw_amount + assert token_proxy.balance_of(api2.address) == node2_balance_before + node2_withdraw_amount