1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 07:28:10 +00:00

tests/sign_tx: Add device tests for transactions with external inputs in bgold, bcash and zcash.

This commit is contained in:
Andrew Kozlik 2020-06-20 19:30:26 +02:00 committed by Andrew Kozlik
parent 9cd600f79e
commit 39c0ed2ff0
5 changed files with 217 additions and 1 deletions

View File

@ -423,3 +423,61 @@ class TestMsgSigntxBch:
serialized_tx.hex()
== "0100000001a07660b10df9868df9393c9cf8962bc34f48cb2cea53b0865d2324bab8b96d8b00000000fdfd0000473044022006f239ef1f065a70873ab9d2c81a623a04ec7a37a0ec5299d3c585668f441f49022032b2f9ef13bc61230d14f6d79b9ad1bbebdf47b95e4757e9af1b1dcdf520d3ab41483045022100a05f77bb39515c21c43e6c4ba401f39ed5d409dc3cfcd90f9a8345a08cc4bc8202205faf8f3b0775748278495324fdd60f370460452e4995e546450209ec4804a0f3414c69522102f8ca0d9665af03de32a7c19a167a4f6e97e4e0ed9505f75d11f7a45ab60b1f4d2103263d87cefd687bc15b4ef7801f9f538267b66d46f18e9fccc41d54071cfdd1ce210388568bf42f02298308eb6fa2fa4b446d544600253b4409be27e2c0c1a71c424853aeffffffff02c05d0000000000001976a91400741952f6a6eab5394f366db5cc5a54b0c2429f88acc05d00000000000017a91478574751407449b97f8054be2e40e684ad07d3738700000000"
)
@pytest.mark.skip_t1
def test_send_bch_external_presigned(self, client):
inp1 = proto.TxInputType(
# address_n=parse_path("44'/145'/0'/1/0"),
# bitcoincash:qzc5q87w069lzg7g3gzx0c8dz83mn7l02scej5aluw
amount=1896050,
prev_hash=TXHASH_502e85,
prev_index=0,
script_type=proto.InputScriptType.EXTERNAL,
script_sig=bytes.fromhex(
"47304402207a2a955f1cb3dc5f03f2c82934f55654882af4e852e5159639f6349e9386ec4002205fb8419dce4e648eae8f67bc4e369adfb130a87d2ea2d668f8144213b12bb457412103174c61e9c5362507e8061e28d2c0ce3d4df4e73f3535ae0b12f37809e0f92d2d"
),
)
inp2 = proto.TxInputType(
address_n=parse_path("44'/145'/0'/0/1"),
# bitcoincash:qr23ajjfd9wd73l87j642puf8cad20lfmqdgwvpat4
amount=73452,
prev_hash=TXHASH_502e85,
prev_index=1,
script_type=proto.InputScriptType.SPENDADDRESS,
)
out1 = proto.TxOutputType(
address="bitcoincash:qq6wnnkrz7ykaqvxrx4hmjvayvzjzml54uyk76arx4",
amount=1934960,
script_type=proto.OutputScriptType.PAYTOADDRESS,
)
with client:
client.set_expected_responses(
[
request_input(0),
request_input(1),
request_meta(TXHASH_502e85),
request_input(0, TXHASH_502e85),
request_output(0, TXHASH_502e85),
request_output(1, TXHASH_502e85),
request_output(0),
proto.ButtonRequest(code=B.ConfirmOutput),
proto.ButtonRequest(code=B.SignTx),
request_input(0),
request_meta(TXHASH_502e85),
request_input(0, TXHASH_502e85),
request_output(0, TXHASH_502e85),
request_output(1, TXHASH_502e85),
request_input(0),
request_input(1),
request_output(0),
request_finished(),
]
)
_, serialized_tx = btc.sign_tx(
client, "Bcash", [inp1, inp2], [out1], prev_txes=TX_API
)
assert (
serialized_tx.hex()
== "01000000022c06cf6f215c5cbfd7caa8e71b1b32630cabf1f816a4432815b037b277852e50000000006a47304402207a2a955f1cb3dc5f03f2c82934f55654882af4e852e5159639f6349e9386ec4002205fb8419dce4e648eae8f67bc4e369adfb130a87d2ea2d668f8144213b12bb457412103174c61e9c5362507e8061e28d2c0ce3d4df4e73f3535ae0b12f37809e0f92d2dffffffff2c06cf6f215c5cbfd7caa8e71b1b32630cabf1f816a4432815b037b277852e50010000006a473044022062151cf960b71823bbe68c7ed2c2a93ad1b9706a30255fddb02fcbe056d8c26102207bad1f0872bc5f0cfaf22e45c925c35d6c1466e303163b75cb7688038f1a5541412102595caf9aeb6ffdd0e82b150739a83297358b9a77564de382671056ad9e5b8c58ffffffff0170861d00000000001976a91434e9cec317896e818619ab7dc99d2305216ff4af88ac00000000"
)

View File

@ -32,7 +32,9 @@ TXHASH_25526b = bytes.fromhex(
TXHASH_db77c2 = bytes.fromhex(
"db77c2461b840e6edbe7f9280043184a98e020d9795c1b65cb7cef2551a8fb18"
)
TXHASH_f55c5b = bytes.fromhex(
"f55c5bc925eb2a0bf9de0ac142b24bed81ec46dd2151d5f69728070eaea1aded"
)
# All data taken from T1
@pytest.mark.altcoin
@ -489,3 +491,62 @@ class TestMsgSigntxBitcoinGold:
btc_hash(serialized_tx)[::-1].hex()
== "2c64109fba890657e37f0782efda29bbc277dfd521658f185d302ddffcacffd2"
)
@pytest.mark.skip_t1
def test_send_btg_external_presigned(self, client):
inp1 = proto.TxInputType(
address_n=parse_path("44'/156'/0'/1/0"),
amount=1252382934,
prev_hash=TXHASH_25526b,
prev_index=0,
script_type=proto.InputScriptType.SPENDADDRESS,
)
inp2 = proto.TxInputType(
# address_n=parse_path("49'/156'/0'/0/0"),
# AXibjT5r96ZaVA8Lu4BQZocdTx7p5Ud8ZP
amount=58456,
prev_hash=TXHASH_f55c5b,
prev_index=0,
script_type=proto.InputScriptType.EXTERNAL,
script_sig=bytes.fromhex("1600147c5edda9b293db2c8894b9d81efd77764910c445"),
witness=bytes.fromhex(
"024730440220091eece828409b3a9aa92dd2f9b032f9fb3a12b21b323a3fdea3cb18d08249af022065412107afcf76b0d28b90188c802f8f17b41790ed81c868d0ee23f1dd2ec53441210386789a34fe1a49bfc3e174adc6706c6222b0d80de76b884a0e3d32f8e9c4dc3e"
),
)
out1 = proto.TxOutputType(
address="GfDB1tvjfm3bukeoBTtfNqrJVFohS2kCTe",
amount=1252382934 + 58456 - 1000,
script_type=proto.OutputScriptType.PAYTOADDRESS,
)
with client:
client.set_expected_responses(
[
request_input(0),
request_meta(TXHASH_25526b),
request_input(0, TXHASH_25526b),
request_output(0, TXHASH_25526b),
request_output(1, TXHASH_25526b),
request_input(1),
request_output(0),
proto.ButtonRequest(code=B.ConfirmOutput),
proto.ButtonRequest(code=B.SignTx),
request_input(1),
request_meta(TXHASH_f55c5b),
request_input(0, TXHASH_f55c5b),
request_output(0, TXHASH_f55c5b),
request_output(1, TXHASH_f55c5b),
request_input(0),
request_input(1),
request_output(0),
request_input(1),
request_finished(),
]
)
_, serialized_tx = btc.sign_tx(
client, "Bgold", [inp1, inp2], [out1], prev_txes=TX_API
)
assert (
btc_hash(serialized_tx)[::-1].hex()
== "95ebe5cdfb8dc3c112eb0107fc3bd7701689ac5ec4a74a3d12e203333d0832d3"
)

View File

@ -248,3 +248,75 @@ class TestMsgSigntxZcash:
serialized_tx.hex()
== "0400008085202f890446828054c6c81a8c370c47dc1cfd6f1b200af5623ac3d5b62501121b74ae91fb000000006b483045022100d40e85efbadd378fc603dc8b11c70774086de631fe5b1418ac2b95a478f86507022072e999d8ddd75a0b33bd2adcc88e7234e6251b9e73c9223e7c59e0d1f8d1ff220121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0ffffffffef42e249deb8e7bc1d5ec7c4590c70c5b89734b2b896c72ad6469d95190ed303000000006b483045022100917d96445d64c80f9569cb9ca45c04c9b6d7b0fda6b9fd0b1d311837366c699202202cd6140489cf38b5d97ed271ba28603f4693c2a36113cc6ec423301f077c5a8e01210294e3e5e77e22eea0e4c0d30d89beb4db7f69b4bf1ae709e411d6a06618b8f852ffffffff6cb78ae689ae1334f4b03c6f613b280c70088b963f1c965f814081d1298841f9010000006a473044022058768c74c9b1698070636388d7d2ae8223748f13b0a5f402716e4d49fc5bc5f30220658d1e6095dcfbe66669b4141d23af28c9ed5bae73480889429b41742be85f32012103f5008445568548bd745a3dedccc6048969436bf1a49411f60938ff1938941f14ffffffff0f9c2ee92a378e5399a6f2c41dce2b4af5a7119ae1bee3c8ec8eb06472e68d5d000000006b483045022100e64853d86bed039c4edce4abaf80d41486cd21c63bec79c0308ea05a351663e302206732aa22a5dee7bd7f3cc8268faebe31a08abadb4b7e3a4257509bc7baa052b60121029ad0b9519779c540b34fa8d11d24d14a5475546bfa28c7de50573d22a503ce21ffffffff01d0c7321c000000001976a91490ede9de4bed6e39008375eace793949de9a533288ac00000000000000000000000000000000000000"
)
@pytest.mark.skip_t1
def test_external_presigned(self, client):
inp1 = proto.TxInputType(
# tmQoJ3PTXgQLaRRZZYT6xk8XtjRbr2kCqwu
address_n=parse_path("m/44h/1h/0h/0/0"),
amount=300000000,
prev_hash=TXHASH_e38206,
prev_index=0,
)
inp2 = proto.TxInputType(
# tmQoJ3PTXgQLaRRZZYT6xk8XtjRbr2kCqwu
# address_n=parse_path("m/44h/1h/0h/0/0"),
amount=300000000,
prev_hash=TXHASH_aaf51e,
prev_index=1,
script_type=proto.InputScriptType.EXTERNAL,
script_sig=bytes.fromhex(
"47304402202495a38e5b368569a1a0c9fc95aa7e57a0dd5ae43f51300d7222dc139015233d022047833eaa571578f72c8468c8b537b36410388b7eb5001d75d1f4b954e1997d590121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0"
),
)
out1 = proto.TxOutputType(
address="tmJ1xYxP8XNTtCoDgvdmQPSrxh5qZJgy65Z",
amount=300000000 + 300000000 - 1940,
script_type=proto.OutputScriptType.PAYTOADDRESS,
)
with client:
client.set_expected_responses(
[
request_input(0),
request_meta(TXHASH_e38206),
request_input(0, TXHASH_e38206),
request_input(1, TXHASH_e38206),
request_output(0, TXHASH_e38206),
request_output(1, TXHASH_e38206),
request_extra_data(0, 1, TXHASH_e38206),
request_input(1),
request_output(0),
proto.ButtonRequest(code=B.ConfirmOutput),
proto.ButtonRequest(code=B.SignTx),
request_input(1),
request_meta(TXHASH_aaf51e),
request_input(0, TXHASH_aaf51e),
request_output(0, TXHASH_aaf51e),
request_output(1, TXHASH_aaf51e),
request_extra_data(0, 1, TXHASH_aaf51e),
request_input(0),
request_input(1),
request_output(0),
request_finished(),
]
)
details = proto.SignTx(
version=4, version_group_id=0x892F2085, branch_id=0x76B809BB,
)
_, serialized_tx = btc.sign_tx(
client,
"Zcash Testnet",
[inp1, inp2],
[out1],
details=details,
prev_txes=TX_API,
)
assert (
serialized_tx.hex()
== "0400008085202f890268039326c180fa7b1e999392e25a3ec6a8aec83c11b787ddb1746922020682e3000000006a473044022007efbf539f8d612d8e140c6af2289b447c34e3d36edd75d539f269fe5526878302206830f6b0398494bca09afdd967fedcd016f49468711cfcd7aafd9a128ee568d20121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0ffffffffdc754d63eff4698ee321476872519c53f14cfe58c9425c7ee464c206461ef5aa010000006a47304402202495a38e5b368569a1a0c9fc95aa7e57a0dd5ae43f51300d7222dc139015233d022047833eaa571578f72c8468c8b537b36410388b7eb5001d75d1f4b954e1997d590121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0ffffffff016c3ec323000000001976a9145b157a678a10021243307e4bb58f36375aa80e1088ac00000000000000000000000000000000000000"
)

View File

@ -0,0 +1,22 @@
{
"bin_outputs": [
{
"amount": 58456,
"script_pubkey": "a914aee37ad448e17438cabfee1756f2a08e33ed3ce887"
},
{
"amount": 18752841785,
"script_pubkey": "76a914f1cfe9b5c03516527f5d14828cfd365aa8f4114088ac"
}
],
"inputs": [
{
"prev_hash": "7ad4b613d7a437ccccca8ff49d4fabea6614fa947bb24dd2be6061d27bb49c1b",
"prev_index": 1,
"script_sig": "47304402201412b937f75af56d853acd1b5207248bbe2d7ff89e5d7e80abdef398175315370220517032f6795da73d047df568f79fd53f93f4aa04b9b367d8ef4ddeda28c84ccf412103467ca0cdba32d5396c25a578b3d761a2878e7efbf8afd29221e4d01bf435ae5c",
"sequence": 4294967295
}
],
"lock_time": 0,
"version": 2
}

View File

@ -245,6 +245,7 @@
"test_msg_signtx.py-test_two_two": "57707ecbcb77f670148c6076724b3da2e880d27ecf86e29135af4a5aeef6fdbc",
"test_msg_signtx_bcash.py-test_attack_change_input": "a03ee0471deeb54d51b73c0fde08795ab0ba8c37daec2d43f5637e705420b435",
"test_msg_signtx_bcash.py-test_send_bch_change": "a03ee0471deeb54d51b73c0fde08795ab0ba8c37daec2d43f5637e705420b435",
"test_msg_signtx_bcash.py-test_send_bch_external_presigned": "8565118d5647934c84124cb65d34f8299a98631631666dc5b1d02595d462fee0",
"test_msg_signtx_bcash.py-test_send_bch_multisig_change": "b607b039e864dc9c5f616ee6f5b780184552ff5c6b8e984ccc8eed133b3d36dd",
"test_msg_signtx_bcash.py-test_send_bch_multisig_wrongchange": "8d5c2c06f8d3dd75a03bdf6ecff865e81f8748e4ef5394d75ade3e50512ea087",
"test_msg_signtx_bcash.py-test_send_bch_nochange": "3895b874e18582ea77dea2d10ea44906fce4e67e3b7ce3118f5c959fc428d037",
@ -252,6 +253,7 @@
"test_msg_signtx_bgold.py-test_attack_change_input": "8e127323823058532b7960ef9507aa24c38c9f22055015d86fdf8132124fb727",
"test_msg_signtx_bgold.py-test_send_bitcoin_gold_change": "8e127323823058532b7960ef9507aa24c38c9f22055015d86fdf8132124fb727",
"test_msg_signtx_bgold.py-test_send_bitcoin_gold_nochange": "6a5adba8117be6e07405372866bf2ac4054d86f2cffb63d64fa0db1f8f3de500",
"test_msg_signtx_bgold.py-test_send_btg_external_presigned": "a7d857098ecde122fd23cc7b8a9193b1d69b6bd70405adb5937f6ea26cd209f1",
"test_msg_signtx_bgold.py-test_send_btg_multisig_change": "6a210a01310014a61c7df66558d48a5503b8e8b5644c404b193cefc94bb7dadb",
"test_msg_signtx_bgold.py-test_send_mixed_inputs": "6a5adba8117be6e07405372866bf2ac4054d86f2cffb63d64fa0db1f8f3de500",
"test_msg_signtx_bgold.py-test_send_multisig_1": "0a611e9cc266a5aec9017373cec013756b1715da3bf9d08281194b20ebad72d2",
@ -295,6 +297,7 @@
"test_msg_signtx_segwit_native.py-test_send_native_change": "6a13d3a2fe41cbfe42b6e3266969017152287d79a755a7cc6664580beeca3292",
"test_msg_signtx_segwit_native.py-test_send_p2sh": "0c15ccc36f6b081cab2ebb1632310cd7e02c0b4650c1d2d607cbefc252c1b9ef",
"test_msg_signtx_segwit_native.py-test_send_p2sh_change": "2a35826b696d0fcf779bc2670a588279c3beb8770c0f79a7942c22eaf6594cc2",
"test_msg_signtx_zcash.py-test_external_presigned": "539b10ad2f3a626a880b9823897ff827a6c30af1dfd041da147bf009fcec2497",
"test_msg_signtx_zcash.py-test_one_one_fee_overwinter": "112df2ad84f4a517623eed893b3be809e0ba43e6139fd70b7f94c12f28cc633c",
"test_msg_signtx_zcash.py-test_one_one_fee_sapling": "112df2ad84f4a517623eed893b3be809e0ba43e6139fd70b7f94c12f28cc633c",
"test_msg_signtx_zcash.py-test_spend_old_versions": "da64743acaead691ec617cd56886b65453f82a2e3eb78b3f9dc737dbfc4155e6",