Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a test for #918 #4906

Merged
merged 4 commits into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion raiden/api/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,18 @@ def channel_open(

if settle_timeout < self.raiden.config["reveal_timeout"] * 2:
raise InvalidSettleTimeout(
"settle_timeout can not be smaller than double the reveal_timeout"
"`settle_timeout` can not be smaller than double the "
"`reveal_timeout`.\n "
"\n "
"The setting `reveal_timeout` determines the maximum number of "
"blocks it should take a transaction to be mined when the "
"blockchain is under congestion. This setting determines the "
"when a node must go on-chain to register a secret, and it is "
"therefore the lower bound of the lock expiration. The "
"`settle_timeout` determines when a channel can be settled "
"on-chain, for this operation to be safe all locks must have "
"been resolved, for this reason the `settle_timeout` has to be "
"larger than `reveal_timeout`."
)

if not is_binary_address(registry_address):
Expand Down
46 changes: 45 additions & 1 deletion raiden/tests/integration/api/test_pythonapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
from raiden.api.python import RaidenAPI
from raiden.exceptions import (
DepositMismatch,
InvalidSettleTimeout,
TokenNotRegistered,
UnexpectedChannelState,
UnknownTokenAddress,
)
from raiden.tests.utils.detect_failure import raise_on_failure
from raiden.tests.utils.events import must_have_event, wait_for_state_change
from raiden.tests.utils.factories import make_address
from raiden.tests.utils.transfer import get_channelstate
from raiden.transfer import channel, views
from raiden.transfer.state import NODE_NETWORK_REACHABLE, NODE_NETWORK_UNKNOWN, ChannelState
Expand Down Expand Up @@ -77,7 +79,9 @@ def run_test_token_addresses(raiden_network, token_addresses):
@raise_on_failure
@pytest.mark.parametrize("number_of_nodes", [2])
@pytest.mark.parametrize("channels_per_node", [0])
def test_raidenapi_channel_lifecycle(raiden_network, token_addresses, deposit, retry_timeout):
def test_raidenapi_channel_lifecycle(
raiden_network, token_addresses, deposit, retry_timeout, settle_timeout_max
):
"""Uses RaidenAPI to go through a complete channel lifecycle."""
node1, node2 = raiden_network
token_address = token_addresses[0]
Expand All @@ -101,6 +105,46 @@ def test_raidenapi_channel_lifecycle(raiden_network, token_addresses, deposit, r
registry_address=registry_address, token_address=None, partner_address=api2.address
)

address_for_lowest_settle_timeout = make_address()
lowest_valid_settle_timeout = node1.raiden.config["reveal_timeout"] * 2

# Make sure a small settle timeout is not accepted when opening a channel
with pytest.raises(InvalidSettleTimeout):
api1.channel_open(
registry_address=node1.raiden.default_registry.address,
token_address=token_address,
partner_address=address_for_lowest_settle_timeout,
settle_timeout=lowest_valid_settle_timeout - 1,
)

# Make sure a the smallest settle timeout is accepted
api1.channel_open(
registry_address=node1.raiden.default_registry.address,
token_address=token_address,
partner_address=address_for_lowest_settle_timeout,
settle_timeout=lowest_valid_settle_timeout,
)

address_for_highest_settle_timeout = make_address()
highest_valid_settle_timeout = settle_timeout_max

# Make sure a large settle timeout is not accepted when opening a channel
with pytest.raises(InvalidSettleTimeout):
api1.channel_open(
registry_address=node1.raiden.default_registry.address,
token_address=token_address,
partner_address=address_for_highest_settle_timeout,
settle_timeout=highest_valid_settle_timeout + 1,
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I was suggesting to test that channel_open will succeed for settle_timeout = node1.raiden.config["reveal_timeout"] * 2 to verify that the settle_timeout validity threshold is honored in both directions.

But maybe the condition is so simple that a test for that is overkill. Add it or leave it at your own discretion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


# Make sure the highest settle timeout is accepted
api1.channel_open(
registry_address=node1.raiden.default_registry.address,
token_address=token_address,
partner_address=address_for_highest_settle_timeout,
settle_timeout=highest_valid_settle_timeout,
)

# open is a synchronous api
api1.channel_open(node1.raiden.default_registry.address, token_address, api2.address)
channels = api1.get_channel_list(registry_address, token_address, api2.address)
Expand Down