# Path: keepkeylib/client.py
# class CallException(Exception):
#     def __init__(self, code, message):
#         super(CallException, self).__init__()
#         self.args = [code, message]
# 
# Path: keepkeylib/tools.py
# def parse_path(nstr):
#     """
#     Convert BIP32 path string to list of uint32 integers with hardened flags.
#     Several conventions are supported to set the hardened flag: -1, 1', 1h
#     e.g.: "0/1h/1" -> [0, 0x80000001, 1]
#     :param nstr: path string
#     :return: list of integers
#     """
#     if not nstr:
#         return []
# 
#     n = nstr.split('/')
# 
#     # m/a/b/c => a/b/c
#     if n[0] == 'm':
#         n = n[1:]
# 
#     # coin_name/a/b/c => 44'/SLIP44_constant'/a/b/c
#     #if n[0] in slip44:
#     #    coin_id = slip44[n[0]]
#     #    n[0:1] = ['44h', '{}h'.format(coin_id)]
# 
#     def str_to_harden(x):
#         if x.startswith('-'):
#             return H_(abs(int(x)))
#         elif x.endswith(('h', "'")):
#             return H_(int(x[:-1]))
#         else:
#             return int(x)
# 
#     try:
#         return list(str_to_harden(x) for x in n)
#     except Exception:
#         raise ValueError('Invalid BIP32 path', nstr)


import unittest
import common
import keepkeylib.messages_pb2 as proto
import keepkeylib.types_pb2 as proto_types
import keepkeylib.messages_cosmos_pb2 as cosmos_proto
from keepkeylib.client import CallException
from keepkeylib.tools import parse_path
            ("cosmos1qpjr794gfnsp4c8uu84xl9xudea7h2tzns7ct8", parse_path("m/44h/118h/12345678h/0/0")),
        ]

        for (expected, path) in vec:
            with self.client:
                self.client.set_expected_responses([
                    proto.ButtonRequest(code=proto_types.ButtonRequest_Address),
                    cosmos_proto.CosmosAddress(address=expected)
                ])

                self.assertEqual(expected, self.client.cosmos_get_address(path, show_display=True))

            with self.client:
                self.client.set_expected_responses([
                    cosmos_proto.CosmosAddress(address=expected)
                ])

                self.assertEqual(expected, self.client.cosmos_get_address(path, show_display=False))


    def test_nonstandard(self):
        self.requires_firmware("6.3.0")
        self.setup_mnemonic_nopin_nopassphrase()

        vec = [
            ("cosmos1njwjrarnsfmzmuadsyu3acykfv5dm9ghe8f3z2", parse_path("m/44h/0h/0h/0/0")),
            ("cosmos17543w8x4dywq0k4nymd4x96ur27um8cn932832", parse_path("m/49h/118h/0h/0/0")),
            ("cosmos19g5s8msys3j3xj64yywwqcamlswrl23yj7jmmh", parse_path("m/44h/118h/0h/0/1")),
            ("cosmos1w6h0mg4nwku4hynv046rat6vy7wt7y6ltu6d8p", parse_path("m/44h/118h/1h/0/1")),
            ("cosmos1w6h0mg4nwku4hynv046rat6vy7wt7y6ltu6d8p", parse_path("m/44h/118h/1h/0/1")),

# Path: keepkeylib/client.py
# class CallException(Exception):
#     def __init__(self, code, message):
#         super(CallException, self).__init__()
#         self.args = [code, message]
# 
# Path: keepkeylib/tools.py
# def parse_path(nstr):
#     """
#     Convert BIP32 path string to list of uint32 integers with hardened flags.
#     Several conventions are supported to set the hardened flag: -1, 1', 1h
#     e.g.: "0/1h/1" -> [0, 0x80000001, 1]
#     :param nstr: path string
#     :return: list of integers
#     """
#     if not nstr:
#         return []
# 
#     n = nstr.split('/')
# 
#     # m/a/b/c => a/b/c
#     if n[0] == 'm':
#         n = n[1:]
# 
#     # coin_name/a/b/c => 44'/SLIP44_constant'/a/b/c
#     #if n[0] in slip44:
#     #    coin_id = slip44[n[0]]
#     #    n[0:1] = ['44h', '{}h'.format(coin_id)]
# 
#     def str_to_harden(x):
#         if x.startswith('-'):
#             return H_(abs(int(x)))
#         elif x.endswith(('h', "'")):
#             return H_(int(x[:-1]))
#         else:
#             return int(x)
# 
#     try:
#         return list(str_to_harden(x) for x in n)
#     except Exception:
#         raise ValueError('Invalid BIP32 path', nstr)


# Path: tests/test_msg_cosmos_getaddress.py
import unittest
import common
import keepkeylib.messages_pb2 as proto
import keepkeylib.types_pb2 as proto_types
import keepkeylib.messages_cosmos_pb2 as cosmos_proto
from keepkeylib.client import CallException
from keepkeylib.tools import parse_path

            ("cosmos1qpjr794gfnsp4c8uu84xl9xudea7h2tzns7ct8", parse_path("m/44h/118h/12345678h/0/0")),
        ]

        for (expected, path) in vec:
            with self.client:
                self.client.set_expected_responses([
                    proto.ButtonRequest(code=proto_types.ButtonRequest_Address),
                    cosmos_proto.CosmosAddress(address=expected)
                ])

                self.assertEqual(expected, self.client.cosmos_get_address(path, show_display=True))

            with self.client:
                self.client.set_expected_responses([
                    cosmos_proto.CosmosAddress(address=expected)
                ])

                self.assertEqual(expected, self.client.cosmos_get_address(path, show_display=False))


    def test_nonstandard(self):
        self.requires_firmware("6.3.0")
        self.setup_mnemonic_nopin_nopassphrase()

        vec = [
            ("cosmos1njwjrarnsfmzmuadsyu3acykfv5dm9ghe8f3z2", parse_path("m/44h/0h/0h/0/0")),
            ("cosmos17543w8x4dywq0k4nymd4x96ur27um8cn932832", parse_path("m/49h/118h/0h/0/0")),
            ("cosmos19g5s8msys3j3xj64yywwqcamlswrl23yj7jmmh", parse_path("m/44h/118h/0h/0/1")),
            ("cosmos1w6h0mg4nwku4hynv046rat6vy7wt7y6ltu6d8p", parse_path("m/44h/118h/1h/0/1")),
            ("cosmos1w6h0mg4nwku4hynv046rat6vy7wt7y6ltu6d8p", parse_path("m/44h/118h/1h/0/1")),

            ("cosmos1yjjkmdpu7metqt5r36jf872a34syws33xa5twl", parse_path("m/0")),