# 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/client.py
# class CallException(Exception):
#     def __init__(self, code, message):
#         super(CallException, self).__init__()
#         self.args = [code, message]
# 
# Path: keepkeylib/tx_api.py
# def pack_varint(n):
#     def __init__(self, network, url):
#     def fetch_json(self, url, resource, resourceid):
#     def get_tx(self, txhash):
#     def __init__(self, network, url, zcash=None):
#     def get_tx(self, txhash):
#     def get_raw_tx(self, txhash):
# class TxApi(object):
# class TxApiInsight(TxApi):


import unittest
import common
import binascii
import itertools
import pytest
import keepkeylib.messages_pb2 as proto
import keepkeylib.types_pb2 as proto_types
from binascii import unhexlify
from keepkeylib.tools import parse_path
from keepkeylib.client import CallException
from keepkeylib import tx_api
                proto.TxRequest(request_type=proto_types.TXFINISHED),
            ])
            (signatures, serialized_tx) = self.client.sign_tx('Testnet', [inp1, ], [out1, out2])

        self.assertEqual(binascii.hexlify(serialized_tx), b'0100000001549d2977998f899a63c0a9da30dedb2841e33fef561097b05822eccbc7f3906f010000006a47304402205ea68e9d52d4be14420ccecf7f2e11489d49b86bedb79ee99b5e9b7188884150022056219cb3384a5df8048cca286a9533403dbda1571afd84b51379cdaee6a6dea80121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff020084d717000000001976a9140223b1a09138753c9cb0baf95a0a62c82711567a88ac0065cd1d000000001976a9142db345c36563122e2fd0f5485fb7ea9bbf7cb5a288ac00000000')

    def test_one_two_fee(self):
        self.setup_mnemonic_allallall()

        # tx: c275c333fd1b36bef4af316226c66a8b3693fbfcc081a5e16a2ae5fcb09e92bf

        inp1 = proto_types.TxInputType(
            address_n=parse_path("m/44'/0'/0'/0/5"),  # 1GA9u9TfCG7SWmKCveBumdA1TZpfom6ZdJ
            # amount=50000,
            prev_hash=TXHASH_50f6f1,
            prev_index=1,
        )

        out1 = proto_types.TxOutputType(
            address_n=parse_path("m/44'/0'/0'/1/3"),  # 1EcL6AyfQTyWKGvXwNSfsWoYnD3whzVFdu
            amount=30000,
            script_type=proto_types.PAYTOADDRESS,
        )

        out2 = proto_types.TxOutputType(
            address='1Up15Msx4sbvUCGm8Xgo2Zp5FQim3wE59',
            amount=10000,
            script_type=proto_types.PAYTOADDRESS,
        )


# 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/client.py
# class CallException(Exception):
#     def __init__(self, code, message):
#         super(CallException, self).__init__()
#         self.args = [code, message]
# 
# Path: keepkeylib/tx_api.py
# def pack_varint(n):
#     def __init__(self, network, url):
#     def fetch_json(self, url, resource, resourceid):
#     def get_tx(self, txhash):
#     def __init__(self, network, url, zcash=None):
#     def get_tx(self, txhash):
#     def get_raw_tx(self, txhash):
# class TxApi(object):
# class TxApiInsight(TxApi):


# Path: tests/test_msg_signtx_raw.py
import unittest
import common
import binascii
import itertools
import pytest
import keepkeylib.messages_pb2 as proto
import keepkeylib.types_pb2 as proto_types
from binascii import unhexlify
from keepkeylib.tools import parse_path
from keepkeylib.client import CallException
from keepkeylib import tx_api

                proto.TxRequest(request_type=proto_types.TXFINISHED),
            ])
            (signatures, serialized_tx) = self.client.sign_tx('Testnet', [inp1, ], [out1, out2])

        self.assertEqual(binascii.hexlify(serialized_tx), b'0100000001549d2977998f899a63c0a9da30dedb2841e33fef561097b05822eccbc7f3906f010000006a47304402205ea68e9d52d4be14420ccecf7f2e11489d49b86bedb79ee99b5e9b7188884150022056219cb3384a5df8048cca286a9533403dbda1571afd84b51379cdaee6a6dea80121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff020084d717000000001976a9140223b1a09138753c9cb0baf95a0a62c82711567a88ac0065cd1d000000001976a9142db345c36563122e2fd0f5485fb7ea9bbf7cb5a288ac00000000')

    def test_one_two_fee(self):
        self.setup_mnemonic_allallall()

        # tx: c275c333fd1b36bef4af316226c66a8b3693fbfcc081a5e16a2ae5fcb09e92bf

        inp1 = proto_types.TxInputType(
            address_n=parse_path("m/44'/0'/0'/0/5"),  # 1GA9u9TfCG7SWmKCveBumdA1TZpfom6ZdJ
            # amount=50000,
            prev_hash=TXHASH_50f6f1,
            prev_index=1,
        )

        out1 = proto_types.TxOutputType(
            address_n=parse_path("m/44'/0'/0'/1/3"),  # 1EcL6AyfQTyWKGvXwNSfsWoYnD3whzVFdu
            amount=30000,
            script_type=proto_types.PAYTOADDRESS,
        )

        out2 = proto_types.TxOutputType(
            address='1Up15Msx4sbvUCGm8Xgo2Zp5FQim3wE59',
            amount=10000,
            script_type=proto_types.PAYTOADDRESS,
        )


        with self.client: