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
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
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) for a in accounts[:4]: for b in accounts[:4]: if a is b: continue currency_network_adapter.set_account( a, b, creditline_given=1_000_000, creditline_received=1_000_000, interest_rate_given=interest_rate, interest_rate_received=interest_rate, m_time=current_time, ) currency_network_adapter.transfer(10_000, path=[accounts[0], accounts[1]]) chain.time_travel(current_time + SECONDS_PER_YEAR) return currency_network_contract
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 ) return contract
def currency_network_adapter_with_trustlines( web3, accounts, make_currency_network_adapter ): network_settings = attr.evolve(NETWORK_SETTINGS, fee_divisor=100) contract = deploy_test_network(web3, network_settings) adapter = make_currency_network_adapter(contract) for (A, B, clAB, clBA) in trustlines: adapter.set_account( accounts[A], accounts[B], creditline_given=clAB, creditline_received=clBA ) return adapter
def currency_network_contract_with_trustlines(web3, accounts, chain, make_currency_network_adapter): settings = attr.evolve(NETWORK_SETTING, expiration_time=EXPIRATION_TIME) contract = deploy_test_network(web3, settings) 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
def currency_network_contract_authorized_with_trustlines( web3, global_authorized_address, accounts, make_currency_network_adapter): network_setting = attr.evolve(NETWORK_SETTING, fee_divisor=100, custom_interests=True) contract = deploy_test_network( web3, network_setting, authorized_addresses=[global_authorized_address]) 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
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
def currency_network_contract(web3): return deploy_test_network(web3, NETWORK_SETTING)
def test_default_interests_rates_out_of_bounds(web3, invalid_interest_rate): invalid_settings = attr.evolve( NETWORK_SETTING, default_interest_rate=invalid_interest_rate ) with pytest.raises(SolidityError): deploy_test_network(web3, invalid_settings)
def currency_network_contract_with_trustline_update(web3, accounts): contract = deploy_test_network(web3, NETWORK_SETTING) contract.functions.updateTrustline(accounts[1], 1, 1, 0, 0, False).transact( {"from": accounts[0]} ) return contract
def currency_network_contract_with_expiration(web3, accounts, chain, make_currency_network_adapter): settings = attr.evolve(NETWORK_SETTING, expiration_time=EXPIRATION_TIME) return deploy_test_network(web3, settings)
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