Skip to content

Commit adf5a64

Browse files
committed
Fix ETH Transfer tests
1 parent 58982fc commit adf5a64

File tree

2 files changed

+48
-41
lines changed

2 files changed

+48
-41
lines changed

keepkeylib/client.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -571,24 +571,26 @@ def int_to_big_endian(value):
571571
return rlp.utils.int_to_big_endian(value)
572572

573573
n = self._convert_prime(n)
574-
if address_type == 1: #Ethereum transfer transaction
574+
if address_type == types.TRANSFER: #Ethereum transfer transaction
575575
msg = proto.EthereumSignTx(
576576
address_n=n,
577577
nonce=int_to_big_endian(nonce),
578578
gas_price=int_to_big_endian(gas_price),
579579
gas_limit=int_to_big_endian(gas_limit),
580580
value=int_to_big_endian(value),
581-
to_address_n=to_n
581+
to_address_n=to_n,
582+
address_type=address_type
582583
)
583-
elif address_type == 3: #Ethereum exchange transaction
584+
elif address_type == types.EXCHANGE: #Ethereum exchange transaction
584585
msg = proto.EthereumSignTx(
585586
address_n=n,
586587
nonce=int_to_big_endian(nonce),
587588
gas_price=int_to_big_endian(gas_price),
588589
gas_limit=int_to_big_endian(gas_limit),
589590
value=int_to_big_endian(value),
590591
to_address_n=to_n,
591-
exchange_type=exchange_type
592+
exchange_type=exchange_type,
593+
address_type=address_type
592594
)
593595
msg.address_type = address_type
594596
else:

tests/test_msg_ethereum_signtx_xfer.py

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
from rlp.utils import int_to_big_endian
3232

3333
class TestMsgEthereumSigntx(common.KeepKeyTest):
34-
@unittest.expectedFailure # Safety check fails
3534
def test_ethereum_tx_xfer_acc1(self):
3635
self.setup_mnemonic_nopin_nopassphrase()
3736
self.client.apply_policy('ShapeShift', 1)
@@ -41,21 +40,21 @@ def test_ethereum_tx_xfer_acc1(self):
4140
nonce=0,
4241
gas_price=20,
4342
gas_limit=20,
44-
value=12345678901234567890,
45-
to_n=[0x8000002c, 0x8000003c, 1, 0, 0],
46-
address_type=1,
43+
value=1234567890,
44+
to_n=[0x8000002c, 0x8000003c, 0x80000001, 0, 0],
45+
address_type=proto_types.TRANSFER,
46+
chain_id=1,
4747
)
4848

49-
self.assertEqual(sig_v, 27)
50-
self.assertEqual(binascii.hexlify(sig_r), '99f70cb618893ed3489add3de2adc0a3597bb59f683b67feb67f14145bef6766')
51-
self.assertEqual(binascii.hexlify(sig_s), '03c76425482270f1c720cb3c457a91b3d9e55848f21fdbde949e075fda344ab7')
52-
self.assertEqual(binascii.hexlify(hash), '4cc3cd55e89f68f3bab16eeb94bc50c53fec6e8946e749a85be390b06cd09f42')
53-
self.assertEqual(binascii.hexlify(signature_der), '304502210099f70cb618893ed3489add3de2adc0a3597bb59f683b67feb67f14145bef6766022003c76425482270f1c720cb3c457a91b3d9e55848f21fdbde949e075fda344ab7')
49+
self.assertEqual(sig_v, 37)
50+
self.assertEqual(binascii.hexlify(sig_r), '72b87b41a92dbad6dffcd7f9441102029adad4864291f867726abaaa3572dee7')
51+
self.assertEqual(binascii.hexlify(sig_s), '26814243d29bea4dddaef6da5b8af6836e499c2c7ccaa0877204f5465edc8290')
52+
self.assertEqual(binascii.hexlify(hash), 'f8cb6ffe80afaa7f651e66933e62667c3250a0168fcc29b1f46529511bf53fe6')
53+
self.assertEqual(binascii.hexlify(signature_der), '3044022072b87b41a92dbad6dffcd7f9441102029adad4864291f867726abaaa3572dee7022026814243d29bea4dddaef6da5b8af6836e499c2c7ccaa0877204f5465edc8290')
5454

5555
#reset policy ("ShapeShift")
5656
self.client.apply_policy('ShapeShift', 0)
5757

58-
@unittest.expectedFailure # Safety check fails
5958
def test_ethereum_tx_xfer_acc2(self):
6059
self.setup_mnemonic_nopin_nopassphrase()
6160
self.client.apply_policy('ShapeShift', 1)
@@ -65,21 +64,21 @@ def test_ethereum_tx_xfer_acc2(self):
6564
nonce=0,
6665
gas_price=20,
6766
gas_limit=20,
68-
value=12345678901234567890,
69-
to_n=[0x8000002c, 0x8000003c, 2, 0, 0],
70-
address_type=1,
67+
value=1234567890,
68+
to_n=[0x8000002c, 0x8000003c, 0x80000002, 0, 0],
69+
address_type=proto_types.TRANSFER,
70+
chain_id=1,
7171
)
7272

73-
self.assertEqual(sig_v, 28)
74-
self.assertEqual(binascii.hexlify(sig_r), '1c1949e8a261f8abfc40f4b6230fd69d7ce14c8d5ca7629af61ceb4ba0ea0b45')
75-
self.assertEqual(binascii.hexlify(sig_s), '59c450dce64d38aba22527353a8708255859c9c25abbfca07a19cf180d5a3858')
76-
self.assertEqual(binascii.hexlify(hash), '77e95b8843f6fd5f27c37a3ced1a1369a236e566ed0fea45a7a57d278c590860')
77-
self.assertEqual(binascii.hexlify(signature_der), '304402201c1949e8a261f8abfc40f4b6230fd69d7ce14c8d5ca7629af61ceb4ba0ea0b45022059c450dce64d38aba22527353a8708255859c9c25abbfca07a19cf180d5a3858')
73+
self.assertEqual(sig_v, 37)
74+
self.assertEqual(binascii.hexlify(sig_r), '24b978c585e12ef9bb816105718adcdd11824262919489c22b63d9c71873535f')
75+
self.assertEqual(binascii.hexlify(sig_s), '079f2a155bec09d7a7e23189aa5f6a4305df839605eed23a720486a919306259')
76+
self.assertEqual(binascii.hexlify(hash), '9d78419c4bbe60057b4ce5e3b8115b8a486589890dc9751b87c2bece0ed2f4a1')
77+
self.assertEqual(binascii.hexlify(signature_der), '3044022024b978c585e12ef9bb816105718adcdd11824262919489c22b63d9c71873535f0220079f2a155bec09d7a7e23189aa5f6a4305df839605eed23a720486a919306259')
7878

7979
#reset policy ("ShapeShift")
8080
self.client.apply_policy('ShapeShift', 0)
8181

82-
@unittest.expectedFailure # Safety check fails
8382
def test_ethereum_xfer_account_path_error_0(self):
8483
self.setup_mnemonic_nopin_nopassphrase()
8584
self.client.apply_policy('ShapeShift', 1)
@@ -89,9 +88,10 @@ def test_ethereum_xfer_account_path_error_0(self):
8988
nonce=0,
9089
gas_price=20,
9190
gas_limit=20,
92-
value=12345678901234567890,
93-
to_n=[0x8000002c, 0x8000003c, 2, 0, 0],
94-
address_type=1,
91+
value=1234567890,
92+
to_n=[0x8000002c, 0x8000003c, 0x80000002, 0, 0],
93+
address_type=proto_types.TRANSFER,
94+
chain_id=1,
9595
)
9696

9797
try:
@@ -100,10 +100,11 @@ def test_ethereum_xfer_account_path_error_0(self):
100100
nonce=0,
101101
gas_price=20,
102102
gas_limit=20,
103-
to_n=[0x8000002a, 0x8000003c, 1, 0, 0],
104-
#error here -^-
105-
value=12345678901234567890,
106-
address_type=1,
103+
to_n=[0x8000002c, 0x8000003c, 2, 0, 0],
104+
#error here -^-
105+
value=1234567890,
106+
address_type=proto_types.TRANSFER,
107+
chain_id=1,
107108
)
108109
except CallException as e:
109110
self.assertEndsWith(e.args[1], 'Failed to compile output')
@@ -114,21 +115,25 @@ def test_ethereum_xfer_account_path_error_0(self):
114115
#reset policy ("ShapeShift")
115116
self.client.apply_policy('ShapeShift', 0)
116117

117-
@unittest.expectedFailure # Safety check fails
118118
def test_ethereum_xfer_account_path_error_1(self):
119119
self.setup_mnemonic_nopin_nopassphrase()
120120
self.client.apply_policy('ShapeShift', 1)
121121

122+
# Really we should warn instead in this case, and show:
123+
# "Transfer 0.001234 ETH to m/44'/60'/1'/0/0/"
124+
# on the device, rathern than erroring out.
125+
122126
try:
123127
signature_der = self.client.ethereum_sign_tx(
124128
n=[0, 0],
125129
nonce=0,
126130
gas_price=20,
127131
gas_limit=20,
128-
to_n=[0x8000002c, 0x80000030, 1, 0, 0],
129-
#error here -^-
130-
value=12345678901234567890,
131-
address_type=1,
132+
to_n=[0x8000002c, 0x8000003c, 1, 0, 0],
133+
#error here -^-
134+
value=1234000000000000,
135+
address_type=proto_types.TRANSFER,
136+
chain_id=1,
132137
)
133138
except CallException as e:
134139
self.assertEndsWith(e.args[1], 'Failed to compile output')
@@ -139,7 +144,6 @@ def test_ethereum_xfer_account_path_error_1(self):
139144
#reset policy ("ShapeShift")
140145
self.client.apply_policy('ShapeShift', 0)
141146

142-
@unittest.expectedFailure # Safety check fails
143147
def test_ethereum_xfer_account_path_error_2(self):
144148
self.setup_mnemonic_nopin_nopassphrase()
145149
self.client.apply_policy('ShapeShift', 1)
@@ -153,8 +157,9 @@ def test_ethereum_xfer_account_path_error_2(self):
153157
gas_limit=20,
154158
to_n=[0x8000002c, 0x8000003c, 1, 1, 0],
155159
#error here -^-
156-
value=12345678901234567890,
157-
address_type=1,
160+
value=1234567890,
161+
address_type=proto_types.TRANSFER,
162+
chain_id=1,
158163
)
159164
except CallException as e:
160165
self.assertEndsWith(e.args[1], 'Failed to compile output')
@@ -165,7 +170,6 @@ def test_ethereum_xfer_account_path_error_2(self):
165170
#reset policy ("ShapeShift")
166171
self.client.apply_policy('ShapeShift', 0)
167172

168-
@unittest.expectedFailure # Safety check fails
169173
def test_ethereum_xfer_account_path_error_3(self):
170174
self.setup_mnemonic_nopin_nopassphrase()
171175
self.client.apply_policy('ShapeShift', 1)
@@ -178,8 +182,9 @@ def test_ethereum_xfer_account_path_error_3(self):
178182
gas_limit=20,
179183
to_n=[0x8000002c, 0x8000003c, 1, 0, 1],
180184
#error here -^-
181-
value=12345678901234567890,
182-
address_type=1,
185+
value=1234567890,
186+
address_type=proto_types.TRANSFER,
187+
chain_id=1,
183188
)
184189
except CallException as e:
185190
self.assertEndsWith(e.args[1], 'Failed to compile output')

0 commit comments

Comments
 (0)