From 3be88e69ffe6bbc929e3105a42eef8ff50988588 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Tue, 16 Aug 2016 17:22:30 +0200 Subject: [PATCH] add unit tests for ethereum messages --- tests/config.py | 2 - tests/test_msg_ethereum_getaddress.py | 17 +++++++ tests/test_msg_ethereum_signtx.py | 66 +++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 tests/test_msg_ethereum_getaddress.py create mode 100644 tests/test_msg_ethereum_signtx.py diff --git a/tests/config.py b/tests/config.py index 7b882e4..35df62f 100644 --- a/tests/config.py +++ b/tests/config.py @@ -5,8 +5,6 @@ sys.path = ['../',] + sys.path from trezorlib.transport_pipe import PipeTransport from trezorlib.transport_hid import HidTransport -from trezorlib.transport_socket import SocketTransportClient -#from trezorlib.transport_bridge import BridgeTransport devices = HidTransport.enumerate() diff --git a/tests/test_msg_ethereum_getaddress.py b/tests/test_msg_ethereum_getaddress.py new file mode 100644 index 0000000..8bbb0ba --- /dev/null +++ b/tests/test_msg_ethereum_getaddress.py @@ -0,0 +1,17 @@ +import unittest +import common +import trezorlib.ckd_public as bip32 +import binascii + +class TestMsgEthereumGetaddress(common.TrezorTest): + + def test_ethereum_getaddress(self): + self.setup_mnemonic_nopin_nopassphrase() + self.assertEqual(binascii.hexlify(self.client.ethereum_get_address([])), '1d1c328764a41bda0492b66baa30c4a339ff85ef') + self.assertEqual(binascii.hexlify(self.client.ethereum_get_address([1])), '437207ca3cf43bf2e47dea0756d736c5df4f597a') + self.assertEqual(binascii.hexlify(self.client.ethereum_get_address([0, -1])), 'e5d96dfa07bcf1a3ae43677840c31394258861bf') + self.assertEqual(binascii.hexlify(self.client.ethereum_get_address([-9, 0])), 'f68804ac9eca9483ab4241d3e4751590d2c05102') + self.assertEqual(binascii.hexlify(self.client.ethereum_get_address([0, 9999999])), '7a6366ecfcaf0d5dcc1539c171696c6cdd1eb8ed') + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_msg_ethereum_signtx.py b/tests/test_msg_ethereum_signtx.py new file mode 100644 index 0000000..c423b79 --- /dev/null +++ b/tests/test_msg_ethereum_signtx.py @@ -0,0 +1,66 @@ +import unittest +import common +import binascii + +import trezorlib.messages_pb2 as proto +import trezorlib.types_pb2 as proto_types + +from rlp.utils import int_to_big_endian + +class TestMsgEthereumSigntx(common.TrezorTest): + + def test_ethereum_signtx_nodata(self): + self.setup_mnemonic_nopin_nopassphrase() + + sig_v, sig_r, sig_s = self.client.ethereum_sign_tx( + n=[0, 0], + nonce=0, + gas_price=20, + gas_limit=20, + to=binascii.unhexlify('1d1c328764a41bda0492b66baa30c4a339ff85ef'), + value=10) + self.assertEqual(sig_v, 27) + self.assertEqual(binascii.hexlify(sig_r), '9b61192a161d056c66cfbbd331edb2d783a0193bd4f65f49ee965f791d898f72') + self.assertEqual(binascii.hexlify(sig_s), '49c0bbe35131592c6ed5c871ac457feeb16a1493f64237387fab9b83c1a202f7') + + sig_v, sig_r, sig_s = self.client.ethereum_sign_tx( + n=[0, 0], + nonce=123456, + gas_price=20000, + gas_limit=20000, + to=binascii.unhexlify('1d1c328764a41bda0492b66baa30c4a339ff85ef'), + value=12345678901234567890) + self.assertEqual(sig_v, 28) + self.assertEqual(binascii.hexlify(sig_r), '6de597b8ec1b46501e5b159676e132c1aa78a95bd5892ef23560a9867528975a') + self.assertEqual(binascii.hexlify(sig_s), '6e33c4230b1ecf96a8dbb514b4aec0a6d6ba53f8991c8143f77812aa6daa993f') + + def test_ethereum_signtx_data(self): + self.setup_mnemonic_nopin_nopassphrase() + + sig_v, sig_r, sig_s = self.client.ethereum_sign_tx( + n=[0, 0], + nonce=0, + gas_price=20, + gas_limit=20, + to=binascii.unhexlify('1d1c328764a41bda0492b66baa30c4a339ff85ef'), + value=10, + data='abcdefghijklmnop' * 16) + self.assertEqual(sig_v, 28) + self.assertEqual(binascii.hexlify(sig_r), '6da89ed8627a491bedc9e0382f37707ac4e5102e25e7a1234cb697cedb7cd2c0') + self.assertEqual(binascii.hexlify(sig_s), '691f73b145647623e2d115b208a7c3455a6a8a83e3b4db5b9c6d9bc75825038a') + + sig_v, sig_r, sig_s = self.client.ethereum_sign_tx( + n=[0, 0], + nonce=123456, + gas_price=20000, + gas_limit=20000, + to=binascii.unhexlify('1d1c328764a41bda0492b66baa30c4a339ff85ef'), + value=12345678901234567890, + data='ABCDEFGHIJKLMNOP' * 256 + '!!!') + self.assertEqual(sig_v, 28) + self.assertEqual(binascii.hexlify(sig_r), '4e90b13c45c6a9bf4aaad0e5427c3e62d76692b36eb727c78d332441b7400404') + self.assertEqual(binascii.hexlify(sig_s), '3ff236e7d05f0f9b1ee3d70599bb4200638f28388a8faf6bb36db9e04dc544be') + + +if __name__ == '__main__': + unittest.main()