|
| 1 | +# This file is part of the KEEPKEY project. |
| 2 | +# |
| 3 | +# Copyright (C) 2021 Shapeshift |
| 4 | +# |
| 5 | +# This library is free software: you can redistribute it and/or modify |
| 6 | +# it under the terms of the GNU Lesser General Public License as published by |
| 7 | +# the Free Software Foundation, either version 3 of the License, or |
| 8 | +# (at your option) any later version. |
| 9 | +# |
| 10 | +# This library is distributed in the hope that it will be useful, |
| 11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +# GNU Lesser General Public License for more details. |
| 14 | +# |
| 15 | +# You should have received a copy of the GNU Lesser General Public License |
| 16 | +# along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + |
| 18 | +import unittest |
| 19 | +import common |
| 20 | +import binascii |
| 21 | +import struct |
| 22 | + |
| 23 | +import keepkeylib.messages_pb2 as proto |
| 24 | +import keepkeylib.types_pb2 as proto_types |
| 25 | +import keepkeylib.exchange_pb2 as proto_exchange |
| 26 | +from keepkeylib.client import CallException |
| 27 | +from keepkeylib.tools import int_to_big_endian |
| 28 | + |
| 29 | +class TestMsgEthereum0xtxERC20(common.KeepKeyTest): |
| 30 | + |
| 31 | + def test_sign_0x_swap(self): |
| 32 | + self.setup_mnemonic_nopin_nopassphrase() |
| 33 | + |
| 34 | + sig_v, sig_r, sig_s = self.client.ethereum_sign_tx( |
| 35 | + n=[2147483692,2147483708,2147483648,0,0], |
| 36 | + nonce=0xab, |
| 37 | + gas_price=0x24c988ac00, |
| 38 | + gas_limit=0x26249, |
| 39 | + value=0x2386f26fc10000, |
| 40 | + to=binascii.unhexlify('def1c0ded9bec7f1a1670819833240f027b25eff'), |
| 41 | + address_type=0, |
| 42 | + chain_id=1, |
| 43 | + data=binascii.unhexlify('d9627aa4000000000000000000000000' + |
| 44 | + '0000000000000000000000000000000000000080000000000000000000000000' + |
| 45 | + '000000000000000000000000002386f26fc10000000000000000000000000000' + |
| 46 | + '0000000000000000000000000000000000ce5ba6000000000000000000000000' + |
| 47 | + '0000000000000000000000000000000000000001000000000000000000000000' + |
| 48 | + '0000000000000000000000000000000000000002000000000000000000000000' + |
| 49 | + 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee000000000000000000000000' + |
| 50 | + 'a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48869584cd0000000000000000' + |
| 51 | + '00000000c770eefad204b5180df6a14ee197d99d808ee52d0000000000000000' + |
| 52 | + '000000000000000000000000000000b27e9475e6602eb781') |
| 53 | + ) |
| 54 | + |
| 55 | + self.assertEqual(sig_v, 37) |
| 56 | + self.assertEqual(binascii.hexlify(sig_r), '7ac66b6b14b9c148da3c075ce43322814e8e5d76f412f6f4adbccd97f50f0e3c') |
| 57 | + self.assertEqual(binascii.hexlify(sig_s), '00bba3641b4b05c4871444983c300f48e3e9d7046e35cfa78b95b2888d94d65b') |
| 58 | + |
| 59 | + def test_sign_longdata_swap(self): |
| 60 | + self.setup_mnemonic_nopin_nopassphrase() |
| 61 | + |
| 62 | + sig_v, sig_r, sig_s = self.client.ethereum_sign_tx( |
| 63 | + n=[2147483692,2147483708,2147483648,0,0], |
| 64 | + nonce=0xab, |
| 65 | + gas_price=0x24c988ac00, |
| 66 | + gas_limit=0x26249, |
| 67 | + value=0x2386f26fc10000, |
| 68 | + to=binascii.unhexlify('def1c0ded9bec7f1a1670819833240f027b25eff'), |
| 69 | + address_type=0, |
| 70 | + chain_id=1, |
| 71 | + data=binascii.unhexlify('ef3f3d0b' + |
| 72 | + '000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' + |
| 73 | + '000000000000000000000000b25c9552a91dd8c7e64ed444fb4aa5ac4dca5c9d00000000000000000000000000000000000000000000000000000000000f4240' + |
| 74 | + '000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001e0' + |
| 75 | + '00000000000000000000000000000000000000000000000000000000000002600000000000000000000000000000000000000000000000000000000000000420' + |
| 76 | + '00000000000000000000000000000000000000000000000000000000000004c00000000000000000000000000000000000000000000000000001fde92d4e8a1d' + |
| 77 | + '00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003' + |
| 78 | + '000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48' + |
| 79 | + '0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d0000000000000000000000000000000000000000000000000000000000000003' + |
| 80 | + '00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' + |
| 81 | + '0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d000000000000000000000000000000000000000000000000000000000000018c' + |
| 82 | + '095ea7b30000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d00000000000000000000000000000000000000000000000000000000' + |
| 83 | + '00000000095ea7b30000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488dffffffffffffffffffffffffffffffffffffffffffffffff' + |
| 84 | + 'ffffffffffffffff18cbafe500000000000000000000000000000000000000000000000000000000000f42400000000000000000000000000000000000000000' + |
| 85 | + '00000000000000000000000100000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000b76c291871b92a7c' + |
| 86 | + '9e020b2511a3402a3bf0499d00000000000000000000000000000000000000000000000000000000602cb5fe0000000000000000000000000000000000000000' + |
| 87 | + '000000000000000000000002000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d' + |
| 88 | + '0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004' + |
| 89 | + '00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044' + |
| 90 | + '0000000000000000000000000000000000000000000000000000000000000088000000000000000000000000000000000000000000000000000000000000018c' + |
| 91 | + '00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000' + |
| 92 | + '00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000') |
| 93 | + ) |
| 94 | + self.assertEqual(sig_v, 38) |
| 95 | + self.assertEqual(binascii.hexlify(sig_r), 'fc7f619f0b7d2b59757bbad8a5e5943fb49b1f67fe8eada1329435af48f4c119') |
| 96 | + self.assertEqual(binascii.hexlify(sig_s), '75afaec8233d4297d28cf63b23e593ffe4896bf53e3d156d6f13ae2ba6b4dae4') |
| 97 | + |
| 98 | +if __name__ == '__main__': |
| 99 | + unittest.main() |
0 commit comments