From 2df19127fdf4917b6e0a5ac5b8b81b54507ddc0d Mon Sep 17 00:00:00 2001 From: Saleem Rashid Date: Tue, 19 Dec 2017 15:19:55 +0000 Subject: [PATCH] device_tests: Add test_decred_send_change --- .../device_tests/test_msg_signtx_decred.py | 79 +++++++++++++++++++ ...a9b17538a8850b4c2c24ecb9b7ba48059b970.json | 1 + ...a81e222758122682d522eff8ae1fcbc93bc74.json | 1 + ...bc28025d4ee02234d68bdea2d8353b47a3113.json | 1 + 4 files changed, 82 insertions(+) create mode 100644 trezorlib/tests/txcache/insight_decred_testnet_tx_5e6e3500a333c53c02f523db5f1a9b17538a8850b4c2c24ecb9b7ba48059b970.json create mode 100644 trezorlib/tests/txcache/insight_decred_testnet_tx_ccf95b0fd220ef59ae2e5b17005a81e222758122682d522eff8ae1fcbc93bc74.json create mode 100644 trezorlib/tests/txcache/insight_decred_testnet_tx_f395ef3e72a831a766db15e7a38bc28025d4ee02234d68bdea2d8353b47a3113.json diff --git a/trezorlib/tests/device_tests/test_msg_signtx_decred.py b/trezorlib/tests/device_tests/test_msg_signtx_decred.py index 600662843..5120b68fe 100644 --- a/trezorlib/tests/device_tests/test_msg_signtx_decred.py +++ b/trezorlib/tests/device_tests/test_msg_signtx_decred.py @@ -24,6 +24,9 @@ from trezorlib.tx_api import TxApiDecredTestnet TXHASH_e16248 = binascii.unhexlify("e16248f0b39a0a0c0e53d6f2f84c2a944f0d50e017a82701e8e02e46e979d5ed") +TXHASH_5e6e35 = binascii.unhexlify("5e6e3500a333c53c02f523db5f1a9b17538a8850b4c2c24ecb9b7ba48059b970") +TXHASH_ccf95b = binascii.unhexlify("ccf95b0fd220ef59ae2e5b17005a81e222758122682d522eff8ae1fcbc93bc74") +TXHASH_f395ef = binascii.unhexlify("f395ef3e72a831a766db15e7a38bc28025d4ee02234d68bdea2d8353b47a3113") @pytest.mark.skip_t1 @@ -68,3 +71,79 @@ class TestMsgSigntxDecred(common.TrezorTest): # Accepted by network: 5e6e3500a333c53c02f523db5f1a9b17538a8850b4c2c24ecb9b7ba48059b970 self.assertEqual(serialized_tx, binascii.unhexlify("0100000001edd579e9462ee0e80127a817e0500d4f942a4cf8f2d6530e0c0a9ab3f04862e10100000000ffffffff01802b530b0000000000001976a914819d291a2f7fbf770e784bfd78b5ce92c58e95ea88ac000000000000000001000000000000000000000000ffffffff6b483045022100bad68486491e449a731513805c129201d7f65601d6f07c97fda0588453c97d22022013e9ef59657ae4f344ac4f0db2b7a23dbfcdb51ebeb85277146ac189e547d3f7012102f5a745afb96077c071e4d19911a5d3d024faa1314ee8688bc6eec39751d0818f")) + + def test_send_decred_change(self): + self.setup_mnemonic_allallall() + self.client.set_tx_api(TxApiDecredTestnet) + + inp1 = proto.TxInputType( + # TscqTv1he8MZrV321SfRghw7LFBCJDKB3oz + address_n=self.client.expand_path("m/44'/1'/0'/0/0"), + prev_hash=TXHASH_5e6e35, + prev_index=0, + script_type=proto.InputScriptType.SPENDADDRESS, + decred_tree=0, + ) + + inp2 = proto.TxInputType( + # TscqTv1he8MZrV321SfRghw7LFBCJDKB3oz + address_n=self.client.expand_path("m/44'/1'/0'/0/0"), + prev_hash=TXHASH_ccf95b, + prev_index=1, + script_type=proto.InputScriptType.SPENDADDRESS, + decred_tree=0, + ) + + inp3 = proto.TxInputType( + # Tskt39YEvzoJ5KBDH4f1auNzG3jViVjZ2RV + address_n=self.client.expand_path("m/44'/1'/0'/0/1"), + prev_hash=TXHASH_f395ef, + prev_index=0, + script_type=proto.InputScriptType.SPENDADDRESS, + decred_tree=0, + ) + + out1 = proto.TxOutputType( + address="TsWjioPrP8E1TuTMmTrVMM2BA4iPrjQXBpR", + amount=489975000, + script_type=proto.OutputScriptType.PAYTOADDRESS, + decred_script_version=0, + ) + + out2 = proto.TxOutputType( + # TsaSFRwfN9muW5F6ZX36iSksc9hruiC5F97 + address_n=self.client.expand_path("m/44'/1'/0'/1/0"), + amount=100000000, + script_type=proto.OutputScriptType.PAYTOADDRESS, + decred_script_version=0, + ) + + with self.client: + self.client.set_expected_responses([ + proto.TxRequest(request_type=proto.RequestType.TXINPUT, details=proto.TxRequestDetailsType(request_index=0)), + proto.TxRequest(request_type=proto.RequestType.TXMETA, details=proto.TxRequestDetailsType(tx_hash=TXHASH_5e6e35)), + proto.TxRequest(request_type=proto.RequestType.TXINPUT, details=proto.TxRequestDetailsType(tx_hash=TXHASH_5e6e35, request_index=0)), + proto.TxRequest(request_type=proto.RequestType.TXOUTPUT, details=proto.TxRequestDetailsType(tx_hash=TXHASH_5e6e35, request_index=0)), + proto.TxRequest(request_type=proto.RequestType.TXINPUT, details=proto.TxRequestDetailsType(request_index=1)), + proto.TxRequest(request_type=proto.RequestType.TXMETA, details=proto.TxRequestDetailsType(tx_hash=TXHASH_ccf95b)), + proto.TxRequest(request_type=proto.RequestType.TXINPUT, details=proto.TxRequestDetailsType(tx_hash=TXHASH_ccf95b, request_index=0)), + proto.TxRequest(request_type=proto.RequestType.TXOUTPUT, details=proto.TxRequestDetailsType(tx_hash=TXHASH_ccf95b, request_index=0)), + proto.TxRequest(request_type=proto.RequestType.TXOUTPUT, details=proto.TxRequestDetailsType(tx_hash=TXHASH_ccf95b, request_index=1)), + proto.TxRequest(request_type=proto.RequestType.TXINPUT, details=proto.TxRequestDetailsType(request_index=2)), + proto.TxRequest(request_type=proto.RequestType.TXMETA, details=proto.TxRequestDetailsType(tx_hash=TXHASH_f395ef)), + proto.TxRequest(request_type=proto.RequestType.TXINPUT, details=proto.TxRequestDetailsType(tx_hash=TXHASH_f395ef, request_index=0)), + proto.TxRequest(request_type=proto.RequestType.TXOUTPUT, details=proto.TxRequestDetailsType(tx_hash=TXHASH_f395ef, request_index=0)), + proto.TxRequest(request_type=proto.RequestType.TXOUTPUT, details=proto.TxRequestDetailsType(tx_hash=TXHASH_f395ef, request_index=1)), + proto.TxRequest(request_type=proto.RequestType.TXOUTPUT, details=proto.TxRequestDetailsType(request_index=0)), + proto.ButtonRequest(code=proto.ButtonRequestType.ConfirmOutput), + proto.TxRequest(request_type=proto.RequestType.TXOUTPUT, details=proto.TxRequestDetailsType(request_index=1)), + proto.ButtonRequest(code=proto.ButtonRequestType.SignTx), + proto.TxRequest(request_type=proto.RequestType.TXINPUT, details=proto.TxRequestDetailsType(request_index=0)), + proto.TxRequest(request_type=proto.RequestType.TXINPUT, details=proto.TxRequestDetailsType(request_index=1)), + proto.TxRequest(request_type=proto.RequestType.TXINPUT, details=proto.TxRequestDetailsType(request_index=2)), + proto.TxRequest(request_type=proto.RequestType.TXFINISHED), + ]) + (signatures, serialized_tx) = self.client.sign_tx("Decred Testnet", [inp1, inp2, inp3], [out1, out2]) + + # Accepted by network: c5ff767141a162b665acf775fcc35b60ff622fbe21a21e0a6609ed768c3737f4 + self.assertEqual(serialized_tx, binascii.unhexlify("010000000370b95980a47b9bcb4ec2c2b450888a53179b1a5fdb23f5023cc533a300356e5e0000000000ffffffff74bc93bcfce18aff2e522d6822817522e2815a00175b2eae59ef20d20f5bf9cc0100000000ffffffff13317ab453832deabd684d2302eed42580c28ba3e715db66a731a8723eef95f30000000000ffffffff02d86c341d0000000000001976a9143eb656115197956125365348c542e37b6d3d259988ac00e1f5050000000000001976a9146748ebb8694c069742ee69eab2159c33c7f57d2b88ac000000000000000003000000000000000000000000ffffffff6b483045022100d91237a32b8968e1d3316b76f045cc18fed12736aebd570dd023a61826279cc102204222b133189762368d3398d11eb9a6843a67de11d70ac58426a28b605fa102b1012102f5a745afb96077c071e4d19911a5d3d024faa1314ee8688bc6eec39751d0818f000000000000000000000000ffffffff69463043021f7cf9b0b180f3fcde8d3d036d81e575e368d6ab5c8c6a2ffef47c06a0170023022036b964bf26ff276c58862dfacafa93216618832d6240f16b6100a9d10d5eb753012102f5a745afb96077c071e4d19911a5d3d024faa1314ee8688bc6eec39751d0818f000000000000000000000000ffffffff6b48304502210098f3a0cc17c3383f5998c542950b5cccb1175cc94b8d0343f420dc64abe9a50e0220507974c6ef0761925634fe3e13ec458b8cd3e42856828d584d4a5d39cc4d0f890121022c6099c7af8124d58e97beefc85c529dcfb3865794d46ec04095e70872e32a2e")) diff --git a/trezorlib/tests/txcache/insight_decred_testnet_tx_5e6e3500a333c53c02f523db5f1a9b17538a8850b4c2c24ecb9b7ba48059b970.json b/trezorlib/tests/txcache/insight_decred_testnet_tx_5e6e3500a333c53c02f523db5f1a9b17538a8850b4c2c24ecb9b7ba48059b970.json new file mode 100644 index 000000000..9d41786aa --- /dev/null +++ b/trezorlib/tests/txcache/insight_decred_testnet_tx_5e6e3500a333c53c02f523db5f1a9b17538a8850b4c2c24ecb9b7ba48059b970.json @@ -0,0 +1 @@ +{"txid": "5e6e3500a333c53c02f523db5f1a9b17538a8850b4c2c24ecb9b7ba48059b970", "version": 1, "locktime": 0, "expiry": 0, "vin": [{"txid": "e16248f0b39a0a0c0e53d6f2f84c2a944f0d50e017a82701e8e02e46e979d5ed", "vout": 1, "tree": 0, "sequence": 4294967295, "amountin": 2, "blockheight": 192676, "blockindex": 1, "scriptSig": {"asm": "3045022100bad68486491e449a731513805c129201d7f65601d6f07c97fda0588453c97d22022013e9ef59657ae4f344ac4f0db2b7a23dbfcdb51ebeb85277146ac189e547d3f701 02f5a745afb96077c071e4d19911a5d3d024faa1314ee8688bc6eec39751d0818f", "hex": "483045022100bad68486491e449a731513805c129201d7f65601d6f07c97fda0588453c97d22022013e9ef59657ae4f344ac4f0db2b7a23dbfcdb51ebeb85277146ac189e547d3f7012102f5a745afb96077c071e4d19911a5d3d024faa1314ee8688bc6eec39751d0818f"}, "n": 0, "addr": "TscqTv1he8MZrV321SfRghw7LFBCJDKB3oz", "valueSat": 200000000, "value": 2, "doubleSpentTxID": null, "isConfirmed": true, "confirmations": 6387, "unconfirmedInput": false}], "vout": [{"value": "1.90000000", "n": 0, "version": 0, "scriptPubKey": {"asm": "OP_DUP OP_HASH160 819d291a2f7fbf770e784bfd78b5ce92c58e95ea OP_EQUALVERIFY OP_CHECKSIG", "hex": "76a914819d291a2f7fbf770e784bfd78b5ce92c58e95ea88ac", "reqSigs": 1, "type": "pubkeyhash", "addresses": ["TscqTv1he8MZrV321SfRghw7LFBCJDKB3oz"]}}], "blockhash": "000000000139f68a47d95f708bb91ac9b35573640bc70d36a94302af07ba8168", "blockheight": 197841, "confirmations": 1222, "time": 1513543546, "blocktime": 1513543546, "valueOut": "1.9", "size": 216, "valueIn": 2, "fees": "0.1"} \ No newline at end of file diff --git a/trezorlib/tests/txcache/insight_decred_testnet_tx_ccf95b0fd220ef59ae2e5b17005a81e222758122682d522eff8ae1fcbc93bc74.json b/trezorlib/tests/txcache/insight_decred_testnet_tx_ccf95b0fd220ef59ae2e5b17005a81e222758122682d522eff8ae1fcbc93bc74.json new file mode 100644 index 000000000..50c90756f --- /dev/null +++ b/trezorlib/tests/txcache/insight_decred_testnet_tx_ccf95b0fd220ef59ae2e5b17005a81e222758122682d522eff8ae1fcbc93bc74.json @@ -0,0 +1 @@ +{"txid": "ccf95b0fd220ef59ae2e5b17005a81e222758122682d522eff8ae1fcbc93bc74", "version": 1, "locktime": 0, "expiry": 0, "vin": [{"txid": "bcc56f8b646c787d505275a7ab174fb060b028dcc4469e9a4d8391224fe67515", "vout": 2, "tree": 0, "sequence": 4294967295, "amountin": "4.86000277", "blockheight": 186396, "blockindex": 0, "scriptSig": {"asm": "304502210094eb39bdfaa3236cf211c8249cf82603c0b7275dc59dc7b27936806e20a063b90220691aa71e9a0ab246a1dc4568c0ad4b5202d35ed0639fe64da17085701303e21801 02ae1f6b51086bd753f072f94eb8ffe6806d3570c088a3ede46c678b6ea47d1675", "hex": "48304502210094eb39bdfaa3236cf211c8249cf82603c0b7275dc59dc7b27936806e20a063b90220691aa71e9a0ab246a1dc4568c0ad4b5202d35ed0639fe64da17085701303e218012102ae1f6b51086bd753f072f94eb8ffe6806d3570c088a3ede46c678b6ea47d1675"}, "n": 0, "addr": "TseH9wPe4bfRqS2qwceAyjzNGFrMAPgzkvB", "valueSat": 486000277, "value": "4.86000277", "doubleSpentTxID": null, "isConfirmed": true, "confirmations": 12667, "unconfirmedInput": false}], "vout": [{"value": "2.85974977", "n": 0, "version": 0, "scriptPubKey": {"asm": "OP_DUP OP_HASH160 0f193c04da94b7e23651ff2574e455bc5ea2cf92 OP_EQUALVERIFY OP_CHECKSIG", "hex": "76a9140f193c04da94b7e23651ff2574e455bc5ea2cf9288ac", "reqSigs": 1, "type": "pubkeyhash", "addresses": ["TsSPxqktwRjPpixa2cD7iYHa2gGGKCm5949"]}}, {"value": "2.00000000", "n": 1, "version": 0, "scriptPubKey": {"asm": "OP_DUP OP_HASH160 819d291a2f7fbf770e784bfd78b5ce92c58e95ea OP_EQUALVERIFY OP_CHECKSIG", "hex": "76a914819d291a2f7fbf770e784bfd78b5ce92c58e95ea88ac", "reqSigs": 1, "type": "pubkeyhash", "addresses": ["TscqTv1he8MZrV321SfRghw7LFBCJDKB3oz"]}}], "blockhash": "000000000140a23561418c3a34078550adc7369494c377d8584bc4410dba704f", "blockheight": 199049, "confirmations": 14, "time": 1513693477, "blocktime": 1513693477, "valueOut": "4.85974977", "size": 252, "valueIn": "4.86000277", "fees": "0.000253"} \ No newline at end of file diff --git a/trezorlib/tests/txcache/insight_decred_testnet_tx_f395ef3e72a831a766db15e7a38bc28025d4ee02234d68bdea2d8353b47a3113.json b/trezorlib/tests/txcache/insight_decred_testnet_tx_f395ef3e72a831a766db15e7a38bc28025d4ee02234d68bdea2d8353b47a3113.json new file mode 100644 index 000000000..5635e3900 --- /dev/null +++ b/trezorlib/tests/txcache/insight_decred_testnet_tx_f395ef3e72a831a766db15e7a38bc28025d4ee02234d68bdea2d8353b47a3113.json @@ -0,0 +1 @@ +{"txid": "f395ef3e72a831a766db15e7a38bc28025d4ee02234d68bdea2d8353b47a3113", "version": 1, "locktime": 0, "expiry": 0, "vin": [{"txid": "e1b86d7694cf3bf9c83188bdb380892b85cd82a31410b09e267a745caaab7715", "vout": 2, "tree": 0, "sequence": 4294967295, "amountin": "6.18712631", "blockheight": 184001, "blockindex": 0, "scriptSig": {"asm": "304402205de1a5bd40d551f77cd2a60d58767f92baa265ec99808ad14afe571682498e9b022054d148cd29d287e3e22d700b99e6a30823a9584a5db5e4ba26f4e60f613b4cc901 02ae1f6b51086bd753f072f94eb8ffe6806d3570c088a3ede46c678b6ea47d1675", "hex": "47304402205de1a5bd40d551f77cd2a60d58767f92baa265ec99808ad14afe571682498e9b022054d148cd29d287e3e22d700b99e6a30823a9584a5db5e4ba26f4e60f613b4cc9012102ae1f6b51086bd753f072f94eb8ffe6806d3570c088a3ede46c678b6ea47d1675"}, "n": 0, "addr": "TseH9wPe4bfRqS2qwceAyjzNGFrMAPgzkvB", "valueSat": 618712631, "value": "6.18712631", "doubleSpentTxID": null, "isConfirmed": true, "confirmations": 15062, "unconfirmedInput": false}], "vout": [{"value": "2.00000000", "n": 0, "version": 0, "scriptPubKey": {"asm": "OP_DUP OP_HASH160 d9dabd8d92a93da3244096f6fea327ba441fe6d0 OP_EQUALVERIFY OP_CHECKSIG", "hex": "76a914d9dabd8d92a93da3244096f6fea327ba441fe6d088ac", "reqSigs": 1, "type": "pubkeyhash", "addresses": ["Tskt39YEvzoJ5KBDH4f1auNzG3jViVjZ2RV"]}}, {"value": "4.18687331", "n": 1, "version": 0, "scriptPubKey": {"asm": "OP_DUP OP_HASH160 457c5d36407d75c9650017b9b0f05e16ebd4e39f OP_EQUALVERIFY OP_CHECKSIG", "hex": "76a914457c5d36407d75c9650017b9b0f05e16ebd4e39f88ac", "reqSigs": 1, "type": "pubkeyhash", "addresses": ["TsXMY5mP6CojGAVoxbVugE3YH6bDGeg6XrT"]}}], "blockhash": "0000000001eea1dab265ee3a8aea01c79ce2bd4d99f57bc6dc042fc04a8ce37b", "blockheight": 199055, "confirmations": 8, "time": 1513694580, "blocktime": 1513694580, "valueOut": "6.18687331", "size": 251, "valueIn": "6.18712631", "fees": "0.000253"} \ No newline at end of file