def test_same_addresses_for_payment(raiden_network, token_addresses): app0, _ = raiden_network api0 = RaidenAPI(app0.raiden) registry_address = app0.raiden.default_registry.address token_address = token_addresses[0] with pytest.raises(SamePeerAddress): api0.transfer( registry_address=registry_address, token_address=token_address, target=app0.raiden.address, amount=PaymentAmount(1), )
def test_close_regression(raiden_network, deposit, token_addresses): """ The python api was using the wrong balance proof to close the channel, thus the close was failing if a transfer was made. """ app0, app1 = raiden_network token_address = token_addresses[0] api1 = RaidenAPI(app0.raiden) api2 = RaidenAPI(app1.raiden) channel_list = api1.get_channel_list(token_address, app1.raiden.address) channel12 = channel_list[0] token_proxy = app0.raiden.chain.token(token_address) node1_balance_before = token_proxy.balance_of(api1.address) node2_balance_before = token_proxy.balance_of(api2.address) # Initialize app2 balance proof and close the channel amount = 10 assert api1.transfer(token_address, amount, api2.address) api2.channel_close(token_address, api1.address) waiting.wait_for_settle( app0.raiden, app0.raiden.default_registry.address, token_address, [channel12.identifier], app0.raiden.alarm.wait_time, ) node1_expected_balance = node1_balance_before + deposit - amount node2_expected_balance = node2_balance_before + deposit + amount assert token_proxy.balance_of(api1.address) == node1_expected_balance assert token_proxy.balance_of(api2.address) == node2_expected_balance
def test_close_regression(raiden_network, deposit, token_addresses): """ The python api was using the wrong balance proof to close the channel, thus the close was failing if a transfer was made. """ app0, app1 = raiden_network registry_address = app0.raiden.default_registry.address token_address = token_addresses[0] api1 = RaidenAPI(app0.raiden) api2 = RaidenAPI(app1.raiden) registry_address = app0.raiden.default_registry.address channel_list = api1.get_channel_list(registry_address, token_address, app1.raiden.address) channel12 = channel_list[0] token_proxy = app0.raiden.chain.token(token_address) node1_balance_before = token_proxy.balance_of(api1.address) node2_balance_before = token_proxy.balance_of(api2.address) # Initialize app2 balance proof and close the channel amount = 10 identifier = 42 assert api1.transfer( registry_address, token_address, amount, api2.address, identifier=identifier, ) exception = ValueError( 'Waiting for transfer received success in the WAL timed out') with gevent.Timeout(seconds=5, exception=exception): waiting.wait_for_transfer_success( app1.raiden, identifier, amount, app1.raiden.alarm.sleep_time, ) api2.channel_close(registry_address, token_address, api1.address) waiting.wait_for_settle( app0.raiden, app0.raiden.default_registry.address, token_address, [channel12.identifier], app0.raiden.alarm.sleep_time, ) node1_expected_balance = node1_balance_before + deposit - amount node2_expected_balance = node2_balance_before + deposit + amount assert token_proxy.balance_of(api1.address) == node1_expected_balance assert token_proxy.balance_of(api2.address) == node2_expected_balance
def test_close_regression(raiden_network, deposit, token_addresses): """ The python api was using the wrong balance proof to close the channel, thus the close was failing if a transfer was made. """ app0, app1 = raiden_network registry_address = app0.raiden.default_registry.address token_address = token_addresses[0] api1 = RaidenAPI(app0.raiden) api2 = RaidenAPI(app1.raiden) registry_address = app0.raiden.default_registry.address channel_list = api1.get_channel_list(registry_address, token_address, app1.raiden.address) channel12 = channel_list[0] token_proxy = app0.raiden.chain.token(token_address) node1_balance_before = token_proxy.balance_of(api1.address) node2_balance_before = token_proxy.balance_of(api2.address) # Initialize app2 balance proof and close the channel amount = 10 identifier = 42 assert api1.transfer( registry_address, token_address, amount, api2.address, identifier=identifier, ) exception = ValueError('Waiting for transfer received success in the WAL timed out') with gevent.Timeout(seconds=5, exception=exception): waiting.wait_for_transfer_success( app1.raiden, identifier, amount, app1.raiden.alarm.sleep_time, ) api2.channel_close(registry_address, token_address, api1.address) waiting.wait_for_settle( app0.raiden, app0.raiden.default_registry.address, token_address, [channel12.identifier], app0.raiden.alarm.sleep_time, ) node1_expected_balance = node1_balance_before + deposit - amount node2_expected_balance = node2_balance_before + deposit + amount assert token_proxy.balance_of(api1.address) == node1_expected_balance assert token_proxy.balance_of(api2.address) == node2_expected_balance
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
def run_test_close_regression(raiden_network, deposit, token_addresses): app0, app1 = raiden_network registry_address = app0.raiden.default_registry.address token_address = token_addresses[0] api1 = RaidenAPI(app0.raiden) api2 = RaidenAPI(app1.raiden) registry_address = app0.raiden.default_registry.address channel_list = api1.get_channel_list(registry_address, token_address, app1.raiden.address) channel12 = channel_list[0] token_proxy = app0.raiden.chain.token(token_address) node1_balance_before = token_proxy.balance_of(api1.address) node2_balance_before = token_proxy.balance_of(api2.address) # Initialize app2 balance proof and close the channel amount = 10 identifier = 42 assert api1.transfer(registry_address, token_address, amount, api2.address, identifier=identifier, payment_hash_invoice=EMPTY_PAYMENT_HASH_INVOICE) exception = ValueError( "Waiting for transfer received success in the WAL timed out") with gevent.Timeout(seconds=5, exception=exception): waiting.wait_for_transfer_success(app1.raiden, identifier, amount, app1.raiden.alarm.sleep_time) api2.channel_close(registry_address, token_address, api1.address) waiting.wait_for_settle( app0.raiden, app0.raiden.default_registry.address, token_address, [channel12.identifier], app0.raiden.alarm.sleep_time, ) node1_expected_balance = node1_balance_before + deposit - amount node2_expected_balance = node2_balance_before + deposit + amount assert token_proxy.balance_of(api1.address) == node1_expected_balance assert token_proxy.balance_of(api2.address) == node2_expected_balance