diff --git a/tests/device_tests/test_msg_signtx.py b/tests/device_tests/test_msg_signtx.py index 597512d3ce9..5ab8d7553c3 100644 --- a/tests/device_tests/test_msg_signtx.py +++ b/tests/device_tests/test_msg_signtx.py @@ -16,7 +16,7 @@ import pytest -from trezorlib import btc, device, messages as proto +from trezorlib import btc, device, messages from trezorlib.exceptions import TrezorFailure from trezorlib.tools import H_, parse_path, tx_hash @@ -24,7 +24,7 @@ from ..tx_cache import TxCache from .signtx import request_finished, request_input, request_meta, request_output -B = proto.ButtonRequestType +B = messages.ButtonRequestType TX_CACHE_TESTNET = TxCache("Testnet") TX_CACHE_MAINNET = TxCache("Bitcoin") @@ -85,17 +85,17 @@ def test_one_one_fee(self, client): # tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882 # input 0: 0.0039 BTC - inp1 = proto.TxInputType( + inp1 = messages.TxInputType( address_n=parse_path("44h/0h/0h/0/0"), # amount=390000, prev_hash=TXHASH_d5f65e, prev_index=0, ) - out1 = proto.TxOutputType( + out1 = messages.TxOutputType( address="1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1", amount=390000 - 10000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) with client: @@ -107,8 +107,8 @@ def test_one_one_fee(self, client): request_input(1, TXHASH_d5f65e), request_output(0, TXHASH_d5f65e), request_output(0), - proto.ButtonRequest(code=B.ConfirmOutput), - proto.ButtonRequest(code=B.SignTx), + messages.ButtonRequest(code=B.ConfirmOutput), + messages.ButtonRequest(code=B.SignTx), request_input(0), request_output(0), request_output(0), @@ -130,23 +130,23 @@ def test_testnet_one_two_fee(self, client): # tx: e5040e1bc1ae7667ffb9e5248e90b2fb93cd9150234151ce90e14ab2f5933bcd # input 0: 0.31 BTC - inp1 = proto.TxInputType( + inp1 = messages.TxInputType( address_n=parse_path("44'/1'/0'/0/0"), # amount=31000000, prev_hash=TXHASH_e5040e, prev_index=0, ) - out1 = proto.TxOutputType( + out1 = messages.TxOutputType( address="msj42CCGruhRsFrGATiUuh25dtxYtnpbTx", amount=30090000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) - out2 = proto.TxOutputType( + out2 = messages.TxOutputType( address_n=parse_path("44'/1'/0'/1/0"), amount=900000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) with client: @@ -158,9 +158,9 @@ def test_testnet_one_two_fee(self, client): request_output(0, TXHASH_e5040e), request_output(1, TXHASH_e5040e), request_output(0), - proto.ButtonRequest(code=B.ConfirmOutput), + messages.ButtonRequest(code=B.ConfirmOutput), request_output(1), - proto.ButtonRequest(code=B.SignTx), + messages.ButtonRequest(code=B.SignTx), request_input(0), request_output(0), request_output(1), @@ -181,23 +181,23 @@ def test_testnet_one_two_fee(self, client): def test_testnet_fee_high_warning(self, client): # tx: 6f90f3c7cbec2258b0971056ef3fe34128dbde30daa9c0639a898f9977299d54 # input 1: 10.00000000 BTC - inp1 = proto.TxInputType( + inp1 = messages.TxInputType( address_n=parse_path("44'/1'/0'/0/0"), # amount=1000000000, prev_hash=TXHASH_6f90f3, prev_index=1, ) - out1 = proto.TxOutputType( + out1 = messages.TxOutputType( address="mfiGQVPcRcaEvQPYDErR34DcCovtxYvUUV", amount=1000000000 - 500000000 - 8000000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) - out2 = proto.TxOutputType( + out2 = messages.TxOutputType( address_n=parse_path("44'/1'/0'/1/0"), amount=500000000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) with client: @@ -210,10 +210,10 @@ def test_testnet_fee_high_warning(self, client): request_output(0, TXHASH_6f90f3), request_output(1, TXHASH_6f90f3), request_output(0), - proto.ButtonRequest(code=B.ConfirmOutput), + messages.ButtonRequest(code=B.ConfirmOutput), request_output(1), - proto.ButtonRequest(code=B.FeeOverThreshold), - proto.ButtonRequest(code=B.SignTx), + messages.ButtonRequest(code=B.FeeOverThreshold), + messages.ButtonRequest(code=B.SignTx), request_input(0), request_output(0), request_output(1), @@ -235,23 +235,23 @@ def test_testnet_fee_high_warning(self, client): def test_testnet_fee_high_hardfail(self, client): # tx: 6f90f3c7cbec2258b0971056ef3fe34128dbde30daa9c0639a898f9977299d54 # input 1: 10.00000000 BTC - inp1 = proto.TxInputType( + inp1 = messages.TxInputType( address_n=parse_path("44'/1'/0'/0/0"), # amount=1000000000, prev_hash=TXHASH_6f90f3, prev_index=1, ) - out1 = proto.TxOutputType( + out1 = messages.TxOutputType( address="mfiGQVPcRcaEvQPYDErR34DcCovtxYvUUV", amount=1000000000 - 500000000 - 80000000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) - out2 = proto.TxOutputType( + out2 = messages.TxOutputType( address_n=parse_path("44'/1'/0'/1/0"), amount=500000000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) with pytest.raises(TrezorFailure, match="fee is unexpectedly large"): @@ -265,7 +265,7 @@ def test_testnet_fee_high_hardfail(self, client): client.watch_layout() client.set_input_flow(input_flow_record(client, responses)) - device.apply_settings(client, safety_checks=proto.SafetyCheckLevel.Prompt) + device.apply_settings(client, safety_checks=messages.SafetyCheckLevel.Prompt) _, serialized_tx = btc.sign_tx( client, "Testnet", [inp1], [out1, out2], prev_txes=TX_CACHE_TESTNET ) @@ -279,7 +279,7 @@ def test_testnet_fee_high_hardfail(self, client): def test_one_two_fee(self, client): # tx: c275c333fd1b36bef4af316226c66a8b3693fbfcc081a5e16a2ae5fcb09e92bf - inp1 = proto.TxInputType( + inp1 = messages.TxInputType( address_n=parse_path( "m/44'/0'/0'/0/5" ), # 1GA9u9TfCG7SWmKCveBumdA1TZpfom6ZdJ @@ -288,18 +288,18 @@ def test_one_two_fee(self, client): prev_index=1, ) - out1 = proto.TxOutputType( + out1 = messages.TxOutputType( address_n=parse_path( "m/44'/0'/0'/1/3" ), # 1EcL6AyfQTyWKGvXwNSfsWoYnD3whzVFdu amount=30000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) - out2 = proto.TxOutputType( + out2 = messages.TxOutputType( address="1Up15Msx4sbvUCGm8Xgo2Zp5FQim3wE59", amount=10000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) with client: @@ -312,8 +312,8 @@ def test_one_two_fee(self, client): request_output(1, TXHASH_50f6f1), request_output(0), request_output(1), - proto.ButtonRequest(code=B.ConfirmOutput), - proto.ButtonRequest(code=B.SignTx), + messages.ButtonRequest(code=B.ConfirmOutput), + messages.ButtonRequest(code=B.SignTx), request_input(0), request_output(0), request_output(1), @@ -335,29 +335,29 @@ def test_one_three_fee(self, client): # tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882 # input 0: 0.0039 BTC - inp1 = proto.TxInputType( + inp1 = messages.TxInputType( address_n=parse_path("44'/0'/0'/0/0"), # amount=390000, prev_hash=TXHASH_d5f65e, prev_index=0, ) - out1 = proto.TxOutputType( + out1 = messages.TxOutputType( address="1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1", amount=390000 - 80000 - 12000 - 10000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) - out2 = proto.TxOutputType( + out2 = messages.TxOutputType( address="13uaUYn6XAooo88QvAqAVsiVvr2mAXutqP", amount=12000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) - out3 = proto.TxOutputType( + out3 = messages.TxOutputType( address_n=parse_path("44'/0'/0'/1/0"), amount=80000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) with client: @@ -369,11 +369,11 @@ def test_one_three_fee(self, client): request_input(1, TXHASH_d5f65e), request_output(0, TXHASH_d5f65e), request_output(0), - proto.ButtonRequest(code=B.ConfirmOutput), + messages.ButtonRequest(code=B.ConfirmOutput), request_output(1), - proto.ButtonRequest(code=B.ConfirmOutput), + messages.ButtonRequest(code=B.ConfirmOutput), request_output(2), - proto.ButtonRequest(code=B.SignTx), + messages.ButtonRequest(code=B.SignTx), request_input(0), request_output(0), request_output(1), @@ -403,30 +403,30 @@ def test_two_two(self, client): # tx: 58497a7757224d1ff1941488d23087071103e5bf855f4c1c44e5c8d9d82ca46e # input 1: 0.0011 BTC - inp1 = proto.TxInputType( + inp1 = messages.TxInputType( address_n=parse_path("44h/0h/0h/0/0"), # amount=100000, prev_hash=TXHASH_c6be22, prev_index=1, ) - inp2 = proto.TxInputType( + inp2 = messages.TxInputType( address_n=parse_path("44h/0h/0h/0/1"), # amount=110000, prev_hash=TXHASH_58497a, prev_index=1, ) - out1 = proto.TxOutputType( + out1 = messages.TxOutputType( address="15Jvu3nZNP7u2ipw2533Q9VVgEu2Lu9F2B", amount=210000 - 100000 - 10000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) - out2 = proto.TxOutputType( + out2 = messages.TxOutputType( address_n=parse_path("44h/0h/0h/1/0"), amount=100000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) with client: @@ -443,9 +443,9 @@ def test_two_two(self, client): request_output(0, TXHASH_58497a), request_output(1, TXHASH_58497a), request_output(0), - proto.ButtonRequest(code=B.ConfirmOutput), + messages.ButtonRequest(code=B.ConfirmOutput), request_output(1), - proto.ButtonRequest(code=B.SignTx), + messages.ButtonRequest(code=B.SignTx), request_input(0), request_input(1), request_output(0), @@ -483,16 +483,16 @@ def test_lots_of_inputs(self, client): inputs = [] for i in range(100): inputs.append( - proto.TxInputType( + messages.TxInputType( address_n=parse_path(f"44h/0h/0h/0/{i}"), prev_hash=TXHASH_4a7b7e, prev_index=i, ) ) - out = proto.TxOutputType( + out = messages.TxOutputType( address="19dvDdyxxptP9dGvozYe8BP6tgFV9L4jg5", amount=100 * 26000 - 15 * 10000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) _, serialized_tx = btc.sign_tx( client, "Bitcoin", inputs, [out], prev_txes=TX_CACHE_MAINNET @@ -512,14 +512,14 @@ def test_lots_of_outputs(self, client): # tx: 39a29e954977662ab3879c66fb251ef753e0912223a83d1dcb009111d28265e5 # index 1: 0.0254 BTC - inp1 = proto.TxInputType( + inp1 = messages.TxInputType( address_n=parse_path("44h/0h/1h/0/0"), # amount=100000, prev_hash=TXHASH_c63e24, prev_index=1, ) - inp2 = proto.TxInputType( + inp2 = messages.TxInputType( address_n=parse_path("44h/0h/1h/0/1"), # amount=2540000, prev_hash=TXHASH_39a29e, @@ -529,10 +529,10 @@ def test_lots_of_outputs(self, client): outputs = [] cnt = 255 for _ in range(cnt): - out = proto.TxOutputType( + out = messages.TxOutputType( address="1NwN6UduuVkJi6sw3gSiKZaCY5rHgVXC2h", amount=(100000 + 2540000 - 39000) // cnt, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) outputs.append(out) @@ -554,14 +554,14 @@ def test_lots_of_change(self, client): # tx: 39a29e954977662ab3879c66fb251ef753e0912223a83d1dcb009111d28265e5 # index 1: 0.0254 BTC - inp1 = proto.TxInputType( + inp1 = messages.TxInputType( address_n=parse_path("44h/0h/1h/0/0"), # amount=100000, prev_hash=TXHASH_c63e24, prev_index=1, ) - inp2 = proto.TxInputType( + inp2 = messages.TxInputType( address_n=parse_path("44h/0h/1h/0/1"), # amount=2540000, prev_hash=TXHASH_39a29e, @@ -569,19 +569,19 @@ def test_lots_of_change(self, client): ) outputs = [ - proto.TxOutputType( + messages.TxOutputType( address="1NwN6UduuVkJi6sw3gSiKZaCY5rHgVXC2h", amount=500000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) ] cnt = 20 for i in range(cnt): - out = proto.TxOutputType( + out = messages.TxOutputType( address_n=parse_path(f"44h/0h/1h/1/{i}"), amount=(100000 + 2540000 - 500000 - 39000) // cnt, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) outputs.append(out) @@ -602,12 +602,12 @@ def test_lots_of_change(self, client): request_output(0, TXHASH_39a29e), request_output(1, TXHASH_39a29e), request_output(0), - proto.ButtonRequest(code=B.ConfirmOutput), + messages.ButtonRequest(code=B.ConfirmOutput), ] + request_change_outputs + [ - proto.ButtonRequest(code=B.SignTx), - proto.ButtonRequest(code=B.SignTx), + messages.ButtonRequest(code=B.SignTx), + messages.ButtonRequest(code=B.SignTx), request_input(0), request_input(1), request_output(0), @@ -633,17 +633,17 @@ def test_fee_high_warning(self, client): # tx: 1570416eb4302cf52979afd5e6909e37d8fdd874301f7cc87e547e509cb1caa6 # input 0: 1.0 BTC - inp1 = proto.TxInputType( + inp1 = messages.TxInputType( address_n=parse_path("44h/0h/0h/0/0"), # amount=100000000, prev_hash=TXHASH_157041, prev_index=0, ) - out1 = proto.TxOutputType( + out1 = messages.TxOutputType( address="1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1", amount=100000000 - 510000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) with client: @@ -655,9 +655,9 @@ def test_fee_high_warning(self, client): request_output(0, TXHASH_157041), request_output(1, TXHASH_157041), request_output(0), - proto.ButtonRequest(code=B.ConfirmOutput), - proto.ButtonRequest(code=B.FeeOverThreshold), - proto.ButtonRequest(code=B.SignTx), + messages.ButtonRequest(code=B.ConfirmOutput), + messages.ButtonRequest(code=B.FeeOverThreshold), + messages.ButtonRequest(code=B.SignTx), request_input(0), request_output(0), request_output(0), @@ -678,17 +678,17 @@ def test_fee_high_hardfail(self, client): # tx: 1570416eb4302cf52979afd5e6909e37d8fdd874301f7cc87e547e509cb1caa6 # input 0: 1.0 BTC - inp1 = proto.TxInputType( + inp1 = messages.TxInputType( address_n=parse_path("44h/0h/0h/0/0"), # amount=100000000, prev_hash=TXHASH_157041, prev_index=0, ) - out1 = proto.TxOutputType( + out1 = messages.TxOutputType( address="1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1", amount=100000000 - 5100000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) with client: @@ -700,8 +700,8 @@ def test_fee_high_hardfail(self, client): request_output(0, TXHASH_157041), request_output(1, TXHASH_157041), request_output(0), - proto.ButtonRequest(code=B.ConfirmOutput), - proto.Failure(code=proto.FailureType.DataError), + messages.ButtonRequest(code=B.ConfirmOutput), + messages.Failure(code=messages.FailureType.DataError), ] ) with pytest.raises(TrezorFailure, match="fee is unexpectedly large"): @@ -715,7 +715,7 @@ def test_fee_high_hardfail(self, client): client.watch_layout() client.set_input_flow(input_flow_record(client, responses)) - device.apply_settings(client, safety_checks=proto.SafetyCheckLevel.Prompt) + device.apply_settings(client, safety_checks=messages.SafetyCheckLevel.Prompt) _, serialized_tx = btc.sign_tx( client, "Bitcoin", [inp1], [out1], prev_txes=TX_CACHE_MAINNET ) @@ -730,17 +730,17 @@ def test_not_enough_funds(self, client): # tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882 # input 0: 0.0039 BTC - inp1 = proto.TxInputType( + inp1 = messages.TxInputType( address_n=parse_path("44h/0h/0h/0/0"), # amount=390000, prev_hash=TXHASH_d5f65e, prev_index=0, ) - out1 = proto.TxOutputType( + out1 = messages.TxOutputType( address="1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1", amount=400000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) with client: @@ -752,8 +752,8 @@ def test_not_enough_funds(self, client): request_input(1, TXHASH_d5f65e), request_output(0, TXHASH_d5f65e), request_output(0), - proto.ButtonRequest(code=B.ConfirmOutput), - proto.Failure(code=proto.FailureType.NotEnoughFunds), + messages.ButtonRequest(code=B.ConfirmOutput), + messages.Failure(code=messages.FailureType.NotEnoughFunds), ] ) with pytest.raises(TrezorFailure, match="NotEnoughFunds"): @@ -762,17 +762,17 @@ def test_not_enough_funds(self, client): ) def test_p2sh(self, client): - inp1 = proto.TxInputType( + inp1 = messages.TxInputType( address_n=parse_path("44h/0h/0h/0/0"), # amount=400000, prev_hash=TXHASH_54aa56, prev_index=1, ) - out1 = proto.TxOutputType( + out1 = messages.TxOutputType( address="3DKGE1pvPpBAgZj94MbCinwmksewUNNYVR", # p2sh amount=400000 - 10000, - script_type=proto.OutputScriptType.PAYTOSCRIPTHASH, + script_type=messages.OutputScriptType.PAYTOSCRIPTHASH, ) with client: @@ -784,8 +784,8 @@ def test_p2sh(self, client): request_output(0, TXHASH_54aa56), request_output(1, TXHASH_54aa56), request_output(0), - proto.ButtonRequest(code=B.ConfirmOutput), - proto.ButtonRequest(code=B.SignTx), + messages.ButtonRequest(code=B.ConfirmOutput), + messages.ButtonRequest(code=B.SignTx), request_input(0), request_output(0), request_output(0), @@ -807,16 +807,16 @@ def test_testnet_big_amount(self, client): # tx: 2bac7ad1dec654579a71ea9555463f63ac7b7df9d8ba67b4682bba4e514d0f0c:1 # input 1: 411102528330 Satoshi - inp1 = proto.TxInputType( + inp1 = messages.TxInputType( address_n=parse_path("m/44'/1'/0'/0/0"), amount=411102528330, prev_hash=TXHASH_2bac7a, prev_index=1, ) - out1 = proto.TxOutputType( + out1 = messages.TxOutputType( address="mopZWqZZyQc3F2Sy33cvDtJchSAMsnLi7b", # seed allallall, bip32: m/44'/1'/0'/0/1 amount=411102528330, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) _, serialized_tx = btc.sign_tx( client, "Testnet", [inp1], [out1], prev_txes=TX_CACHE_TESTNET @@ -828,30 +828,30 @@ def test_testnet_big_amount(self, client): @pytest.mark.setup_client(mnemonic=MNEMONIC12) def test_attack_change_outputs(self, client): - inp1 = proto.TxInputType( + inp1 = messages.TxInputType( address_n=parse_path("44h/0h/0h/0/0"), # amount=100000, prev_hash=TXHASH_c6be22, prev_index=1, ) - inp2 = proto.TxInputType( + inp2 = messages.TxInputType( address_n=parse_path("44h/0h/0h/0/1"), # amount=110000, prev_hash=TXHASH_58497a, prev_index=1, ) - out1 = proto.TxOutputType( + out1 = messages.TxOutputType( address="15Jvu3nZNP7u2ipw2533Q9VVgEu2Lu9F2B", amount=210000 - 100000 - 10000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) - out2 = proto.TxOutputType( + out2 = messages.TxOutputType( address_n=parse_path("44h/0h/0h/1/0"), amount=100000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) # Test if the transaction can be signed normally @@ -878,7 +878,7 @@ def attack_processor(msg): return msg # Set up attack processors - client.set_filter(proto.TxAck, attack_processor) + client.set_filter(messages.TxAck, attack_processor) with pytest.raises( TrezorFailure, match="Transaction has changed during signing" @@ -898,23 +898,23 @@ def test_attack_modify_change_address(self, client): # tx: e5040e1bc1ae7667ffb9e5248e90b2fb93cd9150234151ce90e14ab2f5933bcd # input 0: 0.31 BTC - inp1 = proto.TxInputType( + inp1 = messages.TxInputType( address_n=parse_path("44'/1'/0'/0/0"), # amount=31000000, prev_hash=TXHASH_e5040e, prev_index=0, ) - out1 = proto.TxOutputType( + out1 = messages.TxOutputType( address="msj42CCGruhRsFrGATiUuh25dtxYtnpbTx", amount=30090000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) - out2 = proto.TxOutputType( + out2 = messages.TxOutputType( address_n=parse_path("44'/1'/0'/1/0"), amount=900000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) run_attack = False @@ -931,7 +931,7 @@ def attack_processor(msg): return msg # Set up attack processors - client.set_filter(proto.TxAck, attack_processor) + client.set_filter(messages.TxAck, attack_processor) with pytest.raises( TrezorFailure, match="Transaction has changed during signing" @@ -941,24 +941,24 @@ def attack_processor(msg): ) def test_attack_change_input_address(self, client): - inp1 = proto.TxInputType( + inp1 = messages.TxInputType( address_n=parse_path("44'/1'/4'/0/0"), # moUJnmge8SRXuediK7bW6t4YfrPqbE6hD7 prev_hash=TXHASH_d2dcda, prev_index=1, - script_type=proto.InputScriptType.SPENDADDRESS, + script_type=messages.InputScriptType.SPENDADDRESS, ) - out1 = proto.TxOutputType( + out1 = messages.TxOutputType( address="mwue7mokpBRAsJtHqEMcRPanYBmsSmYKvY", amount=100000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) - out2 = proto.TxOutputType( + out2 = messages.TxOutputType( address_n=parse_path("44'/1'/4'/1/0"), amount=123400000 - 5000 - 100000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) # Test if the transaction can be signed normally @@ -983,7 +983,7 @@ def attack_processor(msg): return msg - client.set_filter(proto.TxAck, attack_processor) + client.set_filter(messages.TxAck, attack_processor) # Now run the attack, must trigger the exception with client: client.set_expected_responses( @@ -994,11 +994,11 @@ def attack_processor(msg): request_output(0, TXHASH_d2dcda), request_output(1, TXHASH_d2dcda), request_output(0), - proto.ButtonRequest(code=B.ConfirmOutput), + messages.ButtonRequest(code=B.ConfirmOutput), request_output(1), - proto.ButtonRequest(code=B.SignTx), + messages.ButtonRequest(code=B.SignTx), request_input(0), - proto.Failure(code=proto.FailureType.ProcessError), + messages.Failure(code=messages.FailureType.ProcessError), ] ) # Now run the attack, must trigger the exception @@ -1007,7 +1007,7 @@ def attack_processor(msg): client, "Testnet", [inp1], [out1, out2], prev_txes=TX_CACHE_TESTNET, ) - assert exc.value.code == proto.FailureType.ProcessError + assert exc.value.code == messages.FailureType.ProcessError if client.features.model == "1": assert exc.value.message.endswith("Failed to compile input") else: @@ -1016,17 +1016,17 @@ def attack_processor(msg): ) def test_spend_coinbase(self, client): - inp1 = proto.TxInputType( + inp1 = messages.TxInputType( address_n=parse_path("44h/1h/0h/0/0"), # amount=390000, prev_hash=TXHASH_d6da21, prev_index=0, ) - out1 = proto.TxOutputType( + out1 = messages.TxOutputType( address="mm6FM31rM5Vc3sw5D7kztiBg3jHUzyqF1g", amount=2500278230 - 10000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) with client: @@ -1037,8 +1037,8 @@ def test_spend_coinbase(self, client): request_input(0, TXHASH_d6da21), request_output(0, TXHASH_d6da21), request_output(0), - proto.ButtonRequest(code=B.ConfirmOutput), - proto.ButtonRequest(code=B.SignTx), + messages.ButtonRequest(code=B.ConfirmOutput), + messages.ButtonRequest(code=B.SignTx), request_input(0), request_output(0), request_output(0), @@ -1060,29 +1060,29 @@ def test_two_changes(self, client): # tx: e5040e1bc1ae7667ffb9e5248e90b2fb93cd9150234151ce90e14ab2f5933bcd # input 0: 0.31 BTC - inp1 = proto.TxInputType( + inp1 = messages.TxInputType( address_n=parse_path("44'/1'/0'/0/0"), # amount=31000000, prev_hash=TXHASH_e5040e, prev_index=0, ) - out1 = proto.TxOutputType( + out1 = messages.TxOutputType( address="msj42CCGruhRsFrGATiUuh25dtxYtnpbTx", amount=30090000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) - out_change1 = proto.TxOutputType( + out_change1 = messages.TxOutputType( address_n=parse_path("44'/1'/0'/1/0"), amount=900000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) - out_change2 = proto.TxOutputType( + out_change2 = messages.TxOutputType( address_n=parse_path("44'/1'/0'/1/1"), amount=10000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) with client: @@ -1094,10 +1094,10 @@ def test_two_changes(self, client): request_output(0, TXHASH_e5040e), request_output(1, TXHASH_e5040e), request_output(0), - proto.ButtonRequest(code=B.ConfirmOutput), + messages.ButtonRequest(code=B.ConfirmOutput), request_output(1), request_output(2), - proto.ButtonRequest(code=B.SignTx), + messages.ButtonRequest(code=B.SignTx), request_input(0), request_output(0), request_output(1), @@ -1122,24 +1122,24 @@ def test_change_on_main_chain_allowed(self, client): # tx: e5040e1bc1ae7667ffb9e5248e90b2fb93cd9150234151ce90e14ab2f5933bcd # input 0: 0.31 BTC - inp1 = proto.TxInputType( + inp1 = messages.TxInputType( address_n=parse_path("44'/1'/0'/0/0"), # amount=31000000, prev_hash=TXHASH_e5040e, prev_index=0, ) - out1 = proto.TxOutputType( + out1 = messages.TxOutputType( address="msj42CCGruhRsFrGATiUuh25dtxYtnpbTx", amount=30090000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) # change on main chain is allowed => treated as a change - out_change = proto.TxOutputType( + out_change = messages.TxOutputType( address_n=parse_path("44'/1'/0'/0/0"), amount=900000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) with client: @@ -1151,9 +1151,9 @@ def test_change_on_main_chain_allowed(self, client): request_output(0, TXHASH_e5040e), request_output(1, TXHASH_e5040e), request_output(0), - proto.ButtonRequest(code=B.ConfirmOutput), + messages.ButtonRequest(code=B.ConfirmOutput), request_output(1), - proto.ButtonRequest(code=B.SignTx), + messages.ButtonRequest(code=B.SignTx), request_input(0), request_output(0), request_output(1), @@ -1179,22 +1179,22 @@ def test_not_enough_vouts(self, client): assert len(prev_tx.bin_outputs) == 2 # vout[0] and vout[1] exist - inp0 = proto.TxInputType( + inp0 = messages.TxInputType( address_n=parse_path("44h/0h/0h/0/0"), prev_hash=TXHASH_157041, prev_index=0 ) - inp1 = proto.TxInputType( + inp1 = messages.TxInputType( address_n=parse_path("44h/0h/0h/0/1"), prev_hash=TXHASH_157041, prev_index=1 ) # vout[2] does not exist - inp2 = proto.TxInputType( + inp2 = messages.TxInputType( address_n=parse_path("44h/0h/0h/1/0"), prev_hash=TXHASH_157041, prev_index=2 ) # try to spend the sum of existing vouts - out1 = proto.TxOutputType( + out1 = messages.TxOutputType( address="1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1", amount=220160000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) with pytest.raises( @@ -1220,13 +1220,13 @@ def test_not_enough_vouts(self, client): ) @pytest.mark.skip_ui def test_prevtx_forbidden_fields(self, client, field, value): - inp0 = proto.TxInputType( + inp0 = messages.TxInputType( address_n=parse_path("44h/0h/0h/0/0"), prev_hash=TXHASH_157041, prev_index=0 ) - out1 = proto.TxOutputType( + out1 = messages.TxOutputType( address="1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1", amount=1000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) prev_tx = TX_CACHE_MAINNET[TXHASH_157041] @@ -1245,16 +1245,16 @@ def test_prevtx_forbidden_fields(self, client, field, value): ) @pytest.mark.skip_ui def test_signtx_forbidden_fields(self, client, field, value): - inp0 = proto.TxInputType( + inp0 = messages.TxInputType( address_n=parse_path("44h/0h/0h/0/0"), prev_hash=TXHASH_157041, prev_index=0 ) - out1 = proto.TxOutputType( + out1 = messages.TxOutputType( address="1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1", amount=1000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) - details = proto.SignTx() + details = messages.SignTx() setattr(details, field, value) name = field.replace("_", " ") with pytest.raises( @@ -1266,7 +1266,7 @@ def test_signtx_forbidden_fields(self, client, field, value): @pytest.mark.parametrize( "script_type", - (proto.InputScriptType.SPENDADDRESS, proto.InputScriptType.EXTERNAL), + (messages.InputScriptType.SPENDADDRESS, messages.InputScriptType.EXTERNAL), ) @pytest.mark.skip_ui def test_incorrect_input_script_type(self, client, script_type): @@ -1275,11 +1275,11 @@ def test_incorrect_input_script_type(self, client, script_type): "030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0" ) - multisig = proto.MultisigRedeemScriptType( + multisig = messages.MultisigRedeemScriptType( m=1, nodes=[ btc.get_public_node(client, address_n, coin_name="Testnet").node, - proto.HDNodeType( + messages.HDNodeType( depth=0, fingerprint=0, child_num=0, @@ -1289,7 +1289,7 @@ def test_incorrect_input_script_type(self, client, script_type): ], address_n=[], ) - inp1 = proto.TxInputType( + inp1 = messages.TxInputType( address_n=address_n, prev_index=1, sequence=0xFFFFFFFF, @@ -1297,16 +1297,16 @@ def test_incorrect_input_script_type(self, client, script_type): multisig=multisig, prev_hash=TXHASH_e5040e, ) - out1 = proto.TxOutputType( + out1 = messages.TxOutputType( address_n=address_n, amount=1000000 - 50000 - 10000, - script_type=proto.OutputScriptType.PAYTOMULTISIG, + script_type=messages.OutputScriptType.PAYTOMULTISIG, multisig=multisig, ) - out2 = proto.TxOutputType( + out2 = messages.TxOutputType( address="mtkyndbpgv1G7nwggwKDVagRpxEJrwwyh6", amount=50000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) with pytest.raises( @@ -1318,7 +1318,7 @@ def test_incorrect_input_script_type(self, client, script_type): @pytest.mark.parametrize( "script_type", - (proto.OutputScriptType.PAYTOADDRESS, proto.OutputScriptType.PAYTOSCRIPTHASH), + (messages.OutputScriptType.PAYTOADDRESS, messages.OutputScriptType.PAYTOSCRIPTHASH), ) @pytest.mark.skip_ui def test_incorrect_output_script_type(self, client, script_type): @@ -1327,11 +1327,11 @@ def test_incorrect_output_script_type(self, client, script_type): "030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0" ) - multisig = proto.MultisigRedeemScriptType( + multisig = messages.MultisigRedeemScriptType( m=1, nodes=[ btc.get_public_node(client, address_n, coin_name="Testnet").node, - proto.HDNodeType( + messages.HDNodeType( depth=0, fingerprint=0, child_num=0, @@ -1341,23 +1341,23 @@ def test_incorrect_output_script_type(self, client, script_type): ], address_n=[], ) - inp1 = proto.TxInputType( + inp1 = messages.TxInputType( address_n=address_n, prev_index=1, sequence=0xFFFFFFFF, - script_type=proto.InputScriptType.SPENDADDRESS, + script_type=messages.InputScriptType.SPENDADDRESS, prev_hash=TXHASH_e5040e, ) - out1 = proto.TxOutputType( + out1 = messages.TxOutputType( address_n=address_n, amount=1000000 - 50000 - 10000, script_type=script_type, # incorrect script type multisig=multisig, ) - out2 = proto.TxOutputType( + out2 = messages.TxOutputType( address="mtkyndbpgv1G7nwggwKDVagRpxEJrwwyh6", amount=50000, - script_type=proto.OutputScriptType.PAYTOADDRESS, + script_type=messages.OutputScriptType.PAYTOADDRESS, ) with pytest.raises(