import hashlib


def make_unique_built_contract_filename(unitname: str, contractname: str):
    """Create a unique filename to store the contract identified by (unitname, contractname)

    This function shrinks the 'unitname', which may contain a path, keeping the
    uniqueness of the (unitname, contractname) tuple.

    :param unitname: source unit containing the contract
    :param contractname: name of the contract
    :return: unique filename
    """
    h = hashlib.md5()
    h.update(unitname.encode("utf-8"))
    h.update(b"\0")
    h.update(contractname.encode("utf-8"))
    return "build_" + contractname + "_" + h.hexdigest() + ".json"