1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-26 17:38:39 +00:00

tests: add device tests for SignTx with amount_unit

This commit is contained in:
Pavol Rusnak 2021-01-19 11:39:56 +01:00 committed by Tomas Susanka
parent 1d3166017d
commit be2ca4772c
2 changed files with 76 additions and 5 deletions

View File

@ -0,0 +1,71 @@
# This file is part of the Trezor project.
#
# Copyright (C) 2012-2020 SatoshiLabs and contributors
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version 3
# as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the License along with this library.
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
import pytest
from trezorlib import btc, messages
from trezorlib.tools import parse_path
from ..tx_cache import TxCache
TX_API = TxCache("Testnet")
TXHASH_091446 = bytes.fromhex(
"09144602765ce3dd8f4329445b20e3684e948709c5cdcaf12da3bb079c99448a"
)
VECTORS = ( # amount_unit
None,
messages.AmountUnit.BITCOIN,
messages.AmountUnit.MILLIBITCOIN,
messages.AmountUnit.MICROBITCOIN,
messages.AmountUnit.SATOSHI,
)
@pytest.mark.parametrize("amount_unit", VECTORS)
def test_signtx(client, amount_unit):
inp1 = messages.TxInputType(
address_n=parse_path("84'/1'/0'/0/0"),
amount=12300000,
prev_hash=TXHASH_091446,
prev_index=0,
script_type=messages.InputScriptType.SPENDWITNESS,
)
out1 = messages.TxOutputType(
address="2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp",
amount=5000000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address="tb1q694ccp5qcc0udmfwgp692u2s2hjpq5h407urtu",
script_type=messages.OutputScriptType.PAYTOADDRESS,
amount=12300000 - 11000 - 5000000,
)
with client:
_, serialized_tx = btc.sign_tx(
client,
"Testnet",
[inp1],
[out1, out2],
prev_txes=TX_API,
amount_unit=amount_unit,
)
assert (
serialized_tx.hex()
== "010000000001018a44999c07bba32df1cacdc50987944e68e3205b4429438fdde35c76024614090000000000ffffffff02404b4c000000000017a9147a55d61848e77ca266e79a39bfc85c580a6426c987a8386f0000000000160014d16b8c0680c61fc6ed2e407455715055e41052f502473044022073ce72dcf2f6e42eeb44adbe7d5038cf3763f168d1c04bd8b873a19b53331f51022016b051725731e7f53a567021bcd9c370727f551c81e857ebae7c128472119652012103adc58245cf28406af0ef5cc24b8afba7f1be6c72f279b642d85c48798685f86200000000"
)

View File

@ -341,11 +341,11 @@
"test_msg_signtx.py-test_testnet_one_two_fee": "cfd5c83510c044c456622298138e222aee135a6df607bb6e5603228535f0762f", "test_msg_signtx.py-test_testnet_one_two_fee": "cfd5c83510c044c456622298138e222aee135a6df607bb6e5603228535f0762f",
"test_msg_signtx.py-test_two_changes": "832d4b168551c37c9e09cf2ce16fd062d6599bcd0473305f70c5175bd874a920", "test_msg_signtx.py-test_two_changes": "832d4b168551c37c9e09cf2ce16fd062d6599bcd0473305f70c5175bd874a920",
"test_msg_signtx.py-test_two_two": "57707ecbcb77f670148c6076724b3da2e880d27ecf86e29135af4a5aeef6fdbc", "test_msg_signtx.py-test_two_two": "57707ecbcb77f670148c6076724b3da2e880d27ecf86e29135af4a5aeef6fdbc",
"test_msg_signtx_amount_unit.py::test_signtx[0]": "6e2e50b35c091b2b354f902b6870aae7d6c6d922505700ec6c2e7426e71aca5d", "test_msg_signtx_amount_unit.py::test_signtx[0]": "4a77d57ca4d923444fa6c17401b2da63fd00f08f4fdfd95ccaddc1e9d3301333",
"test_msg_signtx_amount_unit.py::test_signtx[1]": "042c9893993bdc7e6a3f3aaaa12c0748ce1b77c38517fb46db8f40012a502ab4", "test_msg_signtx_amount_unit.py::test_signtx[1]": "b3c9e51c66e966d794fcf9f34d5aa2b37ef6ed471188577d103cb1f07ccba37d",
"test_msg_signtx_amount_unit.py::test_signtx[2]": "5c152a03da99bf5c90ef67c84dd8930d10bca736d86d0ceb72c4e415baadd51f", "test_msg_signtx_amount_unit.py::test_signtx[2]": "6a249c3cf9b7c5422c9bac654da33245397e279f408cbf7a74e0f0cbee17db34",
"test_msg_signtx_amount_unit.py::test_signtx[3]": "11d05687339364b3268b64be6f771194c64137efa8e69b8c6197f5e01c960348", "test_msg_signtx_amount_unit.py::test_signtx[3]": "724a19010a863bee2a1445177e827c8f0ebe25a4b9e563e91ab9b287582b6ec6",
"test_msg_signtx_amount_unit.py::test_signtx[None]": "6e2e50b35c091b2b354f902b6870aae7d6c6d922505700ec6c2e7426e71aca5d", "test_msg_signtx_amount_unit.py::test_signtx[None]": "4a77d57ca4d923444fa6c17401b2da63fd00f08f4fdfd95ccaddc1e9d3301333",
"test_msg_signtx_bcash.py-test_attack_change_input": "a03ee0471deeb54d51b73c0fde08795ab0ba8c37daec2d43f5637e705420b435", "test_msg_signtx_bcash.py-test_attack_change_input": "a03ee0471deeb54d51b73c0fde08795ab0ba8c37daec2d43f5637e705420b435",
"test_msg_signtx_bcash.py-test_send_bch_change": "a03ee0471deeb54d51b73c0fde08795ab0ba8c37daec2d43f5637e705420b435", "test_msg_signtx_bcash.py-test_send_bch_change": "a03ee0471deeb54d51b73c0fde08795ab0ba8c37daec2d43f5637e705420b435",
"test_msg_signtx_bcash.py-test_send_bch_external_presigned": "8565118d5647934c84124cb65d34f8299a98631631666dc5b1d02595d462fee0", "test_msg_signtx_bcash.py-test_send_bch_external_presigned": "8565118d5647934c84124cb65d34f8299a98631631666dc5b1d02595d462fee0",