From feec0a572c5c72448948d2a86b8c8a4eb16cc524 Mon Sep 17 00:00:00 2001 From: Saleem Rashid Date: Mon, 18 Dec 2017 10:55:41 +0000 Subject: [PATCH] device_tests: Add TestMsgSigntxDecred --- tests/device_tests/test_msg_signtx_decred.py | 67 +++++++++++++++++++ ...c2a944f0d50e017a82701e8e02e46e979d5ed.json | 1 + 2 files changed, 68 insertions(+) create mode 100644 tests/device_tests/test_msg_signtx_decred.py create mode 100644 tests/txcache/insight_decred_testnet_tx_e16248f0b39a0a0c0e53d6f2f84c2a944f0d50e017a82701e8e02e46e979d5ed.json diff --git a/tests/device_tests/test_msg_signtx_decred.py b/tests/device_tests/test_msg_signtx_decred.py new file mode 100644 index 0000000..0880db7 --- /dev/null +++ b/tests/device_tests/test_msg_signtx_decred.py @@ -0,0 +1,67 @@ +# This file is part of the TREZOR project. +# +# Copyright (C) 2017 Saleem Rashid +# +# This library is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# 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 GNU Lesser General Public License +# along with this library. If not, see . + +import unittest +import common +import binascii + +from trezorlib import messages as proto +from trezorlib.tx_api import TxApiDecredTestnet + + +TXHASH_e16248 = binascii.unhexlify("e16248f0b39a0a0c0e53d6f2f84c2a944f0d50e017a82701e8e02e46e979d5ed") + + +class TestMsgSigntxDecred(common.TrezorTest): + + def test_send_decred(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_e16248, + prev_index=1, + script_type=proto.InputScriptType.SPENDADDRESS, + decred_tree=0, + ) + + out1 = proto.TxOutputType( + address='TscqTv1he8MZrV321SfRghw7LFBCJDKB3oz', + amount=190000000, + 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_e16248)), + proto.TxRequest(request_type=proto.RequestType.TXINPUT, details=proto.TxRequestDetailsType(tx_hash=TXHASH_e16248, request_index=0)), + proto.TxRequest(request_type=proto.RequestType.TXOUTPUT, details=proto.TxRequestDetailsType(tx_hash=TXHASH_e16248, request_index=0)), + proto.TxRequest(request_type=proto.RequestType.TXOUTPUT, details=proto.TxRequestDetailsType(tx_hash=TXHASH_e16248, request_index=1)), + proto.TxRequest(request_type=proto.RequestType.TXOUTPUT, details=proto.TxRequestDetailsType(request_index=0)), + proto.ButtonRequest(code=proto.ButtonRequestType.ConfirmOutput), + proto.ButtonRequest(code=proto.ButtonRequestType.FeeOverThreshold), + 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.TXFINISHED), + ]) + (signatures, serialized_tx) = self.client.sign_tx("Decred Testnet", [inp1], [out1]) + + self.assertEqual(serialized_tx, binascii.unhexlify("0100000001edd579e9462ee0e80127a817e0500d4f942a4cf8f2d6530e0c0a9ab3f04862e10100000000ffffffff01802b530b0000000000001976a914819d291a2f7fbf770e784bfd78b5ce92c58e95ea88ac000000000000000001000000000000000000000000ffffffff6b483045022100bad68486491e449a731513805c129201d7f65601d6f07c97fda0588453c97d22022013e9ef59657ae4f344ac4f0db2b7a23dbfcdb51ebeb85277146ac189e547d3f7012102f5a745afb96077c071e4d19911a5d3d024faa1314ee8688bc6eec39751d0818f")) diff --git a/tests/txcache/insight_decred_testnet_tx_e16248f0b39a0a0c0e53d6f2f84c2a944f0d50e017a82701e8e02e46e979d5ed.json b/tests/txcache/insight_decred_testnet_tx_e16248f0b39a0a0c0e53d6f2f84c2a944f0d50e017a82701e8e02e46e979d5ed.json new file mode 100644 index 0000000..d19dfbd --- /dev/null +++ b/tests/txcache/insight_decred_testnet_tx_e16248f0b39a0a0c0e53d6f2f84c2a944f0d50e017a82701e8e02e46e979d5ed.json @@ -0,0 +1 @@ +{"txid": "e16248f0b39a0a0c0e53d6f2f84c2a944f0d50e017a82701e8e02e46e979d5ed", "version": 1, "locktime": 0, "expiry": 0, "vin": [{"txid": "21012b08c5077036460e8f75bbc57beb11d7bc30e7ad224ad5e67d15bd086500", "vout": 2, "tree": 0, "sequence": 4294967295, "amountin": "3.53210301", "blockheight": 192566, "blockindex": 0, "scriptSig": {"asm": "304402207d127d59a44187952d9d0de94ad34a19dd9a84beb124fd8a3fb439c862544d3202206618f321385c30bda96fb01ce03f70a269d78a301c0b0c2e3e3689dfae3f473301 02ae1f6b51086bd753f072f94eb8ffe6806d3570c088a3ede46c678b6ea47d1675", "hex": "47304402207d127d59a44187952d9d0de94ad34a19dd9a84beb124fd8a3fb439c862544d3202206618f321385c30bda96fb01ce03f70a269d78a301c0b0c2e3e3689dfae3f4733012102ae1f6b51086bd753f072f94eb8ffe6806d3570c088a3ede46c678b6ea47d1675"}, "n": 0, "addr": "TseH9wPe4bfRqS2qwceAyjzNGFrMAPgzkvB", "valueSat": 353210301, "value": "3.53210301", "doubleSpentTxID": null, "isConfirmed": true, "confirmations": 5745, "unconfirmedInput": false}], "vout": [{"value": "1.53185001", "n": 0, "version": 0, "scriptPubKey": {"asm": "OP_DUP OP_HASH160 e4111051ae0349ab5589cf2b7e125c6da694a1a1 OP_EQUALVERIFY OP_CHECKSIG", "hex": "76a914e4111051ae0349ab5589cf2b7e125c6da694a1a188ac", "reqSigs": 1, "type": "pubkeyhash", "addresses": ["Tsmp2yuZrtECpPocckpBeNoFfXo1PME8F63"]}}, {"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"]}, "spentTxId": "5e6e3500a333c53c02f523db5f1a9b17538a8850b4c2c24ecb9b7ba48059b970", "spentIndex": 0, "spentTs": 0}], "blockhash": "000000000215d08d0f64fe615e8cdf483aff9853ccf23825acd45dfaf0f3039a", "blockheight": 192676, "confirmations": 5635, "time": 1512926987, "blocktime": 1512926987, "valueOut": "3.53185001", "size": 251, "valueIn": "3.53210301", "fees": "0.000253"} \ No newline at end of file