Beispiel #1
0
def test_delivered_message_must_clean_unordered_messages(chain_id):
    pseudo_random_generator = random.Random()
    block_number = 10
    our_address = factories.make_address()
    recipient = factories.make_address()
    channel_identifier = 1
    message_identifier = random.randint(0, 2**16)
    secret = factories.random_secret()

    chain_state = state.ChainState(
        pseudo_random_generator,
        block_number,
        our_address,
        chain_id,
    )
    queue_identifier = QueueIdentifier(
        recipient,
        events.CHANNEL_IDENTIFIER_GLOBAL_QUEUE,
    )
    message = events.SendRevealSecret(
        recipient,
        channel_identifier,
        message_identifier,
        secret,
    )

    chain_state.queueids_to_queues[queue_identifier] = [message]
    delivered_message = state_change.ReceiveDelivered(message_identifier)

    iteration = node.handle_delivered(chain_state, delivered_message)

    new_queue = iteration.new_state.queueids_to_queues.get(
        queue_identifier, [])
    assert not new_queue
Beispiel #2
0
def test_delivered_message_must_clean_unordered_messages(chain_id):
    pseudo_random_generator = random.Random()
    block_number = 10
    our_address = factories.make_address()
    recipient = factories.make_address()
    canonical_identifier = factories.make_canonical_identifier()
    message_identifier = random.randint(0, 2**16)
    secret = factories.random_secret()

    chain_state = state.ChainState(
        pseudo_random_generator=pseudo_random_generator,
        block_number=block_number,
        block_hash=factories.make_block_hash(),
        our_address=our_address,
        chain_id=chain_id,
    )
    queue_identifier = QueueIdentifier(
        recipient=recipient,
        canonical_identifier=CANONICAL_IDENTIFIER_GLOBAL_QUEUE)

    # Regression test:
    # The code delivered_message handler worked only with a queue of one
    # element
    first_message = SendSecretReveal(
        recipient=recipient,
        message_identifier=message_identifier,
        secret=secret,
        canonical_identifier=canonical_identifier,
    )

    second_message = SendSecretReveal(
        recipient=recipient,
        message_identifier=random.randint(0, 2**16),
        secret=secret,
        canonical_identifier=canonical_identifier,
    )

    chain_state.queueids_to_queues[queue_identifier] = [
        first_message, second_message
    ]

    delivered_message = state_change.ReceiveDelivered(recipient,
                                                      message_identifier)

    iteration = node.handle_receive_delivered(chain_state, delivered_message)
    new_queue = iteration.new_state.queueids_to_queues.get(
        queue_identifier, [])

    assert first_message not in new_queue
def test_chainstate_restore():
    pseudo_random_generator = random.Random()
    block_number = 577
    our_address = factories.make_address()
    chain_id = 777

    original_obj = state.ChainState(
        pseudo_random_generator=pseudo_random_generator,
        block_number=block_number,
        our_address=our_address,
        chain_id=chain_id,
    )

    decoded_obj = JSONSerializer.deserialize(
        JSONSerializer.serialize(original_obj), )

    assert original_obj == decoded_obj
Beispiel #4
0
def test_withdraw_request_message_cleanup(chain_id, token_network_state):
    pseudo_random_generator = random.Random()
    block_number = 10
    our_address = factories.make_address()
    recipient1 = factories.make_address()
    recipient2 = factories.make_address()
    channel_identifier = 1
    message_identifier = random.randint(0, 2**16)

    chain_state = state.ChainState(
        pseudo_random_generator=pseudo_random_generator,
        block_number=block_number,
        block_hash=factories.make_block_hash(),
        our_address=our_address,
        chain_id=chain_id,
    )
    queue_identifier = QueueIdentifier(recipient1,
                                       CANONICAL_IDENTIFIER_GLOBAL_QUEUE)

    withdraw_message = SendWithdrawRequest(
        message_identifier=message_identifier,
        canonical_identifier=CanonicalIdentifier(
            chain_identifier=chain_id,
            token_network_address=token_network_state.address,
            channel_identifier=channel_identifier,
        ),
        total_withdraw=100,
        participant=our_address,
        recipient=recipient1,
        nonce=1,
        expiration=10,
    )

    chain_state.queueids_to_queues[queue_identifier] = [withdraw_message]
    processed_message = state_change.ReceiveProcessed(recipient1,
                                                      message_identifier)

    iteration = node.handle_receive_processed(chain_state, processed_message)
    new_queue = iteration.new_state.queueids_to_queues.get(
        queue_identifier, [])

    # Processed should not have removed the WithdrawRequest message
    assert withdraw_message in new_queue

    receive_withdraw = ReceiveWithdrawConfirmation(
        message_identifier=message_identifier,
        canonical_identifier=CanonicalIdentifier(
            chain_identifier=chain_id,
            token_network_address=token_network_state.address,
            channel_identifier=channel_identifier,
        ),
        total_withdraw=100,
        signature=factories.make_32bytes(),
        sender=recipient2,
        participant=recipient2,
        nonce=1,
        expiration=10,
    )
    iteration = node.handle_receive_withdraw_confirmation(
        chain_state, receive_withdraw)
    new_queue = iteration.new_state.queueids_to_queues.get(
        queue_identifier, [])

    # ReceiveWithdraw from another recipient should not remove the WithdrawRequest
    assert withdraw_message in new_queue

    receive_withdraw = ReceiveWithdrawConfirmation(
        message_identifier=message_identifier,
        canonical_identifier=CanonicalIdentifier(
            chain_identifier=chain_id,
            token_network_address=token_network_state.address,
            channel_identifier=channel_identifier,
        ),
        total_withdraw=100,
        signature=factories.make_32bytes(),
        sender=recipient1,
        participant=recipient1,
        nonce=1,
        expiration=10,
    )
    iteration = node.handle_receive_withdraw_confirmation(
        chain_state, receive_withdraw)
    new_queue = iteration.new_state.queueids_to_queues.get(
        queue_identifier, [])
    assert withdraw_message not in new_queue