2017-11-10 13:10:19 +00:00
|
|
|
from common import *
|
|
|
|
|
|
|
|
from trezor.utils import chunks
|
2018-12-13 12:53:53 +00:00
|
|
|
from trezor.crypto import bip39
|
2021-03-23 12:35:27 +00:00
|
|
|
from trezor.messages import SignTx
|
|
|
|
from trezor.messages import TxAckInput
|
|
|
|
from trezor.messages import TxAckInputWrapper
|
|
|
|
from trezor.messages import TxInput
|
|
|
|
from trezor.messages import TxAckOutput
|
|
|
|
from trezor.messages import TxAckOutputWrapper
|
|
|
|
from trezor.messages import TxOutput
|
|
|
|
from trezor.messages import TxAckPrevMeta
|
|
|
|
from trezor.messages import PrevTx
|
|
|
|
from trezor.messages import TxAckPrevInput
|
|
|
|
from trezor.messages import TxAckPrevInputWrapper
|
|
|
|
from trezor.messages import PrevInput
|
|
|
|
from trezor.messages import TxAckPrevOutput
|
|
|
|
from trezor.messages import TxAckPrevOutputWrapper
|
|
|
|
from trezor.messages import PrevOutput
|
|
|
|
from trezor.messages import TxRequest
|
|
|
|
from trezor.enums.RequestType import TXINPUT, TXMETA, TXOUTPUT, TXFINISHED
|
|
|
|
from trezor.messages import TxRequestDetailsType
|
|
|
|
from trezor.messages import TxRequestSerializedType
|
|
|
|
from trezor.enums import AmountUnit
|
|
|
|
from trezor.enums import InputScriptType
|
|
|
|
from trezor.enums import OutputScriptType
|
2020-05-15 18:35:09 +00:00
|
|
|
from trezor import wire
|
2017-11-10 13:10:19 +00:00
|
|
|
|
|
|
|
from apps.common import coins
|
2020-07-23 14:20:54 +00:00
|
|
|
from apps.common.keychain import Keychain
|
2022-09-21 07:56:28 +00:00
|
|
|
from apps.bitcoin.keychain import _get_schemas_for_coin
|
2020-05-15 18:35:09 +00:00
|
|
|
from apps.bitcoin.sign_tx import helpers, bitcoin
|
2020-04-16 12:31:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
EMPTY_SERIALIZED = TxRequestSerializedType(serialized_tx=bytearray())
|
2017-11-10 13:10:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestSignSegwitTxNativeP2WPKH(unittest.TestCase):
|
|
|
|
# pylint: disable=C0301
|
|
|
|
|
|
|
|
def test_send_native_p2wpkh(self):
|
|
|
|
|
|
|
|
coin = coins.by_name('Testnet')
|
|
|
|
seed = bip39.seed(' '.join(['all'] * 12), '')
|
|
|
|
|
2020-09-23 11:08:26 +00:00
|
|
|
inp1 = TxInput(
|
2017-11-10 13:10:19 +00:00
|
|
|
# 49'/1'/0'/0/0" - tb1qqzv60m9ajw8drqulta4ld4gfx0rdh82un5s65s
|
|
|
|
address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0],
|
|
|
|
amount=12300000,
|
|
|
|
prev_hash=unhexlify('09144602765ce3dd8f4329445b20e3684e948709c5cdcaf12da3bb079c99448a'),
|
|
|
|
prev_index=0,
|
|
|
|
script_type=InputScriptType.SPENDWITNESS,
|
|
|
|
sequence=0xffffffff,
|
2017-11-23 17:40:27 +00:00
|
|
|
multisig=None,
|
2017-11-10 13:10:19 +00:00
|
|
|
)
|
2020-09-23 11:08:26 +00:00
|
|
|
ptx1 = PrevTx(version=1, lock_time=0, inputs_count=1, outputs_count=2, extra_data_len=0)
|
|
|
|
pinp1 = PrevInput(script_sig=unhexlify('160014d16b8c0680c61fc6ed2e407455715055e41052f5'),
|
2020-05-15 14:55:18 +00:00
|
|
|
prev_hash=unhexlify('20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337'),
|
|
|
|
prev_index=0,
|
|
|
|
sequence=4294967295)
|
2020-09-23 11:08:26 +00:00
|
|
|
pout1 = PrevOutput(script_pubkey=unhexlify('00140099a7ecbd938ed1839f5f6bf6d50933c6db9d5c'),
|
2020-05-15 14:55:18 +00:00
|
|
|
amount=12300000)
|
2020-09-23 11:08:26 +00:00
|
|
|
pout2 = PrevOutput(script_pubkey=unhexlify('a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'),
|
2020-05-15 14:55:18 +00:00
|
|
|
amount=111145789)
|
|
|
|
|
2020-09-23 11:08:26 +00:00
|
|
|
out1 = TxOutput(
|
2017-11-10 13:10:19 +00:00
|
|
|
address='2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp',
|
|
|
|
amount=5000000,
|
|
|
|
script_type=OutputScriptType.PAYTOADDRESS,
|
2018-02-26 13:17:39 +00:00
|
|
|
address_n=[],
|
2018-02-12 11:40:18 +00:00
|
|
|
multisig=None,
|
2017-11-10 13:10:19 +00:00
|
|
|
)
|
2020-09-23 11:08:26 +00:00
|
|
|
out2 = TxOutput(
|
2017-11-20 16:41:23 +00:00
|
|
|
address='tb1q694ccp5qcc0udmfwgp692u2s2hjpq5h407urtu',
|
2017-11-10 13:10:19 +00:00
|
|
|
script_type=OutputScriptType.PAYTOADDRESS,
|
|
|
|
amount=12300000 - 11000 - 5000000,
|
2018-02-26 13:17:39 +00:00
|
|
|
address_n=[],
|
2018-02-12 11:40:18 +00:00
|
|
|
multisig=None,
|
2017-11-10 13:10:19 +00:00
|
|
|
)
|
2020-09-16 12:51:19 +00:00
|
|
|
tx = SignTx(coin_name='Testnet', version=1, lock_time=0, inputs_count=1, outputs_count=2)
|
2017-11-10 13:10:19 +00:00
|
|
|
|
2022-08-02 09:05:06 +00:00
|
|
|
# precomputed tx weight is 142 = ceil(566 / 4)
|
|
|
|
fee_rate = 11000 / 142
|
2022-05-03 13:21:58 +00:00
|
|
|
|
2017-11-10 13:10:19 +00:00
|
|
|
messages = [
|
|
|
|
None,
|
|
|
|
|
|
|
|
# check fee
|
2020-04-16 12:31:15 +00:00
|
|
|
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
|
2020-09-16 12:51:19 +00:00
|
|
|
TxAckInput(tx=TxAckInputWrapper(input=inp1)),
|
2017-11-10 13:10:19 +00:00
|
|
|
|
2020-07-17 15:39:43 +00:00
|
|
|
helpers.UiConfirmForeignAddress(address_n=inp1.address_n),
|
|
|
|
True,
|
|
|
|
|
2020-04-16 12:31:15 +00:00
|
|
|
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
|
2020-09-16 12:51:19 +00:00
|
|
|
TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
|
2017-11-10 13:10:19 +00:00
|
|
|
|
2020-11-23 14:01:25 +00:00
|
|
|
helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN),
|
2017-11-10 13:10:19 +00:00
|
|
|
True,
|
|
|
|
|
2020-04-16 12:31:15 +00:00
|
|
|
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED),
|
2020-09-16 12:51:19 +00:00
|
|
|
TxAckOutput(tx=TxAckOutputWrapper(output=out2)),
|
2017-11-10 13:10:19 +00:00
|
|
|
|
2020-11-23 14:01:25 +00:00
|
|
|
helpers.UiConfirmOutput(out2, coin, AmountUnit.BITCOIN),
|
2017-11-10 13:10:19 +00:00
|
|
|
True,
|
|
|
|
|
2022-05-03 13:21:58 +00:00
|
|
|
helpers.UiConfirmTotal(12300000, 11000, fee_rate, coin, AmountUnit.BITCOIN),
|
2017-11-10 13:10:19 +00:00
|
|
|
True,
|
|
|
|
|
2020-08-22 15:28:29 +00:00
|
|
|
# check prev tx
|
|
|
|
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
|
2020-09-16 12:51:19 +00:00
|
|
|
TxAckInput(tx=TxAckInputWrapper(input=inp1)),
|
2020-08-22 15:28:29 +00:00
|
|
|
|
|
|
|
TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
|
2020-09-16 12:51:19 +00:00
|
|
|
TxAckPrevMeta(tx=ptx1),
|
2020-08-22 15:28:29 +00:00
|
|
|
|
|
|
|
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
|
2020-09-16 12:51:19 +00:00
|
|
|
TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp1)),
|
2020-08-22 15:28:29 +00:00
|
|
|
|
|
|
|
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
|
2020-09-16 12:51:19 +00:00
|
|
|
TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout1)),
|
2020-08-22 15:28:29 +00:00
|
|
|
|
|
|
|
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
|
2020-09-16 12:51:19 +00:00
|
|
|
TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout2)),
|
2020-08-22 15:28:29 +00:00
|
|
|
|
2017-11-10 13:10:19 +00:00
|
|
|
# sign tx
|
2020-04-16 12:31:15 +00:00
|
|
|
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(
|
|
|
|
# returned serialized header
|
|
|
|
serialized_tx=unhexlify('01000000000101'),
|
|
|
|
)),
|
2020-09-16 12:51:19 +00:00
|
|
|
TxAckInput(tx=TxAckInputWrapper(input=inp1)),
|
2017-11-10 13:10:19 +00:00
|
|
|
|
|
|
|
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(
|
|
|
|
# returned serialized inp1
|
2020-04-16 12:31:15 +00:00
|
|
|
serialized_tx=unhexlify('8a44999c07bba32df1cacdc50987944e68e3205b4429438fdde35c76024614090000000000ffffffff02'),
|
2017-11-10 13:10:19 +00:00
|
|
|
)),
|
2020-09-16 12:51:19 +00:00
|
|
|
TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
|
2017-11-10 13:10:19 +00:00
|
|
|
|
|
|
|
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=TxRequestSerializedType(
|
|
|
|
# returned serialized out1
|
2020-04-16 12:31:15 +00:00
|
|
|
serialized_tx=unhexlify('404b4c000000000017a9147a55d61848e77ca266e79a39bfc85c580a6426c987'),
|
2017-11-10 13:10:19 +00:00
|
|
|
signature_index=None,
|
|
|
|
signature=None,
|
|
|
|
)),
|
2020-09-16 12:51:19 +00:00
|
|
|
TxAckOutput(tx=TxAckOutputWrapper(output=out2)),
|
2017-11-10 13:10:19 +00:00
|
|
|
|
|
|
|
# segwit
|
|
|
|
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(
|
|
|
|
# returned serialized out2
|
|
|
|
serialized_tx=unhexlify('a8386f0000000000160014d16b8c0680c61fc6ed2e407455715055e41052f5'),
|
|
|
|
signature_index=None,
|
|
|
|
signature=None,
|
|
|
|
)),
|
2020-09-16 12:51:19 +00:00
|
|
|
TxAckInput(tx=TxAckInputWrapper(input=inp1)),
|
2017-11-10 13:10:19 +00:00
|
|
|
|
2020-04-22 19:26:04 +00:00
|
|
|
TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType(
|
2017-11-10 13:10:19 +00:00
|
|
|
serialized_tx=unhexlify('02483045022100a7ca8f097525f9044e64376dc0a0f5d4aeb8d15d66808ba97979a0475b06b66502200597c8ebcef63e047f9aeef1a8001d3560470cf896c12f6990eec4faec599b950121033add1f0e8e3c3136f7428dd4a4de1057380bd311f5b0856e2269170b4ffa65bf00000000'),
|
2017-11-20 16:41:23 +00:00
|
|
|
signature_index=0,
|
|
|
|
signature=unhexlify('3045022100a7ca8f097525f9044e64376dc0a0f5d4aeb8d15d66808ba97979a0475b06b66502200597c8ebcef63e047f9aeef1a8001d3560470cf896c12f6990eec4faec599b95'),
|
2017-11-10 13:10:19 +00:00
|
|
|
)),
|
|
|
|
]
|
|
|
|
|
2022-09-21 07:56:28 +00:00
|
|
|
ns = _get_schemas_for_coin(coin)
|
2020-07-23 14:20:54 +00:00
|
|
|
keychain = Keychain(seed, coin.curve_name, ns)
|
2021-01-30 00:49:18 +00:00
|
|
|
signer = bitcoin.Bitcoin(tx, keychain, coin, None).signer()
|
2017-11-10 13:10:19 +00:00
|
|
|
for request, response in chunks(messages, 2):
|
2020-04-16 12:31:15 +00:00
|
|
|
res = signer.send(request)
|
2020-09-16 12:51:19 +00:00
|
|
|
if isinstance(res, tuple):
|
|
|
|
_, res = res
|
2020-04-16 12:31:15 +00:00
|
|
|
self.assertEqual(res, response)
|
2017-11-10 13:10:19 +00:00
|
|
|
with self.assertRaises(StopIteration):
|
|
|
|
signer.send(None)
|
|
|
|
|
|
|
|
def test_send_native_p2wpkh_change(self):
|
|
|
|
|
|
|
|
coin = coins.by_name('Testnet')
|
|
|
|
seed = bip39.seed(' '.join(['all'] * 12), '')
|
|
|
|
|
2020-09-23 11:08:26 +00:00
|
|
|
inp1 = TxInput(
|
2017-11-10 13:10:19 +00:00
|
|
|
# 49'/1'/0'/0/0" - tb1qqzv60m9ajw8drqulta4ld4gfx0rdh82un5s65s
|
|
|
|
address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0],
|
|
|
|
amount=12300000,
|
|
|
|
prev_hash=unhexlify('09144602765ce3dd8f4329445b20e3684e948709c5cdcaf12da3bb079c99448a'),
|
|
|
|
prev_index=0,
|
|
|
|
script_type=InputScriptType.SPENDWITNESS,
|
|
|
|
sequence=0xffffffff,
|
2017-11-23 17:40:27 +00:00
|
|
|
multisig=None,
|
2017-11-10 13:10:19 +00:00
|
|
|
)
|
2020-09-23 11:08:26 +00:00
|
|
|
ptx1 = PrevTx(version=1, lock_time=0, inputs_count=1, outputs_count=2, extra_data_len=0)
|
|
|
|
pinp1 = PrevInput(script_sig=unhexlify('160014d16b8c0680c61fc6ed2e407455715055e41052f5'),
|
2020-05-15 14:55:18 +00:00
|
|
|
prev_hash=unhexlify('20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337'),
|
|
|
|
prev_index=0,
|
|
|
|
sequence=4294967295)
|
2020-09-23 11:08:26 +00:00
|
|
|
pout1 = PrevOutput(script_pubkey=unhexlify('00140099a7ecbd938ed1839f5f6bf6d50933c6db9d5c'),
|
2020-05-15 14:55:18 +00:00
|
|
|
amount=12300000)
|
2020-09-23 11:08:26 +00:00
|
|
|
pout2 = PrevOutput(script_pubkey=unhexlify('a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'),
|
2020-05-15 14:55:18 +00:00
|
|
|
amount=111145789)
|
|
|
|
|
2020-09-23 11:08:26 +00:00
|
|
|
out1 = TxOutput(
|
2017-11-10 13:10:19 +00:00
|
|
|
address='2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp',
|
|
|
|
amount=5000000,
|
|
|
|
script_type=OutputScriptType.PAYTOADDRESS,
|
2018-02-26 13:17:39 +00:00
|
|
|
address_n=[],
|
2018-02-12 11:40:18 +00:00
|
|
|
multisig=None,
|
2017-11-10 13:10:19 +00:00
|
|
|
)
|
2020-09-23 11:08:26 +00:00
|
|
|
out2 = TxOutput(
|
2017-11-10 13:10:19 +00:00
|
|
|
address=None,
|
2022-05-03 13:21:58 +00:00
|
|
|
# 49'/1'/0'/1/0" - 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
|
2017-11-10 13:10:19 +00:00
|
|
|
address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0],
|
|
|
|
script_type=OutputScriptType.PAYTOWITNESS,
|
|
|
|
amount=12300000 - 11000 - 5000000,
|
2018-02-12 11:40:18 +00:00
|
|
|
multisig=None,
|
2017-11-10 13:10:19 +00:00
|
|
|
)
|
2020-09-16 12:51:19 +00:00
|
|
|
tx = SignTx(coin_name='Testnet', version=1, lock_time=0, inputs_count=1, outputs_count=2)
|
2017-11-10 13:10:19 +00:00
|
|
|
|
2022-08-02 09:05:06 +00:00
|
|
|
# precomputed tx weight is 142 = ceil(566 / 4)
|
|
|
|
fee_rate = 11000 / 142
|
2022-05-03 13:21:58 +00:00
|
|
|
|
2017-11-10 13:10:19 +00:00
|
|
|
messages = [
|
|
|
|
None,
|
|
|
|
|
|
|
|
# check fee
|
2020-04-16 12:31:15 +00:00
|
|
|
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
|
2020-09-16 12:51:19 +00:00
|
|
|
TxAckInput(tx=TxAckInputWrapper(input=inp1)),
|
2017-11-10 13:10:19 +00:00
|
|
|
|
2020-07-17 15:39:43 +00:00
|
|
|
helpers.UiConfirmForeignAddress(address_n=inp1.address_n),
|
|
|
|
True,
|
|
|
|
|
2020-04-16 12:31:15 +00:00
|
|
|
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
|
2020-09-16 12:51:19 +00:00
|
|
|
TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
|
2017-11-10 13:10:19 +00:00
|
|
|
|
2020-11-23 14:01:25 +00:00
|
|
|
helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN),
|
2017-11-10 13:10:19 +00:00
|
|
|
True,
|
|
|
|
|
2020-04-16 12:31:15 +00:00
|
|
|
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED),
|
2020-09-16 12:51:19 +00:00
|
|
|
TxAckOutput(tx=TxAckOutputWrapper(output=out2)),
|
2017-11-10 13:10:19 +00:00
|
|
|
|
2022-05-03 13:21:58 +00:00
|
|
|
helpers.UiConfirmTotal(5000000 + 11000, 11000, fee_rate, coin, AmountUnit.BITCOIN),
|
2017-11-10 13:10:19 +00:00
|
|
|
True,
|
|
|
|
|
2020-08-22 15:28:29 +00:00
|
|
|
# check prev tx
|
|
|
|
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
|
2020-09-16 12:51:19 +00:00
|
|
|
TxAckInput(tx=TxAckInputWrapper(input=inp1)),
|
2020-08-22 15:28:29 +00:00
|
|
|
|
|
|
|
TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
|
2020-09-16 12:51:19 +00:00
|
|
|
TxAckPrevMeta(tx=ptx1),
|
2020-08-22 15:28:29 +00:00
|
|
|
|
|
|
|
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
|
2020-09-16 12:51:19 +00:00
|
|
|
TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp1)),
|
2020-08-22 15:28:29 +00:00
|
|
|
|
|
|
|
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
|
2020-09-16 12:51:19 +00:00
|
|
|
TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout1)),
|
2020-08-22 15:28:29 +00:00
|
|
|
|
|
|
|
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
|
2020-09-16 12:51:19 +00:00
|
|
|
TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout2)),
|
2020-08-22 15:28:29 +00:00
|
|
|
|
2017-11-10 13:10:19 +00:00
|
|
|
# sign tx
|
2020-04-16 12:31:15 +00:00
|
|
|
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(
|
|
|
|
# returned serialized header
|
|
|
|
serialized_tx=unhexlify('01000000000101'),
|
|
|
|
)),
|
2020-09-16 12:51:19 +00:00
|
|
|
TxAckInput(tx=TxAckInputWrapper(input=inp1)),
|
2017-11-10 13:10:19 +00:00
|
|
|
|
|
|
|
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(
|
|
|
|
# returned serialized inp1
|
2020-04-16 12:31:15 +00:00
|
|
|
serialized_tx=unhexlify('8a44999c07bba32df1cacdc50987944e68e3205b4429438fdde35c76024614090000000000ffffffff02'),
|
2017-11-10 13:10:19 +00:00
|
|
|
)),
|
2017-11-20 16:41:23 +00:00
|
|
|
# the out has to be cloned not to send the same object which was modified
|
2020-09-23 11:08:26 +00:00
|
|
|
TxAckOutput(tx=TxAckOutputWrapper(output=TxOutput(**out1.__dict__))),
|
2017-11-10 13:10:19 +00:00
|
|
|
|
|
|
|
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=TxRequestSerializedType(
|
|
|
|
# returned serialized out1
|
2020-04-16 12:31:15 +00:00
|
|
|
serialized_tx=unhexlify('404b4c000000000017a9147a55d61848e77ca266e79a39bfc85c580a6426c987'),
|
2017-11-10 13:10:19 +00:00
|
|
|
signature_index=None,
|
|
|
|
signature=None,
|
|
|
|
)),
|
2020-09-23 11:08:26 +00:00
|
|
|
TxAckOutput(tx=TxAckOutputWrapper(output=TxOutput(**out2.__dict__))),
|
2017-11-10 13:10:19 +00:00
|
|
|
|
|
|
|
# segwit
|
|
|
|
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(
|
|
|
|
# returned serialized out2
|
|
|
|
serialized_tx=unhexlify('a8386f0000000000160014d16b8c0680c61fc6ed2e407455715055e41052f5'),
|
|
|
|
signature_index=None,
|
|
|
|
signature=None,
|
|
|
|
)),
|
2020-09-16 12:51:19 +00:00
|
|
|
TxAckInput(tx=TxAckInputWrapper(input=inp1)),
|
2017-11-10 13:10:19 +00:00
|
|
|
|
2020-04-22 19:26:04 +00:00
|
|
|
TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType(
|
2017-11-10 13:10:19 +00:00
|
|
|
serialized_tx=unhexlify('02483045022100a7ca8f097525f9044e64376dc0a0f5d4aeb8d15d66808ba97979a0475b06b66502200597c8ebcef63e047f9aeef1a8001d3560470cf896c12f6990eec4faec599b950121033add1f0e8e3c3136f7428dd4a4de1057380bd311f5b0856e2269170b4ffa65bf00000000'),
|
2017-11-20 16:41:23 +00:00
|
|
|
signature_index=0,
|
|
|
|
signature=unhexlify('3045022100a7ca8f097525f9044e64376dc0a0f5d4aeb8d15d66808ba97979a0475b06b66502200597c8ebcef63e047f9aeef1a8001d3560470cf896c12f6990eec4faec599b95'),
|
2017-11-10 13:10:19 +00:00
|
|
|
)),
|
|
|
|
]
|
|
|
|
|
2022-09-21 07:56:28 +00:00
|
|
|
ns = _get_schemas_for_coin(coin)
|
2020-07-23 14:20:54 +00:00
|
|
|
keychain = Keychain(seed, coin.curve_name, ns)
|
2021-01-30 00:49:18 +00:00
|
|
|
signer = bitcoin.Bitcoin(tx, keychain, coin, None).signer()
|
2020-09-16 12:51:19 +00:00
|
|
|
for request, expected_response in chunks(messages, 2):
|
|
|
|
response = signer.send(request)
|
|
|
|
if isinstance(response, tuple):
|
|
|
|
_, response = response
|
|
|
|
self.assertEqual(response, expected_response)
|
2017-11-10 13:10:19 +00:00
|
|
|
with self.assertRaises(StopIteration):
|
|
|
|
signer.send(None)
|
|
|
|
|
2020-02-25 11:10:40 +00:00
|
|
|
def test_send_native_invalid_address(self):
|
|
|
|
|
|
|
|
coin = coins.by_name('Testnet')
|
|
|
|
seed = bip39.seed(' '.join(['all'] * 12), '')
|
|
|
|
|
2020-09-23 11:08:26 +00:00
|
|
|
inp1 = TxInput(
|
2020-02-25 11:10:40 +00:00
|
|
|
# 49'/1'/0'/0/0" - tb1qqzv60m9ajw8drqulta4ld4gfx0rdh82un5s65s
|
|
|
|
address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0],
|
|
|
|
amount=12300000,
|
|
|
|
prev_hash=unhexlify('09144602765ce3dd8f4329445b20e3684e948709c5cdcaf12da3bb079c99448a'),
|
|
|
|
prev_index=0,
|
|
|
|
script_type=InputScriptType.SPENDWITNESS,
|
|
|
|
sequence=0xffffffff,
|
|
|
|
multisig=None,
|
|
|
|
)
|
2020-09-23 11:08:26 +00:00
|
|
|
ptx1 = PrevTx(version=1, lock_time=0, inputs_count=1, outputs_count=2, extra_data_len=0)
|
|
|
|
pinp1 = PrevInput(script_sig=unhexlify('160014d16b8c0680c61fc6ed2e407455715055e41052f5'),
|
2020-05-15 14:55:18 +00:00
|
|
|
prev_hash=unhexlify('20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337'),
|
|
|
|
prev_index=0,
|
|
|
|
sequence=4294967295)
|
2020-09-23 11:08:26 +00:00
|
|
|
pout1 = PrevOutput(script_pubkey=unhexlify('00140099a7ecbd938ed1839f5f6bf6d50933c6db9d5c'),
|
2020-05-15 14:55:18 +00:00
|
|
|
amount=12300000)
|
2020-09-23 11:08:26 +00:00
|
|
|
pout2 = PrevOutput(script_pubkey=unhexlify('a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'),
|
2020-05-15 14:55:18 +00:00
|
|
|
amount=111145789)
|
|
|
|
|
2020-09-23 11:08:26 +00:00
|
|
|
out1 = TxOutput(
|
2020-02-25 11:10:40 +00:00
|
|
|
address='TB1Q694CCP5QCC0UDMFWGP692U2S2HJPQ5H407URTU', # Error: should be lower case
|
|
|
|
script_type=OutputScriptType.PAYTOADDRESS,
|
|
|
|
amount=12300000 - 11000 - 5000000,
|
|
|
|
address_n=[],
|
|
|
|
multisig=None,
|
|
|
|
)
|
2020-09-16 12:51:19 +00:00
|
|
|
tx = SignTx(coin_name='Testnet', version=1, lock_time=0, inputs_count=1, outputs_count=1)
|
2020-02-25 11:10:40 +00:00
|
|
|
|
|
|
|
messages = [
|
|
|
|
None,
|
|
|
|
|
|
|
|
# check fee
|
2020-04-16 12:31:15 +00:00
|
|
|
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
|
2020-09-16 12:51:19 +00:00
|
|
|
TxAckInput(tx=TxAckInputWrapper(input=inp1)),
|
2020-02-25 11:10:40 +00:00
|
|
|
|
2020-07-17 15:39:43 +00:00
|
|
|
helpers.UiConfirmForeignAddress(address_n=inp1.address_n),
|
|
|
|
True,
|
|
|
|
|
2020-04-16 12:31:15 +00:00
|
|
|
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
|
2020-09-16 12:51:19 +00:00
|
|
|
TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
|
2020-02-25 11:10:40 +00:00
|
|
|
None
|
|
|
|
]
|
|
|
|
|
2022-09-21 07:56:28 +00:00
|
|
|
ns = _get_schemas_for_coin(coin)
|
2020-07-23 14:20:54 +00:00
|
|
|
keychain = Keychain(seed, coin.curve_name, ns)
|
2021-01-30 00:49:18 +00:00
|
|
|
signer = bitcoin.Bitcoin(tx, keychain, coin, None).signer()
|
2020-09-16 12:51:19 +00:00
|
|
|
for request, expected_response in chunks(messages, 2):
|
|
|
|
if expected_response is None:
|
2020-05-15 18:35:09 +00:00
|
|
|
with self.assertRaises(wire.DataError):
|
2020-02-25 11:10:40 +00:00
|
|
|
signer.send(request)
|
|
|
|
else:
|
2020-09-16 12:51:19 +00:00
|
|
|
response = signer.send(request)
|
|
|
|
if isinstance(response, tuple):
|
|
|
|
_, response = response
|
|
|
|
self.assertEqual(response, expected_response)
|
2020-02-25 11:10:40 +00:00
|
|
|
|
2017-11-10 13:10:19 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|