コード例 #1
0
def test_api_channel_open_channel_invalid_input(
        api_server_test_instance: APIServer, token_addresses, reveal_timeout):
    partner_address = "0x61C808D82A3Ac53231750daDc13c777b59310bD9"
    token_address = token_addresses[0]
    settle_timeout = TEST_SETTLE_TIMEOUT_MIN - 1
    channel_data_obj = {
        "partner_address": partner_address,
        "token_address": to_checksum_address(token_address),
        "settle_timeout": str(settle_timeout),
        "reveal_timeout": str(reveal_timeout),
    }
    request = grequests.put(api_url_for(api_server_test_instance,
                                        "channelsresource"),
                            json=channel_data_obj)
    response = request.send().response
    assert_response_with_error(response, status_code=HTTPStatus.CONFLICT)

    channel_data_obj["settle_timeout"] = str(TEST_SETTLE_TIMEOUT_MAX + 1)
    request = grequests.put(api_url_for(api_server_test_instance,
                                        "channelsresource"),
                            json=channel_data_obj)
    response = request.send().response
    assert_response_with_error(response, status_code=HTTPStatus.CONFLICT)

    channel_data_obj["settle_timeout"] = str(TEST_SETTLE_TIMEOUT_MAX - 1)
    channel_data_obj["token_address"] = to_checksum_address(
        factories.make_address())
    request = grequests.put(api_url_for(api_server_test_instance,
                                        "channelsresource"),
                            json=channel_data_obj)
    response = request.send().response
    assert_response_with_error(response, status_code=HTTPStatus.CONFLICT)
コード例 #2
0
def test_get_connection_managers_info(api_server_test_instance: APIServer,
                                      token_addresses):
    # check that there are no registered tokens
    request = grequests.get(
        api_url_for(api_server_test_instance, "connectionsinforesource"))
    response = request.send().response
    result = get_json_response(response)
    assert len(result) == 0

    funds = 100
    token_address1 = to_checksum_address(token_addresses[0])
    connect_data_obj = {"funds": funds}
    request = grequests.put(
        api_url_for(api_server_test_instance,
                    "connectionsresource",
                    token_address=token_address1),
        json=connect_data_obj,
    )
    response = request.send().response
    assert_no_content_response(response)

    # check that there now is one registered channel manager
    request = grequests.get(
        api_url_for(api_server_test_instance, "connectionsinforesource"))
    response = request.send().response
    result = get_json_response(response)
    assert isinstance(result, dict) and len(result.keys()) == 1
    assert token_address1 in result
    assert isinstance(result[token_address1], dict)
    assert set(result[token_address1].keys()) == {
        "funds", "sum_deposits", "channels"
    }
コード例 #3
0
def test_channel_events(api_server_test_instance: APIServer, token_addresses):
    # 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": str(settle_timeout),
    }
    request = grequests.put(api_url_for(api_server_test_instance,
                                        "channelsresource"),
                            json=channel_data_obj)
    response = request.send().response

    assert_proper_response(response, status_code=HTTPStatus.CREATED)

    request = grequests.get(
        api_url_for(
            api_server_test_instance,
            "tokenchanneleventsresourceblockchain",
            token_address=token_address,
            from_block=str(GENESIS_BLOCK_NUMBER),
        ))
    response = request.send().response
    assert_proper_response(response, status_code=HTTPStatus.OK)
    assert len(get_json_response(response)) > 0
コード例 #4
0
def test_get_connections_info(
    raiden_network: List[RaidenService],
    api_server_test_instance: APIServer,
    token_addresses: List[TokenAddress],
):
    token_address = token_addresses[0]

    # Check that there are no registered tokens
    request = grequests.get(
        api_url_for(api_server_test_instance, "connectionsinforesource"))
    response = request.send().response
    result = get_json_response(response)
    assert len(result) == 0

    # Create a channel
    app0 = raiden_network[0]
    RaidenAPI(app0).channel_open(
        registry_address=app0.default_registry.address,
        token_address=token_address,
        partner_address=factories.make_address(),
    )

    # Check that there is a channel for one token, now
    cs_token_address = to_checksum_address(token_address)
    request = grequests.get(
        api_url_for(api_server_test_instance, "connectionsinforesource"))
    response = request.send().response
    result = get_json_response(response)
    assert isinstance(result, dict) and len(result.keys()) == 1
    assert cs_token_address in result
    assert isinstance(result[cs_token_address], dict)
    assert set(result[cs_token_address].keys()) == {"sum_deposits", "channels"}
コード例 #5
0
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
コード例 #6
0
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)
コード例 #7
0
def test_get_token_network_for_token(
    api_server_test_instance,
    token_amount,
    token_addresses,
    raiden_network: List[RaidenService],
    contract_manager,
    retry_timeout,
    unregistered_token,
):
    app0 = raiden_network[0]
    new_token_address = unregistered_token

    # Wait until Raiden can start using the token contract.
    # Here, the block at which the contract was deployed should be confirmed by Raiden.
    # Therefore, until that block is received.
    wait_for_block(
        raiden=app0,
        block_number=BlockNumber(app0.get_block_number() +
                                 DEFAULT_NUMBER_OF_BLOCK_CONFIRMATIONS + 1),
        retry_timeout=retry_timeout,
    )

    # unregistered token returns 404
    token_request = grequests.get(
        api_url_for(
            api_server_test_instance,
            "registertokenresource",
            token_address=to_checksum_address(new_token_address),
        ))
    token_response = token_request.send().response
    assert_proper_response(token_response, status_code=HTTPStatus.NOT_FOUND)

    # register token
    register_request = grequests.put(
        api_url_for(
            api_server_test_instance,
            "registertokenresource",
            token_address=to_checksum_address(new_token_address),
        ))
    register_response = register_request.send().response
    assert_proper_response(register_response, status_code=HTTPStatus.CREATED)
    token_network_address = get_json_response(
        register_response)["token_network_address"]

    wait_for_token_network(app0, app0.default_registry.address,
                           new_token_address, 0.1)

    # now it should return the token address
    token_request = grequests.get(
        api_url_for(
            api_server_test_instance,
            "registertokenresource",
            token_address=to_checksum_address(new_token_address),
        ))
    token_response = token_request.send().response
    assert_proper_response(token_response, status_code=HTTPStatus.OK)
    assert token_network_address == get_json_response(token_response)
コード例 #8
0
ファイル: test_payments.py プロジェクト: weilbith/raiden
def test_api_payments_with_invalid_input(api_server_test_instance: APIServer,
                                         raiden_network, token_addresses):
    _, app1 = raiden_network
    amount = 100
    token_address = token_addresses[0]
    target_address = app1.raiden.address
    settle_timeout = 39

    # Invalid identifier being 0 or negative
    request = grequests.post(
        api_url_for(
            api_server_test_instance,
            "token_target_paymentresource",
            token_address=to_checksum_address(token_address),
            target_address=to_checksum_address(target_address),
        ),
        json={
            "amount": str(amount),
            "identifier": "0",
            "lock_timeout": str(settle_timeout)
        },
    )
    response = request.send().response
    assert_response_with_error(response, status_code=HTTPStatus.CONFLICT)

    request = grequests.post(
        api_url_for(
            api_server_test_instance,
            "token_target_paymentresource",
            token_address=to_checksum_address(token_address),
            target_address=to_checksum_address(target_address),
        ),
        json={
            "amount": str(amount),
            "identifier": "-1",
            "lock_timeout": str(settle_timeout)
        },
    )
    response = request.send().response
    assert_response_with_error(response, status_code=HTTPStatus.CONFLICT)

    request = grequests.post(
        api_url_for(
            api_server_test_instance,
            "token_target_paymentresource",
            token_address=to_checksum_address(token_address),
            target_address=to_checksum_address(target_address),
        ),
        json={
            "amount": str(amount),
            "identifier": str(UINT64_MAX + 1),
            "lock_timeout": str(settle_timeout),
        },
    )
    response = request.send().response
    assert_response_with_error(response, status_code=HTTPStatus.CONFLICT)
コード例 #9
0
ファイル: test_payments.py プロジェクト: weilbith/raiden
def test_api_payments_target_error(api_server_test_instance: APIServer,
                                   raiden_network, token_addresses):
    _, app1 = raiden_network
    amount = 200
    identifier = 42
    token_address = token_addresses[0]
    target_address = app1.raiden.address

    # stop app1 to force an error
    app1.stop()

    request = grequests.post(
        api_url_for(
            api_server_test_instance,
            "token_target_paymentresource",
            token_address=to_checksum_address(token_address),
            target_address=to_checksum_address(target_address),
        ),
        json={
            "amount": str(amount),
            "identifier": str(identifier)
        },
    )
    response = request.send().response
    assert_proper_response(response, status_code=HTTPStatus.CONFLICT)
コード例 #10
0
ファイル: test_token_networks.py プロジェクト: sekmet/raiden
def test_register_token_without_balance(
    api_server_test_instance,
    token_amount,
    raiden_network: List[RaidenService],
    contract_manager,
    retry_timeout,
):
    app0 = raiden_network[0]
    contract_proxy, _ = app0.rpc_client.deploy_single_contract(
        contract_name=CONTRACT_HUMAN_STANDARD_TOKEN,
        contract=contract_manager.get_contract(CONTRACT_HUMAN_STANDARD_TOKEN),
        constructor_parameters=(token_amount, 2, "raiden", "Rd2"),
    )
    new_token_address = Address(to_canonical_address(contract_proxy.address))

    # Wait until Raiden can start using the token contract.
    # Here, the block at which the contract was deployed should be confirmed by Raiden.
    # Therefore, until that block is received.
    wait_for_block(
        raiden=app0,
        block_number=BlockNumber(app0.get_block_number() +
                                 DEFAULT_NUMBER_OF_BLOCK_CONFIRMATIONS + 1),
        retry_timeout=retry_timeout,
    )

    # Burn all the eth and then make sure we get the appropriate API error
    burn_eth(app0.rpc_client)
    poor_request = grequests.put(
        api_url_for(
            api_server_test_instance,
            "registertokenresource",
            token_address=to_checksum_address(new_token_address),
        ))
    poor_response = poor_request.send().response
    assert_response_with_error(poor_response, HTTPStatus.PAYMENT_REQUIRED)
コード例 #11
0
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)

    # trying to mint with no ETH
    burn_eth(api_server_test_instance.rest_api.raiden_api.raiden.rpc_client)
    request = grequests.post(url, json=dict(to=user_address, value=1))
    response = request.send().response
    assert_response_with_code(response, HTTPStatus.PAYMENT_REQUIRED)
コード例 #12
0
def test_api_channel_close_insufficient_eth(
        api_server_test_instance: APIServer, 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": str(settle_timeout),
    }
    request = grequests.put(api_url_for(api_server_test_instance,
                                        "channelsresource"),
                            json=channel_data_obj)
    response = request.send().response

    balance = 0
    assert_proper_response(response, status_code=HTTPStatus.CREATED)
    channel_identifier = 1
    json_response = get_json_response(response)
    expected_response = channel_data_obj.copy()
    expected_response.update({
        "balance": str(balance),
        "state": ChannelState.STATE_OPENED.value,
        "reveal_timeout": str(reveal_timeout),
        "channel_identifier": str(channel_identifier),
        "total_deposit": "0",
    })
    assert check_dict_nested_attrs(json_response, expected_response)

    # let's burn all eth and try to close the channel
    burn_eth(api_server_test_instance.rest_api.raiden_api.raiden.rpc_client)
    request = grequests.patch(
        api_url_for(
            api_server_test_instance,
            "channelsresourcebytokenandpartneraddress",
            token_address=token_address,
            partner_address=partner_address,
        ),
        json={"state": ChannelState.STATE_CLOSED.value},
    )
    response = request.send().response
    assert_proper_response(response, HTTPStatus.PAYMENT_REQUIRED)
    json_response = get_json_response(response)
    assert "insufficient ETH" in json_response["errors"]
コード例 #13
0
def test_api_get_raiden_version(api_server_test_instance: APIServer):
    request = grequests.get(
        api_url_for(api_server_test_instance, "versionresource"))
    response = request.send().response
    assert_proper_response(response)

    raiden_version = get_system_spec()["raiden"]

    assert get_json_response(response) == {"version": raiden_version}
コード例 #14
0
def test_api_query_our_address(api_server_test_instance: APIServer):
    request = grequests.get(
        api_url_for(api_server_test_instance, "addressresource"))
    response = request.send().response
    assert_proper_response(response)

    our_address = api_server_test_instance.rest_api.raiden_api.address
    assert get_json_response(response) == {
        "our_address": to_checksum_address(our_address)
    }
コード例 #15
0
def test_api_get_node_settings(api_server_test_instance: APIServer):
    request = grequests.get(
        api_url_for(api_server_test_instance, "nodesettingsresource"))
    response = request.send().response
    assert_proper_response(response)

    pfs_config = api_server_test_instance.rest_api.raiden_api.raiden.config.pfs_config
    assert get_json_response(response) == {
        "pathfinding_service_address": pfs_config and pfs_config.info.url
    }
コード例 #16
0
def test_api_payments_post_without_required_params(api_server_test_instance,
                                                   token_addresses):
    token_address = token_addresses[0]

    request = grequests.post(
        api_url_for(
            api_server_test_instance,
            "paymentresource",
        ), )
    response = request.send().response
    assert_proper_response(response, status_code=HTTPStatus.METHOD_NOT_ALLOWED)

    request = grequests.post(
        api_url_for(
            api_server_test_instance,
            "token_paymentresource",
            token_address=to_checksum_address(token_address),
        ), )
    response = request.send().response
    assert_proper_response(response, status_code=HTTPStatus.METHOD_NOT_ALLOWED)
コード例 #17
0
def test_api_tokens(api_server_test_instance: APIServer, blockchain_services,
                    token_addresses):
    partner_address = "0x61C808D82A3Ac53231750daDc13c777b59310bD9"
    token_address1 = token_addresses[0]
    token_address2 = token_addresses[1]
    settle_timeout = 1650

    channel_data_obj = {
        "partner_address": partner_address,
        "token_address": to_checksum_address(token_address1),
        "settle_timeout": str(settle_timeout),
    }
    request = grequests.put(api_url_for(api_server_test_instance,
                                        "channelsresource"),
                            json=channel_data_obj)
    response = request.send().response
    assert_proper_response(response, HTTPStatus.CREATED)

    settle_timeout = 1650
    channel_data_obj = {
        "partner_address": partner_address,
        "token_address": to_checksum_address(token_address2),
        "settle_timeout": str(settle_timeout),
    }
    request = grequests.put(api_url_for(api_server_test_instance,
                                        "channelsresource"),
                            json=channel_data_obj)
    response = request.send().response
    assert_proper_response(response, HTTPStatus.CREATED)

    # and now let's get the token list
    request = grequests.get(
        api_url_for(api_server_test_instance, "tokensresource"))
    response = request.send().response
    assert_proper_response(response)
    json_response = get_json_response(response)
    expected_response = [
        to_checksum_address(token_address1),
        to_checksum_address(token_address2)
    ]
    assert set(json_response) == set(expected_response)
コード例 #18
0
def test_payload_with_address_not_eip55(api_server_test_instance: APIServer):
    """ Provided addresses must be EIP55 encoded. """
    invalid_address = "0xf696209d2ca35e6c88e5b99b7cda3abf316bed69"
    channel_data_obj = {
        "partner_address": invalid_address,
        "token_address": "0xEA674fdDe714fd979de3EdF0F56AA9716B898ec8",
        "settle_timeout": "90",
    }
    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)
コード例 #19
0
def test_api_get_channel_list(api_server_test_instance: APIServer,
                              token_addresses, reveal_timeout):
    partner_address = "0x61C808D82A3Ac53231750daDc13c777b59310bD9"

    request = grequests.get(
        api_url_for(api_server_test_instance, "channelsresource"))
    response = request.send().response
    assert_proper_response(response, HTTPStatus.OK)

    json_response = get_json_response(response)
    assert json_response == []

    # let's create a new channel
    token_address = token_addresses[0]
    settle_timeout = 1650
    channel_data_obj = {
        "partner_address": partner_address,
        "token_address": to_checksum_address(token_address),
        "settle_timeout": str(settle_timeout),
        "reveal_timeout": str(reveal_timeout),
    }

    request = grequests.put(api_url_for(api_server_test_instance,
                                        "channelsresource"),
                            json=channel_data_obj)
    response = request.send().response

    assert_proper_response(response, HTTPStatus.CREATED)

    request = grequests.get(
        api_url_for(api_server_test_instance, "channelsresource"))
    response = request.send().response
    assert_proper_response(response, HTTPStatus.OK)
    json_response = get_json_response(response)
    channel_info = json_response[0]
    assert channel_info["partner_address"] == partner_address
    assert channel_info["token_address"] == to_checksum_address(token_address)
    assert channel_info["total_deposit"] == "0"
    assert "token_network_address" in channel_info
コード例 #20
0
def test_payload_with_address_invalid_length(
        api_server_test_instance: APIServer):
    """ Encoded addresses must have the right length. """
    invalid_address = "0x61c808d82a3ac53231750dadc13c777b59310b"  # one char short
    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)
コード例 #21
0
def test_payload_with_address_invalid_chars(
        api_server_test_instance: APIServer):
    """ Addresses cannot have invalid characters in it. """
    invalid_address = "0x61c808d82a3ac53231750dadc13c777b59310bdg"  # g at the end is invalid
    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)
コード例 #22
0
def test_token_events_errors_for_unregistered_token(api_server_test_instance):
    request = grequests.get(
        api_url_for(
            api_server_test_instance,
            "tokenchanneleventsresourceblockchain",
            token_address="0x61C808D82A3Ac53231750daDc13c777b59310bD9",
            from_block="5",
            to_block="20",
        ))
    response = request.send().response
    assert_response_with_error(response, status_code=HTTPStatus.NOT_FOUND)

    request = grequests.get(
        api_url_for(
            api_server_test_instance,
            "channelblockchaineventsresource",
            token_address="0x61C808D82A3Ac53231750daDc13c777b59310bD9",
            partner_address="0x61C808D82A3Ac53231750daDc13c777b59313bD9",
            from_block="5",
            to_block="20",
        ))
    response = request.send().response
    assert_response_with_error(response, status_code=HTTPStatus.NOT_FOUND)
コード例 #23
0
def test_api_channel_status_channel_nonexistant(
        api_server_test_instance: APIServer, token_addresses):
    partner_address = "0x61C808D82A3Ac53231750daDc13c777b59310bD9"
    token_address = token_addresses[0]

    request = grequests.get(
        api_url_for(
            api_server_test_instance,
            "channelsresourcebytokenandpartneraddress",
            token_address=token_address,
            partner_address=partner_address,
        ))
    response = request.send().response
    assert_proper_response(response, HTTPStatus.NOT_FOUND)
    assert get_json_response(response)["errors"] == (
        "Channel with partner '{}' for token '{}' could not be found.".format(
            to_checksum_address(partner_address),
            to_checksum_address(token_address)))
コード例 #24
0
def test_connect_insufficient_reserve(api_server_test_instance: APIServer,
                                      token_addresses):

    # Burn all eth and then try to connect to a token network
    burn_eth(api_server_test_instance.rest_api.raiden_api.raiden.rpc_client)
    funds = 100
    token_address1 = to_checksum_address(token_addresses[0])
    connect_data_obj = {"funds": funds}
    request = grequests.put(
        api_url_for(api_server_test_instance,
                    "connectionsresource",
                    token_address=token_address1),
        json=connect_data_obj,
    )
    response = request.send().response
    assert_proper_response(response, HTTPStatus.PAYMENT_REQUIRED)
    json_response = get_json_response(response)
    assert "The account balance is below the estimated amount" in json_response[
        "errors"]
コード例 #25
0
def test_api_get_contract_infos(api_server_test_instance: APIServer):
    request = grequests.get(
        api_url_for(api_server_test_instance, "contractsresource"))
    response = request.send().response
    assert_proper_response(response)

    json = get_json_response(response)

    assert json["contracts_version"] == CONTRACTS_VERSION
    for contract_name in [
            "token_network_registry_address",
            "secret_registry_address",
            "service_registry_address",
            "user_deposit_address",
            "monitoring_service_address",
            "one_to_n_address",
    ]:
        address = json[contract_name]
        if address is not None:
            assert is_checksum_address(address)
コード例 #26
0
ファイル: test_payments.py プロジェクト: weilbith/raiden
def test_api_payments_with_secret_and_hash(api_server_test_instance: APIServer,
                                           raiden_network, token_addresses):
    _, app1 = raiden_network
    amount = 100
    identifier = 42
    token_address = token_addresses[0]
    target_address = app1.raiden.address
    secret = to_hex(factories.make_secret())
    secret_hash = to_hex(sha256(to_bytes(hexstr=secret)).digest())

    our_address = api_server_test_instance.rest_api.raiden_api.address

    payment = {
        "initiator_address": to_checksum_address(our_address),
        "target_address": to_checksum_address(target_address),
        "token_address": to_checksum_address(token_address),
        "amount": str(amount),
        "identifier": str(identifier),
    }

    request = grequests.post(
        api_url_for(
            api_server_test_instance,
            "token_target_paymentresource",
            token_address=to_checksum_address(token_address),
            target_address=to_checksum_address(target_address),
        ),
        json={
            "amount": str(amount),
            "identifier": str(identifier),
            "secret": secret,
            "secret_hash": secret_hash,
        },
    )
    with watch_for_unlock_failures(*raiden_network):
        response = request.send().response
    assert_proper_response(response)
    json_response = get_json_response(response)
    assert_payment_secret_and_hash(json_response, payment)
    assert secret == json_response["secret"]
    assert secret_hash == json_response["secret_hash"]
コード例 #27
0
ファイル: test_token_networks.py プロジェクト: sekmet/raiden
def test_register_token_mainnet(
    api_server_test_instance: APIServer,
    token_amount,
    raiden_network: List[RaidenService],
    contract_manager,
):
    app0 = raiden_network[0]
    contract_proxy, _ = app0.rpc_client.deploy_single_contract(
        contract_name=CONTRACT_HUMAN_STANDARD_TOKEN,
        contract=contract_manager.get_contract(CONTRACT_HUMAN_STANDARD_TOKEN),
        constructor_parameters=(token_amount, 2, "raiden", "Rd"),
    )
    new_token_address = Address(to_canonical_address(contract_proxy.address))
    register_request = grequests.put(
        api_url_for(
            api_server_test_instance,
            "registertokenresource",
            token_address=to_checksum_address(new_token_address),
        ))
    response = register_request.send().response
    assert response is not None and response.status_code == HTTPStatus.NOT_IMPLEMENTED
コード例 #28
0
def test_api_payments_conflicts(api_server_test_instance: APIServer,
                                raiden_network: List[RaidenService],
                                token_addresses):
    _, app1 = raiden_network
    token_address = token_addresses[0]
    target_address = app1.address

    payment_url = api_url_for(
        api_server_test_instance,
        "token_target_paymentresource",
        token_address=to_checksum_address(token_address),
        target_address=to_checksum_address(target_address),
    )

    # two different transfers (different amounts) with same identifier at the same time:
    # payment conflict
    responses = grequests.map([
        grequests.post(payment_url, json={
            "amount": "10",
            "identifier": "11"
        }),
        grequests.post(payment_url, json={
            "amount": "11",
            "identifier": "11"
        }),
    ])
    assert_payment_conflict(responses)

    # same request sent twice, e. g. when it is retried: no conflict
    responses = grequests.map([
        grequests.post(payment_url, json={
            "amount": "10",
            "identifier": "73"
        }),
        grequests.post(payment_url, json={
            "amount": "10",
            "identifier": "73"
        }),
    ])
    assert all(response.status_code == HTTPStatus.OK for response in responses)
コード例 #29
0
def test_api_payments_with_hash_no_secret(api_server_test_instance,
                                          raiden_network, token_addresses):
    _, app1 = raiden_network
    token_address = token_addresses[0]
    target_address = app1.raiden.address
    secret_hash = factories.make_secret_hash()

    request = grequests.post(
        api_url_for(
            api_server_test_instance,
            "token_target_paymentresource",
            token_address=to_checksum_address(token_address),
            target_address=to_checksum_address(target_address),
        ),
        json={
            "amount": DEFAULT_AMOUNT,
            "identifier": DEFAULT_ID,
            "secret_hash": to_hex(secret_hash),
        },
    )
    response = request.send().response
    assert_proper_response(response, status_code=HTTPStatus.CONFLICT)
コード例 #30
0
def test_channel_events_raiden(api_server_test_instance: APIServer,
                               raiden_network, token_addresses):
    _, app1 = raiden_network
    amount = 100
    identifier = 42
    token_address = token_addresses[0]
    target_address = app1.raiden.address

    request = grequests.post(
        api_url_for(
            api_server_test_instance,
            "token_target_paymentresource",
            token_address=to_checksum_address(token_address),
            target_address=to_checksum_address(target_address),
        ),
        json={
            "amount": str(amount),
            "identifier": str(identifier)
        },
    )
    response = request.send().response
    assert_proper_response(response)