def test_is_channel_close_needed_paid():
    """ Close the channel if the payee transfer is paid but the payer has not paid. """
    amount = 10
    expiration = 10
    reveal_timeout = 5

    for paid_state in ('payee_contract_withdraw', 'payee_balance_proof'):
        paid_pair = make_transfer_pair(
            payer=factories.HOP1,
            payee=factories.HOP2,
            initiator=factories.HOP3,
            target=factories.HOP4,
            amount=amount,
            expiration=expiration,
            reveal_timeout=reveal_timeout,
        )

        paid_pair.payee_state = paid_state
        assert paid_pair.payer_route.state == CHANNEL_STATE_OPENED

        safe_block = expiration - reveal_timeout - 1
        assert mediator.is_channel_close_needed(paid_pair, safe_block) is False

        unsafe_block = expiration - reveal_timeout
        assert mediator.is_channel_close_needed(paid_pair, unsafe_block) is True
def test_is_channel_close_need_channel_closed():
    """ If the channel is already closed the anser is always no. """
    amount = 10
    expiration = 10
    reveal_timeout = 5

    for state in MediationPairState.valid_payee_states:
        pair = make_transfer_pair(
            payer=factories.HOP1,
            payee=factories.HOP2,
            initiator=factories.HOP3,
            target=factories.HOP4,
            amount=amount,
            expiration=expiration,
            reveal_timeout=reveal_timeout,
        )

        pair.payee_state = state
        pair.payer_route.state = CHANNEL_STATE_CLOSED

        safe_block = expiration - reveal_timeout - 1
        assert mediator.is_channel_close_needed(pair, safe_block) is False

        unsafe_block = expiration - reveal_timeout
        assert mediator.is_channel_close_needed(pair, unsafe_block) is False
def test_is_channel_close_needed_unpaid():
    """ Don't close the channel if the payee transfer is not paid. """
    amount = 10
    expiration = 10
    reveal_timeout = 5

    # even if the secret is known by the payee, the transfer is paid only if a
    # withdraw on-chain happened or if the mediator has sent a balance proof
    for unpaid_state in ('payee_pending', 'payee_secret_revealed', 'payee_refund_withdraw'):
        unpaid_pair = make_transfer_pair(
            payer=factories.HOP1,
            payee=factories.HOP2,
            initiator=factories.HOP3,
            target=factories.HOP4,
            amount=amount,
            expiration=expiration,
            reveal_timeout=reveal_timeout,
        )

        unpaid_pair.payer_state = unpaid_state
        assert unpaid_pair.payer_route.state == CHANNEL_STATE_OPENED

        safe_block = expiration - reveal_timeout - 1
        assert mediator.is_channel_close_needed(unpaid_pair, safe_block) is False

        unsafe_block = expiration - reveal_timeout
        assert mediator.is_channel_close_needed(unpaid_pair, unsafe_block) is False
Example #4
0
def test_is_channel_close_needed_unpaid():
    """ Don't close the channel if the payee transfer is not paid. """
    amount = 10
    expiration = 10
    reveal_timeout = 5

    # even if the secret is known by the payee, the transfer is paid only if a
    # withdraw on-chain happened or if the mediator has sent a balance proof
    for unpaid_state in ('payee_pending', 'payee_secret_revealed', 'payee_refund_withdraw'):
        unpaid_pair = make_transfer_pair(
            payer=factories.HOP1,
            payee=factories.HOP2,
            target=factories.HOP3,
            amount=amount,
            expiration=expiration,
            reveal_timeout=reveal_timeout,
        )

        unpaid_pair.payer_state = unpaid_state
        assert unpaid_pair.payer_route.state == 'available'

        safe_block = expiration - reveal_timeout - 1
        assert mediator.is_channel_close_needed(unpaid_pair, safe_block) is False

        unsafe_block = expiration - reveal_timeout
        assert mediator.is_channel_close_needed(unpaid_pair, unsafe_block) is False
def test_is_channel_close_need_channel_closed():
    """ If the channel is already closed the anser is always no. """
    amount = 10
    expiration = 10
    reveal_timeout = 5

    for state in MediationPairState.valid_payee_states:
        pair = make_transfer_pair(
            payer=factories.HOP1,
            payee=factories.HOP2,
            initiator=factories.HOP3,
            target=factories.HOP4,
            amount=amount,
            expiration=expiration,
            reveal_timeout=reveal_timeout,
        )

        pair.payee_state = state
        pair.payer_route.state = CHANNEL_STATE_CLOSED

        safe_block = expiration - reveal_timeout - 1
        assert mediator.is_channel_close_needed(pair, safe_block) is False

        unsafe_block = expiration - reveal_timeout
        assert mediator.is_channel_close_needed(pair, unsafe_block) is False
def test_is_channel_close_needed_paid():
    """ Close the channel if the payee transfer is paid but the payer has not paid. """
    amount = 10
    expiration = 10
    reveal_timeout = 5

    for paid_state in ('payee_contract_withdraw', 'payee_balance_proof'):
        paid_pair = make_transfer_pair(
            payer=factories.HOP1,
            payee=factories.HOP2,
            initiator=factories.HOP3,
            target=factories.HOP4,
            amount=amount,
            expiration=expiration,
            reveal_timeout=reveal_timeout,
        )

        paid_pair.payee_state = paid_state
        assert paid_pair.payer_route.state == CHANNEL_STATE_OPENED

        safe_block = expiration - reveal_timeout - 1
        assert mediator.is_channel_close_needed(paid_pair, safe_block) is False

        unsafe_block = expiration - reveal_timeout
        assert mediator.is_channel_close_needed(paid_pair, unsafe_block) is True
Example #7
0
def test_is_channel_close_needed_closed():
    amount = 10
    expiration = 10
    reveal_timeout = 5

    paid_pair = make_transfer_pair(
        payer=factories.HOP1,
        payee=factories.HOP2,
        target=factories.HOP3,
        amount=amount,
        expiration=expiration,
        reveal_timeout=reveal_timeout,
    )
    paid_pair.payee_state = 'payee_balance_proof'

    assert paid_pair.payer_route.state == 'available'

    safe_block = expiration - reveal_timeout - 1
    assert mediator.is_channel_close_needed(paid_pair, safe_block) is False

    unsafe_block = expiration - reveal_timeout
    assert mediator.is_channel_close_needed(paid_pair, unsafe_block) is True
def test_is_channel_close_needed_closed():
    amount = 10
    expiration = 10
    reveal_timeout = 5

    paid_pair = make_transfer_pair(
        payer=factories.HOP1,
        payee=factories.HOP2,
        initiator=factories.HOP3,
        target=factories.HOP4,
        amount=amount,
        expiration=expiration,
        reveal_timeout=reveal_timeout,
    )
    paid_pair.payee_state = 'payee_balance_proof'

    assert paid_pair.payer_route.state == CHANNEL_STATE_OPENED

    safe_block = expiration - reveal_timeout - 1
    assert mediator.is_channel_close_needed(paid_pair, safe_block) is False

    unsafe_block = expiration - reveal_timeout
    assert mediator.is_channel_close_needed(paid_pair, unsafe_block) is True