From a0bc12375cf1c7f8b4d62d7aa8bc0dbd662a2f7e Mon Sep 17 00:00:00 2001 From: slush0 Date: Thu, 13 Feb 2014 18:51:38 +0100 Subject: [PATCH] Add tests for too long message and for testnet addresses --- tests/test_messages.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/test_messages.py b/tests/test_messages.py index db5918f931..360a80347f 100644 --- a/tests/test_messages.py +++ b/tests/test_messages.py @@ -1,9 +1,9 @@ import unittest import common import binascii +import base64 -import trezorlib.messages_pb2 as proto -import trezorlib.types_pb2 as proto_types +from trezorlib.client import CallException class TestMessages(common.TrezorTest): @@ -12,6 +12,23 @@ class TestMessages(common.TrezorTest): self.assertEqual(sig.address, '14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e') self.assertEqual(binascii.hexlify(sig.signature), '209e23edf0e4e47ff1dec27f32cd78c50e74ef018ee8a6adf35ae17c7a9b0dd96f48b493fd7dbab03efb6f439c6383c9523b3bbc5f1a7d158a6af90ab154e9be80') + def test_too_long(self): + # Message cannot be longer than 255 bytes + self.assertRaises(CallException, self.client.sign_message, [0], '1' * 256) + + ret = self.client.verify_message('1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T', + binascii.unhexlify('1ba77e01a9e17ba158b962cfef5f13dfed676ffc2b4bada24e58f784458b52b97421470d001d53d5880cf5e10e76f02be3e80bf21e18398cbd41e8c3b4af74c8c2'), + '1' * 256 + ) + self.assertFalse(ret) + + def test_message_testnet(self): + sig = base64.b64decode('IFP/nvQalDo9lWCI7kScOzRkz/fiiScdkw7tFAKPoGbl6S8AY3wEws43s2gR57AfwZP8/8y7+F+wvGK9phQghN4=') + ret = self.client.verify_message('moRDikgmxcpouFtqnKnVVzLYgkDD2gQ3sk', sig, 'Ahoj') + + self.assertTrue(ret) + + def test_message_verify(self): # uncompressed pubkey - OK