Example #1
0
def test_close_settled(client: Client, channel_manager: ChannelManager,
                       web3: Web3, wait_for_blocks):
    sender = client.context.address
    receiver = channel_manager.receiver

    channel = client.open_channel(receiver, 10)
    wait_for_blocks(channel_manager.n_confirmations + 1)
    channel_manager.register_payment(sender, channel.block, 2,
                                     encode_hex(channel.create_transfer(2)))
    receiver_sig = channel_manager.sign_close(sender, channel.block, 2)
    channel.close_cooperatively(receiver_sig)
    wait_for_blocks(channel_manager.n_confirmations + 1)

    channel_manager.stop()  # don't update state from this point on
    channel_manager.join()
    state = channel_manager.state

    tx_count_before = web3.eth.getTransactionCount(receiver)
    close_open_channels(channel_manager.private_key,
                        state,
                        channel_manager.channel_manager_contract,
                        wait=lambda: wait_for_blocks(1))
    tx_count_after = web3.eth.getTransactionCount(receiver)
    assert tx_count_after == tx_count_before
    wait_for_blocks(1)
Example #2
0
def test_close_valid_close(client: Client, channel_manager: ChannelManager,
                           web3: Web3, wait_for_blocks):
    sender = client.context.address
    receiver = channel_manager.receiver

    channel = client.open_channel(receiver, 10)
    wait_for_blocks(channel_manager.n_confirmations + 1)
    channel_manager.register_payment(sender, channel.block, 2,
                                     encode_hex(channel.create_transfer(2)))
    channel.close()

    channel_manager.stop()  # don't update state from this point on
    channel_manager.join()
    state = channel_manager.state

    tx_count_before = web3.eth.getTransactionCount(receiver)
    close_open_channels(channel_manager.private_key,
                        state,
                        channel_manager.channel_manager_contract,
                        wait=lambda: wait_for_blocks(1))
    tx_count_after = web3.eth.getTransactionCount(receiver)
    assert tx_count_after == tx_count_before + 1

    with pytest.raises((BadFunctionCallOutput, TransactionFailed)):
        channel_id = (channel.sender, channel.receiver, channel.block)
        channel_manager.channel_manager_contract.call().getChannelInfo(
            *channel_id)
    wait_for_blocks(1)
def test_withdraw_above_minimum(
        client: Client,
        channel_manager: ChannelManager,
        web3: Web3,
        wait_for_blocks
):
    sender = client.context.address
    receiver = channel_manager.receiver

    channel = client.open_channel(receiver, 10)
    wait_for_blocks(channel_manager.n_confirmations + 1)
    channel_manager.register_payment(sender, channel.block, 4,
                                     encode_hex(channel.create_transfer(4)))

    channel_manager.stop()  # don't update state from this point on
    channel_manager.join()
    state = channel_manager.state
    tx_count_before = web3.eth.getTransactionCount(receiver)
    withdraw_from_channels(
        channel_manager.private_key,
        state,
        channel_manager.channel_manager_contract,
        3,
        wait=lambda: wait_for_blocks(1)
    )
    tx_count_after = web3.eth.getTransactionCount(receiver)
    assert tx_count_after == tx_count_before + 1

    channel_id = (channel.sender, channel.receiver, channel.block)
    channel_info = channel_manager.channel_manager_contract.call().getChannelInfo(*channel_id)
    _, deposit, settle_block_number, closing_balance, transferred_tokens = channel_info
    assert transferred_tokens == 4

    wait_for_blocks(1)