mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-16 11:28:14 +00:00
525 lines
46 KiB
Python
525 lines
46 KiB
Python
# tx 4a7b7e0403ae5607e473949cfa03f09f2cd8b0f404bf99ce10b7303d86280bf7
|
|
# 100 UTXO for spending for unittests
|
|
|
|
import unittest
|
|
import common
|
|
import binascii
|
|
|
|
import trezorlib.messages_pb2 as proto
|
|
import trezorlib.types_pb2 as proto_types
|
|
from trezorlib.client import CallException
|
|
|
|
class FakeTestnetBlockchain(object):
|
|
def get_tx(self, txhash):
|
|
if txhash != '6f90f3c7cbec2258b0971056ef3fe34128dbde30daa9c0639a898f9977299d54':
|
|
raise Exception("Unexpected hash")
|
|
|
|
t = proto_types.TransactionType()
|
|
|
|
i = t.inputs.add()
|
|
i.prev_hash = binascii.unhexlify('ee336e79153d51f4f3e45278f1f77ab29fd5bb135dce467282e2aff22cb9c570')
|
|
i.prev_index = 1
|
|
i.script_sig = binascii.unhexlify('483045022066c418874dbe5628296700382d727ce1734928796068c26271472df09dccf1a20221009dec59d19f9d73db381fcd35c0fff757ad73e54ef59157b0d7c57e6739a092f00121033fef08c603943dc7d25f4ce65771762143b1cd8678343d660a1a76b9d1d3ced7')
|
|
|
|
i = t.inputs.add()
|
|
i.prev_hash = binascii.unhexlify('2fe4d8af2b44faccc10dd5a6578c923491d2d21269a1dfe8c83f492a30fb8f9f')
|
|
i.prev_index = 1
|
|
i.script_sig = binascii.unhexlify('47304402206fbb8e14be706b8557a2280d2a2a75c0a65c4f7936d90d510f0971c93f41f74402201b79c8c4e4ac4c944913611633c230193558296e70a36269b7fc3a80efa27d120121030cb5be79bdc36a4ff4443dbac43068cc43d638ea06ff2fa1b8dab389e39aefc7')
|
|
|
|
o = t.outputs.add()
|
|
o.amount = 403850989
|
|
o.script_pubkey = binascii.unhexlify('76a914f5a05c2664b40d3116b1c5086c9ba38ed15b742e88ac')
|
|
|
|
o = t.outputs.add()
|
|
o.amount = 1000000000
|
|
o.script_pubkey = binascii.unhexlify('76a91424a56db43cf6f2b02e838ea493f95d8d6047423188ac')
|
|
|
|
return t
|
|
|
|
class TestMsgSimplesigntx(common.TrezorTest):
|
|
|
|
def test_one_one_fee(self):
|
|
self.setup_mnemonic_nopin_nopassphrase()
|
|
|
|
# tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882
|
|
# input 0: 0.0039 BTC
|
|
|
|
inp1 = proto_types.TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
|
|
# amount=390000,
|
|
prev_hash=binascii.unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882'),
|
|
prev_index=0,
|
|
)
|
|
|
|
out1 = proto_types.TxOutputType(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
|
|
amount=390000 - 10000,
|
|
script_type=proto_types.PAYTOADDRESS,
|
|
)
|
|
|
|
with self.client:
|
|
msg = self.client._prepare_simple_sign_tx('Bitcoin', [inp1, ], [out1, ])
|
|
self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_ConfirmOutput),
|
|
proto.ButtonRequest(code=proto_types.ButtonRequest_SignTx),
|
|
proto.TxRequest(request_index=-1)])
|
|
tx = self.client.call(msg)
|
|
|
|
# Accepted by network: tx fd79435246dee76b2f159d2db08032d666c95adc544de64c8c49f474df4a7fee
|
|
self.assertEqual(binascii.hexlify(tx.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_func(FakeTestnetBlockchain().get_tx)
|
|
msg = self.client._prepare_simple_sign_tx('Testnet', [inp1, ], [out1, out2])
|
|
self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_ConfirmOutput),
|
|
# proto.ButtonRequest(code=proto_types.ButtonRequest_ConfirmOutput), # don't confirm change
|
|
proto.ButtonRequest(code=proto_types.ButtonRequest_SignTx),
|
|
proto.TxRequest()])
|
|
tx = self.client.call(msg)
|
|
|
|
self.assertEqual(binascii.hexlify(tx.serialized_tx), '0100000001549d2977998f899a63c0a9da30dedb2841e33fef561097b05822eccbc7f3906f010000006b4830450221009c2d30385519fdb13dce13d5ac038be07d7b2dad0b0f7b2c1c339d7255bcf553022056a2f5bceab3cd0ffed4d388387e631f419d67ff9ce7798e3d7dfe6a6d6ec4bd0121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff0280ce341d000000001976a9140223b1a09138753c9cb0baf95a0a62c82711567a88ac0065cd1d000000001976a9142db345c36563122e2fd0f5485fb7ea9bbf7cb5a288ac00000000')
|
|
|
|
def test_testnet_fee_too_high(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 - 20000000,
|
|
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_func(FakeTestnetBlockchain().get_tx)
|
|
msg = self.client._prepare_simple_sign_tx('Testnet', [inp1, ], [out1, out2])
|
|
self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_ConfirmOutput),
|
|
# proto.ButtonRequest(code=proto_types.ButtonRequest_ConfirmOutput), # don't confirm change
|
|
proto.ButtonRequest(code=proto_types.ButtonRequest_FeeOverThreshold),
|
|
proto.ButtonRequest(code=proto_types.ButtonRequest_SignTx),
|
|
proto.TxRequest()])
|
|
tx = self.client.call(msg)
|
|
|
|
self.assertEqual(binascii.hexlify(tx.serialized_tx), '0100000001549d2977998f899a63c0a9da30dedb2841e33fef561097b05822eccbc7f3906f010000006b483045022100d74e9fa5c7ff5966d52bce8d1d772c1e3ef1376395fb85a0bbf910e723bd606d02204cb8df6debd7c4c076632011bb1e180495bcf3630d2471c354bed56c2e45a2180121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff0200389c1c000000001976a9140223b1a09138753c9cb0baf95a0a62c82711567a88ac0065cd1d000000001976a9142db345c36563122e2fd0f5485fb7ea9bbf7cb5a288ac00000000')
|
|
|
|
def test_one_two_fee(self):
|
|
self.setup_mnemonic_nopin_nopassphrase()
|
|
|
|
# tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882
|
|
# input 0: 0.0039 BTC
|
|
|
|
inp1 = proto_types.TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
|
|
# amount=390000,
|
|
prev_hash=binascii.unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882'),
|
|
prev_index=0,
|
|
)
|
|
|
|
out1 = proto_types.TxOutputType(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
|
|
amount=390000 - 80000 - 10000,
|
|
script_type=proto_types.PAYTOADDRESS,
|
|
)
|
|
|
|
out2 = proto_types.TxOutputType(address_n=[1],
|
|
amount=80000,
|
|
script_type=proto_types.PAYTOADDRESS,
|
|
)
|
|
|
|
with self.client:
|
|
msg = self.client._prepare_simple_sign_tx('Bitcoin', [inp1, ], [out1, out2])
|
|
self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_ConfirmOutput),
|
|
# proto.ButtonRequest(code=proto_types.ButtonRequest_ConfirmOutput), # don't confirm change
|
|
proto.ButtonRequest(code=proto_types.ButtonRequest_SignTx),
|
|
proto.TxRequest()])
|
|
tx = self.client.call(msg)
|
|
|
|
self.assertEqual(binascii.hexlify(tx.serialized_tx), '010000000182488650ef25a58fef6788bd71b8212038d7f2bbe4750bc7bcb44701e85ef6d5000000006b483045022100c1400d8485d3bdcae7413e123148f35ece84806fc387ab88c66b469df89aef1702201d481d04216b319dc549ffe2333143629ba18828a4e2d1783ab719a6aa263eb70121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff02e0930400000000001976a914de9b2a8da088824e8fe51debea566617d851537888ac80380100000000001976a9140223b1a09138753c9cb0baf95a0a62c82711567a88ac00000000')
|
|
|
|
def test_one_three_fee(self):
|
|
self.setup_mnemonic_nopin_nopassphrase()
|
|
|
|
# tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882
|
|
# input 0: 0.0039 BTC
|
|
|
|
inp1 = proto_types.TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
|
|
# amount=390000,
|
|
prev_hash=binascii.unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882'),
|
|
prev_index=0,
|
|
)
|
|
|
|
out1 = proto_types.TxOutputType(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
|
|
amount=390000 - 80000 - 12000 - 10000,
|
|
script_type=proto_types.PAYTOADDRESS,
|
|
)
|
|
|
|
out2 = proto_types.TxOutputType(address='13uaUYn6XAooo88QvAqAVsiVvr2mAXutqP',
|
|
amount=12000,
|
|
script_type=proto_types.PAYTOADDRESS,
|
|
)
|
|
|
|
out3 = proto_types.TxOutputType(address_n=[1],
|
|
amount=80000,
|
|
script_type=proto_types.PAYTOADDRESS,
|
|
)
|
|
|
|
with self.client:
|
|
msg = self.client._prepare_simple_sign_tx('Bitcoin', [inp1, ], [out1, out2, out3])
|
|
self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_ConfirmOutput),
|
|
proto.ButtonRequest(code=proto_types.ButtonRequest_ConfirmOutput),
|
|
# proto.ButtonRequest(code=proto_types.ButtonRequest_ConfirmOutput), # don't confirm change
|
|
proto.ButtonRequest(code=proto_types.ButtonRequest_SignTx),
|
|
proto.TxRequest()])
|
|
tx = self.client.call(msg)
|
|
|
|
self.assertEqual(binascii.hexlify(tx.serialized_tx), '010000000182488650ef25a58fef6788bd71b8212038d7f2bbe4750bc7bcb44701e85ef6d5000000006b483045022100e695e2c530c7c0fc32e6b79b7cff56a7f70a8c9da787534f46b4204070f914fc02207b0879a81408a11e23b11d4c7965c62b5fc6d5c2d92340f5ee2da7b40e99314a0121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff0300650400000000001976a914de9b2a8da088824e8fe51debea566617d851537888ace02e0000000000001976a9141fe1d337fb81afca42818051e12fd18245d1b17288ac80380100000000001976a9140223b1a09138753c9cb0baf95a0a62c82711567a88ac00000000')
|
|
|
|
def test_two_two(self):
|
|
self.setup_mnemonic_nopin_nopassphrase()
|
|
|
|
# tx: c6be22d34946593bcad1d2b013e12f74159e69574ffea21581dad115572e031c
|
|
# input 1: 0.0010 BTC
|
|
# tx: 58497a7757224d1ff1941488d23087071103e5bf855f4c1c44e5c8d9d82ca46e
|
|
# input 1: 0.0011 BTC
|
|
|
|
inp1 = proto_types.TxInputType(address_n=[1], # 1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb
|
|
# amount=100000,
|
|
prev_hash=binascii.unhexlify('c6be22d34946593bcad1d2b013e12f74159e69574ffea21581dad115572e031c'),
|
|
prev_index=1,
|
|
)
|
|
|
|
inp2 = proto_types.TxInputType(address_n=[2], # 15AeAhtNJNKyowK8qPHwgpXkhsokzLtUpG
|
|
# amount=110000,
|
|
prev_hash=binascii.unhexlify('58497a7757224d1ff1941488d23087071103e5bf855f4c1c44e5c8d9d82ca46e'),
|
|
prev_index=1,
|
|
)
|
|
|
|
out1 = proto_types.TxOutputType(address='15Jvu3nZNP7u2ipw2533Q9VVgEu2Lu9F2B',
|
|
amount=210000 - 100000 - 10000,
|
|
script_type=proto_types.PAYTOADDRESS,
|
|
)
|
|
|
|
out2 = proto_types.TxOutputType(address_n=[3], # 1CmzyJp9w3NafXMSEFH4SLYUPAVCSUrrJ5
|
|
amount=100000,
|
|
script_type=proto_types.PAYTOADDRESS,
|
|
)
|
|
|
|
with self.client:
|
|
msg = self.client._prepare_simple_sign_tx('Bitcoin', [inp1, inp2], [out1, out2])
|
|
self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_ConfirmOutput),
|
|
# proto.ButtonRequest(code=proto_types.ButtonRequest_ConfirmOutput), # don't confirm change
|
|
proto.ButtonRequest(code=proto_types.ButtonRequest_SignTx),
|
|
proto.TxRequest()])
|
|
tx = self.client.call(msg)
|
|
|
|
# Accepted by network: tx c63e24ed820c5851b60c54613fbc4bcb37df6cd49b4c96143e99580a472f79fb
|
|
self.assertEqual(binascii.hexlify(tx.serialized_tx), '01000000021c032e5715d1da8115a2fe4f57699e15742fe113b0d2d1ca3b594649d322bec6010000006b483045022100f773c403b2f85a5c1d6c9c4ad69c43de66930fff4b1bc818eb257af98305546a0220443bde4be439f276a6ce793664b463580e210ec6c9255d68354449ac0443c76501210338d78612e990f2eea0c426b5e48a8db70b9d7ed66282b3b26511e0b1c75515a6ffffffff6ea42cd8d9c8e5441c4c5f85bfe50311078730d2881494f11f4d2257777a4958010000006b48304502210090cff1c1911e771605358a8cddd5ae94c7b60cc96e50275908d9bf9d6367c79f02202bfa72e10260a146abd59d0526e1335bacfbb2b4401780e9e3a7441b0480c8da0121038caebd6f753bbbd2bb1f3346a43cd32140648583673a31d62f2dfb56ad0ab9e3ffffffff02a0860100000000001976a9142f4490d5263906e4887ca2996b9e207af3e7824088aca0860100000000001976a914812c13d97f9159e54e326b481b8f88a73df8507a88ac00000000')
|
|
|
|
'''
|
|
def test_255_outputs(self):
|
|
self.setup_mnemonic_nopin_nopassphrase()
|
|
|
|
# Tests if device implements serialization of len(outputs) correctly
|
|
|
|
# tx: c63e24ed820c5851b60c54613fbc4bcb37df6cd49b4c96143e99580a472f79fb
|
|
# index 1: 0.0010 BTC
|
|
# tx: 39a29e954977662ab3879c66fb251ef753e0912223a83d1dcb009111d28265e5
|
|
# index 1: 0.0254 BTC
|
|
|
|
inp1 = proto_types.TxInputType(address_n=[3], # 1CmzyJp9w3NafXMSEFH4SLYUPAVCSUrrJ5
|
|
# amount=100000,
|
|
prev_hash=binascii.unhexlify('c63e24ed820c5851b60c54613fbc4bcb37df6cd49b4c96143e99580a472f79fb'),
|
|
prev_index=1,
|
|
)
|
|
|
|
inp2 = proto_types.TxInputType(address_n=[3], # 1CmzyJp9w3NafXMSEFH4SLYUPAVCSUrrJ5
|
|
# amount=2540000,
|
|
prev_hash=binascii.unhexlify('39a29e954977662ab3879c66fb251ef753e0912223a83d1dcb009111d28265e5'),
|
|
prev_index=1,
|
|
)
|
|
|
|
outputs = []
|
|
for _ in range(255):
|
|
out = proto_types.TxOutputType(address='1NwN6UduuVkJi6sw3gSiKZaCY5rHgVXC2h',
|
|
amount=10200,
|
|
script_type=proto_types.PAYTOADDRESS,
|
|
)
|
|
outputs.append(out)
|
|
|
|
with self.client:
|
|
msg = self.client._prepare_simple_sign_tx('Bitcoin', [inp1, inp2], outputs)
|
|
self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_ConfirmOutput), ] * 255 + \
|
|
[proto.ButtonRequest(code=proto_types.ButtonRequest_SignTx),
|
|
proto.TxRequest(), ])
|
|
tx = self.client.call(msg)
|
|
|
|
self.assertEqual(binascii.hexlify(tx.serialized_tx), '0100000002fb792f470a58993e14964c9bd46cdf37cb4bbc3f61540cb651580c82ed243ec6010000006b483045022100969da46f94a81f34f3717b014e0c3e1826eda1b0022ec2f9ce39f3d750ab9235022026da269770993211a1503413566a339bbb4389a482fffcf8e1f76713fc3b94f5012103477b9f0f34ae85434ce795f0c5e1e90c9420e5b5fad084d7cce9a487b94a7902ffffffffe56582d2119100cb1d3da8232291e053f71e25fb669c87b32a667749959ea239010000006a473044022052e1419bb237b9db400ab5e3df16db6355619d545fde9030924a360763ae9ad40220704beab04d72ecaeb42eca7d98faca7a0941e65f2e1341f183be2b83e6b09e1c012103477b9f0f34ae85434ce795f0c5e1e90c9420e5b5fad084d7cce9a487b94a7902fffffffffdff00d8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088acd8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088ac00000000')
|
|
'''
|
|
|
|
def test_fee_too_high(self):
|
|
self.setup_mnemonic_nopin_nopassphrase()
|
|
|
|
# tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882
|
|
# input 0: 0.0039 BTC
|
|
|
|
inp1 = proto_types.TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
|
|
# amount=390000,
|
|
prev_hash=binascii.unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882'),
|
|
prev_index=0,
|
|
)
|
|
|
|
out1 = proto_types.TxOutputType(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
|
|
amount=390000 - 50000,
|
|
script_type=proto_types.PAYTOADDRESS,
|
|
)
|
|
|
|
with self.client:
|
|
msg = self.client._prepare_simple_sign_tx('Bitcoin', [inp1, ], [out1, ])
|
|
self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_ConfirmOutput),
|
|
proto.ButtonRequest(code=proto_types.ButtonRequest_FeeOverThreshold),
|
|
proto.ButtonRequest(code=proto_types.ButtonRequest_SignTx),
|
|
proto.TxRequest()])
|
|
tx = self.client.call(msg)
|
|
|
|
self.assertEqual(binascii.hexlify(tx.serialized_tx), '010000000182488650ef25a58fef6788bd71b8212038d7f2bbe4750bc7bcb44701e85ef6d5000000006a4730440220361b8268718533055682f4532d30c553ce778f70b217457a9aa1956e457c5aac0220538ae285bb340484bb09a67635d29192a14e61d8a8385b8b090a92e3e97e1c010121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff0120300500000000001976a914de9b2a8da088824e8fe51debea566617d851537888ac00000000')
|
|
|
|
def test_not_enough_funds(self):
|
|
self.setup_mnemonic_nopin_nopassphrase()
|
|
|
|
# tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882
|
|
# input 0: 0.0039 BTC
|
|
|
|
inp1 = proto_types.TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
|
|
# amount=390000,
|
|
prev_hash=binascii.unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882'),
|
|
prev_index=0,
|
|
)
|
|
|
|
out1 = proto_types.TxOutputType(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
|
|
amount=400000,
|
|
script_type=proto_types.PAYTOADDRESS,
|
|
)
|
|
|
|
with self.client:
|
|
msg = self.client._prepare_simple_sign_tx('Bitcoin', [inp1, ], [out1, ])
|
|
self.client.set_expected_responses([proto.ButtonRequest(code=proto_types.ButtonRequest_ConfirmOutput),
|
|
proto.Failure(code=proto_types.Failure_NotEnoughFunds)])
|
|
|
|
try:
|
|
self.client.call(msg)
|
|
except CallException as e:
|
|
self.assertEqual(e.args[0], proto_types.Failure_NotEnoughFunds)
|
|
else:
|
|
self.assert_(False, "types.Failure_NotEnoughFunds expected")
|
|
|
|
'''
|
|
def test_simplesigntx_testnet(self):
|
|
self.client.load_device_by_xprv('xprv9s21ZrQH143K3zttRjiQmYwyugvd13pnd2VzefWrfSouRfnj5oSkJgBQXxtn18E9mqrDop7fQ8Xnb9JCLPE4vghzhpU4dT33ZJ7frjzTEW8',
|
|
'', False, 'testnet')
|
|
|
|
inp1 = proto_types.TxInputType(address_n=[6], # mo8uUSFJULCMA4neRS9aS9jiXZ1N72FSLK
|
|
# amount=390000,
|
|
prev_hash=binascii.unhexlify('d83b27f16ce5069e0c8e4a02813f252500e257744d5b00c9b6128be7189117b1'),
|
|
prev_index=0,
|
|
)
|
|
|
|
out1 = proto_types.TxOutputType(address='mjKKH3Dk95VMbdNnDQYHZXoQ9QwuCZocwb',
|
|
amount=80085000,
|
|
script_type=proto_types.PAYTOADDRESS,
|
|
)
|
|
|
|
rawtx = {'d83b27f16ce5069e0c8e4a02813f252500e257744d5b00c9b6128be7189117b1': '01000000013b21cc65080c57793d0e47045a24d8e92262dc47efdc425fd5cad9a25e928f6c000000006b483045022100bde591f2c997bafa8388916663b148f4093914851a33a9903da69ad97afa6f470220138c6ff11321339974bac9c0992d7b9d72aef0c2d098f26267ec9f05d532c859012103edcc8dc5cac7dca6ed191d812621fb300863fea0dd5d14180b482b917a35acc4ffffffff020800c604000000001976a91453958011070469e2ef5e1115f34f509717d6884288acf8c99502000000001976a9141e2ba9407a6920246d0f345beecb89ed47c99a7788ac00000000'}
|
|
tx = self.client.simple_sign_tx('Testnet', [inp1, ], [out1, ])
|
|
print binascii.hexlify(tx.serialized_tx)
|
|
self.assertEqual(binascii.hexlify(tx.serialized_tx), '010000000182488650ef25a58fef6788bd71b8212038d7f2bbe4750bc7bcb44701e85ef6d5000000006b4830450221009a0b7be0d4ed3146ee262b42202841834698bb3ee39c24e7437df208b8b7077102202b79ab1e7736219387dffe8d615bbdba87e11477104b867ef47afed1a5ede7810121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff0160cc0500000000001976a914de9b2a8da088824e8fe51debea566617d851537888ac00000000')
|
|
|
|
def test_signtx(self):
|
|
expected_tx = '01000000012de70f7d6ffed0db70f8882f3fca90db9bb09f0e99bce27468c23d3c994fcd56' \
|
|
'010000008b4830450221009b985e14d53cfeed3496846db6ddaa77a0206138d0df4c2ccd3b' \
|
|
'759e91bae3e1022004c76e10f99ccac8ced761719181a96bae25a74829eab3ecb8f29eb07f' \
|
|
'e18f7e01410436ae8595f03a7324d1d1482ede8560a4508c767fbc662559482d5759b32209' \
|
|
'a62964699995f6e018cfbeb7a71a66d4c64fa38875d79ead0a9ac66f59c1c8b3a3ffffffff' \
|
|
'0250c30000000000001976a91444ce5c6789b0bb0e8a9ab9a4769fe181cb274c4688aca086' \
|
|
'0100000000001976a9149e03078026388661b197129a43f0f64f88379ce688ac00000000'
|
|
|
|
inp1 = proto.TxInput(index=0,
|
|
address_n=[1, 0],
|
|
amount=200000, # 0.002 BTC
|
|
prev_hash=binascii.unhexlify('56cd4f993c3dc26874e2bc990e9fb09bdb90ca3f2f88f870dbd0fe6f7d0fe72d'),
|
|
prev_index=1,
|
|
#script_sig=
|
|
)
|
|
|
|
out1 = proto.TxOutput(index=0,
|
|
address='1GnnT11aZeH6QZCtT7EjCvRF3EXHoY3owE',
|
|
address_n=[0, 1],
|
|
amount=50000, # 0.0005 BTC
|
|
script_type=proto.PAYTOADDRESS,
|
|
#script_args=
|
|
)
|
|
|
|
out2 = proto.TxOutput(index=1,
|
|
address='1FQVPnjrbkPWeA8poUoEnX9U3n9DyhAVtv',
|
|
#address_n=[],
|
|
amount=100000, # 0.001 BTC
|
|
script_type=proto.PAYTOADDRESS,
|
|
#script_args=
|
|
)
|
|
|
|
print binascii.hexlify(self.client.sign_tx([inp1], [out1, out2])[1])
|
|
'''
|
|
'''
|
|
def test_workflow(self):
|
|
inp1 = proto.TxInput(index=0,
|
|
address_n=[1,0],
|
|
amount=100000000,
|
|
prev_hash='prevhash1234354346543456543654',
|
|
prev_index=11,
|
|
)
|
|
|
|
inp2 = proto.TxInput(index=1,
|
|
address_n=[2,0],
|
|
amount=100000000,
|
|
prev_hash='prevhash2222254346543456543654',
|
|
prev_index=11,
|
|
)
|
|
|
|
out1 = proto.TxOutput(index=0,
|
|
address='1BitkeyP2nDd5oa647AjvBbbwST54W5Zmx',
|
|
amount=100000000,
|
|
script_type=proto.PAYTOADDRESS,
|
|
)
|
|
|
|
out2 = proto.TxOutput(index=1,
|
|
address='1BitkeyP2nDd5oa647AjvBbbwST54W5Zmx',
|
|
#address_n=[],
|
|
amount=100000000,
|
|
script_type=proto.PAYTOADDRESS,
|
|
#script_args=
|
|
)
|
|
|
|
serialized = ''
|
|
|
|
# Prepare and send initial message
|
|
tx = proto.SignTx()
|
|
tx.algo = proto.ELECTRUM
|
|
tx.random = self.client._get_local_entropy()
|
|
tx.inputs_count = 2
|
|
tx.outputs_count = 2
|
|
|
|
res = self.client.call(tx)
|
|
self.assertIsInstance(res, proto.TxRequest)
|
|
self.assertEqual(res.request_type, proto.TXINPUT)
|
|
self.assertEqual(res.request_index, 0)
|
|
self.assertEqual(res.signature, '')
|
|
self.assertEqual(res.serialized_tx, '')
|
|
|
|
# FIRST SIGNATURE
|
|
res = self.client.call(inp1)
|
|
self.assertIsInstance(res, proto.TxRequest)
|
|
self.assertEqual(res.request_type, proto.TXINPUT)
|
|
self.assertEqual(res.request_index, 1)
|
|
self.assertEqual(res.signature, '')
|
|
self.assertEqual(res.serialized_tx, '')
|
|
|
|
res = self.client.call(inp2)
|
|
self.assertIsInstance(res, proto.TxRequest)
|
|
self.assertEqual(res.request_type, proto.TXOUTPUT)
|
|
self.assertEqual(res.request_index, 0)
|
|
self.assertEqual(res.signature, '')
|
|
self.assertEqual(res.serialized_tx, '')
|
|
|
|
res = self.client.call(out1)
|
|
self.assertIsInstance(res, proto.TxRequest)
|
|
self.assertEqual(res.request_type, proto.TXOUTPUT)
|
|
self.assertEqual(res.request_index, 1)
|
|
self.assertEqual(res.signature, '')
|
|
self.assertEqual(res.serialized_tx, '')
|
|
|
|
res = self.client.call(out2)
|
|
self.assertIsInstance(res, proto.TxRequest)
|
|
self.assertEqual(res.request_type, proto.TXINPUT)
|
|
self.assertEqual(res.request_index, 0)
|
|
self.assertNotEqual(res.signature, '')
|
|
self.assertNotEqual(res.serialized_tx, '')
|
|
serialized += res.serialized_tx
|
|
|
|
# SECOND SIGNATURE
|
|
res = self.client.call(inp1)
|
|
self.assertIsInstance(res, proto.TxRequest)
|
|
self.assertEqual(res.request_type, proto.TXINPUT)
|
|
self.assertEqual(res.request_index, 1)
|
|
self.assertEqual(res.signature, '')
|
|
self.assertEqual(res.serialized_tx, '')
|
|
|
|
res = self.client.call(inp2)
|
|
self.assertIsInstance(res, proto.TxRequest)
|
|
self.assertEqual(res.request_type, proto.TXOUTPUT)
|
|
self.assertEqual(res.request_index, 0)
|
|
self.assertEqual(res.signature, '')
|
|
self.assertEqual(res.serialized_tx, '')
|
|
|
|
res = self.client.call(out1)
|
|
self.assertIsInstance(res, proto.TxRequest)
|
|
self.assertEqual(res.request_type, proto.TXOUTPUT)
|
|
self.assertEqual(res.request_index, 1)
|
|
self.assertEqual(res.signature, '')
|
|
self.assertEqual(res.serialized_tx, '')
|
|
|
|
res = self.client.call(out2)
|
|
self.assertIsInstance(res, proto.TxRequest)
|
|
self.assertEqual(res.request_type, proto.TXOUTPUT)
|
|
self.assertEqual(res.request_index, 0)
|
|
self.assertNotEqual(res.signature, '')
|
|
self.assertNotEqual(res.serialized_tx, '')
|
|
serialized += res.serialized_tx
|
|
|
|
# FINALIZING OUTPUTS
|
|
res = self.client.call(out1)
|
|
self.assertIsInstance(res, proto.TxRequest)
|
|
self.assertEqual(res.request_type, proto.TXOUTPUT)
|
|
self.assertEqual(res.request_index, 1)
|
|
self.assertEqual(res.signature, '')
|
|
self.assertNotEqual(res.serialized_tx, '')
|
|
serialized += res.serialized_tx
|
|
|
|
res = self.client.call(out2)
|
|
self.assertIsInstance(res, proto.TxRequest)
|
|
self.assertEqual(res.request_type, proto.TXOUTPUT)
|
|
self.assertEqual(res.request_index, -1)
|
|
self.assertEqual(res.signature, '')
|
|
self.assertNotEqual(res.serialized_tx, '')
|
|
serialized += res.serialized_tx
|
|
|
|
print binascii.hexlify(serialized)
|
|
'''
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|