コード例 #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)
コード例 #2
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)
コード例 #3
0
ファイル: test_uraiden.py プロジェクト: tominop/microraiden
def test_version(web3, owner, get_accounts, get_uraiden_contract,
                 uraiden_instance, token_instance):
    (A, B) = get_accounts(2)
    token = token_instance
    other_contract = get_uraiden_contract(
        [token.address, challenge_period_min], {'from': A})

    assert uraiden_instance.call().version() == uraiden_contract_version
コード例 #4
0
def test_version(
    web3,
    owner,
    get_accounts,
    get_uraiden_contract,
    uraiden_instance,
    token_instance):
    (A, B) = get_accounts(2)
    token = token_instance
    other_contract = get_uraiden_contract(
        [token.address, challenge_period_min, []],
        {'from': A}
    )

    assert uraiden_instance.call().version() == uraiden_contract_version
コード例 #5
0
def test_uncooperative_close_uint32_overflow(web3, channel_params,
                                             get_uraiden_contract,
                                             token_instance, get_channel):
    challenge_period = MAX_UINT32 - 20
    uraiden_instance = get_uraiden_contract(
        [token_instance.address, challenge_period])

    (sender, receiver, open_block_number) = get_channel(uraiden_instance)[:3]
    balance = channel_params['balance']

    block_number = web3.eth.getBlock('latest')['number']
    web3.testing.mine(MAX_UINT32 - 1 - block_number - challenge_period)

    assert web3.eth.getBlock(
        'latest')['number'] + challenge_period == MAX_UINT32 - 1

    uraiden_instance.transact({
        "from": sender
    }).uncooperativeClose(receiver, open_block_number, balance)
コード例 #6
0
def test_uncooperative_close_uint32_overflow(
        web3,
        channel_params,
        get_uraiden_contract,
        token_instance,
        get_channel):
    challenge_period = MAX_UINT32 - 20
    uraiden_instance = get_uraiden_contract(
        [token_instance.address, challenge_period, []]
    )

    (sender, receiver, open_block_number) = get_channel(uraiden_instance)[:3]
    balance = channel_params['balance']

    block_number = web3.eth.getBlock('latest')['number']
    web3.testing.mine(MAX_UINT32 - 1 - block_number - challenge_period)

    assert web3.eth.getBlock('latest')['number'] + challenge_period == MAX_UINT32 - 1

    uraiden_instance.transact({"from": sender}).uncooperativeClose(
        receiver,
        open_block_number,
        balance
    )
コード例 #7
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
コード例 #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