Skip to content

Commit 5ee7378

Browse files
committed
test: reject unrenderable Ethereum amounts
1 parent f840e38 commit 5ee7378

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

tests/test_msg_ethereum_signtx.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,49 @@
3030

3131

3232
class TestMsgEthereumSigntx(common.KeepKeyTest):
33+
def test_ethereum_unrenderable_amounts_are_rejected(self):
34+
"""Neither a native nor ERC-20 amount may reach an approval blank."""
35+
self.requires_firmware("7.14.2")
36+
self.requires_fullFeature()
37+
self.setup_mnemonic_nopin_nopassphrase()
38+
39+
recipient = binascii.unhexlify(
40+
"1d1c328764a41bda0492b66baa30c4a339ff85ef"
41+
)
42+
max_uint256 = (1 << 256) - 1
43+
44+
with self.client:
45+
self.client.set_expected_responses([
46+
proto.Failure(
47+
code=proto_types.Failure_SyntaxError,
48+
message="Ethereum amount too large"),
49+
])
50+
with self.assertRaises(CallException):
51+
self.client.ethereum_sign_tx(
52+
n=[0, 0], nonce=0, gas_price=20, gas_limit=21000,
53+
to=recipient, value=max_uint256, chain_id=1,
54+
)
55+
56+
# Known mainnet ERC-20 transfer with the same unrenderable amount.
57+
erc20_data = (
58+
binascii.unhexlify("a9059cbb" + "00" * 12) +
59+
recipient + int_to_big_endian(max_uint256).rjust(32, b"\x00")
60+
)
61+
with self.client:
62+
self.client.set_expected_responses([
63+
proto.Failure(
64+
code=proto_types.Failure_SyntaxError,
65+
message="Ethereum amount too large"),
66+
])
67+
with self.assertRaises(CallException):
68+
self.client.ethereum_sign_tx(
69+
n=[0, 0], nonce=0, gas_price=20, gas_limit=60000,
70+
to=binascii.unhexlify(
71+
"d0d6d6c5fe4a677d343cc433536bb717bae167dd"
72+
),
73+
value=0, chain_id=1, data=erc20_data,
74+
)
75+
3376
def test_ethereum_signtx_data(self):
3477
self.requires_fullFeature()
3578
self.setup_mnemonic_nopin_nopassphrase()

0 commit comments

Comments
 (0)