tests: update bgold test with actual transactions

release/2020-06
matejcik 4 years ago committed by Tomas Susanka
parent 7a3637d5b0
commit 396a509725

@ -18,7 +18,7 @@ import pytest
from trezorlib import btc, messages as proto
from trezorlib.exceptions import TrezorFailure
from trezorlib.tools import H_, parse_path
from trezorlib.tools import H_, btc_hash, parse_path
from ..tx_cache import TxCache
from .signtx import request_finished, request_input, request_output
@ -32,12 +32,6 @@ TXHASH_25526b = bytes.fromhex(
TXHASH_db77c2 = bytes.fromhex(
"db77c2461b840e6edbe7f9280043184a98e020d9795c1b65cb7cef2551a8fb18"
)
TXHASH_e5040e = bytes.fromhex(
"e5040e1bc1ae7667ffb9e5248e90b2fb93cd9150234151ce90e14ab2f5933bcd"
)
TXHASH_65b811 = bytes.fromhex(
"65b811d3eca0fe6915d9f2d77c86c5a7f19bf66b1b1253c2c51cb4ae5f0c017b"
)
# All data taken from T1
@ -46,7 +40,7 @@ class TestMsgSigntxBitcoinGold:
def test_send_bitcoin_gold_change(self, client):
inp1 = proto.TxInputType(
address_n=parse_path("44'/156'/0'/0/0"),
amount=1995344,
amount=1252382934,
prev_hash=TXHASH_25526b,
prev_index=0,
script_type=proto.InputScriptType.SPENDADDRESS,
@ -58,7 +52,7 @@ class TestMsgSigntxBitcoinGold:
)
out2 = proto.TxOutputType(
address="GfDB1tvjfm3bukeoBTtfNqrJVFohS2kCTe",
amount=73452,
amount=1252382934 - 1896050 - 1000,
script_type=proto.OutputScriptType.PAYTOADDRESS,
)
with client:
@ -80,14 +74,14 @@ class TestMsgSigntxBitcoinGold:
)
assert (
serialized_tx.hex()
== "010000000185c9dd4ae1071affd77d90b9d03c1b5fdd7c62cf30a9bb8230ad766cf06b5225000000006b483045022100963904da0731b71ce468afd45366dd80fbff566ec0d39c1161ab85d17459c7ca02202f5c24a7a7272d98b14a3f5bc000c7cde8ac0eb773f20f4c3131518186cc98854121023bd0ec4022d12d0106c5b7308a25572953ba1951f576f691354a7b147ee0cc1fffffffff0272ee1c00000000001976a9141c82b9c11f193ad82413caadc0955730572b50ae88acec1e0100000000001976a914ea5f904d195079a350b534db4446433b3cec222e88ac00000000"
btc_hash(serialized_tx)[::-1].hex()
== "39a0716c361610724c7c40916baa20808cbdd7538b6c38689ce80cb73e7f51d1"
)
def test_send_bitcoin_gold_nochange(self, client):
inp1 = proto.TxInputType(
address_n=parse_path("44'/156'/0'/1/0"),
amount=1896050,
amount=1252382934,
prev_hash=TXHASH_25526b,
prev_index=0,
script_type=proto.InputScriptType.SPENDADDRESS,
@ -95,14 +89,14 @@ class TestMsgSigntxBitcoinGold:
inp2 = proto.TxInputType(
address_n=parse_path("44'/156'/0'/0/1"),
# 1LRspCZNFJcbuNKQkXgHMDucctFRQya5a3
amount=73452,
amount=38448607,
prev_hash=TXHASH_db77c2,
prev_index=1,
prev_index=0,
script_type=proto.InputScriptType.SPENDADDRESS,
)
out1 = proto.TxOutputType(
address="GfDB1tvjfm3bukeoBTtfNqrJVFohS2kCTe",
amount=1934960,
amount=1252382934 + 38448607 - 1000,
script_type=proto.OutputScriptType.PAYTOADDRESS,
)
with client:
@ -124,14 +118,14 @@ class TestMsgSigntxBitcoinGold:
)
assert (
serialized_tx.hex()
== "010000000285c9dd4ae1071affd77d90b9d03c1b5fdd7c62cf30a9bb8230ad766cf06b5225000000006b483045022100928852076c9fab160c07564cd54691af1cbc37fb28f0b7bee7299c7925ef62f0022058856387afecc6508f2f04ecdfd292a13026a5b2107ebdd2cc789bdf8820d552412102a6c3998d0d4e5197ff41aab5c53580253b3b91f583f4c31f7624be7dc83ce15fffffffff18fba85125ef7ccb651b5c79d920e0984a18430028f9e7db6e0e841b46c277db010000006b483045022100faa2f4f01cc95e680349a093923aae0aa2ea01429873555aa8a84bf630ef33a002204c3f4bf567e2d20540c0f71dc278481d6ccb6b95acda2a2f87ce521c79d6b872412102d54a7e5733b1635e5e9442943f48179b1700206b2d1925250ba10f1c86878be8ffffffff0170861d00000000001976a914ea5f904d195079a350b534db4446433b3cec222e88ac00000000"
btc_hash(serialized_tx)[::-1].hex()
== "ac9d452b900eb747d3137e1f3044bb0f46efaeb6e0fc8c27b02d1d08d238a904"
)
def test_attack_change_input(self, client):
inp1 = proto.TxInputType(
address_n=parse_path("44'/156'/11'/0/0"),
amount=1995344,
amount=1252382934,
prev_hash=TXHASH_25526b,
prev_index=0,
script_type=proto.InputScriptType.SPENDADDRESS,
@ -143,7 +137,7 @@ class TestMsgSigntxBitcoinGold:
)
out2 = proto.TxOutputType(
address="GfDB1tvjfm3bukeoBTtfNqrJVFohS2kCTe",
amount=73452,
amount=1252382934 - 1896050 - 1000,
script_type=proto.OutputScriptType.PAYTOADDRESS,
)
@ -194,7 +188,7 @@ class TestMsgSigntxBitcoinGold:
address_n=parse_path("48'/156'/3'/0/0"),
multisig=getmultisig(0, 0),
# 33Ju286QvonBz5N1V754ZekQv4GLJqcc5R
amount=48490,
amount=1252382934,
prev_hash=TXHASH_25526b,
prev_index=0,
script_type=proto.InputScriptType.SPENDMULTISIG,
@ -208,7 +202,7 @@ class TestMsgSigntxBitcoinGold:
address_n=parse_path("48'/156'/3'/1/0"),
multisig=getmultisig(1, 0),
script_type=proto.OutputScriptType.PAYTOMULTISIG,
amount=24000,
amount=1252382934 - 24000 - 1000,
)
with client:
client.set_expected_responses(
@ -230,13 +224,13 @@ class TestMsgSigntxBitcoinGold:
assert (
signatures[0].hex()
== "3045022100d954f341ddd3ec96e4bc6cdb90f2df9b2032723f85e4a0187346dd743130bfca0220105ce08b795c70dc09a55569d7874bff684a877219ec2fc37c88cdffe12f332c"
== "30440220271c46ef3d7c37bd499804128623da3aa0014f3b4447dd39c4573b23c4537f6902205329167b9eb48427af62b04bf5138295f4c38613f6ba955934d15c499bff0d8a"
)
inp1 = proto.TxInputType(
address_n=parse_path("48'/156'/1'/0/0"),
multisig=getmultisig(0, 0, [b"", b"", signatures[0]]),
amount=48490,
amount=1252382934,
prev_hash=TXHASH_25526b,
prev_index=0,
script_type=proto.InputScriptType.SPENDMULTISIG,
@ -263,17 +257,17 @@ class TestMsgSigntxBitcoinGold:
assert (
signatures[0].hex()
== "30440220614f9a18695365a2edba0d930404a77cae970d3430ad86c5b5239a96fd54bf84022030bc76a322e3b2b1c987622b5eb6da23ac1e6c905ee9b3b6405a4e4edd5bbb87"
== "3045022100bdf8c4bd14217c183612c7e8f79691f6479bcb35aa403f77d70182f58633ac6e02205b10a79b7894bb40248a120c8fcb7096a46950593e4c5b48a20bc5ebe53d85fa"
)
assert (
serialized_tx.hex()
== "010000000185c9dd4ae1071affd77d90b9d03c1b5fdd7c62cf30a9bb8230ad766cf06b522500000000fdfd00004730440220614f9a18695365a2edba0d930404a77cae970d3430ad86c5b5239a96fd54bf84022030bc76a322e3b2b1c987622b5eb6da23ac1e6c905ee9b3b6405a4e4edd5bbb8741483045022100d954f341ddd3ec96e4bc6cdb90f2df9b2032723f85e4a0187346dd743130bfca0220105ce08b795c70dc09a55569d7874bff684a877219ec2fc37c88cdffe12f332c414c695221035a8db79c0ef57a202664a3da60ca41e8865c6d86ed0aafc03f8e75173341b58021037fba152d8fca660cc49973d8bc9421ff49a75b44ea200873d70d3990f763ed4c210348cbcbd93e069416e0d5db93e86b5698852d9fd54502ad0bed9722fa83f90e4b53aeffffffff02c05d0000000000001976a914ea5f904d195079a350b534db4446433b3cec222e88acc05d00000000000017a914623c803f7fb654dac8dda7786fbf9bc38cd867f48700000000"
btc_hash(serialized_tx)[::-1].hex()
== "b45ba21b69e1e1c6ad79f5408fe70d92fb861742d239cb6a952213f60c253e40"
)
def test_send_p2sh(self, client):
inp1 = proto.TxInputType(
address_n=parse_path("49'/156'/0'/1/0"),
amount=123456789,
amount=1252382934,
prev_hash=TXHASH_25526b,
prev_index=0,
script_type=proto.InputScriptType.SPENDP2SHWITNESS,
@ -286,7 +280,7 @@ class TestMsgSigntxBitcoinGold:
out2 = proto.TxOutputType(
address="GZFLExxrvWFuFT1xRzhfwQWSE2bPDedBfn",
script_type=proto.OutputScriptType.PAYTOADDRESS,
amount=123456789 - 11000 - 12300000,
amount=1252382934 - 11000 - 12300000,
)
with client:
client.set_expected_responses(
@ -309,14 +303,14 @@ class TestMsgSigntxBitcoinGold:
)
assert (
serialized_tx.hex()
== "0100000000010185c9dd4ae1071affd77d90b9d03c1b5fdd7c62cf30a9bb8230ad766cf06b52250000000017160014b5355d001e720d8f4513da00ff2bba4dcf9d39fcffffffff02e0aebb00000000001976a914ea5f904d195079a350b534db4446433b3cec222e88ac3df39f06000000001976a914a8f757819ec6779409f45788f7b4a0e8f51ec50488ac02473044022073fcbf2876f073f78923ab427f14de5b2a0fbeb313a9b2b650b3567061f242a702202f45fc22c501108ff6222afe3aca7da9d8c7dc860f9cda335bef31fa184e7bef412102ecea08b559fc5abd009acf77cfae13fa8a3b1933e3e031956c65c12cec8ca3e300000000"
btc_hash(serialized_tx)[::-1].hex()
== "d5732fc8a594ae3b7ba695d7b276b2186f8572b0eb157120e0ba35d3511c6060"
)
def test_send_p2sh_witness_change(self, client):
inp1 = proto.TxInputType(
address_n=parse_path("49'/156'/0'/1/0"),
amount=123456789,
amount=1252382934,
prev_hash=TXHASH_25526b,
prev_index=0,
script_type=proto.InputScriptType.SPENDP2SHWITNESS,
@ -329,7 +323,7 @@ class TestMsgSigntxBitcoinGold:
out2 = proto.TxOutputType(
address_n=parse_path("49'/156'/0'/1/0"),
script_type=proto.OutputScriptType.PAYTOP2SHWITNESS,
amount=123456789 - 11000 - 12300000,
amount=1252382934 - 11000 - 12300000,
)
with client:
client.set_expected_responses(
@ -351,8 +345,8 @@ class TestMsgSigntxBitcoinGold:
)
assert (
serialized_tx.hex()
== "0100000000010185c9dd4ae1071affd77d90b9d03c1b5fdd7c62cf30a9bb8230ad766cf06b52250000000017160014b5355d001e720d8f4513da00ff2bba4dcf9d39fcffffffff02e0aebb00000000001976a914ea5f904d195079a350b534db4446433b3cec222e88ac3df39f060000000017a9140cd03822b799a452c106d1b3771844a067b17f118702483045022100d79b33384c686d8dd40ad5f84f46691d30994992c1cb42e934c2a625d86cb2f902206859805a9a98ba140b71a9d4b9a6b8df94a9424f9c40f3bd804149fd6e278d63412102ecea08b559fc5abd009acf77cfae13fa8a3b1933e3e031956c65c12cec8ca3e300000000"
btc_hash(serialized_tx)[::-1].hex()
== "eed4ef86a408602e35ae416591f349847db38cdaddef1429a9bb0e39520d100d"
)
@pytest.mark.multisig
@ -370,15 +364,15 @@ class TestMsgSigntxBitcoinGold:
inp1 = proto.TxInputType(
address_n=parse_path("49'/156'/1'/1/0"),
prev_hash=TXHASH_25526b,
prev_index=1,
prev_index=0,
script_type=proto.InputScriptType.SPENDP2SHWITNESS,
multisig=multisig,
amount=1610436,
amount=1252382934,
)
out1 = proto.TxOutputType(
address="GfDB1tvjfm3bukeoBTtfNqrJVFohS2kCTe",
amount=1605000,
amount=1252382934 - 1000,
script_type=proto.OutputScriptType.PAYTOADDRESS,
)
@ -419,30 +413,30 @@ class TestMsgSigntxBitcoinGold:
)
assert (
serialized_tx.hex()
== "0100000000010185c9dd4ae1071affd77d90b9d03c1b5fdd7c62cf30a9bb8230ad766cf06b52250100000023220020ea9ec48498c451286c2ebaf9e19255e2873b0fb517d67b2f2005298c7e437829ffffffff01887d1800000000001976a914ea5f904d195079a350b534db4446433b3cec222e88ac0400473044022077cb8b2a534f79328810ca8c330539ae9ffa086c359ddb7da11026557b04eef202201d95be0dd1da0aa01720953e52d5dabffd19a998d1490c13a21b8e52e4ead2e041483045022100e41cbd6a501ba8fe6f65554420e23e950d35af0da9b052da54a087463b0717ca02206c695c8d1f74f9535b5d89a2fd1f9326a0ef20e5400137f1e1daeee992b62b594169522103279aea0b253b144d1b2bb8532280001a996dcddd04f86e5e13df1355032cbc1321032c6465c956c0879663fa8be974c912d229c179a5cdedeb29611a1bec1f951eb22103494480a4b72101cbd2eadac8e18c7a3a7589a7f576bf46b8971c38c51e5eceeb53ae00000000"
btc_hash(serialized_tx)[::-1].hex()
== "efa5b21916ac7ea5316c38b2d7d5520d80cbe563c58304f956ea6ddb241001d1"
)
def test_send_mixed_inputs(self, client):
# First is non-segwit, second is segwit.
inp1 = proto.TxInputType(
address_n=parse_path("44'/156'/0'/0/0"),
amount=31000000,
prev_hash=TXHASH_e5040e,
address_n=parse_path("44'/156'/11'/0/0"),
amount=38448607,
prev_hash=TXHASH_db77c2,
prev_index=0,
script_type=proto.InputScriptType.SPENDADDRESS,
)
inp2 = proto.TxInputType(
address_n=parse_path("84'/156'/0'/1/0"),
amount=7289000,
prev_hash=TXHASH_65b811,
prev_index=1,
script_type=proto.InputScriptType.SPENDWITNESS,
address_n=parse_path("49'/156'/0'/1/0"),
amount=1252382934,
prev_hash=TXHASH_25526b,
prev_index=0,
script_type=proto.InputScriptType.SPENDP2SHWITNESS,
)
out1 = proto.TxOutputType(
address="GfDB1tvjfm3bukeoBTtfNqrJVFohS2kCTe",
amount=31000000 + 7289000 - 1000,
amount=38448607 + 1252382934 - 1000,
script_type=proto.OutputScriptType.PAYTOADDRESS,
)
@ -452,6 +446,6 @@ class TestMsgSigntxBitcoinGold:
)
assert (
serialized_tx.hex()
== "01000000000102cd3b93f5b24ae190ce5141235091cd93fbb2908e24e5b9ff6776aec11b0e04e5000000006a473044022061e94392fa4c0a4bf510bf713c23a37c6c5f6f4dbe5c116e86cff23a93c578e9022026661d2ffb1102d07b7c1631270152441fa171d91108b75a7b9a2cc36ca7db6c4121023bd0ec4022d12d0106c5b7308a25572953ba1951f576f691354a7b147ee0cc1fffffffff7b010c5faeb41cc5c253121b6bf69bf1a7c5867cd7f2d91569fea0ecd311b8650100000000ffffffff01803a4802000000001976a914ea5f904d195079a350b534db4446433b3cec222e88ac0002483045022100e39d9bff8350b9ba20cb2ed88e82d7568a83184616acdc16bd1adb4005c5a471022066ff36084e896a69a91a0fad01721f20f2bb42b41e20be35e72fc3729ac7ace74121030b75ccac9add5f82a4c61fe34e791a2f2eda61b544bce4f6fa3d403bb0de748400000000"
btc_hash(serialized_tx)[::-1].hex()
== "2c64109fba890657e37f0782efda29bbc277dfd521658f185d302ddffcacffd2"
)

Loading…
Cancel
Save