def test_dataclasses_json_dict() -> None: for network_name, net in NETWORKS.items(): assert net == Network.from_dict(net.to_dict()) datadir = path.join(path.dirname(__file__), "_generated_files") filename = path.join(datadir, network_name + ".json") with open(filename, "w", encoding="ascii") as file_: json.dump(net.to_dict(), file_, indent=4)
def test_curve_from_xkeyversion() -> None: for net_str, net in NETWORKS.items(): all_versions = xpubversions_from_network(net_str) all_versions += xprvversions_from_network(net_str) for version in all_versions: # unfortunately 'regtest' shares same versions with 'testnet' if net_str != "regtest": assert net_str == network_from_xkeyversion(version) assert net.curve == curve_from_xkeyversion(version)
def test_dataclasses_json_dict() -> None: for net in NETWORKS.values(): net2 = Network.from_json(net.to_json()) assert net2 == net net2 = Network.from_dict(net.to_dict()) assert net2 == net datadir = path.join(path.dirname(__file__), "generated_files") filename = path.join(datadir, "mainnet.json") with open(filename, "w") as file_: json.dump(NETWORKS["mainnet"].to_dict(), file_, indent=4)
def has_segwit_prefix(addr: String) -> bool: str_addr = addr.strip().lower() if isinstance( addr, str) else addr.decode("ascii") return any(str_addr.startswith(net.hrp + "1") for net in NETWORKS.values())