def test_register_token_insufficient_eth(raiden_network, token_amount): app1 = raiden_network[0] registry_address = app1.raiden.default_registry.address token_address = deploy_contract_web3( CONTRACT_HUMAN_STANDARD_TOKEN, app1.raiden.chain.client, num_confirmations=None, constructor_arguments=( token_amount, 2, 'raiden', 'Rd', ), ) api1 = RaidenAPI(app1.raiden) assert token_address not in api1.get_tokens_list(registry_address) # app1.raiden loses all its ETH because it has been naughty burn_all_eth(app1.raiden) # At this point we should get the InsufficientFunds exception with pytest.raises(InsufficientFunds): api1.token_network_register(registry_address, token_address)
def test_register_token(api_backend, token_amount, token_addresses, raiden_network): app0 = raiden_network[0] new_token_address = deploy_contract_web3( CONTRACT_HUMAN_STANDARD_TOKEN, app0.raiden.chain.client, num_confirmations=None, constructor_arguments=( token_amount, 2, 'raiden', 'Rd', ), ) other_token_address = deploy_contract_web3( CONTRACT_HUMAN_STANDARD_TOKEN, app0.raiden.chain.client, num_confirmations=None, constructor_arguments=( token_amount, 2, 'raiden', 'Rd', ), ) register_request = grequests.put( api_url_for( api_backend, 'registertokenresource', token_address=to_checksum_address(new_token_address), )) register_response = register_request.send().response assert_proper_response(register_response, status_code=HTTPStatus.CREATED) response_json = register_response.json() assert 'token_network_address' in response_json assert is_checksum_address(response_json['token_network_address']) # now try to reregister it and get the error conflict_request = grequests.put( api_url_for( api_backend, 'registertokenresource', token_address=to_checksum_address(new_token_address), )) conflict_response = conflict_request.send().response assert_response_with_error(conflict_response, HTTPStatus.CONFLICT) # Burn all the eth and then make sure we get the appropriate API error burn_all_eth(app0.raiden) poor_request = grequests.put( api_url_for( api_backend, 'registertokenresource', token_address=to_checksum_address(other_token_address), )) poor_response = poor_request.send().response assert_response_with_error(poor_response, HTTPStatus.PAYMENT_REQUIRED)
def test_register_token(api_backend, token_amount, token_addresses, raiden_network): app0 = raiden_network[0] new_token_address = deploy_contract_web3( CONTRACT_HUMAN_STANDARD_TOKEN, app0.raiden.chain.client, num_confirmations=None, constructor_arguments=( token_amount, 2, 'raiden', 'Rd', ), ) other_token_address = deploy_contract_web3( CONTRACT_HUMAN_STANDARD_TOKEN, app0.raiden.chain.client, num_confirmations=None, constructor_arguments=( token_amount, 2, 'raiden', 'Rd', ), ) register_request = grequests.put(api_url_for( api_backend, 'registertokenresource', token_address=to_checksum_address(new_token_address), )) register_response = register_request.send().response assert_proper_response(register_response, status_code=HTTPStatus.CREATED) response_json = register_response.json() assert 'token_network_address' in response_json assert is_checksum_address(response_json['token_network_address']) # now try to reregister it and get the error conflict_request = grequests.put(api_url_for( api_backend, 'registertokenresource', token_address=to_checksum_address(new_token_address), )) conflict_response = conflict_request.send().response assert_response_with_error(conflict_response, HTTPStatus.CONFLICT) # Burn all the eth and then make sure we get the appropriate API error burn_all_eth(app0.raiden) poor_request = grequests.put(api_url_for( api_backend, 'registertokenresource', token_address=to_checksum_address(other_token_address), )) poor_response = poor_request.send().response assert_response_with_error(poor_response, HTTPStatus.PAYMENT_REQUIRED)
def test_api_close_insufficient_eth( api_backend, token_addresses, reveal_timeout, ): # let's create a new channel partner_address = '0x61C808D82A3Ac53231750daDc13c777b59310bD9' token_address = token_addresses[0] settle_timeout = 1650 channel_data_obj = { 'partner_address': partner_address, 'token_address': to_checksum_address(token_address), 'settle_timeout': settle_timeout, } request = grequests.put( api_url_for( api_backend, 'channelsresource', ), json=channel_data_obj, ) response = request.send().response balance = 0 assert_proper_response(response, status_code=HTTPStatus.CREATED) channel_identifier = 1 response = response.json() expected_response = channel_data_obj expected_response['balance'] = balance expected_response['state'] = CHANNEL_STATE_OPENED expected_response['reveal_timeout'] = reveal_timeout expected_response['channel_identifier'] = channel_identifier expected_response[ 'token_network_identifier'] = assert_dicts_are_equal.IGNORE_VALUE expected_response['total_deposit'] = 0 assert_dicts_are_equal(response, expected_response) # let's burn all eth and try to close the channel api_server, _ = api_backend burn_all_eth(api_server.rest_api.raiden_api.raiden) request = grequests.patch( api_url_for( api_backend, 'channelsresourcebytokenandpartneraddress', token_address=token_address, partner_address=partner_address, ), json={'state': CHANNEL_STATE_CLOSED}, ) response = request.send().response assert_proper_response(response, HTTPStatus.PAYMENT_REQUIRED) response = response.json() assert 'Insufficient ETH' in response['errors']
def test_api_close_insufficient_eth( api_backend, token_addresses, reveal_timeout, ): # let's create a new channel partner_address = '0x61C808D82A3Ac53231750daDc13c777b59310bD9' token_address = token_addresses[0] settle_timeout = 1650 channel_data_obj = { 'partner_address': partner_address, 'token_address': to_checksum_address(token_address), 'settle_timeout': settle_timeout, } request = grequests.put( api_url_for( api_backend, 'channelsresource', ), json=channel_data_obj, ) response = request.send().response balance = 0 assert_proper_response(response, status_code=HTTPStatus.CREATED) response = response.json() expected_response = channel_data_obj expected_response['balance'] = balance expected_response['state'] = CHANNEL_STATE_OPENED expected_response['reveal_timeout'] = reveal_timeout expected_response['channel_identifier'] = assert_dicts_are_equal.IGNORE_VALUE expected_response['token_network_identifier'] = assert_dicts_are_equal.IGNORE_VALUE assert_dicts_are_equal(response, expected_response) # let's burn all eth and try to close the channel api_server, _ = api_backend burn_all_eth(api_server.rest_api.raiden_api.raiden) request = grequests.patch( api_url_for( api_backend, 'channelsresourcebytokenandpartneraddress', token_address=token_address, partner_address=partner_address, ), json={'state': CHANNEL_STATE_CLOSED}, ) response = request.send().response assert_proper_response(response, HTTPStatus.PAYMENT_REQUIRED) response = response.json() assert 'Insufficient ETH' in response['errors']
def test_connect_insufficient_eth(api_backend, token_addresses): # Burn all eth and then try to connect to a token network api_server, _ = api_backend burn_all_eth(api_server.rest_api.raiden_api.raiden) funds = 100 token_address1 = to_checksum_address(token_addresses[0]) connect_data_obj = { 'funds': funds, } request = grequests.put( api_url_for( api_backend, 'connectionsresource', token_address=token_address1, ), json=connect_data_obj, ) response = request.send().response assert_proper_response(response, HTTPStatus.PAYMENT_REQUIRED) response = response.json() assert 'Insufficient ETH' in response['errors']
def test_api_open_and_deposit_channel( api_backend, token_addresses, reveal_timeout, ): # let's create a new channel first_partner_address = '0x61C808D82A3Ac53231750daDc13c777b59310bD9' token_address = token_addresses[0] settle_timeout = 1650 channel_data_obj = { 'partner_address': first_partner_address, 'token_address': to_checksum_address(token_address), 'settle_timeout': settle_timeout, 'reveal_timeout': reveal_timeout, } request = grequests.put( api_url_for( api_backend, 'channelsresource', ), json=channel_data_obj, ) response = request.send().response assert_proper_response(response, HTTPStatus.CREATED) response = response.json() expected_response = channel_data_obj expected_response['balance'] = 0 expected_response['state'] = CHANNEL_STATE_OPENED expected_response[ 'channel_identifier'] = assert_dicts_are_equal.IGNORE_VALUE expected_response[ 'token_network_identifier'] = assert_dicts_are_equal.IGNORE_VALUE assert_dicts_are_equal(response, expected_response) token_network_identifier = response['token_network_identifier'] # now let's open a channel and make a deposit too second_partner_address = '0x29FA6cf0Cce24582a9B20DB94Be4B6E017896038' balance = 100 channel_data_obj = { 'partner_address': second_partner_address, 'token_address': to_checksum_address(token_address), 'settle_timeout': settle_timeout, 'reveal_timeout': reveal_timeout, 'balance': balance, } request = grequests.put( api_url_for( api_backend, 'channelsresource', ), json=channel_data_obj, ) response = request.send().response assert_proper_response(response, HTTPStatus.CREATED) response = response.json() expected_response = channel_data_obj expected_response['balance'] = balance expected_response['state'] = CHANNEL_STATE_OPENED expected_response[ 'channel_identifier'] = assert_dicts_are_equal.IGNORE_VALUE expected_response['token_network_identifier'] = token_network_identifier assert_dicts_are_equal(response, expected_response) # assert depositing negative amount fails request = grequests.patch( api_url_for( api_backend, 'channelsresourcebytokenandpartneraddress', token_address=token_address, partner_address=first_partner_address, ), json={'total_deposit': -1000}, ) response = request.send().response assert_proper_response(response, HTTPStatus.CONFLICT) # let's deposit on the first channel request = grequests.patch( api_url_for( api_backend, 'channelsresourcebytokenandpartneraddress', token_address=token_address, partner_address=first_partner_address, ), json={'total_deposit': balance}, ) response = request.send().response assert_proper_response(response) response = response.json() expected_response = { 'channel_identifier': assert_dicts_are_equal.IGNORE_VALUE, 'partner_address': first_partner_address, 'token_address': to_checksum_address(token_address), 'settle_timeout': settle_timeout, 'reveal_timeout': reveal_timeout, 'state': CHANNEL_STATE_OPENED, 'balance': balance, 'token_network_identifier': token_network_identifier, } assert_dicts_are_equal(response, expected_response) # let's try querying for the second channel request = grequests.get( api_url_for( api_backend, 'channelsresourcebytokenandpartneraddress', token_address=token_address, partner_address=second_partner_address, ), ) response = request.send().response assert_proper_response(response) response = response.json() expected_response = { 'channel_identifier': assert_dicts_are_equal.IGNORE_VALUE, 'partner_address': second_partner_address, 'token_address': to_checksum_address(token_address), 'settle_timeout': settle_timeout, 'reveal_timeout': reveal_timeout, 'state': CHANNEL_STATE_OPENED, 'balance': balance, 'token_network_identifier': token_network_identifier, } assert_dicts_are_equal(response, expected_response) # finally let's burn all eth and try to open another channel api_server, _ = api_backend burn_all_eth(api_server.rest_api.raiden_api.raiden) channel_data_obj = { 'partner_address': '0xf3AF96F89b3d7CdcBE0C083690A28185Feb0b3CE', 'token_address': to_checksum_address(token_address), 'settle_timeout': settle_timeout, 'reveal_timeout': reveal_timeout, 'balance': 1, } request = grequests.put( api_url_for( api_backend, 'channelsresource', ), json=channel_data_obj, ) response = request.send().response assert_proper_response(response, HTTPStatus.PAYMENT_REQUIRED) response = response.json() assert 'The account balance is below the estimated amount' in response[ 'errors']
def test_api_open_and_deposit_channel( api_backend, token_addresses, reveal_timeout, ): # let's create a new channel first_partner_address = '0x61C808D82A3Ac53231750daDc13c777b59310bD9' token_address = token_addresses[0] settle_timeout = 1650 channel_data_obj = { 'partner_address': first_partner_address, 'token_address': to_checksum_address(token_address), 'settle_timeout': settle_timeout, 'reveal_timeout': reveal_timeout, } request = grequests.put( api_url_for( api_backend, 'channelsresource', ), json=channel_data_obj, ) response = request.send().response assert_proper_response(response, HTTPStatus.CREATED) response = response.json() expected_response = channel_data_obj expected_response['balance'] = 0 expected_response['state'] = CHANNEL_STATE_OPENED expected_response['channel_identifier'] = assert_dicts_are_equal.IGNORE_VALUE expected_response['token_network_identifier'] = assert_dicts_are_equal.IGNORE_VALUE assert_dicts_are_equal(response, expected_response) token_network_identifier = response['token_network_identifier'] # now let's open a channel and make a deposit too second_partner_address = '0x29FA6cf0Cce24582a9B20DB94Be4B6E017896038' balance = 100 channel_data_obj = { 'partner_address': second_partner_address, 'token_address': to_checksum_address(token_address), 'settle_timeout': settle_timeout, 'reveal_timeout': reveal_timeout, 'balance': balance, } request = grequests.put( api_url_for( api_backend, 'channelsresource', ), json=channel_data_obj, ) response = request.send().response assert_proper_response(response, HTTPStatus.CREATED) response = response.json() expected_response = channel_data_obj expected_response['balance'] = balance expected_response['state'] = CHANNEL_STATE_OPENED expected_response['channel_identifier'] = assert_dicts_are_equal.IGNORE_VALUE expected_response['token_network_identifier'] = token_network_identifier assert_dicts_are_equal(response, expected_response) # let's deposit on the first channel request = grequests.patch( api_url_for( api_backend, 'channelsresourcebytokenandpartneraddress', token_address=token_address, partner_address=first_partner_address, ), json={'total_deposit': balance}, ) response = request.send().response assert_proper_response(response) response = response.json() expected_response = { 'channel_identifier': assert_dicts_are_equal.IGNORE_VALUE, 'partner_address': first_partner_address, 'token_address': to_checksum_address(token_address), 'settle_timeout': settle_timeout, 'reveal_timeout': reveal_timeout, 'state': CHANNEL_STATE_OPENED, 'balance': balance, 'token_network_identifier': token_network_identifier, } assert_dicts_are_equal(response, expected_response) # let's try querying for the second channel request = grequests.get( api_url_for( api_backend, 'channelsresourcebytokenandpartneraddress', token_address=token_address, partner_address=second_partner_address, ), ) response = request.send().response assert_proper_response(response) response = response.json() expected_response = { 'channel_identifier': assert_dicts_are_equal.IGNORE_VALUE, 'partner_address': second_partner_address, 'token_address': to_checksum_address(token_address), 'settle_timeout': settle_timeout, 'reveal_timeout': reveal_timeout, 'state': CHANNEL_STATE_OPENED, 'balance': balance, 'token_network_identifier': token_network_identifier, } assert_dicts_are_equal(response, expected_response) # finally let's burn all eth and try to open another channel api_server, _ = api_backend burn_all_eth(api_server.rest_api.raiden_api.raiden) channel_data_obj = { 'partner_address': '0xf3AF96F89b3d7CdcBE0C083690A28185Feb0b3CE', 'token_address': to_checksum_address(token_address), 'settle_timeout': settle_timeout, 'reveal_timeout': reveal_timeout, 'balance': 1, } request = grequests.put( api_url_for( api_backend, 'channelsresource', ), json=channel_data_obj, ) response = request.send().response assert_proper_response(response, HTTPStatus.PAYMENT_REQUIRED) response = response.json() assert 'Insufficient ETH' in response['errors']