def test_api_testnet_token_mint(api_server_test_instance: APIServer, token_addresses): user_address = factories.make_checksum_address() token_address = token_addresses[0] url = api_url_for(api_server_test_instance, "tokensmintresource", token_address=token_address) request = grequests.post(url, json=dict(to=user_address, value=1)) response = request.send().response assert_response_with_code(response, HTTPStatus.OK) # mint method defaults to mintFor request = grequests.post(url, json=dict(to=user_address, value=10)) response = request.send().response assert_response_with_code(response, HTTPStatus.OK) # invalid due to negative value request = grequests.post(url, json=dict(to=user_address, value=-1)) response = request.send().response assert_response_with_error(response, HTTPStatus.BAD_REQUEST) # invalid due to invalid address request = grequests.post(url, json=dict(to=user_address[:-2], value=10)) response = request.send().response assert_response_with_error(response, HTTPStatus.BAD_REQUEST)
def test_api_channel_set_reveal_timeout( api_server_test_instance: APIServer, raiden_network: List[RaidenService], token_addresses, settle_timeout, ): app0, app1 = raiden_network token_address = token_addresses[0] partner_address = app1.address request = grequests.patch( api_url_for( api_server_test_instance, "channelsresourcebytokenandpartneraddress", token_address=token_address, partner_address=partner_address, ), json=dict(reveal_timeout=0), ) response = request.send().response assert_response_with_error(response, HTTPStatus.CONFLICT) request = grequests.patch( api_url_for( api_server_test_instance, "channelsresourcebytokenandpartneraddress", token_address=token_address, partner_address=partner_address, ), json=dict(reveal_timeout=settle_timeout + 1), ) response = request.send().response assert_response_with_error(response, HTTPStatus.CONFLICT) reveal_timeout = int(settle_timeout / 2) request = grequests.patch( api_url_for( api_server_test_instance, "channelsresourcebytokenandpartneraddress", token_address=token_address, partner_address=partner_address, ), json=dict(reveal_timeout=reveal_timeout), ) response = request.send().response assert_response_with_code(response, HTTPStatus.OK) token_network_address = views.get_token_network_address_by_token_address( views.state_from_raiden(app0), app0.default_registry.address, token_address) assert token_network_address channel_state = views.get_channelstate_by_token_network_and_partner( chain_state=views.state_from_raiden(app0), token_network_address=token_network_address, partner_address=app1.address, ) assert channel_state assert channel_state.reveal_timeout == reveal_timeout
def test_api_channel_withdraw(api_server_test_instance: APIServer, raiden_network: List[RaidenService], token_addresses): _, app1 = raiden_network token_address = token_addresses[0] partner_address = app1.address # Withdraw a 0 amount request = grequests.patch( api_url_for( api_server_test_instance, "channelsresourcebytokenandpartneraddress", token_address=token_address, partner_address=partner_address, ), json=dict(total_withdraw="0"), ) response = request.send().response assert_response_with_error(response, HTTPStatus.CONFLICT) # Withdraw an amount larger than balance request = grequests.patch( api_url_for( api_server_test_instance, "channelsresourcebytokenandpartneraddress", token_address=token_address, partner_address=partner_address, ), json=dict(total_withdraw="1500"), ) response = request.send().response assert_response_with_error(response, HTTPStatus.CONFLICT) # Withdraw a valid amount request = grequests.patch( api_url_for( api_server_test_instance, "channelsresourcebytokenandpartneraddress", token_address=token_address, partner_address=partner_address, ), json=dict(total_withdraw="750"), ) response = request.send().response assert_response_with_code(response, HTTPStatus.OK) # Withdraw same amount as before which would sum up to more than the balance request = grequests.patch( api_url_for( api_server_test_instance, "channelsresourcebytokenandpartneraddress", token_address=token_address, partner_address=partner_address, ), json=dict(total_withdraw="750"), ) response = request.send().response assert_response_with_error(response, HTTPStatus.CONFLICT)
def test_shutdown(api_server_test_instance: APIServer): """ Node must stop after shutdown is called """ url = ("http://localhost:{port}/api/v1/shutdown").format( port=api_server_test_instance.config.port) response = grequests.post(url).send().response assert_response_with_code(response, HTTPStatus.OK) finished = gevent.joinall({api_server_test_instance}, timeout=10, raise_error=True) assert finished, "The Raiden node did not shut down!"
def test_payload_with_invalid_addresses(api_server_test_instance: APIServer): """ Addresses require leading 0x in the payload. """ invalid_address = "61c808d82a3ac53231750dadc13c777b59310bd9" channel_data_obj = { "partner_address": invalid_address, "token_address": "0xEA674fdDe714fd979de3EdF0F56AA9716B898ec8", "settle_timeout": "10", } request = grequests.put(api_url_for(api_server_test_instance, "channelsresource"), json=channel_data_obj) response = request.send().response assert_response_with_error(response, HTTPStatus.BAD_REQUEST) url_without_prefix = ( "http://localhost:{port}/api/v1/channels/ea674fdde714fd979de3edf0f56aa9716b898ec8" ).format(port=api_server_test_instance.config.port) request = grequests.patch( url_without_prefix, json=dict(state=ChannelState.STATE_SETTLED.value)) response = request.send().response assert_response_with_code(response, HTTPStatus.NOT_FOUND)