1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-24 15:28:10 +00:00

chore(core): update unit tests to kwargs usage and new TxAck subtypes

This commit is contained in:
matejcik 2020-09-16 14:51:19 +02:00 committed by matejcik
parent d89c42e139
commit 8b2e46eb2d
16 changed files with 597 additions and 449 deletions

View File

@ -2,8 +2,8 @@ from common import unittest, await_result, H_
from trezor import wire from trezor import wire
from trezor.messages.AuthorizeCoinJoin import AuthorizeCoinJoin from trezor.messages.AuthorizeCoinJoin import AuthorizeCoinJoin
from trezor.messages.TxInputType import TxInputType from trezor.messages.TxAckInputType import TxAckInputType
from trezor.messages.TxOutputType import TxOutputType from trezor.messages.TxAckOutputType import TxAckOutputType
from trezor.messages.SignTx import SignTx from trezor.messages.SignTx import SignTx
from trezor.messages import InputScriptType, OutputScriptType from trezor.messages import InputScriptType, OutputScriptType
@ -32,7 +32,9 @@ class TestApprover(unittest.TestCase):
# Other's inputs. # Other's inputs.
inputs = [ inputs = [
TxInputType( TxAckInputType(
prev_hash=b"",
prev_index=0,
amount=denomination + 1000000 * (i + 1), amount=denomination + 1000000 * (i + 1),
script_type=InputScriptType.EXTERNAL, script_type=InputScriptType.EXTERNAL,
sequence=0xffffffff, sequence=0xffffffff,
@ -42,7 +44,9 @@ class TestApprover(unittest.TestCase):
# Our input. # Our input.
inputs.insert( inputs.insert(
30, 30,
TxInputType( TxAckInputType(
prev_hash=b"",
prev_index=0,
address_n=[H_(84), H_(0), H_(0), 0, 1], address_n=[H_(84), H_(0), H_(0), 0, 1],
amount=denomination + 1000000, amount=denomination + 1000000,
script_type=InputScriptType.SPENDWITNESS, script_type=InputScriptType.SPENDWITNESS,
@ -52,7 +56,7 @@ class TestApprover(unittest.TestCase):
# Other's CoinJoined outputs. # Other's CoinJoined outputs.
outputs = [ outputs = [
TxOutputType( TxAckOutputType(
amount=denomination, amount=denomination,
script_type=OutputScriptType.PAYTOWITNESS, script_type=OutputScriptType.PAYTOWITNESS,
) for i in range(99) ) for i in range(99)
@ -61,7 +65,7 @@ class TestApprover(unittest.TestCase):
# Our CoinJoined output. # Our CoinJoined output.
outputs.insert( outputs.insert(
40, 40,
TxOutputType( TxAckOutputType(
address_n=[H_(84), H_(0), H_(0), 0, 2], address_n=[H_(84), H_(0), H_(0), 0, 2],
amount=denomination, amount=denomination,
script_type=OutputScriptType.PAYTOWITNESS, script_type=OutputScriptType.PAYTOWITNESS,
@ -74,7 +78,7 @@ class TestApprover(unittest.TestCase):
# Other's change-outputs. # Other's change-outputs.
outputs.extend( outputs.extend(
TxOutputType( TxAckOutputType(
amount=1000000 * (i + 1) - fees, amount=1000000 * (i + 1) - fees,
script_type=OutputScriptType.PAYTOWITNESS, script_type=OutputScriptType.PAYTOWITNESS,
) for i in range(99) ) for i in range(99)
@ -82,7 +86,7 @@ class TestApprover(unittest.TestCase):
# Our change-output. # Our change-output.
outputs.append( outputs.append(
TxOutputType( TxAckOutputType(
address_n=[H_(84), H_(0), H_(0), 1, 1], address_n=[H_(84), H_(0), H_(0), 1, 1],
amount=1000000 - fees, amount=1000000 - fees,
script_type=OutputScriptType.PAYTOWITNESS, script_type=OutputScriptType.PAYTOWITNESS,
@ -91,7 +95,7 @@ class TestApprover(unittest.TestCase):
# Coordinator's output. # Coordinator's output.
outputs.append( outputs.append(
TxOutputType( TxAckOutputType(
amount=total_coordinator_fee, amount=total_coordinator_fee,
script_type=OutputScriptType.PAYTOWITNESS, script_type=OutputScriptType.PAYTOWITNESS,
) )
@ -120,7 +124,9 @@ class TestApprover(unittest.TestCase):
tx = SignTx(outputs_count=201, inputs_count=100, coin_name=self.coin.coin_name, lock_time=0) tx = SignTx(outputs_count=201, inputs_count=100, coin_name=self.coin.coin_name, lock_time=0)
approver = CoinJoinApprover(tx, self.coin, authorization) approver = CoinJoinApprover(tx, self.coin, authorization)
txi = TxInputType( txi = TxAckInputType(
prev_hash=b"",
prev_index=0,
address_n=[H_(49), H_(0), H_(0), 0], address_n=[H_(49), H_(0), H_(0), 0],
amount=10000000, amount=10000000,
script_type=InputScriptType.SPENDWITNESS script_type=InputScriptType.SPENDWITNESS
@ -134,7 +140,9 @@ class TestApprover(unittest.TestCase):
tx = SignTx(outputs_count=201, inputs_count=100, coin_name=self.coin.coin_name, lock_time=0) tx = SignTx(outputs_count=201, inputs_count=100, coin_name=self.coin.coin_name, lock_time=0)
approver = CoinJoinApprover(tx, self.coin, authorization) approver = CoinJoinApprover(tx, self.coin, authorization)
txi = TxInputType( txi = TxAckInputType(
prev_hash=b"",
prev_index=0,
address_n=[H_(49), H_(0), H_(0), 0, 2], address_n=[H_(49), H_(0), H_(0), 0, 2],
amount=10000000, amount=10000000,
script_type=InputScriptType.SPENDWITNESS script_type=InputScriptType.SPENDWITNESS

View File

@ -7,9 +7,9 @@ from apps.bitcoin.writers import get_tx_hash
from apps.common import coins from apps.common import coins
from apps.common.keychain import Keychain from apps.common.keychain import Keychain
from trezor.messages.SignTx import SignTx from trezor.messages.SignTx import SignTx
from trezor.messages.TxInputType import TxInputType from trezor.messages.TxAckInputType import TxAckInputType
from trezor.messages.TxOutputType import TxOutputType from trezor.messages.TxAckOutputType import TxAckOutputType
from trezor.messages.TxOutputBinType import TxOutputBinType from trezor.messages.TxAckPrevOutputType import TxAckPrevOutputType
from trezor.messages import InputScriptType from trezor.messages import InputScriptType
from trezor.messages import OutputScriptType from trezor.messages import OutputScriptType
from trezor.crypto import bip39 from trezor.crypto import bip39
@ -19,7 +19,7 @@ class TestSegwitBip143NativeP2WPKH(unittest.TestCase):
# pylint: disable=C0301 # pylint: disable=C0301
tx = SignTx(coin_name='Bitcoin', version=1, lock_time=0x00000011, inputs_count=2, outputs_count=2) tx = SignTx(coin_name='Bitcoin', version=1, lock_time=0x00000011, inputs_count=2, outputs_count=2)
inp1 = TxInputType(address_n=[0], inp1 = TxAckInputType(address_n=[0],
# Trezor expects hash in reversed format # Trezor expects hash in reversed format
prev_hash=unhexlify('9f96ade4b41d5433f4eda31e1738ec2b36f6e7d1420d94a6af99801a88f7f7ff'), prev_hash=unhexlify('9f96ade4b41d5433f4eda31e1738ec2b36f6e7d1420d94a6af99801a88f7f7ff'),
prev_index=0, prev_index=0,
@ -27,7 +27,7 @@ class TestSegwitBip143NativeP2WPKH(unittest.TestCase):
script_type=InputScriptType.SPENDWITNESS, script_type=InputScriptType.SPENDWITNESS,
multisig=None, multisig=None,
sequence=0xffffffee) sequence=0xffffffee)
inp2 = TxInputType(address_n=[1], inp2 = TxAckInputType(address_n=[1],
# Trezor expects hash in reversed format # Trezor expects hash in reversed format
prev_hash=unhexlify('8ac60eb9575db5b2d987e29f301b5b819ea83a5c6579d282d189cc04b8e151ef'), prev_hash=unhexlify('8ac60eb9575db5b2d987e29f301b5b819ea83a5c6579d282d189cc04b8e151ef'),
prev_index=1, prev_index=1,
@ -35,12 +35,12 @@ class TestSegwitBip143NativeP2WPKH(unittest.TestCase):
amount=600000000, # 6 btc amount=600000000, # 6 btc
script_type=InputScriptType.SPENDWITNESS, script_type=InputScriptType.SPENDWITNESS,
sequence=0xffffffff) sequence=0xffffffff)
out1 = TxOutputType(address='1Cu32FVupVCgHkMMRJdYJugxwo2Aprgk7H', # derived out1 = TxAckOutputType(address='1Cu32FVupVCgHkMMRJdYJugxwo2Aprgk7H', # derived
amount=0x0000000006b22c20, amount=0x0000000006b22c20,
script_type=OutputScriptType.PAYTOADDRESS, script_type=OutputScriptType.PAYTOADDRESS,
multisig=None, multisig=None,
address_n=[]) address_n=[])
out2 = TxOutputType(address='16TZ8J6Q5iZKBWizWzFAYnrsaox5Z5aBRV', # derived out2 = TxAckOutputType(address='16TZ8J6Q5iZKBWizWzFAYnrsaox5Z5aBRV', # derived
amount=0x000000000d519390, amount=0x000000000d519390,
script_type=OutputScriptType.PAYTOADDRESS, script_type=OutputScriptType.PAYTOADDRESS,
multisig=None, multisig=None,
@ -69,9 +69,8 @@ class TestSegwitBip143NativeP2WPKH(unittest.TestCase):
bip143 = Bitcoin(self.tx, None, coin, BasicApprover(self.tx, coin)) bip143 = Bitcoin(self.tx, None, coin, BasicApprover(self.tx, coin))
for txo in [self.out1, self.out2]: for txo in [self.out1, self.out2]:
txo_bin = TxOutputBinType()
txo_bin.amount = txo.amount
script_pubkey = output_derive_script(txo.address, coin) script_pubkey = output_derive_script(txo.address, coin)
txo_bin = TxAckPrevOutputType(amount=txo.amount, script_pubkey=script_pubkey)
bip143.hash143_add_output(txo_bin, script_pubkey) bip143.hash143_add_output(txo_bin, script_pubkey)
outputs_hash = get_tx_hash(bip143.h_outputs, double=coin.sign_hash_double) outputs_hash = get_tx_hash(bip143.h_outputs, double=coin.sign_hash_double)
@ -86,9 +85,8 @@ class TestSegwitBip143NativeP2WPKH(unittest.TestCase):
bip143.hash143_add_input(self.inp2) bip143.hash143_add_input(self.inp2)
for txo in [self.out1, self.out2]: for txo in [self.out1, self.out2]:
txo_bin = TxOutputBinType()
txo_bin.amount = txo.amount
script_pubkey = output_derive_script(txo.address, coin) script_pubkey = output_derive_script(txo.address, coin)
txo_bin = TxAckPrevOutputType(amount=txo.amount, script_pubkey=script_pubkey)
bip143.hash143_add_output(txo_bin, script_pubkey) bip143.hash143_add_output(txo_bin, script_pubkey)
keychain = Keychain(seed, coin.curve_name, [[]]) keychain = Keychain(seed, coin.curve_name, [[]])

View File

@ -7,9 +7,9 @@ from apps.bitcoin.writers import get_tx_hash
from apps.common import coins from apps.common import coins
from apps.common.keychain import Keychain from apps.common.keychain import Keychain
from trezor.messages.SignTx import SignTx from trezor.messages.SignTx import SignTx
from trezor.messages.TxInputType import TxInputType from trezor.messages.TxAckInputType import TxAckInputType
from trezor.messages.TxOutputType import TxOutputType from trezor.messages.TxAckOutputType import TxAckOutputType
from trezor.messages.TxOutputBinType import TxOutputBinType from trezor.messages.TxAckPrevOutputType import TxAckPrevOutputType
from trezor.messages import InputScriptType from trezor.messages import InputScriptType
from trezor.messages import OutputScriptType from trezor.messages import OutputScriptType
from trezor.crypto import bip39 from trezor.crypto import bip39
@ -19,7 +19,7 @@ class TestSegwitBip143(unittest.TestCase):
# pylint: disable=C0301 # pylint: disable=C0301
tx = SignTx(coin_name='Bitcoin', version=1, lock_time=0x00000492, inputs_count=1, outputs_count=2) tx = SignTx(coin_name='Bitcoin', version=1, lock_time=0x00000492, inputs_count=1, outputs_count=2)
inp1 = TxInputType(address_n=[0], inp1 = TxAckInputType(address_n=[0],
# Trezor expects hash in reversed format # Trezor expects hash in reversed format
prev_hash=unhexlify('77541aeb3c4dac9260b68f74f44c973081a9d4cb2ebe8038b2d70faa201b6bdb'), prev_hash=unhexlify('77541aeb3c4dac9260b68f74f44c973081a9d4cb2ebe8038b2d70faa201b6bdb'),
prev_index=1, prev_index=1,
@ -27,12 +27,12 @@ class TestSegwitBip143(unittest.TestCase):
amount=1000000000, # 10 btc amount=1000000000, # 10 btc
script_type=InputScriptType.SPENDP2SHWITNESS, # TODO: is this correct? script_type=InputScriptType.SPENDP2SHWITNESS, # TODO: is this correct?
sequence=0xfffffffe) sequence=0xfffffffe)
out1 = TxOutputType(address='1Fyxts6r24DpEieygQiNnWxUdb18ANa5p7', out1 = TxAckOutputType(address='1Fyxts6r24DpEieygQiNnWxUdb18ANa5p7',
amount=0x000000000bebb4b8, amount=0x000000000bebb4b8,
script_type=OutputScriptType.PAYTOADDRESS, script_type=OutputScriptType.PAYTOADDRESS,
multisig=None, multisig=None,
address_n=[]) address_n=[])
out2 = TxOutputType(address='1Q5YjKVj5yQWHBBsyEBamkfph3cA6G9KK8', out2 = TxAckOutputType(address='1Q5YjKVj5yQWHBBsyEBamkfph3cA6G9KK8',
amount=0x000000002faf0800, amount=0x000000002faf0800,
script_type=OutputScriptType.PAYTOADDRESS, script_type=OutputScriptType.PAYTOADDRESS,
multisig=None, multisig=None,
@ -58,9 +58,8 @@ class TestSegwitBip143(unittest.TestCase):
bip143 = Bitcoin(self.tx, None, coin, BasicApprover(self.tx, coin)) bip143 = Bitcoin(self.tx, None, coin, BasicApprover(self.tx, coin))
for txo in [self.out1, self.out2]: for txo in [self.out1, self.out2]:
txo_bin = TxOutputBinType()
txo_bin.amount = txo.amount
script_pubkey = output_derive_script(txo.address, coin) script_pubkey = output_derive_script(txo.address, coin)
txo_bin = TxAckPrevOutputType(amount=txo.amount, script_pubkey=script_pubkey)
bip143.hash143_add_output(txo_bin, script_pubkey) bip143.hash143_add_output(txo_bin, script_pubkey)
outputs_hash = get_tx_hash(bip143.h_outputs, double=coin.sign_hash_double) outputs_hash = get_tx_hash(bip143.h_outputs, double=coin.sign_hash_double)
@ -72,9 +71,8 @@ class TestSegwitBip143(unittest.TestCase):
bip143 = Bitcoin(self.tx, None, coin, BasicApprover(self.tx, coin)) bip143 = Bitcoin(self.tx, None, coin, BasicApprover(self.tx, coin))
bip143.hash143_add_input(self.inp1) bip143.hash143_add_input(self.inp1)
for txo in [self.out1, self.out2]: for txo in [self.out1, self.out2]:
txo_bin = TxOutputBinType()
txo_bin.amount = txo.amount
script_pubkey = output_derive_script(txo.address, coin) script_pubkey = output_derive_script(txo.address, coin)
txo_bin = TxAckPrevOutputType(amount=txo.amount, script_pubkey=script_pubkey)
bip143.hash143_add_output(txo_bin, script_pubkey) bip143.hash143_add_output(txo_bin, script_pubkey)
keychain = Keychain(seed, coin.curve_name, [[]]) keychain = Keychain(seed, coin.curve_name, [[]])

View File

@ -3,12 +3,21 @@ from common import *
from trezor.utils import chunks from trezor.utils import chunks
from trezor.crypto import bip39 from trezor.crypto import bip39
from trezor.messages.SignTx import SignTx from trezor.messages.SignTx import SignTx
from trezor.messages.TxInputType import TxInputType from trezor.messages.TxAckInput import TxAckInput
from trezor.messages.TxOutputBinType import TxOutputBinType from trezor.messages.TxAckInputWrapper import TxAckInputWrapper
from trezor.messages.TxOutputType import TxOutputType from trezor.messages.TxAckInputType import TxAckInputType
from trezor.messages.TxAckOutput import TxAckOutput
from trezor.messages.TxAckOutputWrapper import TxAckOutputWrapper
from trezor.messages.TxAckOutputType import TxAckOutputType
from trezor.messages.TxAckPrevMeta import TxAckPrevMeta
from trezor.messages.TxAckPrevTxType import TxAckPrevTxType
from trezor.messages.TxAckPrevInput import TxAckPrevInput
from trezor.messages.TxAckPrevInputWrapper import TxAckPrevInputWrapper
from trezor.messages.TxAckPrevInputType import TxAckPrevInputType
from trezor.messages.TxAckPrevOutput import TxAckPrevOutput
from trezor.messages.TxAckPrevOutputWrapper import TxAckPrevOutputWrapper
from trezor.messages.TxAckPrevOutputType import TxAckPrevOutputType
from trezor.messages.TxRequest import TxRequest from trezor.messages.TxRequest import TxRequest
from trezor.messages.TxAck import TxAck
from trezor.messages.TransactionType import TransactionType
from trezor.messages.RequestType import TXINPUT, TXMETA, TXOUTPUT, TXFINISHED from trezor.messages.RequestType import TXINPUT, TXMETA, TXOUTPUT, TXFINISHED
from trezor.messages.TxRequestDetailsType import TxRequestDetailsType from trezor.messages.TxRequestDetailsType import TxRequestDetailsType
from trezor.messages.TxRequestSerializedType import TxRequestSerializedType from trezor.messages.TxRequestSerializedType import TxRequestSerializedType
@ -34,7 +43,7 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase):
coin = coins.by_name('Testnet') coin = coins.by_name('Testnet')
seed = bip39.seed(' '.join(['all'] * 12), '') seed = bip39.seed(' '.join(['all'] * 12), '')
inp1 = TxInputType( inp1 = TxAckInputType(
# 49'/1'/0'/0/0" - tb1qqzv60m9ajw8drqulta4ld4gfx0rdh82un5s65s # 49'/1'/0'/0/0" - tb1qqzv60m9ajw8drqulta4ld4gfx0rdh82un5s65s
address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0], address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0],
amount=12300000, amount=12300000,
@ -44,51 +53,50 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase):
sequence=0xffffffff, sequence=0xffffffff,
multisig=None, multisig=None,
) )
ptx1 = TransactionType(version=1, lock_time=0, inputs_cnt=1, outputs_cnt=2, extra_data_len=0) ptx1 = TxAckPrevTxType(version=1, lock_time=0, inputs_count=1, outputs_count=2, extra_data_len=0)
pinp1 = TxInputType(script_sig=unhexlify('160014d16b8c0680c61fc6ed2e407455715055e41052f5'), pinp1 = TxAckPrevInputType(script_sig=unhexlify('160014d16b8c0680c61fc6ed2e407455715055e41052f5'),
prev_hash=unhexlify('20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337'), prev_hash=unhexlify('20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337'),
prev_index=0, prev_index=0,
script_type=None,
sequence=4294967295) sequence=4294967295)
pout1 = TxOutputBinType(script_pubkey=unhexlify('00140099a7ecbd938ed1839f5f6bf6d50933c6db9d5c'), pout1 = TxAckPrevOutputType(script_pubkey=unhexlify('00140099a7ecbd938ed1839f5f6bf6d50933c6db9d5c'),
amount=12300000) amount=12300000)
pout2 = TxOutputBinType(script_pubkey=unhexlify('a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'), pout2 = TxAckPrevOutputType(script_pubkey=unhexlify('a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'),
amount=111145789) amount=111145789)
out1 = TxOutputType( out1 = TxAckOutputType(
address='2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp', address='2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp',
amount=5000000, amount=5000000,
script_type=OutputScriptType.PAYTOADDRESS, script_type=OutputScriptType.PAYTOADDRESS,
address_n=[], address_n=[],
multisig=None, multisig=None,
) )
out2 = TxOutputType( out2 = TxAckOutputType(
address='tb1q694ccp5qcc0udmfwgp692u2s2hjpq5h407urtu', address='tb1q694ccp5qcc0udmfwgp692u2s2hjpq5h407urtu',
script_type=OutputScriptType.PAYTOADDRESS, script_type=OutputScriptType.PAYTOADDRESS,
amount=12300000 - 11000 - 5000000, amount=12300000 - 11000 - 5000000,
address_n=[], address_n=[],
multisig=None, multisig=None,
) )
tx = SignTx(coin_name='Testnet', version=None, lock_time=None, inputs_count=1, outputs_count=2) tx = SignTx(coin_name='Testnet', version=1, lock_time=0, inputs_count=1, outputs_count=2)
messages = [ messages = [
None, None,
# check fee # check fee
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
helpers.UiConfirmForeignAddress(address_n=inp1.address_n), helpers.UiConfirmForeignAddress(address_n=inp1.address_n),
True, True,
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(outputs=[out1])), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
helpers.UiConfirmOutput(out1, coin), helpers.UiConfirmOutput(out1, coin),
True, True,
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(outputs=[out2])), TxAckOutput(tx=TxAckOutputWrapper(output=out2)),
helpers.UiConfirmOutput(out2, coin), helpers.UiConfirmOutput(out2, coin),
True, True,
@ -98,32 +106,32 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase):
# check prev tx # check prev tx
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=ptx1), TxAckPrevMeta(tx=ptx1),
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[pinp1])), TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(bin_outputs=[pout1])), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(bin_outputs=[pout2])), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout2)),
# sign tx # sign tx
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(
# returned serialized header # returned serialized header
serialized_tx=unhexlify('01000000000101'), serialized_tx=unhexlify('01000000000101'),
)), )),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(
# returned serialized inp1 # returned serialized inp1
serialized_tx=unhexlify('8a44999c07bba32df1cacdc50987944e68e3205b4429438fdde35c76024614090000000000ffffffff02'), serialized_tx=unhexlify('8a44999c07bba32df1cacdc50987944e68e3205b4429438fdde35c76024614090000000000ffffffff02'),
)), )),
TxAck(tx=TransactionType(outputs=[out1])), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=TxRequestSerializedType( TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=TxRequestSerializedType(
# returned serialized out1 # returned serialized out1
@ -131,7 +139,7 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase):
signature_index=None, signature_index=None,
signature=None, signature=None,
)), )),
TxAck(tx=TransactionType(outputs=[out2])), TxAckOutput(tx=TxAckOutputWrapper(output=out2)),
# segwit # segwit
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(
@ -140,7 +148,7 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase):
signature_index=None, signature_index=None,
signature=None, signature=None,
)), )),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType( TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType(
serialized_tx=unhexlify('02483045022100a7ca8f097525f9044e64376dc0a0f5d4aeb8d15d66808ba97979a0475b06b66502200597c8ebcef63e047f9aeef1a8001d3560470cf896c12f6990eec4faec599b950121033add1f0e8e3c3136f7428dd4a4de1057380bd311f5b0856e2269170b4ffa65bf00000000'), serialized_tx=unhexlify('02483045022100a7ca8f097525f9044e64376dc0a0f5d4aeb8d15d66808ba97979a0475b06b66502200597c8ebcef63e047f9aeef1a8001d3560470cf896c12f6990eec4faec599b950121033add1f0e8e3c3136f7428dd4a4de1057380bd311f5b0856e2269170b4ffa65bf00000000'),
@ -155,6 +163,8 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase):
signer = bitcoin.Bitcoin(tx, keychain, coin, approver).signer() signer = bitcoin.Bitcoin(tx, keychain, coin, approver).signer()
for request, response in chunks(messages, 2): for request, response in chunks(messages, 2):
res = signer.send(request) res = signer.send(request)
if isinstance(res, tuple):
_, res = res
self.assertEqual(res, response) self.assertEqual(res, response)
with self.assertRaises(StopIteration): with self.assertRaises(StopIteration):
signer.send(None) signer.send(None)
@ -164,7 +174,7 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase):
coin = coins.by_name('Testnet') coin = coins.by_name('Testnet')
seed = bip39.seed(' '.join(['all'] * 12), '') seed = bip39.seed(' '.join(['all'] * 12), '')
inp1 = TxInputType( inp1 = TxAckInputType(
# 49'/1'/0'/0/0" - tb1qqzv60m9ajw8drqulta4ld4gfx0rdh82un5s65s # 49'/1'/0'/0/0" - tb1qqzv60m9ajw8drqulta4ld4gfx0rdh82un5s65s
address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0], address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0],
amount=12300000, amount=12300000,
@ -174,84 +184,83 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase):
sequence=0xffffffff, sequence=0xffffffff,
multisig=None, multisig=None,
) )
ptx1 = TransactionType(version=1, lock_time=0, inputs_cnt=1, outputs_cnt=2, extra_data_len=0) ptx1 = TxAckPrevTxType(version=1, lock_time=0, inputs_count=1, outputs_count=2, extra_data_len=0)
pinp1 = TxInputType(script_sig=unhexlify('160014d16b8c0680c61fc6ed2e407455715055e41052f5'), pinp1 = TxAckPrevInputType(script_sig=unhexlify('160014d16b8c0680c61fc6ed2e407455715055e41052f5'),
prev_hash=unhexlify('20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337'), prev_hash=unhexlify('20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337'),
prev_index=0, prev_index=0,
script_type=None,
sequence=4294967295) sequence=4294967295)
pout1 = TxOutputBinType(script_pubkey=unhexlify('00140099a7ecbd938ed1839f5f6bf6d50933c6db9d5c'), pout1 = TxAckPrevOutputType(script_pubkey=unhexlify('00140099a7ecbd938ed1839f5f6bf6d50933c6db9d5c'),
amount=12300000) amount=12300000)
pout2 = TxOutputBinType(script_pubkey=unhexlify('a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'), pout2 = TxAckPrevOutputType(script_pubkey=unhexlify('a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'),
amount=111145789) amount=111145789)
out1 = TxOutputType( out1 = TxAckOutputType(
address='2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp', address='2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp',
amount=5000000, amount=5000000,
script_type=OutputScriptType.PAYTOADDRESS, script_type=OutputScriptType.PAYTOADDRESS,
address_n=[], address_n=[],
multisig=None, multisig=None,
) )
out2 = TxOutputType( out2 = TxAckOutputType(
address=None, address=None,
address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0], address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0],
script_type=OutputScriptType.PAYTOWITNESS, script_type=OutputScriptType.PAYTOWITNESS,
amount=12300000 - 11000 - 5000000, amount=12300000 - 11000 - 5000000,
multisig=None, multisig=None,
) )
tx = SignTx(coin_name='Testnet', version=None, lock_time=None, inputs_count=1, outputs_count=2) tx = SignTx(coin_name='Testnet', version=1, lock_time=0, inputs_count=1, outputs_count=2)
messages = [ messages = [
None, None,
# check fee # check fee
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
helpers.UiConfirmForeignAddress(address_n=inp1.address_n), helpers.UiConfirmForeignAddress(address_n=inp1.address_n),
True, True,
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(outputs=[out1])), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
helpers.UiConfirmOutput(out1, coin), helpers.UiConfirmOutput(out1, coin),
True, True,
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(outputs=[out2])), TxAckOutput(tx=TxAckOutputWrapper(output=out2)),
helpers.UiConfirmTotal(5000000 + 11000, 11000, coin), helpers.UiConfirmTotal(5000000 + 11000, 11000, coin),
True, True,
# check prev tx # check prev tx
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=ptx1), TxAckPrevMeta(tx=ptx1),
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[pinp1])), TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(bin_outputs=[pout1])), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(bin_outputs=[pout2])), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout2)),
# sign tx # sign tx
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(
# returned serialized header # returned serialized header
serialized_tx=unhexlify('01000000000101'), serialized_tx=unhexlify('01000000000101'),
)), )),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(
# returned serialized inp1 # returned serialized inp1
serialized_tx=unhexlify('8a44999c07bba32df1cacdc50987944e68e3205b4429438fdde35c76024614090000000000ffffffff02'), serialized_tx=unhexlify('8a44999c07bba32df1cacdc50987944e68e3205b4429438fdde35c76024614090000000000ffffffff02'),
)), )),
# the out has to be cloned not to send the same object which was modified # the out has to be cloned not to send the same object which was modified
TxAck(tx=TransactionType(outputs=[TxOutputType(**out1.__dict__)])), TxAckOutput(tx=TxAckOutputWrapper(output=TxAckOutputType(**out1.__dict__))),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=TxRequestSerializedType( TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=TxRequestSerializedType(
# returned serialized out1 # returned serialized out1
@ -259,7 +268,7 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase):
signature_index=None, signature_index=None,
signature=None, signature=None,
)), )),
TxAck(tx=TransactionType(outputs=[TxOutputType(**out2.__dict__)])), TxAckOutput(tx=TxAckOutputWrapper(output=TxAckOutputType(**out2.__dict__))),
# segwit # segwit
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(
@ -268,7 +277,7 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase):
signature_index=None, signature_index=None,
signature=None, signature=None,
)), )),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType( TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType(
serialized_tx=unhexlify('02483045022100a7ca8f097525f9044e64376dc0a0f5d4aeb8d15d66808ba97979a0475b06b66502200597c8ebcef63e047f9aeef1a8001d3560470cf896c12f6990eec4faec599b950121033add1f0e8e3c3136f7428dd4a4de1057380bd311f5b0856e2269170b4ffa65bf00000000'), serialized_tx=unhexlify('02483045022100a7ca8f097525f9044e64376dc0a0f5d4aeb8d15d66808ba97979a0475b06b66502200597c8ebcef63e047f9aeef1a8001d3560470cf896c12f6990eec4faec599b950121033add1f0e8e3c3136f7428dd4a4de1057380bd311f5b0856e2269170b4ffa65bf00000000'),
@ -281,8 +290,11 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase):
keychain = Keychain(seed, coin.curve_name, ns) keychain = Keychain(seed, coin.curve_name, ns)
approver = BasicApprover(tx, coin) approver = BasicApprover(tx, coin)
signer = bitcoin.Bitcoin(tx, keychain, coin, approver).signer() signer = bitcoin.Bitcoin(tx, keychain, coin, approver).signer()
for request, response in chunks(messages, 2): for request, expected_response in chunks(messages, 2):
self.assertEqual(signer.send(request), response) response = signer.send(request)
if isinstance(response, tuple):
_, response = response
self.assertEqual(response, expected_response)
with self.assertRaises(StopIteration): with self.assertRaises(StopIteration):
signer.send(None) signer.send(None)
@ -291,7 +303,7 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase):
coin = coins.by_name('Testnet') coin = coins.by_name('Testnet')
seed = bip39.seed(' '.join(['all'] * 12), '') seed = bip39.seed(' '.join(['all'] * 12), '')
inp1 = TxInputType( inp1 = TxAckInputType(
# 49'/1'/0'/0/0" - tb1qqzv60m9ajw8drqulta4ld4gfx0rdh82un5s65s # 49'/1'/0'/0/0" - tb1qqzv60m9ajw8drqulta4ld4gfx0rdh82un5s65s
address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0], address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0],
amount=12300000, amount=12300000,
@ -301,38 +313,37 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase):
sequence=0xffffffff, sequence=0xffffffff,
multisig=None, multisig=None,
) )
ptx1 = TransactionType(version=1, lock_time=0, inputs_cnt=1, outputs_cnt=2, extra_data_len=0) ptx1 = TxAckPrevTxType(version=1, lock_time=0, inputs_count=1, outputs_count=2, extra_data_len=0)
pinp1 = TxInputType(script_sig=unhexlify('160014d16b8c0680c61fc6ed2e407455715055e41052f5'), pinp1 = TxAckPrevInputType(script_sig=unhexlify('160014d16b8c0680c61fc6ed2e407455715055e41052f5'),
prev_hash=unhexlify('20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337'), prev_hash=unhexlify('20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337'),
prev_index=0, prev_index=0,
script_type=None,
sequence=4294967295) sequence=4294967295)
pout1 = TxOutputBinType(script_pubkey=unhexlify('00140099a7ecbd938ed1839f5f6bf6d50933c6db9d5c'), pout1 = TxAckPrevOutputType(script_pubkey=unhexlify('00140099a7ecbd938ed1839f5f6bf6d50933c6db9d5c'),
amount=12300000) amount=12300000)
pout2 = TxOutputBinType(script_pubkey=unhexlify('a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'), pout2 = TxAckPrevOutputType(script_pubkey=unhexlify('a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'),
amount=111145789) amount=111145789)
out1 = TxOutputType( out1 = TxAckOutputType(
address='TB1Q694CCP5QCC0UDMFWGP692U2S2HJPQ5H407URTU', # Error: should be lower case address='TB1Q694CCP5QCC0UDMFWGP692U2S2HJPQ5H407URTU', # Error: should be lower case
script_type=OutputScriptType.PAYTOADDRESS, script_type=OutputScriptType.PAYTOADDRESS,
amount=12300000 - 11000 - 5000000, amount=12300000 - 11000 - 5000000,
address_n=[], address_n=[],
multisig=None, multisig=None,
) )
tx = SignTx(coin_name='Testnet', version=None, lock_time=None, inputs_count=1, outputs_count=1) tx = SignTx(coin_name='Testnet', version=1, lock_time=0, inputs_count=1, outputs_count=1)
messages = [ messages = [
None, None,
# check fee # check fee
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
helpers.UiConfirmForeignAddress(address_n=inp1.address_n), helpers.UiConfirmForeignAddress(address_n=inp1.address_n),
True, True,
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(outputs=[out1])), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
None None
] ]
@ -340,12 +351,15 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase):
keychain = Keychain(seed, coin.curve_name, ns) keychain = Keychain(seed, coin.curve_name, ns)
approver = BasicApprover(tx, coin) approver = BasicApprover(tx, coin)
signer = bitcoin.Bitcoin(tx, keychain, coin, approver).signer() signer = bitcoin.Bitcoin(tx, keychain, coin, approver).signer()
for request, response in chunks(messages, 2): for request, expected_response in chunks(messages, 2):
if response is None: if expected_response is None:
with self.assertRaises(wire.DataError): with self.assertRaises(wire.DataError):
signer.send(request) signer.send(request)
else: else:
self.assertEqual(signer.send(request), response) response = signer.send(request)
if isinstance(response, tuple):
_, response = response
self.assertEqual(response, expected_response)
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -3,12 +3,21 @@ from common import *
from trezor.utils import chunks from trezor.utils import chunks
from trezor.crypto import bip39 from trezor.crypto import bip39
from trezor.messages.SignTx import SignTx from trezor.messages.SignTx import SignTx
from trezor.messages.TxInputType import TxInputType from trezor.messages.TxAckInput import TxAckInput
from trezor.messages.TxOutputBinType import TxOutputBinType from trezor.messages.TxAckInputWrapper import TxAckInputWrapper
from trezor.messages.TxOutputType import TxOutputType from trezor.messages.TxAckInputType import TxAckInputType
from trezor.messages.TxAckOutput import TxAckOutput
from trezor.messages.TxAckOutputWrapper import TxAckOutputWrapper
from trezor.messages.TxAckOutputType import TxAckOutputType
from trezor.messages.TxAckPrevMeta import TxAckPrevMeta
from trezor.messages.TxAckPrevTxType import TxAckPrevTxType
from trezor.messages.TxAckPrevInput import TxAckPrevInput
from trezor.messages.TxAckPrevInputWrapper import TxAckPrevInputWrapper
from trezor.messages.TxAckPrevInputType import TxAckPrevInputType
from trezor.messages.TxAckPrevOutput import TxAckPrevOutput
from trezor.messages.TxAckPrevOutputWrapper import TxAckPrevOutputWrapper
from trezor.messages.TxAckPrevOutputType import TxAckPrevOutputType
from trezor.messages.TxRequest import TxRequest from trezor.messages.TxRequest import TxRequest
from trezor.messages.TxAck import TxAck
from trezor.messages.TransactionType import TransactionType
from trezor.messages.RequestType import TXINPUT, TXMETA, TXOUTPUT, TXFINISHED from trezor.messages.RequestType import TXINPUT, TXMETA, TXOUTPUT, TXFINISHED
from trezor.messages.TxRequestDetailsType import TxRequestDetailsType from trezor.messages.TxRequestDetailsType import TxRequestDetailsType
from trezor.messages.TxRequestSerializedType import TxRequestSerializedType from trezor.messages.TxRequestSerializedType import TxRequestSerializedType
@ -35,7 +44,7 @@ class TestSignSegwitTxNativeP2WPKH_GRS(unittest.TestCase):
coin = coins.by_name('Groestlcoin Testnet') coin = coins.by_name('Groestlcoin Testnet')
seed = bip39.seed(' '.join(['all'] * 12), '') seed = bip39.seed(' '.join(['all'] * 12), '')
inp1 = TxInputType( inp1 = TxAckInputType(
# 84'/1'/0'/0/0" - tgrs1qkvwu9g3k2pdxewfqr7syz89r3gj557l3ued7ja # 84'/1'/0'/0/0" - tgrs1qkvwu9g3k2pdxewfqr7syz89r3gj557l3ued7ja
address_n=[84 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0], address_n=[84 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0],
amount=12300000, amount=12300000,
@ -45,48 +54,47 @@ class TestSignSegwitTxNativeP2WPKH_GRS(unittest.TestCase):
sequence=0xfffffffe, sequence=0xfffffffe,
multisig=None, multisig=None,
) )
ptx1 = TransactionType(version=1, lock_time=650645, inputs_cnt=1, outputs_cnt=2, extra_data_len=0) ptx1 = TxAckPrevTxType(version=1, lock_time=650645, inputs_count=1, outputs_count=2, extra_data_len=0)
pinp1 = TxInputType(script_sig=unhexlify('483045022100d9615361c044e91f6dd7bb4455f3ad686cd5a663d7800bb74c448b2706500ccb022026bed24b81a501e8398411c5a9a793741d9bfe39617d51c363dde0a84f44f4f9012102659a6eefcc72d6f2eff92e57095388b17db0b06034946ecd44120e5e7a830ff4'), pinp1 = TxAckPrevInputType(script_sig=unhexlify('483045022100d9615361c044e91f6dd7bb4455f3ad686cd5a663d7800bb74c448b2706500ccb022026bed24b81a501e8398411c5a9a793741d9bfe39617d51c363dde0a84f44f4f9012102659a6eefcc72d6f2eff92e57095388b17db0b06034946ecd44120e5e7a830ff4'),
prev_hash=unhexlify('1c92508b38239e5c10b23fb46dcf765ee2f3a95b835edbf0943ec21b21711160'), prev_hash=unhexlify('1c92508b38239e5c10b23fb46dcf765ee2f3a95b835edbf0943ec21b21711160'),
prev_index=1, prev_index=1,
script_type=None,
sequence=4294967293) sequence=4294967293)
pout1 = TxOutputBinType(script_pubkey=unhexlify('0014b31dc2a236505a6cb9201fa0411ca38a254a7bf1'), pout1 = TxAckPrevOutputType(script_pubkey=unhexlify('0014b31dc2a236505a6cb9201fa0411ca38a254a7bf1'),
amount=12300000) amount=12300000)
pout2 = TxOutputBinType(script_pubkey=unhexlify('76a91438cc090e4a4b2e458c33fe35af1c5c0094699ac288ac'), pout2 = TxAckPrevOutputType(script_pubkey=unhexlify('76a91438cc090e4a4b2e458c33fe35af1c5c0094699ac288ac'),
amount=9887699777) amount=9887699777)
out1 = TxOutputType( out1 = TxAckOutputType(
address='2N4Q5FhU2497BryFfUgbqkAJE87aKDv3V3e', address='2N4Q5FhU2497BryFfUgbqkAJE87aKDv3V3e',
amount=5000000, amount=5000000,
script_type=OutputScriptType.PAYTOADDRESS, script_type=OutputScriptType.PAYTOADDRESS,
address_n=[], address_n=[],
multisig=None, multisig=None,
) )
out2 = TxOutputType( out2 = TxAckOutputType(
address='tgrs1qejqxwzfld7zr6mf7ygqy5s5se5xq7vmt9lkd57', address='tgrs1qejqxwzfld7zr6mf7ygqy5s5se5xq7vmt9lkd57',
script_type=OutputScriptType.PAYTOADDRESS, script_type=OutputScriptType.PAYTOADDRESS,
amount=12300000 - 11000 - 5000000, amount=12300000 - 11000 - 5000000,
address_n=[], address_n=[],
multisig=None, multisig=None,
) )
tx = SignTx(coin_name='Groestlcoin Testnet', version=None, lock_time=650713, inputs_count=1, outputs_count=2) tx = SignTx(coin_name='Groestlcoin Testnet', version=1, lock_time=650713, inputs_count=1, outputs_count=2)
messages = [ messages = [
None, None,
# check fee # check fee
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(outputs=[out1])), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
helpers.UiConfirmOutput(out1, coin), helpers.UiConfirmOutput(out1, coin),
True, True,
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(outputs=[out2])), TxAckOutput(tx=TxAckOutputWrapper(output=out2)),
helpers.UiConfirmOutput(out2, coin), helpers.UiConfirmOutput(out2, coin),
True, True,
@ -99,32 +107,32 @@ class TestSignSegwitTxNativeP2WPKH_GRS(unittest.TestCase):
# check prev tx # check prev tx
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=ptx1), TxAckPrevMeta(tx=ptx1),
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[pinp1])), TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(bin_outputs=[pout1])), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(bin_outputs=[pout2])), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout2)),
# sign tx # sign tx
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(
# returned serialized header # returned serialized header
serialized_tx=unhexlify('01000000000101'), serialized_tx=unhexlify('01000000000101'),
)), )),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(
# returned serialized inp1 # returned serialized inp1
serialized_tx=unhexlify('d1613f483f2086d076c82fe34674385a86beb08f052d5405fe1aed397f852f4f0000000000feffffff02'), serialized_tx=unhexlify('d1613f483f2086d076c82fe34674385a86beb08f052d5405fe1aed397f852f4f0000000000feffffff02'),
)), )),
TxAck(tx=TransactionType(outputs=[out1])), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=TxRequestSerializedType( TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=TxRequestSerializedType(
# returned serialized out1 # returned serialized out1
@ -132,7 +140,7 @@ class TestSignSegwitTxNativeP2WPKH_GRS(unittest.TestCase):
signature_index=None, signature_index=None,
signature=None, signature=None,
)), )),
TxAck(tx=TransactionType(outputs=[out2])), TxAckOutput(tx=TxAckOutputWrapper(output=out2)),
# segwit # segwit
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(
@ -141,7 +149,7 @@ class TestSignSegwitTxNativeP2WPKH_GRS(unittest.TestCase):
signature_index=None, signature_index=None,
signature=None, signature=None,
)), )),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType( TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType(
serialized_tx=unhexlify('02483045022100ea8780bc1e60e14e945a80654a41748bbf1aa7d6f2e40a88d91dfc2de1f34bd10220181a474a3420444bd188501d8d270736e1e9fe379da9970de992ff445b0972e3012103adc58245cf28406af0ef5cc24b8afba7f1be6c72f279b642d85c48798685f862d9ed0900'), serialized_tx=unhexlify('02483045022100ea8780bc1e60e14e945a80654a41748bbf1aa7d6f2e40a88d91dfc2de1f34bd10220181a474a3420444bd188501d8d270736e1e9fe379da9970de992ff445b0972e3012103adc58245cf28406af0ef5cc24b8afba7f1be6c72f279b642d85c48798685f862d9ed0900'),
@ -154,8 +162,11 @@ class TestSignSegwitTxNativeP2WPKH_GRS(unittest.TestCase):
keychain = Keychain(seed, coin.curve_name, ns) keychain = Keychain(seed, coin.curve_name, ns)
approver = BasicApprover(tx, coin) approver = BasicApprover(tx, coin)
signer = bitcoinlike.Bitcoinlike(tx, keychain, coin, approver).signer() signer = bitcoinlike.Bitcoinlike(tx, keychain, coin, approver).signer()
for request, response in chunks(messages, 2): for request, expected_response in chunks(messages, 2):
self.assertEqual(signer.send(request), response) response = signer.send(request)
if isinstance(response, tuple):
_, response = response
self.assertEqual(response, expected_response)
with self.assertRaises(StopIteration): with self.assertRaises(StopIteration):
signer.send(None) signer.send(None)
@ -164,7 +175,7 @@ class TestSignSegwitTxNativeP2WPKH_GRS(unittest.TestCase):
coin = coins.by_name('Groestlcoin Testnet') coin = coins.by_name('Groestlcoin Testnet')
seed = bip39.seed(' '.join(['all'] * 12), '') seed = bip39.seed(' '.join(['all'] * 12), '')
inp1 = TxInputType( inp1 = TxAckInputType(
# 84'/1'/0'/0/0" - tgrs1qkvwu9g3k2pdxewfqr7syz89r3gj557l3ued7ja # 84'/1'/0'/0/0" - tgrs1qkvwu9g3k2pdxewfqr7syz89r3gj557l3ued7ja
address_n=[84 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0], address_n=[84 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0],
amount=12300000, amount=12300000,
@ -174,48 +185,47 @@ class TestSignSegwitTxNativeP2WPKH_GRS(unittest.TestCase):
sequence=0xfffffffe, sequence=0xfffffffe,
multisig=None, multisig=None,
) )
ptx1 = TransactionType(version=1, lock_time=650645, inputs_cnt=1, outputs_cnt=2, extra_data_len=0) ptx1 = TxAckPrevTxType(version=1, lock_time=650645, inputs_count=1, outputs_count=2, extra_data_len=0)
pinp1 = TxInputType(script_sig=unhexlify('483045022100d9615361c044e91f6dd7bb4455f3ad686cd5a663d7800bb74c448b2706500ccb022026bed24b81a501e8398411c5a9a793741d9bfe39617d51c363dde0a84f44f4f9012102659a6eefcc72d6f2eff92e57095388b17db0b06034946ecd44120e5e7a830ff4'), pinp1 = TxAckPrevInputType(script_sig=unhexlify('483045022100d9615361c044e91f6dd7bb4455f3ad686cd5a663d7800bb74c448b2706500ccb022026bed24b81a501e8398411c5a9a793741d9bfe39617d51c363dde0a84f44f4f9012102659a6eefcc72d6f2eff92e57095388b17db0b06034946ecd44120e5e7a830ff4'),
prev_hash=unhexlify('1c92508b38239e5c10b23fb46dcf765ee2f3a95b835edbf0943ec21b21711160'), prev_hash=unhexlify('1c92508b38239e5c10b23fb46dcf765ee2f3a95b835edbf0943ec21b21711160'),
prev_index=1, prev_index=1,
script_type=None,
sequence=4294967293) sequence=4294967293)
pout1 = TxOutputBinType(script_pubkey=unhexlify('0014b31dc2a236505a6cb9201fa0411ca38a254a7bf1'), pout1 = TxAckPrevOutputType(script_pubkey=unhexlify('0014b31dc2a236505a6cb9201fa0411ca38a254a7bf1'),
amount=12300000) amount=12300000)
pout2 = TxOutputBinType(script_pubkey=unhexlify('76a91438cc090e4a4b2e458c33fe35af1c5c0094699ac288ac'), pout2 = TxAckPrevOutputType(script_pubkey=unhexlify('76a91438cc090e4a4b2e458c33fe35af1c5c0094699ac288ac'),
amount=9887699777) amount=9887699777)
out1 = TxOutputType( out1 = TxAckOutputType(
address='2N4Q5FhU2497BryFfUgbqkAJE87aKDv3V3e', address='2N4Q5FhU2497BryFfUgbqkAJE87aKDv3V3e',
amount=5000000, amount=5000000,
script_type=OutputScriptType.PAYTOADDRESS, script_type=OutputScriptType.PAYTOADDRESS,
address_n=[], address_n=[],
multisig=None, multisig=None,
) )
out2 = TxOutputType( out2 = TxAckOutputType(
address=None, address=None,
address_n=[84 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0], address_n=[84 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0],
script_type=OutputScriptType.PAYTOWITNESS, script_type=OutputScriptType.PAYTOWITNESS,
amount=12300000 - 11000 - 5000000, amount=12300000 - 11000 - 5000000,
multisig=None, multisig=None,
) )
tx = SignTx(coin_name='Groestlcoin Testnet', version=None, lock_time=650713, inputs_count=1, outputs_count=2) tx = SignTx(coin_name='Groestlcoin Testnet', version=1, lock_time=650713, inputs_count=1, outputs_count=2)
messages = [ messages = [
None, None,
# check fee # check fee
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(outputs=[out1])), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
helpers.UiConfirmOutput(out1, coin), helpers.UiConfirmOutput(out1, coin),
True, True,
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(outputs=[out2])), TxAckOutput(tx=TxAckOutputWrapper(output=out2)),
helpers.UiConfirmNonDefaultLocktime(tx.lock_time, lock_time_disabled=False), helpers.UiConfirmNonDefaultLocktime(tx.lock_time, lock_time_disabled=False),
True, True,
@ -225,33 +235,33 @@ class TestSignSegwitTxNativeP2WPKH_GRS(unittest.TestCase):
# check prev tx # check prev tx
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=ptx1), TxAckPrevMeta(tx=ptx1),
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[pinp1])), TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(bin_outputs=[pout1])), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(bin_outputs=[pout2])), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout2)),
# sign tx # sign tx
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(
# returned serialized header # returned serialized header
serialized_tx=unhexlify('01000000000101'), serialized_tx=unhexlify('01000000000101'),
)), )),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(
# returned serialized inp1 # returned serialized inp1
serialized_tx=unhexlify('d1613f483f2086d076c82fe34674385a86beb08f052d5405fe1aed397f852f4f0000000000feffffff02'), serialized_tx=unhexlify('d1613f483f2086d076c82fe34674385a86beb08f052d5405fe1aed397f852f4f0000000000feffffff02'),
)), )),
# the out has to be cloned not to send the same object which was modified # the out has to be cloned not to send the same object which was modified
TxAck(tx=TransactionType(outputs=[TxOutputType(**out1.__dict__)])), TxAckOutput(tx=TxAckOutputWrapper(output=TxAckOutputType(**out1.__dict__))),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=TxRequestSerializedType( TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=TxRequestSerializedType(
# returned serialized out1 # returned serialized out1
@ -259,7 +269,7 @@ class TestSignSegwitTxNativeP2WPKH_GRS(unittest.TestCase):
signature_index=None, signature_index=None,
signature=None, signature=None,
)), )),
TxAck(tx=TransactionType(outputs=[TxOutputType(**out2.__dict__)])), TxAckOutput(tx=TxAckOutputWrapper(output=TxAckOutputType(**out2.__dict__))),
# segwit # segwit
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(
@ -268,7 +278,7 @@ class TestSignSegwitTxNativeP2WPKH_GRS(unittest.TestCase):
signature_index=None, signature_index=None,
signature=None, signature=None,
)), )),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType( TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType(
serialized_tx=unhexlify('02483045022100ea8780bc1e60e14e945a80654a41748bbf1aa7d6f2e40a88d91dfc2de1f34bd10220181a474a3420444bd188501d8d270736e1e9fe379da9970de992ff445b0972e3012103adc58245cf28406af0ef5cc24b8afba7f1be6c72f279b642d85c48798685f862d9ed0900'), serialized_tx=unhexlify('02483045022100ea8780bc1e60e14e945a80654a41748bbf1aa7d6f2e40a88d91dfc2de1f34bd10220181a474a3420444bd188501d8d270736e1e9fe379da9970de992ff445b0972e3012103adc58245cf28406af0ef5cc24b8afba7f1be6c72f279b642d85c48798685f862d9ed0900'),
@ -281,8 +291,11 @@ class TestSignSegwitTxNativeP2WPKH_GRS(unittest.TestCase):
keychain = Keychain(seed, coin.curve_name, ns) keychain = Keychain(seed, coin.curve_name, ns)
approver = BasicApprover(tx, coin) approver = BasicApprover(tx, coin)
signer = bitcoinlike.Bitcoinlike(tx, keychain, coin, approver).signer() signer = bitcoinlike.Bitcoinlike(tx, keychain, coin, approver).signer()
for request, response in chunks(messages, 2): for request, expected_response in chunks(messages, 2):
self.assertEqual(signer.send(request), response) response = signer.send(request)
if isinstance(response, tuple):
_, response = response
self.assertEqual(response, expected_response)
with self.assertRaises(StopIteration): with self.assertRaises(StopIteration):
signer.send(None) signer.send(None)

View File

@ -3,12 +3,21 @@ from common import *
from trezor.utils import chunks from trezor.utils import chunks
from trezor.crypto import bip39 from trezor.crypto import bip39
from trezor.messages.SignTx import SignTx from trezor.messages.SignTx import SignTx
from trezor.messages.TxInputType import TxInputType from trezor.messages.TxAckInput import TxAckInput
from trezor.messages.TxOutputType import TxOutputType from trezor.messages.TxAckInputWrapper import TxAckInputWrapper
from trezor.messages.TxOutputBinType import TxOutputBinType from trezor.messages.TxAckInputType import TxAckInputType
from trezor.messages.TxAckOutput import TxAckOutput
from trezor.messages.TxAckOutputWrapper import TxAckOutputWrapper
from trezor.messages.TxAckOutputType import TxAckOutputType
from trezor.messages.TxAckPrevMeta import TxAckPrevMeta
from trezor.messages.TxAckPrevTxType import TxAckPrevTxType
from trezor.messages.TxAckPrevInput import TxAckPrevInput
from trezor.messages.TxAckPrevInputWrapper import TxAckPrevInputWrapper
from trezor.messages.TxAckPrevInputType import TxAckPrevInputType
from trezor.messages.TxAckPrevOutput import TxAckPrevOutput
from trezor.messages.TxAckPrevOutputWrapper import TxAckPrevOutputWrapper
from trezor.messages.TxAckPrevOutputType import TxAckPrevOutputType
from trezor.messages.TxRequest import TxRequest from trezor.messages.TxRequest import TxRequest
from trezor.messages.TxAck import TxAck
from trezor.messages.TransactionType import TransactionType
from trezor.messages.RequestType import TXINPUT, TXMETA, TXOUTPUT, TXFINISHED from trezor.messages.RequestType import TXINPUT, TXMETA, TXOUTPUT, TXFINISHED
from trezor.messages.TxRequestDetailsType import TxRequestDetailsType from trezor.messages.TxRequestDetailsType import TxRequestDetailsType
from trezor.messages.TxRequestSerializedType import TxRequestSerializedType from trezor.messages.TxRequestSerializedType import TxRequestSerializedType
@ -34,7 +43,7 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase):
coin = coins.by_name('Testnet') coin = coins.by_name('Testnet')
seed = bip39.seed(' '.join(['all'] * 12), '') seed = bip39.seed(' '.join(['all'] * 12), '')
inp1 = TxInputType( inp1 = TxAckInputType(
# 49'/1'/0'/1/0" - 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX # 49'/1'/0'/1/0" - 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0], address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0],
amount=123456789, amount=123456789,
@ -44,48 +53,47 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase):
sequence=0xffffffff, sequence=0xffffffff,
multisig=None, multisig=None,
) )
ptx1 = TransactionType(version=1, lock_time=0, inputs_cnt=1, outputs_cnt=2, extra_data_len=0) ptx1 = TxAckPrevTxType(version=1, lock_time=0, inputs_count=1, outputs_count=2, extra_data_len=0)
pinp1 = TxInputType(script_sig=unhexlify('4730440220548e087d0426b20b8a571b03b9e05829f7558b80c53c12143e342f56ab29e51d02205b68cb7fb223981d4c999725ac1485a982c4259c4f50b8280f137878c232998a012102794a25b254a268e59a5869da57fbae2fadc6727cb3309321dab409b12b2fa17c'), pinp1 = TxAckPrevInputType(script_sig=unhexlify('4730440220548e087d0426b20b8a571b03b9e05829f7558b80c53c12143e342f56ab29e51d02205b68cb7fb223981d4c999725ac1485a982c4259c4f50b8280f137878c232998a012102794a25b254a268e59a5869da57fbae2fadc6727cb3309321dab409b12b2fa17c'),
prev_hash=unhexlify('802cabf0843b945eabe136d7fc7c89f41021658abf56cba000acbce88c41143a'), prev_hash=unhexlify('802cabf0843b945eabe136d7fc7c89f41021658abf56cba000acbce88c41143a'),
prev_index=0, prev_index=0,
script_type=None,
sequence=4294967295) sequence=4294967295)
pout1 = TxOutputBinType(script_pubkey=unhexlify('a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'), pout1 = TxAckPrevOutputType(script_pubkey=unhexlify('a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'),
amount=123456789) amount=123456789)
pout2 = TxOutputBinType(script_pubkey=unhexlify('76a914b84bacdcd8f4cc59274a5bfb73f804ca10f7fd1488ac'), pout2 = TxAckPrevOutputType(script_pubkey=unhexlify('76a914b84bacdcd8f4cc59274a5bfb73f804ca10f7fd1488ac'),
amount=865519308) amount=865519308)
out1 = TxOutputType( out1 = TxAckOutputType(
address='mhRx1CeVfaayqRwq5zgRQmD7W5aWBfD5mC', address='mhRx1CeVfaayqRwq5zgRQmD7W5aWBfD5mC',
amount=12300000, amount=12300000,
script_type=OutputScriptType.PAYTOADDRESS, script_type=OutputScriptType.PAYTOADDRESS,
address_n=[], address_n=[],
multisig=None, multisig=None,
) )
out2 = TxOutputType( out2 = TxAckOutputType(
address='2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX', address='2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX',
script_type=OutputScriptType.PAYTOADDRESS, script_type=OutputScriptType.PAYTOADDRESS,
amount=123456789 - 11000 - 12300000, amount=123456789 - 11000 - 12300000,
address_n=[], address_n=[],
multisig=None, multisig=None,
) )
tx = SignTx(coin_name='Testnet', version=None, lock_time=None, inputs_count=1, outputs_count=2) tx = SignTx(coin_name='Testnet', version=1, lock_time=0, inputs_count=1, outputs_count=2)
messages = [ messages = [
None, None,
# check fee # check fee
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(outputs=[out1])), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
helpers.UiConfirmOutput(out1, coin), helpers.UiConfirmOutput(out1, coin),
True, True,
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(outputs=[out2])), TxAckOutput(tx=TxAckOutputWrapper(output=out2)),
helpers.UiConfirmOutput(out2, coin), helpers.UiConfirmOutput(out2, coin),
True, True,
@ -95,32 +103,32 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase):
# check prev tx # check prev tx
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=ptx1), TxAckPrevMeta(tx=ptx1),
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[pinp1])), TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(bin_outputs=[pout1])), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(bin_outputs=[pout2])), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout2)),
# sign tx # sign tx
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(
# returned serialized header # returned serialized header
serialized_tx=unhexlify('01000000000101'), serialized_tx=unhexlify('01000000000101'),
)), )),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(
# returned serialized inp1 # returned serialized inp1
serialized_tx=unhexlify('37c361fb8f2d9056ba8c98c5611930fcb48cacfdd0fe2e0449d83eea982f91200000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5ffffffff02'), serialized_tx=unhexlify('37c361fb8f2d9056ba8c98c5611930fcb48cacfdd0fe2e0449d83eea982f91200000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5ffffffff02'),
)), )),
TxAck(tx=TransactionType(outputs=[out1])), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=TxRequestSerializedType( TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=TxRequestSerializedType(
# returned serialized out1 # returned serialized out1
@ -128,7 +136,7 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase):
signature_index=None, signature_index=None,
signature=None, signature=None,
)), )),
TxAck(tx=TransactionType(outputs=[out2])), TxAckOutput(tx=TxAckOutputWrapper(output=out2)),
# segwit # segwit
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(
@ -137,7 +145,7 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase):
signature_index=None, signature_index=None,
signature=None, signature=None,
)), )),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType( TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType(
serialized_tx=unhexlify('02483045022100ccd253bfdf8a5593cd7b6701370c531199f0f05a418cd547dfc7da3f21515f0f02203fa08a0753688871c220648f9edadbdb98af42e5d8269364a326572cf703895b012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7900000000'), serialized_tx=unhexlify('02483045022100ccd253bfdf8a5593cd7b6701370c531199f0f05a418cd547dfc7da3f21515f0f02203fa08a0753688871c220648f9edadbdb98af42e5d8269364a326572cf703895b012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7900000000'),
@ -150,8 +158,11 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase):
keychain = Keychain(seed, coin.curve_name, ns) keychain = Keychain(seed, coin.curve_name, ns)
approver = BasicApprover(tx, coin) approver = BasicApprover(tx, coin)
signer = bitcoin.Bitcoin(tx, keychain, coin, approver).signer() signer = bitcoin.Bitcoin(tx, keychain, coin, approver).signer()
for request, response in chunks(messages, 2): for request, expected_response in chunks(messages, 2):
self.assertEqual(signer.send(request), response) response = signer.send(request)
if isinstance(response, tuple):
_, response = response
self.assertEqual(response, expected_response)
with self.assertRaises(StopIteration): with self.assertRaises(StopIteration):
signer.send(None) signer.send(None)
@ -160,7 +171,7 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase):
coin = coins.by_name('Testnet') coin = coins.by_name('Testnet')
seed = bip39.seed(' '.join(['all'] * 12), '') seed = bip39.seed(' '.join(['all'] * 12), '')
inp1 = TxInputType( inp1 = TxAckInputType(
# 49'/1'/0'/1/0" - 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX # 49'/1'/0'/1/0" - 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0], address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0],
amount=123456789, amount=123456789,
@ -170,68 +181,67 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase):
sequence=0xffffffff, sequence=0xffffffff,
multisig=None, multisig=None,
) )
ptx1 = TransactionType(version=1, lock_time=0, inputs_cnt=1, outputs_cnt=2, extra_data_len=0) ptx1 = TxAckPrevTxType(version=1, lock_time=0, inputs_count=1, outputs_count=2, extra_data_len=0)
pinp1 = TxInputType(script_sig=unhexlify('4730440220548e087d0426b20b8a571b03b9e05829f7558b80c53c12143e342f56ab29e51d02205b68cb7fb223981d4c999725ac1485a982c4259c4f50b8280f137878c232998a012102794a25b254a268e59a5869da57fbae2fadc6727cb3309321dab409b12b2fa17c'), pinp1 = TxAckPrevInputType(script_sig=unhexlify('4730440220548e087d0426b20b8a571b03b9e05829f7558b80c53c12143e342f56ab29e51d02205b68cb7fb223981d4c999725ac1485a982c4259c4f50b8280f137878c232998a012102794a25b254a268e59a5869da57fbae2fadc6727cb3309321dab409b12b2fa17c'),
prev_hash=unhexlify('802cabf0843b945eabe136d7fc7c89f41021658abf56cba000acbce88c41143a'), prev_hash=unhexlify('802cabf0843b945eabe136d7fc7c89f41021658abf56cba000acbce88c41143a'),
prev_index=0, prev_index=0,
script_type=None,
sequence=4294967295) sequence=4294967295)
pout1 = TxOutputBinType(script_pubkey=unhexlify('a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'), pout1 = TxAckPrevOutputType(script_pubkey=unhexlify('a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'),
amount=123456789) amount=123456789)
pout2 = TxOutputBinType(script_pubkey=unhexlify('76a914b84bacdcd8f4cc59274a5bfb73f804ca10f7fd1488ac'), pout2 = TxAckPrevOutputType(script_pubkey=unhexlify('76a914b84bacdcd8f4cc59274a5bfb73f804ca10f7fd1488ac'),
amount=865519308) amount=865519308)
out1 = TxOutputType( out1 = TxAckOutputType(
address='mhRx1CeVfaayqRwq5zgRQmD7W5aWBfD5mC', address='mhRx1CeVfaayqRwq5zgRQmD7W5aWBfD5mC',
amount=12300000, amount=12300000,
script_type=OutputScriptType.PAYTOADDRESS, script_type=OutputScriptType.PAYTOADDRESS,
address_n=[], address_n=[],
multisig=None, multisig=None,
) )
out2 = TxOutputType( out2 = TxAckOutputType(
address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0], address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0],
script_type=OutputScriptType.PAYTOP2SHWITNESS, script_type=OutputScriptType.PAYTOP2SHWITNESS,
amount=123456789 - 11000 - 12300000, amount=123456789 - 11000 - 12300000,
address=None, address=None,
multisig=None, multisig=None,
) )
tx = SignTx(coin_name='Testnet', version=None, lock_time=None, inputs_count=1, outputs_count=2) tx = SignTx(coin_name='Testnet', version=1, lock_time=0, inputs_count=1, outputs_count=2)
messages = [ messages = [
None, None,
# check fee # check fee
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(outputs=[out1])), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
helpers.UiConfirmOutput(out1, coin), helpers.UiConfirmOutput(out1, coin),
True, True,
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(outputs=[out2])), TxAckOutput(tx=TxAckOutputWrapper(output=out2)),
helpers.UiConfirmTotal(12300000 + 11000, 11000, coin), helpers.UiConfirmTotal(12300000 + 11000, 11000, coin),
True, True,
# check prev tx # check prev tx
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=ptx1), TxAckPrevMeta(tx=ptx1),
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[pinp1])), TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(bin_outputs=[pout1])), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(bin_outputs=[pout2])), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout2)),
# sign tx # sign tx
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None),
@ -241,7 +251,7 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase):
'01000000000101'), '01000000000101'),
)), )),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None),
serialized=TxRequestSerializedType( serialized=TxRequestSerializedType(
@ -250,7 +260,7 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase):
'37c361fb8f2d9056ba8c98c5611930fcb48cacfdd0fe2e0449d83eea982f91200000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5ffffffff02'), '37c361fb8f2d9056ba8c98c5611930fcb48cacfdd0fe2e0449d83eea982f91200000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5ffffffff02'),
)), )),
# the out has to be cloned not to send the same object which was modified # the out has to be cloned not to send the same object which was modified
TxAck(tx=TransactionType(outputs=[TxOutputType(**out1.__dict__)])), TxAckOutput(tx=TxAckOutputWrapper(output=TxAckOutputType(**out1.__dict__))),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None),
serialized=TxRequestSerializedType( serialized=TxRequestSerializedType(
@ -260,7 +270,7 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase):
signature_index=None, signature_index=None,
signature=None, signature=None,
)), )),
TxAck(tx=TransactionType(outputs=[TxOutputType(**out2.__dict__)])), TxAckOutput(tx=TxAckOutputWrapper(output=TxAckOutputType(**out2.__dict__))),
# segwit # segwit
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None),
@ -271,7 +281,7 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase):
signature_index=None, signature_index=None,
signature=None, signature=None,
)), )),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType( TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType(
serialized_tx=unhexlify( serialized_tx=unhexlify(
@ -285,8 +295,11 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase):
keychain = Keychain(seed, coin.curve_name, ns) keychain = Keychain(seed, coin.curve_name, ns)
approver = BasicApprover(tx, coin) approver = BasicApprover(tx, coin)
signer = bitcoin.Bitcoin(tx, keychain, coin, approver).signer() signer = bitcoin.Bitcoin(tx, keychain, coin, approver).signer()
for request, response in chunks(messages, 2): for request, expected_response in chunks(messages, 2):
self.assertEqual(signer.send(request), response) response = signer.send(request)
if isinstance(response, tuple):
_, response = response
self.assertEqual(response, expected_response)
with self.assertRaises(StopIteration): with self.assertRaises(StopIteration):
signer.send(None) signer.send(None)
@ -295,7 +308,7 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase):
coin = coins.by_name('Testnet') coin = coins.by_name('Testnet')
seed = bip39.seed(' '.join(['all'] * 12), '') seed = bip39.seed(' '.join(['all'] * 12), '')
inp1 = TxInputType( inp1 = TxAckInputType(
# 49'/1'/0'/1/0" - 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX # 49'/1'/0'/1/0" - 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0], address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0],
amount=10, amount=10,
@ -305,18 +318,17 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase):
sequence=0xffffffff, sequence=0xffffffff,
multisig=None, multisig=None,
) )
ptx1 = TransactionType(version=1, lock_time=0, inputs_cnt=1, outputs_cnt=2, extra_data_len=0) ptx1 = TxAckPrevTxType(version=1, lock_time=0, inputs_count=1, outputs_count=2, extra_data_len=0)
pinp1 = TxInputType(script_sig=unhexlify('4730440220548e087d0426b20b8a571b03b9e05829f7558b80c53c12143e342f56ab29e51d02205b68cb7fb223981d4c999725ac1485a982c4259c4f50b8280f137878c232998a012102794a25b254a268e59a5869da57fbae2fadc6727cb3309321dab409b12b2fa17c'), pinp1 = TxAckPrevInputType(script_sig=unhexlify('4730440220548e087d0426b20b8a571b03b9e05829f7558b80c53c12143e342f56ab29e51d02205b68cb7fb223981d4c999725ac1485a982c4259c4f50b8280f137878c232998a012102794a25b254a268e59a5869da57fbae2fadc6727cb3309321dab409b12b2fa17c'),
prev_hash=unhexlify('802cabf0843b945eabe136d7fc7c89f41021658abf56cba000acbce88c41143a'), prev_hash=unhexlify('802cabf0843b945eabe136d7fc7c89f41021658abf56cba000acbce88c41143a'),
prev_index=0, prev_index=0,
script_type=None,
sequence=4294967295) sequence=4294967295)
pout1 = TxOutputBinType(script_pubkey=unhexlify('a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'), pout1 = TxAckPrevOutputType(script_pubkey=unhexlify('a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'),
amount=123456789) amount=123456789)
pout2 = TxOutputBinType(script_pubkey=unhexlify('76a914b84bacdcd8f4cc59274a5bfb73f804ca10f7fd1488ac'), pout2 = TxAckPrevOutputType(script_pubkey=unhexlify('76a914b84bacdcd8f4cc59274a5bfb73f804ca10f7fd1488ac'),
amount=865519308) amount=865519308)
inpattack = TxInputType( inpattack = TxAckInputType(
# 49'/1'/0'/1/0" - 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX # 49'/1'/0'/1/0" - 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0], address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0],
amount=9, # modified! amount=9, # modified!
@ -326,56 +338,56 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase):
sequence=0xffffffff, sequence=0xffffffff,
multisig=None, multisig=None,
) )
out1 = TxOutputType( out1 = TxAckOutputType(
address='mhRx1CeVfaayqRwq5zgRQmD7W5aWBfD5mC', address='mhRx1CeVfaayqRwq5zgRQmD7W5aWBfD5mC',
amount=8, amount=8,
script_type=OutputScriptType.PAYTOADDRESS, script_type=OutputScriptType.PAYTOADDRESS,
address_n=[], address_n=[],
multisig=None, multisig=None,
) )
out2 = TxOutputType( out2 = TxAckOutputType(
address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0], address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0],
script_type=OutputScriptType.PAYTOP2SHWITNESS, script_type=OutputScriptType.PAYTOP2SHWITNESS,
amount=1, amount=1,
address=None, address=None,
multisig=None, multisig=None,
) )
tx = SignTx(coin_name='Testnet', version=None, lock_time=None, inputs_count=1, outputs_count=2) tx = SignTx(coin_name='Testnet', version=1, lock_time=0, inputs_count=1, outputs_count=2)
messages = [ messages = [
None, None,
# check fee # check fee
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[inpattack])), TxAckInput(tx=TxAckInputWrapper(input=inpattack)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(outputs=[out1])), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
helpers.UiConfirmOutput(out1, coin), helpers.UiConfirmOutput(out1, coin),
True, True,
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(outputs=[out2])), TxAckOutput(tx=TxAckOutputWrapper(output=out2)),
helpers.UiConfirmTotal(9 - 1, 9 - 8 - 1, coin), helpers.UiConfirmTotal(9 - 1, 9 - 8 - 1, coin),
True, True,
# check prev tx # check prev tx
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=ptx1), TxAckPrevMeta(tx=ptx1),
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[pinp1])), TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(bin_outputs=[pout1])), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(bin_outputs=[pout2])), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout2)),
# sign tx # sign tx
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None),
@ -392,11 +404,14 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase):
signer = bitcoin.Bitcoin(tx, keychain, coin, approver).signer() signer = bitcoin.Bitcoin(tx, keychain, coin, approver).signer()
i = 0 i = 0
messages_count = int(len(messages) / 2) messages_count = int(len(messages) / 2)
for request, response in chunks(messages, 2): for request, expected_response in chunks(messages, 2):
if i == messages_count - 1: # last message should throw wire.Error if i == messages_count - 1: # last message should throw wire.Error
self.assertRaises(wire.DataError, signer.send, request) self.assertRaises(wire.DataError, signer.send, request)
else: else:
self.assertEqual(signer.send(request), response) response = signer.send(request)
if isinstance(response, tuple):
_, response = response
self.assertEqual(response, expected_response)
i += 1 i += 1
with self.assertRaises(StopIteration): with self.assertRaises(StopIteration):
signer.send(None) signer.send(None)

View File

@ -3,12 +3,21 @@ from common import *
from trezor.utils import chunks from trezor.utils import chunks
from trezor.crypto import bip39 from trezor.crypto import bip39
from trezor.messages.SignTx import SignTx from trezor.messages.SignTx import SignTx
from trezor.messages.TxInputType import TxInputType from trezor.messages.TxAckInput import TxAckInput
from trezor.messages.TxOutputBinType import TxOutputBinType from trezor.messages.TxAckInputWrapper import TxAckInputWrapper
from trezor.messages.TxOutputType import TxOutputType from trezor.messages.TxAckInputType import TxAckInputType
from trezor.messages.TxAckOutput import TxAckOutput
from trezor.messages.TxAckOutputWrapper import TxAckOutputWrapper
from trezor.messages.TxAckOutputType import TxAckOutputType
from trezor.messages.TxAckPrevMeta import TxAckPrevMeta
from trezor.messages.TxAckPrevTxType import TxAckPrevTxType
from trezor.messages.TxAckPrevInput import TxAckPrevInput
from trezor.messages.TxAckPrevInputWrapper import TxAckPrevInputWrapper
from trezor.messages.TxAckPrevInputType import TxAckPrevInputType
from trezor.messages.TxAckPrevOutput import TxAckPrevOutput
from trezor.messages.TxAckPrevOutputWrapper import TxAckPrevOutputWrapper
from trezor.messages.TxAckPrevOutputType import TxAckPrevOutputType
from trezor.messages.TxRequest import TxRequest from trezor.messages.TxRequest import TxRequest
from trezor.messages.TxAck import TxAck
from trezor.messages.TransactionType import TransactionType
from trezor.messages.RequestType import TXINPUT, TXMETA, TXOUTPUT, TXFINISHED from trezor.messages.RequestType import TXINPUT, TXMETA, TXOUTPUT, TXFINISHED
from trezor.messages.TxRequestDetailsType import TxRequestDetailsType from trezor.messages.TxRequestDetailsType import TxRequestDetailsType
from trezor.messages.TxRequestSerializedType import TxRequestSerializedType from trezor.messages.TxRequestSerializedType import TxRequestSerializedType
@ -35,7 +44,7 @@ class TestSignSegwitTxP2WPKHInP2SH_GRS(unittest.TestCase):
coin = coins.by_name('Groestlcoin Testnet') coin = coins.by_name('Groestlcoin Testnet')
seed = bip39.seed(' '.join(['all'] * 12), '') seed = bip39.seed(' '.join(['all'] * 12), '')
inp1 = TxInputType( inp1 = TxAckInputType(
# 49'/1'/0'/1/0" - 2N1LGaGg836mqSQqiuUBLfcyGBhyZYBtBZ7 # 49'/1'/0'/1/0" - 2N1LGaGg836mqSQqiuUBLfcyGBhyZYBtBZ7
address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0], address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0],
amount=123456789, amount=123456789,
@ -45,48 +54,47 @@ class TestSignSegwitTxP2WPKHInP2SH_GRS(unittest.TestCase):
sequence=0xfffffffe, sequence=0xfffffffe,
multisig=None, multisig=None,
) )
ptx1 = TransactionType(version=1, lock_time=650749, inputs_cnt=1, outputs_cnt=2, extra_data_len=0) ptx1 = TxAckPrevTxType(version=1, lock_time=650749, inputs_count=1, outputs_count=2, extra_data_len=0)
pinp1 = TxInputType(script_sig=unhexlify('47304402201f8f57f708144c3a11da322546cb37bd385aa825d940c37e8016f0efd6ec3e9402202a41bc02c29e4f3f13efd4bededbcd4308a6393279111d614ee1f7635cf3e65701210371546a36bdf6bc82087301b3f6e759736dc8790150673d2e7e2715d2ad72f3a4'), pinp1 = TxAckPrevInputType(script_sig=unhexlify('47304402201f8f57f708144c3a11da322546cb37bd385aa825d940c37e8016f0efd6ec3e9402202a41bc02c29e4f3f13efd4bededbcd4308a6393279111d614ee1f7635cf3e65701210371546a36bdf6bc82087301b3f6e759736dc8790150673d2e7e2715d2ad72f3a4'),
prev_hash=unhexlify('4f2f857f39ed1afe05542d058fb0be865a387446e32fc876d086203f483f61d1'), prev_hash=unhexlify('4f2f857f39ed1afe05542d058fb0be865a387446e32fc876d086203f483f61d1'),
prev_index=1, prev_index=1,
script_type=None,
sequence=4294967294) sequence=4294967294)
pout1 = TxOutputBinType(script_pubkey=unhexlify('a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'), pout1 = TxAckPrevOutputType(script_pubkey=unhexlify('a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'),
amount=123456789) amount=123456789)
pout2 = TxOutputBinType(script_pubkey=unhexlify('76a91435528b20e9a793cf2c3a1cf9cff1f2127ad377da88ac'), pout2 = TxAckPrevOutputType(script_pubkey=unhexlify('76a91435528b20e9a793cf2c3a1cf9cff1f2127ad377da88ac'),
amount=9764242764) amount=9764242764)
out1 = TxOutputType( out1 = TxAckOutputType(
address='mvbu1Gdy8SUjTenqerxUaZyYjmvedc787y', address='mvbu1Gdy8SUjTenqerxUaZyYjmvedc787y',
amount=12300000, amount=12300000,
script_type=OutputScriptType.PAYTOADDRESS, script_type=OutputScriptType.PAYTOADDRESS,
address_n=[], address_n=[],
multisig=None, multisig=None,
) )
out2 = TxOutputType( out2 = TxAckOutputType(
address='2N1LGaGg836mqSQqiuUBLfcyGBhyZYBtBZ7', address='2N1LGaGg836mqSQqiuUBLfcyGBhyZYBtBZ7',
script_type=OutputScriptType.PAYTOADDRESS, script_type=OutputScriptType.PAYTOADDRESS,
amount=123456789 - 11000 - 12300000, amount=123456789 - 11000 - 12300000,
address_n=[], address_n=[],
multisig=None, multisig=None,
) )
tx = SignTx(coin_name='Groestlcoin Testnet', version=None, lock_time=650756, inputs_count=1, outputs_count=2) tx = SignTx(coin_name='Groestlcoin Testnet', version=1, lock_time=650756, inputs_count=1, outputs_count=2)
messages = [ messages = [
None, None,
# check fee # check fee
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(outputs=[out1])), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
helpers.UiConfirmOutput(out1, coin), helpers.UiConfirmOutput(out1, coin),
True, True,
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(outputs=[out2])), TxAckOutput(tx=TxAckOutputWrapper(output=out2)),
helpers.UiConfirmOutput(out2, coin), helpers.UiConfirmOutput(out2, coin),
True, True,
@ -99,32 +107,32 @@ class TestSignSegwitTxP2WPKHInP2SH_GRS(unittest.TestCase):
# check prev tx # check prev tx
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=ptx1), TxAckPrevMeta(tx=ptx1),
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[pinp1])), TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(bin_outputs=[pout1])), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(bin_outputs=[pout2])), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout2)),
# sign tx # sign tx
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(
# returned serialized header # returned serialized header
serialized_tx=unhexlify('01000000000101'), serialized_tx=unhexlify('01000000000101'),
)), )),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(
# returned serialized inp1 # returned serialized inp1
serialized_tx=unhexlify('cf60ded29a2bd7ebf93453feace8551889d0321beab90c4f6e5c9d2fce8ba4090000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5feffffff02'), serialized_tx=unhexlify('cf60ded29a2bd7ebf93453feace8551889d0321beab90c4f6e5c9d2fce8ba4090000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5feffffff02'),
)), )),
TxAck(tx=TransactionType(outputs=[out1])), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=TxRequestSerializedType( TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=TxRequestSerializedType(
# returned serialized out1 # returned serialized out1
@ -132,7 +140,7 @@ class TestSignSegwitTxP2WPKHInP2SH_GRS(unittest.TestCase):
signature_index=None, signature_index=None,
signature=None, signature=None,
)), )),
TxAck(tx=TransactionType(outputs=[out2])), TxAckOutput(tx=TxAckOutputWrapper(output=out2)),
# segwit # segwit
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(
@ -141,7 +149,7 @@ class TestSignSegwitTxP2WPKHInP2SH_GRS(unittest.TestCase):
signature_index=None, signature_index=None,
signature=None, signature=None,
)), )),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType( TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType(
serialized_tx=unhexlify('02483045022100b7ce2972bcbc3a661fe320ba901e680913b2753fcb47055c9c6ba632fc4acf81022001c3cfd6c2fe92eb60f5176ce0f43707114dd7223da19c56f2df89c13c2fef80012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7904ee0900'), serialized_tx=unhexlify('02483045022100b7ce2972bcbc3a661fe320ba901e680913b2753fcb47055c9c6ba632fc4acf81022001c3cfd6c2fe92eb60f5176ce0f43707114dd7223da19c56f2df89c13c2fef80012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7904ee0900'),
@ -154,8 +162,11 @@ class TestSignSegwitTxP2WPKHInP2SH_GRS(unittest.TestCase):
keychain = Keychain(seed, coin.curve_name, ns) keychain = Keychain(seed, coin.curve_name, ns)
approver = BasicApprover(tx, coin) approver = BasicApprover(tx, coin)
signer = bitcoinlike.Bitcoinlike(tx, keychain, coin, approver).signer() signer = bitcoinlike.Bitcoinlike(tx, keychain, coin, approver).signer()
for request, response in chunks(messages, 2): for request, expected_response in chunks(messages, 2):
self.assertEqual(signer.send(request), response) response = signer.send(request)
if isinstance(response, tuple):
_, response = response
self.assertEqual(response, expected_response)
with self.assertRaises(StopIteration): with self.assertRaises(StopIteration):
signer.send(None) signer.send(None)
@ -164,7 +175,7 @@ class TestSignSegwitTxP2WPKHInP2SH_GRS(unittest.TestCase):
coin = coins.by_name('Groestlcoin Testnet') coin = coins.by_name('Groestlcoin Testnet')
seed = bip39.seed(' '.join(['all'] * 12), '') seed = bip39.seed(' '.join(['all'] * 12), '')
inp1 = TxInputType( inp1 = TxAckInputType(
# 49'/1'/0'/1/0" - 2N1LGaGg836mqSQqiuUBLfcyGBhyZYBtBZ7 # 49'/1'/0'/1/0" - 2N1LGaGg836mqSQqiuUBLfcyGBhyZYBtBZ7
address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0], address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0],
amount=123456789, amount=123456789,
@ -174,48 +185,47 @@ class TestSignSegwitTxP2WPKHInP2SH_GRS(unittest.TestCase):
sequence=0xfffffffe, sequence=0xfffffffe,
multisig=None, multisig=None,
) )
ptx1 = TransactionType(version=1, lock_time=650749, inputs_cnt=1, outputs_cnt=2, extra_data_len=0) ptx1 = TxAckPrevTxType(version=1, lock_time=650749, inputs_count=1, outputs_count=2, extra_data_len=0)
pinp1 = TxInputType(script_sig=unhexlify('47304402201f8f57f708144c3a11da322546cb37bd385aa825d940c37e8016f0efd6ec3e9402202a41bc02c29e4f3f13efd4bededbcd4308a6393279111d614ee1f7635cf3e65701210371546a36bdf6bc82087301b3f6e759736dc8790150673d2e7e2715d2ad72f3a4'), pinp1 = TxAckPrevInputType(script_sig=unhexlify('47304402201f8f57f708144c3a11da322546cb37bd385aa825d940c37e8016f0efd6ec3e9402202a41bc02c29e4f3f13efd4bededbcd4308a6393279111d614ee1f7635cf3e65701210371546a36bdf6bc82087301b3f6e759736dc8790150673d2e7e2715d2ad72f3a4'),
prev_hash=unhexlify('4f2f857f39ed1afe05542d058fb0be865a387446e32fc876d086203f483f61d1'), prev_hash=unhexlify('4f2f857f39ed1afe05542d058fb0be865a387446e32fc876d086203f483f61d1'),
prev_index=1, prev_index=1,
script_type=None,
sequence=4294967294) sequence=4294967294)
pout1 = TxOutputBinType(script_pubkey=unhexlify('a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'), pout1 = TxAckPrevOutputType(script_pubkey=unhexlify('a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'),
amount=123456789) amount=123456789)
pout2 = TxOutputBinType(script_pubkey=unhexlify('76a91435528b20e9a793cf2c3a1cf9cff1f2127ad377da88ac'), pout2 = TxAckPrevOutputType(script_pubkey=unhexlify('76a91435528b20e9a793cf2c3a1cf9cff1f2127ad377da88ac'),
amount=9764242764) amount=9764242764)
out1 = TxOutputType( out1 = TxAckOutputType(
address='mvbu1Gdy8SUjTenqerxUaZyYjmvedc787y', address='mvbu1Gdy8SUjTenqerxUaZyYjmvedc787y',
amount=12300000, amount=12300000,
script_type=OutputScriptType.PAYTOADDRESS, script_type=OutputScriptType.PAYTOADDRESS,
address_n=[], address_n=[],
multisig=None, multisig=None,
) )
out2 = TxOutputType( out2 = TxAckOutputType(
address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0], address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0],
script_type=OutputScriptType.PAYTOP2SHWITNESS, script_type=OutputScriptType.PAYTOP2SHWITNESS,
amount=123456789 - 11000 - 12300000, amount=123456789 - 11000 - 12300000,
address=None, address=None,
multisig=None, multisig=None,
) )
tx = SignTx(coin_name='Groestlcoin Testnet', version=None, lock_time=650756, inputs_count=1, outputs_count=2) tx = SignTx(coin_name='Groestlcoin Testnet', version=1, lock_time=650756, inputs_count=1, outputs_count=2)
messages = [ messages = [
None, None,
# check fee # check fee
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(outputs=[out1])), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
helpers.UiConfirmOutput(out1, coin), helpers.UiConfirmOutput(out1, coin),
True, True,
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(outputs=[out2])), TxAckOutput(tx=TxAckOutputWrapper(output=out2)),
helpers.UiConfirmNonDefaultLocktime(tx.lock_time, lock_time_disabled=False), helpers.UiConfirmNonDefaultLocktime(tx.lock_time, lock_time_disabled=False),
True, True,
@ -225,19 +235,19 @@ class TestSignSegwitTxP2WPKHInP2SH_GRS(unittest.TestCase):
# check prev tx # check prev tx
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=ptx1), TxAckPrevMeta(tx=ptx1),
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[pinp1])), TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(bin_outputs=[pout1])), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(bin_outputs=[pout2])), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout2)),
# sign tx # sign tx
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None),
@ -246,7 +256,7 @@ class TestSignSegwitTxP2WPKHInP2SH_GRS(unittest.TestCase):
serialized_tx=unhexlify( serialized_tx=unhexlify(
'01000000000101'), '01000000000101'),
)), )),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None),
serialized=TxRequestSerializedType( serialized=TxRequestSerializedType(
@ -255,7 +265,7 @@ class TestSignSegwitTxP2WPKHInP2SH_GRS(unittest.TestCase):
'cf60ded29a2bd7ebf93453feace8551889d0321beab90c4f6e5c9d2fce8ba4090000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5feffffff02'), 'cf60ded29a2bd7ebf93453feace8551889d0321beab90c4f6e5c9d2fce8ba4090000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5feffffff02'),
)), )),
# the out has to be cloned not to send the same object which was modified # the out has to be cloned not to send the same object which was modified
TxAck(tx=TransactionType(outputs=[TxOutputType(**out1.__dict__)])), TxAckOutput(tx=TxAckOutputWrapper(output=TxAckOutputType(**out1.__dict__))),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None),
serialized=TxRequestSerializedType( serialized=TxRequestSerializedType(
@ -265,7 +275,7 @@ class TestSignSegwitTxP2WPKHInP2SH_GRS(unittest.TestCase):
signature_index=None, signature_index=None,
signature=None, signature=None,
)), )),
TxAck(tx=TransactionType(outputs=[TxOutputType(**out2.__dict__)])), TxAckOutput(tx=TxAckOutputWrapper(output=TxAckOutputType(**out2.__dict__))),
# segwit # segwit
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None),
@ -276,7 +286,7 @@ class TestSignSegwitTxP2WPKHInP2SH_GRS(unittest.TestCase):
signature_index=None, signature_index=None,
signature=None, signature=None,
)), )),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType( TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType(
serialized_tx=unhexlify('02483045022100b7ce2972bcbc3a661fe320ba901e680913b2753fcb47055c9c6ba632fc4acf81022001c3cfd6c2fe92eb60f5176ce0f43707114dd7223da19c56f2df89c13c2fef80012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7904ee0900'), serialized_tx=unhexlify('02483045022100b7ce2972bcbc3a661fe320ba901e680913b2753fcb47055c9c6ba632fc4acf81022001c3cfd6c2fe92eb60f5176ce0f43707114dd7223da19c56f2df89c13c2fef80012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7904ee0900'),
@ -289,8 +299,11 @@ class TestSignSegwitTxP2WPKHInP2SH_GRS(unittest.TestCase):
keychain = Keychain(seed, coin.curve_name, ns) keychain = Keychain(seed, coin.curve_name, ns)
approver = BasicApprover(tx, coin) approver = BasicApprover(tx, coin)
signer = bitcoinlike.Bitcoinlike(tx, keychain, coin, approver).signer() signer = bitcoinlike.Bitcoinlike(tx, keychain, coin, approver).signer()
for request, response in chunks(messages, 2): for request, expected_response in chunks(messages, 2):
self.assertEqual(signer.send(request), response) response = signer.send(request)
if isinstance(response, tuple):
_, response = response
self.assertEqual(response, expected_response)
with self.assertRaises(StopIteration): with self.assertRaises(StopIteration):
signer.send(None) signer.send(None)

View File

@ -1,6 +1,6 @@
from common import * from common import *
from trezor.messages.TxInputType import TxInputType from trezor.messages.TxAckInputType import TxAckInputType
from trezor.messages import InputScriptType from trezor.messages import InputScriptType
from apps.bitcoin import writers from apps.bitcoin import writers
@ -8,7 +8,7 @@ from apps.bitcoin import writers
class TestWriters(unittest.TestCase): class TestWriters(unittest.TestCase):
def test_tx_input(self): def test_tx_input(self):
inp = TxInputType( inp = TxAckInputType(
address_n=[0], address_n=[0],
amount=390000, amount=390000,
prev_hash=unhexlify( prev_hash=unhexlify(
@ -28,7 +28,7 @@ class TestWriters(unittest.TestCase):
self.assertRaises(AssertionError, writers.write_tx_input, b, inp, inp.script_sig) self.assertRaises(AssertionError, writers.write_tx_input, b, inp, inp.script_sig)
def test_tx_input_check(self): def test_tx_input_check(self):
inp = TxInputType( inp = TxAckInputType(
address_n=[0], address_n=[0],
amount=390000, amount=390000,
prev_hash=unhexlify( prev_hash=unhexlify(

View File

@ -3,12 +3,21 @@ from common import *
from trezor.utils import chunks from trezor.utils import chunks
from trezor.crypto import bip32, bip39 from trezor.crypto import bip32, bip39
from trezor.messages.SignTx import SignTx from trezor.messages.SignTx import SignTx
from trezor.messages.TxInputType import TxInputType from trezor.messages.TxAckInput import TxAckInput
from trezor.messages.TxOutputType import TxOutputType from trezor.messages.TxAckInputWrapper import TxAckInputWrapper
from trezor.messages.TxOutputBinType import TxOutputBinType from trezor.messages.TxAckInputType import TxAckInputType
from trezor.messages.TxAckOutput import TxAckOutput
from trezor.messages.TxAckOutputWrapper import TxAckOutputWrapper
from trezor.messages.TxAckOutputType import TxAckOutputType
from trezor.messages.TxAckPrevMeta import TxAckPrevMeta
from trezor.messages.TxAckPrevTxType import TxAckPrevTxType
from trezor.messages.TxAckPrevInput import TxAckPrevInput
from trezor.messages.TxAckPrevInputWrapper import TxAckPrevInputWrapper
from trezor.messages.TxAckPrevInputType import TxAckPrevInputType
from trezor.messages.TxAckPrevOutput import TxAckPrevOutput
from trezor.messages.TxAckPrevOutputWrapper import TxAckPrevOutputWrapper
from trezor.messages.TxAckPrevOutputType import TxAckPrevOutputType
from trezor.messages.TxRequest import TxRequest from trezor.messages.TxRequest import TxRequest
from trezor.messages.TxAck import TxAck
from trezor.messages.TransactionType import TransactionType
from trezor.messages.RequestType import TXINPUT, TXOUTPUT, TXMETA from trezor.messages.RequestType import TXINPUT, TXOUTPUT, TXMETA
from trezor.messages.TxRequestDetailsType import TxRequestDetailsType from trezor.messages.TxRequestDetailsType import TxRequestDetailsType
from trezor.messages.TxRequestSerializedType import TxRequestSerializedType from trezor.messages.TxRequestSerializedType import TxRequestSerializedType
@ -36,54 +45,45 @@ class TestSignTxFeeThreshold(unittest.TestCase):
def test_over_fee_threshold(self): def test_over_fee_threshold(self):
coin_bitcoin = coins.by_name('Bitcoin') coin_bitcoin = coins.by_name('Bitcoin')
ptx1 = TransactionType(version=1, lock_time=0, inputs_cnt=2, outputs_cnt=1, extra_data_len=0) ptx1 = TxAckPrevTxType(version=1, lock_time=0, inputs_count=2, outputs_count=1, extra_data_len=0)
pinp1 = TxInputType(script_sig=unhexlify('483045022072ba61305fe7cb542d142b8f3299a7b10f9ea61f6ffaab5dca8142601869d53c0221009a8027ed79eb3b9bc13577ac2853269323434558528c6b6a7e542be46e7e9a820141047a2d177c0f3626fc68c53610b0270fa6156181f46586c679ba6a88b34c6f4874686390b4d92e5769fbb89c8050b984f4ec0b257a0e5c4ff8bd3b035a51709503'), pinp1 = TxAckPrevInputType(script_sig=unhexlify('483045022072ba61305fe7cb542d142b8f3299a7b10f9ea61f6ffaab5dca8142601869d53c0221009a8027ed79eb3b9bc13577ac2853269323434558528c6b6a7e542be46e7e9a820141047a2d177c0f3626fc68c53610b0270fa6156181f46586c679ba6a88b34c6f4874686390b4d92e5769fbb89c8050b984f4ec0b257a0e5c4ff8bd3b035a51709503'),
prev_hash=unhexlify('c16a03f1cf8f99f6b5297ab614586cacec784c2d259af245909dedb0e39eddcf'), prev_hash=unhexlify('c16a03f1cf8f99f6b5297ab614586cacec784c2d259af245909dedb0e39eddcf'),
prev_index=1, prev_index=1)
multisig=None, pinp2 = TxAckPrevInputType(script_sig=unhexlify('48304502200fd63adc8f6cb34359dc6cca9e5458d7ea50376cbd0a74514880735e6d1b8a4c0221008b6ead7fe5fbdab7319d6dfede3a0bc8e2a7c5b5a9301636d1de4aa31a3ee9b101410486ad608470d796236b003635718dfc07c0cac0cfc3bfc3079e4f491b0426f0676e6643a39198e8e7bdaffb94f4b49ea21baa107ec2e237368872836073668214'),
script_type=None,
sequence=None)
pinp2 = TxInputType(script_sig=unhexlify('48304502200fd63adc8f6cb34359dc6cca9e5458d7ea50376cbd0a74514880735e6d1b8a4c0221008b6ead7fe5fbdab7319d6dfede3a0bc8e2a7c5b5a9301636d1de4aa31a3ee9b101410486ad608470d796236b003635718dfc07c0cac0cfc3bfc3079e4f491b0426f0676e6643a39198e8e7bdaffb94f4b49ea21baa107ec2e237368872836073668214'),
prev_hash=unhexlify('1ae39a2f8d59670c8fc61179148a8e61e039d0d9e8ab08610cb69b4a19453eaf'), prev_hash=unhexlify('1ae39a2f8d59670c8fc61179148a8e61e039d0d9e8ab08610cb69b4a19453eaf'),
prev_index=1, prev_index=1)
multisig=None, pout1 = TxAckPrevOutputType(script_pubkey=unhexlify('76a91424a56db43cf6f2b02e838ea493f95d8d6047423188ac'),
script_type=None,
sequence=None)
pout1 = TxOutputBinType(script_pubkey=unhexlify('76a91424a56db43cf6f2b02e838ea493f95d8d6047423188ac'),
amount=390000) amount=390000)
inp1 = TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e inp1 = TxAckInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
# amount=390000, # amount=390000,
prev_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882'), prev_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882'),
prev_index=0, prev_index=0,
amount=None, amount=None)
script_type=None, out1 = TxAckOutputType(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
multisig=None,
sequence=None)
out1 = TxOutputType(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
amount=390000 - 100000, # fee increased to 100000 => too high amount=390000 - 100000, # fee increased to 100000 => too high
multisig=None, multisig=None,
script_type=OutputScriptType.PAYTOADDRESS, script_type=OutputScriptType.PAYTOADDRESS,
address_n=[]) address_n=[])
tx = SignTx(coin_name=None, version=None, lock_time=None, inputs_count=1, outputs_count=1) tx = SignTx(coin_name=None, version=1, lock_time=0, inputs_count=1, outputs_count=1)
messages = [ messages = [
None, None,
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None)), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None)),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
helpers.UiConfirmForeignAddress(address_n=inp1.address_n), helpers.UiConfirmForeignAddress(address_n=inp1.address_n),
True, True,
TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=None), TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=None),
TxAck(tx=ptx1), TxAckPrevMeta(tx=ptx1),
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=None), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=None),
TxAck(tx=TransactionType(inputs=[pinp1])), TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp1)),
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=1, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=None), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=1, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=None),
TxAck(tx=TransactionType(inputs=[pinp2])), TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp2)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=None), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=None),
TxAck(tx=TransactionType(bin_outputs=[pout1])), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=None), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=None),
TxAck(tx=TransactionType(outputs=[out1])), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
helpers.UiConfirmOutput(out1, coin_bitcoin), helpers.UiConfirmOutput(out1, coin_bitcoin),
True, True,
helpers.UiConfirmFeeOverThreshold(100000, coin_bitcoin), helpers.UiConfirmFeeOverThreshold(100000, coin_bitcoin),
@ -98,66 +98,64 @@ class TestSignTxFeeThreshold(unittest.TestCase):
keychain = Keychain([[coin_bitcoin.curve_name]], [root]) keychain = Keychain([[coin_bitcoin.curve_name]], [root])
signer = signing.sign_tx(tx, keychain) signer = signing.sign_tx(tx, keychain)
for request, response in chunks(messages, 2): for request, expected_response in chunks(messages, 2):
self.assertEqual(signer.send(request), response) response = signer.send(request)
if isinstance(response, tuple):
_, response = response
self.assertEqual(response, expected_response)
""" """
def test_under_threshold(self): def test_under_threshold(self):
coin_bitcoin = coins.by_name('Bitcoin') coin_bitcoin = coins.by_name('Bitcoin')
ptx1 = TransactionType(version=1, lock_time=0, inputs_cnt=2, outputs_cnt=1, extra_data_len=0) ptx1 = TxAckPrevTxType(version=1, lock_time=0, inputs_count=2, outputs_count=1, extra_data_len=0)
pinp1 = TxInputType(script_sig=unhexlify('483045022072ba61305fe7cb542d142b8f3299a7b10f9ea61f6ffaab5dca8142601869d53c0221009a8027ed79eb3b9bc13577ac2853269323434558528c6b6a7e542be46e7e9a820141047a2d177c0f3626fc68c53610b0270fa6156181f46586c679ba6a88b34c6f4874686390b4d92e5769fbb89c8050b984f4ec0b257a0e5c4ff8bd3b035a51709503'), pinp1 = TxAckPrevInputType(script_sig=unhexlify('483045022072ba61305fe7cb542d142b8f3299a7b10f9ea61f6ffaab5dca8142601869d53c0221009a8027ed79eb3b9bc13577ac2853269323434558528c6b6a7e542be46e7e9a820141047a2d177c0f3626fc68c53610b0270fa6156181f46586c679ba6a88b34c6f4874686390b4d92e5769fbb89c8050b984f4ec0b257a0e5c4ff8bd3b035a51709503'),
prev_hash=unhexlify('c16a03f1cf8f99f6b5297ab614586cacec784c2d259af245909dedb0e39eddcf'), prev_hash=unhexlify('c16a03f1cf8f99f6b5297ab614586cacec784c2d259af245909dedb0e39eddcf'),
prev_index=1, prev_index=1,
script_type=None, sequence=0xffff_ffff)
multisig=None, pinp2 = TxAckPrevInputType(script_sig=unhexlify('48304502200fd63adc8f6cb34359dc6cca9e5458d7ea50376cbd0a74514880735e6d1b8a4c0221008b6ead7fe5fbdab7319d6dfede3a0bc8e2a7c5b5a9301636d1de4aa31a3ee9b101410486ad608470d796236b003635718dfc07c0cac0cfc3bfc3079e4f491b0426f0676e6643a39198e8e7bdaffb94f4b49ea21baa107ec2e237368872836073668214'),
sequence=None)
pinp2 = TxInputType(script_sig=unhexlify('48304502200fd63adc8f6cb34359dc6cca9e5458d7ea50376cbd0a74514880735e6d1b8a4c0221008b6ead7fe5fbdab7319d6dfede3a0bc8e2a7c5b5a9301636d1de4aa31a3ee9b101410486ad608470d796236b003635718dfc07c0cac0cfc3bfc3079e4f491b0426f0676e6643a39198e8e7bdaffb94f4b49ea21baa107ec2e237368872836073668214'),
prev_hash=unhexlify('1ae39a2f8d59670c8fc61179148a8e61e039d0d9e8ab08610cb69b4a19453eaf'), prev_hash=unhexlify('1ae39a2f8d59670c8fc61179148a8e61e039d0d9e8ab08610cb69b4a19453eaf'),
prev_index=1, prev_index=1,
multisig=None, sequence=0xffff_ffff)
script_type=None, pout1 = TxAckPrevOutputType(script_pubkey=unhexlify('76a91424a56db43cf6f2b02e838ea493f95d8d6047423188ac'),
sequence=None)
pout1 = TxOutputBinType(script_pubkey=unhexlify('76a91424a56db43cf6f2b02e838ea493f95d8d6047423188ac'),
amount=390000) amount=390000)
inp1 = TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e inp1 = TxAckInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
amount=390000, amount=390000,
prev_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882'), prev_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882'),
prev_index=0, prev_index=0,
multisig=None, multisig=None,
script_type=None, sequence=0xffff_ffff)
sequence=None) out1 = TxAckOutputType(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
out1 = TxOutputType(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
amount=390000 - 90000, # fee increased to 90000, slightly less than the threshold amount=390000 - 90000, # fee increased to 90000, slightly less than the threshold
script_type=OutputScriptType.PAYTOADDRESS, script_type=OutputScriptType.PAYTOADDRESS,
multisig=None, multisig=None,
address_n=[]) address_n=[])
tx = SignTx(coin_name=None, version=None, lock_time=None, inputs_count=1, outputs_count=1) tx = SignTx(coin_name=None, version=1, lock_time=0, inputs_count=1, outputs_count=1)
messages = [ messages = [
None, None,
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
helpers.UiConfirmForeignAddress(address_n=inp1.address_n), helpers.UiConfirmForeignAddress(address_n=inp1.address_n),
True, True,
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(outputs=[out1])), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
helpers.UiConfirmOutput(out1, coin_bitcoin), helpers.UiConfirmOutput(out1, coin_bitcoin),
True, True,
helpers.UiConfirmTotal(300000 + 90000, 90000, coin_bitcoin), helpers.UiConfirmTotal(300000 + 90000, 90000, coin_bitcoin),
True, True,
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=EMPTY_SERIALIZED),
TxAck(tx=ptx1), TxAckPrevMeta(tx=ptx1),
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[pinp1])), TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp1)),
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=1, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=1, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[pinp2])), TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp2)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(bin_outputs=[pout1])), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout1)),
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(serialized_tx=unhexlify('0100000001'))), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(serialized_tx=unhexlify('0100000001'))),
] ]
@ -168,6 +166,8 @@ class TestSignTxFeeThreshold(unittest.TestCase):
signer = bitcoin.Bitcoin(tx, keychain, coin_bitcoin, approver).signer() signer = bitcoin.Bitcoin(tx, keychain, coin_bitcoin, approver).signer()
for request, response in chunks(messages, 2): for request, response in chunks(messages, 2):
res = signer.send(request) res = signer.send(request)
if isinstance(res, tuple):
_, res = res
self.assertEqual(res, response) self.assertEqual(res, response)

View File

@ -3,12 +3,21 @@ from common import *
from trezor.utils import chunks from trezor.utils import chunks
from trezor.crypto import bip32, bip39 from trezor.crypto import bip32, bip39
from trezor.messages.SignTx import SignTx from trezor.messages.SignTx import SignTx
from trezor.messages.TxInputType import TxInputType from trezor.messages.TxAckInput import TxAckInput
from trezor.messages.TxOutputType import TxOutputType from trezor.messages.TxAckInputWrapper import TxAckInputWrapper
from trezor.messages.TxOutputBinType import TxOutputBinType from trezor.messages.TxAckInputType import TxAckInputType
from trezor.messages.TxAckOutput import TxAckOutput
from trezor.messages.TxAckOutputWrapper import TxAckOutputWrapper
from trezor.messages.TxAckOutputType import TxAckOutputType
from trezor.messages.TxAckPrevMeta import TxAckPrevMeta
from trezor.messages.TxAckPrevTxType import TxAckPrevTxType
from trezor.messages.TxAckPrevInput import TxAckPrevInput
from trezor.messages.TxAckPrevInputWrapper import TxAckPrevInputWrapper
from trezor.messages.TxAckPrevInputType import TxAckPrevInputType
from trezor.messages.TxAckPrevOutput import TxAckPrevOutput
from trezor.messages.TxAckPrevOutputWrapper import TxAckPrevOutputWrapper
from trezor.messages.TxAckPrevOutputType import TxAckPrevOutputType
from trezor.messages.TxRequest import TxRequest from trezor.messages.TxRequest import TxRequest
from trezor.messages.TxAck import TxAck
from trezor.messages.TransactionType import TransactionType
from trezor.messages.RequestType import TXINPUT, TXOUTPUT, TXMETA, TXFINISHED from trezor.messages.RequestType import TXINPUT, TXOUTPUT, TXMETA, TXFINISHED
from trezor.messages.TxRequestDetailsType import TxRequestDetailsType from trezor.messages.TxRequestDetailsType import TxRequestDetailsType
from trezor.messages.TxRequestSerializedType import TxRequestSerializedType from trezor.messages.TxRequestSerializedType import TxRequestSerializedType
@ -33,43 +42,38 @@ class TestSignTx(unittest.TestCase):
coin_bitcoin = coins.by_name('Bitcoin') coin_bitcoin = coins.by_name('Bitcoin')
ptx1 = TransactionType(version=1, lock_time=0, inputs_cnt=2, outputs_cnt=1, extra_data_len=0) ptx1 = TxAckPrevTxType(version=1, lock_time=0, inputs_count=2, outputs_count=1, extra_data_len=0)
pinp1 = TxInputType(script_sig=unhexlify('483045022072ba61305fe7cb542d142b8f3299a7b10f9ea61f6ffaab5dca8142601869d53c0221009a8027ed79eb3b9bc13577ac2853269323434558528c6b6a7e542be46e7e9a820141047a2d177c0f3626fc68c53610b0270fa6156181f46586c679ba6a88b34c6f4874686390b4d92e5769fbb89c8050b984f4ec0b257a0e5c4ff8bd3b035a51709503'), pinp1 = TxAckPrevInputType(script_sig=unhexlify('483045022072ba61305fe7cb542d142b8f3299a7b10f9ea61f6ffaab5dca8142601869d53c0221009a8027ed79eb3b9bc13577ac2853269323434558528c6b6a7e542be46e7e9a820141047a2d177c0f3626fc68c53610b0270fa6156181f46586c679ba6a88b34c6f4874686390b4d92e5769fbb89c8050b984f4ec0b257a0e5c4ff8bd3b035a51709503'),
prev_hash=unhexlify('c16a03f1cf8f99f6b5297ab614586cacec784c2d259af245909dedb0e39eddcf'), prev_hash=unhexlify('c16a03f1cf8f99f6b5297ab614586cacec784c2d259af245909dedb0e39eddcf'),
prev_index=1, prev_index=1,
amount=200000, sequence=0xffff_ffff)
script_type=None, pinp2 = TxAckPrevInputType(script_sig=unhexlify('48304502200fd63adc8f6cb34359dc6cca9e5458d7ea50376cbd0a74514880735e6d1b8a4c0221008b6ead7fe5fbdab7319d6dfede3a0bc8e2a7c5b5a9301636d1de4aa31a3ee9b101410486ad608470d796236b003635718dfc07c0cac0cfc3bfc3079e4f491b0426f0676e6643a39198e8e7bdaffb94f4b49ea21baa107ec2e237368872836073668214'),
sequence=None)
pinp2 = TxInputType(script_sig=unhexlify('48304502200fd63adc8f6cb34359dc6cca9e5458d7ea50376cbd0a74514880735e6d1b8a4c0221008b6ead7fe5fbdab7319d6dfede3a0bc8e2a7c5b5a9301636d1de4aa31a3ee9b101410486ad608470d796236b003635718dfc07c0cac0cfc3bfc3079e4f491b0426f0676e6643a39198e8e7bdaffb94f4b49ea21baa107ec2e237368872836073668214'),
prev_hash=unhexlify('1ae39a2f8d59670c8fc61179148a8e61e039d0d9e8ab08610cb69b4a19453eaf'), prev_hash=unhexlify('1ae39a2f8d59670c8fc61179148a8e61e039d0d9e8ab08610cb69b4a19453eaf'),
prev_index=1, prev_index=1,
amount=200000, sequence=0xffff_ffff)
script_type=None, pout1 = TxAckPrevOutputType(script_pubkey=unhexlify('76a91424a56db43cf6f2b02e838ea493f95d8d6047423188ac'),
sequence=None)
pout1 = TxOutputBinType(script_pubkey=unhexlify('76a91424a56db43cf6f2b02e838ea493f95d8d6047423188ac'),
amount=200000 + 200000 - 10000) amount=200000 + 200000 - 10000)
inp1 = TxInputType(address_n=[44 | 0x80000000, 0 | 0x80000000, 0 | 0x80000000, 0, 0], inp1 = TxAckInputType(address_n=[44 | 0x80000000, 0 | 0x80000000, 0 | 0x80000000, 0, 0],
# amount=390000, # amount=390000,
prev_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882'), prev_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882'),
prev_index=0, prev_index=0,
amount=390000, amount=390000,
script_type=None,
multisig=None, multisig=None,
sequence=None) sequence=0xffff_ffff)
out1 = TxOutputType(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1', out1 = TxAckOutputType(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
amount=390000 - 10000, amount=390000 - 10000,
script_type=OutputScriptType.PAYTOADDRESS, script_type=OutputScriptType.PAYTOADDRESS,
multisig=None) multisig=None)
tx = SignTx(coin_name=None, version=None, lock_time=None, inputs_count=1, outputs_count=1) tx = SignTx(coin_name=None, version=1, lock_time=0, inputs_count=1, outputs_count=1)
messages = [ messages = [
None, None,
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(outputs=[out1])), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
helpers.UiConfirmOutput(out1, coin_bitcoin), helpers.UiConfirmOutput(out1, coin_bitcoin),
True, True,
helpers.UiConfirmTotal(380000 + 10000, 10000, coin_bitcoin), helpers.UiConfirmTotal(380000 + 10000, 10000, coin_bitcoin),
@ -77,24 +81,24 @@ class TestSignTx(unittest.TestCase):
# ButtonRequest(code=ButtonRequest_ConfirmOutput), # ButtonRequest(code=ButtonRequest_ConfirmOutput),
# ButtonRequest(code=ButtonRequest_SignTx), # ButtonRequest(code=ButtonRequest_SignTx),
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=EMPTY_SERIALIZED),
TxAck(tx=ptx1), TxAckPrevMeta(tx=ptx1),
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[pinp1])), TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp1)),
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=1, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=1, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[pinp2])), TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp2)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(bin_outputs=[pout1])), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout1)),
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(serialized_tx=unhexlify('0100000001'))), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(serialized_tx=unhexlify('0100000001'))),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(outputs=[out1])), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(
signature_index=0, signature_index=0,
signature=unhexlify('30440220198146fa987da8d78c4c7a471614fceb54d161ede244412f3369f436a7aec386022066bbede7644baa38abbdb4b1f3037f8db225c04e107099b625339a55614c3db3'), signature=unhexlify('30440220198146fa987da8d78c4c7a471614fceb54d161ede244412f3369f436a7aec386022066bbede7644baa38abbdb4b1f3037f8db225c04e107099b625339a55614c3db3'),
serialized_tx=unhexlify('82488650ef25a58fef6788bd71b8212038d7f2bbe4750bc7bcb44701e85ef6d5000000006a4730440220198146fa987da8d78c4c7a471614fceb54d161ede244412f3369f436a7aec386022066bbede7644baa38abbdb4b1f3037f8db225c04e107099b625339a55614c3db30121027a4cebff51c97c047637cda66838e8b64421a4af6bf8ef3c99717f92d09b3c1dffffffff01'))), serialized_tx=unhexlify('82488650ef25a58fef6788bd71b8212038d7f2bbe4750bc7bcb44701e85ef6d5000000006a4730440220198146fa987da8d78c4c7a471614fceb54d161ede244412f3369f436a7aec386022066bbede7644baa38abbdb4b1f3037f8db225c04e107099b625339a55614c3db30121027a4cebff51c97c047637cda66838e8b64421a4af6bf8ef3c99717f92d09b3c1dffffffff01'))),
TxAck(tx=TransactionType(outputs=[out1])), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType( TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType(
signature_index=None, signature_index=None,
signature=None, signature=None,
@ -110,6 +114,8 @@ class TestSignTx(unittest.TestCase):
for request, response in chunks(messages, 2): for request, response in chunks(messages, 2):
res = signer.send(request) res = signer.send(request)
if isinstance(res, tuple):
_, res = res
self.assertEqual(res, response) self.assertEqual(res, response)
with self.assertRaises(StopIteration): with self.assertRaises(StopIteration):

View File

@ -3,12 +3,21 @@ from common import *
from trezor.utils import chunks from trezor.utils import chunks
from trezor.crypto import bip39 from trezor.crypto import bip39
from trezor.messages.SignTx import SignTx from trezor.messages.SignTx import SignTx
from trezor.messages.TxInputType import TxInputType from trezor.messages.TxAckInput import TxAckInput
from trezor.messages.TxOutputType import TxOutputType from trezor.messages.TxAckInputWrapper import TxAckInputWrapper
from trezor.messages.TxOutputBinType import TxOutputBinType from trezor.messages.TxAckInputType import TxAckInputType
from trezor.messages.TxAckOutput import TxAckOutput
from trezor.messages.TxAckOutputWrapper import TxAckOutputWrapper
from trezor.messages.TxAckOutputType import TxAckOutputType
from trezor.messages.TxAckPrevMeta import TxAckPrevMeta
from trezor.messages.TxAckPrevTxType import TxAckPrevTxType
from trezor.messages.TxAckPrevInput import TxAckPrevInput
from trezor.messages.TxAckPrevInputWrapper import TxAckPrevInputWrapper
from trezor.messages.TxAckPrevInputType import TxAckPrevInputType
from trezor.messages.TxAckPrevOutput import TxAckPrevOutput
from trezor.messages.TxAckPrevOutputWrapper import TxAckPrevOutputWrapper
from trezor.messages.TxAckPrevOutputType import TxAckPrevOutputType
from trezor.messages.TxRequest import TxRequest from trezor.messages.TxRequest import TxRequest
from trezor.messages.TxAck import TxAck
from trezor.messages.TransactionType import TransactionType
from trezor.messages.RequestType import TXINPUT, TXOUTPUT, TXMETA, TXFINISHED from trezor.messages.RequestType import TXINPUT, TXOUTPUT, TXMETA, TXFINISHED
from trezor.messages.TxRequestDetailsType import TxRequestDetailsType from trezor.messages.TxRequestDetailsType import TxRequestDetailsType
from trezor.messages.TxRequestSerializedType import TxRequestSerializedType from trezor.messages.TxRequestSerializedType import TxRequestSerializedType
@ -34,61 +43,56 @@ class TestSignTx_GRS(unittest.TestCase):
coin = coins.by_name('Groestlcoin') coin = coins.by_name('Groestlcoin')
ptx1 = TransactionType(version=1, lock_time=2160993, inputs_cnt=1, outputs_cnt=1, extra_data_len=0) ptx1 = TxAckPrevTxType(version=1, lock_time=2160993, inputs_count=1, outputs_count=1, extra_data_len=0)
pinp1 = TxInputType(script_sig=unhexlify('48304502210096a287593b1212a188e778596eb8ecd4cc169b93a4d115226460d8e3deae431c02206c78ec09b3df977f04a6df5eb53181165c4ea5a0b35f826551349130f879d6b8012102cf5126ff54e38a80a919579d7091cafe24840eab1d30fe2b4d59bdd9d267cad8'), pinp1 = TxAckPrevInputType(script_sig=unhexlify('48304502210096a287593b1212a188e778596eb8ecd4cc169b93a4d115226460d8e3deae431c02206c78ec09b3df977f04a6df5eb53181165c4ea5a0b35f826551349130f879d6b8012102cf5126ff54e38a80a919579d7091cafe24840eab1d30fe2b4d59bdd9d267cad8'),
prev_hash=unhexlify('7dc74a738c50c2ae1228ce9890841e5355fd6d7f2c1367e0a74403ab60db3224'), prev_hash=unhexlify('7dc74a738c50c2ae1228ce9890841e5355fd6d7f2c1367e0a74403ab60db3224'),
prev_index=0, prev_index=0,
script_type=None,
sequence=4294967294) sequence=4294967294)
pout1 = TxOutputBinType(script_pubkey=unhexlify('76a914172b4e06e9b7881a48d2ee8062b495d0b2517fe888ac'), pout1 = TxAckPrevOutputType(script_pubkey=unhexlify('76a914172b4e06e9b7881a48d2ee8062b495d0b2517fe888ac'),
amount=210016) amount=210016)
inp1 = TxInputType(address_n=[44 | 0x80000000, 17 | 0x80000000, 0 | 0x80000000, 0, 2], # FXHDsC5ZqWQHkDmShzgRVZ1MatpWhwxTAA inp1 = TxAckInputType(address_n=[44 | 0x80000000, 17 | 0x80000000, 0 | 0x80000000, 0, 2], # FXHDsC5ZqWQHkDmShzgRVZ1MatpWhwxTAA
prev_hash=unhexlify('cb74c8478c5814742c87cffdb4a21231869888f8042fb07a90e015a9db1f9d4a'), prev_hash=unhexlify('cb74c8478c5814742c87cffdb4a21231869888f8042fb07a90e015a9db1f9d4a'),
prev_index=0, prev_index=0,
amount=210016, amount=210016)
script_type=None, out1 = TxAckOutputType(address='FtM4zAn9aVYgHgxmamWBgWPyZsb6RhvkA9',
multisig=None,
sequence=None)
out1 = TxOutputType(address='FtM4zAn9aVYgHgxmamWBgWPyZsb6RhvkA9',
amount=210016 - 192, amount=210016 - 192,
script_type=OutputScriptType.PAYTOADDRESS, script_type=OutputScriptType.PAYTOADDRESS,
address_n=[], address_n=[])
multisig=None) tx = SignTx(coin_name='Groestlcoin', version=1, lock_time=0, inputs_count=1, outputs_count=1)
tx = SignTx(coin_name='Groestlcoin', version=None, lock_time=None, inputs_count=1, outputs_count=1)
messages = [ messages = [
None, None,
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(outputs=[out1])), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
helpers.UiConfirmOutput(out1, coin), helpers.UiConfirmOutput(out1, coin),
True, True,
helpers.UiConfirmTotal(210016, 192, coin), helpers.UiConfirmTotal(210016, 192, coin),
True, True,
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=unhexlify('cb74c8478c5814742c87cffdb4a21231869888f8042fb07a90e015a9db1f9d4a')), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=unhexlify('cb74c8478c5814742c87cffdb4a21231869888f8042fb07a90e015a9db1f9d4a')), serialized=EMPTY_SERIALIZED),
TxAck(tx=ptx1), TxAckPrevMeta(tx=ptx1),
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=unhexlify('cb74c8478c5814742c87cffdb4a21231869888f8042fb07a90e015a9db1f9d4a')), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=unhexlify('cb74c8478c5814742c87cffdb4a21231869888f8042fb07a90e015a9db1f9d4a')), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(inputs=[pinp1])), TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=unhexlify('cb74c8478c5814742c87cffdb4a21231869888f8042fb07a90e015a9db1f9d4a')), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=unhexlify('cb74c8478c5814742c87cffdb4a21231869888f8042fb07a90e015a9db1f9d4a')), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(bin_outputs=[pout1])), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout1)),
# ButtonRequest(code=ButtonRequest_ConfirmOutput), # ButtonRequest(code=ButtonRequest_ConfirmOutput),
# ButtonRequest(code=ButtonRequest_SignTx), # ButtonRequest(code=ButtonRequest_SignTx),
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(
signature_index=None, signature_index=None,
signature=None, signature=None,
serialized_tx=unhexlify('0100000001'))), serialized_tx=unhexlify('0100000001'))),
TxAck(tx=TransactionType(inputs=[inp1])), TxAckInput(tx=TxAckInputWrapper(input=inp1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAck(tx=TransactionType(outputs=[out1])), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(
signature_index=0, signature_index=0,
signature=unhexlify('304402201fb96d20d0778f54520ab59afe70d5fb20e500ecc9f02281cf57934e8029e8e10220383d5a3e80f2e1eb92765b6da0f23d454aecbd8236f083d483e9a74302368761'), signature=unhexlify('304402201fb96d20d0778f54520ab59afe70d5fb20e500ecc9f02281cf57934e8029e8e10220383d5a3e80f2e1eb92765b6da0f23d454aecbd8236f083d483e9a74302368761'),
serialized_tx=unhexlify('4a9d1fdba915e0907ab02f04f88898863112a2b4fdcf872c7414588c47c874cb000000006a47304402201fb96d20d0778f54520ab59afe70d5fb20e500ecc9f02281cf57934e8029e8e10220383d5a3e80f2e1eb92765b6da0f23d454aecbd8236f083d483e9a7430236876101210331693756f749180aeed0a65a0fab0625a2250bd9abca502282a4cf0723152e67ffffffff01'))), serialized_tx=unhexlify('4a9d1fdba915e0907ab02f04f88898863112a2b4fdcf872c7414588c47c874cb000000006a47304402201fb96d20d0778f54520ab59afe70d5fb20e500ecc9f02281cf57934e8029e8e10220383d5a3e80f2e1eb92765b6da0f23d454aecbd8236f083d483e9a7430236876101210331693756f749180aeed0a65a0fab0625a2250bd9abca502282a4cf0723152e67ffffffff01'))),
TxAck(tx=TransactionType(outputs=[out1])), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType( TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType(
signature_index=None, signature_index=None,
signature=None, signature=None,
@ -101,8 +105,11 @@ class TestSignTx_GRS(unittest.TestCase):
keychain = Keychain(seed, coin.curve_name, ns) keychain = Keychain(seed, coin.curve_name, ns)
approver = BasicApprover(tx, coin) approver = BasicApprover(tx, coin)
signer = bitcoinlike.Bitcoinlike(tx, keychain, coin, approver).signer() signer = bitcoinlike.Bitcoinlike(tx, keychain, coin, approver).signer()
for request, response in chunks(messages, 2): for request, expected_response in chunks(messages, 2):
self.assertEqual(signer.send(request), response) response = signer.send(request)
if isinstance(response, tuple):
_, response = response
self.assertEqual(response, expected_response)
with self.assertRaises(StopIteration): with self.assertRaises(StopIteration):
signer.send(None) signer.send(None)

View File

@ -1,7 +1,7 @@
from common import * from common import *
from trezor.messages.TxOutputType import TxOutputType from trezor.messages.TxAckInputType import TxAckInputType
from trezor.messages.SignTx import SignTx from trezor.messages.TxAckOutputType import TxAckOutputType
from trezor.messages import OutputScriptType from trezor.messages import OutputScriptType
from trezor.crypto import bip32, bip39 from trezor.crypto import bip32, bip39
@ -18,15 +18,15 @@ class TestCalculateTxWeight(unittest.TestCase):
coin = coins.by_name('Bitcoin') coin = coins.by_name('Bitcoin')
seed = bip39.seed(' '.join(['all'] * 12), '') seed = bip39.seed(' '.join(['all'] * 12), '')
inp1 = TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e inp1 = TxAckInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
# amount=390000, # amount=390000,
prev_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882'), prev_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882'),
prev_index=0, prev_index=0,
amount=None, amount=None,
script_type=InputScriptType.SPENDADDRESS, script_type=InputScriptType.SPENDADDRESS,
sequence=None, sequence=0xffff_ffff,
multisig=None) multisig=None)
out1 = TxOutputType(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1', out1 = TxAckOutputType(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
amount=390000 - 10000, amount=390000 - 10000,
script_type=OutputScriptType.PAYTOADDRESS, script_type=OutputScriptType.PAYTOADDRESS,
address_n=[], address_n=[],
@ -46,7 +46,7 @@ class TestCalculateTxWeight(unittest.TestCase):
coin = coins.by_name('Testnet') coin = coins.by_name('Testnet')
seed = bip39.seed(' '.join(['all'] * 12), '') seed = bip39.seed(' '.join(['all'] * 12), '')
inp1 = TxInputType( inp1 = TxAckInputType(
# 49'/1'/0'/1/0" - 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX # 49'/1'/0'/1/0" - 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0], address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0],
amount=123456789, amount=123456789,
@ -56,14 +56,14 @@ class TestCalculateTxWeight(unittest.TestCase):
sequence=0xffffffff, sequence=0xffffffff,
multisig=None, multisig=None,
) )
out1 = TxOutputType( out1 = TxAckOutputType(
address='mhRx1CeVfaayqRwq5zgRQmD7W5aWBfD5mC', address='mhRx1CeVfaayqRwq5zgRQmD7W5aWBfD5mC',
amount=12300000, amount=12300000,
script_type=OutputScriptType.PAYTOADDRESS, script_type=OutputScriptType.PAYTOADDRESS,
address_n=[], address_n=[],
multisig=None, multisig=None,
) )
out2 = TxOutputType( out2 = TxAckOutputType(
address='2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX', address='2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX',
script_type=OutputScriptType.PAYTOADDRESS, script_type=OutputScriptType.PAYTOADDRESS,
amount=123456789 - 11000 - 12300000, amount=123456789 - 11000 - 12300000,
@ -86,7 +86,7 @@ class TestCalculateTxWeight(unittest.TestCase):
coin = coins.by_name('Testnet') coin = coins.by_name('Testnet')
seed = bip39.seed(' '.join(['all'] * 12), '') seed = bip39.seed(' '.join(['all'] * 12), '')
inp1 = TxInputType( inp1 = TxAckInputType(
# 49'/1'/0'/0/0" - tb1qqzv60m9ajw8drqulta4ld4gfx0rdh82un5s65s # 49'/1'/0'/0/0" - tb1qqzv60m9ajw8drqulta4ld4gfx0rdh82un5s65s
address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0], address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0],
amount=12300000, amount=12300000,
@ -96,14 +96,14 @@ class TestCalculateTxWeight(unittest.TestCase):
sequence=0xffffffff, sequence=0xffffffff,
multisig=None, multisig=None,
) )
out1 = TxOutputType( out1 = TxAckOutputType(
address='2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp', address='2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp',
amount=5000000, amount=5000000,
script_type=OutputScriptType.PAYTOADDRESS, script_type=OutputScriptType.PAYTOADDRESS,
address_n=[], address_n=[],
multisig=None, multisig=None,
) )
out2 = TxOutputType( out2 = TxAckOutputType(
address='tb1q694ccp5qcc0udmfwgp692u2s2hjpq5h407urtu', address='tb1q694ccp5qcc0udmfwgp692u2s2hjpq5h407urtu',
script_type=OutputScriptType.PAYTOADDRESS, script_type=OutputScriptType.PAYTOADDRESS,
amount=12300000 - 11000 - 5000000, amount=12300000 - 11000 - 5000000,

View File

@ -1,8 +1,8 @@
from common import * from common import *
from trezor.messages import InputScriptType from trezor.messages import InputScriptType
from trezor.messages.SignTx import SignTx from trezor.messages.SignTx import SignTx
from trezor.messages.TxInputType import TxInputType from trezor.messages.TxAckInputType import TxAckInputType
from trezor.messages.TxOutputBinType import TxOutputBinType from trezor.messages.TxAckPrevOutputType import TxAckPrevOutputType
from apps.common import coins from apps.common import coins
from apps.bitcoin.writers import get_tx_hash from apps.bitcoin.writers import get_tx_hash
@ -194,17 +194,19 @@ class TestZcashZip243(unittest.TestCase):
zip243 = Zcashlike(tx, None, coin, BasicApprover(tx, coin)) zip243 = Zcashlike(tx, None, coin, BasicApprover(tx, coin))
for i in v["inputs"]: for i in v["inputs"]:
txi = TxInputType() txi = TxAckInputType(
txi.amount = i["amount"] amount = i["amount"],
txi.prev_hash = unhexlify(i["prevout"][0]) prev_hash = unhexlify(i["prevout"][0]),
txi.prev_index = i["prevout"][1] prev_index = i["prevout"][1],
txi.script_type = i["script_type"] script_type = i["script_type"],
txi.sequence = i["sequence"] sequence = i["sequence"],
)
zip243.hash143_add_input(txi) zip243.hash143_add_input(txi)
for o in v["outputs"]: for o in v["outputs"]:
txo = TxOutputBinType() txo = TxAckPrevOutputType(
txo.amount = o["amount"] amount = o["amount"],
txo.script_pubkey = unhexlify(o["script_pubkey"]) script_pubkey = unhexlify(o["script_pubkey"]),
)
zip243.hash143_add_output(txo, txo.script_pubkey) zip243.hash143_add_output(txo, txo.script_pubkey)
self.assertEqual(hexlify(get_tx_hash(zip243.h_prevouts)), v["prevouts_hash"]) self.assertEqual(hexlify(get_tx_hash(zip243.h_prevouts)), v["prevouts_hash"])

View File

@ -423,8 +423,8 @@ class TestCardanoAddress(unittest.TestCase):
test_vectors = [ test_vectors = [
# network id, pointer, expected result # network id, pointer, expected result
(network_ids.MAINNET, CardanoBlockchainPointerType(1, 2, 3), "addr1gx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzerspqgpse33frd"), (network_ids.MAINNET, CardanoBlockchainPointerType(block_index=1, tx_index=2, certificate_index=3), "addr1gx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzerspqgpse33frd"),
(network_ids.TESTNET, CardanoBlockchainPointerType(24157, 177, 42), "addr_test1gz2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer5ph3wczvf2pfz4ly") (network_ids.TESTNET, CardanoBlockchainPointerType(block_index=24157, tx_index=177, certificate_index=42), "addr_test1gz2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer5ph3wczvf2pfz4ly")
] ]
for network_id, pointer, expected_address in test_vectors: for network_id, pointer, expected_address in test_vectors:
@ -457,7 +457,7 @@ class TestCardanoAddress(unittest.TestCase):
address_parameters = CardanoAddressParametersType( address_parameters = CardanoAddressParametersType(
address_type=CardanoAddressType.POINTER, address_type=CardanoAddressType.POINTER,
address_n=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0], address_n=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0],
certificate_pointer=CardanoBlockchainPointerType(None, 2, 3), certificate_pointer=CardanoBlockchainPointerType(block_index=None, tx_index=2, certificate_index=3),
) )
derive_human_readable_address(keychain, address_parameters, 0, 0) derive_human_readable_address(keychain, address_parameters, 0, 0)
@ -466,7 +466,7 @@ class TestCardanoAddress(unittest.TestCase):
address_parameters = CardanoAddressParametersType( address_parameters = CardanoAddressParametersType(
address_type=CardanoAddressType.POINTER, address_type=CardanoAddressType.POINTER,
address_n=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0], address_n=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0],
certificate_pointer=CardanoBlockchainPointerType(1, None, 3), certificate_pointer=CardanoBlockchainPointerType(block_index=1, tx_index=None, certificate_index=3),
) )
derive_human_readable_address(keychain, address_parameters, 0, 0) derive_human_readable_address(keychain, address_parameters, 0, 0)
@ -475,7 +475,7 @@ class TestCardanoAddress(unittest.TestCase):
address_parameters = CardanoAddressParametersType( address_parameters = CardanoAddressParametersType(
address_type=CardanoAddressType.POINTER, address_type=CardanoAddressType.POINTER,
address_n=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0], address_n=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0],
certificate_pointer=CardanoBlockchainPointerType(1, 2, None), certificate_pointer=CardanoBlockchainPointerType(block_index=1, tx_index=2, certificate_index=None),
) )
derive_human_readable_address(keychain, address_parameters, 0, 0) derive_human_readable_address(keychain, address_parameters, 0, 0)
@ -534,7 +534,7 @@ class TestCardanoAddress(unittest.TestCase):
address_parameters = CardanoAddressParametersType( address_parameters = CardanoAddressParametersType(
address_type=CardanoAddressType.POINTER, address_type=CardanoAddressType.POINTER,
address_n=[44 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0], address_n=[44 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0],
certificate_pointer=CardanoBlockchainPointerType(0, 0, 0) certificate_pointer=CardanoBlockchainPointerType(block_index=0, tx_index=0, certificate_index=0)
) )
derive_human_readable_address(keychain, address_parameters, 0, 0) derive_human_readable_address(keychain, address_parameters, 0, 0)

View File

@ -72,13 +72,13 @@ class TestCardanoSignTransaction(unittest.TestCase):
for output_path, input_paths in outputs_to_show: for output_path, input_paths in outputs_to_show:
inputs = [ inputs = [
CardanoTxInputType(input_path, "", 0) for input_path in input_paths CardanoTxInputType(address_n=input_path, prev_hash=b"", prev_index=0) for input_path in input_paths
] ]
self.assertTrue(_should_hide_output(output_path, inputs)) self.assertTrue(_should_hide_output(output_path, inputs))
for output_path, input_paths in outputs_to_hide: for output_path, input_paths in outputs_to_hide:
inputs = [ inputs = [
CardanoTxInputType(input_path, "", 0) for input_path in input_paths CardanoTxInputType(address_n=input_path, prev_hash=b"", prev_index=0) for input_path in input_paths
] ]
self.assertFalse(_should_hide_output(output_path, inputs)) self.assertFalse(_should_hide_output(output_path, inputs))

View File

@ -24,49 +24,120 @@ class TestRippleSerializer(unittest.TestCase):
def test_transactions(self): def test_transactions(self):
# from https://github.com/miracle2k/ripple-python # from https://github.com/miracle2k/ripple-python
source_address = "r3P9vH81KBayazSTrQj6S25jW6kDb779Gi" source_address = "r3P9vH81KBayazSTrQj6S25jW6kDb779Gi"
payment = RipplePayment(200000000, "r3kmLJN5D28dHuH8vZNUZpMC43pEHpaocV") payment = RipplePayment(
common = RippleSignTx(None, 10, None, 1, None, payment) amount=200000000, destination="r3kmLJN5D28dHuH8vZNUZpMC43pEHpaocV"
self.assertEqual(serialize(common, source_address), unhexlify( )
"120000240000000161400000000bebc20068400000000000000a811450f97a072f1c4357f1ad84566a609479d927c9428314550fc62003e785dc231a1058a05e56e3f09cf4e6" common = RippleSignTx(
)) address_n=None,
fee=10,
flags=None,
sequence=1,
last_ledger_sequence=None,
payment=payment,
)
self.assertEqual(
serialize(common, source_address),
unhexlify(
"120000240000000161400000000bebc20068400000000000000a811450f97a072f1c4357f1ad84566a609479d927c9428314550fc62003e785dc231a1058a05e56e3f09cf4e6"
),
)
source_address = "r3kmLJN5D28dHuH8vZNUZpMC43pEHpaocV" source_address = "r3kmLJN5D28dHuH8vZNUZpMC43pEHpaocV"
payment = RipplePayment(1, "r3P9vH81KBayazSTrQj6S25jW6kDb779Gi") payment = RipplePayment(
common = RippleSignTx(None, 99, None, 99, None, payment) amount=1, destination="r3P9vH81KBayazSTrQj6S25jW6kDb779Gi"
self.assertEqual(serialize(common, source_address), unhexlify( )
"12000024000000636140000000000000016840000000000000638114550fc62003e785dc231a1058a05e56e3f09cf4e6831450f97a072f1c4357f1ad84566a609479d927c942" common = RippleSignTx(
)) address_n=None,
fee=99,
flags=None,
sequence=99,
last_ledger_sequence=None,
payment=payment,
)
self.assertEqual(
serialize(common, source_address),
unhexlify(
"12000024000000636140000000000000016840000000000000638114550fc62003e785dc231a1058a05e56e3f09cf4e6831450f97a072f1c4357f1ad84566a609479d927c942"
),
)
# https://github.com/ripple/ripple-binary-codec/blob/4581f1b41e712f545ba08be15e188a557c731ecf/test/fixtures/data-driven-tests.json#L1579 # https://github.com/ripple/ripple-binary-codec/blob/4581f1b41e712f545ba08be15e188a557c731ecf/test/fixtures/data-driven-tests.json#L1579
source_address = "r9TeThyi5xiuUUrFjtPKZiHcDxs7K9H6Rb" source_address = "r9TeThyi5xiuUUrFjtPKZiHcDxs7K9H6Rb"
payment = RipplePayment(25000000, "r4BPgS7DHebQiU31xWELvZawwSG2fSPJ7C") payment = RipplePayment(
common = RippleSignTx(None, 10, 0, 2, None, payment) amount=25000000, destination="r4BPgS7DHebQiU31xWELvZawwSG2fSPJ7C"
self.assertEqual(serialize(common, source_address), unhexlify( )
"120000220000000024000000026140000000017d784068400000000000000a81145ccb151f6e9d603f394ae778acf10d3bece874f68314e851bbbe79e328e43d68f43445368133df5fba5a" common = RippleSignTx(
)) address_n=None,
fee=10,
flags=0,
sequence=2,
last_ledger_sequence=None,
payment=payment,
)
self.assertEqual(
serialize(common, source_address),
unhexlify(
"120000220000000024000000026140000000017d784068400000000000000a81145ccb151f6e9d603f394ae778acf10d3bece874f68314e851bbbe79e328e43d68f43445368133df5fba5a"
),
)
# https://github.com/ripple/ripple-binary-codec/blob/4581f1b41e712f545ba08be15e188a557c731ecf/test/fixtures/data-driven-tests.json#L1651 # https://github.com/ripple/ripple-binary-codec/blob/4581f1b41e712f545ba08be15e188a557c731ecf/test/fixtures/data-driven-tests.json#L1651
source_address = "rGWTUVmm1fB5QUjMYn8KfnyrFNgDiD9H9e" source_address = "rGWTUVmm1fB5QUjMYn8KfnyrFNgDiD9H9e"
payment = RipplePayment(200000, "rw71Qs1UYQrSQ9hSgRohqNNQcyjCCfffkQ") payment = RipplePayment(
common = RippleSignTx(None, 15, 0, 144, None, payment) amount=200000, destination="rw71Qs1UYQrSQ9hSgRohqNNQcyjCCfffkQ"
)
common = RippleSignTx(
address_n=None,
fee=15,
flags=0,
sequence=144,
last_ledger_sequence=None,
payment=payment,
)
# 201b005ee9ba removed from the test vector because last ledger sequence is not supported # 201b005ee9ba removed from the test vector because last ledger sequence is not supported
self.assertEqual(serialize(common, source_address), unhexlify( self.assertEqual(
"12000022000000002400000090614000000000030d4068400000000000000f8114aa1bd19d9e87be8069fdbf6843653c43837c03c6831467fe6ec28e0464dd24fb2d62a492aac697cfad02" serialize(common, source_address),
)) unhexlify(
"12000022000000002400000090614000000000030d4068400000000000000f8114aa1bd19d9e87be8069fdbf6843653c43837c03c6831467fe6ec28e0464dd24fb2d62a492aac697cfad02"
),
)
# https://github.com/ripple/ripple-binary-codec/blob/4581f1b41e712f545ba08be15e188a557c731ecf/test/fixtures/data-driven-tests.json#L1732 # https://github.com/ripple/ripple-binary-codec/blob/4581f1b41e712f545ba08be15e188a557c731ecf/test/fixtures/data-driven-tests.json#L1732
source_address = "r4BPgS7DHebQiU31xWELvZawwSG2fSPJ7C" source_address = "r4BPgS7DHebQiU31xWELvZawwSG2fSPJ7C"
payment = RipplePayment(25000000, "rBqSFEFg2B6GBMobtxnU1eLA1zbNC9NDGM", 4146942154) payment = RipplePayment(
common = RippleSignTx(None, 12, 0, 1, None, payment) amount=25000000,
self.assertEqual(serialize(common, source_address), unhexlify( destination="rBqSFEFg2B6GBMobtxnU1eLA1zbNC9NDGM",
"120000220000000024000000012ef72d50ca6140000000017d784068400000000000000c8114e851bbbe79e328e43d68f43445368133df5fba5a831476dac5e814cd4aa74142c3ab45e69a900e637aa2" destination_tag=4146942154,
)) )
common = RippleSignTx(
address_n=None,
fee=12,
flags=0,
sequence=1,
last_ledger_sequence=None,
payment=payment,
)
self.assertEqual(
serialize(common, source_address),
unhexlify(
"120000220000000024000000012ef72d50ca6140000000017d784068400000000000000c8114e851bbbe79e328e43d68f43445368133df5fba5a831476dac5e814cd4aa74142c3ab45e69a900e637aa2"
),
)
def test_transactions_for_signing(self): def test_transactions_for_signing(self):
# https://github.com/ripple/ripple-binary-codec/blob/4581f1b41e712f545ba08be15e188a557c731ecf/test/signing-data-encoding-test.js # https://github.com/ripple/ripple-binary-codec/blob/4581f1b41e712f545ba08be15e188a557c731ecf/test/signing-data-encoding-test.js
source_address = "r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ" source_address = "r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ"
payment = RipplePayment(1000, "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh") payment = RipplePayment(
common = RippleSignTx(None, 10, 2147483648, 1, None, payment) amount=1000, destination="rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh"
)
common = RippleSignTx(
address_n=None,
fee=10,
flags=2147483648,
sequence=1,
last_ledger_sequence=None,
payment=payment,
)
tx = serialize( tx = serialize(
common, common,
@ -83,15 +154,18 @@ class TestRippleSerializer(unittest.TestCase):
self.assertEqual(tx[12:17], unhexlify("2400000001")) # sequence self.assertEqual(tx[12:17], unhexlify("2400000001")) # sequence
self.assertEqual(tx[17:26], unhexlify("6140000000000003e8")) # amount self.assertEqual(tx[17:26], unhexlify("6140000000000003e8")) # amount
self.assertEqual(tx[26:35], unhexlify("68400000000000000a")) # fee self.assertEqual(tx[26:35], unhexlify("68400000000000000a")) # fee
self.assertEqual(tx[35:70], unhexlify( self.assertEqual(
"7321ed5f5ac8b98974a3ca843326d9b88cebd0560177b973ee0b149f782cfaa06dc66a" tx[35:70],
)) # signing pub key unhexlify(
self.assertEqual(tx[70:92], unhexlify( "7321ed5f5ac8b98974a3ca843326d9b88cebd0560177b973ee0b149f782cfaa06dc66a"
"81145b812c9d57731e27a2da8b1830195f88ef32a3b6" ),
)) # account ) # signing pub key
self.assertEqual(tx[92:114], unhexlify( self.assertEqual(
"8314b5f762798a53d543a014caf8b297cff8f2f937e8" tx[70:92], unhexlify("81145b812c9d57731e27a2da8b1830195f88ef32a3b6")
)) # destination ) # account
self.assertEqual(
tx[92:114], unhexlify("8314b5f762798a53d543a014caf8b297cff8f2f937e8")
) # destination
self.assertEqual(len(tx[114:]), 0) # that's it self.assertEqual(len(tx[114:]), 0) # that's it