From 169c47217281da7c05323840a747f5c318839d16 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Sat, 7 Aug 2021 14:20:09 +0100 Subject: [PATCH] refactor(tests): modernize test_msg_getaddress_segwit_native --- .../test_msg_getaddress_segwit_native.py | 238 +++++++++--------- tests/ui_tests/fixtures.json | 20 +- 2 files changed, 127 insertions(+), 131 deletions(-) diff --git a/tests/device_tests/test_msg_getaddress_segwit_native.py b/tests/device_tests/test_msg_getaddress_segwit_native.py index 4ea7d5f93..6611fd67a 100644 --- a/tests/device_tests/test_msg_getaddress_segwit_native.py +++ b/tests/device_tests/test_msg_getaddress_segwit_native.py @@ -20,152 +20,138 @@ from trezorlib import btc, messages as proto from trezorlib.exceptions import TrezorFailure from trezorlib.tools import parse_path +VECTORS = ( # coin, path, script_type, address + ( + "Testnet", + "84'/1'/0'/0/0", + proto.InputScriptType.SPENDWITNESS, + "tb1qkvwu9g3k2pdxewfqr7syz89r3gj557l3uuf9r9", + ), + ( + "Testnet", + "84'/1'/0'/1/0", + proto.InputScriptType.SPENDWITNESS, + "tb1qejqxwzfld7zr6mf7ygqy5s5se5xq7vmt96jk9x", + ), + ( + "Bitcoin", + "84'/0'/0'/0/0", + proto.InputScriptType.SPENDWITNESS, + "bc1qannfxke2tfd4l7vhepehpvt05y83v3qsf6nfkk", + ), + ( + "Bitcoin", + "84'/0'/0'/1/0", + proto.InputScriptType.SPENDWITNESS, + "bc1qktmhrsmsenepnnfst8x6j27l0uqv7ggrg8x38q", + ), + pytest.param( + "Groestlcoin", + "84'/17'/0'/0/0", + proto.InputScriptType.SPENDWITNESS, + "grs1qw4teyraux2s77nhjdwh9ar8rl9dt7zww8r6lne", + marks=pytest.mark.altcoin, + ), + pytest.param( + "Elements", + "84'/1'/0'/0/0", + proto.InputScriptType.SPENDWITNESS, + "ert1qkvwu9g3k2pdxewfqr7syz89r3gj557l3xp9k2v", + marks=pytest.mark.altcoin, + ), +) -class TestMsgGetaddressSegwitNative: - def test_show_segwit(self, client): - assert ( - btc.get_address( - client, - "Testnet", - parse_path("84'/1'/0'/0/0"), - True, - None, - script_type=proto.InputScriptType.SPENDWITNESS, - ) - == "tb1qkvwu9g3k2pdxewfqr7syz89r3gj557l3uuf9r9" + +@pytest.mark.parametrize("show_display", (True, False)) +@pytest.mark.parametrize("coin, path, script_type, address", VECTORS) +def test_show_segwit(client, show_display, coin, path, script_type, address): + assert ( + btc.get_address( + client, + coin, + parse_path(path), + show_display, + None, + script_type=script_type, ) + == address + ) + + +@pytest.mark.multisig +def test_show_multisig_3(client): + nodes = [ + btc.get_public_node( + client, parse_path("84'/1'/%d'" % index), coin_name="Testnet" + ).node + for index in range(1, 4) + ] + multisig1 = proto.MultisigRedeemScriptType( + nodes=nodes, address_n=[0, 0], signatures=[b"", b"", b""], m=2 + ) + multisig2 = proto.MultisigRedeemScriptType( + nodes=nodes, address_n=[0, 1], signatures=[b"", b"", b""], m=2 + ) + for i in [1, 2, 3]: assert ( btc.get_address( client, "Testnet", - parse_path("84'/1'/0'/1/0"), + parse_path("84'/1'/%d'/0/1" % i), False, - None, + multisig2, script_type=proto.InputScriptType.SPENDWITNESS, ) - == "tb1qejqxwzfld7zr6mf7ygqy5s5se5xq7vmt96jk9x" + == "tb1qauuv4e2pwjkr4ws5f8p20hu562jlqpe5h74whxqrwf7pufsgzcms9y8set" ) assert ( btc.get_address( client, "Testnet", - parse_path("84'/1'/0'/0/0"), + parse_path("84'/1'/%d'/0/0" % i), False, - None, + multisig1, script_type=proto.InputScriptType.SPENDWITNESS, ) - == "tb1qkvwu9g3k2pdxewfqr7syz89r3gj557l3uuf9r9" - ) - assert ( - btc.get_address( - client, - "Testnet", - parse_path("44'/1'/0'/0/0"), - False, - None, - script_type=proto.InputScriptType.SPENDADDRESS, - ) - == "mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q" + == "tb1qgvn67p4twmpqhs8c39tukmu9geamtf7x0z3flwf9rrw4ff3h6d2qt0czq3" ) - @pytest.mark.altcoin - def test_show_segwit_altcoin(self, client): - assert ( - btc.get_address( - client, - "Groestlcoin", - parse_path("84'/17'/0'/0/0"), - False, - None, - script_type=proto.InputScriptType.SPENDWITNESS, - ) - == "grs1qw4teyraux2s77nhjdwh9ar8rl9dt7zww8r6lne" - ) - assert ( + +@pytest.mark.multisig +@pytest.mark.parametrize("show_display", (True, False)) +def test_multisig_missing(client, show_display): + # Multisig with global suffix specification. + # Use account numbers 1, 2 and 3 to create a valid multisig, + # but not containing the keys from account 0 used below. + nodes = [ + btc.get_public_node(client, parse_path("84'/0'/%d'" % i)).node + for i in range(1, 4) + ] + multisig1 = proto.MultisigRedeemScriptType( + nodes=nodes, address_n=[0, 0], signatures=[b"", b"", b""], m=2 + ) + + # Multisig with per-node suffix specification. + node = btc.get_public_node( + client, parse_path("84h/0h/0h/0"), coin_name="Bitcoin" + ).node + multisig2 = proto.MultisigRedeemScriptType( + pubkeys=[ + proto.HDNodePathType(node=node, address_n=[1]), + proto.HDNodePathType(node=node, address_n=[2]), + proto.HDNodePathType(node=node, address_n=[3]), + ], + signatures=[b"", b"", b""], + m=2, + ) + + for multisig in (multisig1, multisig2): + with pytest.raises(TrezorFailure): btc.get_address( client, - "Elements", - parse_path("84'/1'/0'/0/0"), - False, - None, + "Bitcoin", + parse_path("84'/0'/0'/0/0"), + show_display=show_display, + multisig=multisig, script_type=proto.InputScriptType.SPENDWITNESS, ) - == "ert1qkvwu9g3k2pdxewfqr7syz89r3gj557l3xp9k2v" - ) - - @pytest.mark.multisig - def test_show_multisig_3(self, client): - nodes = [ - btc.get_public_node( - client, parse_path("84'/1'/%d'" % index), coin_name="Testnet" - ).node - for index in range(1, 4) - ] - multisig1 = proto.MultisigRedeemScriptType( - nodes=nodes, address_n=[0, 0], signatures=[b"", b"", b""], m=2 - ) - multisig2 = proto.MultisigRedeemScriptType( - nodes=nodes, address_n=[0, 1], signatures=[b"", b"", b""], m=2 - ) - for i in [1, 2, 3]: - assert ( - btc.get_address( - client, - "Testnet", - parse_path("84'/1'/%d'/0/1" % i), - False, - multisig2, - script_type=proto.InputScriptType.SPENDWITNESS, - ) - == "tb1qauuv4e2pwjkr4ws5f8p20hu562jlqpe5h74whxqrwf7pufsgzcms9y8set" - ) - assert ( - btc.get_address( - client, - "Testnet", - parse_path("84'/1'/%d'/0/0" % i), - False, - multisig1, - script_type=proto.InputScriptType.SPENDWITNESS, - ) - == "tb1qgvn67p4twmpqhs8c39tukmu9geamtf7x0z3flwf9rrw4ff3h6d2qt0czq3" - ) - - @pytest.mark.multisig - @pytest.mark.parametrize("show_display", (True, False)) - def test_multisig_missing(self, client, show_display): - # Multisig with global suffix specification. - # Use account numbers 1, 2 and 3 to create a valid multisig, - # but not containing the keys from account 0 used below. - nodes = [ - btc.get_public_node(client, parse_path("84'/0'/%d'" % i)).node - for i in range(1, 4) - ] - multisig1 = proto.MultisigRedeemScriptType( - nodes=nodes, address_n=[0, 0], signatures=[b"", b"", b""], m=2 - ) - - # Multisig with per-node suffix specification. - node = btc.get_public_node( - client, parse_path("84h/0h/0h/0"), coin_name="Bitcoin" - ).node - multisig2 = proto.MultisigRedeemScriptType( - pubkeys=[ - proto.HDNodePathType(node=node, address_n=[1]), - proto.HDNodePathType(node=node, address_n=[2]), - proto.HDNodePathType(node=node, address_n=[3]), - ], - signatures=[b"", b"", b""], - m=2, - ) - - for multisig in (multisig1, multisig2): - with pytest.raises(TrezorFailure): - btc.get_address( - client, - "Bitcoin", - parse_path("84'/0'/0'/0/0"), - show_display=show_display, - multisig=multisig, - script_type=proto.InputScriptType.SPENDWITNESS, - ) diff --git a/tests/ui_tests/fixtures.json b/tests/ui_tests/fixtures.json index df9112327..9d5ba6ebe 100644 --- a/tests/ui_tests/fixtures.json +++ b/tests/ui_tests/fixtures.json @@ -289,11 +289,21 @@ "test_msg_getaddress_segwit.py-test_show_multisig_3": "c09de07fbbf1e047442180e2facb5482d06a1a428891b875b7dd93c9e4704ae1", "test_msg_getaddress_segwit.py-test_show_segwit": "8fee331410c7b921ea9bca379bd8c626672e9a8f87e99eca3e8786b27a10814c", "test_msg_getaddress_segwit.py-test_show_segwit_altcoin": "c09de07fbbf1e047442180e2facb5482d06a1a428891b875b7dd93c9e4704ae1", -"test_msg_getaddress_segwit_native.py-test_multisig_missing[False]": "c09de07fbbf1e047442180e2facb5482d06a1a428891b875b7dd93c9e4704ae1", -"test_msg_getaddress_segwit_native.py-test_multisig_missing[True]": "c09de07fbbf1e047442180e2facb5482d06a1a428891b875b7dd93c9e4704ae1", -"test_msg_getaddress_segwit_native.py-test_show_multisig_3": "c09de07fbbf1e047442180e2facb5482d06a1a428891b875b7dd93c9e4704ae1", -"test_msg_getaddress_segwit_native.py-test_show_segwit": "222d8057b5db530e7e5f1e1328c9049d2ccdc520f797cf02f8f578cdd53fb784", -"test_msg_getaddress_segwit_native.py-test_show_segwit_altcoin": "c09de07fbbf1e047442180e2facb5482d06a1a428891b875b7dd93c9e4704ae1", +"test_msg_getaddress_segwit_native.py::test_multisig_missing[False]": "c09de07fbbf1e047442180e2facb5482d06a1a428891b875b7dd93c9e4704ae1", +"test_msg_getaddress_segwit_native.py::test_multisig_missing[True]": "c09de07fbbf1e047442180e2facb5482d06a1a428891b875b7dd93c9e4704ae1", +"test_msg_getaddress_segwit_native.py::test_show_multisig_3": "c09de07fbbf1e047442180e2facb5482d06a1a428891b875b7dd93c9e4704ae1", +"test_msg_getaddress_segwit_native.py::test_show_segwit[Bitcoin-84'-0'-0'-0-0-InputScriptTyp-1daa684c": "6ed624858ce8f9e7a2c3eb3d3ea369caffb800e8f64a2a70320fbc901ab5fcde", +"test_msg_getaddress_segwit_native.py::test_show_segwit[Bitcoin-84'-0'-0'-0-0-InputScriptTyp-edbd0ef5": "c09de07fbbf1e047442180e2facb5482d06a1a428891b875b7dd93c9e4704ae1", +"test_msg_getaddress_segwit_native.py::test_show_segwit[Bitcoin-84'-0'-0'-1-0-InputScriptTyp-6154dbf8": "a021b0436b425f2b32923601fc4e79dbb1668ae7077cab5f8852fa0278334e19", +"test_msg_getaddress_segwit_native.py::test_show_segwit[Bitcoin-84'-0'-0'-1-0-InputScriptTyp-baf8e630": "c09de07fbbf1e047442180e2facb5482d06a1a428891b875b7dd93c9e4704ae1", +"test_msg_getaddress_segwit_native.py::test_show_segwit[Elements-84'-1'-0'-0-0-InputScriptTy-85a82103": "c09de07fbbf1e047442180e2facb5482d06a1a428891b875b7dd93c9e4704ae1", +"test_msg_getaddress_segwit_native.py::test_show_segwit[Elements-84'-1'-0'-0-0-InputScriptTy-fddcab5b": "f780fae7616adf03f07144ef8d3482fa04cd0e744ec4502aa93cc0ec0877e61d", +"test_msg_getaddress_segwit_native.py::test_show_segwit[Groestlcoin-84'-17'-0'-0-0-InputScri-94cc4c77": "c5311f036fdb7d7cae9878b6161a4f3cae3b6a594bff9b1e2099455cd0bf3d28", +"test_msg_getaddress_segwit_native.py::test_show_segwit[Groestlcoin-84'-17'-0'-0-0-InputScri-c8d41d22": "c09de07fbbf1e047442180e2facb5482d06a1a428891b875b7dd93c9e4704ae1", +"test_msg_getaddress_segwit_native.py::test_show_segwit[Testnet-84'-1'-0'-0-0-InputScriptTyp-41719d2f": "c09de07fbbf1e047442180e2facb5482d06a1a428891b875b7dd93c9e4704ae1", +"test_msg_getaddress_segwit_native.py::test_show_segwit[Testnet-84'-1'-0'-0-0-InputScriptTyp-b1cc1c24": "222d8057b5db530e7e5f1e1328c9049d2ccdc520f797cf02f8f578cdd53fb784", +"test_msg_getaddress_segwit_native.py::test_show_segwit[Testnet-84'-1'-0'-1-0-InputScriptTyp-63e7b548": "cd275027373a9939bc0443381cfcd062c7edef26d817efbcc6f7cb1b17bd276d", +"test_msg_getaddress_segwit_native.py::test_show_segwit[Testnet-84'-1'-0'-1-0-InputScriptTyp-d9df6906": "c09de07fbbf1e047442180e2facb5482d06a1a428891b875b7dd93c9e4704ae1", "test_msg_getaddress_show.py::test_show[m-44h-0h-12h-0-0-InputScriptType.SPENDADDRESS-1FM6Kz-0e830714": "1639a90cd9deccc25478b736c1992bd3f1ef17db95ab7e0ea82451dff0ebb12d", "test_msg_getaddress_show.py::test_show[m-49h-0h-12h-0-0-InputScriptType.SPENDP2SHWITNESS-3H-3d077d2b": "a2b3af26697700980024d2d9ba1145925d9c3c9dea40f6cc3d4546ea94e6e913", "test_msg_getaddress_show.py::test_show[m-84h-0h-12h-0-0-InputScriptType.SPENDWITNESS-bc1qdu-723cf9ae": "c3258bfb300e27bb54aec51eaf68008e087191b97794ddb8a1e6ee650fd8a6b2",