コード例 #1
0
def test_event_operators():
    a = EventPaymentSentSuccess(1, 4, 2, 5, sha3(b"target"), b"0", [])
    b = EventPaymentSentSuccess(1, 4, 2, 5, sha3(b"target"), b"0", [])
    c = EventPaymentSentSuccess(2, 7, 3, 4, sha3(b"target"), b"0", [])
    d = EventPaymentSentSuccess(2, 7, 3, 4, sha3(b"differenttarget"), b"0", [])

    # pylint: disable=unneeded-not
    assert a == b
    assert not a != b
    assert a != c
    assert not a == c
    assert not c == d

    a = EventPaymentSentFailed(1, 7, 2, "target", "BECAUSE")
    b = EventPaymentSentFailed(1, 7, 2, "target", "BECAUSE")
    c = EventPaymentSentFailed(3, 3, 3, "target", "UNKNOWN")

    assert a == b
    assert not a != b
    assert a != c
    assert not a == c

    a = EventPaymentReceivedSuccess(4, 4, 2, 5, sha3(b"initiator"))
    b = EventPaymentReceivedSuccess(4, 4, 2, 5, sha3(b"initiator"))
    c = EventPaymentReceivedSuccess(1, 2, 3, 5, sha3(b"initiator"))
    d = EventPaymentReceivedSuccess(1, 2, 3, 5, sha3(b"other initiator"))

    assert a == b
    assert not a != b
    assert a != c
    assert not a == c
    assert c != d
    assert not c == d
コード例 #2
0
ファイル: test_operators.py プロジェクト: wx7063/raiden
def test_event_operators():
    a = EventPaymentSentSuccess(1, 4, 2, 5, sha3(b'target'))
    b = EventPaymentSentSuccess(1, 4, 2, 5, sha3(b'target'))
    c = EventPaymentSentSuccess(2, 7, 3, 4, sha3(b'target'))
    d = EventPaymentSentSuccess(2, 7, 3, 4, sha3(b'differenttarget'))

    # pylint: disable=unneeded-not
    assert a == b
    assert not a != b
    assert a != c
    assert not a == c
    assert not c == d

    a = EventPaymentSentFailed(1, 7, 2, 'target', 'BECAUSE')
    b = EventPaymentSentFailed(1, 7, 2, 'target', 'BECAUSE')
    c = EventPaymentSentFailed(3, 3, 3, 'target', 'UNKNOWN')

    assert a == b
    assert not a != b
    assert a != c
    assert not a == c

    a = EventPaymentReceivedSuccess(4, 4, 2, 5, sha3(b'initiator'))
    b = EventPaymentReceivedSuccess(4, 4, 2, 5, sha3(b'initiator'))
    c = EventPaymentReceivedSuccess(1, 2, 3, 5, sha3(b'initiator'))
    d = EventPaymentReceivedSuccess(1, 2, 3, 5, sha3(b'other initiator'))

    assert a == b
    assert not a != b
    assert a != c
    assert not a == c
    assert c != d
    assert not c == d
コード例 #3
0
ファイル: test_events.py プロジェクト: Kaitou786/raiden
def test_invalid_instantiation_event_payment_received_success():
    kwargs = dict(
        token_network_registry_address=factories.UNIT_TOKEN_NETWORK_REGISTRY_IDENTIFIER,
        token_network_address=factories.UNIT_TOKEN_NETWORK_ADDRESS,
        identifier=factories.UNIT_TRANSFER_IDENTIFIER,
        initiator=factories.make_address(),
    )

    with pytest.raises(ValueError):
        EventPaymentReceivedSuccess(amount=UINT256_MAX + 1, **kwargs)

    with pytest.raises(ValueError):
        EventPaymentReceivedSuccess(amount=-5, **kwargs)
コード例 #4
0
ファイル: target.py プロジェクト: zointblackbriar/raiden
def handle_unlock(
    target_state: TargetTransferState,
    state_change: ReceiveUnlock,
    channel_state: NettingChannelState,
) -> TransitionResult[Optional[TargetTransferState]]:
    """ Handles a ReceiveUnlock state change. """
    balance_proof_sender = state_change.balance_proof.sender

    is_valid, events, _ = channel.handle_unlock(channel_state, state_change)
    next_target_state: Optional[TargetTransferState] = target_state

    if is_valid:
        transfer = target_state.transfer
        payment_received_success = EventPaymentReceivedSuccess(
            token_network_registry_address=channel_state.token_network_registry_address,
            token_network_address=channel_state.token_network_address,
            identifier=transfer.payment_identifier,
            amount=PaymentAmount(transfer.lock.amount),
            initiator=transfer.initiator,
        )

        unlock_success = EventUnlockClaimSuccess(
            transfer.payment_identifier, transfer.lock.secrethash
        )

        send_processed = SendProcessed(
            recipient=balance_proof_sender,
            message_identifier=state_change.message_identifier,
            canonical_identifier=CANONICAL_IDENTIFIER_UNORDERED_QUEUE,
        )

        events.extend([payment_received_success, unlock_success, send_processed])
        next_target_state = None

    return TransitionResult(next_target_state, events)
コード例 #5
0
def test_event_filter_for_payments():
    secret = factories.make_secret()
    identifier = PaymentID(1)
    target = TargetAddress(factories.make_address())
    event1 = EventPaymentSentSuccess(
        token_network_registry_address=UNIT_TOKEN_NETWORK_REGISTRY_ADDRESS,
        token_network_address=UNIT_TOKEN_NETWORK_ADDRESS,
        identifier=identifier,
        amount=PaymentAmount(5),
        target=target,
        secret=secret,
        route=[],
    )
    assert event_filter_for_payments(event=event1, partner_address=None)
    assert event_filter_for_payments(event=event1,
                                     partner_address=Address(target))
    assert not event_filter_for_payments(
        event=event1, partner_address=factories.make_address())

    initiator = InitiatorAddress(factories.make_address())
    event2 = EventPaymentReceivedSuccess(
        token_network_registry_address=UNIT_TOKEN_NETWORK_REGISTRY_ADDRESS,
        token_network_address=UNIT_TOKEN_NETWORK_ADDRESS,
        identifier=identifier,
        amount=TokenAmount(5),
        initiator=initiator,
    )
    assert event_filter_for_payments(event=event2, partner_address=None)
    assert event_filter_for_payments(event=event2,
                                     partner_address=Address(initiator))
    assert not event_filter_for_payments(
        event=event2, partner_address=factories.make_address())

    event3 = EventPaymentSentFailed(
        token_network_registry_address=UNIT_TOKEN_NETWORK_REGISTRY_ADDRESS,
        token_network_address=UNIT_TOKEN_NETWORK_ADDRESS,
        identifier=identifier,
        target=target,
        reason="whatever",
    )
    assert event_filter_for_payments(event=event3, partner_address=None)
    assert event_filter_for_payments(event=event3,
                                     partner_address=Address(target))
    assert not event_filter_for_payments(
        event=event3, partner_address=factories.make_address())
コード例 #6
0
def test_event_filter_for_payments():
    token_network_address = factories.make_address()
    secret = factories.make_secret()
    token_network_registry_address = factories.make_token_network_registry_address(
    )
    identifier = 1
    target = factories.make_address()
    event = EventPaymentSentSuccess(
        token_network_registry_address=token_network_registry_address,
        token_network_address=token_network_address,
        identifier=identifier,
        amount=5,
        target=target,
        secret=secret,
        route=[],
    )
    assert event_filter_for_payments(event=event, partner_address=None)
    assert event_filter_for_payments(event=event, partner_address=target)
    assert not event_filter_for_payments(
        event=event, partner_address=factories.make_address())

    event = EventPaymentReceivedSuccess(
        token_network_registry_address=token_network_registry_address,
        token_network_address=token_network_address,
        identifier=identifier,
        amount=5,
        initiator=target,
    )
    assert event_filter_for_payments(event=event, partner_address=None)
    assert event_filter_for_payments(event=event, partner_address=target)
    assert not event_filter_for_payments(
        event=event, partner_address=factories.make_address())

    event = EventPaymentSentFailed(
        token_network_registry_address=factories.
        make_token_network_registry_address(),
        token_network_address=token_network_address,
        identifier=identifier,
        target=target,
        reason="whatever",
    )
    assert event_filter_for_payments(event=event, partner_address=None)
    assert event_filter_for_payments(event=event, partner_address=target)
    assert not event_filter_for_payments(
        event=event, partner_address=factories.make_address())
コード例 #7
0
ファイル: target.py プロジェクト: zhengyunly/raiden
def handle_unlock(
    target_state: TargetTransferState,
    state_change: ReceiveUnlock,
    channel_state: NettingChannelState,
):
    """ Handles a ReceiveUnlock state change. """
    iteration = TransitionResult(target_state, list())
    balance_proof_sender = state_change.balance_proof.sender

    if balance_proof_sender == target_state.route.node_address:
        is_valid, events, _ = channel.handle_unlock(
            channel_state,
            state_change,
        )

        if is_valid:
            transfer = target_state.transfer
            payment_received_success = EventPaymentReceivedSuccess(
                payment_network_identifier=channel_state.
                payment_network_identifier,
                token_network_identifier=channel_state.
                token_network_identifier,
                identifier=transfer.payment_identifier,
                amount=transfer.lock.amount,
                initiator=transfer.initiator,
            )

            unlock_success = EventUnlockClaimSuccess(
                transfer.payment_identifier,
                transfer.lock.secrethash,
            )

            send_processed = SendProcessed(
                recipient=balance_proof_sender,
                channel_identifier=CHANNEL_IDENTIFIER_GLOBAL_QUEUE,
                message_identifier=state_change.message_identifier,
            )

            events.extend(
                [payment_received_success, unlock_success, send_processed])
            iteration = TransitionResult(None, events)

    return iteration
コード例 #8
0
def test_event_filter_for_payments():
    token_network_identifier = factories.make_address()
    payment_network_identifier = factories.make_payment_network_identifier()
    identifier = 1
    target = factories.make_address()
    event = EventPaymentSentSuccess(
        payment_network_identifier=payment_network_identifier,
        token_network_identifier=token_network_identifier,
        identifier=identifier,
        amount=5,
        target=target,
    )
    assert event_filter_for_payments(event, token_network_identifier, None)
    assert event_filter_for_payments(event, token_network_identifier, target)
    assert not event_filter_for_payments(event, token_network_identifier,
                                         factories.make_address())

    event = EventPaymentReceivedSuccess(
        payment_network_identifier=payment_network_identifier,
        token_network_identifier=token_network_identifier,
        identifier=identifier,
        amount=5,
        initiator=target,
    )
    assert event_filter_for_payments(event, token_network_identifier, None)
    assert event_filter_for_payments(event, token_network_identifier, target)
    assert not event_filter_for_payments(event, token_network_identifier,
                                         factories.make_address())

    event = EventPaymentSentFailed(
        payment_network_identifier=factories.make_payment_network_identifier(),
        token_network_identifier=token_network_identifier,
        identifier=identifier,
        target=target,
        reason="whatever",
    )
    assert event_filter_for_payments(event, token_network_identifier, None)
    assert event_filter_for_payments(event, token_network_identifier, target)
    assert not event_filter_for_payments(event, token_network_identifier,
                                         factories.make_address())
コード例 #9
0
def handle_unlock_light(
    target_state: TargetTransferState,
    state_change: ReceiveUnlockLight,
    channel_state: NettingChannelState,
) -> TransitionResult[TargetTransferState]:
    """ Handles a ReceiveUnlockLight state change. """

    is_valid, events, _ = channel.handle_unlock_light(channel_state, state_change)
    next_target_state: Optional[TargetTransferState] = target_state

    if is_valid:
        transfer = target_state.transfer
        payment_received_success = EventPaymentReceivedSuccess(
            payment_network_identifier=channel_state.payment_network_identifier,
            token_network_identifier=TokenNetworkID(channel_state.token_network_identifier),
            identifier=transfer.payment_identifier,
            amount=TokenAmount(transfer.lock.amount),
            initiator=transfer.initiator,
        )

        unlock_success = EventUnlockClaimSuccess(
            transfer.payment_identifier, transfer.lock.secrethash
        )

        store_unlock_message = StoreMessageEvent(
            state_change.signed_unlock.message_identifier,
            state_change.signed_unlock.payment_identifier,
            11,
            state_change.signed_unlock,
            True
        )

        events.extend([payment_received_success, unlock_success, store_unlock_message])
        next_target_state = None

    return TransitionResult(next_target_state, events)