From 36985519b546b9824ef5a6a2e01cb388e9a8c00a Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Mon, 17 Jul 2017 14:40:35 +0200 Subject: [PATCH] tests: add test for ethereum sign/verify message --- .../test_msg_ethereum_signmessage.py | 39 ++++++++++++++++ .../test_msg_ethereum_verifymessage.py | 45 +++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 tests/device_tests/test_msg_ethereum_signmessage.py create mode 100644 tests/device_tests/test_msg_ethereum_verifymessage.py diff --git a/tests/device_tests/test_msg_ethereum_signmessage.py b/tests/device_tests/test_msg_ethereum_signmessage.py new file mode 100644 index 0000000..279e22c --- /dev/null +++ b/tests/device_tests/test_msg_ethereum_signmessage.py @@ -0,0 +1,39 @@ +# This file is part of the TREZOR project. +# +# Copyright (C) 2016-2017 Pavol Rusnak +# +# 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 + + +class TestMsgEthereumSignmessage(common.TrezorTest): + + def test_sign(self): + self.setup_mnemonic_nopin_nopassphrase() + sig = self.client.ethereum_sign_message([0], 'This is an example of a signed message.') + self.assertEqual(binascii.hexlify(sig.address), b'cb3864960e8db1a751212c580af27ee8867d688f') + self.assertEqual(binascii.hexlify(sig.signature), b'95b64a7b3aa492f0cc1668a24097004562cc2b4f0e755e3c0d60dd791b9f9e285f95b618258ff97036b8419d0a0dd1af3751c625b4d248ee6deff84eba21b8ee1c') + + def test_sign_long(self): + self.setup_mnemonic_nopin_nopassphrase() + sig = self.client.ethereum_sign_message([0], 'VeryLongMessage!' * 64) + self.assertEqual(binascii.hexlify(sig.address), b'cb3864960e8db1a751212c580af27ee8867d688f') + self.assertEqual(binascii.hexlify(sig.signature), b'70d03c8447b64489e80ae44ce4f1a543e8eb5dd9e9a19c4743ce95fbd9b8234b2d2a16db87cee857f5b474107ad2c0c0c86118f8a33d5df3d98b766be92d71331b') + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/device_tests/test_msg_ethereum_verifymessage.py b/tests/device_tests/test_msg_ethereum_verifymessage.py new file mode 100644 index 0000000..f84f5ea --- /dev/null +++ b/tests/device_tests/test_msg_ethereum_verifymessage.py @@ -0,0 +1,45 @@ +# This file is part of the TREZOR project. +# +# Copyright (C) 2016-2017 Pavol Rusnak +# +# 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 + + +class TestMsgEthereumVerifymessage(common.TrezorTest): + + def test_verify(self): + self.setup_mnemonic_nopin_nopassphrase() + res = self.client.ethereum_verify_message( + binascii.unhexlify(b'cb3864960e8db1a751212c580af27ee8867d688f'), + binascii.unhexlify(b'95b64a7b3aa492f0cc1668a24097004562cc2b4f0e755e3c0d60dd791b9f9e285f95b618258ff97036b8419d0a0dd1af3751c625b4d248ee6deff84eba21b8ee1c'), + 'This is an example of a signed message.' + ) + self.assertTrue(res) + + def test_verify_long(self): + self.setup_mnemonic_nopin_nopassphrase() + ret = self.client.ethereum_verify_message( + binascii.unhexlify(b'cb3864960e8db1a751212c580af27ee8867d688f'), + binascii.unhexlify(b'70d03c8447b64489e80ae44ce4f1a543e8eb5dd9e9a19c4743ce95fbd9b8234b2d2a16db87cee857f5b474107ad2c0c0c86118f8a33d5df3d98b766be92d71331b'), + 'VeryLongMessage!' * 64 + ) + self.assertTrue(ret) + + +if __name__ == '__main__': + unittest.main()