Esempio n. 1
0
def test_channel_closed_must_clear_ordered_messages(chain_state,
                                                    token_network_state,
                                                    netting_channel_state):
    recipient = netting_channel_state.partner_state.address
    message_identifier = random.randint(0, 2**16)
    amount = 10

    queue_identifier = QueueIdentifier(
        recipient=recipient,
        canonical_identifier=netting_channel_state.canonical_identifier)

    # Regression test:
    # The code delivered_message handler worked only with a queue of one
    # element
    message = factories.create(
        factories.LockedTransferProperties(
            message_identifier=message_identifier,
            token=token_network_state.token_address,
            canonical_identifier=netting_channel_state.canonical_identifier,
            transferred_amount=amount,
            recipient=recipient,
        ))

    chain_state.queueids_to_queues[queue_identifier] = [message]

    closed = state_change.ContractReceiveChannelClosed(
        transaction_hash=EMPTY_HASH,
        transaction_from=recipient,
        canonical_identifier=netting_channel_state.canonical_identifier,
        block_number=1,
        block_hash=factories.make_block_hash(),
    )

    iteration = node.handle_state_change(chain_state, closed)
    assert queue_identifier not in iteration.new_state.queueids_to_queues
Esempio n. 2
0
def test_channel_closed_must_clear_ordered_messages(
    chain_id,
    chain_state,
    payment_network_state,
    token_network_state,
    netting_channel_state,
):
    recipient = netting_channel_state.partner_state.address
    channel_identifier = netting_channel_state.identifier
    message_identifier = random.randint(0, 2**16)
    amount = 10

    queue_identifier = QueueIdentifier(
        recipient,
        channel_identifier,
    )

    # Regression test:
    # The code delivered_message handler worked only with a queue of one
    # element
    message = make_direct_transfer(
        message_identifier=message_identifier,
        registry_address=payment_network_state.address,
        token=token_network_state.token_address,
        channel_identifier=channel_identifier,
        transferred_amount=amount,
        recipient=recipient,
    )

    chain_state.queueids_to_queues[queue_identifier] = [message]

    closed = state_change.ContractReceiveChannelClosed(
        transaction_hash=EMPTY_HASH,
        transaction_from=recipient,
        token_network_identifier=token_network_state.address,
        channel_identifier=channel_identifier,
        block_number=1,
    )

    iteration = node.handle_state_change(
        chain_state,
        closed,
    )
    assert queue_identifier not in iteration.new_state.queueids_to_queues