Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions tests/test_msg_ethereum_erc20_0x_signtx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# This file is part of the KEEPKEY project.
#
# Copyright (C) 2021 Shapeshift
#
# 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 <http://www.gnu.org/licenses/>.

import unittest
import common
import binascii
import struct

import keepkeylib.messages_pb2 as proto
import keepkeylib.types_pb2 as proto_types
import keepkeylib.exchange_pb2 as proto_exchange
from keepkeylib.client import CallException
from keepkeylib.tools import int_to_big_endian

class TestMsgEthereum0xtxERC20(common.KeepKeyTest):

def test_sign_0x_swap(self):
self.setup_mnemonic_nopin_nopassphrase()

sig_v, sig_r, sig_s = self.client.ethereum_sign_tx(
n=[2147483692,2147483708,2147483648,0,0],
nonce=0xab,
gas_price=0x24c988ac00,
gas_limit=0x26249,
value=0x2386f26fc10000,
to=binascii.unhexlify('def1c0ded9bec7f1a1670819833240f027b25eff'),
address_type=0,
chain_id=1,
data=binascii.unhexlify('d9627aa4000000000000000000000000' +
'0000000000000000000000000000000000000080000000000000000000000000' +
'000000000000000000000000002386f26fc10000000000000000000000000000' +
'0000000000000000000000000000000000ce5ba6000000000000000000000000' +
'0000000000000000000000000000000000000001000000000000000000000000' +
'0000000000000000000000000000000000000002000000000000000000000000' +
'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee000000000000000000000000' +
'a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48869584cd0000000000000000' +
'00000000c770eefad204b5180df6a14ee197d99d808ee52d0000000000000000' +
'000000000000000000000000000000b27e9475e6602eb781')
)

self.assertEqual(sig_v, 37)
self.assertEqual(binascii.hexlify(sig_r), '7ac66b6b14b9c148da3c075ce43322814e8e5d76f412f6f4adbccd97f50f0e3c')
self.assertEqual(binascii.hexlify(sig_s), '00bba3641b4b05c4871444983c300f48e3e9d7046e35cfa78b95b2888d94d65b')

def test_sign_longdata_swap(self):
self.setup_mnemonic_nopin_nopassphrase()

sig_v, sig_r, sig_s = self.client.ethereum_sign_tx(
n=[2147483692,2147483708,2147483648,0,0],
nonce=0xab,
gas_price=0x24c988ac00,
gas_limit=0x26249,
value=0x2386f26fc10000,
to=binascii.unhexlify('def1c0ded9bec7f1a1670819833240f027b25eff'),
address_type=0,
chain_id=1,
data=binascii.unhexlify('ef3f3d0b' +
'000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' +
'000000000000000000000000b25c9552a91dd8c7e64ed444fb4aa5ac4dca5c9d00000000000000000000000000000000000000000000000000000000000f4240' +
'000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001e0' +
'00000000000000000000000000000000000000000000000000000000000002600000000000000000000000000000000000000000000000000000000000000420' +
'00000000000000000000000000000000000000000000000000000000000004c00000000000000000000000000000000000000000000000000001fde92d4e8a1d' +
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003' +
'000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48' +
'0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d0000000000000000000000000000000000000000000000000000000000000003' +
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' +
'0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d000000000000000000000000000000000000000000000000000000000000018c' +
'095ea7b30000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d00000000000000000000000000000000000000000000000000000000' +
'00000000095ea7b30000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488dffffffffffffffffffffffffffffffffffffffffffffffff' +
'ffffffffffffffff18cbafe500000000000000000000000000000000000000000000000000000000000f42400000000000000000000000000000000000000000' +
'00000000000000000000000100000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000b76c291871b92a7c' +
'9e020b2511a3402a3bf0499d00000000000000000000000000000000000000000000000000000000602cb5fe0000000000000000000000000000000000000000' +
'000000000000000000000002000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d' +
'0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004' +
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044' +
'0000000000000000000000000000000000000000000000000000000000000088000000000000000000000000000000000000000000000000000000000000018c' +
'00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000' +
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000')
)
self.assertEqual(sig_v, 38)
self.assertEqual(binascii.hexlify(sig_r), 'fc7f619f0b7d2b59757bbad8a5e5943fb49b1f67fe8eada1329435af48f4c119')
self.assertEqual(binascii.hexlify(sig_s), '75afaec8233d4297d28cf63b23e593ffe4896bf53e3d156d6f13ae2ba6b4dae4')

if __name__ == '__main__':
unittest.main()