2017-11-23 17:40:27 +00:00
|
|
|
from common import *
|
|
|
|
|
|
|
|
from trezor.utils import chunks
|
|
|
|
from trezor.crypto import bip32, bip39
|
|
|
|
from trezor.messages.SignTx import SignTx
|
|
|
|
from trezor.messages.TxInputType import TxInputType
|
|
|
|
from trezor.messages.TxOutputType import TxOutputType
|
|
|
|
from trezor.messages.TxOutputBinType import TxOutputBinType
|
|
|
|
from trezor.messages.TxRequest import TxRequest
|
|
|
|
from trezor.messages.TxAck import TxAck
|
|
|
|
from trezor.messages.TransactionType import TransactionType
|
2018-02-27 02:05:15 +00:00
|
|
|
from trezor.messages.RequestType import TXINPUT, TXOUTPUT, TXMETA
|
2017-11-23 17:40:27 +00:00
|
|
|
from trezor.messages.TxRequestDetailsType import TxRequestDetailsType
|
|
|
|
from trezor.messages import OutputScriptType
|
|
|
|
|
|
|
|
from apps.common import coins
|
2018-12-04 13:27:06 +00:00
|
|
|
from apps.common.seed import Keychain
|
2018-11-06 14:45:02 +00:00
|
|
|
from apps.wallet.sign_tx import helpers, signing
|
2017-11-23 17:40:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestSignTxFeeThreshold(unittest.TestCase):
|
|
|
|
# pylint: disable=C0301
|
|
|
|
|
2019-05-22 17:29:05 +00:00
|
|
|
# the following test is disabled, because there are not enough
|
|
|
|
# inputs to trigger the excessive threshold warning
|
|
|
|
#
|
|
|
|
# this is being tested in the device test:
|
|
|
|
# test_msg_signtx.test_testnet_fee_too_high
|
|
|
|
|
|
|
|
"""
|
2017-11-23 17:40:27 +00:00
|
|
|
def test_over_fee_threshold(self):
|
|
|
|
coin_bitcoin = coins.by_name('Bitcoin')
|
|
|
|
|
2017-11-29 13:02:42 +00:00
|
|
|
ptx1 = TransactionType(version=1, lock_time=0, inputs_cnt=2, outputs_cnt=1, extra_data_len=0)
|
2017-11-23 17:40:27 +00:00
|
|
|
pinp1 = TxInputType(script_sig=unhexlify('483045022072ba61305fe7cb542d142b8f3299a7b10f9ea61f6ffaab5dca8142601869d53c0221009a8027ed79eb3b9bc13577ac2853269323434558528c6b6a7e542be46e7e9a820141047a2d177c0f3626fc68c53610b0270fa6156181f46586c679ba6a88b34c6f4874686390b4d92e5769fbb89c8050b984f4ec0b257a0e5c4ff8bd3b035a51709503'),
|
|
|
|
prev_hash=unhexlify('c16a03f1cf8f99f6b5297ab614586cacec784c2d259af245909dedb0e39eddcf'),
|
|
|
|
prev_index=1,
|
2018-02-12 11:40:18 +00:00
|
|
|
multisig=None,
|
2017-11-23 17:40:27 +00:00
|
|
|
script_type=None,
|
|
|
|
sequence=None)
|
|
|
|
pinp2 = TxInputType(script_sig=unhexlify('48304502200fd63adc8f6cb34359dc6cca9e5458d7ea50376cbd0a74514880735e6d1b8a4c0221008b6ead7fe5fbdab7319d6dfede3a0bc8e2a7c5b5a9301636d1de4aa31a3ee9b101410486ad608470d796236b003635718dfc07c0cac0cfc3bfc3079e4f491b0426f0676e6643a39198e8e7bdaffb94f4b49ea21baa107ec2e237368872836073668214'),
|
|
|
|
prev_hash=unhexlify('1ae39a2f8d59670c8fc61179148a8e61e039d0d9e8ab08610cb69b4a19453eaf'),
|
|
|
|
prev_index=1,
|
2018-02-12 11:40:18 +00:00
|
|
|
multisig=None,
|
2017-11-23 17:40:27 +00:00
|
|
|
script_type=None,
|
|
|
|
sequence=None)
|
|
|
|
pout1 = TxOutputBinType(script_pubkey=unhexlify('76a91424a56db43cf6f2b02e838ea493f95d8d6047423188ac'),
|
2018-05-09 15:28:13 +00:00
|
|
|
amount=390000)
|
2017-11-23 17:40:27 +00:00
|
|
|
|
|
|
|
inp1 = TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
|
|
|
|
# amount=390000,
|
|
|
|
prev_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882'),
|
|
|
|
prev_index=0,
|
|
|
|
amount=None,
|
|
|
|
script_type=None,
|
|
|
|
multisig=None,
|
|
|
|
sequence=None)
|
|
|
|
out1 = TxOutputType(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
|
|
|
|
amount=390000 - 100000, # fee increased to 100000 => too high
|
2018-02-12 11:40:18 +00:00
|
|
|
multisig=None,
|
2017-11-23 17:40:27 +00:00
|
|
|
script_type=OutputScriptType.PAYTOADDRESS,
|
2018-02-26 13:17:39 +00:00
|
|
|
address_n=[])
|
2017-11-23 17:40:27 +00:00
|
|
|
tx = SignTx(coin_name=None, version=None, lock_time=None, inputs_count=1, outputs_count=1)
|
|
|
|
|
|
|
|
messages = [
|
|
|
|
None,
|
2018-08-30 11:45:09 +00:00
|
|
|
|
2017-11-23 17:40:27 +00:00
|
|
|
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None)),
|
|
|
|
TxAck(tx=TransactionType(inputs=[inp1])),
|
2018-12-04 13:27:06 +00:00
|
|
|
helpers.UiConfirmForeignAddress(address_n=inp1.address_n),
|
2018-08-30 11:45:09 +00:00
|
|
|
True,
|
2017-11-23 17:40:27 +00:00
|
|
|
TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=None),
|
|
|
|
TxAck(tx=ptx1),
|
|
|
|
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=None),
|
|
|
|
TxAck(tx=TransactionType(inputs=[pinp1])),
|
|
|
|
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=1, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=None),
|
|
|
|
TxAck(tx=TransactionType(inputs=[pinp2])),
|
|
|
|
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=None),
|
|
|
|
TxAck(tx=TransactionType(bin_outputs=[pout1])),
|
|
|
|
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=None),
|
|
|
|
TxAck(tx=TransactionType(outputs=[out1])),
|
2018-11-06 14:45:02 +00:00
|
|
|
helpers.UiConfirmOutput(out1, coin_bitcoin),
|
2017-11-23 17:40:27 +00:00
|
|
|
True,
|
2018-11-06 14:45:02 +00:00
|
|
|
helpers.UiConfirmFeeOverThreshold(100000, coin_bitcoin),
|
2017-11-23 17:40:27 +00:00
|
|
|
True,
|
2018-11-06 14:45:02 +00:00
|
|
|
helpers.UiConfirmTotal(290000 + 100000, 100000, coin_bitcoin),
|
2017-11-23 17:40:27 +00:00
|
|
|
True,
|
|
|
|
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=None),
|
|
|
|
]
|
|
|
|
|
|
|
|
seed = bip39.seed('alcohol woman abuse must during monitor noble actual mixed trade anger aisle', '')
|
|
|
|
root = bip32.from_seed(seed, 'secp256k1')
|
|
|
|
|
2018-12-04 13:27:06 +00:00
|
|
|
keychain = Keychain([[coin_bitcoin.curve_name]], [root])
|
|
|
|
signer = signing.sign_tx(tx, keychain)
|
2017-11-23 17:40:27 +00:00
|
|
|
for request, response in chunks(messages, 2):
|
2018-12-04 13:27:06 +00:00
|
|
|
self.assertEqual(signer.send(request), response)
|
2019-05-22 17:29:05 +00:00
|
|
|
"""
|
2017-11-23 17:40:27 +00:00
|
|
|
|
|
|
|
def test_under_threshold(self):
|
|
|
|
coin_bitcoin = coins.by_name('Bitcoin')
|
|
|
|
|
2017-11-29 13:02:42 +00:00
|
|
|
ptx1 = TransactionType(version=1, lock_time=0, inputs_cnt=2, outputs_cnt=1, extra_data_len=0)
|
2017-11-23 17:40:27 +00:00
|
|
|
pinp1 = TxInputType(script_sig=unhexlify('483045022072ba61305fe7cb542d142b8f3299a7b10f9ea61f6ffaab5dca8142601869d53c0221009a8027ed79eb3b9bc13577ac2853269323434558528c6b6a7e542be46e7e9a820141047a2d177c0f3626fc68c53610b0270fa6156181f46586c679ba6a88b34c6f4874686390b4d92e5769fbb89c8050b984f4ec0b257a0e5c4ff8bd3b035a51709503'),
|
|
|
|
prev_hash=unhexlify('c16a03f1cf8f99f6b5297ab614586cacec784c2d259af245909dedb0e39eddcf'),
|
|
|
|
prev_index=1,
|
|
|
|
script_type=None,
|
2018-02-12 11:40:18 +00:00
|
|
|
multisig=None,
|
2017-11-23 17:40:27 +00:00
|
|
|
sequence=None)
|
|
|
|
pinp2 = TxInputType(script_sig=unhexlify('48304502200fd63adc8f6cb34359dc6cca9e5458d7ea50376cbd0a74514880735e6d1b8a4c0221008b6ead7fe5fbdab7319d6dfede3a0bc8e2a7c5b5a9301636d1de4aa31a3ee9b101410486ad608470d796236b003635718dfc07c0cac0cfc3bfc3079e4f491b0426f0676e6643a39198e8e7bdaffb94f4b49ea21baa107ec2e237368872836073668214'),
|
|
|
|
prev_hash=unhexlify('1ae39a2f8d59670c8fc61179148a8e61e039d0d9e8ab08610cb69b4a19453eaf'),
|
|
|
|
prev_index=1,
|
2018-02-12 11:40:18 +00:00
|
|
|
multisig=None,
|
2017-11-23 17:40:27 +00:00
|
|
|
script_type=None,
|
|
|
|
sequence=None)
|
|
|
|
pout1 = TxOutputBinType(script_pubkey=unhexlify('76a91424a56db43cf6f2b02e838ea493f95d8d6047423188ac'),
|
2018-05-09 15:28:13 +00:00
|
|
|
amount=390000)
|
2017-11-23 17:40:27 +00:00
|
|
|
|
|
|
|
inp1 = TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e
|
|
|
|
# amount=390000,
|
|
|
|
prev_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882'),
|
|
|
|
prev_index=0,
|
|
|
|
amount=None,
|
|
|
|
multisig=None,
|
|
|
|
script_type=None,
|
|
|
|
sequence=None)
|
|
|
|
out1 = TxOutputType(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1',
|
|
|
|
amount=390000 - 90000, # fee increased to 90000, slightly less than the threshold
|
|
|
|
script_type=OutputScriptType.PAYTOADDRESS,
|
2018-02-12 11:40:18 +00:00
|
|
|
multisig=None,
|
2018-02-26 13:17:39 +00:00
|
|
|
address_n=[])
|
2017-11-23 17:40:27 +00:00
|
|
|
tx = SignTx(coin_name=None, version=None, lock_time=None, inputs_count=1, outputs_count=1)
|
|
|
|
|
|
|
|
messages = [
|
|
|
|
None,
|
2018-08-30 11:45:09 +00:00
|
|
|
|
2017-11-23 17:40:27 +00:00
|
|
|
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None)),
|
|
|
|
TxAck(tx=TransactionType(inputs=[inp1])),
|
2018-12-04 13:27:06 +00:00
|
|
|
helpers.UiConfirmForeignAddress(address_n=inp1.address_n),
|
2018-08-30 11:45:09 +00:00
|
|
|
True,
|
2017-11-23 17:40:27 +00:00
|
|
|
TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=None),
|
|
|
|
TxAck(tx=ptx1),
|
|
|
|
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=None),
|
|
|
|
TxAck(tx=TransactionType(inputs=[pinp1])),
|
|
|
|
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=1, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=None),
|
|
|
|
TxAck(tx=TransactionType(inputs=[pinp2])),
|
|
|
|
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=None),
|
|
|
|
TxAck(tx=TransactionType(bin_outputs=[pout1])),
|
|
|
|
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=None),
|
|
|
|
TxAck(tx=TransactionType(outputs=[out1])),
|
2018-11-06 14:45:02 +00:00
|
|
|
helpers.UiConfirmOutput(out1, coin_bitcoin),
|
2017-11-23 17:40:27 +00:00
|
|
|
True,
|
2018-11-06 14:45:02 +00:00
|
|
|
helpers.UiConfirmTotal(300000 + 90000, 90000, coin_bitcoin),
|
2017-11-23 17:40:27 +00:00
|
|
|
True,
|
|
|
|
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=None),
|
|
|
|
]
|
|
|
|
|
|
|
|
seed = bip39.seed('alcohol woman abuse must during monitor noble actual mixed trade anger aisle', '')
|
|
|
|
|
2019-07-02 12:19:08 +00:00
|
|
|
keychain = Keychain(seed, [[coin_bitcoin.curve_name]])
|
2018-12-04 13:27:06 +00:00
|
|
|
signer = signing.sign_tx(tx, keychain)
|
2017-11-23 17:40:27 +00:00
|
|
|
for request, response in chunks(messages, 2):
|
2018-12-04 13:27:06 +00:00
|
|
|
self.assertEqual(signer.send(request), response)
|
2017-11-23 17:40:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|