def get_contracts_addresses(network, config): addresses = {} try: addresses = ContractHandler.get_contracts_addresses( network, config.address_file ) except Exception as e: print( f"error reading contract addresses: {e}.\n" f"artifacts path is {ContractHandler.artifacts_path}, address file is {config.address_file}" ) if not addresses: print( f"cannot find contract addresses: \n" f"artifacts path is {ContractHandler.artifacts_path}, address file is {config.address_file}" ) print(f"address file exists? {os.path.exists(config.address_file)}") print( f"artifacts path exists? {os.path.exists(ContractHandler.artifacts_path)}" ) print( f"contents of artifacts folder: \n" f"{os.listdir(ContractHandler.artifacts_path)}" ) return addresses or {}
def test_load__name_and_address(network, example_config): """Tests load() from (name, address) query.""" addresses = ContractHandler.get_contracts_addresses( network, example_config.address_file) target_address = addresses["DTFactory"] test_tuple = ("DTFactory", target_address) assert test_tuple not in ContractHandler._contracts ContractHandler._load("DTFactory", target_address) assert test_tuple in ContractHandler._contracts
def test_load__name_and_address(network, example_config): # test load() from (name, address) query addresses = ContractHandler.get_contracts_addresses( network, example_config.address_file) target_address = addresses["DTFactory"] tup = ("DTFactory", target_address) assert tup not in ContractHandler._contracts contract = ContractHandler._load("DTFactory", target_address) assert ContractHandler._contracts[tup] == contract
def test_get_contracts_addresses_example_config(network, example_config): """Tests that an address can be set if using testing config.""" # ensure we're testing locally assert network in ["ganache", "development"] # do we get addresses for every contract? addresses = ContractHandler.get_contracts_addresses( network, example_config.address_file) assert set(addresses.keys()) == set( ["DTFactory", "BFactory", "FixedRateExchange", "Metadata", "Ocean"]) # are address values sane? for address in addresses.values(): assert address[0:2] == "0x"
def test_get_contracts_addresses_good_path_use_network_alias(tmp_path): """Tests that an address with a network alias can be set on a Contract.""" assert ContractHandler.network_alias == {"ganache": "development"} # create & fill test file d = tmp_path / "subdir" d.mkdir() address_file = d / "address.json" address_file.write_text('{"development" : "myvals"}') # not "ganache" # the main test addresses = ContractHandler.get_contracts_addresses( network="ganache", address_file=address_file) assert addresses == "myvals"
def test_get_contracts_addresses_good_path_custom_network(tmp_path): """Tests that an address with a custom network can be set on a Contract.""" # tmp_path:pathlib.Path is special pytest feature # create & fill test file d = tmp_path / "subdir" d.mkdir() address_file = d / "address.json" address_file.write_text('{"my_custom_network" : "myvals"}') # the main test addresses = ContractHandler.get_contracts_addresses( network="my_custom_network", address_file=address_file) assert addresses == "myvals"
def test_get_and_has__name_and_address(network, example_config): """Tests get() and has() from (name, address) queries, which also call _load() and read_abi_from_file().""" addresses = ContractHandler.get_contracts_addresses( network, example_config.address_file) target_address = addresses["DTFactory"] contract = ContractHandler.get("DTFactory", target_address) assert "createToken" in str(contract.abi) assert contract.address == addresses["DTFactory"] assert ContractHandler.has("DTFactory", target_address) assert not ContractHandler.has("foo name", "foo address") assert not ContractHandler.has("foo name", contract.address) assert not ContractHandler.has("DTFactory", "foo address")
def contracts_addresses(): return ContractHandler.get_contracts_addresses( _NETWORK, ConfigProvider.get_config().address_file)
def configured_address(cls, network, address_file): addresses = ContractHandler.get_contracts_addresses( network, address_file) return addresses.get(cls.CONTRACT_NAME) if addresses else None
def get_contracts_addresses(address_file): addresses = ContractHandler.get_contracts_addresses( 'ganache', address_file) return addresses
def test_get_contracts_addresses_bad_path(): """Tests that a non-existent address can not be set on a Contract.""" addresses = ContractHandler.get_contracts_addresses( _NETWORK, address_file="/bin/foo/bar/tralala" ) assert addresses is None
def test_get_contracts_addresses_empty(): """Tests that an empty address can not be set on a Contract.""" addresses = ContractHandler.get_contracts_addresses(_NETWORK, address_file=None) assert addresses is None