Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 3
0
def test_close_invalid_close(client, channel_manager, web3, wait_for_blocks):
    sender = client.account
    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)))
    # cheat
    channel.update_balance(0)
    channel.create_transfer(1)
    channel.close()

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

    tx_count_before = web3.eth.getTransactionCount(receiver)
    close_open_channels(state,
                        contract_proxy,
                        10,
                        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)
        contract_proxy.contract.call().getChannelInfo(*channel_id)
    wait_for_blocks(1)