def test_close_trustline_direct_transfer_event(
        currency_network_adapter_with_trustlines: CurrencyNetworkAdapter,
        accounts, web3):
    from_address = accounts[1]
    to_address = accounts[0]

    (
        creditline_given,
        creditline_received,
        interest_rate_given,
        interest_rate_received,
        is_frozen,
        m_time,
        balance,
    ) = currency_network_adapter_with_trustlines.get_account(
        from_address, to_address)

    currency_network_adapter_with_trustlines.close_trustline_by_direct_transfer(
        from_address, to_address, min_balance=10_000, max_balance=20_000)

    block_time = web3.eth.getBlock("latest")["timestamp"]
    last_block_number = web3.eth.blockNumber
    balance_with_interests = (
        currency_network_adapter_with_trustlines.balance_with_interests(
            balance, m_time, block_time, interest_rate_given,
            interest_rate_received))

    assert currency_network_adapter_with_trustlines.is_trustline_closed(
        from_address, to_address)

    transfer_event_args = get_single_event_of_contract(
        currency_network_adapter_with_trustlines.contract, "Transfer",
        last_block_number)["args"]
    assert transfer_event_args["_from"] == from_address
    assert transfer_event_args["_to"] == to_address
    assert transfer_event_args["_value"] == balance_with_interests
    assert transfer_event_args["_extraData"] == b""

    balance_update_event_args = get_single_event_of_contract(
        currency_network_adapter_with_trustlines.contract,
        "BalanceUpdate",
        last_block_number,
    )["args"]
    assert balance_update_event_args["_from"] == from_address
    assert balance_update_event_args["_to"] == to_address
    assert balance_update_event_args["_value"] == 0

    trustline_update_event_args = get_single_event_of_contract(
        currency_network_adapter_with_trustlines.contract,
        "TrustlineUpdate",
        last_block_number,
    )["args"]
    assert trustline_update_event_args["_creditor"] == from_address
    assert trustline_update_event_args["_debtor"] == to_address
    assert trustline_update_event_args["_creditlineGiven"] == 0
    assert trustline_update_event_args["_creditlineReceived"] == 0
    assert trustline_update_event_args["_interestRateGiven"] == 0
    assert trustline_update_event_args["_interestRateReceived"] == 0
    assert trustline_update_event_args["_isFrozen"] is False
def test_set_account_events(
    currency_network_adapter: CurrencyNetworkAdapter,
    owner,
    accounts,
    creditor_index,
    debtor_index,
    web3,
):
    creditor = accounts[creditor_index]
    debtor = accounts[debtor_index]
    creditline_given = 123
    creditline_received = 321
    interest_rate_given = 1
    interest_rate_received = 2
    is_frozen = True
    old_mtime = 123456
    balance = 1000

    block_number = web3.eth.blockNumber
    currency_network_adapter.contract.functions.setAccount(
        creditor,
        debtor,
        creditline_given,
        creditline_received,
        interest_rate_given,
        interest_rate_received,
        is_frozen,
        old_mtime,
        balance,
    ).transact({"from": owner})

    new_mtime = web3.eth.getBlock(web3.eth.blockNumber)["timestamp"]
    new_balance = currency_network_adapter.balance_with_interests(
        balance, old_mtime, new_mtime, interest_rate_given,
        interest_rate_received)

    trustline_update_event_args = get_single_event_of_contract(
        currency_network_adapter.contract, "TrustlineUpdate",
        block_number)["args"]
    assert trustline_update_event_args["_creditor"] == creditor
    assert trustline_update_event_args["_debtor"] == debtor
    assert trustline_update_event_args["_creditlineGiven"] == creditline_given
    assert trustline_update_event_args[
        "_creditlineReceived"] == creditline_received
    assert trustline_update_event_args[
        "_interestRateGiven"] == interest_rate_given
    assert (trustline_update_event_args["_interestRateReceived"] ==
            interest_rate_received)
    assert trustline_update_event_args["_isFrozen"] == is_frozen

    balance_update_event_args = get_single_event_of_contract(
        currency_network_adapter.contract, "BalanceUpdate",
        block_number)["args"]
    assert balance_update_event_args["_from"] == creditor
    assert balance_update_event_args["_to"] == debtor
    assert balance_update_event_args["_value"] == new_balance
def test_remove_owner_event(currency_network_contract, owner, web3):
    currency_network_contract.functions.removeOwner().transact({"from": owner})
    assert (get_single_event_of_contract(
        currency_network_contract,
        "OwnerRemoval",
        web3.eth.blockNumber,
    ) is not None)
def test_unfreeze_network_event(currency_network_adapter, owner, web3):
    currency_network_adapter.unfreeze_network(
        transaction_options={"from": owner})
    assert (get_single_event_of_contract(
        currency_network_adapter.contract,
        "NetworkUnfreeze",
        web3.eth.blockNumber,
    ) is not None)
def test_set_on_boarder_event(currency_network_contract, owner, accounts,
                              creditor_index, debtor_index, web3):
    user = accounts[1]
    on_boarder = accounts[2]

    block_number = web3.eth.blockNumber
    currency_network_contract.functions.setOnboarder(
        user, on_boarder).transact({"from": owner})

    event_args = get_single_event_of_contract(currency_network_contract,
                                              "Onboard", block_number)["args"]
    assert event_args["_onboarder"] == on_boarder
    assert event_args["_onboardee"] == user
示例#6
0
def test_change_beacon_and_call_event(
    proxy,
    owner,
    new_proxy_beacon,
    proxied_upgraded_contract,
    upgraded_initialized_value,
    proxy_beacon,
):
    init_call = proxied_upgraded_contract.encodeABI(
        "init", (upgraded_initialized_value, ))
    proxy.functions.changeBeaconAndCall(new_proxy_beacon.address,
                                        init_call).transact({"from": owner})
    event = get_single_event_of_contract(proxy, "BeaconChanged")
    assert event["args"]["previousBeacon"] == proxy_beacon.address
    assert event["args"]["newBeacon"] == new_proxy_beacon.address
def test_set_trustline_request_event(
        currency_network_adapter: CurrencyNetworkAdapter, owner, accounts,
        web3):
    creditor = accounts[0]
    debtor = accounts[1]
    creditline_given = 123
    creditline_received = 321
    interest_rate_given = 1
    interest_rate_received = 2
    is_frozen = True

    currency_network_adapter.set_trustline_request(
        creditor,
        debtor,
        creditline_given,
        creditline_received,
        interest_rate_given,
        interest_rate_received,
        is_frozen,
        transaction_options={"from": owner},
    )
    trustline_update_request_event_args = get_single_event_of_contract(
        currency_network_adapter.contract,
        "TrustlineUpdateRequest",
        web3.eth.blockNumber,
    )["args"]

    assert trustline_update_request_event_args["_creditor"] == creditor
    assert trustline_update_request_event_args["_debtor"] == debtor
    assert trustline_update_request_event_args[
        "_creditlineGiven"] == creditline_given
    assert (trustline_update_request_event_args["_creditlineReceived"] ==
            creditline_received)
    assert (trustline_update_request_event_args["_interestRateGiven"] ==
            interest_rate_given)
    assert (trustline_update_request_event_args["_interestRateReceived"] ==
            interest_rate_received)
    assert trustline_update_request_event_args["_isFrozen"] == is_frozen
示例#8
0
def test_change_beacon_event(proxy, new_proxy_beacon, proxy_beacon, owner):
    proxy.functions.changeBeacon(new_proxy_beacon.address).transact(
        {"from": owner})
    event = get_single_event_of_contract(proxy, "BeaconChanged")
    assert event["args"]["previousBeacon"] == proxy_beacon.address
    assert event["args"]["newBeacon"] == new_proxy_beacon.address
示例#9
0
def test_change_admin_event(proxy, not_owner, owner):
    proxy.functions.changeAdmin(not_owner).transact({"from": owner})
    event = get_single_event_of_contract(proxy, "AdminChanged")
    assert event["args"]["previousAdmin"] == owner
    assert event["args"]["newAdmin"] == not_owner
def test_update_implementation_event(proxy_beacon, upgraded_implementation, owner):
    proxy_beacon.functions.upgradeTo(upgraded_implementation.address).transact(
        {"from": owner}
    )
    upgraded_event = get_single_event_of_contract(proxy_beacon, "Upgraded")
    assert upgraded_event["args"]["implementation"] == upgraded_implementation.address