# 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 keepkeylib.messages_pb2 as proto
import keepkeylib.types_pb2 as proto_types
from keepkeylib.client import CallException
from keepkeylib import tx_api
                proto.TxRequest(request_type=proto_types.TXFINISHED),
            ])

            (signatures, serialized_tx) = self.client.sign_tx('Bitcoin', [inp1, ], [out1, ])

        # Accepted by network: tx fd79435246dee76b2f159d2db08032d666c95adc544de64c8c49f474df4a7fee
        self.assertEqual(binascii.hexlify(serialized_tx), '010000000182488650ef25a58fef6788bd71b8212038d7f2bbe4750bc7bcb44701e85ef6d5000000006b4830450221009a0b7be0d4ed3146ee262b42202841834698bb3ee39c24e7437df208b8b7077102202b79ab1e7736219387dffe8d615bbdba87e11477104b867ef47afed1a5ede7810121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff0160cc0500000000001976a914de9b2a8da088824e8fe51debea566617d851537888ac00000000')

    def test_testnet_one_two_fee(self):
        self.setup_mnemonic_nopin_nopassphrase()

        # tx: 6f90f3c7cbec2258b0971056ef3fe34128dbde30daa9c0639a898f9977299d54
        # input 1: 10.00000000 BTC
        inp1 = proto_types.TxInputType(address_n=[0],  # mirio8q3gtv7fhdnmb3TpZ4EuafdzSs7zL
                             # amount=1000000000,
                             prev_hash=binascii.unhexlify('6f90f3c7cbec2258b0971056ef3fe34128dbde30daa9c0639a898f9977299d54'),
                             prev_index=1,
                             )

        out1 = proto_types.TxOutputType(address='mfiGQVPcRcaEvQPYDErR34DcCovtxYvUUV',
                              amount=1000000000 - 500000000 - 10000000,
                              script_type=proto_types.PAYTOADDRESS,
                              )

        out2 = proto_types.TxOutputType(address_n=[2],
                              amount=500000000,
                              script_type=proto_types.PAYTOADDRESS,
                              )

        with self.client:

# 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.py
import unittest
import common
import binascii
import itertools
import keepkeylib.messages_pb2 as proto
import keepkeylib.types_pb2 as proto_types
from keepkeylib.client import CallException
from keepkeylib import tx_api

                proto.TxRequest(request_type=proto_types.TXFINISHED),
            ])

            (signatures, serialized_tx) = self.client.sign_tx('Bitcoin', [inp1, ], [out1, ])

        # Accepted by network: tx fd79435246dee76b2f159d2db08032d666c95adc544de64c8c49f474df4a7fee
        self.assertEqual(binascii.hexlify(serialized_tx), '010000000182488650ef25a58fef6788bd71b8212038d7f2bbe4750bc7bcb44701e85ef6d5000000006b4830450221009a0b7be0d4ed3146ee262b42202841834698bb3ee39c24e7437df208b8b7077102202b79ab1e7736219387dffe8d615bbdba87e11477104b867ef47afed1a5ede7810121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff0160cc0500000000001976a914de9b2a8da088824e8fe51debea566617d851537888ac00000000')

    def test_testnet_one_two_fee(self):
        self.setup_mnemonic_nopin_nopassphrase()

        # tx: 6f90f3c7cbec2258b0971056ef3fe34128dbde30daa9c0639a898f9977299d54
        # input 1: 10.00000000 BTC
        inp1 = proto_types.TxInputType(address_n=[0],  # mirio8q3gtv7fhdnmb3TpZ4EuafdzSs7zL
                             # amount=1000000000,
                             prev_hash=binascii.unhexlify('6f90f3c7cbec2258b0971056ef3fe34128dbde30daa9c0639a898f9977299d54'),
                             prev_index=1,
                             )

        out1 = proto_types.TxOutputType(address='mfiGQVPcRcaEvQPYDErR34DcCovtxYvUUV',
                              amount=1000000000 - 500000000 - 10000000,
                              script_type=proto_types.PAYTOADDRESS,
                              )

        out2 = proto_types.TxOutputType(address_n=[2],
                              amount=500000000,
                              script_type=proto_types.PAYTOADDRESS,
                              )

        with self.client:

            self.client.set_tx_api(tx_api.TxApiTestnet)