diff --git a/tests/test_signtx.py b/tests/test_signtx.py index 786a478..00a4477 100644 --- a/tests/test_signtx.py +++ b/tests/test_signtx.py @@ -6,6 +6,7 @@ import trezorlib.messages_pb2 as proto import trezorlib.types_pb2 as proto_types class TestSignTx(common.TrezorTest): + def test_simplesigntx(self): # tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882 # input 0: 0.0039 BTC @@ -22,7 +23,6 @@ class TestSignTx(common.TrezorTest): ) tx = self.client.simple_sign_tx('Bitcoin', [inp1, ], [out1, ]) - # print binascii.hexlify(tx.serialized_tx) self.assertEqual(binascii.hexlify(tx.serialized_tx), '010000000182488650ef25a58fef6788bd71b8212038d7f2bbe4750bc7bcb44701e85ef6d5000000006b4830450221009a0b7be0d4ed3146ee262b42202841834698bb3ee39c24e7437df208b8b7077102202b79ab1e7736219387dffe8d615bbdba87e11477104b867ef47afed1a5ede7810121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff0160cc0500000000001976a914de9b2a8da088824e8fe51debea566617d851537888ac00000000') def test_estimate_size(self): diff --git a/trezorlib/client.py b/trezorlib/client.py old mode 100644 new mode 100755 index 6a40d79..97e9e79 --- a/trezorlib/client.py +++ b/trezorlib/client.py @@ -9,6 +9,22 @@ import messages_pb2 as proto import types_pb2 as types from api_blockchain import BlockchainApi +# === start monkeypatching: text formatting of protobuf messages +import google.protobuf.text_format +import google.protobuf.descriptor + +_oldPrintFieldValue = google.protobuf.text_format.PrintFieldValue + +def _customPrintFieldValue(field, value, out, indent=0, as_utf8=False, as_one_line=False): + if field.cpp_type == google.protobuf.descriptor.FieldDescriptor.CPPTYPE_STRING: + if str(field.GetOptions()).strip() == '[binary]:': # binary option set + _oldPrintFieldValue(field, 'hex(%s)' % binascii.hexlify(value), out, indent, as_utf8, as_one_line) + else: + _oldPrintFieldValue(field, value, out, indent, as_utf8, as_one_line) + +google.protobuf.text_format.PrintFieldValue = _customPrintFieldValue +# === end of monkeypatching + def show_message(message): print "MESSAGE FROM DEVICE:", message