Exemplo n.º 1
0
def test_trusted_contracts_constructor(owner, get_accounts,
                                       get_uraiden_contract, uraiden_contract,
                                       token_instance, delegate_contract,
                                       contract_params):
    trusted_contract = delegate_contract()
    trusted_contract2 = delegate_contract()
    other_contract = delegate_contract()
    simple_account = get_accounts(1)[0]
    uraiden = uraiden_contract(token_instance, [trusted_contract.address])

    assert uraiden.call().trusted_contracts(trusted_contract.address)
    assert not uraiden.call().trusted_contracts(other_contract.address)

    with pytest.raises(TypeError):
        get_uraiden_contract([token_instance.address, challenge_period_min])
    with pytest.raises(TypeError):
        get_uraiden_contract(
            [token_instance.address, challenge_period_min, [fake_address]])

    uraiden2 = get_uraiden_contract([
        token_instance.address, challenge_period_min,
        [trusted_contract2.address, empty_address, simple_account]
    ])
    assert uraiden2.call().trusted_contracts(trusted_contract2.address)
    assert not uraiden2.call().trusted_contracts(empty_address)
    assert not uraiden2.call().trusted_contracts(simple_account)
Exemplo n.º 2
0
def test_variable_access(owner, uraiden_contract, token_instance, contract_params):
    uraiden = uraiden_contract(token_instance)
    assert is_same_address(uraiden.call().owner_address(), owner)
    assert is_same_address(uraiden.call().token(), token_instance.address)
    assert uraiden.call().challenge_period() == contract_params['challenge_period']
    assert uraiden.call().version() == uraiden_contract_version
    assert uraiden.call().channel_deposit_bugbounty_limit() == channel_deposit_bugbounty_limit
def test_trusted_contracts_constructor(
        owner,
        get_accounts,
        get_uraiden_contract,
        uraiden_contract,
        token_instance,
        delegate_contract,
        contract_params):
    trusted_contract = delegate_contract()
    trusted_contract2 = delegate_contract()
    other_contract = delegate_contract()
    simple_account = get_accounts(1)[0]
    uraiden = uraiden_contract(token_instance, [trusted_contract.address])

    assert uraiden.call().trusted_contracts(trusted_contract.address)
    assert not uraiden.call().trusted_contracts(other_contract.address)

    with pytest.raises(TypeError):
        get_uraiden_contract([token_instance.address, challenge_period_min])
    with pytest.raises(TypeError):
        get_uraiden_contract([token_instance.address, challenge_period_min, [fake_address]])

    uraiden2 = get_uraiden_contract([
        token_instance.address,
        challenge_period_min,
        [trusted_contract2.address, empty_address, simple_account]
    ])
    assert uraiden2.call().trusted_contracts(trusted_contract2.address)
    assert not uraiden2.call().trusted_contracts(empty_address)
    assert not uraiden2.call().trusted_contracts(simple_account)
def test_create_token_fallback_uint_conversion(
        owner,
        get_accounts,
        uraiden_contract,
        get_token_contract):
    token = get_token_contract([MAX_UINT192 + 100, 'CustomToken', 'TKN', 18])
    uraiden = uraiden_contract(token)
    (sender, receiver) = get_accounts(2)
    txdata = bytes.fromhex(sender[2:] + receiver[2:])

    # Fund accounts with tokens
    token.transact({"from": owner}).transfer(sender, MAX_UINT192 + 5)
    assert token.call().balanceOf(sender) == MAX_UINT192 + 5

    # Open a channel with tokenFallback
    # uint192 deposit = uint192(_deposit), where _deposit is uint256
    with pytest.raises(tester.TransactionFailed):
        token.transact({"from": sender}).transfer(
            uraiden.address,
            MAX_UINT192 + 1,
            txdata
        )
    with pytest.raises(tester.TransactionFailed):
        token.transact({"from": sender}).transfer(
            uraiden.address,
            MAX_UINT192 + 4,
            txdata
        )
Exemplo n.º 5
0
def test_variable_access(owner, uraiden_contract, token_instance,
                         contract_params):
    uraiden = uraiden_contract()
    assert uraiden.call().token() == token_instance.address
    assert uraiden.call().challenge_period(
    ) == contract_params['challenge_period']
    assert uraiden.call().version() == uraiden_contract_version
    assert uraiden.call().channel_deposit_bugbounty_limit(
    ) == channel_deposit_bugbounty_limit
Exemplo n.º 6
0
def test_function_access(
    owner,
    get_accounts,
    uraiden_contract,
    uraiden_instance,
    token_instance,
    get_channel):
    (A, B, C, D) = get_accounts(4)
    uraiden_instance2 = uraiden_contract()
    channel = get_channel(uraiden_instance, token_instance, 100, A, B)[:3]
    (sender, receiver, open_block_number) = channel

    uraiden_instance.call().getKey(*channel)
    uraiden_instance.call().getChannelInfo(*channel)

    # even if TransactionFailed , this means the function is public / external
    with pytest.raises(tester.TransactionFailed):
        uraiden_instance.transact().extractBalanceProofSignature(
            receiver,
            open_block_number,
            10,
            encode_hex(bytearray(65))
        )
    with pytest.raises(tester.TransactionFailed):
        uraiden_instance.transact().tokenFallback(sender, 10, encode_hex(bytearray(20)))
    with pytest.raises(tester.TransactionFailed):
        uraiden_instance.transact({'from': C}).createChannel(D, 10)
    with pytest.raises(tester.TransactionFailed):
        uraiden_instance.transact().topUp(receiver, open_block_number, 10)
    with pytest.raises(tester.TransactionFailed):
        uraiden_instance.transact().uncooperativeClose(receiver, open_block_number, 10)
    with pytest.raises(tester.TransactionFailed):
        uraiden_instance.transact().cooperativeClose(
            receiver,
            open_block_number,
            10,
            encode_hex(bytearray(65)),
            encode_hex(bytearray(65))
        )
    with pytest.raises(tester.TransactionFailed):
        uraiden_instance.transact().settle(receiver, open_block_number)

    # Test functions are private
    # raise ValueError("No matching functions found")
    with pytest.raises(ValueError):
        uraiden_instance.transact().createChannelPrivate(*channel)
    with pytest.raises(ValueError):
        uraiden_instance.transact().topUpPrivate(*channel, 10)
    with pytest.raises(ValueError):
        uraiden_instance.transact().initChallengePeriod(receiver, open_block_number, 10)
    with pytest.raises(ValueError):
        uraiden_instance.transact().settleChannel(*channel, 10)
Exemplo n.º 7
0
def test_function_access(owner, get_accounts, uraiden_contract,
                         uraiden_instance, token_instance, get_channel):
    (A, B, C, D) = get_accounts(4)
    uraiden_instance2 = uraiden_contract()
    channel = get_channel(uraiden_instance, token_instance, 100, A, B)
    (sender, receiver, open_block_number) = channel

    uraiden_instance.call().getKey(*channel)
    uraiden_instance.call().getChannelInfo(*channel)

    # even if TransactionFailed , this means the function is public / external
    with pytest.raises(tester.TransactionFailed):
        uraiden_instance.transact().verifyBalanceProof(receiver,
                                                       open_block_number, 10,
                                                       bytearray(65))
    with pytest.raises(tester.TransactionFailed):
        uraiden_instance.transact().tokenFallback(sender, 10, bytearray(20))
    with pytest.raises(tester.TransactionFailed):
        uraiden_instance.transact({'from': C}).createChannelERC20(D, 10)
    with pytest.raises(tester.TransactionFailed):
        uraiden_instance.transact().topUpERC20(receiver, open_block_number, 10)
    with pytest.raises(tester.TransactionFailed):
        uraiden_instance.transact().uncooperativeClose(receiver,
                                                       open_block_number, 10,
                                                       bytearray(65))
    with pytest.raises(tester.TransactionFailed):
        uraiden_instance.transact().cooperativeClose(receiver,
                                                     open_block_number, 10,
                                                     bytearray(65),
                                                     bytearray(65))
    with pytest.raises(tester.TransactionFailed):
        uraiden_instance.transact().settle(receiver, open_block_number)

    # Test functions are private
    # raise ValueError("No matching functions found")
    with pytest.raises(ValueError):
        uraiden_instance.transact().createChannelPrivate(*channel)
    with pytest.raises(ValueError):
        uraiden_instance.transact().topUpPrivate(*channel, 10)
    with pytest.raises(ValueError):
        uraiden_instance.transact().initChallengePeriod(
            receiver, open_block_number, 10)
    with pytest.raises(ValueError):
        uraiden_instance.transact().settleChannel(*channel, 10)
Exemplo n.º 8
0
def test_uraiden_init(
    web3,
    owner,
    get_accounts,
    get_uraiden_contract,
    token_contract,
    uraiden_contract):
    token = token_contract()
    fake_token = uraiden_contract()
    (A, B) = get_accounts(2)

    with pytest.raises(TypeError):
        get_uraiden_contract([token.address])
    with pytest.raises(TypeError):
        get_uraiden_contract([token.address, 500])
    with pytest.raises(TypeError):
        get_uraiden_contract([fake_address, challenge_period_min, []])
    with pytest.raises(TypeError):
        get_uraiden_contract([token.address, -2, []])
    with pytest.raises(TypeError):
        get_uraiden_contract([token.address, 2 ** 32, []])
    with pytest.raises(TypeError):
        get_uraiden_contract([0x0, challenge_period_min, []])
    with pytest.raises(tester.TransactionFailed):
        get_uraiden_contract([empty_address, challenge_period_min, []])
    with pytest.raises(tester.TransactionFailed):
        get_uraiden_contract([A, challenge_period_min, []])
    with pytest.raises(tester.TransactionFailed):
        get_uraiden_contract([token.address, 0, []])
    with pytest.raises(tester.TransactionFailed):
        get_uraiden_contract([token.address, challenge_period_min - 1, []])
    with pytest.raises(tester.TransactionFailed):
        get_uraiden_contract([fake_token.address, challenge_period_min, []])

    uraiden = get_uraiden_contract([token.address, 2 ** 32 - 1, []])
    assert is_same_address(uraiden.call().owner_address(), owner)
    assert is_same_address(uraiden.call().token(), token.address)
    assert uraiden.call().challenge_period() == 2 ** 32 - 1
    assert token.call().balanceOf(uraiden.address) == 0
    assert web3.eth.getBalance(uraiden.address) == 0

    # Temporary limit for the bug bounty release
    assert uraiden.call().channel_deposit_bugbounty_limit() == channel_deposit_bugbounty_limit
Exemplo n.º 9
0
def test_uraiden_init(
    web3,
    owner,
    get_accounts,
    get_uraiden_contract,
    token_contract,
    uraiden_contract):
    token = token_contract()
    fake_token = uraiden_contract()
    (A, B) = get_accounts(2)

    with pytest.raises(TypeError):
        get_uraiden_contract([token.address])
    with pytest.raises(TypeError):
        get_uraiden_contract([fake_address, challenge_period_min])
    with pytest.raises(TypeError):
        get_uraiden_contract([token.address, -2])
    with pytest.raises(TypeError):
        get_uraiden_contract([token.address, 2 ** 32])
    with pytest.raises(TypeError):
        get_uraiden_contract([0x0, challenge_period_min])
    with pytest.raises(tester.TransactionFailed):
        get_uraiden_contract([empty_address, challenge_period_min])
    with pytest.raises(tester.TransactionFailed):
        get_uraiden_contract([A, challenge_period_min])
    with pytest.raises(tester.TransactionFailed):
        get_uraiden_contract([token.address, 0])
    with pytest.raises(tester.TransactionFailed):
        get_uraiden_contract([token.address, challenge_period_min - 1])
    with pytest.raises(tester.TransactionFailed):
        get_uraiden_contract([fake_token.address, challenge_period_min])

    uraiden = get_uraiden_contract([token.address, 2 ** 32 - 1])
    assert uraiden.call().token() == token.address
    assert uraiden.call().challenge_period() == 2 ** 32 - 1
    assert token.call().balanceOf(uraiden.address) == 0
    assert web3.eth.getBalance(uraiden.address) == 0

    # Temporary limit for the bug bounty release
    assert uraiden.call().channel_deposit_bugbounty_limit() == channel_deposit_bugbounty_limit