예제 #1
0
def handle_offchain_secretreveal(
        payment_state: InitiatorPaymentState,
        state_change: ReceiveSecretReveal,
        channelidentifiers_to_channels: ChannelMap,
        pseudo_random_generator: random.Random,
) -> TransitionResult:
    channel_identifier = payment_state.initiator.channel_identifier
    channel_state = channelidentifiers_to_channels[channel_identifier]
    sub_iteration = initiator.handle_offchain_secretreveal(
        payment_state.initiator,
        state_change,
        channel_state,
        pseudo_random_generator,
    )
    iteration = iteration_from_sub(payment_state, sub_iteration)
    return iteration
예제 #2
0
def handle_offchain_secretreveal(
    payment_state: InitiatorPaymentState,
    state_change: ReceiveSecretReveal,
    channelidentifiers_to_channels: typing.ChannelMap,
    pseudo_random_generator: random.Random,
) -> TransitionResult:
    channel_identifier = payment_state.initiator.channel_identifier
    channel_state = channelidentifiers_to_channels[channel_identifier]
    sub_iteration = initiator.handle_offchain_secretreveal(
        payment_state.initiator,
        state_change,
        channel_state,
        pseudo_random_generator,
    )
    iteration = iteration_from_sub(payment_state, sub_iteration)
    return iteration
def test_handle_offchain_emptyhash_secret():
    setup = setup_initiator_tests(block_number=10)

    secret_reveal = ReceiveSecretReveal(
        secret=EMPTY_HASH,
        sender=setup.channel.partner_state.address,
    )
    iteration = initiator.handle_offchain_secretreveal(
        initiator_state=setup.current_state.initiator,
        state_change=secret_reveal,
        channel_state=setup.channel,
        pseudo_random_generator=setup.prng,
    )
    secrethash = factories.UNIT_TRANSFER_DESCRIPTION.secrethash
    assert len(iteration.events) == 0
    # make sure the lock has not moved
    assert secrethash in setup.channel.our_state.secrethashes_to_lockedlocks
예제 #4
0
def test_handle_offchain_emptyhash_secret():
    setup = setup_initiator_tests(block_number=10)

    secret_reveal = ReceiveSecretReveal(
        secret=EMPTY_HASH,
        sender=setup.channel.partner_state.address,
    )
    iteration = initiator.handle_offchain_secretreveal(
        initiator_state=setup.current_state.initiator,
        state_change=secret_reveal,
        channel_state=setup.channel,
        pseudo_random_generator=setup.prng,
    )
    secrethash = factories.UNIT_TRANSFER_DESCRIPTION.secrethash
    assert len(iteration.events) == 0
    # make sure the lock has not moved
    assert secrethash in setup.channel.our_state.secrethashes_to_lockedlocks
예제 #5
0
def test_handle_offchain_secretreveal():
    setup = setup_initiator_tests()

    secret_reveal = ReceiveSecretReveal(
        secret=UNIT_SECRET,
        sender=setup.channel.partner_state.address,
    )
    message_identifier = message_identifier_from_prng(deepcopy(setup.prng))
    iteration = initiator.handle_offchain_secretreveal(
        initiator_state=setup.current_state.initiator,
        state_change=secret_reveal,
        channel_state=setup.channel,
        pseudo_random_generator=setup.prng,
    )

    payment_identifier = setup.current_state.initiator.transfer_description.payment_identifier
    assert events.must_contain_entry(iteration.events, SendBalanceProof, {
        'message_identifier': message_identifier,
        'payment_identifier': payment_identifier,
    })
예제 #6
0
def test_handle_offchain_secretreveal():
    setup = setup_initiator_tests()

    secret_reveal = ReceiveSecretReveal(
        secret=UNIT_SECRET,
        sender=setup.channel.partner_state.address,
    )
    message_identifier = message_identifier_from_prng(deepcopy(setup.prng))
    iteration = initiator.handle_offchain_secretreveal(
        initiator_state=setup.current_state.initiator,
        state_change=secret_reveal,
        channel_state=setup.channel,
        pseudo_random_generator=setup.prng,
    )

    payment_identifier = setup.current_state.initiator.transfer_description.payment_identifier
    assert events.must_contain_entry(iteration.events, SendBalanceProof, {
        'message_identifier': message_identifier,
        'payment_identifier': payment_identifier,
    })
예제 #7
0
def test_handle_offchain_secretreveal():
    channel1 = factories.make_channel(
        our_balance=UNIT_TRANSFER_AMOUNT,
        token_address=UNIT_TOKEN_ADDRESS,
        token_network_identifier=UNIT_TOKEN_NETWORK_ADDRESS,
    )
    channel_map = {channel1.identifier: channel1}
    available_routes = [factories.route_from_channel(channel1)]
    pseudo_random_generator = random.Random()
    block_number = 10

    manager_state = make_initiator_manager_state(
        available_routes,
        factories.UNIT_TRANSFER_DESCRIPTION,
        channel_map,
        pseudo_random_generator,
        block_number,
    )

    secret_reveal = ReceiveSecretReveal(
        secret=UNIT_SECRET,
        sender=channel1.partner_state.address,
    )

    message_identifier = message_identifier_from_prng(
        deepcopy(pseudo_random_generator))

    iteration = initiator.handle_offchain_secretreveal(
        initiator_state=manager_state.initiator,
        state_change=secret_reveal,
        channel_state=channel1,
        pseudo_random_generator=pseudo_random_generator,
    )

    assert events.must_contain_entry(
        iteration.events, SendBalanceProof, {
            'message_identifier':
            message_identifier,
            'payment_identifier':
            manager_state.initiator.transfer_description.payment_identifier,
        })