def test_deploy_networks(web3):
    example_settings = [
        NetworkSettings(
            name="Test",
            symbol="TST",
            decimals=4,
            fee_divisor=1000,
            default_interest_rate=0,
            custom_interests=True,
            expiration_time=EXPIRATION_TIME,
            prevent_mediator_interests=False,
        ),
        NetworkSettings(
            name="Test Coin",
            symbol="TCN",
            decimals=2,
            fee_divisor=0,
            default_interest_rate=1000,
            custom_interests=False,
            expiration_time=0,
            prevent_mediator_interests=False,
        ),
    ]
    networks, exchange, unw_eth = deploy_networks(web3, example_settings)

    assert networks[0].functions.name().call() == "Test"
    assert networks[0].functions.symbol().call() == "TST"
    assert networks[1].functions.decimals().call() == 2
    assert unw_eth.functions.decimals().call() == 18
def currency_network_contract_with_trustlines(web3, accounts):
    contract = deploy_test_network(web3, NetworkSettings(fee_divisor=100))
    for (A, B, clAB, clBA) in trustlines:
        contract.functions.setAccount(
            accounts[A], accounts[B], clAB, clBA, 0, 0, False, 0, 0
        ).transact()
    return contract
예제 #3
0
def currency_network_contract_with_trustlines(web3, accounts,
                                              make_currency_network_adapter):
    contract = deploy_test_network(
        web3, NetworkSettings(expiration_time=EXPIRATION_TIME))
    for (A, B, clAB, clBA) in trustlines:
        make_currency_network_adapter(contract).set_account(
            accounts[A],
            accounts[B],
            creditline_given=clAB,
            creditline_received=clBA)
    return contract
예제 #4
0
def deploy_currency_network_v2(web3):
    return deploy_network(
        web3,
        network_settings=NetworkSettings(
            fee_divisor=100,
            name="Trustlines",
            symbol="T",
            custom_interests=True,
            expiration_time=EXPIRATION_TIME,
        ),
        currency_network_contract_name="CurrencyNetworkV2",
    )
예제 #5
0
def test_currency_network_v1(web3, currency_network_v2_abi,
                             testnetwork1_address, contracts):
    """This is the only remaining contract of type `TestCurrencyNetwork`.
    It should only be used for its test functions of unfreezing a network"""
    network = deploy_network(
        web3,
        network_settings=NetworkSettings(
            fee_divisor=100,
            name="Trustlines",
            symbol="T",
            custom_interests=True,
            expiration_time=EXPIRATION_TIME,
        ),
        currency_network_contract_name="TestCurrencyNetwork",
    )
    return CurrencyNetworkProxy(web3, contracts["TestCurrencyNetwork"]["abi"],
                                network.address)
def currency_network_contract_with_high_trustlines(web3, accounts):
    contract = deploy_test_network(web3, NetworkSettings(fee_divisor=100))
    creditline = 1000000
    contract.functions.setAccount(
        accounts[0], accounts[1], creditline, creditline, 0, 0, False, 0, 0
    ).transact()
    contract.functions.setAccount(
        accounts[1], accounts[2], creditline, creditline, 0, 0, False, 0, 0
    ).transact()
    contract.functions.setAccount(
        accounts[2], accounts[3], creditline, creditline, 0, 0, False, 0, 0
    ).transact()

    contract.functions.setAccount(
        accounts[0], accounts[2], creditline, creditline, 0, 0, False, 0, 0
    ).transact()
    contract.functions.setAccount(
        accounts[2], accounts[4], creditline, creditline, 0, 0, False, 0, 0
    ).transact()
    contract.functions.setAccount(
        accounts[4], accounts[3], creditline, creditline, 0, 0, False, 0, 0
    ).transact()

    return contract
예제 #7
0
def owned_currency_network(web3, owner):
    settings = NetworkSettings(custom_interests=True)
    return deploy_ownable_network(web3,
                                  settings,
                                  transaction_options={"from": owner})
def new_contract(web3, owner):
    return deploy_ownable_network(
        web3,
        NetworkSettings(custom_interests=True),
        transaction_options={"from": owner},
    )
This file showcases how to get relevant information related to trustlines transfer
only using events (and events timestamps)
see https://github.com/trustlines-network/project/issues/545 for motive
These tests shall ensure that the information stays available, but also work as an example of how to implement it.
Of course there might be optimizations possible in the specific case.
"""

trustlines = [
    (0, 1, 100, 150),
    (1, 2, 200, 250),
    (2, 3, 300, 350),
    (3, 4, 400, 450),
]  # (A, B, clAB, clBA)

NETWORK_SETTING = NetworkSettings(
    fee_divisor=100, default_interest_rate=1000, custom_interests=False
)


@pytest.fixture(scope="session")
def currency_network_contract_with_trustlines(web3, accounts):
    contract = deploy_test_network(web3, NETWORK_SETTING)
    for (A, B, clAB, clBA) in trustlines:
        contract.functions.setAccountDefaultInterests(
            accounts[A], accounts[B], clAB, clBA, False, 0, 0
        ).transact()
    return contract


@pytest.fixture()
def currency_network_with_pending_interests(
예제 #10
0
import pytest
from tldeploy.core import deploy_currency_network_proxy, NetworkSettings


NETWORK_SETTINGS = NetworkSettings(
    name="TestCoin",
    symbol="T",
    custom_interests=True,
    expiration_time=2_000_000_000,
    fee_divisor=100,
)


@pytest.fixture(scope="session")
def upgraded_currency_network_implementation(deploy_contract):
    return deploy_contract(contract_identifier="CurrencyNetworkOwnableV2")


@pytest.fixture(scope="session")
def proxied_currency_network(
    web3, contract_assets, beacon_with_currency_network, owner, account_keys, accounts
):

    deployer_key = account_keys[1]
    deployer = accounts[1]

    proxied_currency_network = deploy_currency_network_proxy(
        web3=web3,
        network_settings=NETWORK_SETTINGS,
        beacon_address=beacon_with_currency_network.address,
        owner_address=owner,
예제 #11
0
import eth_tester
import pytest
from tlbin import load_packaged_contracts
from tldeploy.core import NetworkSettings, deploy_network, deploy_networks
from tldeploy.identity import MetaTransaction

from relay.blockchain import currency_network_proxy

EXPIRATION_TIME = 4102444800  # 01/01/2100

NETWORK_SETTINGS = [
    NetworkSettings(
        name="Cash",
        symbol="CASH",
        fee_divisor=1000,
        custom_interests=True,
        expiration_time=EXPIRATION_TIME,
    ),
    NetworkSettings(
        name="Work Hours",
        symbol="HOU",
        custom_interests=False,
        default_interest_rate=1000,
        expiration_time=EXPIRATION_TIME,
    ),
    NetworkSettings(name="Beers",
                    symbol="BEER",
                    decimals=0,
                    expiration_time=EXPIRATION_TIME),
]
"""increate eth_tester's GAS_LIMIT
예제 #12
0
def currency_network_contract_custom_interest(web3):
    network_settings = NetworkSettings(custom_interests=True,
                                       expiration_time=EXPIRATION_TIME)
    return deploy_test_network(web3, network_settings)
#! pytest

import time
import pytest
from tldeploy.core import NetworkSettings

from tests.conftest import (
    MAX_UINT_64,
    CurrencyNetworkAdapter,
    get_single_event_of_contract,
)
from tests.currency_network.conftest import deploy_test_network

SECONDS_PER_YEAR = 60 * 60 * 24 * 365
NETWORK_SETTING = NetworkSettings(fee_divisor=100, custom_interests=True)


@pytest.fixture(scope="session", params=[0, 100, 2000])  # 0% , 1%, 20%
def interest_rate(request):
    return request.param


@pytest.fixture()
def currency_network_contract_with_trustlines(chain, web3, accounts,
                                              interest_rate,
                                              make_currency_network_adapter):
    currency_network_contract = deploy_test_network(web3, NETWORK_SETTING)
    currency_network_adapter = make_currency_network_adapter(
        currency_network_contract)
    current_time = int(time.time())
    chain.time_travel(current_time + 10)
예제 #14
0
def currency_network_contract_with_fees(web3):
    setting = NetworkSettings(fee_divisor=100, custom_interests=True)
    return deploy_test_network(web3, setting)
예제 #15
0
from tldeploy.core import deploy_network, NetworkSettings

from tests.conftest import EXPIRATION_TIME

ADDRESS_0 = "0x0000000000000000000000000000000000000000"
NO_ONBOARDER = "0x0000000000000000000000000000000000000001"

trustlines = [
    (0, 1, 100, 150),
    (1, 2, 200, 250),
    (2, 3, 300, 350),
    (3, 4, 400, 450),
    (0, 4, 500, 550),
]  # (A, B, clAB, clBA)

NETWORK_SETTING = NetworkSettings(name="TestCoin", symbol="T")


def deploy_test_network(web3, network_setting, **kwargs):
    return deploy_network(
        web3,
        network_setting,
        currency_network_contract_name="TestCurrencyNetwork",
        **kwargs,
    )


def deploy_ownable_network(web3, network_setting, **kwargs):
    return deploy_network(
        web3,
        network_setting,
예제 #16
0
def currency_network_contract_custom_interests_safe_ripple(web3):
    return deploy_network(
        web3,
        NetworkSettings(prevent_mediator_interests=True, custom_interests=True),
        currency_network_contract_name="TestCurrencyNetwork",
    )
예제 #17
0
def currency_network_contract_negative_interests(web3):
    return deploy_network(
        web3,
        NetworkSettings(default_interest_rate=-100, custom_interests=False),
        currency_network_contract_name="TestCurrencyNetwork",
    )
예제 #18
0
def currency_network_contract_no_interests(web3):
    return deploy_network(
        web3,
        NetworkSettings(custom_interests=False),
        currency_network_contract_name="TestCurrencyNetwork",
    )
def old_contract(
    web3,
    accounts,
    chain,
    on_boarders,
    on_boardees,
    creditors,
    debtors,
    debt_values,
    make_currency_network_adapter,
):
    """Create a currency network with on boardees, debts, and trustlines to migrate from"""

    expiration_time = web3.eth.getBlock("latest")["timestamp"] + 1000
    settings = NetworkSettings(expiration_time=expiration_time,
                               custom_interests=True)
    contract = deploy_test_network(web3, settings)
    currency_network = make_currency_network_adapter(contract)

    # set on boardees by opening trustlines from on boarder
    for (on_boarder, on_boardee) in zip(on_boarders, on_boardees):
        if on_boarder == NO_ONBOARDER:
            # NO_ONBOARDER is not really an account, and should (can) not send transactions
            # We use `set_account` to set NO_ONBOARDER to on_boardee
            currency_network.set_account(on_boarder,
                                         on_boardee,
                                         creditline_given=1,
                                         creditline_received=1)
        else:
            currency_network.update_trustline(
                on_boarder,
                on_boardee,
                creditline_given=1,
                creditline_received=1,
                accept=True,
            )
        assert (currency_network.get_on_boarder(on_boardee) == on_boarder
                ), "Setting up the on boarder failed"

    # set debts
    for (creditor, debtor, debt_value) in zip(creditors, debtors, debt_values):
        currency_network.increase_debt(debtor, creditor, debt_value)
        assert (currency_network.get_debt(
            debtor, creditor) == debt_value), "Failed at setting up debts"

    # set trustlines
    for (A, B, clAB, clBA, is_frozen) in trustlines:
        currency_network.update_trustline(
            accounts[A],
            accounts[B],
            creditline_given=clAB,
            creditline_received=clBA,
            is_frozen=is_frozen,
            accept=True,
        )

    # set pending trustline requests
    for (
            A,
            B,
            clAB,
            clBA,
            interest_AB,
            interest_BA,
            is_frozen,
    ) in pending_trustlines_requests:
        currency_network.update_trustline(
            accounts[A],
            accounts[B],
            creditline_given=clAB,
            creditline_received=clBA,
            interest_rate_given=interest_AB,
            interest_rate_received=interest_BA,
            is_frozen=is_frozen,
            accept=False,
        )

    chain.time_travel(expiration_time)
    chain.mine_block()
    contract.functions.freezeNetwork().transact()
    return contract
from tests.conftest import EXTRA_DATA
from tests.currency_network.conftest import deploy_test_network

trustlines = [
    (0, 1, 100, 150),
    (1, 2, 200, 250),
    (2, 3, 300, 350),
    (3, 4, 400, 450),
    (0, 4, 500, 550),
]  # (A, B, clAB, clBA)

max_int256 = 2 ** 255 - 1
min_int256 = -(max_int256 + 1)

NETWORK_SETTING = NetworkSettings(fee_divisor=100)


@pytest.fixture(scope="session")
def currency_network_contract(web3):
    return deploy_test_network(web3, NETWORK_SETTING)


@pytest.fixture(scope="session")
def currency_network_contract_with_trustlines(
    web3, accounts, make_currency_network_adapter
):
    contract = deploy_test_network(web3, NETWORK_SETTING)
    for (A, B, clAB, clBA) in trustlines:
        make_currency_network_adapter(contract).set_account(
            accounts[A], accounts[B], creditline_given=clAB, creditline_received=clBA
예제 #21
0
def second_currency_network_contract(web3):
    return deploy_network(web3, NetworkSettings())