# 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: keepkeylib/nano.py
# def encode_balance(balance):


import unittest
import common
from binascii import hexlify, unhexlify
from keepkeylib.client import CallException
from keepkeylib.tools import parse_path
from keepkeylib import messages_pb2 as proto
from keepkeylib import messages_nano_pb2 as proto_nano
from keepkeylib import types_pb2 as proto_types
from keepkeylib import nano
        with self.assertRaises(CallException):
            # Invalid parent_representative value
            self.client.nano_sign_tx(
                'Nano', NANO_ACCOUNT_0_PATH,
                grandparent_hash=unhexlify('517565abb71bdccf03754421b1bcaee8327cfce7a571a844ae5392e851531ece'),
                parent_link=unhexlify('0000000000000000000000000000000000000000000000000000000000000000'),
                parent_representative=REP_NANODE[:-2],
                parent_balance=9624176000000000000000000000000,
                link_hash=unhexlify('4f3d6ce7553bd16d0c03314efeb696dde1b2ae92a28e6346b5ed2cf6a8ff0d8b'),
                representative=REP_NANODE,
                balance=19624176000000000000000000000000,
            )

    def test_invalid_block_13(self):
        self.setup_mnemonic_nopin_nopassphrase()
        with self.assertRaises(CallException):
            # Invalid representative value
            self.client.nano_sign_tx(
                'Nano', NANO_ACCOUNT_0_PATH,
                grandparent_hash=unhexlify('517565abb71bdccf03754421b1bcaee8327cfce7a571a844ae5392e851531ece'),
                parent_link=unhexlify('0000000000000000000000000000000000000000000000000000000000000000'),
                parent_representative=REP_NANODE,
                parent_balance=9624176000000000000000000000000,
                link_hash=unhexlify('4f3d6ce7553bd16d0c03314efeb696dde1b2ae92a28e6346b5ed2cf6a8ff0d8b'),
                representative=REP_NANODE[:-2],
                balance=19624176000000000000000000000000,
            )

    def test_invalid_block_14(self):
        self.setup_mnemonic_nopin_nopassphrase()

# 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: keepkeylib/nano.py
# def encode_balance(balance):


# Path: tests/test_msg_nano_signtx.py
import unittest
import common
from binascii import hexlify, unhexlify
from keepkeylib.client import CallException
from keepkeylib.tools import parse_path
from keepkeylib import messages_pb2 as proto
from keepkeylib import messages_nano_pb2 as proto_nano
from keepkeylib import types_pb2 as proto_types
from keepkeylib import nano

        with self.assertRaises(CallException):
            # Invalid parent_representative value
            self.client.nano_sign_tx(
                'Nano', NANO_ACCOUNT_0_PATH,
                grandparent_hash=unhexlify('517565abb71bdccf03754421b1bcaee8327cfce7a571a844ae5392e851531ece'),
                parent_link=unhexlify('0000000000000000000000000000000000000000000000000000000000000000'),
                parent_representative=REP_NANODE[:-2],
                parent_balance=9624176000000000000000000000000,
                link_hash=unhexlify('4f3d6ce7553bd16d0c03314efeb696dde1b2ae92a28e6346b5ed2cf6a8ff0d8b'),
                representative=REP_NANODE,
                balance=19624176000000000000000000000000,
            )

    def test_invalid_block_13(self):
        self.setup_mnemonic_nopin_nopassphrase()
        with self.assertRaises(CallException):
            # Invalid representative value
            self.client.nano_sign_tx(
                'Nano', NANO_ACCOUNT_0_PATH,
                grandparent_hash=unhexlify('517565abb71bdccf03754421b1bcaee8327cfce7a571a844ae5392e851531ece'),
                parent_link=unhexlify('0000000000000000000000000000000000000000000000000000000000000000'),
                parent_representative=REP_NANODE,
                parent_balance=9624176000000000000000000000000,
                link_hash=unhexlify('4f3d6ce7553bd16d0c03314efeb696dde1b2ae92a28e6346b5ed2cf6a8ff0d8b'),
                representative=REP_NANODE[:-2],
                balance=19624176000000000000000000000000,
            )

    def test_invalid_block_14(self):
        self.setup_mnemonic_nopin_nopassphrase()

        with self.assertRaises(CallException):