diff --git a/python/src/trezorlib/tools.py b/python/src/trezorlib/tools.py index 1870a79dae..34f9139d18 100644 --- a/python/src/trezorlib/tools.py +++ b/python/src/trezorlib/tools.py @@ -40,6 +40,14 @@ def btc_hash(data): return hashlib.sha256(hashlib.sha256(data).digest()).digest() +def tx_hash(data): + """Calculate and return double-SHA256 hash in reverse order. + + This is what Bitcoin uses as txids. + """ + return btc_hash(data)[::-1] + + def hash_160(public_key): md = hashlib.new("ripemd160") md.update(hashlib.sha256(public_key).digest()) diff --git a/tests/common.py b/tests/common.py index 387a4d8da0..4bfd538ac1 100644 --- a/tests/common.py +++ b/tests/common.py @@ -14,6 +14,7 @@ # You should have received a copy of the License along with this library. # If not, see . +from trezorlib import btc, tools from trezorlib.messages import ButtonRequestType as B # fmt: off @@ -41,6 +42,8 @@ MNEMONIC_SLIP39_ADVANCED_33 = [ EXTERNAL_ENTROPY = b"zlutoucky kun upel divoke ody" * 2 # fmt: on +TEST_ADDRESS_N = tools.parse_path("m/44h/1h/0h/0/0") + def generate_entropy(strength, internal_entropy, external_entropy): """ @@ -164,3 +167,7 @@ def read_and_confirm_mnemonic(debug, words): debug.input(mnemonic[index]) return " ".join(mnemonic) + + +def test_address(client): + return btc.get_address(client, "Testnet", TEST_ADDRESS_N) diff --git a/tests/device_tests/test_cancel.py b/tests/device_tests/test_cancel.py index 9fa5f82c94..2000b349e0 100644 --- a/tests/device_tests/test_cancel.py +++ b/tests/device_tests/test_cancel.py @@ -19,14 +19,16 @@ import pytest import trezorlib.messages as m from trezorlib.exceptions import Cancelled +from ..common import TEST_ADDRESS_N + @pytest.mark.parametrize( "message", [ m.Ping(message="hello", button_protection=True), m.GetAddress( - address_n=[0], - coin_name="Bitcoin", + address_n=TEST_ADDRESS_N, + coin_name="Testnet", script_type=m.InputScriptType.SPENDADDRESS, show_display=True, ), @@ -48,8 +50,8 @@ def test_cancel_message_via_cancel(client, message): [ m.Ping(message="hello", button_protection=True), m.GetAddress( - address_n=[0], - coin_name="Bitcoin", + address_n=TEST_ADDRESS_N, + coin_name="Testnet", script_type=m.InputScriptType.SPENDADDRESS, show_display=True, ), diff --git a/tests/device_tests/test_msg_ethereum_signtx_eip155.py b/tests/device_tests/test_msg_ethereum_signtx_eip155.py index fd81a7f781..ff262a1bf3 100644 --- a/tests/device_tests/test_msg_ethereum_signtx_eip155.py +++ b/tests/device_tests/test_msg_ethereum_signtx_eip155.py @@ -14,208 +14,125 @@ # You should have received a copy of the License along with this library. # If not, see . -from collections import namedtuple import pytest from trezorlib import ethereum -from trezorlib.tools import H_ +from trezorlib.tools import parse_path -Vector = namedtuple("Vector", "chain_id nonce sig_v sig_r sig_s value gas_limit data") - - -VECTORS = [ - Vector(*t) - for t in [ +VECTORS_CHAIN_IDS = ( # chain_id, slip44, sig_v, sig_r, sig_s + # Ethereum + ( + 1, + 60, ( - 3, - 0, - 42, - "cde31d8ab07d423d5e52aeb148180528ea54974cdb4c5578499c0137ec24d892", - "41fc58955b3b3e3f3b2aced65e11e8a3cb6339027f943bec3d504d6398b69dd2", - 100000000000000000, - 21000, - None, - ), - Vector( - 3, - 1, - 41, - "57951fed170f3765dea164d65acd31373799db32ec572e213b1d9a1209956b98", - "0971f8830c0e2e89919309f217ed2eadb0c63d647e016d220729ce79d27c24a0", - 100000000000000000, - 21000, - None, - ), - ( - 3, - 2, - 42, - "73744f66231690edd9eed2ab3c2b56ec4f6c4b9aabc633ae7f3f4ea94223d52c", - "7f500afbe2b2b4e4e57f22511e3a42b3596b85cad7fe1eca700cdae1905d3555", - 100000000000000000, - 21004, - b"\0", - ), - ( - 3, - 3, - 42, - "1a4fc1ec5f98bf874d5336aaf1fa9069ce68dc36c3f77e93465c9ac2c8b4b741", - "13007c9b1df6a0d2f2ffa9d0ebcdec189122a5e781eb64967eb0d6a6def95b7a", - 100000000000000000, - 299732, - b"ABCDEFGHIJKLMNOP" * 256 + b"!!!", - ), - ( - 3, - 4, - 42, - "8da0358d780df542f767d977f99ad034b6d9fa808fe50997141be2a1b93542c0", - "2dafe1ead8aae1051e6662c5d553b34067bda9c8fa7314ae8693ec61ddfc96d4", - 0, - 21004, - b"\0", - ), - ( - 1, - 1, 38, - "b72707f0f5a38339c9dd0359720312c739a8ac6554659c7af48456f06ba33374", - "75a431c046046942f9c1f3305cd08f34302164811c675ac0a0ac0b73cb30a90e", - 0, - 21004, - b"\0", + "6a6349bddb5749bb8b96ce2566a035ef87a09dbf89b5c7e3dfdf9ed725912f24", + "4ae58ccd3bacee07cdc4a3e8540544fd009c4311af7048122da60f2054c07ee4", ), + ), + # Ropsten + ( + 3, + 1, ( - 255, - 1, - 545, - "529172fb644a6d29b7218fb783f3d666021fc29cc4bf9bffbcfb3b84ab8d6181", - "30980c6102a12872ef9cd888f2bf90c81bbbdc8878ff7d1d1382f8983b0d0c49", - 0, - 21004, - b"\0", + 42, + "9d49a5c234a134bc56d00a7cf0c208c97d746f002c1fd3609b643eb8ef99d07d", + "3f064e133624cb59f8103fd5de76c089d8754e3da233a59d2ab2ca47fc306837", ), + ), + # Rinkeby + ( + 4, + 1, ( - 256, - 1, - 548, - "db53c05c679bdfdf3ded787ce9607d3f109ae46c87b1dcc9ab34053e5ed0eace", - "39645dd48118d369b588dbf279f1a8c01051fabf65bf8eaa633c6433ff120cce", - 0, - 21004, - b"\0", + 43, + "79a9fd0391f027ed518f3d796a598bf33eef0fb30ef22568a140d674d6b0b76c", + "408cd459abafcdb7f2e415b269c85a308aad4c53e63c01d3431d3db6ab6292dd", ), + ), + # ETC + ( + 61, + 61, ( - 65535, - 1, - 131105, - "b520fa77767cdf07b6014d4a8fb35eebe5ed7c0edab97132b0dc74e3e1f13ed9", - "78735b2db4cf95fb651c5c1f5529e60542019e456c6cb7a9f4bd9bbb83418d99", - 0, - 21004, - b"\0", + 158, + "6f03621da2fe75877494697b0852c379ea3b2c4ec4f99ab9ce0c8753ebbaf3aa", + "2b8c8def7534e7bc692ee2975a674a0e31c0dbd9137e53d27dee6b15e121c210", ), + ), + # EOS Classic + ( + 2018, + 2018, ( - 65536, - 1, - 131107, - "4b6122ba875b57ce084bd5f08e9ae1944e998726a4056c9b7746432d8f46ba99", - "6812c2668ac9c9927b69ef7cf9baec54436f7319ccc14f0f664e1e94e6109e06", - 0, - 21004, - b"\0", + 4071, + "2a890f3e4ae40614dd093e0696b99da02bb25ec03cdd3e7c1a77c425b8dc010b", + "33db0e15ab3d6d02f7c4e0ed39e496c0e5859b998e1258ce8d17a7f254e2c967", ), + ), + # Auxilium + ( + 28945486, + 344, ( - 16777215, - 1, - 33554465, - "68a8c6f2336a8e3296f17a307d84a1e6d3ab1383fdcc62611c2e8426f2e2777e", - "2d4ce900077ab40aac26064945998dbac5a014baadae2d3cb629cdeb9452db61", - 0, - 21004, - b"\0", + 57891008, + "3298b58680045cfb373b9945f17c468a5c5725c9115c7c18915e8c585c67193f", + "6bf1c719350150a520d59542815afd8263d7fe7087608051abe7df11dd7fcbec", ), + ), + # Pirl + ( + 3125659152, + 164, ( - 16777216, - 1, - 33554468, - "b6c42c584ef69621a2e5f3e1ab9dad890dbff3c92a599230dd0e394cd29d1c68", - "497eec05ea52773d0f05e7fdf4f7993b3a06ef958804b39af699ef09ed0f5d7e", - 0, - 21004, - b"\0", - ), - ( - 2147483629, - 1, - 4294967294, - "1a31f886c0bba527e622a731270dc29e62a607ff63558fca38745e5b9a672686", - "0f3fce8a70598bbb54387cde7e8f957a27e4a816cbc9408717b27d8666222bd9", - 0, - 21004, - b"\0", - ), - ( - 2147483630, - 1, - 4294967296, - "ba6cb6e2ebbac3726db9a3e4a939454009108f6515330e567aeada14ecebe074", - "2bbfba1154cae32e3e6c6bbf3ce41cba6cc8c6b764245ba6026605506838e690", - 0, - 21004, - None, - ), - ( - 2147483631, - 1, - 4294967298, - "3c743528e9ce315db02e487de93f2b2cfc93421e43f1d519f77a2f05bd2ce190", - "16c1fec1495fe5da89d1a026f1a575ff354e18ff0fb9d04a6cfb0413267ab2bc", - 100000000000000000, - 21000, - None, - ), - ( - 3125659152, - 1, 6251318340, - "82cde0c9e1a94c1305791b09e1bcd021a49b036a16d9733acbc1a08bb30f3410", - "472c8897519ba410b86f80993236d992e18e94d1f59c3d8760d2d7c90914dfc6", - 1, - 21005, - None, + "a876d3cf19f4f6b51fb980aac49e8bd378b88f11adbebc1be33d7b86eb84a054", + "3bee0e5a07661e78c9c4af49c8a42f4735f80cbb82931607ac35fc78f8d5b113", ), - ( - 4294967295, - 1, - 8589934625, - "67788e892fb372bba16823e16d3186f67494d7b1128555248f3661ad87e9d7ef", - "2faf9f06dfdf23ceca2796cf0d55c88187f199e98a94dfb15722824b244d81a1", - 100000000000000000, - 21000, - None, - ), - ] -] + ), +) @pytest.mark.altcoin @pytest.mark.ethereum -@pytest.mark.parametrize("vector", VECTORS) -def test_ethereum_signtx_eip155(client, vector): +@pytest.mark.parametrize("chain_id, slip44, sig", VECTORS_CHAIN_IDS) +def test_chain_ids(client, chain_id, slip44, sig): sig_v, sig_r, sig_s = ethereum.sign_tx( client, - n=[H_(44), H_(60), H_(0), 0, 0], - nonce=vector.nonce, + n=parse_path(f"m/44h/{slip44}h/0h/0/0"), + nonce=0, gas_price=20000000000, - gas_limit=vector.gas_limit, + gas_limit=21000, to="0x8eA7a3fccC211ED48b763b4164884DDbcF3b0A98", - value=vector.value, - chain_id=vector.chain_id, - data=vector.data, + value=10000000000, + chain_id=chain_id, + ) + expected_v = 2 * chain_id + 35 + assert sig_v in (expected_v, expected_v + 1) + assert (sig_v, sig_r.hex(), sig_s.hex()) == sig + + +@pytest.mark.altcoin +@pytest.mark.ethereum +def test_with_data(client): + sig_v, sig_r, sig_s = ethereum.sign_tx( + client, + n=parse_path(f"m/44h/60h/0h/0/0"), + nonce=0, + gas_price=20000000000, + gas_limit=21000, + to="0x8eA7a3fccC211ED48b763b4164884DDbcF3b0A98", + value=10000000000, + chain_id=1, + data=b"ABCDEFGHIJKLM", + ) + assert sig_v == 37 + assert ( + sig_r.hex() + == "c57556e308f49c84adc614042bf443381676fd2797f9512a85dc529f7acb7fa8" + ) + assert ( + sig_s.hex() + == "60a82338641fd4a924a6ec31da4aadc0a43ac77d3a021307ec07bb6982ccbe8d" ) - assert sig_v == vector.sig_v - assert sig_r.hex() == vector.sig_r - assert sig_s.hex() == vector.sig_s diff --git a/tests/device_tests/test_msg_getaddress.py b/tests/device_tests/test_msg_getaddress.py index df28701128..047195a3a4 100644 --- a/tests/device_tests/test_msg_getaddress.py +++ b/tests/device_tests/test_msg_getaddress.py @@ -16,16 +16,15 @@ import pytest -from trezorlib import btc, messages as proto +from trezorlib import btc, messages from trezorlib.exceptions import TrezorFailure -from trezorlib.tools import H_, parse_path +from trezorlib.tools import parse_path from .. import bip32 -from ..common import MNEMONIC12 def getmultisig(chain, nr, xpubs, signatures=[b"", b"", b""]): - return proto.MultisigRedeemScriptType( + return messages.MultisigRedeemScriptType( nodes=[bip32.deserialize(xpub) for xpub in xpubs], address_n=[chain, nr], signatures=signatures, @@ -33,59 +32,49 @@ def getmultisig(chain, nr, xpubs, signatures=[b"", b"", b""]): ) +@pytest.mark.skip_ui class TestMsgGetaddress: - @pytest.mark.setup_client(mnemonic=MNEMONIC12) def test_btc(self, client): assert ( - btc.get_address(client, "Bitcoin", []) - == "1EfKbQupktEMXf4gujJ9kCFo83k1iMqwqK" + btc.get_address(client, "Bitcoin", parse_path("m/44'/0'/0'/0/0")) + == "1JAd7XCBzGudGpJQSDSfpmJhiygtLQWaGL" ) assert ( - btc.get_address(client, "Bitcoin", [1]) - == "1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb" + btc.get_address(client, "Bitcoin", parse_path("m/44'/0'/0'/0/1")) + == "1GWFxtwWmNVqotUPXLcKVL2mUKpshuJYo" ) assert ( - btc.get_address(client, "Bitcoin", [0, H_(1)]) - == "1JVq66pzRBvqaBRFeU9SPVvg3er4ZDgoMs" - ) - assert ( - btc.get_address(client, "Bitcoin", [H_(9), 0]) - == "1F4YdQdL9ZQwvcNTuy5mjyQxXkyCfMcP2P" - ) - assert ( - btc.get_address(client, "Bitcoin", [0, 9999999]) - == "1GS8X3yc7ntzwGw9vXwj9wqmBWZkTFewBV" + btc.get_address(client, "Bitcoin", parse_path("m/44'/0'/0'/1/0")) + == "1DyHzbQUoQEsLxJn6M7fMD8Xdt1XvNiwNE" ) @pytest.mark.altcoin - @pytest.mark.setup_client(mnemonic=MNEMONIC12) def test_ltc(self, client): assert ( - btc.get_address(client, "Litecoin", []) - == "LYtGrdDeqYUQnTkr5sHT2DKZLG7Hqg7HTK" + btc.get_address(client, "Litecoin", parse_path("m/44'/2'/0'/0/0")) + == "LcubERmHD31PWup1fbozpKuiqjHZ4anxcL" ) assert ( - btc.get_address(client, "Litecoin", [1]) - == "LKRGNecThFP3Q6c5fosLVA53Z2hUDb1qnE" + btc.get_address(client, "Litecoin", parse_path("m/44'/2'/0'/0/1")) + == "LVWBmHBkCGNjSPHucvL2PmnuRAJnucmRE6" ) assert ( - btc.get_address(client, "Litecoin", [0, H_(1)]) - == "LcinMK8pVrAtpz7Qpc8jfWzSFsDLgLYfG6" - ) - assert ( - btc.get_address(client, "Litecoin", [H_(9), 0]) - == "LZHVtcwAEDf1BR4d67551zUijyLUpDF9EX" - ) - assert ( - btc.get_address(client, "Litecoin", [0, 9999999]) - == "Laf5nGHSCT94C5dK6fw2RxuXPiw2ZuRR9S" + btc.get_address(client, "Litecoin", parse_path("m/44'/2'/0'/1/0")) + == "LWj6ApswZxay4cJEJES2sGe7fLMLRvvv8h" ) - @pytest.mark.setup_client(mnemonic=MNEMONIC12) def test_tbtc(self, client): assert ( - btc.get_address(client, "Testnet", [111, 42]) - == "moN6aN6NP1KWgnPSqzrrRPvx2x1UtZJssa" + btc.get_address(client, "Testnet", parse_path("m/44'/1'/0'/0/0")) + == "mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q" + ) + assert ( + btc.get_address(client, "Testnet", parse_path("m/44'/1'/0'/0/1")) + == "mopZWqZZyQc3F2Sy33cvDtJchSAMsnLi7b" + ) + assert ( + btc.get_address(client, "Testnet", parse_path("m/44'/1'/0'/1/0")) + == "mm6kLYbGEL1tGe4ZA8xacfgRPdW1NLjCbZ" ) @pytest.mark.altcoin @@ -186,7 +175,9 @@ class TestMsgGetaddress: def test_bch_multisig(self, client): xpubs = [] for n in range(1, 4): - node = btc.get_public_node(client, parse_path("44'/145'/%d'" % n)) + node = btc.get_public_node( + client, parse_path("44'/145'/%d'" % n), coin_name="Bcash" + ) xpubs.append(node.xpub) for nr in range(1, 4): @@ -211,17 +202,39 @@ class TestMsgGetaddress: == "bitcoincash:pp6kcpkhua7789g2vyj0qfkcux3yvje7euhyhltn0a" ) - @pytest.mark.setup_client(mnemonic=MNEMONIC12) def test_public_ckd(self, client): - node = btc.get_public_node(client, []).node - node_sub1 = btc.get_public_node(client, [1]).node - node_sub2 = bip32.public_ckd(node, [1]) + node = btc.get_public_node(client, parse_path("m/44'/0'/0'")).node + node_sub1 = btc.get_public_node(client, parse_path("m/44'/0'/0'/1/0")).node + node_sub2 = bip32.public_ckd(node, [1, 0]) assert node_sub1.chain_code == node_sub2.chain_code assert node_sub1.public_key == node_sub2.public_key - address1 = btc.get_address(client, "Bitcoin", [1]) + address1 = btc.get_address(client, "Bitcoin", parse_path("m/44'/0'/0'/1/0")) address2 = bip32.get_address(node_sub2, 0) - assert address2 == "1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb" + assert address2 == "1DyHzbQUoQEsLxJn6M7fMD8Xdt1XvNiwNE" assert address1 == address2 + + +@pytest.mark.skip_t1 +@pytest.mark.skip_ui +def test_invalid_path(client): + with pytest.raises(TrezorFailure, match="Forbidden key path"): + # slip44 id mismatch + btc.get_address(client, "Bitcoin", parse_path("m/44'/111'/0'/0/0")) + + +@pytest.mark.skip_t1 +def test_unknown_path(client): + with client: + client.set_expected_responses( + [ + messages.ButtonRequest( + code=messages.ButtonRequestType.UnknownDerivationPath + ), + messages.Address(), + ] + ) + # account number is too high + btc.get_address(client, "Bitcoin", parse_path("m/44'/0'/21'/0/0")) diff --git a/tests/device_tests/test_msg_getaddress_segwit.py b/tests/device_tests/test_msg_getaddress_segwit.py index e041a477af..d06277915a 100644 --- a/tests/device_tests/test_msg_getaddress_segwit.py +++ b/tests/device_tests/test_msg_getaddress_segwit.py @@ -95,12 +95,14 @@ class TestMsgGetaddressSegwit: @pytest.mark.multisig def test_show_multisig_3(self, client): nodes = [ - btc.get_public_node(client, parse_path("999'/1'/%d'" % i)).node + btc.get_public_node( + client, parse_path("49'/1'/%d'" % i), coin_name="Testnet" + ).node for i in range(1, 4) ] multisig1 = proto.MultisigRedeemScriptType( - nodes=nodes, address_n=[2, 0], signatures=[b"", b"", b""], m=2 + nodes=nodes, address_n=[0, 7], signatures=[b"", b"", b""], m=2 ) # multisig2 = proto.MultisigRedeemScriptType( # pubkeys=map(lambda n: proto.HDNodePathType(node=bip32.deserialize(n.xpub), address_n=[2, 1]), nodes), @@ -112,10 +114,10 @@ class TestMsgGetaddressSegwit: btc.get_address( client, "Testnet", - parse_path("999'/1'/%d'/2/0" % i), + parse_path(f"49'/1'/{i}'/0/7"), False, multisig1, script_type=proto.InputScriptType.SPENDP2SHWITNESS, ) - == "2N2MxyAfifVhb3AMagisxaj3uij8bfXqf4Y" + == "2MwuUwUzPG17wiKQpfXmzfxJEoe7RXZDRad" ) diff --git a/tests/device_tests/test_msg_getaddress_segwit_native.py b/tests/device_tests/test_msg_getaddress_segwit_native.py index ec3008dd33..5b2b503db2 100644 --- a/tests/device_tests/test_msg_getaddress_segwit_native.py +++ b/tests/device_tests/test_msg_getaddress_segwit_native.py @@ -95,7 +95,9 @@ class TestMsgGetaddressSegwitNative: @pytest.mark.multisig def test_show_multisig_3(self, client): nodes = [ - btc.get_public_node(client, parse_path("999'/1'/%d'" % index)).node + btc.get_public_node( + client, parse_path("84'/1'/%d'" % index), coin_name="Testnet" + ).node for index in range(1, 4) ] multisig1 = proto.MultisigRedeemScriptType( @@ -109,21 +111,21 @@ class TestMsgGetaddressSegwitNative: btc.get_address( client, "Testnet", - parse_path("999'/1'/%d'/2/1" % i), + parse_path("84'/1'/%d'/2/1" % i), False, multisig2, script_type=proto.InputScriptType.SPENDWITNESS, ) - == "tb1qch62pf820spe9mlq49ns5uexfnl6jzcezp7d328fw58lj0rhlhasge9hzy" + == "tb1qnqlw0gwzpcdken0sarskrgxf7l36pprlfy4uk7yf98jz9rfd36ss2tc6ja" ) assert ( btc.get_address( client, "Testnet", - parse_path("999'/1'/%d'/2/0" % i), + parse_path("84'/1'/%d'/2/0" % i), False, multisig1, script_type=proto.InputScriptType.SPENDWITNESS, ) - == "tb1qr6xa5v60zyt3ry9nmfew2fk5g9y3gerkjeu6xxdz7qga5kknz2ssld9z2z" + == "tb1qaqrlzu8unz58p77d30ej85n3gv5574alkqw0qcjsyd2hs9frp2vstew67z" ) diff --git a/tests/device_tests/test_msg_getaddress_show.py b/tests/device_tests/test_msg_getaddress_show.py index 4d05256823..e7549538ea 100644 --- a/tests/device_tests/test_msg_getaddress_show.py +++ b/tests/device_tests/test_msg_getaddress_show.py @@ -18,138 +18,157 @@ import pytest from trezorlib import btc, messages, tools -from .. import bip32 -from ..common import MNEMONIC12 +VECTORS = ( # path, script_type, address + ( + "m/44h/0h/12h/0/0", + messages.InputScriptType.SPENDADDRESS, + "1FM6Kz3oT3GoGv65jNpU8AFFun8nHAXrPk", + ), + ( + "m/49h/0h/12h/0/0", + messages.InputScriptType.SPENDP2SHWITNESS, + "3HfEUkuwmtZ87XzowkiD5nMp5Q3hqKXZ2i", + ), + ( + "m/84h/0h/12h/0/0", + messages.InputScriptType.SPENDWITNESS, + "bc1qduvap743hcl7twn8u6f9l0u8y7x83965xy0raj", + ), +) -class TestMsgGetaddressShow: - @pytest.mark.setup_client(mnemonic=MNEMONIC12) - def test_show(self, client): +@pytest.mark.parametrize("path, script_type, address", VECTORS) +def test_show(client, path, script_type, address): + assert ( + btc.get_address( + client, + "Bitcoin", + tools.parse_path(path), + script_type=script_type, + show_display=True, + ) + == address + ) + + +@pytest.mark.multisig +def test_show_multisig_3(client): + node = btc.get_public_node( + client, tools.parse_path("44h/0h/0h/0"), coin_name="Bitcoin" + ).node + multisig = messages.MultisigRedeemScriptType( + pubkeys=[ + messages.HDNodePathType(node=node, address_n=[1]), + messages.HDNodePathType(node=node, address_n=[2]), + messages.HDNodePathType(node=node, address_n=[3]), + ], + signatures=[b"", b"", b""], + m=2, + ) + + for i in [1, 2, 3]: assert ( - btc.get_address(client, "Bitcoin", [1], show_display=True) - == "1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb" - ) - assert ( - btc.get_address(client, "Bitcoin", [2], show_display=True) - == "15AeAhtNJNKyowK8qPHwgpXkhsokzLtUpG" - ) - assert ( - btc.get_address(client, "Bitcoin", [3], show_display=True) - == "1CmzyJp9w3NafXMSEFH4SLYUPAVCSUrrJ5" + btc.get_address( + client, + "Bitcoin", + tools.parse_path(f"44h/0h/0h/0/{i}"), + show_display=True, + multisig=multisig, + ) + == "36AvLYugbb9CsN8sQ5k7kJ2diWF54msYKs" ) - @pytest.mark.multisig - @pytest.mark.setup_client(mnemonic=MNEMONIC12) - def test_show_multisig_3(self, client): - node = bip32.deserialize( - "xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy" - ) - multisig = messages.MultisigRedeemScriptType( - pubkeys=[ - messages.HDNodePathType(node=node, address_n=[1]), - messages.HDNodePathType(node=node, address_n=[2]), - messages.HDNodePathType(node=node, address_n=[3]), - ], - signatures=[b"", b"", b""], - m=2, - ) - for i in [1, 2, 3]: - assert ( - btc.get_address( - client, "Bitcoin", [i], show_display=True, multisig=multisig - ) - == "3E7GDtuHqnqPmDgwH59pVC7AvySiSkbibz" +@pytest.mark.skip_t1 +@pytest.mark.multisig +def test_show_multisig_xpubs(client): + nodes = [ + btc.get_public_node( + client, tools.parse_path(f"48h/0h/{i}h"), coin_name="Bitcoin" + ) + for i in range(3) + ] + multisig = messages.MultisigRedeemScriptType( + nodes=[n.node for n in nodes], + signatures=[b"", b"", b""], + address_n=[0, 0], + m=2, + ) + + xpubs = [[n.xpub[i * 16 : (i + 1) * 16] for i in range(5)] for n in nodes] + + for i in range(3): + + def input_flow(): + yield # show address + assert client.debug.wait_layout().lines == [ + "Multisig 2 of 3", + "34yJV2b2GtbmxfZNw", + "jPyuyUYkUbUnogqa8", + ] + + client.debug.press_no() + yield # show QR code + assert client.debug.wait_layout().text.startswith("Qr") + + client.debug.press_no() + yield # show XPUB#1 + lines = client.debug.wait_layout().lines + assert lines[0] == "XPUB #1 " + ("(yours)" if i == 0 else "(others)") + assert lines[1:] == xpubs[0] + # just for UI test + client.debug.swipe_up() + + client.debug.press_no() + yield # show XPUB#2 + lines = client.debug.wait_layout().lines + assert lines[0] == "XPUB #2 " + ("(yours)" if i == 1 else "(others)") + assert lines[1:] == xpubs[1] + # just for UI test + client.debug.swipe_up() + + client.debug.press_no() + yield # show XPUB#3 + lines = client.debug.wait_layout().lines + assert lines[0] == "XPUB #3 " + ("(yours)" if i == 2 else "(others)") + assert lines[1:] == xpubs[2] + # just for UI test + client.debug.swipe_up() + + client.debug.press_yes() + + with client: + client.set_input_flow(input_flow) + btc.get_address( + client, + "Bitcoin", + tools.parse_path(f"48h/0h/{i}h/0/0"), + show_display=True, + multisig=multisig, + script_type=messages.InputScriptType.SPENDMULTISIG, ) - @pytest.mark.skip_t1 - @pytest.mark.multisig - def test_show_multisig_xpubs(self, client): - nodes = [ - btc.get_public_node( - client, tools.parse_path(f"48h/0h/{i}h"), coin_name="Bitcoin" + +@pytest.mark.multisig +def test_show_multisig_15(client): + node = btc.get_public_node( + client, tools.parse_path("44h/0h/0h/0"), coin_name="Bitcoin" + ).node + + pubs = [messages.HDNodePathType(node=node, address_n=[x]) for x in range(15)] + + multisig = messages.MultisigRedeemScriptType( + pubkeys=pubs, signatures=[b""] * 15, m=15 + ) + + for i in range(15): + assert ( + btc.get_address( + client, + "Bitcoin", + tools.parse_path(f"44h/0h/0h/0/{i}"), + show_display=True, + multisig=multisig, ) - for i in range(3) - ] - multisig = messages.MultisigRedeemScriptType( - nodes=[n.node for n in nodes], - signatures=[b"", b"", b""], - address_n=[0, 0], - m=2, + == "3D9EDNTZde5KizWdjidELFzx7xtrcdM7AG" ) - - xpubs = [[n.xpub[i * 16 : (i + 1) * 16] for i in range(5)] for n in nodes] - - for i in range(3): - - def input_flow(): - yield # show address - assert client.debug.wait_layout().lines == [ - "Multisig 2 of 3", - "34yJV2b2GtbmxfZNw", - "jPyuyUYkUbUnogqa8", - ] - - client.debug.press_no() - yield # show QR code - assert client.debug.wait_layout().text.startswith("Qr") - - client.debug.press_no() - yield # show XPUB#1 - lines = client.debug.wait_layout().lines - assert lines[0] == "XPUB #1 " + ("(yours)" if i == 0 else "(others)") - assert lines[1:] == xpubs[0] - # just for UI test - client.debug.swipe_up() - - client.debug.press_no() - yield # show XPUB#2 - lines = client.debug.wait_layout().lines - assert lines[0] == "XPUB #2 " + ("(yours)" if i == 1 else "(others)") - assert lines[1:] == xpubs[1] - # just for UI test - client.debug.swipe_up() - - client.debug.press_no() - yield # show XPUB#3 - lines = client.debug.wait_layout().lines - assert lines[0] == "XPUB #3 " + ("(yours)" if i == 2 else "(others)") - assert lines[1:] == xpubs[2] - # just for UI test - client.debug.swipe_up() - - client.debug.press_yes() - - with client: - client.set_input_flow(input_flow) - btc.get_address( - client, - "Bitcoin", - tools.parse_path(f"48h/0h/{i}h/0/0"), - show_display=True, - multisig=multisig, - script_type=messages.InputScriptType.SPENDMULTISIG, - ) - - @pytest.mark.multisig - @pytest.mark.setup_client(mnemonic=MNEMONIC12) - def test_show_multisig_15(self, client): - node = bip32.deserialize( - "xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy" - ) - - pubs = [] - for x in range(15): - pubs.append(messages.HDNodePathType(node=node, address_n=[x])) - - multisig = messages.MultisigRedeemScriptType( - pubkeys=pubs, signatures=[b""] * 15, m=15 - ) - - for i in range(15): - assert ( - btc.get_address( - client, "Bitcoin", [i], show_display=True, multisig=multisig - ) - == "3QaKF8zobqcqY8aS6nxCD5ZYdiRfL3RCmU" - ) diff --git a/tests/device_tests/test_msg_getpublickey.py b/tests/device_tests/test_msg_getpublickey.py index eae943c22d..79bb448100 100644 --- a/tests/device_tests/test_msg_getpublickey.py +++ b/tests/device_tests/test_msg_getpublickey.py @@ -16,142 +16,117 @@ import pytest -from trezorlib import btc, messages as proto -from trezorlib.tools import H_ +from trezorlib import btc, messages +from trezorlib.tools import parse_path from .. import bip32 -from ..common import MNEMONIC12 + +VECTORS_BITCOIN = ( # coin_name, xpub_magic, path, xpub + ( + "Bitcoin", + 0x0488B21E, + parse_path("m/44h/0h/0h"), + "xpub6BiVtCpG9fQPxnPmHXG8PhtzQdWC2Su4qWu6XW9tpWFYhxydCLJGrWBJZ5H6qTAHdPQ7pQhtpjiYZVZARo14qHiay2fvrX996oEP42u8wZy", + ), + ( + "Bitcoin", + 0x0488B21E, + parse_path("m/44h/0h/10h"), + "xpub6BiVtCpG9fQQR6cSuFeDaSvCDgNvNme499JUGX4RHDiZVWwZy9NwNieWKXHLe8XRbdrEmY87aqztBCbRJkXWV7VJB96XBT5cpkqYMHwvLWB", + ), + ( + "Bitcoin", + 0x0488B21E, + parse_path("m/44h/0h/0h/0/0"), + "xpub6FVDRC1jiWNTuT3embehwSZ1buxRDyZGbTakVCkBr6w2LwpERmYqXyvtrLeJX9hqzLaucS3qJXGekeFsSVCELkbgepp7FVGeH5BYekEgT9x", + ), + ( + "Bitcoin", + 0x0488B21E, + parse_path("m/44h/0h/10h/1/100"), + "xpub6GhTNegKCjTqjYS4HNkPhXHXHNZV2cPC38N7HbpUKexXXuTkjKPnijqKTB7yXidP4JtTUWTuWPTt6P55xi91NPgUp51BnqYzYdNhho4y5j8", + ), + ( + "Testnet", + 0x043587CF, + parse_path("m/44h/1h/0h"), + "tpubDDKn3FtHc74CaRrRbi1WFdJNaaenZkDWqq9NsEhcafnDZ4VuKeuLG2aKHm5SuwuLgAhRkkfHqcCxpnVNSrs5kJYZXwa6Ud431VnevzzzK3U", + ), + ( + "Testnet", + 0x043587CF, + parse_path("m/44h/1h/0h/0/0"), + "tpubDGwNSs8z8jZU2EcUiubR4frGvKqddvLBqCDNknnWhmoUd6EHrRWrqXmDaWBNddWzM5Yqh4e4TUYFK9hGCEnSrMKgV6cthRhArfZpwzihdw7", + ), +) + +VECTORS_ALTCOINS = ( + ( + "Litecoin", + 0x019DA462, + parse_path("m/44h/2h/0h"), + "Ltub2Y8PyEMWQVgiX4L4gVzU8PakBTQ2WBxFdS6tJARQeasUUfXmBut2jGShnQyD3jgyBf7mmvs5jPNgmgXad5J6M8a8FiZK78dbT21fYtTAC9a", + ), + ( + "Litecoin", + 0x019DA462, + parse_path("m/44h/2h/10h"), + "Ltub2Y8PyEMWQVgiy8Zio1XrKWkGL6ZmCZB9W5ShbvbzZ14irCrAb62YEoMafTAM5a2A6x6XNcyDdCNW7NVgES9jtQqyUZcBUFTimS7VVJ8tbpE", + ), + ( + "Litecoin", + 0x019DA462, + parse_path("m/44h/2h/0h/0/0"), + "Ltub2dTvwC4v7GNeR6UEaywQ6j72wHi4dwRo3oDDzvXAwb4CrXVQEUTbxC4hEfULiKByiUMEmYLhuMo1YMYmBBjKJ8kyk9ia5gZaVNWq5rVLom4", + ), + ( + "Litecoin", + 0x019DA462, + parse_path("m/44h/2h/10h/1/100"), + "Ltub2dcb6Nghj3kwaC2g3TtPgFzMSm7LXfe4mijFYsvEtxXu18vicTB4kYc9z6jGVMpdYhMScNhVY1naQYALnM2x4fvaGzAAGgcuZ89nFyyLhiK", + ), +) -class TestMsgGetpublickey: - @pytest.mark.setup_client(mnemonic=MNEMONIC12) - def test_btc(self, client): - assert ( - bip32.serialize(btc.get_public_node(client, []).node, 0x0488B21E) - == "xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy" - ) - assert ( - btc.get_public_node(client, [], coin_name="Bitcoin").xpub - == "xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy" - ) - assert ( - bip32.serialize(btc.get_public_node(client, [1]).node, 0x0488B21E) - == "xpub68zNxjsTrV8y9AadThLW7dTAqEpZ7xBLFSyJ3X9pjTv6Njg6kxgjXJkzxq8u3ttnjBw1jupQHMP3gpGZzZqd1eh5S4GjkaMhPR18vMyUi8N" - ) - assert ( - btc.get_public_node(client, [1], coin_name="Bitcoin").xpub - == "xpub68zNxjsTrV8y9AadThLW7dTAqEpZ7xBLFSyJ3X9pjTv6Njg6kxgjXJkzxq8u3ttnjBw1jupQHMP3gpGZzZqd1eh5S4GjkaMhPR18vMyUi8N" - ) - assert ( - bip32.serialize(btc.get_public_node(client, [0, H_(1)]).node, 0x0488B21E) - == "xpub6A3FoZqYXj1AbW4thRwBh26YwZWbmoyjTaZwwxJjY1oKUpefLepL3RFS9DHKQrjAfxDrzDepYMDZPqXN6upQm3bHQ9xaXD5a3mqni3goF4v" - ) - assert ( - btc.get_public_node(client, [0, H_(1)], coin_name="Bitcoin").xpub - == "xpub6A3FoZqYXj1AbW4thRwBh26YwZWbmoyjTaZwwxJjY1oKUpefLepL3RFS9DHKQrjAfxDrzDepYMDZPqXN6upQm3bHQ9xaXD5a3mqni3goF4v" - ) - assert ( - bip32.serialize(btc.get_public_node(client, [H_(9), 0]).node, 0x0488B21E) - == "xpub6A2h5mzLDfYginoD7q7wCWbq18wTbN9gducRr2w5NRTwdLeoT3cJSwefFqW7uXTpVFGtpUyDMBNYs3DNvvXx6NPjF9YEbUQrtxFSWnPtVrv" - ) - assert ( - btc.get_public_node(client, [H_(9), 0], coin_name="Bitcoin").xpub - == "xpub6A2h5mzLDfYginoD7q7wCWbq18wTbN9gducRr2w5NRTwdLeoT3cJSwefFqW7uXTpVFGtpUyDMBNYs3DNvvXx6NPjF9YEbUQrtxFSWnPtVrv" - ) - assert ( - bip32.serialize(btc.get_public_node(client, [0, 9999999]).node, 0x0488B21E) - == "xpub6A3FoZqQEK6iwLZ4HFkqSo5fb35BH4bpjC4SPZ63prfLdGYPwYxEuC6o91bUvFFdMzKWe5rs3axHRUjxJaSvBnKKFtnfLwDACRxPxabsv2r" - ) - assert ( - btc.get_public_node(client, [0, 9999999], coin_name="Bitcoin").xpub - == "xpub6A3FoZqQEK6iwLZ4HFkqSo5fb35BH4bpjC4SPZ63prfLdGYPwYxEuC6o91bUvFFdMzKWe5rs3axHRUjxJaSvBnKKFtnfLwDACRxPxabsv2r" - ) +@pytest.mark.parametrize("coin_name, xpub_magic, path, xpub", VECTORS_BITCOIN) +def test_get_public_node(client, coin_name, xpub_magic, path, xpub): + res = btc.get_public_node(client, path, coin_name=coin_name) + assert res.xpub == xpub + assert bip32.serialize(res.node, xpub_magic) == xpub - @pytest.mark.altcoin - @pytest.mark.setup_client(mnemonic=MNEMONIC12) - def test_ltc(self, client): - assert ( - bip32.serialize(btc.get_public_node(client, []).node, 0x019DA462) - == "Ltub2SSUS19CirucVPGDKDBatBDBEM2s9UbH66pBURfaKrMocCPLhQ7Z7hecy5VYLHA5fRdXwB2e61j2VJCNzVsqKTCVEU1vECjqi5EyczFX9xp" - ) - assert ( - btc.get_public_node(client, [], coin_name="Litecoin").xpub - == "Ltub2SSUS19CirucVPGDKDBatBDBEM2s9UbH66pBURfaKrMocCPLhQ7Z7hecy5VYLHA5fRdXwB2e61j2VJCNzVsqKTCVEU1vECjqi5EyczFX9xp" - ) - assert ( - bip32.serialize(btc.get_public_node(client, [1]).node, 0x019DA462) - == "Ltub2VRVRP5VjvSyPXra4BLVyVZPv397sjhUNjBGsbtw6xko77JuQyBULxFSKheviJJ3KQLbL3Cx8P2RnudguTw4raUVjCACRG7jsumUptYx55C" - ) - assert ( - btc.get_public_node(client, [1], coin_name="Litecoin").xpub - == "Ltub2VRVRP5VjvSyPXra4BLVyVZPv397sjhUNjBGsbtw6xko77JuQyBULxFSKheviJJ3KQLbL3Cx8P2RnudguTw4raUVjCACRG7jsumUptYx55C" - ) - assert ( - bip32.serialize(btc.get_public_node(client, [0, H_(1)]).node, 0x019DA462) - == "Ltub2WUNGD3aRAKAqsLqHuwBYtCn2MqAXbVsarmvn33quWe2DCHTzfK4s4jsW5oM5G8RGAdSaM3NPNrwVvtV1ourbyNhhHr3BtqcYGc8caf5GoT" - ) - assert ( - btc.get_public_node(client, [0, H_(1)], coin_name="Litecoin").xpub - == "Ltub2WUNGD3aRAKAqsLqHuwBYtCn2MqAXbVsarmvn33quWe2DCHTzfK4s4jsW5oM5G8RGAdSaM3NPNrwVvtV1ourbyNhhHr3BtqcYGc8caf5GoT" - ) - assert ( - bip32.serialize(btc.get_public_node(client, [H_(9), 0]).node, 0x019DA462) - == "Ltub2WToYRCN76rgyA59iK7w4Ni45wG2M9fpmBpQg7gBjvJeMiHc7473Gb96ci29Zvs55TgUQcMmCD1vy8aVqpdPwJB9YHRhGAAuPT1nRLLXmFu" - ) - assert ( - btc.get_public_node(client, [H_(9), 0], coin_name="Litecoin").xpub - == "Ltub2WToYRCN76rgyA59iK7w4Ni45wG2M9fpmBpQg7gBjvJeMiHc7473Gb96ci29Zvs55TgUQcMmCD1vy8aVqpdPwJB9YHRhGAAuPT1nRLLXmFu" - ) - assert ( - bip32.serialize(btc.get_public_node(client, [0, 9999999]).node, 0x019DA462) - == "Ltub2WUNGD3S7kQjBhpzsjkqJfBtfqPk2r7xrUGRDdqACMW3MeBCbZSyiqbEVt7WaeesxCj6EDFQtcbfXa75DUYN2i6jZ2g81cyCgvijs9J2u2n" - ) - assert ( - btc.get_public_node(client, [0, 9999999], coin_name="Litecoin").xpub - == "Ltub2WUNGD3S7kQjBhpzsjkqJfBtfqPk2r7xrUGRDdqACMW3MeBCbZSyiqbEVt7WaeesxCj6EDFQtcbfXa75DUYN2i6jZ2g81cyCgvijs9J2u2n" - ) - @pytest.mark.setup_client(mnemonic=MNEMONIC12) - def test_tbtc(self, client): - assert ( - bip32.serialize(btc.get_public_node(client, [111, 42]).node, 0x043587CF) - == "tpubDAgixSyai5PWbc8N1mBkHDR5nLgAnHFtY7r4y5EzxqAxrt9YUDpZL3kaRoHVvCfrcwNo31c2isBP2uTHcZxEosuKbyJhCAbrvGoPuLUZ7Mz" - ) - assert ( - btc.get_public_node(client, [111, 42], coin_name="Testnet").xpub - == "tpubDAgixSyai5PWbc8N1mBkHDR5nLgAnHFtY7r4y5EzxqAxrt9YUDpZL3kaRoHVvCfrcwNo31c2isBP2uTHcZxEosuKbyJhCAbrvGoPuLUZ7Mz" - ) +@pytest.mark.parametrize("coin_name, xpub_magic, path, xpub", VECTORS_ALTCOINS) +@pytest.mark.altcoin +def test_get_public_node_altcoin(client, coin_name, xpub_magic, path, xpub): + res = btc.get_public_node(client, path, coin_name=coin_name) + assert res.xpub == xpub + assert bip32.serialize(res.node, xpub_magic) == xpub - @pytest.mark.setup_client(mnemonic=MNEMONIC12) - def test_script_type(self, client): - assert ( - btc.get_public_node(client, [], coin_name="Bitcoin").xpub - == "xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy" - ) - assert ( - btc.get_public_node( - client, - [], - coin_name="Bitcoin", - script_type=proto.InputScriptType.SPENDADDRESS, - ).xpub - == "xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy" - ) - assert ( - btc.get_public_node( - client, - [], - coin_name="Bitcoin", - script_type=proto.InputScriptType.SPENDP2SHWITNESS, - ).xpub - == "ypub6QqdH2c5z7966KBPZ5yDEQCTKWrkLK4dsw8RRjpMLMtyvvZmJ3nNv7pKdQw6fnQkUrLm6XEeheSCGVSpoJCQGm6fofpt9RoHVJYH72ecmVm" - ) - assert ( - btc.get_public_node( - client, - [], - coin_name="Bitcoin", - script_type=proto.InputScriptType.SPENDWITNESS, - ).xpub - == "zpub6jftahH18ngZwcNWPSkqSVHxVV1CGw48o3eeD8iEiNGrz2NzYhwwYBUTectgfh4ftVTZqzqDAJnk9n4PWzcR4znGg1XJjLcmm2bvVc3Honv" - ) + +VECTORS_SCRIPT_TYPES = ( # script_type, xpub + ( + None, + "xpub6BiVtCp7ozsRo7kaoYNrCNAVJwPYTQHjoXFD3YS797S55Y42sm2raxPrXQWAJodn7aXnHJdhz433ZJDhyUztHW55WatHeoYUVqui8cYNX8y", + ), + ( + messages.InputScriptType.SPENDADDRESS, + "xpub6BiVtCp7ozsRo7kaoYNrCNAVJwPYTQHjoXFD3YS797S55Y42sm2raxPrXQWAJodn7aXnHJdhz433ZJDhyUztHW55WatHeoYUVqui8cYNX8y", + ), + ( + messages.InputScriptType.SPENDP2SHWITNESS, + "ypub6WYmBsV2xgQueQwhduAUQTFzUuXzQ2HEidmRpwKzX7ox8dsG8RCRD23zYcTkJiHhXDeb2nEGSiPbSaqGhBQu5jkgNvaiEiMxmZyMXEvfNco", + ), + ( + messages.InputScriptType.SPENDWITNESS, + "zpub6qP2VY9x7MxPVi8pUFx6cYMVesgSLeGjdkHecLDsu8BqBjgVP5Myq5i8ZpRLJcwcvrmPnFppuNk9KsSqQspusySHFGH8pdBT3J2zujqcVuz", + ), +) + + +@pytest.mark.parametrize("script_type, xpub", VECTORS_SCRIPT_TYPES) +def test_script_type(client, script_type, xpub): + path = parse_path("m/44h/0h/0") + res = btc.get_public_node( + client, path, coin_name="Bitcoin", script_type=script_type + ) + assert res.xpub == xpub diff --git a/tests/device_tests/test_msg_getpublickey_curve.py b/tests/device_tests/test_msg_getpublickey_curve.py index f5b5b4ba41..4f2f1594e7 100644 --- a/tests/device_tests/test_msg_getpublickey_curve.py +++ b/tests/device_tests/test_msg_getpublickey_curve.py @@ -18,68 +18,58 @@ import pytest from trezorlib import btc from trezorlib.exceptions import TrezorFailure -from trezorlib.tools import H_ +from trezorlib.tools import parse_path -from ..common import MNEMONIC12 +pytestmark = pytest.mark.skip_ui + +PATH_PRIVATE = parse_path("m/17h/0h/1h/2h/3h") +PATH_PUBLIC = parse_path("m/17h/0h/1h/2h/3h/42") + +VECTORS = ( # curve, path, pubkey + ( + "secp256k1", + PATH_PRIVATE, + "02f65ce170451f66f46daf9486b0cf266bd199a3e67f734e469556745a78d254ee", + ), + ( + "secp256k1", + PATH_PUBLIC, + "0212f4629f4f224db0f778ca68abd1c53e21dd02e76dbd1f7312788544b5b1e042", + ), + ( + "nist256p1", + PATH_PRIVATE, + "0324c6860c25cdf7a8c103666662ac6183bf5a181a3341ea4130dcc6fdee7919e4", + ), + ( + "nist256p1", + PATH_PUBLIC, + "03b93f7e6c777143ad4eeb590aaa7cdcd95980cf68d3f75dc2c31ca637ec50c49b", + ), + ( + "ed25519", + PATH_PRIVATE, + "002e28dc0346d6d30d4e33f53c47f2fa97f3cfb5e80fc30fa3570fccf30652718a", + ), +) -class TestMsgGetpublickeyCurve: - @pytest.mark.setup_client(mnemonic=MNEMONIC12) - def test_default_curve(self, client): - assert ( - btc.get_public_node(client, [H_(111), 42]).node.public_key.hex() - == "02e7fcec053f0df94d88c86447970743e8a1979d242d09338dcf8687a9966f7fbc" - ) - assert ( - btc.get_public_node(client, [H_(111), H_(42)]).node.public_key.hex() - == "03ce7b690969d773ba9ed212464eb2b534b87b9b8a9383300bddabe1f093f79220" - ) +@pytest.mark.parametrize("curve, path, pubkey", VECTORS) +def test_publickey_curve(client, curve, path, pubkey): + resp = btc.get_public_node(client, path, ecdsa_curve_name=curve) + assert resp.node.public_key.hex() == pubkey - @pytest.mark.setup_client(mnemonic=MNEMONIC12) - def test_secp256k1_curve(self, client): - assert ( - btc.get_public_node( - client, [H_(111), 42], ecdsa_curve_name="secp256k1" - ).node.public_key.hex() - == "02e7fcec053f0df94d88c86447970743e8a1979d242d09338dcf8687a9966f7fbc" - ) - assert ( - btc.get_public_node( - client, [H_(111), H_(42)], ecdsa_curve_name="secp256k1" - ).node.public_key.hex() - == "03ce7b690969d773ba9ed212464eb2b534b87b9b8a9383300bddabe1f093f79220" - ) - @pytest.mark.setup_client(mnemonic=MNEMONIC12) - def test_nist256p1_curve(self, client): - assert ( - btc.get_public_node( - client, [H_(111), 42], ecdsa_curve_name="nist256p1" - ).node.public_key.hex() - == "02a9ce59b32bd64a70bc52aca96e5d09af65c6b9593ba2a60af8fccfe1437f2129" - ) - assert ( - btc.get_public_node( - client, [H_(111), H_(42)], ecdsa_curve_name="nist256p1" - ).node.public_key.hex() - == "026fe35d8afed67dbf0561a1d32922e8ad0cd0d86effbc82be970cbed7d9bab2c2" - ) +def test_ed25519_public(client): + with pytest.raises(TrezorFailure): + btc.get_public_node(client, PATH_PUBLIC, ecdsa_curve_name="ed25519") - @pytest.mark.setup_client(mnemonic=MNEMONIC12) - def test_ed25519_curve(self, client): - # ed25519 curve does not support public derivation, so test only private derivation paths - assert ( - btc.get_public_node( - client, [H_(111), H_(42)], ecdsa_curve_name="ed25519" - ).node.public_key.hex() - == "0069a14b478e508eab6e93303f4e6f5c50b8136627830f2ed5c3a835fc6c0ea2b7" + +@pytest.mark.skip_t1 +def test_coin_and_curve(client): + with pytest.raises( + TrezorFailure, match="Cannot use coin_name or script_type with ecdsa_curve_name" + ): + btc.get_public_node( + client, PATH_PRIVATE, coin_name="Bitcoin", ecdsa_curve_name="ed25519" ) - assert ( - btc.get_public_node( - client, [H_(111), H_(65535)], ecdsa_curve_name="ed25519" - ).node.public_key.hex() - == "00514f73a05184458611b14c348fee4fd988d36cf3aee7207737861bac611de991" - ) - # test failure when using public derivation - with pytest.raises(TrezorFailure): - btc.get_public_node(client, [H_(111), 42], ecdsa_curve_name="ed25519") diff --git a/tests/device_tests/test_msg_loaddevice.py b/tests/device_tests/test_msg_loaddevice.py index 06bf70c59c..0b48ea46f1 100644 --- a/tests/device_tests/test_msg_loaddevice.py +++ b/tests/device_tests/test_msg_loaddevice.py @@ -16,13 +16,14 @@ import pytest -from trezorlib import btc, debuglink, device +from trezorlib import debuglink, device from trezorlib.messages import BackupType from ..common import ( MNEMONIC12, MNEMONIC_SLIP39_ADVANCED_20, MNEMONIC_SLIP39_BASIC_20_3of6, + test_address, ) @@ -41,8 +42,8 @@ class TestDeviceLoad: assert state.pin is None assert state.passphrase_protection is False - address = btc.get_address(client, "Bitcoin", []) - assert address == "1EfKbQupktEMXf4gujJ9kCFo83k1iMqwqK" + address = test_address(client) + assert address == "mkqRFzxmkCGX9jxgpqqFHcxRUmLJcLDBer" def test_load_device_2(self, client): debuglink.load_device( @@ -61,8 +62,8 @@ class TestDeviceLoad: assert state.pin == "1234" assert state.passphrase_protection is True - address = btc.get_address(client, "Bitcoin", []) - assert address == "15fiTDFwZd2kauHYYseifGi9daH2wniDHH" + address = test_address(client) + assert address == "mx77VZjTVixVsU7nCtAKHnGFdsyNCnsWWw" @pytest.mark.skip_t1 def test_load_device_slip39_basic(self, client): @@ -115,7 +116,7 @@ class TestDeviceLoad: skip_checksum=True, ) client.use_passphrase(passphrase_nfkd) - address_nfkd = btc.get_address(client, "Bitcoin", []) + address_nfkd = test_address(client) device.wipe(client) debuglink.load_device( @@ -128,7 +129,7 @@ class TestDeviceLoad: skip_checksum=True, ) client.use_passphrase(passphrase_nfc) - address_nfc = btc.get_address(client, "Bitcoin", []) + address_nfc = test_address(client) device.wipe(client) debuglink.load_device( @@ -141,7 +142,7 @@ class TestDeviceLoad: skip_checksum=True, ) client.use_passphrase(passphrase_nfkc) - address_nfkc = btc.get_address(client, "Bitcoin", []) + address_nfkc = test_address(client) device.wipe(client) debuglink.load_device( @@ -154,7 +155,7 @@ class TestDeviceLoad: skip_checksum=True, ) client.use_passphrase(passphrase_nfd) - address_nfd = btc.get_address(client, "Bitcoin", []) + address_nfd = test_address(client) assert address_nfkd == address_nfc assert address_nfkd == address_nfkc diff --git a/tests/device_tests/test_msg_signmessage.py b/tests/device_tests/test_msg_signmessage.py index c438773e69..220f27de9e 100644 --- a/tests/device_tests/test_msg_signmessage.py +++ b/tests/device_tests/test_msg_signmessage.py @@ -14,86 +14,195 @@ # You should have received a copy of the License along with this library. # If not, see . -import base64 import pytest -from trezorlib import btc +from trezorlib import btc, messages from trezorlib.tools import parse_path -from ..common import MNEMONIC12 +S = messages.InputScriptType -class TestMsgSignmessage: - @pytest.mark.setup_client(mnemonic=MNEMONIC12) - def test_sign(self, client): - sig = btc.sign_message( - client, "Bitcoin", [0], "This is an example of a signed message." - ) - assert sig.address == "14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e" - assert ( - sig.signature.hex() - == "209e23edf0e4e47ff1dec27f32cd78c50e74ef018ee8a6adf35ae17c7a9b0dd96f48b493fd7dbab03efb6f439c6383c9523b3bbc5f1a7d158a6af90ab154e9be80" - ) +def case(id, *args, altcoin=False): + if altcoin: + marks = pytest.mark.altcoin + else: + marks = () + return pytest.param(*args, id=id, marks=marks) - @pytest.mark.setup_client(mnemonic=MNEMONIC12) - def test_sign_testnet(self, client): - sig = btc.sign_message( - client, "Testnet", [0], "This is an example of a signed message." - ) - assert sig.address == "mirio8q3gtv7fhdnmb3TpZ4EuafdzSs7zL" - assert ( - sig.signature.hex() - == "209e23edf0e4e47ff1dec27f32cd78c50e74ef018ee8a6adf35ae17c7a9b0dd96f48b493fd7dbab03efb6f439c6383c9523b3bbc5f1a7d158a6af90ab154e9be80" - ) - @pytest.mark.altcoin - @pytest.mark.setup_client(mnemonic=MNEMONIC12) - def test_sign_bch(self, client): - sig = btc.sign_message( - client, "Bcash", [0], "This is an example of a signed message." - ) - assert sig.address == "bitcoincash:qqj22md58nm09vpwsw82fyletkxkq36zxyxh322pru" - assert ( - sig.signature.hex() - == "209e23edf0e4e47ff1dec27f32cd78c50e74ef018ee8a6adf35ae17c7a9b0dd96f48b493fd7dbab03efb6f439c6383c9523b3bbc5f1a7d158a6af90ab154e9be80" - ) +MESSAGE_NFKD = u"Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a" +MESSAGE_NFC = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f" +NFKD_NFC_SIGNATURE = "2046a0b46e81492f82e0412c73701b9740e6462c603575ee2d36c7d7b4c20f0f33763ca8cb3027ea8e1ce5e83fda8b6746fea8f5c82655d78fd419e7c766a5e17a" - @pytest.mark.altcoin - def test_sign_grs(self, client): - sig = btc.sign_message( - client, "Groestlcoin", parse_path("44'/17'/0'/0/0"), "test" - ) - assert sig.address == "Fj62rBJi8LvbmWu2jzkaUX1NFXLEqDLoZM" - assert ( - base64.b64encode(sig.signature) - == b"INOYaa/jj8Yxz3mD5k+bZfUmjkjB9VzoV4dNG7+RsBUyK30xL7I9yMgWWVvsL46C5yQtxtZY0cRRk7q9N6b+YTM=" - ) +VECTORS = ( # case name, coin_name, path, script_type, address, message, signature + # ==== Bitcoin script types ==== + case( + "p2pkh", + "Bitcoin", + "44h/0h/0h/0/0", + S.SPENDADDRESS, + "1JAd7XCBzGudGpJQSDSfpmJhiygtLQWaGL", + "This is an example of a signed message.", + "20fd8f2f7db5238fcdd077d5204c3e6949c261d700269cefc1d9d2dcef6b95023630ee617f6c8acf9eb40c8edd704c9ca74ea4afc393f43f35b4e8958324cbdd1c", + ), + case( + "segwit-p2sh", + "Bitcoin", + "49h/0h/0h/0/0", + S.SPENDP2SHWITNESS, + "3L6TyTisPBmrDAj6RoKmDzNnj4eQi54gD2", + "This is an example of a signed message.", + "23744de4516fac5c140808015664516a32fead94de89775cec7e24dbc24fe133075ac09301c4cc8e197bea4b6481661d5b8e9bf19d8b7b8a382ecdb53c2ee0750d", + ), + case( + "segwit-native", + "Bitcoin", + "84h/0h/0h/0/0", + S.SPENDWITNESS, + "bc1qannfxke2tfd4l7vhepehpvt05y83v3qsf6nfkk", + "This is an example of a signed message.", + "28b55d7600d9e9a7e2a49155ddf3cfdb8e796c207faab833010fa41fb7828889bc47cf62348a7aaa0923c0832a589fab541e8f12eb54fb711c90e2307f0f66b194", + ), + # ==== Bitcoin with long message ==== + case( + "p2pkh long message", + "Bitcoin", + "44h/0h/0h/0/0", + S.SPENDADDRESS, + "1JAd7XCBzGudGpJQSDSfpmJhiygtLQWaGL", + "VeryLongMessage!" * 64, + "200a46476ceb84d06ef5784828026f922c8815f57aac837b8c013007ca8a8460db63ef917dbebaebd108b1c814bbeea6db1f2b2241a958e53fe715cc86b199d9c3", + ), + case( + "segwit-p2sh long message", + "Bitcoin", + "49h/0h/0h/0/0", + S.SPENDP2SHWITNESS, + "3L6TyTisPBmrDAj6RoKmDzNnj4eQi54gD2", + "VeryLongMessage!" * 64, + "236eadee380684f70749c52141c8aa7c3b6afd84d0e5f38cfa71823f3b1105a5f34e23834a5bb6f239ff28ad87f409f44e4ce6269754adc00388b19507a5d9386f", + ), + case( + "segwit-native long message", + "Bitcoin", + "84h/0h/0h/0/0", + S.SPENDWITNESS, + "bc1qannfxke2tfd4l7vhepehpvt05y83v3qsf6nfkk", + "VeryLongMessage!" * 64, + "28c6f86e255eaa768c447d635d91da01631ac54af223c2c182d4fa3676cfecae4a199ad33a74fe04fb46c39432acb8d83de74da90f5f01123b3b7d8bc252bc7f71", + ), + # ==== NFKD vs NFC message - signatures must be identical ==== + case( + "NFKD message", + "Bitcoin", + "44h/0h/0h/0/1", + S.SPENDADDRESS, + "1GWFxtwWmNVqotUPXLcKVL2mUKpshuJYo", + MESSAGE_NFKD, + NFKD_NFC_SIGNATURE, + ), + case( + "NFC message", + "Bitcoin", + "44h/0h/0h/0/1", + S.SPENDADDRESS, + "1GWFxtwWmNVqotUPXLcKVL2mUKpshuJYo", + MESSAGE_NFC, + NFKD_NFC_SIGNATURE, + ), + # ==== Testnet script types ==== + case( + "p2pkh", + "Testnet", + "44h/1h/0h/0/0", + S.SPENDADDRESS, + "mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q", + "This is an example of a signed message.", + "2030cd7f116c0481d1936cfef48137fd23ee56aaf00787bfa08a94837466ec9909390c3efacfc56bae5782f1db4cf49ae05f242b5f62a47f871ec46bf1a3253e7f", + ), + case( + "segwit-p2sh", + "Testnet", + "49h/1h/0h/0/0", + S.SPENDP2SHWITNESS, + "2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp", + "This is an example of a signed message.", + "23ef39fd388c3425d6aaa04274dcd5c7dd4c283a411b616443474fbcde5dd966050d91bc7c57e9578f28efdd84c9a9bcba415f93c5727b5d3f2bf3de46d7084896", + ), + case( + "segwit-native", + "Testnet", + "84h/1h/0h/0/0", + S.SPENDWITNESS, + "tb1qkvwu9g3k2pdxewfqr7syz89r3gj557l3uuf9r9", + "This is an example of a signed message.", + "27758b3393396ad9fe48f6ce81f63410145e7b2b69a5dfc1d48b5e6e623e91e08e3afb60bda1546f9c6f9fb5bd0a41887b784c266036dd4b4015a0abc1137daa1d", + ), + # ==== Altcoins ==== + case( + "bcash", + "Bcash", + "44h/145h/0h/0/0", + S.SPENDADDRESS, + "bitcoincash:qr08q88p9etk89wgv05nwlrkm4l0urz4cyl36hh9sv", + "This is an example of a signed message.", + "1fda7733e666a4ab8ba86f3cfc3728d318ecf824a3bf99597570297aa131607c10316959136b2c500b2b478a73c563ba314c0b7b2a22065b6d9596118f246d360e", + altcoin=True, + ), + case( + "grs-p2pkh", + "Groestlcoin", + "44h/17h/0h/0/0", + S.SPENDADDRESS, + "Fj62rBJi8LvbmWu2jzkaUX1NFXLEqDLoZM", + "test", + "20d39869afe38fc631cf7983e64f9b65f5268e48c1f55ce857874d1bbf91b015322b7d312fb23dc8c816595bec2f8e82e7242dc6d658d1c45193babd37a6fe6133", + altcoin=True, + ), + case( + "grs-segwit-p2sh", + "Groestlcoin", + "49h/17h/0h/0/0", + S.SPENDP2SHWITNESS, + "31inaRqambLsd9D7Ke4USZmGEVd3PHkh7P", + "test", + "23f340fc9f9ea6469e13dbc743b70313e4d076bcd8ce867eddd71ec41160d02a4a462205d21ec6e49502bf3e2a8463d48e895ca56f6b385b15ec2cc7556292ecae", + altcoin=True, + ), + case( + "grs-segwit-native", + "Groestlcoin", + "84h/17h/0h/0/0", + S.SPENDWITNESS, + "grs1qw4teyraux2s77nhjdwh9ar8rl9dt7zww8r6lne", + "test", + "288253db4b4a1d5dac059296385310a353ef80992c4777a44133a335d12d3444da6c287d32aec4071ec49ae327e208f89ba0a115a129f106221c8dd5590fd3df13", + altcoin=True, + ), + case( + "decred", + "Decred", + "44h/42h/0h/0/0", + S.SPENDADDRESS, + "DsZtHtXHwvNR3nWf1PqfxrEdnRJisKEyzp1", + "This is an example of a signed message.", + "206b1f8ba47ef9eaf87aa900e41ab1e97f67e8c09292faa4acf825228d074c4b774484046dcb1d9bbf0603045dbfb328c3e1b0c09c5ae133e89e604a67a1fc6cca", + altcoin=True, + ), +) - @pytest.mark.setup_client(mnemonic=MNEMONIC12) - def test_sign_long(self, client): - sig = btc.sign_message(client, "Bitcoin", [0], "VeryLongMessage!" * 64) - assert sig.address == "14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e" - assert ( - sig.signature.hex() - == "205ff795c29aef7538f8b3bdb2e8add0d0722ad630a140b6aefd504a5a895cbd867cbb00981afc50edd0398211e8d7c304bb8efa461181bc0afa67ea4a720a89ed" - ) - @pytest.mark.setup_client(mnemonic=MNEMONIC12) - def test_sign_utf(self, client): - words_nfkd = u"Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a" - words_nfc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f" - - sig_nfkd = btc.sign_message(client, "Bitcoin", [0], words_nfkd) - assert sig_nfkd.address == "14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e" - assert ( - sig_nfkd.signature.hex() - == "20d0ec02ed8da8df23e7fe9e680e7867cc290312fe1c970749d8306ddad1a1eda41c6a771b13d495dd225b13b0a9d0f915a984ee3d0703f92287bf8009fbb9f7d6" - ) - - sig_nfc = btc.sign_message(client, "Bitcoin", [0], words_nfc) - assert sig_nfc.address == "14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e" - assert ( - sig_nfc.signature.hex() - == "20d0ec02ed8da8df23e7fe9e680e7867cc290312fe1c970749d8306ddad1a1eda41c6a771b13d495dd225b13b0a9d0f915a984ee3d0703f92287bf8009fbb9f7d6" - ) +@pytest.mark.parametrize( + "coin_name, path, script_type, address, message, signature", VECTORS +) +def test_signmessage(client, coin_name, path, script_type, address, message, signature): + sig = btc.sign_message( + client, + coin_name=coin_name, + n=parse_path(path), + script_type=script_type, + message=message, + ) + assert sig.address == address + assert sig.signature.hex() == signature diff --git a/tests/device_tests/test_msg_signmessage_decred.py b/tests/device_tests/test_msg_signmessage_decred.py deleted file mode 100644 index ae43ad3669..0000000000 --- a/tests/device_tests/test_msg_signmessage_decred.py +++ /dev/null @@ -1,84 +0,0 @@ -# This file is part of the Trezor project. -# -# Copyright (C) 2012-2019 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 . - -import pytest - -from trezorlib import btc -from trezorlib.tools import parse_path - -from ..common import MNEMONIC12 - - -@pytest.mark.altcoin -@pytest.mark.decred -class TestMsgSignmessageDecred: - @pytest.mark.setup_client(mnemonic=MNEMONIC12) - def test_sign_mainnet(self, client): - address_n = parse_path("m/44'/42'/0'/0/0") - sig = btc.sign_message( - client, "Decred", address_n, "This is an example of a signed message." - ) - assert sig.address == "DsbjnfJrnL1orxJBCN8Kf39NjMwEktdfdWy" - assert ( - sig.signature.hex() - == "20417ee6116304a65d267aec989a1450ed3699201cc0f2a6e8273a3ad31dfb3cda26a5b26f040aa3d0d76c66d6d7c1d1e5e424c1298b3ba1201c36a0a87971ed83" - ) - - @pytest.mark.setup_client(mnemonic=MNEMONIC12) - def test_sign_testnet(self, client): - address_n = parse_path("m/44'/1'/0'/0/0") - sig = btc.sign_message( - client, - "Decred Testnet", - address_n, - "This is an example of a signed message.", - ) - assert sig.address == "TsRQTRqf5TdEfqsnJ1gcQEDvPP363cEjr4B" - assert ( - sig.signature.hex() - == "20260e5665cca98e0a08ebf33346a0e1cdb7ef313d0c50d1403f5c1ea7ef5958204c9a3f3ad3fa793456365b1b3ca700c7299099646813b43dcad6249ba77a469f" - ) - - @pytest.mark.setup_client(mnemonic=MNEMONIC12) - def test_sign_long(self, client): - address_n = parse_path("m/44'/42'/0'/0/0") - sig = btc.sign_message(client, "Decred", address_n, "VeryLongMessage!" * 64) - assert sig.address == "DsbjnfJrnL1orxJBCN8Kf39NjMwEktdfdWy" - assert ( - sig.signature.hex() - == "1f4ce0f81b387d6c9ce3961baf9ae10c2fe14a2d13243ec5863131d526c77d4459636ba71217a47726ecf7517bde41e3ef95a3de10054ff88bbf8ca5cb0b5f3cea" - ) - - @pytest.mark.setup_client(mnemonic=MNEMONIC12) - def test_sign_utf(self, client): - address_n = parse_path("m/44'/42'/0'/0/0") - - words_nfkd = u"Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a" - words_nfc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f" - - sig_nfkd = btc.sign_message(client, "Decred", address_n, words_nfkd) - assert sig_nfkd.address == "DsbjnfJrnL1orxJBCN8Kf39NjMwEktdfdWy" - assert ( - sig_nfkd.signature.hex() - == "1feb2e6eeabe6508fff655c7c3aa7b52098b09e01c9f0cfae404bd4d7baf856e762b72a4c13a8f826b7a42c0b48a5a1b12a96497ca90bd2b183e42f4b3d4eea16b" - ) - - sig_nfc = btc.sign_message(client, "Decred", address_n, words_nfc) - assert sig_nfc.address == "DsbjnfJrnL1orxJBCN8Kf39NjMwEktdfdWy" - assert ( - sig_nfc.signature.hex() - == "1feb2e6eeabe6508fff655c7c3aa7b52098b09e01c9f0cfae404bd4d7baf856e762b72a4c13a8f826b7a42c0b48a5a1b12a96497ca90bd2b183e42f4b3d4eea16b" - ) diff --git a/tests/device_tests/test_msg_signmessage_segwit.py b/tests/device_tests/test_msg_signmessage_segwit.py deleted file mode 100644 index 69948dcbd0..0000000000 --- a/tests/device_tests/test_msg_signmessage_segwit.py +++ /dev/null @@ -1,117 +0,0 @@ -# This file is part of the Trezor project. -# -# Copyright (C) 2012-2019 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 . - -import base64 - -import pytest - -from trezorlib import btc, messages as proto -from trezorlib.tools import parse_path - -from ..common import MNEMONIC12 - - -class TestMsgSignmessageSegwit: - @pytest.mark.setup_client(mnemonic=MNEMONIC12) - def test_sign(self, client): - sig = btc.sign_message( - client, - "Bitcoin", - [0], - "This is an example of a signed message.", - script_type=proto.InputScriptType.SPENDP2SHWITNESS, - ) - assert sig.address == "3CwYaeWxhpXXiHue3ciQez1DLaTEAXcKa1" - assert ( - sig.signature.hex() - == "249e23edf0e4e47ff1dec27f32cd78c50e74ef018ee8a6adf35ae17c7a9b0dd96f48b493fd7dbab03efb6f439c6383c9523b3bbc5f1a7d158a6af90ab154e9be80" - ) - - @pytest.mark.setup_client(mnemonic=MNEMONIC12) - def test_sign_testnet(self, client): - sig = btc.sign_message( - client, - "Testnet", - [0], - "This is an example of a signed message.", - script_type=proto.InputScriptType.SPENDP2SHWITNESS, - ) - assert sig.address == "2N4VkePSzKH2sv5YBikLHGvzUYvfPxV6zS9" - assert ( - sig.signature.hex() - == "249e23edf0e4e47ff1dec27f32cd78c50e74ef018ee8a6adf35ae17c7a9b0dd96f48b493fd7dbab03efb6f439c6383c9523b3bbc5f1a7d158a6af90ab154e9be80" - ) - - @pytest.mark.altcoin - def test_sign_grs(self, client): - sig = btc.sign_message( - client, - "Groestlcoin", - parse_path("49'/17'/0'/0/0"), - "test", - script_type=proto.InputScriptType.SPENDP2SHWITNESS, - ) - assert sig.address == "31inaRqambLsd9D7Ke4USZmGEVd3PHkh7P" - assert ( - base64.b64encode(sig.signature) - == b"I/NA/J+epkaeE9vHQ7cDE+TQdrzYzoZ+3dcexBFg0CpKRiIF0h7G5JUCvz4qhGPUjolcpW9rOFsV7CzHVWKS7K4=" - ) - - @pytest.mark.setup_client(mnemonic=MNEMONIC12) - def test_sign_long(self, client): - sig = btc.sign_message( - client, - "Bitcoin", - [0], - "VeryLongMessage!" * 64, - script_type=proto.InputScriptType.SPENDP2SHWITNESS, - ) - assert sig.address == "3CwYaeWxhpXXiHue3ciQez1DLaTEAXcKa1" - assert ( - sig.signature.hex() - == "245ff795c29aef7538f8b3bdb2e8add0d0722ad630a140b6aefd504a5a895cbd867cbb00981afc50edd0398211e8d7c304bb8efa461181bc0afa67ea4a720a89ed" - ) - - @pytest.mark.setup_client(mnemonic=MNEMONIC12) - def test_sign_utf(self, client): - words_nfkd = u"Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a" - words_nfc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f" - - sig_nfkd = btc.sign_message( - client, - "Bitcoin", - [0], - words_nfkd, - script_type=proto.InputScriptType.SPENDP2SHWITNESS, - ) - assert sig_nfkd.address == "3CwYaeWxhpXXiHue3ciQez1DLaTEAXcKa1" - assert ( - sig_nfkd.signature.hex() - == "24d0ec02ed8da8df23e7fe9e680e7867cc290312fe1c970749d8306ddad1a1eda41c6a771b13d495dd225b13b0a9d0f915a984ee3d0703f92287bf8009fbb9f7d6" - ) - - sig_nfc = btc.sign_message( - client, - "Bitcoin", - [0], - words_nfc, - script_type=proto.InputScriptType.SPENDP2SHWITNESS, - ) - assert sig_nfc.address == "3CwYaeWxhpXXiHue3ciQez1DLaTEAXcKa1" - assert ( - sig_nfc.signature.hex() - == "24d0ec02ed8da8df23e7fe9e680e7867cc290312fe1c970749d8306ddad1a1eda41c6a771b13d495dd225b13b0a9d0f915a984ee3d0703f92287bf8009fbb9f7d6" - ) diff --git a/tests/device_tests/test_msg_signmessage_segwit_native.py b/tests/device_tests/test_msg_signmessage_segwit_native.py deleted file mode 100644 index b50493a343..0000000000 --- a/tests/device_tests/test_msg_signmessage_segwit_native.py +++ /dev/null @@ -1,117 +0,0 @@ -# This file is part of the Trezor project. -# -# Copyright (C) 2012-2019 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 . - -import base64 - -import pytest - -from trezorlib import btc, messages as proto -from trezorlib.tools import parse_path - -from ..common import MNEMONIC12 - - -class TestMsgSignmessageSegwitNative: - @pytest.mark.setup_client(mnemonic=MNEMONIC12) - def test_sign(self, client): - sig = btc.sign_message( - client, - "Bitcoin", - [0], - "This is an example of a signed message.", - script_type=proto.InputScriptType.SPENDWITNESS, - ) - assert sig.address == "bc1qyjjkmdpu7metqt5r36jf872a34syws33s82q2j" - assert ( - sig.signature.hex() - == "289e23edf0e4e47ff1dec27f32cd78c50e74ef018ee8a6adf35ae17c7a9b0dd96f48b493fd7dbab03efb6f439c6383c9523b3bbc5f1a7d158a6af90ab154e9be80" - ) - - @pytest.mark.setup_client(mnemonic=MNEMONIC12) - def test_sign_testnet(self, client): - sig = btc.sign_message( - client, - "Testnet", - [0], - "This is an example of a signed message.", - script_type=proto.InputScriptType.SPENDWITNESS, - ) - assert sig.address == "tb1qyjjkmdpu7metqt5r36jf872a34syws336p3n3p" - assert ( - sig.signature.hex() - == "289e23edf0e4e47ff1dec27f32cd78c50e74ef018ee8a6adf35ae17c7a9b0dd96f48b493fd7dbab03efb6f439c6383c9523b3bbc5f1a7d158a6af90ab154e9be80" - ) - - @pytest.mark.altcoin - def test_sign_grs(self, client): - sig = btc.sign_message( - client, - "Groestlcoin", - parse_path("84'/17'/0'/0/0"), - "test", - script_type=proto.InputScriptType.SPENDWITNESS, - ) - assert sig.address == "grs1qw4teyraux2s77nhjdwh9ar8rl9dt7zww8r6lne" - assert ( - base64.b64encode(sig.signature) - == b"KIJT20tKHV2sBZKWOFMQo1PvgJksR3ekQTOjNdEtNETabCh9Mq7EBx7EmuMn4gj4m6ChFaEp8QYiHI3VWQ/T3xM=" - ) - - @pytest.mark.setup_client(mnemonic=MNEMONIC12) - def test_sign_long(self, client): - sig = btc.sign_message( - client, - "Bitcoin", - [0], - "VeryLongMessage!" * 64, - script_type=proto.InputScriptType.SPENDWITNESS, - ) - assert sig.address == "bc1qyjjkmdpu7metqt5r36jf872a34syws33s82q2j" - assert ( - sig.signature.hex() - == "285ff795c29aef7538f8b3bdb2e8add0d0722ad630a140b6aefd504a5a895cbd867cbb00981afc50edd0398211e8d7c304bb8efa461181bc0afa67ea4a720a89ed" - ) - - @pytest.mark.setup_client(mnemonic=MNEMONIC12) - def test_sign_utf(self, client): - words_nfkd = u"Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a" - words_nfc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f" - - sig_nfkd = btc.sign_message( - client, - "Bitcoin", - [0], - words_nfkd, - script_type=proto.InputScriptType.SPENDWITNESS, - ) - assert sig_nfkd.address == "bc1qyjjkmdpu7metqt5r36jf872a34syws33s82q2j" - assert ( - sig_nfkd.signature.hex() - == "28d0ec02ed8da8df23e7fe9e680e7867cc290312fe1c970749d8306ddad1a1eda41c6a771b13d495dd225b13b0a9d0f915a984ee3d0703f92287bf8009fbb9f7d6" - ) - - sig_nfc = btc.sign_message( - client, - "Bitcoin", - [0], - words_nfc, - script_type=proto.InputScriptType.SPENDWITNESS, - ) - assert sig_nfc.address == "bc1qyjjkmdpu7metqt5r36jf872a34syws33s82q2j" - assert ( - sig_nfc.signature.hex() - == "28d0ec02ed8da8df23e7fe9e680e7867cc290312fe1c970749d8306ddad1a1eda41c6a771b13d495dd225b13b0a9d0f915a984ee3d0703f92287bf8009fbb9f7d6" - ) diff --git a/tests/device_tests/test_msg_signtx.py b/tests/device_tests/test_msg_signtx.py index b49f9df871..1322125752 100644 --- a/tests/device_tests/test_msg_signtx.py +++ b/tests/device_tests/test_msg_signtx.py @@ -18,7 +18,7 @@ import pytest from trezorlib import btc, messages as proto from trezorlib.exceptions import TrezorFailure -from trezorlib.tools import H_, btc_hash, parse_path +from trezorlib.tools import H_, parse_path, tx_hash from ..common import MNEMONIC12 from ..tx_cache import TxCache @@ -74,13 +74,12 @@ TXHASH_2bac7a = bytes.fromhex( class TestMsgSigntx: - @pytest.mark.setup_client(mnemonic=MNEMONIC12) def test_one_one_fee(self, client): # tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882 # input 0: 0.0039 BTC inp1 = proto.TxInputType( - address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e + address_n=parse_path("44h/0h/0h/0/0"), # amount=390000, prev_hash=TXHASH_d5f65e, prev_index=0, @@ -92,12 +91,10 @@ class TestMsgSigntx: script_type=proto.OutputScriptType.PAYTOADDRESS, ) - trezor_core = client.features.model != "1" with client: client.set_expected_responses( [ request_input(0), - (trezor_core, proto.ButtonRequest(code=B.UnknownDerivationPath)), request_meta(TXHASH_d5f65e), request_input(0, TXHASH_d5f65e), request_input(1, TXHASH_d5f65e), @@ -116,10 +113,9 @@ class TestMsgSigntx: client, "Bitcoin", [inp1], [out1], prev_txes=TX_CACHE_MAINNET ) - # Accepted by network: tx fd79435246dee76b2f159d2db08032d666c95adc544de64c8c49f474df4a7fee assert ( - serialized_tx.hex() - == "010000000182488650ef25a58fef6788bd71b8212038d7f2bbe4750bc7bcb44701e85ef6d5000000006b4830450221009a0b7be0d4ed3146ee262b42202841834698bb3ee39c24e7437df208b8b7077102202b79ab1e7736219387dffe8d615bbdba87e11477104b867ef47afed1a5ede7810121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff0160cc0500000000001976a914de9b2a8da088824e8fe51debea566617d851537888ac00000000" + tx_hash(serialized_tx).hex() + == "f6b22f324894c708e32d340a60af670c8accb3b62d05906d31e60ae49696c0c3" ) def test_testnet_one_two_fee(self, client): @@ -175,12 +171,11 @@ class TestMsgSigntx: == "0100000001cd3b93f5b24ae190ce5141235091cd93fbb2908e24e5b9ff6776aec11b0e04e5000000006b483045022100eba3bbcbb82ab1ebac88a394e8fb53b0263dadbb3e8072f0a21ee62818c911060220686a9b7f306d028b54a228b5c47cc6c27b1d01a3b0770440bcc64d55d8bace2c0121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0ffffffff021023cb01000000001976a91485eb47fe98f349065d6f044e27a4ac541af79ee288aca0bb0d00000000001976a9143d3cca567e00a04819742b21a696a67da796498b88ac00000000" ) - @pytest.mark.setup_client(mnemonic=MNEMONIC12) def test_testnet_fee_too_high(self, client): # tx: 6f90f3c7cbec2258b0971056ef3fe34128dbde30daa9c0639a898f9977299d54 # input 1: 10.00000000 BTC inp1 = proto.TxInputType( - address_n=[0], # mirio8q3gtv7fhdnmb3TpZ4EuafdzSs7zL + address_n=parse_path("44'/1'/0'/0/0"), # amount=1000000000, prev_hash=TXHASH_6f90f3, prev_index=1, @@ -193,17 +188,15 @@ class TestMsgSigntx: ) out2 = proto.TxOutputType( - address_n=[2], + address_n=parse_path("44'/1'/0'/1/0"), amount=500000000, script_type=proto.OutputScriptType.PAYTOADDRESS, ) - trezor_core = client.features.model != "1" with client: client.set_expected_responses( [ request_input(0), - (trezor_core, proto.ButtonRequest(code=B.UnknownDerivationPath)), request_meta(TXHASH_6f90f3), request_input(0, TXHASH_6f90f3), request_input(1, TXHASH_6f90f3), @@ -212,7 +205,6 @@ class TestMsgSigntx: request_output(0), proto.ButtonRequest(code=B.ConfirmOutput), request_output(1), - proto.ButtonRequest(code=B.ConfirmOutput), proto.ButtonRequest(code=B.FeeOverThreshold), proto.ButtonRequest(code=B.SignTx), request_input(0), @@ -228,8 +220,8 @@ class TestMsgSigntx: ) assert ( - serialized_tx.hex() - == "0100000001549d2977998f899a63c0a9da30dedb2841e33fef561097b05822eccbc7f3906f010000006a47304402205ea68e9d52d4be14420ccecf7f2e11489d49b86bedb79ee99b5e9b7188884150022056219cb3384a5df8048cca286a9533403dbda1571afd84b51379cdaee6a6dea80121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff020084d717000000001976a9140223b1a09138753c9cb0baf95a0a62c82711567a88ac0065cd1d000000001976a9142db345c36563122e2fd0f5485fb7ea9bbf7cb5a288ac00000000" + tx_hash(serialized_tx).hex() + == "c669527e0d80dc645925f6965e1622e71fa5ca51e284442c4620c1ade7a76c63" ) def test_one_two_fee(self, client): @@ -287,13 +279,12 @@ class TestMsgSigntx: == "01000000016d20f69067ad1ffd50ee7c0f377dde2c932ccb03e84b5659732da99c20f1f650010000006a47304402203429bd3ce7b38c5c1e8a15340edd79ced41a2939aae62e259d2e3d18e0c5ee7602201b83b10ebc4d6dcee3f9eb42ba8f1ef8a059a05397e0c1b9223d1565a3e6ec01012102a7a079c1ef9916b289c2ff21a992c808d0de3dfcf8a9f163205c5c9e21f55d5cffffffff0230750000000000001976a914954820f1de627a703596ac0396f986d958e3de4c88ac10270000000000001976a91405427736705cfbfaff76b1cff48283707fb1037088ac00000000" ) - @pytest.mark.setup_client(mnemonic=MNEMONIC12) def test_one_three_fee(self, client): # tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882 # input 0: 0.0039 BTC inp1 = proto.TxInputType( - address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e + address_n=parse_path("44'/0'/0'/0/0"), # amount=390000, prev_hash=TXHASH_d5f65e, prev_index=0, @@ -312,15 +303,15 @@ class TestMsgSigntx: ) out3 = proto.TxOutputType( - address_n=[1], amount=80000, script_type=proto.OutputScriptType.PAYTOADDRESS + address_n=parse_path("44'/0'/0'/1/0"), + amount=80000, + script_type=proto.OutputScriptType.PAYTOADDRESS, ) - trezor_core = client.features.model != "1" with client: client.set_expected_responses( [ request_input(0), - (trezor_core, proto.ButtonRequest(code=B.UnknownDerivationPath)), request_meta(TXHASH_d5f65e), request_input(0, TXHASH_d5f65e), request_input(1, TXHASH_d5f65e), @@ -330,7 +321,6 @@ class TestMsgSigntx: request_output(1), proto.ButtonRequest(code=B.ConfirmOutput), request_output(2), - proto.ButtonRequest(code=B.ConfirmOutput), proto.ButtonRequest(code=B.SignTx), request_input(0), request_output(0), @@ -351,11 +341,10 @@ class TestMsgSigntx: ) assert ( - serialized_tx.hex() - == "010000000182488650ef25a58fef6788bd71b8212038d7f2bbe4750bc7bcb44701e85ef6d5000000006b483045022100e695e2c530c7c0fc32e6b79b7cff56a7f70a8c9da787534f46b4204070f914fc02207b0879a81408a11e23b11d4c7965c62b5fc6d5c2d92340f5ee2da7b40e99314a0121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff0300650400000000001976a914de9b2a8da088824e8fe51debea566617d851537888ace02e0000000000001976a9141fe1d337fb81afca42818051e12fd18245d1b17288ac80380100000000001976a9140223b1a09138753c9cb0baf95a0a62c82711567a88ac00000000" + tx_hash(serialized_tx).hex() + == "fedbba83b115725a713c2b1a13db09fd33de582132d520a3f6ff72503ca5da61" ) - @pytest.mark.setup_client(mnemonic=MNEMONIC12) def test_two_two(self, client): # tx: c6be22d34946593bcad1d2b013e12f74159e69574ffea21581dad115572e031c # input 1: 0.0010 BTC @@ -363,14 +352,14 @@ class TestMsgSigntx: # input 1: 0.0011 BTC inp1 = proto.TxInputType( - address_n=[1], # 1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb + address_n=parse_path("44h/0h/0h/0/0"), # amount=100000, prev_hash=TXHASH_c6be22, prev_index=1, ) inp2 = proto.TxInputType( - address_n=[2], # 15AeAhtNJNKyowK8qPHwgpXkhsokzLtUpG + address_n=parse_path("44h/0h/0h/0/1"), # amount=110000, prev_hash=TXHASH_58497a, prev_index=1, @@ -383,23 +372,20 @@ class TestMsgSigntx: ) out2 = proto.TxOutputType( - address_n=[3], # 1CmzyJp9w3NafXMSEFH4SLYUPAVCSUrrJ5 + address_n=parse_path("44h/0h/0h/1/0"), amount=100000, script_type=proto.OutputScriptType.PAYTOADDRESS, ) - trezor_core = client.features.model != "1" with client: client.set_expected_responses( [ request_input(0), - (trezor_core, proto.ButtonRequest(code=B.UnknownDerivationPath)), request_meta(TXHASH_c6be22), request_input(0, TXHASH_c6be22), request_output(0, TXHASH_c6be22), request_output(1, TXHASH_c6be22), request_input(1), - (trezor_core, proto.ButtonRequest(code=B.UnknownDerivationPath)), request_meta(TXHASH_58497a), request_input(0, TXHASH_58497a), request_output(0, TXHASH_58497a), @@ -407,7 +393,6 @@ class TestMsgSigntx: request_output(0), proto.ButtonRequest(code=B.ConfirmOutput), request_output(1), - proto.ButtonRequest(code=B.ConfirmOutput), proto.ButtonRequest(code=B.SignTx), request_input(0), request_input(1), @@ -434,11 +419,10 @@ class TestMsgSigntx: # The transaction was produced before Trezor implemented BIP-66, so the signature # is now different and txhash doesn't match what is on the blockchain. assert ( - serialized_tx.hex() - == "01000000021c032e5715d1da8115a2fe4f57699e15742fe113b0d2d1ca3b594649d322bec6010000006b483045022100f773c403b2f85a5c1d6c9c4ad69c43de66930fff4b1bc818eb257af98305546a0220443bde4be439f276a6ce793664b463580e210ec6c9255d68354449ac0443c76501210338d78612e990f2eea0c426b5e48a8db70b9d7ed66282b3b26511e0b1c75515a6ffffffff6ea42cd8d9c8e5441c4c5f85bfe50311078730d2881494f11f4d2257777a4958010000006b48304502210090cff1c1911e771605358a8cddd5ae94c7b60cc96e50275908d9bf9d6367c79f02202bfa72e10260a146abd59d0526e1335bacfbb2b4401780e9e3a7441b0480c8da0121038caebd6f753bbbd2bb1f3346a43cd32140648583673a31d62f2dfb56ad0ab9e3ffffffff02a0860100000000001976a9142f4490d5263906e4887ca2996b9e207af3e7824088aca0860100000000001976a914812c13d97f9159e54e326b481b8f88a73df8507a88ac00000000" + tx_hash(serialized_tx).hex() + == "6f9775545830731a316a4c2a39515b1890e9c8ab0f9e21e7c6a6ca2c1499116d" ) - @pytest.mark.setup_client(mnemonic=MNEMONIC12) @pytest.mark.skip_ui @pytest.mark.slow def test_lots_of_inputs(self, client): @@ -448,7 +432,7 @@ class TestMsgSigntx: for i in range(100): inputs.append( proto.TxInputType( - address_n=[4], # 1NwN6UduuVkJi6sw3gSiKZaCY5rHgVXC2h + address_n=parse_path(f"44h/0h/0h/0/{i}"), prev_hash=TXHASH_4a7b7e, prev_index=i, ) @@ -461,14 +445,11 @@ class TestMsgSigntx: _, serialized_tx = btc.sign_tx( client, "Bitcoin", inputs, [out], prev_txes=TX_CACHE_MAINNET ) - # Accepted by network: tx 23d9d8eecf3abf6c0f0f3f8b0976a04792d7f1c9a4ea9b0a8931734949e27c92 - # too big put in unit test, only check hash assert ( - btc_hash(serialized_tx)[::-1].hex() - == "23d9d8eecf3abf6c0f0f3f8b0976a04792d7f1c9a4ea9b0a8931734949e27c92" + tx_hash(serialized_tx).hex() + == "f90cdc2224366312be28166e2afe198ece7a60e86e25f5a50f5b14d811713da8" ) - @pytest.mark.setup_client(mnemonic=MNEMONIC12) @pytest.mark.skip_ui @pytest.mark.slow def test_lots_of_outputs(self, client): @@ -480,14 +461,14 @@ class TestMsgSigntx: # index 1: 0.0254 BTC inp1 = proto.TxInputType( - address_n=[3], # 1CmzyJp9w3NafXMSEFH4SLYUPAVCSUrrJ5 + address_n=parse_path("44h/0h/1h/0/0"), # amount=100000, prev_hash=TXHASH_c63e24, prev_index=1, ) inp2 = proto.TxInputType( - address_n=[3], # 1CmzyJp9w3NafXMSEFH4SLYUPAVCSUrrJ5 + address_n=parse_path("44h/0h/1h/0/1"), # amount=2540000, prev_hash=TXHASH_39a29e, prev_index=1, @@ -508,20 +489,16 @@ class TestMsgSigntx: ) assert ( - serialized_tx.hex() - == "0100000002fb792f470a58993e14964c9bd46cdf37cb4bbc3f61540cb651580c82ed243ec6010000006b483045022100969da46f94a81f34f3717b014e0c3e1826eda1b0022ec2f9ce39f3d750ab9235022026da269770993211a1503413566a339bbb4389a482fffcf8e1f76713fc3b94f5012103477b9f0f34ae85434ce795f0c5e1e90c9420e5b5fad084d7cce9a487b94a7902ffffffffe56582d2119100cb1d3da8232291e053f71e25fb669c87b32a667749959ea239010000006a473044022052e1419bb237b9db400ab5e3df16db6355619d545fde9030924a360763ae9ad40220704beab04d72ecaeb42eca7d98faca7a0941e65f2e1341f183be2b83e6b09e1c012103477b9f0f34ae85434ce795f0c5e1e90c9420e5b5fad084d7cce9a487b94a7902fffffffffdff00" - + "d8270000000000001976a914f0a2b64e56ee2ff57126232f84af6e3a41d4055088ac" - * cnt - + "00000000" + tx_hash(serialized_tx).hex() + == "aa0cfe57938b71db47a3992b25d4bee39f258a5de513c907727b982478648a7d" ) - @pytest.mark.setup_client(mnemonic=MNEMONIC12) def test_fee_too_high(self, client): # tx: 1570416eb4302cf52979afd5e6909e37d8fdd874301f7cc87e547e509cb1caa6 # input 0: 1.0 BTC inp1 = proto.TxInputType( - address_n=[0], # 1HWDaLTpTCTtRWyWqZkzWx1wex5NKyncLW + address_n=parse_path("44h/0h/0h/0/0"), # amount=100000000, prev_hash=TXHASH_157041, prev_index=0, @@ -533,12 +510,10 @@ class TestMsgSigntx: script_type=proto.OutputScriptType.PAYTOADDRESS, ) - trezor_core = client.features.model != "1" with client: client.set_expected_responses( [ request_input(0), - (trezor_core, proto.ButtonRequest(code=B.UnknownDerivationPath)), request_meta(TXHASH_157041), request_input(0, TXHASH_157041), request_output(0, TXHASH_157041), @@ -558,17 +533,16 @@ class TestMsgSigntx: ) assert ( - serialized_tx.hex() - == "0100000001a6cab19c507e547ec87c1f3074d8fdd8379e90e6d5af7929f52c30b46e417015000000006b483045022100dc3531da7feb261575f03b5b9bbb35edc7f73bb081c92538827105de4102737002200161e34395f6a8ee93979200cb974fa75ccef6d7c14021511cf468eece90d6450121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff01d018ee05000000001976a914de9b2a8da088824e8fe51debea566617d851537888ac00000000" + tx_hash(serialized_tx).hex() + == "c36928aca6452d50cb63e2592200bbcc3722ce6b631b1dfd185ccdf9a954af28" ) - @pytest.mark.setup_client(mnemonic=MNEMONIC12) def test_not_enough_funds(self, client): # tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882 # input 0: 0.0039 BTC inp1 = proto.TxInputType( - address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e + address_n=parse_path("44h/0h/0h/0/0"), # amount=390000, prev_hash=TXHASH_d5f65e, prev_index=0, @@ -580,12 +554,10 @@ class TestMsgSigntx: script_type=proto.OutputScriptType.PAYTOADDRESS, ) - trezor_core = client.features.model != "1" with client: client.set_expected_responses( [ request_input(0), - (trezor_core, proto.ButtonRequest(code=B.UnknownDerivationPath)), request_meta(TXHASH_d5f65e), request_input(0, TXHASH_d5f65e), request_input(1, TXHASH_d5f65e), @@ -600,10 +572,9 @@ class TestMsgSigntx: client, "Bitcoin", [inp1], [out1], prev_txes=TX_CACHE_MAINNET ) - @pytest.mark.setup_client(mnemonic=MNEMONIC12) def test_p2sh(self, client): inp1 = proto.TxInputType( - address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e + address_n=parse_path("44h/0h/0h/0/0"), # amount=400000, prev_hash=TXHASH_54aa56, prev_index=1, @@ -615,12 +586,10 @@ class TestMsgSigntx: script_type=proto.OutputScriptType.PAYTOSCRIPTHASH, ) - trezor_core = client.features.model != "1" with client: client.set_expected_responses( [ request_input(0), - (trezor_core, proto.ButtonRequest(code=B.UnknownDerivationPath)), request_meta(TXHASH_54aa56), request_input(0, TXHASH_54aa56), request_output(0, TXHASH_54aa56), @@ -638,10 +607,9 @@ class TestMsgSigntx: client, "Bitcoin", [inp1], [out1], prev_txes=TX_CACHE_MAINNET ) - # Accepted by network: tx 8cc1f4adf7224ce855cf535a5104594a0004cb3b640d6714fdb00b9128832dd5 assert ( - serialized_tx.hex() - == "0100000001a3fb2d38322c3b327e54005cebc0686d52fcdf536e53bb5ef481a7de8056aa54010000006b4830450221009e020b0390ccad533b73b552f8a99a9d827212c558e4f755503674d07c92ad4502202d606f7316990e0461c51d4add25054f19c697aa3e3c2ced4d568f0b2c57e62f0121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff0170f305000000000017a9147f844bdb0b8fd54b64e3d16c85dc1170f1ff97c18700000000" + tx_hash(serialized_tx).hex() + == "5042aed319b9f018d693dbf8f3db926ee4ab4dae670a2911625b440a1366f79d" ) def test_testnet_big_amount(self, client): @@ -672,14 +640,14 @@ class TestMsgSigntx: @pytest.mark.setup_client(mnemonic=MNEMONIC12) def test_attack_change_outputs(self, client): inp1 = proto.TxInputType( - address_n=[1], # 1CK7SJdcb8z9HuvVft3D91HLpLC6KSsGb + address_n=parse_path("44h/0h/0h/0/0"), # amount=100000, prev_hash=TXHASH_c6be22, prev_index=1, ) inp2 = proto.TxInputType( - address_n=[2], # 15AeAhtNJNKyowK8qPHwgpXkhsokzLtUpG + address_n=parse_path("44h/0h/0h/0/1"), # amount=110000, prev_hash=TXHASH_58497a, prev_index=1, @@ -692,7 +660,7 @@ class TestMsgSigntx: ) out2 = proto.TxOutputType( - address_n=[3], # 1CmzyJp9w3NafXMSEFH4SLYUPAVCSUrrJ5 + address_n=parse_path("44h/0h/0h/1/0"), amount=100000, script_type=proto.OutputScriptType.PAYTOADDRESS, ) @@ -702,10 +670,9 @@ class TestMsgSigntx: client, "Bitcoin", [inp1, inp2], [out1, out2], prev_txes=TX_CACHE_MAINNET ) - # Accepted by network: tx c63e24ed820c5851b60c54613fbc4bcb37df6cd49b4c96143e99580a472f79fb assert ( - serialized_tx.hex() - == "01000000021c032e5715d1da8115a2fe4f57699e15742fe113b0d2d1ca3b594649d322bec6010000006b483045022100f773c403b2f85a5c1d6c9c4ad69c43de66930fff4b1bc818eb257af98305546a0220443bde4be439f276a6ce793664b463580e210ec6c9255d68354449ac0443c76501210338d78612e990f2eea0c426b5e48a8db70b9d7ed66282b3b26511e0b1c75515a6ffffffff6ea42cd8d9c8e5441c4c5f85bfe50311078730d2881494f11f4d2257777a4958010000006b48304502210090cff1c1911e771605358a8cddd5ae94c7b60cc96e50275908d9bf9d6367c79f02202bfa72e10260a146abd59d0526e1335bacfbb2b4401780e9e3a7441b0480c8da0121038caebd6f753bbbd2bb1f3346a43cd32140648583673a31d62f2dfb56ad0ab9e3ffffffff02a0860100000000001976a9142f4490d5263906e4887ca2996b9e207af3e7824088aca0860100000000001976a914812c13d97f9159e54e326b481b8f88a73df8507a88ac00000000" + tx_hash(serialized_tx).hex() + == "4601b738e1b0f8a7ff9ca5adf0c896fa39dfe8b8ead7ad0d716c98167e8a5d11" ) run_attack = False @@ -859,10 +826,9 @@ class TestMsgSigntx: "Transaction has changed during signing" ) - @pytest.mark.setup_client(mnemonic=MNEMONIC12) def test_spend_coinbase(self, client): inp1 = proto.TxInputType( - address_n=[1], # mfiGQVPcRcaEvQPYDErR34DcCovtxYvUUV + address_n=parse_path("44h/1h/0h/0/0"), # amount=390000, prev_hash=TXHASH_d6da21, prev_index=0, @@ -874,12 +840,10 @@ class TestMsgSigntx: script_type=proto.OutputScriptType.PAYTOADDRESS, ) - trezor_core = client.features.model != "1" with client: client.set_expected_responses( [ request_input(0), - (trezor_core, proto.ButtonRequest(code=B.UnknownDerivationPath)), request_meta(TXHASH_d6da21), request_input(0, TXHASH_d6da21), request_output(0, TXHASH_d6da21), @@ -898,8 +862,8 @@ class TestMsgSigntx: # Accepted by network: tx assert ( - serialized_tx.hex() - == "010000000136825bfdb78c8ede226c7c4f25a018e99a2c061d63c7fb425fca7c7d6721dad6000000006a473044022047845c366eb24f40be315c7815a154513c444c7989eb80f7ce7ff6aeb703d26a022007c1f5efadf67c5889634fd7ac39a7ce78bffac291673e8772ecd8389c901d9f01210338d78612e990f2eea0c426b5e48a8db70b9d7ed66282b3b26511e0b1c75515a6ffffffff01c6100795000000001976a9143d2496e67f5f57a924353da42d4725b318e7a8ea88ac00000000" + tx_hash(serialized_tx).hex() + == "cf5a8ad5a4f0211953e0d40d9145d6651f0d90203e52913e780065bd00840da3" ) def test_two_changes(self, client): @@ -1027,10 +991,16 @@ class TestMsgSigntx: assert len(prev_tx.bin_outputs) == 2 # vout[0] and vout[1] exist - inp0 = proto.TxInputType(address_n=[0], prev_hash=TXHASH_157041, prev_index=0) - inp1 = proto.TxInputType(address_n=[0], prev_hash=TXHASH_157041, prev_index=1) + inp0 = proto.TxInputType( + address_n=parse_path("44h/0h/0h/0/0"), prev_hash=TXHASH_157041, prev_index=0 + ) + inp1 = proto.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(address_n=[0], prev_hash=TXHASH_157041, prev_index=2) + inp2 = proto.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( @@ -1056,7 +1026,9 @@ class TestMsgSigntx: ) @pytest.mark.skip_ui def test_prevtx_forbidden_fields(self, client, field, value): - inp0 = proto.TxInputType(address_n=[0], prev_hash=TXHASH_157041, prev_index=0) + inp0 = proto.TxInputType( + address_n=parse_path("44h/0h/0h/0/0"), prev_hash=TXHASH_157041, prev_index=0 + ) out1 = proto.TxOutputType( address="1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1", amount=1000, @@ -1076,7 +1048,9 @@ class TestMsgSigntx: @pytest.mark.parametrize("field, value", (("expiry", 9), ("timestamp", 42))) @pytest.mark.skip_ui def test_signtx_forbidden_fields(self, client, field, value): - inp0 = proto.TxInputType(address_n=[0], prev_hash=TXHASH_157041, prev_index=0) + inp0 = proto.TxInputType( + address_n=parse_path("44h/0h/0h/0/0"), prev_hash=TXHASH_157041, prev_index=0 + ) out1 = proto.TxOutputType( address="1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1", amount=1000, @@ -1107,7 +1081,7 @@ class TestMsgSigntx: multisig = proto.MultisigRedeemScriptType( m=1, nodes=[ - btc.get_public_node(client, address_n).node, + btc.get_public_node(client, address_n, coin_name="Testnet").node, proto.HDNodeType( depth=0, fingerprint=0, @@ -1159,7 +1133,7 @@ class TestMsgSigntx: multisig = proto.MultisigRedeemScriptType( m=1, nodes=[ - btc.get_public_node(client, address_n).node, + btc.get_public_node(client, address_n, coin_name="Testnet").node, proto.HDNodeType( depth=0, fingerprint=0, diff --git a/tests/device_tests/test_msg_signtx_bcash.py b/tests/device_tests/test_msg_signtx_bcash.py index d95c945723..9b20be92e9 100644 --- a/tests/device_tests/test_msg_signtx_bcash.py +++ b/tests/device_tests/test_msg_signtx_bcash.py @@ -301,7 +301,9 @@ class TestMsgSigntxBch: @pytest.mark.multisig def test_send_bch_multisig_wrongchange(self, client): nodes = [ - btc.get_public_node(client, parse_path("48'/145'/%d'" % i)).node + btc.get_public_node( + client, parse_path(f"48'/145'/{i}'"), coin_name="Bcash" + ).node for i in range(1, 4) ] @@ -374,7 +376,9 @@ class TestMsgSigntxBch: @pytest.mark.multisig def test_send_bch_multisig_change(self, client): nodes = [ - btc.get_public_node(client, parse_path("48'/145'/%d'" % i)).node + btc.get_public_node( + client, parse_path(f"48'/145'/{i}'"), coin_name="Bcash" + ).node for i in range(1, 4) ] diff --git a/tests/device_tests/test_msg_signtx_bgold.py b/tests/device_tests/test_msg_signtx_bgold.py index 3ec4ca6302..59acf1326a 100644 --- a/tests/device_tests/test_msg_signtx_bgold.py +++ b/tests/device_tests/test_msg_signtx_bgold.py @@ -179,7 +179,9 @@ class TestMsgSigntxBitcoinGold: @pytest.mark.multisig def test_send_btg_multisig_change(self, client): nodes = [ - btc.get_public_node(client, parse_path("48'/156'/%d'" % i)).node + btc.get_public_node( + client, parse_path(f"48'/156'/{i}'"), coin_name="Bgold" + ).node for i in range(1, 4) ] @@ -356,7 +358,9 @@ class TestMsgSigntxBitcoinGold: @pytest.mark.multisig def test_send_multisig_1(self, client): nodes = [ - btc.get_public_node(client, parse_path("49'/156'/%d'" % i)).node + btc.get_public_node( + client, parse_path(f"49'/156'/{i}'"), coin_name="Bgold" + ).node for i in range(1, 4) ] multisig = proto.MultisigRedeemScriptType( diff --git a/tests/device_tests/test_msg_signtx_prevhash.py b/tests/device_tests/test_msg_signtx_prevhash.py index 17e3c9b6f1..22957a254e 100644 --- a/tests/device_tests/test_msg_signtx_prevhash.py +++ b/tests/device_tests/test_msg_signtx_prevhash.py @@ -3,7 +3,7 @@ from io import BytesIO import pytest -from trezorlib import btc, messages +from trezorlib import btc, messages, tools from trezorlib.exceptions import TrezorFailure from ..tx_cache import TxCache @@ -77,7 +77,7 @@ def _check_error_message(value: bytes, model: str, message: str): @pytest.mark.parametrize("prev_hash", (None, b"", b"x", b"hello world", b"x" * 33)) def test_invalid_prev_hash(client, prev_hash): inp1 = messages.TxInputType( - address_n=[0], + address_n=tools.parse_path("m/44h/0h/0h/0/0"), amount=123456789, prev_hash=prev_hash, prev_index=0, @@ -99,7 +99,7 @@ def test_invalid_prev_hash(client, prev_hash): def test_invalid_prev_hash_attack(client, prev_hash): # prepare input with a valid prev-hash inp1 = messages.TxInputType( - address_n=[0], + address_n=tools.parse_path("m/44h/0h/0h/0/0"), amount=123456789, prev_hash=b"\x00" * 32, prev_index=0, @@ -147,7 +147,9 @@ def test_invalid_prev_hash_in_prevtx(client, prev_hash): prev_tx.inputs[0].prev_hash = b"\x00" * 32 tx_hash = hash_tx(serialize_tx(prev_tx)) - inp0 = messages.TxInputType(address_n=[0], prev_hash=tx_hash, prev_index=0) + inp0 = messages.TxInputType( + address_n=tools.parse_path("m/44h/0h/0h/0/0"), prev_hash=tx_hash, prev_index=0 + ) out1 = messages.TxOutputType( address="1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1", amount=1000, diff --git a/tests/device_tests/test_msg_signtx_segwit.py b/tests/device_tests/test_msg_signtx_segwit.py index 141d423748..18ad6d01c6 100644 --- a/tests/device_tests/test_msg_signtx_segwit.py +++ b/tests/device_tests/test_msg_signtx_segwit.py @@ -159,7 +159,9 @@ class TestMsgSigntxSegwit: @pytest.mark.multisig def test_send_multisig_1(self, client): nodes = [ - btc.get_public_node(client, parse_path("49'/1'/%d'" % i)).node + btc.get_public_node( + client, parse_path(f"49'/1'/{i}'"), coin_name="Testnet" + ).node for i in range(1, 4) ] diff --git a/tests/device_tests/test_msg_signtx_segwit_native.py b/tests/device_tests/test_msg_signtx_segwit_native.py index 2d2eb19c6c..0c28817ed7 100644 --- a/tests/device_tests/test_msg_signtx_segwit_native.py +++ b/tests/device_tests/test_msg_signtx_segwit_native.py @@ -329,7 +329,9 @@ class TestMsgSigntxSegwitNative: @pytest.mark.multisig def test_send_multisig_1(self, client): nodes = [ - btc.get_public_node(client, parse_path("49'/1'/%d'" % index)) + btc.get_public_node( + client, parse_path(f"49'/1'/{index}'"), coin_name="Testnet" + ) for index in range(1, 4) ] multisig = proto.MultisigRedeemScriptType( @@ -398,7 +400,9 @@ class TestMsgSigntxSegwitNative: @pytest.mark.multisig def test_send_multisig_2(self, client): nodes = [ - btc.get_public_node(client, parse_path("84'/1'/%d'" % index)) + btc.get_public_node( + client, parse_path(f"84'/1'/{index}'"), coin_name="Testnet" + ) for index in range(1, 4) ] multisig = proto.MultisigRedeemScriptType( @@ -467,7 +471,9 @@ class TestMsgSigntxSegwitNative: @pytest.mark.multisig def test_send_multisig_3_change(self, client): nodes = [ - btc.get_public_node(client, parse_path("84'/1'/%d'" % index)) + btc.get_public_node( + client, parse_path(f"84'/1'/{index}'"), coin_name="Testnet" + ) for index in range(1, 4) ] multisig = proto.MultisigRedeemScriptType( @@ -542,7 +548,9 @@ class TestMsgSigntxSegwitNative: @pytest.mark.multisig def test_send_multisig_4_change(self, client): nodes = [ - btc.get_public_node(client, parse_path("49'/1'/%d'" % index)) + btc.get_public_node( + client, parse_path(f"49'/1'/{index}'"), coin_name="Testnet" + ) for index in range(1, 4) ] multisig = proto.MultisigRedeemScriptType( diff --git a/tests/device_tests/test_multisig.py b/tests/device_tests/test_multisig.py index b25dba7010..d534aee85c 100644 --- a/tests/device_tests/test_multisig.py +++ b/tests/device_tests/test_multisig.py @@ -18,9 +18,8 @@ import pytest from trezorlib import btc, messages as proto from trezorlib.exceptions import TrezorFailure -from trezorlib.tools import parse_path +from trezorlib.tools import parse_path, tx_hash -from .. import bip32 from ..common import MNEMONIC12 from ..tx_cache import TxCache from .signtx import request_finished, request_input, request_meta, request_output @@ -150,28 +149,10 @@ class TestMultisig: @pytest.mark.multisig @pytest.mark.setup_client(mnemonic=MNEMONIC12) def test_15_of_15(self, client): - """ - pubs = [] - for x in range(15): - pubs.append(self.client.get_public_node([x]).node.public_key.hex())) - """ - - # xpub: - # print(bip32.serialize(self.client.get_public_node([]).node)) - # xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy - node = bip32.deserialize( - "xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy" - ) - - pubs = [] - for x in range(15): - pubs.append(proto.HDNodePathType(node=node, address_n=[x])) - - # redeeemscript - # 5f21023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43d210338d78612e990f2eea0c426b5e48a8db70b9d7ed66282b3b26511e0b1c75515a621038caebd6f753bbbd2bb1f3346a43cd32140648583673a31d62f2dfb56ad0ab9e32103477b9f0f34ae85434ce795f0c5e1e90c9420e5b5fad084d7cce9a487b94a79022103fe91eca10602d7dad4c9dab2b2a0858f71e25a219a6940749ce7a48118480dae210234716c01c2dd03fa7ee302705e2b8fbd1311895d94b1dca15e62eedea9b0968f210341fb2ead334952cf60f4481ba435c4693d0be649be01d2cfe9b02018e483e7bd2102dad8b2bce360a705c16e74a50a36459b4f8f4b78f9cd67def29d54ef6f7c7cf9210222dbe3f5f197a34a1d50e2cbe2a1085cac2d605c9e176f9a240e0fd0c669330d2103fb41afab56c9cdb013fda63d777d4938ddc3cb2ad939712da688e3ed333f95982102435f177646bdc717cb3211bf46656ca7e8d642726144778c9ce816b8b8c36ccf2102158d8e20095364031d923c7e9f7f08a14b1be1ddee21fe1a5431168e31345e5521026259794892428ca0818c8fb61d2d459ddfe20e57f50803c7295e6f4e2f5586652102815f910a8689151db627e6e262e0a2075ad5ec2993a6bc1b876a9d420923d681210318f54647f645ff01bd49fedc0219343a6a22d3ea3180a3c3d3097e4b888a8db45fae - - # multisig address - # 3QaKF8zobqcqY8aS6nxCD5ZYdiRfL3RCmU + node = btc.get_public_node( + client, parse_path("48h/0h/1h/0"), coin_name="Bitcoin" + ).node + pubs = [proto.HDNodePathType(node=node, address_n=[x]) for x in range(15)] signatures = [b""] * 15 @@ -187,7 +168,7 @@ class TestMultisig: ) inp1 = proto.TxInputType( - address_n=[x], + address_n=parse_path(f"48h/0h/1h/0/{x}"), prev_hash=TXHASH_6189e3, prev_index=1, script_type=proto.InputScriptType.SPENDMULTISIG, @@ -200,18 +181,17 @@ class TestMultisig: ) signatures[x] = sig[0] - # Accepted as tx id dd320786d1f58c095be0509dc56b277b6de8f2fb5517f519c6e6708414e3300b assert ( - serialized_tx.hex() - == "01000000011553ef34c683f4d6a8d346844409e6e7fc4ff01eaa25b7e8ce215abbfee3896101000000fd43060048304502210098e23085ad7282de988bf98afa1e9add9c9830009132f8902a9fa4624d5dc98b0220733216e70ab67791aa64be5c83d2050cb4ed9ff7eda2a1acc35da024d2ab2a670147304402201f8c11fb6e90fd616e484986e9451929797eba039882a9abcc203210948060b9022044da031530de7d9747d3c5a8e7cec04b04b7af495c9120b854ce7362af7fa05a01483045022100ea67c70186acef019bdf1551881bf38e6f88186501b64d3a756a2ce18e4ba18002201c35110325653e21e448b60053a4b5dda46b61096faf701a1faca61fcde91f00014730440220315598992f156d2f9d7b4275395fa067aa61ea95829fa17730885c86df4de70d02203eda9ade1656e2198c668603b17e197acb0969ed183ab0841303ea261205618901473044022060fdd6621edde9b8cf6776bc4eef26ace9b57514d725b7214ba11d333520a30e022044c30744f94484aec0f896233c5613a3256878ec0379f566226906b6d1b6061401483045022100b1d907e3574f60f7834c7e9f2e367998ce0461dad7d742d84ef8917d713f41f902203b3ac54f7bb2f7fb8685f582d2a94f7213a37cb508acffe29090cc06ae01588b01483045022100e3bf90ff3ad6395e42f46002f253f94ca0e8ffaa0620f2ceb4fa21493abdca4d02201d4c28b10b740bb2dc4b3695b4205c18f8c0dad2bb69540eb8a36576463cd5280147304402202cfaf9fab7dc1c9f0c3c23bd46bd6d5cea0664d914139fc9add80766ce998808022012db2802c07853e4cbe147afdf0b47e60bdcbcd31f9df19e04c177ed9aa66c6d0147304402207cbc2d83f351eee5ee91df26bb0c7e1cb07fe328cbbcdb0bb9656d37922c497302201b3435d4c71ffd1b34d45892f2a487bd79c8c7f57cc04373287642bb9610cb840147304402202dc3eab30ccb06553703e794212f43ee9a659f5e787a8374e9ea0bf6de0def7402201a70e970c21a807783313ed102bf4f0a3406ac7c84f94bc8194c5e209464d7230147304402206b04530c190c46a879d7771a6ad53acd33547e0d7fd320d5ad0b5b1fdeb5d4c202207b812be81c3419daadc942cca0c55aa32c7759fa7566c6dc35f030ca87a1c5be01483045022100ce523dddd6eef73d5ae7c44c870466e1ac5a7a77d43475e8def024af68977a1e022028be0276435bfa2ea887d6cf89fa829f96c1c7a55edc57bb3fd667d523fd3bf601473044022019410b20ebcd8eb3ee7ec1eff6bf0f9cbfaea82116811c61f3cf24af7e4434b1022009e5823f3349f695be09ae40754185300d8442a22715ddb5ffa17c4213140e7201483045022100964ef26a9074c3cdafffcfbe4bd445933f8c842ba11fd887922adcf7fabe0c82022023055d94c75ab223c767fbaa825c917e9beecbc7d5758cccf20d886c63d4b72a0147304402207aa3a98197697d258a8baae681f0b4c0ee682982f4205534e6c95a37dabaddd60220517a7ed5c03da2f242e17ccfdae0d81d6f454d7f9ea931fc62df6c0eab922186014d01025f21023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43d210338d78612e990f2eea0c426b5e48a8db70b9d7ed66282b3b26511e0b1c75515a621038caebd6f753bbbd2bb1f3346a43cd32140648583673a31d62f2dfb56ad0ab9e32103477b9f0f34ae85434ce795f0c5e1e90c9420e5b5fad084d7cce9a487b94a79022103fe91eca10602d7dad4c9dab2b2a0858f71e25a219a6940749ce7a48118480dae210234716c01c2dd03fa7ee302705e2b8fbd1311895d94b1dca15e62eedea9b0968f210341fb2ead334952cf60f4481ba435c4693d0be649be01d2cfe9b02018e483e7bd2102dad8b2bce360a705c16e74a50a36459b4f8f4b78f9cd67def29d54ef6f7c7cf9210222dbe3f5f197a34a1d50e2cbe2a1085cac2d605c9e176f9a240e0fd0c669330d2103fb41afab56c9cdb013fda63d777d4938ddc3cb2ad939712da688e3ed333f95982102435f177646bdc717cb3211bf46656ca7e8d642726144778c9ce816b8b8c36ccf2102158d8e20095364031d923c7e9f7f08a14b1be1ddee21fe1a5431168e31345e5521026259794892428ca0818c8fb61d2d459ddfe20e57f50803c7295e6f4e2f5586652102815f910a8689151db627e6e262e0a2075ad5ec2993a6bc1b876a9d420923d681210318f54647f645ff01bd49fedc0219343a6a22d3ea3180a3c3d3097e4b888a8db45faeffffffff0110270000000000001976a9144a087d89f8ad16ca029c675b037c02fd1c5f9aec88ac00000000" + tx_hash(serialized_tx).hex() + == "3bffdb495711c57b0e2cd4e0dbd0ddbccf28052aa67466eafa2d4f666e797e5f" ) @pytest.mark.multisig @pytest.mark.setup_client(mnemonic=MNEMONIC12) def test_missing_pubkey(self, client): - node = bip32.deserialize( - "xpub661MyMwAqRbcF1zGijBb2K6x9YiJPh58xpcCeLvTxMX6spkY3PcpJ4ABcCyWfskq5DDxM3e6Ez5ePCqG5bnPUXR4wL8TZWyoDaUdiWW7bKy" - ) + node = btc.get_public_node( + client, parse_path("48h/0h/1h/0"), coin_name="Bitcoin" + ).node multisig = proto.MultisigRedeemScriptType( pubkeys=[ @@ -225,7 +205,7 @@ class TestMultisig: # Let's go to sign with key 10, which is NOT in pubkeys inp1 = proto.TxInputType( - address_n=[10], + address_n=parse_path("48h/0h/1h/0/10"), prev_hash=TXHASH_c6091a, prev_index=1, script_type=proto.InputScriptType.SPENDMULTISIG, @@ -264,7 +244,7 @@ class TestMultisig: multisig_fake = proto.MultisigRedeemScriptType( m=1, nodes=[ - btc.get_public_node(client, address_n).node, + btc.get_public_node(client, address_n, coin_name="Testnet").node, proto.HDNodeType( depth=0, fingerprint=0, diff --git a/tests/device_tests/test_passphrase_slip39_advanced.py b/tests/device_tests/test_passphrase_slip39_advanced.py index 4ffa1b9086..019633b3fe 100644 --- a/tests/device_tests/test_passphrase_slip39_advanced.py +++ b/tests/device_tests/test_passphrase_slip39_advanced.py @@ -16,9 +16,11 @@ import pytest -from trezorlib import btc - -from ..common import MNEMONIC_SLIP39_ADVANCED_20, MNEMONIC_SLIP39_ADVANCED_33 +from ..common import ( + MNEMONIC_SLIP39_ADVANCED_20, + MNEMONIC_SLIP39_ADVANCED_33, + test_address, +) @pytest.mark.setup_client(mnemonic=MNEMONIC_SLIP39_ADVANCED_20, passphrase=True) @@ -26,17 +28,17 @@ from ..common import MNEMONIC_SLIP39_ADVANCED_20, MNEMONIC_SLIP39_ADVANCED_33 def test_128bit_passphrase(client): """ BIP32 Root Key for passphrase TREZOR: - provided by Andrew, address calculated using Model T + provided by Andrew, address calculated via https://iancoleman.io/bip39/ xprv9s21ZrQH143K3dzDLfeY3cMp23u5vDeFYftu5RPYZPucKc99mNEddU4w99GxdgUGcSfMpVDxhnR1XpJzZNXRN1m6xNgnzFS5MwMP6QyBRKV """ assert client.features.passphrase_protection is True client.use_passphrase("TREZOR") - address = btc.get_address(client, "Bitcoin", []) - assert address == "1CX5rv2vbSV8YFAZEAdMwRVqbxxswPnSPw" + address = test_address(client) + assert address == "mkKDUMRR1CcK8eLAzCZAjKnNbCquPoWPxN" client.state = None client.clear_session() client.use_passphrase("ROZERT") - address_compare = btc.get_address(client, "Bitcoin", []) + address_compare = test_address(client) assert address != address_compare @@ -45,15 +47,15 @@ def test_128bit_passphrase(client): def test_256bit_passphrase(client): """ BIP32 Root Key for passphrase TREZOR: - provided by Andrew, address calculated using Model T + provided by Andrew, address calculated via https://iancoleman.io/bip39/ xprv9s21ZrQH143K2UspC9FRPfQC9NcDB4HPkx1XG9UEtuceYtpcCZ6ypNZWdgfxQ9dAFVeD1F4Zg4roY7nZm2LB7THPD6kaCege3M7EuS8v85c """ assert client.features.passphrase_protection is True client.use_passphrase("TREZOR") - address = btc.get_address(client, "Bitcoin", []) - assert address == "18oNx6UczHWASBQXc5XQqdSdAAZyhUwdQU" + address = test_address(client) + assert address == "mxVtGxUJ898WLzPMmy6PT1FDHD1GUCWGm7" client.state = None client.clear_session() client.use_passphrase("ROZERT") - address_compare = btc.get_address(client, "Bitcoin", []) + address_compare = test_address(client) assert address != address_compare diff --git a/tests/device_tests/test_passphrase_slip39_basic.py b/tests/device_tests/test_passphrase_slip39_basic.py index 5785d0a113..99d1204c21 100644 --- a/tests/device_tests/test_passphrase_slip39_basic.py +++ b/tests/device_tests/test_passphrase_slip39_basic.py @@ -16,9 +16,7 @@ import pytest -from trezorlib import btc - -from ..common import MNEMONIC_SLIP39_BASIC_20_3of6 +from ..common import MNEMONIC_SLIP39_BASIC_20_3of6, test_address @pytest.mark.setup_client(mnemonic=MNEMONIC_SLIP39_BASIC_20_3of6, passphrase=True) @@ -26,13 +24,13 @@ from ..common import MNEMONIC_SLIP39_BASIC_20_3of6 def test_3of6_passphrase(client): """ BIP32 Root Key for passphrase TREZOR: - provided by Andrew, address calculated using T1 + provided by Andrew, address calculated via https://iancoleman.io/bip39/ xprv9s21ZrQH143K2pMWi8jrTawHaj16uKk4CSbvo4Zt61tcrmuUDMx2o1Byzcr3saXNGNvHP8zZgXVdJHsXVdzYFPavxvCyaGyGr1WkAYG83ce """ assert client.features.passphrase_protection is True client.use_passphrase("TREZOR") - address = btc.get_address(client, "Bitcoin", []) - assert address == "18oZEMRWurCZW1FeK8sWYyXuWx2bFqEKyX" + address = test_address(client) + assert address == "mi4HXfRJAqCDyEdet5veunBvXLTKSxpuim" @pytest.mark.setup_client( @@ -46,10 +44,10 @@ def test_3of6_passphrase(client): def test_2of5_passphrase(client): """ BIP32 Root Key for passphrase TREZOR: - provided by Andrew, address calculated using T1 + provided by Andrew, address calculated via https://iancoleman.io/bip39/ xprv9s21ZrQH143K2o6EXEHpVy8TCYoMmkBnDCCESLdR2ieKwmcNG48ck2XJQY4waS7RUQcXqR9N7HnQbUVEDMWYyREdF1idQqxFHuCfK7fqFni """ assert client.features.passphrase_protection is True client.use_passphrase("TREZOR") - address = btc.get_address(client, "Bitcoin", []) - assert address == "19Fjs9AvT13Y2Nx8GtoVfADmFWnccsPinQ" + address = test_address(client) + assert address == "mjXH4pN7TtbHp3tWLqVKktKuaQeByHMoBZ" diff --git a/tests/device_tests/test_zerosig.py b/tests/device_tests/test_zerosig.py deleted file mode 100644 index 24d8d40a84..0000000000 --- a/tests/device_tests/test_zerosig.py +++ /dev/null @@ -1,78 +0,0 @@ -# This file is part of the Trezor project. -# -# Copyright (C) 2012-2019 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 . - -import pytest - -from trezorlib import btc, messages as proto - -from ..common import MNEMONIC12 -from ..tx_cache import TxCache - -TXHASH_d5f65e = bytes.fromhex( - "d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882" -) - - -# address_n = [177] < 68 -# address_n = [16518] < 66 -class TestZerosig: - @pytest.mark.setup_client(mnemonic=MNEMONIC12) - def test_one_zero_signature(self, client): - inp1 = proto.TxInputType( - address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e - # amount=390000, - prev_hash=TXHASH_d5f65e, - prev_index=0, - ) - - # Following address_n has been mined by 'test_mine_zero_signature' - out1 = proto.TxOutputType( - address_n=[177], - amount=390000 - 10000, - script_type=proto.OutputScriptType.PAYTOADDRESS, - ) - - _, serialized_tx = btc.sign_tx( - client, "Bitcoin", [inp1], [out1], prev_txes=TxCache("Bitcoin") - ) - siglen = serialized_tx[44] - - # Trezor must strip leading zero from signature - assert siglen == 67 - - @pytest.mark.setup_client(mnemonic=MNEMONIC12) - def test_two_zero_signature(self, client): - inp1 = proto.TxInputType( - address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e - # amount=390000, - prev_hash=TXHASH_d5f65e, - prev_index=0, - ) - - # Following address_n has been mined by 'test_mine_zero_signature' - out1 = proto.TxOutputType( - address_n=[16518], - amount=390000 - 10000, - script_type=proto.OutputScriptType.PAYTOADDRESS, - ) - - _, serialized_tx = btc.sign_tx( - client, "Bitcoin", [inp1], [out1], prev_txes=TxCache("Bitcoin") - ) - siglen = serialized_tx[44] - - # Trezor must strip leading zero from signature - assert siglen == 66